Skip to content

restore missing factor-of-3 in mean radiative loss - #236

Merged
brownd1978 merged 2 commits into
KFTrack:mainfrom
edcallaghan:fix_radiative_mean
Nov 17, 2026
Merged

brownd1978 merged 2 commits into
KFTrack:mainfrom
edcallaghan:fix_radiative_mean

Conversation

@edcallaghan

@edcallaghan edcallaghan commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The implementation of energy loss via bremsstrahlung follows standard PDG-sanctioned thinking. Claude noticed a missing factor of 3 in the mean radiative loss computed by integrating the soft photoemission spectrum, which I think is real, as I didn't find it compensated for elsewhere. In vacuum, this would just be absorbed into ymax, the unphysical radiation cutoff. and amount to an innocent omission; but because the analogous factor-of-3 is present in the variance, the two aren't consistent. The consequence is that the radiative variance used in the fit is underpredicted, as it is based on a ymax that is has absorbed that factor of 3.

@oksuzian oksuzian left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary — #236

Reviewed at head 256dda4b4845b2572aca28a48cdceb6b61ccf3b8. First pass.

Decision

  • 🟡 comment. The fix is right: the old mean radiative loss was exactly 3 times too large at every cutoff, and the variance on the next line already had the correct coefficients. Two things need attention.
    • The macOS CI failure is caused by this change, through a check in the Truncate unit test that holds only for some toy events. That check needs a small fix before this merges (finding 1).
    • Mu2e tuned its cutoff against the old mean. With Mu2e's current ElectronBrehmsFraction: 0.03, this change moves the reconstructed momentum at the tracker front down by 46 keV/c. The tracker front, centred on MC truth today, then sits 56 keV/c low (finding 2). Mu2e only picks this up with a new KinKal tag, so this is a follow-up for Offline, not a blocker here.

Scope understood

  • One line, MatEnv/DetMaterial.cc:83. The mean radiative (bremsstrahlung) energy loss per radiation length, _erad, is divided by 3. The variance _eradvar on the next line is unchanged.
  • At a given cutoff ymax (the largest photon energy fraction kept), the modelled mean radiative loss drops by a factor 3. This applies to every electron or positron crossing of every material, in the fit and in extrapolation. Muon and pion fits are unaffected, because radiationEnergyLoss applies only to the electron mass (:217).

