Skip to content

Take SimInfo end values from the last simulation stage - #443

Merged
sophiemiddleton merged 1 commit into
Mu2e:mainfrom
oksuzian:siminfo-last-stage-end
Nov 7, 2026
Merged

sophiemiddleton merged 1 commit into
Mu2e:mainfrom
oksuzian:siminfo-last-stage-end

Conversation

@oksuzian

@oksuzian oksuzian commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In staged MC, a particle that crosses a stage boundary has one SimParticle per stage. The ancestry loop in fillAllSimInfos fills each generation from the first stage (originParticle()), so stopCode, endpos and endmom describe 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:

  • Piece A (stage 1): born from a pion decay, ends at TS3, where stage 1 stops tracking it.
  • Piece B (stage 2): starts at TS3, ends where the muon decays into the electron.

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:

SimParticle created by ends with
2, μ⁻ (stage 1) Decay of the π⁻ mu2eKillerVolume at TS3
3, μ⁻ (stage 2) mu2ePrimary (resampled 2) Decay, producing electron 4

The parent entry used to be the start and end of 2. It is now the start of 2 and the end of 3. id stays the first-stage ID, so trkrel, prirel and 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.

  • Before: 223 de tracks from muon decay. Parent muon stopCode = mu2eKillerVolume for 223/223. Distance from the electron pos to the muon endpos: 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, endpos and endmom in demcsim, uemcsim, dmmcsim and ummcsim, 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 mcsim entries 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 through mcsim will see different numbers. Calorimeter SimInfos and the primary entries call fillSimInfo directly and are unchanged. This may conflict with draft #441, which edits the same two files.

🤖 Generated with Claude Code

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
oksuzian marked this pull request as ready for review November 7, 2026 14:59
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