Skip to content

Commit f103213

Browse files
committed
Change structure of ParticleMatchEntry to include a list of duplicates and fakes. Change TrackTruthMatcher.cpp accordingly, with the logic to select the best particle match being unchanged.
1 parent f0b469f commit f103213

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/TrackTruthMatcher.cpp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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));

Examples/Framework/include/ActsExamples/EventData/TruthMatching.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
namespace ActsExamples {
2222

23+
using TrackIndexWithWeight = std::pair<TrackIndexType, double>;
24+
2325
enum class TrackMatchClassification {
2426
Unknown = 0,
2527
/// The track is associated to a truth particle
@@ -41,7 +43,10 @@ struct TrackMatchEntry {
4143
};
4244

4345
struct ParticleMatchEntry {
44-
std::optional<TrackIndexType> track;
46+
std::optional<TrackIndexWithWeight> track;
47+
// weight is the ratio of the number of hits in track belonging to the particle
48+
std::vector<TrackIndexWithWeight> duplicateIdxs;
49+
std::vector<TrackIndexWithWeight> fakeIdxs;
4550
std::uint32_t duplicates{};
4651
std::uint32_t fakes{};
4752
};

0 commit comments

Comments
 (0)