20 #include <unordered_map>
26 namespace ActsExamples {
27 struct AlgorithmContext;
33 :
WriterT(config.inputSeeds,
"SeedingPerformanceWriter", level),
35 m_effPlotTool(
m_cfg.effPlotToolConfig, level),
36 m_duplicationPlotTool(
m_cfg.duplicationPlotToolConfig, level) {
38 throw std::invalid_argument(
"Missing hit-particles map input collection");
41 throw std::invalid_argument(
"Missing input particles collection");
44 throw std::invalid_argument(
"Missing output filename");
56 throw std::invalid_argument(
"Could not open '" +
path +
"'");
64 m_effPlotTool.clear(m_effPlotCache);
65 m_duplicationPlotTool.clear(m_duplicationPlotCache);
66 if (m_outputFile !=
nullptr) {
67 m_outputFile->Close();
72 float eff = float(m_nTotalMatchedParticles) / m_nTotalParticles;
73 float fakeRate = float(m_nTotalSeeds - m_nTotalMatchedSeeds) / m_nTotalSeeds;
74 float duplicationRate =
75 float(m_nTotalDuplicatedParticles) / m_nTotalMatchedParticles;
76 float aveNDuplicatedSeeds =
77 float(m_nTotalMatchedSeeds - m_nTotalMatchedParticles) /
78 m_nTotalMatchedParticles;
79 float totalSeedPurity = float(m_nTotalMatchedSeeds) / m_nTotalSeeds;
81 ACTS_DEBUG(
"nTotalMatchedSeeds = " << m_nTotalMatchedSeeds);
82 ACTS_DEBUG(
"nTotalParticles = " << m_nTotalParticles);
83 ACTS_DEBUG(
"nTotalMatchedParticles = " << m_nTotalMatchedParticles);
84 ACTS_DEBUG(
"nTotalDuplicatedParticles = " << m_nTotalDuplicatedParticles);
86 ACTS_INFO(
"Efficiency (nMatchedParticles / nAllParticles) = " << eff);
87 ACTS_INFO(
"Fake rate (nUnMatchedSeeds / nAllSeeds) = " << fakeRate);
88 ACTS_INFO(
"Total seed purity (nTotalMatchedSeeds / m_nTotalSeeds) = "
91 "Duplication rate (nDuplicatedMatchedParticles / nMatchedParticles) = "
94 "Average number of duplicated seeds ((nMatchedSeeds - nMatchedParticles) "
95 "/ nMatchedParticles) = "
96 << aveNDuplicatedSeeds);
98 if (m_outputFile !=
nullptr) {
100 m_effPlotTool.write(m_effPlotCache);
101 m_duplicationPlotTool.write(m_duplicationPlotCache);
102 ACTS_INFO(
"Wrote performance plots to '" << m_outputFile->GetPath() <<
"'");
110 const auto&
particles = m_inputParticles(ctx);
111 const auto& hitParticlesMap = m_inputMeasurementParticlesMap(ctx);
113 size_t nSeeds = seeds.size();
114 size_t nMatchedSeeds = 0;
116 std::unordered_map<ActsFatras::Barcode, std::size_t> truthCount;
118 for (
size_t itrack = 0; itrack < seeds.size(); ++itrack) {
119 const auto&
seed = seeds[itrack];
121 std::vector<ParticleHitCount> particleHitCounts;
124 if (particleHitCounts.size() == 1) {
125 auto prt = particleHitCounts.at(0);
126 auto it = truthCount.try_emplace(prt.particleId, 0
u).first;
132 int nMatchedParticles = 0;
133 int nDuplicatedParticles = 0;
136 const auto it1 = truthCount.find(
particle.particleId());
137 bool isMatched =
false;
138 int nMatchedSeedsForParticle = 0;
139 if (it1 != truthCount.end()) {
142 nMatchedSeedsForParticle = it1->second;
143 if (nMatchedSeedsForParticle > 1) {
144 nDuplicatedParticles++;
147 m_effPlotTool.fill(m_effPlotCache,
particle, isMatched);
148 m_duplicationPlotTool.fill(m_duplicationPlotCache,
particle,
149 nMatchedSeedsForParticle - 1);
152 m_nTotalSeeds += nSeeds;
153 m_nTotalMatchedSeeds += nMatchedSeeds;
154 m_nTotalParticles += particles.size();
155 m_nTotalMatchedParticles += nMatchedParticles;
156 m_nTotalDuplicatedParticles += nDuplicatedParticles;