Repository navigation
Fix of the bending magnet source component - #2902
Conversation
|
Excellent work if I may say so @antoinepado . This looks really compelling. Haven't gone through the math so can't comment on that, but two practical things.
more to come... |
|
Hi @antoinepado Very nice work !! especially the comparison with Spectra. The failing tests still show very large changes The flux can change dramatically compared to the current reference values, and the BL. This is expected, however I would recommend a careful check of these, esp. ROCK, Test_BM_1, DISCO_1, to understand for each the origin of the change. |
|
@antoinepado agreed, really nice work. :-) And for @ebknudsen:
|
|
I suggest a few changes: - The 'lamdba' branch is broken: I removed it. - I added a test over dE as it is needed for `qe` init. - The Bessel integral function is not used. Removed.
|
I just pushed some fixes to this PR. Mostly the 'lambda' branch is not initialized properly. I removed it to avoid undefined 'qe'. |
|
@farhi @willend @ebknudsen Thank you. |
The lambda mode is restored. Checks for lambda0-dlambda> 0 and E0-dE>0
|
Just put back lambda mode, and add checks for E0-dE>0. |
|
No biggie certainly and not even sure it did before - but a note in the header about lambda-mode is perhaps warranted wrt that sampling is uniform in the corresponding energy-interval, not in lambda as such. |
…flux The fixed Bending_magnet now returns photons/s integrated over the sampled solid angle and energy band, so reference intensities change by design. Values from mxrun (mccode-dev, macOS arm64, CPU) with this PR's component, 1e6-1e7 rays. Test_BM SOURCE=1 (Wiggler) and the %Scan references are unaffected and left as-is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @antoinepado, really nice work. I've rerun every affected Updated %Example values
Test_BM SOURCE=1 is the Wiggler, so it's unaffected. The For ROCK, SAMBA and SIRIUS, the scatter between seeds is several times larger than the error each run reports. At the 1e6 rays the tests use, ROCK, Test_grating_reflect and SIRIUS scatter by 16–25%, so they may still occasionally fail the 20% tolerance. Review comments
I checked the flux expression against Kim's eq. (1), including the angular Jacobian Not tested: GPU, Linux, Windows. |
Use the mean of 5 seeds at 1e7 rays (mxrun, mccode-dev, macOS arm64 CPU) instead of single runs. Largest corrections: SOLEIL_ROCK 1.29e11 -> 1.61e11, SOLEIL_SAMBA 5.92e10 -> 5.69e10. ROCK, SAMBA and SIRIUS show seed-to-seed scatter (7-18% at 1e7) well above the reported per-run error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SOLEIL_DISCO_2: the %Scan ran at the mctest default of 1e5 rays per point. With the new Bending_magnet sampling +-2.5 mrad (was +-1/gamma), 2 of 21 points got no rays on w_monitor, so Wavelength=0. Use -n1e6, as Czerny_Turner already does. Reproduced and checked locally with seed 1000 and 2 MPI ranks (as in CI): all 21 points within 1.5%. Test_grating_reflect: 25% seed-to-seed scatter at 1e6 (CI seed gave 65% of the 5-seed mean). Use -n 1e7: CI seed gives 89%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
amazing ! |
- E0 now overrides lambda0, as documented (lambda mode only if E0==0). - %D: reference Kim (X-Ray Data Booklet eq. 1), state that p is photons/s into the sampled solid angle and [E0-dE,E0+dE], that dE>0 is required, and that without focus the angles are sampled within +-2.5 mrad. - No-focus mode: sample theta/psi uniformly in +-2.5 mrad instead of a gaussian truncated at 1 sigma (nearly flat anyway). Same expectation, but RNG use changes, so seeded results shift within statistics. - Remove unused variables and stale/commented code. CI-style check (seed 1000, 2 MPI ranks): all %Example tests within 14% of the references, both %Scan tests within 1.2% on all points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Update: we've gone ahead and addressed review points 1–5 above in fa469fa, so no action is needed on those, @antoinepado.
Separately, 8645e0e raises ncount for two noisy tests. The A CI-style local check (seed 1000, 2 MPI ranks, macOS arm64) after these changes:
Not tested: GPU, Linux, Windows (CI will cover the last two). |
|
@willend Thank you very much. |
@farhi @willend @ebknudsen
Two main fixes of the bending magnet are proposed. The first concerns the flux and the second the sampling probability densities.
Flux fix
I first started working on the flux fix 2.5 years ago. For archival purposes, work can be found here.
The work presented in this pull request continues this previous work mainly in regards to the sampling fix.
The current McXtrace component uses the spectral flux per$$mrad^2$$ solid angle and per $$0.1%$$ photon energy bandwidth. It is based on equation (28) from B.D. Patterson, Am. J. Phys. 79, 1046 (2011)
Remark : The equation from the paper has a typo and shows$$10^{33}$$ instead of $$10^{13}$$ .
This is the spectral flux density in the horizontal plane. This approximation holds when rays from the bending magnet are close to 0 vertically.
Rather than the above, the full angular distribution of synchrotron radiation is used in the fixed component. See equation (1) from Kim in the X-Ray Data Booklet, Section 2.1 Characteristics of Synchrotron Radiation.
Notice that equation (28) is simply is the full angular distribution of synchrotron radiation equation (1) with the vertical angle$$\psi=0$$ .
I show below one way I justify this change.$$13mm \times 2.4mm$$ placed 8.7m away from the source.
An example of a real source can be found in a paper from Brunelle, Journal of Synchrotron Radiation, 2023 showing the new superbend of SOLEIL's ROCK beamline. The paper describes a slit of aperture
A simulation of ROCK's bending magnet is done with the synchrotron source software SPECTRA and with McXtrace. This comparison is done in order to validate McXtrace's bending magnet.
The following graph shows the flux in units of photons/sec/0.1%bw.
A simulation with and without the slit is run for three different cases:
Flux (photons/sec/0.1%bandwidth), normalized (to see the shape at first):
The graph below shows the same as the above with the flux in units of photons/sec , normalized (to see the shape at first).
In the graphs above we can see SPECTRA and McXtrace correspond for the new fixed bending magnet. The old bending magnet does not correspond to SPECTRA. Additionally, with or without the slit the flux does not change at all for the old bending magnet (the yellow and purple graphs are the same).
Below is the graph showing SPECTRA and the new fixed bending magnet in absolute units instead of normalized:
They correspond in absolute terms also.
Sampling probability densities fix
The fixed component also properly takes into account the sampling probability densities for both the energy and angles (vertical and horizontal).
The correct sampling densities are used whether the sampling is done uniformly or in a truncated gaussian way.
Here is a graph showing the flux (photons/sec/0.1%bandwidth) in absolute value of the new fixed bending magnet for the three different sampling methods (no focus, focus gaussian, focus uniform).
With slit:
Without slit:
The three different sampling methods show the same flux which is to be expected.
McXtrace instruments and simulation data, SPECTRA's configuration files and data, and the plotting script can be found in this uploaded folder in this pull request.
Please let me know if you agree with my analysis. If I have misunderstood something or made mistakes please let me know.
I can go into more detail if needed.
Thank you.
tests_bending_magnet_fixed.zip