Skip to content

Fix wrong mult factor for absorption in Single_crystal - #2880

Merged
willend merged 6 commits into
mccode-dev:mainfrom
antoinepado:main
Oct 29, 2026
Merged

willend merged 6 commits into
mccode-dev:mainfrom
antoinepado:main

Conversation

@antoinepado

Copy link
Copy Markdown
Collaborator

Two fixes have been done.
First, in the abs_xsect variable 10E was used instead of 1E, this changes nothing in practice as this error cancelled out.
Secondly, the bigger change is the conversion from $$cm^2$$ to barns and from $$cm^2$$ to $$fm^2$$. Here is my understanding:
We have
$$1 barn = 10^{-28} m^2$$
and
$$1 femtometre = 10^{-15} m$$

To convert $$cm^2$$ to barns:
$$1 cm^2 = 10^{-2} m \cdot 10^{-2} m = 10^{-4} m^2$$
So we multiply by $$10^{24} \cdot 10^{-24}$$ both sides and we have
$$10^{24} \cdot 10^{-24} \cdot 1 cm^2 = 10^{24} \cdot 10^{-24} \cdot 10^{-4} m^2$$
$$1 cm^2 = 10^{24} \cdot 10^{-28} m^2$$
$$1 cm^2 = 10^{24} \cdot barn$$

And to convert $$cm^2$$ to $$fm^2$$:
$$1 cm^2 = 10^{-2} m \cdot 10^{-2} m = 10^{-4} m^2$$
So we multiply by $$10^{26} \cdot 10^{-26}$$ both sides and we have
$$10^{26} \cdot 10^{-26} \cdot 1 cm^2 = 10^{26} \cdot 10^{-26} \cdot 10^{-4} m^2$$
$$1 cm^2 = 10^{26} \cdot 10^{-30} m^2$$
$$1 cm^2 = 10^{26} \cdot fm^{2}$$

Please let me know if I have misunderstood something. Thank you.

@willend

willend commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@antoinepado thanks once more, I think your corrections are right.

They do however shift output orders of magnitude so I will leave to @farhi to:

  • validate
  • judge when to change/merge

(Especially since we are right before a new release.)

@willend

willend commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@antoinepado, @farhi says we should wait - putting your PR in draft to not merge by chance. ;-) Will make it to 3.10.1 or something like that.

@willend
willend marked this pull request as draft October 22, 2026 07:54
@farhi

farhi commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Hi @willend and @antoinepado

I think we can wait for after the release. This PR will definitively change many test values by orders. It can already be seen from the X/Test_PowderN examples:

  • %Example: index=1 Detector: Sph_mon_I=1.29869e-12 (PowderN)
  • Example: index=2 Detector: Sph_mon_I=3.88313e-14 (SX)
  • %Example: index=3 Detector: Sph_mon_I=6.29534e-12 (FluoPowder)

The index=2 is for the SX, and is typically a factor 100 too small. This test is currently off.

@willend
willend marked this pull request as ready for review October 29, 2026 16:51
@willend

willend commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review + estimated new targets (generated with Claude Code, checked by @willend).

Verdict: the fix is correct. One correction to the description: the old error did not cancel out. Downstream, abs_xlen = σ/V0 with V0 in ų and lengths in m, so σ in fm² gives m⁻¹ directly and the barns branch needs ×100. With the old factors:

  • barns=1 (.hkl from CIF, SSRL): σ came out in fm² but was treated as barns, so absorption was 100× too strong.
  • barns=0 (.lau): σ came out in barns but was treated as fm², so absorption was 100× too weak.

Measured shift. "Stock" is a single 1e6-ray run (seed 1000). "New target" is the inverse-variance weighted mean of 3 runs at 1e6 rays (seeds 1001, 2002, 3003) and 1 run at 1e7 rays (seed 4004), all with the fixed component:

