Repository navigation
Take SimInfo end values from the last simulation stage - #443
Merged
Merged
Conversation
In staged MC, a particle that crosses a stage boundary is split into one SimParticle per stage. fillAllSimInfos fills each generation from the first-stage SimParticle (originParticle()), so stopCode, endpos and endmom described the end of the first stage, for example a muon stopped by the killer volume at TS3, rather than the point where it decayed. Keep the start values from the first stage. Take the end values from the stage that made the track hits (generation 0) or that produced the previous generation. Particles simulated in a single stage are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oksuzian
marked this pull request as ready for review
November 7, 2026 14:59
ehrlich-uva
approved these changes
Nov 7, 2026
sophiemiddleton
approved these changes
Nov 7, 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.
Summary
In staged MC, a particle that crosses a stage boundary has one
SimParticleper stage. The ancestry loop infillAllSimInfosfills each generation from the first stage (originParticle()), sostopCode,endposandendmomdescribe where the first stage ended, not where the particle stopped or decayed.James Mott reported this for muons decaying in flight (POT, then MuBeamResampler, then digi/reco/ntuple). The tracked electron's parent muon was listed as stopped by the killer volume at TS3, several metres from the decay.
In plain terms
A staged simulation stores one real muon as two pieces:
For each particle in the electron's family tree, the ntuple records where it started and where it ended. For the muon it used piece A for both. The start was right (the pion decay). The end was the TS3 cutoff, which is not a physical event. The real end, the decay, is in piece B, which was never read.
The fix takes the start from piece A and the end from piece B. The muon's entry now says it was born from a pion decay and ended by decaying where the electron starts, with its momentum at that point as
endmom. A particle simulated in one stage has a single piece, so its entry does not change.Like a train trip with a transfer: the old code reported the first ticket's origin and destination, which is only the transfer station. The fix reports the first ticket's origin and the last ticket's destination.
The change
fillAllSimInfos for each generation fillSimInfo(current_sim_particle, sim_info) # first stage: id, pdg, start values + fillSimInfoEnd(*current_sim_particle_ptr, sim_info) # stopCode, endpos, endmom from the stage that + # made the hits or produced the previous generation current_sim_particle_ptr = current_sim_particle.parent() current_sim_particle = current_sim_particle_ptr->originParticle()In the reported event:
The parent entry used to be the start and end of 2. It is now the start of 2 and the end of 3.
idstays the first-stage ID, sotrkrel,prireland the duplicate check are unchanged.Evidence
Same input for both runs: a 544-event DIF mcs file (MuBeamCat Run1Bai resampled with the DS at 50% and a forced muon decay, then digitized and reconstructed). The ntuple stage ran with
main(dea6d03) and with this branch, built against AnalysisMDC2025 v02_03_01.detracks from muon decay. Parent muonstopCode= mu2eKillerVolume for 223/223. Distance from the electronposto the muonendpos: 6.4–12.5 m.After: parent muon
stopCode= Decay for 223/223. Distance: 0 mm for 223/223.All 754 leaf branches were compared between the two outputs. The only real differences are
stopCode,endposandendmomindemcsim,uemcsim,dmmcsimandummcsim, for 223, 171, 192 and 146 entries, all of them muons. Electron, pion and proton entries are identical. A few segment branches differ only by NaN values present in both files.The mcs SimParticles confirm the picture: 423/423 decay electrons have a mu2ePrimary muon parent that ends at the electron's start, and the muon one step further back stops in the killer volume.
Merge Danger
Door: two-way
A revert restores the old values. The ntuple format is unchanged: no new branches or fields.
Blast Radius: staged-MC truth
Only
mcsimentries of particles resampled across a stage change, for example beam muons and pions in MuBeamResampler or flash chains. Analyses that relied on the old end values throughmcsimwill see different numbers. Calorimeter SimInfos and the primary entries callfillSimInfodirectly and are unchanged. This may conflict with draft #441, which edits the same two files.🤖 Generated with Claude Code