Coder Social home page Coder Social logo

mcstas_gisans's Introduction

Project to carry out the simulation of GISANS measurements at neutron scattering instruments by joint McStas + BornAgain simulations, using MCPL to facilitate the transition between the two simulation software.

The simulation of a neutron scattering instrument up until the sample is carried out using a McStas model of the instrument, that ends in an MCPL_output component to export neutrons in an MCPL file. This MCPL file is then used as a source of neutrons for the subsequent GISANS simulation of a sample model using BornAgain through a Python script. The result of this simulation is a Qx,Qy,Qz histogram (and corresponding uncertainty) in an NPZ file, that can be processed with a plotting script.

Installation

  • Clone this repository
  • Install McStas 3.x
  • Use conda to create an environment from the conda.yml file:
    conda env create -f conda.yml --name mcstas_ba
    

Simulation

  • Run the McStas simulation in shell set up for running McStas:

    mcstas-3.4-environment
    mcrun mcstas/loki_master_model.instr sampletype=-1 sourceapx=0.010 sampleapx=0.005 sourceapy=0.004 sampleapy=0.0002 l_min=5.5 l_max=6.5 collen=5 source_l_min=5.5 source_l_max=6.5 -n1e8 -d output_dir --mpi=6
    
  • Run the BornAgain simulation script using the MCPL output file from the McStas simulation in a shell with the conda environment activated:

    conda activate mcstas_ba
    python events2BA.py output_dir/test_events.mcpl.gz --instrument='loki' --pixel_number=100 --savename 'test_q'
    
  • Plot the result:

    python plotQ.py --filename test_q.npz --label "test run" --intensity_min 1e-6 --x_min=-0.3 --x_max=0.3 --y_min=-0.25 --y_max=0.3
    

Suggestions for setup

  • Make events2BA.py and plotQ.py executable, so that you don't need to prepend the commands with 'python'.
  • Add the path of your cloned repository to your PATH environment variable, so that you can invoke the events2BA.py and plotQ.py command anywhere.

mcstas_gisans's People

Contributors

milanklausz avatar aglavic avatar

mcstas_gisans's Issues

Output T0 correction figures

Similarly as for the MCPL input filtering, where --figure_output input option can be used to visually verify the TOF filtering range (and Gaussian fitting), a similar option could be implemented for the T0 correction Gaussian fitting.

Either use a separate input option (with new names), or use a unified one (just make sure that the script in only terminated when both figures are created).

Simplify the coordinate system handling

The current coodinate system handling is quite cumbersome (at least to understand). The MCPL_output needs to be rotated by 90deg due to legacy reasons, which creates a new coordinate system doesn't agree either with the standard McStas coord system (Nexus coordinate system) or the Geometric conventions in BornAgain.
The normal McStas coords should be just fine throughout the script, as long as angles for BornAgain are calculated correctly.

The incident angle shouldn't be hardcoded

Issue:
Currently the alpha_inc incident angle is hardcoded in the BornAgain script. The incident angle is the result of the coordinate system rotation for the McStas MCPL output component (e.g.: ROTATED (89.760,0,0) RELATIVE sample_arm gives 0.24 deg incident angle), that is essentially the same as rotating the sample. (BornAgain works in a system where the sample surface is in the horisontal plane.)
There is no coordinate system rotation implemented for the incident neutrons in the BornAgain script so the incident angle is decided by the McStas simulation (output).

In reality, the end of the guide system might have an angle (might not be horisontal), plus the sample could also be rotated (not be in the horisontal plane). Also, the detector surface is assumed to be perpendicular to the sample surface (which also might not be the case)

Expectation
The neutron parameters (position, direction) in the MCPL file should be expressed with respect to a flat sample in the horisontal plane. The coordinate rotation mimicing the sample rotation should be applied in the BornAgain script, based on the intended incident angle from a dedicated input and the guide end angle stored as an MCPL metadata. By default, the detector surface should be vertical, regardless of the sample rotation (incident angle), but there might as well be an input for detector tilt angle.

Tasks

  • The neutron parameters in the MCPL file should be expressed with respect to a flat(liquid) sample. So rotate the MCPL output component in accordance with the angle of the guide end
  • The angle of the guide end should be stored as metadata in the MCPL file
  • The incident angle should be an input value for the BornAgain script
  • Coordinate transformation should be applied to the incident neutrons in the BornAgain script to accound for the guide end angle and the virtual sample rotation (to get the intended incident angle in BornAgain's 'horisontal sample based' coordinate system)
  • The detector surface should remain vertical, regardless of all angles.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.