McStasMcXtrace / McCode

The home of the McStas (neutrons) and McXtrace (x-rays) Monte-Carlo ray-tracing instrument simulation codes.
https://github.com/McStasMcXtrace/McCode/wiki
GNU General Public License v3.0
77 stars 52 forks source link

McXtrace: Single_crystal component simulation bug #1634

Open minghuisvn opened 3 days ago

minghuisvn commented 3 days ago

A bug occurred when simulating the diffraction of a single crystal Si in McXtrace3.2. The code is as follows:

DEFINE INSTRUMENT SimpleInstrument(E0=8.02)
TRACE
COMPONENT Origin = Progress_bar()
AT (0, 0, 0) ABSOLUTE

COMPONENT Source = Source_flat(
    yheight = 1e-3, xwidth = 1e-3, dist = 1, focus_xw = 1e-3,
    focus_yh = 1e-3, E0 = E0, dE = 0.1)
AT (0, 0, 0) RELATIVE Origin

COMPONENT Sample = Single_crystal(xwidth=0.01, yheight=0.01, zdepth=0.01,
delta_d_d=1e-4, mosaic = 5,
ax = 5.44, ay = 0, az = 0,
bx = 0, by = 5.44, bz = 0,
cx = 0, cy = 0, cz = 5.44,
reflections="Si.lau", order=1)
AT (0, 0, 1) RELATIVE Source

COMPONENT beamstop = Beamstop(radius=5e-3)
AT (0, 0, 0.1-1e-3) RELATIVE PREVIOUS

COMPONENT Detector = PSD_monitor(
    nx=200, ny=200, xwidth=0.5, yheight=0.5, filename="psd0",restore_xray=0
)
AT (0, 0, 1e-3) RELATIVE PREVIOUS

END

The simulation result is: image Nothing could be found in the figure of the psd monitor, that is the monitor did not received scattered x-ray photons. However, when i trace that process, and found the x-ray particles actually hit the psd monitor as shown below: image The results are contradictory.

willend commented 3 days ago

Dear @minghuisvn,

First a little general advice:

Now, let us try to understand what could be happening in your simulation.

  1. For every incoming x-ray, the Single_crystal algorithm will lay out reciprocal space in the form of the Ewald construction to investigate if there are reflections that may scatter for this incoming ray. In this case they are actually present as you will see, but not in the forward direction where your detector is located.
  2. It turns out that in the forward direction, the only "output channel" is in fact incoherent scattering which by default has a cross-section of 0, meaning scattered rays of weight 0 - which will never show up as intensity in your detector. :-) (If you look closely, the PSD is in fact measuring ~ 200k events out of 1e6, but all with 0 intensity...)
  3. Your incoming beam is a "pink beam", perhaps start from a Laue-geometry and a white beam
  4. The sample crystallography is perhaps not oriented as you initially thought, adding a sample rotation might work
  5. Making use of PSD_monitor_4PI allows you to get an overview of all scattered rays, this also helps...

In the attached, many of the above points have been added to your instrument, which seems to help. :)

I also attach screenshots of the default output on linear / log scale - there is scattering...

Screenshot 2024-07-04 at 10 44 52 Screenshot 2024-07-04 at 10 44 59

Best, Peter P.s.: Be aware that I am starting vacation this Friday, so I may not respond to further questions/enquiries for a while :-) But perhaps you will be in luck that @farhi has time to look.

SX_instrument.instr.txt

minghuisvn commented 2 days ago

Dear @willend,

Thank you for your advice! I am sorry about my hasty question without careful consideration. Thanks for you advice! I understand that the results that may be confusing at first glance could be understood through the careful analysis on a basis of physical knowledge (May be i should spend more time on that).I will dig into examples and annual school materials again. Thanks for your patient explanation and instructions!

Best regards, Sun

willend commented 2 days ago

Dear @minghuisvn,

You are very welcome and good luck practicing McXtrace. :-)

Best, Peter