Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackClassification.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackClassification.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
16 
17 #include <algorithm>
18 #include <utility>
19 
20 namespace {
21 
23 inline void increaseHitCount(
24  std::vector<ActsExamples::ParticleHitCount>& particleHitCounts,
25  ActsFatras::Barcode particleId) {
26  // linear search since there is no ordering
27  auto it = std::find_if(particleHitCounts.begin(), particleHitCounts.end(),
28  [=](const ActsExamples::ParticleHitCount& phc) {
29  return (phc.particleId == particleId);
30  });
31  // either increase count if we saw the particle before or add it
32  if (it != particleHitCounts.end()) {
33  it->hitCount += 1u;
34  } else {
35  particleHitCounts.push_back({particleId, 1u});
36  }
37 }
38 
40 inline void sortHitCount(
41  std::vector<ActsExamples::ParticleHitCount>& particleHitCounts) {
42  std::sort(particleHitCounts.begin(), particleHitCounts.end(),
45  return (lhs.hitCount > rhs.hitCount);
46  });
47 }
48 
49 } // namespace
50 
52  const IndexMultimap<ActsFatras::Barcode>& hitParticlesMap,
53  const ProtoTrack& protoTrack,
54  std::vector<ActsExamples::ParticleHitCount>& particleHitCounts) {
55  particleHitCounts.clear();
56 
57  for (auto hitIndex : protoTrack) {
58  // register all particles that generated this hit
59  for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
60  increaseHitCount(particleHitCounts, hitParticle.second);
61  }
62  }
63  sortHitCount(particleHitCounts);
64 }
65 
67  const IndexMultimap<ActsFatras::Barcode>& hitParticlesMap,
68  const Trajectories& trajectories, size_t tip,
69  std::vector<ParticleHitCount>& particleHitCounts) {
70  particleHitCounts.clear();
71 
72  if (not trajectories.hasTrajectory(tip)) {
73  return;
74  }
75 
76  trajectories.multiTrajectory().visitBackwards(tip, [&](const auto& state) {
77  // no truth info with non-measurement state
78  if (not state.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
79  return true;
80  }
81  // register all particles that generated this hit
82  IndexSourceLink sl =
83  state.getUncalibratedSourceLink().template get<IndexSourceLink>();
84  auto hitIndex = sl.index();
85  for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
86  increaseHitCount(particleHitCounts, hitParticle.second);
87  }
88  return true;
89  });
90  sortHitCount(particleHitCounts);
91 }