Instrument / example Old target Stock New target (weighted) Status
SSRL_bl_11_2_white_src Etohit=6900 4.24366e+07 4.52e7 1.65837e+10 ± 8.0e7 active, updated
SSRL_bl_11_2_not_white_src Etohit=6900 1.3e+10 1.34e10 4.17271e+11 ± 2.8e9 value updated, still disabled
Test_PowderN index=2 (SX) 3.88313e-14 3.92e-14 1.91726e-12 ± 4.9e-15 value updated, still disabled
Test_FluoPowder E0=15 index=2 (SX) 1.5129e-19 1.53e-19 1.99226e-19 ± 4.6e-23 value updated, still disabled
Test_Mono Mono=6 (no target) — fpi 8.1e-14 fpi 3.9e-14 (single run) n/a: emon is 0 in both runs

These target updates are pushed to this PR as commit 1abedf7b2.

SX examples kept disabled (commit 07170c60e): I had re-enabled Test_PowderN index=2 and Test_FluoPowder index=2, assuming they were off only because of this bug. They were not: they were disabled on purpose earlier, Test_PowderN index=2 in 3c9ec204b (Single_crystal powder mode numerically unstable on GPU) and Test_FluoPowder index=2 in cb9df2a79 (fails consistently on Windows, possibly cif2hkl UB). Windows failed both again on this PR. They are back to disabled, with the new values kept and a note in each file saying why.

%Scan references: the 31-point EnergyMonitor_first_I arrays in both SSRL instruments were also computed with the old absorption and failed CI (worst points off by 3227% and 35772%). Commit 91360680d regenerates them. Each point is the inverse-variance weighted mean of two 1e7-ray scans (seeds 11, 22); the seeds agree within 6% at every point. New ranges: white_src 2.0e9 to 6.8e9 (was ~1e7), not_white_src 3.2e11 to 4.9e11 (was ~1.4e10).

Unchanged: Test_PowderN index 1 and 3, Test_FluoPowder index 1, 3, 4 and 5, and every instrument using material_datafile="NULL" (Test_SX, Test_SX_standalone, SOLEIL_PX1, SOLEIL_PX2a).

Locally, this also fixes the "factor ~100 too small" SX result in Test_PowderN (index=2) that @farhi pointed out: it is now in line with the PowderN result (index=1), about 1.3e-12.

Open question (not verified, separate from this PR): abs_xsect is per atom (A[r] from Si.txt) but is divided by the volume of the whole unit cell (V0). For Si, with 8 atoms per cell, absorption may still be about 8× too weak.

Note: in the SSRL white_src runs the 1e6 results spread a little more than their error bars suggest (1.54e10 to 1.68e10), so CI's tolerance may need to absorb a few percent there.

willend and others added 3 commits October 29, 2026 19:39
…t fix

Targets are inverse-variance weighted means of 3x 1e6 (seeds 1001,
2002, 3003) and 1x 1e7 (seed 4004) runs with the fixed component.
SSRL white_src target raised ~390x (barns=1 absorption was 100x too strong).
Re-enable SX examples in Test_PowderN (index=2) and Test_FluoPowder (index=2).
SSRL not_white_src value updated, left disabled as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ption fix

Each point is the inverse-variance weighted mean of two 1e7-ray scans
(seeds 11, 22) with the fixed component; seeds agree within 6%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both index=2 tests were disabled on purpose earlier (3c9ec20: GPU
instability in powder mode; cb9df2a: Windows failures, possibly
cif2hkl UB). Keep the new target values but leave the tests off, with
a note on why.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@willend
willend merged commit d860451 into mccode-dev:main Oct 29, 2026
20 checks passed
@antoinepado

Copy link
Copy Markdown
Collaborator Author

@willend

Verdict: the fix is correct. One correction to the description: the old error did not cancel out.

I think the above sentence is wrong. We can see that the the error where 10E is used instead of 1E cancels out no?
Line 1546 a division by 10E23 was done, then a multiplication at lines 1552 and 1554 by either 10E26 or 10E24 is done.
This is the same as doing a division by 1E23, then a multiplication by either 1E26 or 1E24.
The error cancels out. Am I misunderstanding something?

The main fix is the corrected conversion though, not the 10E to 1E mistake that had no change in practice.

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