forked from sPHENIX-Collaboration/acts
/
ProtoTrackClassification.cpp
46 lines (40 loc) · 1.69 KB
/
ProtoTrackClassification.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// This file is part of the Acts project.
//
// Copyright (C) 2019 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "ActsExamples/Validation/ProtoTrackClassification.hpp"
#include "ActsExamples/Utilities/Range.hpp"
#include <algorithm>
void ActsExamples::identifyContributingParticles(
const IndexMultimap<ActsFatras::Barcode>& hitParticlesMap,
const ProtoTrack& protoTrack,
std::vector<ActsExamples::ParticleHitCount>& particleHitCount) {
particleHitCount.clear();
for (auto hitIndex : protoTrack) {
// find all particles that generate this hit
for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
auto particleId = hitParticle.second;
// search for existing particle in the existing hit counts
auto isSameParticle = [=](const ParticleHitCount& phc) {
return (phc.particleId == particleId);
};
auto it = std::find_if(particleHitCount.begin(), particleHitCount.end(),
isSameParticle);
// either increase count if we saw the particle before or add it
if (it != particleHitCount.end()) {
it->hitCount += 1;
} else {
particleHitCount.push_back({particleId, 1u});
}
}
}
// sort by hit count, i.e. majority particle first
auto compareHitCount = [](const ParticleHitCount& lhs,
const ParticleHitCount& rhs) {
return lhs.hitCount > rhs.hitCount;
};
std::sort(particleHitCount.begin(), particleHitCount.end(), compareHitCount);
}