Skip to content

Commit 691c816

Browse files
authored
Merge pull request #48986 from AuroraPerego/fixAncestor
Fix `idLastStoredAncestor` to point to a track parent when the full graph is not saved
2 parents 41e8446 + 2dce981 commit 691c816

File tree

9 files changed

+25
-17
lines changed

9 files changed

+25
-17
lines changed

SimDataFormats/Track/interface/SimTrack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SimTrack : public CoreSimTrack {
6868

6969
void setIsPrimary() { trackInfo_ |= (1 << 1); }
7070
void setGenParticleID(const int idx) { igenpart = idx; }
71-
int getPrimaryID() const { return igenpart; }
71+
int getPrimaryOrLastStoredID() const { return igenpart; }
7272
uint8_t getTrackInfo() const { return trackInfo_; }
7373

7474
private:

SimG4CMS/Calo/src/CaloSD.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ unsigned int CaloSD::findBoundaryCrossingParent(const G4Track* track, bool markA
574574
#endif
575575
boundaryCrossingParentMap_[id] = id;
576576
trkInfo->setStoreTrack();
577-
trkInfo->setIdLastStoredAncestor(id);
577+
if (trkInfo->idLastStoredAncestor() == track->GetParentID())
578+
trkInfo->setIdLastStoredAncestor(id);
578579
return id;
579580
}
580581
// Else, traverse the history of the track
@@ -683,7 +684,8 @@ CaloG4Hit* CaloSD::createNewHit(const G4Step* aStep, const G4Track* theTrack, in
683684
#endif
684685
if (etrack >= energyCut || forceSave) {
685686
trkInfo->setStoreTrack();
686-
trkInfo->setIdLastStoredAncestor(theTrack->GetTrackID());
687+
if (trkInfo->idLastStoredAncestor() == theTrack->GetParentID())
688+
trkInfo->setIdLastStoredAncestor(theTrack->GetTrackID());
687689
}
688690
} else {
689691
TrackWithHistory* trkh = tkMap[currentID[k].trackID()];

SimG4CMS/Forward/src/TimingSD.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ void TimingSD::getStepInfo(const G4Step* aStep) {
163163
if (incidentEnergy > energyCut) {
164164
info = cmsTrackInformation(theTrack);
165165
info->setStoreTrack();
166-
info->setIdLastStoredAncestor(theTrack->GetTrackID());
166+
if (info->idLastStoredAncestor() == theTrack->GetParentID())
167+
info->setIdLastStoredAncestor(theTrack->GetTrackID());
167168
}
168169
if (incidentEnergy > energyHistoryCut) {
169170
if (nullptr == info) {

SimG4CMS/Muon/src/MuonSensitiveDetector.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ void MuonSensitiveDetector::createHit(const G4Step* aStep) {
249249
if (thePabs > ePersistentCutGeV_ || (thePID == 13 && allMuonsPersistent_)) {
250250
TrackInformation* info = cmsTrackInformation(theTrack);
251251
info->setStoreTrack();
252-
info->setIdLastStoredAncestor(theTrack->GetTrackID());
252+
if (info->idLastStoredAncestor() == theTrack->GetParentID())
253+
info->setIdLastStoredAncestor(theTrack->GetTrackID());
253254
}
254255

255256
#ifdef EDM_ML_DEBUG

SimG4CMS/Tracker/src/TkAccumulatingSensitiveDetector.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ void TkAccumulatingSensitiveDetector::update(const BeginOfTrack* bot) {
153153
if (gTrack->GetKineticEnergy() > energyCut) {
154154
info = cmsTrackInformation(gTrack);
155155
info->setStoreTrack();
156-
info->setIdLastStoredAncestor(gTrack->GetTrackID());
156+
if (info->idLastStoredAncestor() == gTrack->GetParentID())
157+
info->setIdLastStoredAncestor(gTrack->GetTrackID());
157158
}
158159
//
159160
// Save History?

SimG4Core/Application/plugins/OscarMTProducer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void OscarMTProducer::produce(edm::Event& e, const edm::EventSetup& es) {
268268
edm::LogVerbatim("Track") << " " << i << ". " << (*p1)[i].trackId() << ", " << (*p1)[i] << ", "
269269
<< (*p1)[i].crossedBoundary() << "-> " << (*p1)[i].getIDAtBoundary() << ", "
270270
<< (*p1)[i].isFromBackScattering() << ", " << (*p1)[i].isPrimary() << "-> "
271-
<< (*p1)[i].getPrimaryID();
271+
<< (*p1)[i].getPrimaryOrLastStoredID();
272272
}
273273
}
274274
}

SimG4Core/CustomPhysics/plugins/DBremWatcher.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ void DBremWatcher::update(const BeginOfTrack* trk) {
105105
if (std::find(pdgs_.begin(), pdgs_.end(), pdg) != pdgs_.end()) {
106106
//Found an A'
107107
trkInfo->setStoreTrack();
108-
trkInfo->setIdLastStoredAncestor(theTrack->GetTrackID());
108+
if (trkInfo->idLastStoredAncestor() == theTrack->GetParentID())
109+
trkInfo->setIdLastStoredAncestor(theTrack->GetTrackID());
109110
VertexPos = Vpos;
110111
aPrimeTraj = theTrack->GetMomentum();
111112
LogDebug("DBremWatcher") << "Save SimTrack the Track " << theTrack->GetTrackID() << " Type "
@@ -137,7 +138,8 @@ void DBremWatcher::update(const EndOfTrack* trk) {
137138
if (std::find(pdgs_.begin(), pdgs_.end(), pdg) == pdgs_.end() &&
138139
(theTrack->GetCreatorProcess()->GetProcessName()) == "muDBrem") {
139140
trkInfo->setStoreTrack();
140-
trkInfo->setIdLastStoredAncestor(theTrack->GetTrackID());
141+
if (trkInfo->idLastStoredAncestor() == theTrack->GetParentID())
142+
trkInfo->setIdLastStoredAncestor(theTrack->GetTrackID());
141143
}
142144
}
143145
}

SimG4Core/Notification/src/SimTrackManager.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ void SimTrackManager::addTrack(TrackWithHistory* iTrack, const G4Track* track, b
7676
auto info = static_cast<const TrackInformation*>(track->GetUserInformation());
7777
if (info->isInTrkFromBackscattering())
7878
iTrack->setFromBackScattering();
79-
// set there for the *non-primary* tracks the genParticle ID associated with the G4Track
80-
// for the primaries this is done in the TrackWithHistory constructor.
79+
// set there for the *non-primary* tracks the G4Track ID of the last stored ancestor
80+
// for the primaries the genparticle id is saved in the TrackWithHistory constructor.
8181
// In the constructor of TrackWithHistory the info isPrimary is saved and used
8282
// to give -1 if the track is not a primary.
8383
if (not iTrack->isPrimary())
84-
iTrack->setGenParticleID(info->mcTruthID());
84+
iTrack->setGenParticleID(info->idLastStoredAncestor());
8585
m_trackContainer.push_back(iTrack);
8686
const auto& v = track->GetStep()->GetPostStepPoint()->GetPosition();
8787
std::pair<int, math::XYZVectorD> p(iTrack->trackID(),

SimGeneral/Debugging/plugins/CaloParticleDebugger.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void CaloParticleDebugger::analyze(const edm::Event& iEvent, const edm::EventSet
164164
LogVerbatim("CaloParticleDebuggerSimTracks")
165165
<< i << "\t" << t.trackId() << "\t" << t << " Crossed Boundary: " << t.crossedBoundary()
166166
<< " Vtx: " << t.vertIndex() << " isFromBackScattering: " << t.isFromBackScattering()
167-
<< " isPrimary: " << t.isPrimary() << " ParentID: " << t.getPrimaryID()
167+
<< " isPrimary: " << t.isPrimary() << " ParentID: " << t.getPrimaryOrLastStoredID()
168168
<< " Position Boundary: " << t.getPositionAtBoundary() << " Momentum Boundary: " << t.getMomentumAtBoundary()
169169
<< " Momemtum Origin: " << t.momentum();
170170
trackid_to_track_index[t.trackId()] = i;
@@ -232,10 +232,11 @@ void CaloParticleDebugger::analyze(const edm::Event& iEvent, const edm::EventSet
232232
<< "\n\n"
233233
<< i << "\tType: " << simcl.pdgId() << "\tEnergy: " << simcl.energy() << "\tKey: " << i; // << simcl ;
234234
auto const& simtrack = simcl.g4Tracks()[0];
235-
LogVerbatim("CaloParticleDebuggerSimClusters") << "\n Primary GenParticleID: " << simtrack.getPrimaryID()
236-
<< "\n Crossed Boundary: " << simtrack.crossedBoundary()
237-
<< "\n Position Boundary: " << simtrack.getPositionAtBoundary()
238-
<< "\n Momentum Boundary: " << simtrack.getMomentumAtBoundary();
235+
LogVerbatim("CaloParticleDebuggerSimClusters")
236+
<< "\n GenParticleID/ancestor: " << simtrack.getPrimaryOrLastStoredID()
237+
<< "\n Crossed Boundary: " << simtrack.crossedBoundary()
238+
<< "\n Position Boundary: " << simtrack.getPositionAtBoundary()
239+
<< "\n Momentum Boundary: " << simtrack.getMomentumAtBoundary();
239240
if (simClusters_in_CaloParticles.find(simcl.g4Tracks()[0].trackId()) == simClusters_in_CaloParticles.end()) {
240241
LogVerbatim("CaloParticleDebuggerSimClusters") << " Orphan SimCluster: " << simtrack.trackId();
241242
}

0 commit comments

Comments
 (0)