Repository navigation
X: Fluorescence: fix cross-section normalisation, sampling, SPLIT cache and file handling - #3088
Merged
Merged
Conversation
…he and file handling
…uorescence update
Contributor
|
@farhi looks OK to me, with one remark: |
Contributor
Author
Yes, I've ported the display section from SX. Wait for completion of tests, and merge OK |
This was referenced Nov 11, 2026
willend
added a commit
to willend/McCode
that referenced
this pull request
Nov 11, 2026
… fix Both use FluoPowder, which inherits the Fluorescence code changed in mccode-dev#3088. Refs mccode-dev#3091 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
4 of 32 tasks
khurrumsaleem
pushed a commit
to khurrumsaleem/McCode
that referenced
this pull request
Nov 12, 2026
khurrumsaleem
pushed a commit
to khurrumsaleem/McCode
that referenced
this pull request
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
X: Fluorescence.comp: fix cross-section normalisation, sampling, SPLIT cache and file handling
This is a rather large bug fix for the McXtrace
Fluorescencecomponent. Affected files:FluorescenceSOLEIL_ROCKTest_FluoPowderHere is a synthetic table with changes:
Net effect: reference results have been updated in
SOLEIL_ROCKandTest_FluoPowder. The largest changes are for compounds, Compton, and SPLIT or hollow geometries.Here are more details on the changes:
Physics and normalisation
n_atoms[i] = nAtoms[i]*weight/molarMass.rhois now the density of units: formula units, or unit cells whenweightis a cell weight.weight,density,rhoandpacking_factorare updated accordingly.1/ρ = Σ wᵢ/ρᵢ) instead of a mass-weighted sum of elemental densities. The component exits with an error if neitherdensitynorrhocan be determined.packing_factor. It is applied only when given explicitly, in the range 0 to 1. Previously a defaultdensity/mat_densitywas always derived and applied, which double-counted a user-supplieddensity.(1-s)²and(1+cos²θ)/2weights are removed.Ex,EyandEzare zeroed after emission.CSb_Rayl(Z)andCSb_Compt(Z)instead of the compound total.DCSb_Compt(barn/at/sr) instead ofDCS_Compt(cm²/g/sr).flag_low_z. The weight now includes the missing factornElements, because elements are sampled uniformly with probability 1/nElements. The element index is clamped, and zero cross sections are guarded.flag_rayleigh=0,flag_compton=0and unknown types are now rejected up front withABSORB.my_scomment is corrected: barn·Å⁻³ → m⁻¹ via the factor 100.Sampling and library functions
XRMC_SelectFromDistributioncallers. The cumulated arrays have a leading 0, soNmust be nb_items + 1.XRAYLIB_LINES_MAXinstead of+1, so the last line was unreachable.XRAYLIB_LINES_MAX+1and clamps the index.XRMC_SelectFluorescenceEnergy.*dEis initialised to 0.sum_xs <= 0(no line excited).XRMC_SelectInteraction. It uses a fixedcum_xs[8]stack array, withnb_processes <= 7checked, instead ofmalloc/free.SPLIT caching
reuse_validflag. Before, it matched on |k| only, so unrelated photons with the same energy could reuse stale geometry.reuse_intersectand the new cache fields are initialised.Geometry and transport
p_interact < 0. Intermediate lengths (l1,l2) are now always computed. Previously a hollow geometry broke when forcing was disabled, which is documented as "-1 inactivate".mc_scatt <= 0the photon is transmitted instead of absorbed.dl0+dl1+dl2, including any hole, instead of onlyd_path(dl0+dl2).Material file parsing
materialparameter. It is no longer overwritten with the guessed formula. A localmat_nameis used throughout (parser, error and info messages).Titletoken offset. It isLine+5. It wasLine+7, which dropped the first formula characters.removeSpacesFromStr. It now keeps(,)and., so formulas likeCa(OH)2or fractional stoichiometry survive. It casts tounsigned char.<ctype.h>is now included explicitly.Display and docs
DISPLAY. Fixed the} if (shape == 2)bug, which should beelse if. Removed the duplicated box-drawing block.flag_kisseldoc now says Z ≥ 50, matching the code. It said "Z>=52 Te".typedoc lists TRANSMISSION=3 / DIFFRACTION=4 in the order of the actual#defines? Please check: the#defines areDIFFRACTION 3andTRANSMISSION 4, so the fixed doc order matches the code.flagvariable.Declaration of use of AI-tools
Development OS / boundary conditions
Please describe what OS you developed and tested your additions on, and if any special dependencies are required:
PR Checklist for contributing to McStas/McXtrace
For a coherent and useful contribution to McStas/McXtrace, please fill in relevant parts of the checklist:
My contribution includes patches to an existing component file
mcdocutility and rendered a reasonable documentation page for the component (please attach as screenshot in comments!)mctestutility to test one or more instruments making use of the component (please attachmcviewtestreport as screenshot in comments)mccode-clangformattool to apply the standard McCode component indentation schememcrun --c-lint"linter" and followed advice to remove most / all warnings that are raisedMy contribution includes patches to an existing instrument file
%Test:target values