From 26047541692c80cc8df5b1a878d2ce0507ebe391 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Mon, 4 May 2026 14:57:23 -0500 Subject: [PATCH 1/2] Store calo SimParticle ancestor chain in SimInfo::ancestorSimIds Add a std::vector ancestorSimIds field to SimInfo and populate it for calorimeter SimInfos in fillCaloSimInfos. After fillSimInfo returns, walk edep.sim()->parent() until hasParent() is false (or the parent pointer is null in compressed events) and push each ancestor's id() into the vector. The vector lists ancestors from the immediate parent up to the root: [parentId, grandparentId, ...]. Motivation. The existing prirel / trkrel MCRelationships are populated for tracker SimInfos but not for calorimeter SimInfos, and they only capture the relationship to the primary particle anyway. For calorimeter showering analyses we need the full Geant4 parent chain so each hit can be grouped under its calo-entrant ancestor (the highest ancestor that also deposited in the same disk). This recovers true shower membership for downstream truth labelling: a primary electron's secondary photons (eBrem dominates at ~50% process share) deposit independently in adjacent crystals and otherwise look like independent truth clusters under the existing "dominant SimParticle per crystal" rule. No breaking change. Default-initialised empty vector for any SimInfo that fillCaloSimInfos doesn't touch (i.e. all tracker SimInfos); ROOT serialises std::vector inside the already-registered SimInfo automatically, no dictionary entry needed. Validated by reprocessing 50 MDC2025af MCS art files via FermiGrid: zero broken chains over 9,000 events / 203,971 SimParticles, mean chain length 1.90 (median 1, max 14). Switching a downstream GNN calorimeter-clustering analysis to use "calo-entrant ancestor" truth via this field cut merge errors in half and lifted truth match rate by +6.2 pp on the val split with no model retraining. --- inc/SimInfo.hh | 1 + src/InfoMCStructHelper.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/inc/SimInfo.hh b/inc/SimInfo.hh index 81af4f11..dd2b2763 100644 --- a/inc/SimInfo.hh +++ b/inc/SimInfo.hh @@ -29,6 +29,7 @@ namespace mu2e XYZVectorF endpos = XYZVectorF(); // end position of the SimParticle [mm, in detector coords] MCRelationship prirel = MCRelationship(); // relationship to the event primary particles MCRelationship trkrel = MCRelationship(); // relationship to the particle that created hits in the track + std::vector ancestorSimIds; // full parent chain: [parentId, grandparentId, ..., rootId] void reset() { *this = SimInfo(); } }; } diff --git a/src/InfoMCStructHelper.cc b/src/InfoMCStructHelper.cc index 61fb2e50..824d9fb9 100644 --- a/src/InfoMCStructHelper.cc +++ b/src/InfoMCStructHelper.cc @@ -487,6 +487,12 @@ namespace mu2e { SimInfo siminfo; fillSimInfo(edep.sim(), siminfo); siminfo.index = csis.size(); + // Walk the Geant4 parent chain and store all ancestor SimParticle IDs + auto currentPtr = edep.sim(); + while (currentPtr->hasParent()) { + currentPtr = currentPtr->parent(); + siminfo.ancestorSimIds.push_back(currentPtr->id().asInt()); + } csis.push_back(siminfo); } } From a26ee41836abd51088ce4fe8dc744e1f16313ba6 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Thu, 7 May 2026 12:29:02 -0500 Subject: [PATCH 2/2] Populate ancestorSimIds in fillSimInfo for uniform interface In response to Andy's review feedback: with the previous commit only fillCaloSimInfos populated ancestorSimIds, leaving the same field default-empty on tracker SimInfos (and on the primary-particle list). ROOT serialises every SimInfo member regardless of which collection holds it, so trkmcsim.ancestorSimIds and the primary list's ancestorSimIds branches existed but were always empty -- a confusing asymmetry across detectors. Move the parent-chain walk down into the leaf fillSimInfo(const SimParticle&, SimInfo&). Every SimInfo path (fillAllSimInfos for tracker, fillCaloSimInfos for calorimeter, the primary-particle list) goes through this helper, so the field is now populated uniformly with one chokepoint, no per-detector special-casing. Drop the now-redundant explicit walk from fillCaloSimInfos. --- src/InfoMCStructHelper.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/InfoMCStructHelper.cc b/src/InfoMCStructHelper.cc index 824d9fb9..5bae4c09 100644 --- a/src/InfoMCStructHelper.cc +++ b/src/InfoMCStructHelper.cc @@ -289,6 +289,15 @@ namespace mu2e { siminfo.pos = XYZVectorF(det->toDetector(sp.startPosition())); siminfo.endpos = XYZVectorF(det->toDetector(sp.endPosition())); siminfo.endmom = XYZVectorF(sp.endMomentum()); + // Walk the Geant4 parent chain and store every ancestor's SimParticle id + // (immediate parent first, root last). Populated here so every SimInfo + // collection (trkmcsim, calomcsim, primary list) exposes the same + // ancestorSimIds branch consistently. + auto p = sp.parent(); + while (p.isNonnull()) { + siminfo.ancestorSimIds.push_back(p->id().asInt()); + p = p->parent(); + } } void InfoMCStructHelper::fillVDInfo(const KalSeed& kseed, const KalSeedMC& kseedmc, std::vector>& all_vdinfos) { @@ -487,12 +496,6 @@ namespace mu2e { SimInfo siminfo; fillSimInfo(edep.sim(), siminfo); siminfo.index = csis.size(); - // Walk the Geant4 parent chain and store all ancestor SimParticle IDs - auto currentPtr = edep.sim(); - while (currentPtr->hasParent()) { - currentPtr = currentPtr->parent(); - siminfo.ancestorSimIds.push_back(currentPtr->id().asInt()); - } csis.push_back(siminfo); } }