@@ -97,10 +97,10 @@ ProcessCode TrackTruthMatcher::execute(const AlgorithmContext& ctx) const {
9797 const bool recoMatched =
9898 static_cast <double >(nMajorityHits) / track.nMeasurements () >=
9999 m_cfg.matchingRatio ;
100- const bool truthMatched =
101- static_cast < double >(nMajorityHits) /
102- particleTruthHitCount. at (majorityParticleId) >=
103- m_cfg. matchingRatio ;
100+ const double trackTruthRatio = static_cast < double >(nMajorityHits) /
101+ particleTruthHitCount. at (majorityParticleId);
102+ const bool truthMatched = trackTruthRatio >= m_cfg. matchingRatio ;
103+ const auto trackWithWeight = std::make_pair (track. index (), trackTruthRatio) ;
104104
105105 if ((!m_cfg.doubleMatching && recoMatched) ||
106106 (m_cfg.doubleMatching && recoMatched && truthMatched)) {
@@ -110,33 +110,56 @@ ProcessCode TrackTruthMatcher::execute(const AlgorithmContext& ctx) const {
110110
111111 auto & particleTrackMatch = particleTrackMatching[majorityParticleId];
112112 if (!particleTrackMatch.track ) {
113- particleTrackMatch.track = track. index () ;
113+ particleTrackMatch.track = trackWithWeight ;
114114 } else {
115115 // we already have a track associated with this particle and have to
116116 // resolve the ambiguity.
117117 // we will use the track with more hits and smaller chi2
118- const auto & otherTrack =
118+ const auto & currBestTrack =
119119 tracks.getTrack (particleTrackMatch.track .value ());
120- if (otherTrack .nMeasurements () < track.nMeasurements () ||
121- otherTrack .chi2 () > track.chi2 ()) {
122- trackParticleMatching[otherTrack .index ()].classification =
120+ if (currBestTrack .nMeasurements () < track.nMeasurements () ||
121+ currBestTrack .chi2 () > track.chi2 ()) {
122+ trackParticleMatching[currBestTrack .index ()].classification =
123123 TrackMatchClassification::Duplicate;
124- particleTrackMatch.track = track.index ();
124+ // previous now goes to duplicate since it has a worse match
125+ particleTrackMatch.duplicateIdxs .push_back (
126+ particleTrackMatch.track .value ());
127+ // assign the new track as the main matched track
128+ particleTrackMatch.track = trackWithWeight;
125129 } else {
126130 trackParticleMatch.classification =
127131 TrackMatchClassification::Duplicate;
132+ particleTrackMatch.duplicateIdxs .push_back (trackWithWeight);
128133 }
129134
130135 ++particleTrackMatch.duplicates ;
131136 }
132- } else {
137+ } else { // not matched, i.e. fake track
138+ ACTS_DEBUG (" Track " << track.tipIndex () << " in event " << ctx.eventNumber
139+ << " NOT MATCHED to particle " << majorityParticleId.particle ()
140+ << " with " << particleTruthHitCount.at (majorityParticleId)
141+ << " hits in event " << ctx.eventNumber << " . Out of "
142+ << track.nMeasurements () << " track hits, "
143+ << nMajorityHits << " were right." );
133144 trackParticleMatching[track.index ()] = {TrackMatchClassification::Fake,
134145 std::nullopt , particleHitCounts};
135146
136147 auto & particleTrackMatch = particleTrackMatching[majorityParticleId];
148+ particleTrackMatch.fakeIdxs .push_back (trackWithWeight);
137149 ++particleTrackMatch.fakes ;
138150 }
139151 }
152+ // Sort duplicate and fakes by decreasing weight
153+ for (auto & [_, entry] : particleTrackMatching) {
154+ std::sort (entry.duplicateIdxs .begin (), entry.duplicateIdxs .end (),
155+ [](const TrackIndexWithWeight& t1, const TrackIndexWithWeight& t2) {
156+ return t1.second > t2.second ; // sort by weight
157+ });
158+ std::sort (entry.fakeIdxs .begin (), entry.fakeIdxs .end (),
159+ [](const TrackIndexWithWeight& t1, const TrackIndexWithWeight& t2) {
160+ return t1.second > t2.second ;
161+ });
162+ }
140163
141164 m_outputTrackParticleMatching (ctx, std::move (trackParticleMatching));
142165 m_outputParticleTrackMatching (ctx, std::move (particleTrackMatching));
0 commit comments