Skip to content

Commit

Permalink
Merge pull request #29 from madbaron/matching_fix
Browse files Browse the repository at this point in the history
protections against missing objects
  • Loading branch information
madbaron authored Dec 10, 2024
2 parents d045c6d + 4935bfc commit ce74f55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/ACTSDuplicateRemoval.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void ACTSDuplicateRemoval::processEvent(LCEvent* evt) {
std::vector<EVENT::Track*> 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];

Expand Down
26 changes: 11 additions & 15 deletions src/TrackTruthProc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,15 @@ void TrackTruthProc::processEvent(LCEvent* evt) {
std::vector<std::shared_ptr<LCRelationNavigator>> hit2simhits;
for (const std::string& name : _inColH2SH) {
// Get the collection of tracker hit relations
LCCollection* trackerHitRelationCollection =
ACTSTracking::getCollection(evt, name);
std::shared_ptr<LCRelationNavigator> hit2simhit =
std::make_shared<LCRelationNavigator>(trackerHitRelationCollection);
LCCollection* trackerHitRelationCollection = ACTSTracking::getCollection(evt, name);
if (trackerHitRelationCollection == nullptr) continue;
std::shared_ptr<LCRelationNavigator> hit2simhit = std::make_shared<LCRelationNavigator>(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();

Expand All @@ -83,8 +81,7 @@ void TrackTruthProc::processEvent(LCEvent* evt) {

for (int itT = 0; itT < nTracks; ++itT) {
// Get the track
EVENT::Track* track =
static_cast<EVENT::Track*>(trackCollection->getElementAt(itT));
EVENT::Track* track = static_cast<EVENT::Track*>(trackCollection->getElementAt(itT));

// Loop over all hits in a track and associate it to a MC particle
std::map<EVENT::MCParticle*, uint32_t> trackhit2mc;
Expand All @@ -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<EVENT::MCParticle*, uint32_t>& mchit : trackhit2mc) {
float frac =
static_cast<float>(mchit.second) / track->getTrackerHits().size();
for (const std::pair<EVENT::MCParticle*, uint32_t>& mchit : trackhit2mc) { float frac = static_cast<float>(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;
Expand Down

0 comments on commit ce74f55

Please sign in to comment.