Findings

  1. 🟠 [S1] The macOS CI failure is caused by this change, through a check in Tests/Truncate_unit.cc that does not hold for every toy event.

    • Evidence:
      • Both macOS jobs fail one check, at the head (run 43991735951) and at the first commit bdf3906 (run 43991609287): FAILED: LoopHelix bfcorr inactive hits event 1 effects kept. The other 27 tests pass, and both Ubuntu jobs pass.
      • The same runner image (macos-26-arm64 20261102.0473) and compiler (clang 16.0.6) passed all 28 tests on main at d19623f (run 42379050793). They also passed on #235 (run 43304988418, 2026-11-12), which has the same base. So the trigger is this PR's code, not the runner.
      • The ToyMC simulates material effects with the same materialEffects call the fit uses (Tests/ToyMC.hh:186). So this change alters the generated events.
      • The check at Tests/Truncate_unit.cc:269 requires the number of effects to be unchanged after truncate. But truncate removes the DomainWall into every field domain that begins after the cut, by design (Fit/Track.hh:1099-1101). When the extrapolation past the inactive hits (:247-248) has to add a domain, its wall is removed and the count drops by one. The other cut checks in the same file subtract the removed walls (:87, neff - nwallcut); this one does not.
      • I reproduced this on AlmaLinux 9 (gcc 13.3, Release) with a copy of the test that takes the ToyMC seed as an argument and prints the domains. For seeds 1 to 80, the check fails in 77 seeds at d19623f and in 76 at the head. Every one of the 290 and 288 failures has a domain wall beyond the cut. With the committed seed 123421, no domain is added on Linux at either commit: the existing domain already reaches the extrapolation target, with 0.2 to 1.1 ns to spare.
    • Impact: merged as it is, main goes red on macOS. The physics change is not at fault. The check passes or fails depending on where the domain boundaries happen to fall.
    • Suggested fix: in testInactive, count the walls into domains that begin at or after cut before truncating, and check trk.effects().size() == neff - nwallcut, as checkCut does. Alternatively, check only that all NINACTIVE inactive hits are still among the effects. This can go into this PR, or into a small PR merged first.
  2. 🟠 [S1] Cross-repo follow-up: Mu2e's cutoff was tuned against the old mean, so ElectronBrehmsFraction needs a retune with the KinKal tag that carries this change. The PR reports no validation of the downstream effect; the numbers below supply it.

    • Evidence, tuning history:
      • Offline sets ElectronBrehmsFraction : 0.03 (KinKalGeom/fcl/prolog.fcl:18). It was lowered from 0.04 in Offline commit 54b130c ("Adjust brehmsstrahlung cutoff after pathlength fix", Mu2e/Offline#1900, merged 2026-07-27). That PR's description says the cutoff "is retuned to center the reconstructed track momentum at the tracker front".
      • The earlier 0.04, still KinKal's default (MatEnv/DetMaterial.hh:189), was "tuned to give correct response at TT_Front" (DocDB 54471, p. 9).
      • Both tunes used the 3-times-too-large mean. At 0.03 the mean loss per radiation length drops from 0.1182 E to 0.0394 E. The corrected formula gives the old mean at a cutoff of 0.093, where the variance is 9.2 times larger.
    • Evidence, measured. I ran Production recoMC (OnSpill) on 4,000 events of dig.mu2e.CeMLeadingLogMix1BB.MDC2025au_best_v1_3.001430_00001612.art, then EventNtuple. Offline 8628ceb7 was built twice, linked to KinKal v3.9.1 and to v3.9.1 plus this line, and was otherwise identical. The sample is the downstream e- fits (KKDe) that match an MC electron, converged, with fit consistency above 1e-3: 3,157 fits in base and 3,128 with the PR, of which 3,032 pair up (same event, same tracker-front crossing).
      • Change in reconstructed momentum, PR minus base, on the paired fits:

        where mean median
        tracker front (TT_Front) −45.8 ± 4.5 keV/c −44.0 keV/c
        tracker middle (TT_Mid) 0.0 ± 4.4 keV/c −0.7 keV/c
        tracker back (TT_Back) +44.4 ± 6.5 keV/c +41.6 keV/c
        last IPA crossing −59.4 ± 4.7 keV/c −57.7 keV/c
        stopping target exit (last target intersection) −76.6 ± 4.0 keV/c −71.4 keV/c
        most upstream target intersection −260 ± 9 keV/c −212 keV/c
        calorimeter disk 0 front +58 ± 13 keV/c +41 keV/c
        calorimeter disk 1 front +258 ± 17 keV/c +122 keV/c
      • The fit pivots about the tracker middle. The fits use 0.0116 radiation lengths of tracker material on average (EventNtuple radlen), so the modelled loss across the tracker drops by 0.0116 × 0.0788 × 104 MeV = 95 keV. The measured front-to-back change is 90 keV/c. In the target, each extra intersection adds about −18 keV/c.

      • Reconstructed minus true momentum, core Gaussian mean (core width):

        where base PR
        TT_Front −5 ± 4 keV/c (131) −56 ± 4 keV/c (138)
        TT_Mid −7 ± 3 keV/c (110) −7 ± 3 keV/c (107)
        TT_Back −7 ± 4 keV/c (134) +44 ± 4 keV/c (133)
        last target foil the electron crossed +81 ± 8 keV/c (177) −23 ± 7 keV/c (168)

        The medians at TT_Front are −22 and −73 keV/c. At the target foil they are +40 and −66 keV/c.

      • Today the tracker is centred on MC truth at all three planes, within 7 keV/c. With this change and the same cutoff, the fit models about 90 keV less loss across the tracker than the simulation has. At the target the change moves the residual from +81 to −23 keV/c. So one retuned cutoff may not centre both the tracker and the target.

      • Momentum error and pull at TT_Front: the reported error is unchanged (median 98 keV/c in both; paired change −1.3 ± 2.4 keV/c). The pull core mean goes from −0.04 to −0.44, and its width from 1.37 to 1.34.

      • Fit quality: all 3,837 paired fits converge in both. Above fit consistency 1e-3 the count goes from 3,298 to 3,276 (108 lost, 86 gained). The paired χ²/ndof rises by 0.0041 ± 0.0017.

    • Impact: none at merge, because Mu2e's envset p110 uses KinKal v3.9.1. When Offline adopts a tag with this change, the momentum scale moves by the amounts above unless the cutoff is retuned in the same step.
    • Suggested fix: no code change here. Please say in the PR description, and in the tag's release notes, that the mean radiative loss at a fixed cutoff drops by a factor 3. Every tuned cutoff then needs retuning, including KinKal's own default of 0.04 and the 0.04 in Tests/MatEnv_unit.cc:92. On the Offline side, retune ElectronBrehmsFraction against MC truth at TT_Front in the PR that moves to the new tag. A hard-coded copy of 3e-2 also sits in Mu2e/otsdaq-mu2e-dqm (otsdaq-mu2e-dqm/ArtModules/fcl/tracker_hit_occupancy/tracker_hit_services.fcl).
  3. 🟡 [S2] The variance on the next line grows with the square of the thickness, while photon emission is a Poisson process whose variance grows linearly. So mean and variance still disagree in how they scale with thickness, and the radiative variance is negligible in the fit at any cutoff. This line is outside the diff but bears directly on the PR's stated goal.

    • Evidence: radiationEnergyLossVar returns (mom*pathlen)^2*_eradvar (DetMaterial.cc:226), which is (E t)² f(ymax) for t radiation lengths, with f = ∫ y² dN/dy. For a Poisson process the variance of the summed loss is E² t f (Campbell's theorem). DocDB 54471 (p. 9) says the variance is "computed using Poisson variance of # of photons emitted". For one straw (wall 0.04 mm plus gas 4 mm, t = 1.9e-4) at 105 MeV/c and a cutoff of 0.03, KinKal gives σ = 0.41 keV, while the Poisson form gives 35 keV. The Moyal ionization RMS of the same straw is 1.0 keV. With the square, the result also depends on how a crossing is split into materials; a Poisson variance just adds up.
    • Suggested fix: decide which is intended, and make the code and DocDB 54471 agree. The Poisson form would be pow(mom,2)*fabs(pathlen)*(_density/_radthick)*f(ymax). Whether the full Poisson variance suits a Gaussian fit is a fair question, since most straw crossings emit nothing near the cutoff. Any change here belongs with the retune in finding 2.

Checked, no action needed

  • 🟢 The formula. The spectrum the code cites (RPP 2024 eq. 34.29, the complete-screening limit) is dN/dy = (1/y)(4/3 − 4/3 y + y²) photons per radiation length. The mean fractional loss up to ymax is ∫ y dN/dy = 4/3 y − 2/3 y² + 1/3 y³. That is 1 at ymax = 1, as the definition of the radiation length requires. The second moment is 2/3 y² − 4/9 y³ + 1/4 y⁴, which matches _eradvar. A numerical integration agrees to six digits, and the old-to-new ratio is 3.0000 at cutoffs 0.03, 0.04 and 1.
  • 🟢 It was an accidental omission. The first implementation (6acbf84, 2025-10-30) divided the same polynomial by 3*norm. The /3 was lost later the same day in 6092f23, when the normalisation was removed. The variance kept its coefficients.
  • 🟢 The fix is complete. _erad is read only in radiationEnergyLoss (DetMaterial.cc:218). Its only caller is energyLoss (:118), whose only consumer in KinKal is ElementXing::materialEffects (Detector/ElementXing.hh:102); the ToyMC uses the same path. In Offline, the other energyLoss calls are a debug print (KinKalGeom/src/KKStrawMaterial.cc:88-89) and ExtrapolateSweepTest, which uses the muon mass. radiationFraction, which fills EventNtuple's radlen, uses only the radiation length.
  • 🟢 Nothing compensated the factor elsewhere. No KinKal test has a reference energy loss; MatEnv_unit only prints and plots. The fit tests simulate with the same model they fit, so they cannot see a factor 3 either way. In Mu2e, the only compensation is the empirical cutoff of finding 2.
  • 🟢 Unit tests on Linux. At d19623f and at the head, 28 of 28 tests pass (AlmaLinux 9, gcc 13.3, ROOT 6.38, Release). KinKal v3.9.1, with and without this line, passes 27 of 27.

Validation check

  • Build/tests run: yes.
    • KinKal standalone builds (Release, C++20, as in the p110 spack recipe) of v3.9.1, v3.9.1 plus this one-line diff, d19623f and 256dda4, each followed by ctest.
    • Offline 8628ceb7, Production b2ef90eb, EventNtuple 7b4fe514, mu2e-trig-config 5f221e50 and ArtAnalysis 491fb227 on p110, built twice. The builds differ only in the KinKal library they link. Mu2e's envset p110 expects v3.9.1, so I applied this diff to v3.9.1 rather than taking the PR head, which also carries #234. Both builds exit 0 with no warnings. A loader trace shows each job loads only its own KinKal libraries.
    • Jobs: Production/JobConfig/recoMC/OnSpill.fcl with the validation database, on 4,000 events of the digi file above (online in dCache, read in place), then EventNtuple from_mcs-primary. All jobs exit 0.
  • Config contract check: not applicable; this PR changes no configuration.
  • Cross-repo consistency: needs follow-up in Offline (finding 2).

Residual risk

  • Not measured: upstream e- and e+ fits, the trigger's online fits, and calorimeter E/p matching. They use the same material model and will move too.
  • The sample is one file of mixed CeMLeadingLog events, with about 3,100 CE fits per variant.
  • I could not run macOS. The explanation of finding 1 rests on the CI logs and on the Linux seed scan.

Author follow-ups

  1. Fix the effects kept check at Tests/Truncate_unit.cc:269 so that macOS CI passes (finding 1).
  2. State in the description that the mean radiative loss at a fixed cutoff drops by a factor 3, so tuned cutoffs need retuning, including the KinKal default of 0.04. Tell the Mu2e tracking group before the next tag (finding 2).
  3. Optional: decide how the radiative variance should scale with thickness (finding 3).

@brownd1978 brownd1978 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this error! The AI has made a 1st pass re-calibration of the radiation cutoff, could you create a corresponding PR in Offline referencing this PR? thanks.

@brownd1978
brownd1978 merged commit 906c4ce into KFTrack:main Nov 17, 2026
2 of 4 checks passed
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