Skip to content

McXtrace Single_crystal: compute absorption length directly, use runtime NA - #2937

Merged
willend merged 1 commit into
mainfrom
2026-10-sx-abs-cleanup
Oct 30, 2026
Merged

willend merged 1 commit into
mainfrom
2026-10-sx-abs-cleanup

Conversation

@willend

@willend willend commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #2880, prompted by @antoinepado's point there that the 10E typo itself cancelled out.

In the old code the absorption cross-section went cm² → barns or fm² (depending on barns) → /V0 → ×100 again for barns. That round trip never changes the result in m⁻¹, and the swapped 1e24/1e26 exponents fixed in #2880 were hiding inside it. This PR:

  • computes abs_xlen [1/m] in one expression via fm², independent of the barns flag (inc_xlen keeps its ×100 for barns)
  • uses the runtime NA instead of a hand-typed Avogadro literal (the source of the 10E23 typo)
  • drops the now-unused abs_xsect

Numerical behaviour: unchanged. The runtime NA (6.02214179e23) differs from the old literal (6.02214076e23) by 2e-7 relative. With fixed seeds (1e6 rays, seed 1001), every monitor in Test_PowderN index=2, Test_FluoPowder index=2, SSRL_bl_11_2_white_src, SSRL_bl_11_2_not_white_src and Test_Mono Mono=6 matches main to 7 digits, with the same warnings as main.

Tested on macOS arm64 (clang) only.

🤖 Generated with Claude Code

…ime NA

Follow-up to #2880. The absorption cross-section was converted from cm^2
to barns or fm^2 depending on the barns flag, then scaled by 100 again
for barns: a round trip whose result never depends on the flag, and
where the swapped exponents fixed in #2880 hid. Compute abs_xlen [1/m]
in one expression via fm^2, and use the runtime NA instead of a
hand-typed Avogadro literal (the 10E23 typo).

NA differs from the old literal by 2e-7 relative; results are otherwise
unchanged (identical to 7 digits on Test_PowderN, Test_FluoPowder,
SSRL_bl_11_2_* and Test_Mono with fixed seeds).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@willend

willend commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

@antoinepado and @farhi I think everything is better like this. Agree?

@willend
willend merged commit 88d881c into main Oct 30, 2026
21 checks passed
@antoinepado

Copy link
Copy Markdown
Collaborator

@willend Agreed it is simpler this way. Thank you.

@farhi

farhi commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Thanks all, nice fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants