From 4935bfcbc58c3a779a74f76a995d39685018e1ff Mon Sep 17 00:00:00 2001 From: Federico Meloni Date: Mon, 9 Dec 2024 16:38:32 +0100 Subject: [PATCH] protections against missing objects --- src/ACTSDuplicateRemoval.cxx | 2 +- src/TrackTruthProc.cxx | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/ACTSDuplicateRemoval.cxx b/src/ACTSDuplicateRemoval.cxx index 9b42e19..0d37cba 100644 --- a/src/ACTSDuplicateRemoval.cxx +++ b/src/ACTSDuplicateRemoval.cxx @@ -103,7 +103,7 @@ void ACTSDuplicateRemoval::processEvent(LCEvent* evt) { std::vector finalTracks; for (EVENT::Track* myTrk : sortedInput) { bool foundAnEqual = false; - for (int i = (finalTracks.size() >= 10) ? finalTracks.size() - 10 : 0; + for (size_t i = (finalTracks.size() >= 10) ? finalTracks.size() - 10 : 0; i < finalTracks.size(); ++i) { EVENT::Track* otherTrk = finalTracks[i]; diff --git a/src/TrackTruthProc.cxx b/src/TrackTruthProc.cxx index 1087188..e6956db 100644 --- a/src/TrackTruthProc.cxx +++ b/src/TrackTruthProc.cxx @@ -57,17 +57,15 @@ void TrackTruthProc::processEvent(LCEvent* evt) { std::vector> hit2simhits; for (const std::string& name : _inColH2SH) { // Get the collection of tracker hit relations - LCCollection* trackerHitRelationCollection = - ACTSTracking::getCollection(evt, name); - std::shared_ptr hit2simhit = - std::make_shared(trackerHitRelationCollection); + LCCollection* trackerHitRelationCollection = ACTSTracking::getCollection(evt, name); + if (trackerHitRelationCollection == nullptr) continue; + std::shared_ptr hit2simhit = std::make_shared(trackerHitRelationCollection); hit2simhits.push_back(hit2simhit); } // // MC particles - LCCollection* particleCollection = - ACTSTracking::getCollection(evt, _inColMCP); + LCCollection* particleCollection = ACTSTracking::getCollection(evt, _inColMCP); if (particleCollection == nullptr) return; int nParticles = particleCollection->getNumberOfElements(); @@ -83,8 +81,7 @@ void TrackTruthProc::processEvent(LCEvent* evt) { for (int itT = 0; itT < nTracks; ++itT) { // Get the track - EVENT::Track* track = - static_cast(trackCollection->getElementAt(itT)); + EVENT::Track* track = static_cast(trackCollection->getElementAt(itT)); // Loop over all hits in a track and associate it to a MC particle std::map trackhit2mc; @@ -99,20 +96,19 @@ void TrackTruthProc::processEvent(LCEvent* evt) { } } + if (simHit == nullptr) continue; + // Increment MC particle counter - if (simHit->getMCParticle() != nullptr) - trackhit2mc[simHit->getMCParticle()]++; + if (simHit->getMCParticle() != nullptr) trackhit2mc[simHit->getMCParticle()]++; + } // Update best matches - for (const std::pair& mchit : trackhit2mc) { - float frac = - static_cast(mchit.second) / track->getTrackerHits().size(); + for (const std::pair& mchit : trackhit2mc) { float frac = static_cast(mchit.second) / track->getTrackerHits().size(); bool better = mcBestMatch_track.count(mchit.first) == 0 || // no best match exists - mcBestMatch_frac[mchit.first] < - frac; // this match is better (more hits on track) + mcBestMatch_frac[mchit.first] < frac; // this match is better (more hits on track) if (better) { mcBestMatch_track[mchit.first] = track;