EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProtoTrackClassification.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ProtoTrackClassification.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 
12 
13 #include <algorithm>
14 
16  const IndexMultimap<ActsFatras::Barcode>& hitParticlesMap,
17  const ProtoTrack& protoTrack,
18  std::vector<ActsExamples::ParticleHitCount>& particleHitCount) {
19  particleHitCount.clear();
20 
21  for (auto hitIndex : protoTrack) {
22  // find all particles that generate this hit
23  for (auto hitParticle : makeRange(hitParticlesMap.equal_range(hitIndex))) {
24  auto particleId = hitParticle.second;
25  // search for existing particle in the existing hit counts
26  auto isSameParticle = [=](const ParticleHitCount& phc) {
27  return (phc.particleId == particleId);
28  };
29  auto it = std::find_if(particleHitCount.begin(), particleHitCount.end(),
30  isSameParticle);
31  // either increase count if we saw the particle before or add it
32  if (it != particleHitCount.end()) {
33  it->hitCount += 1;
34  } else {
35  particleHitCount.push_back({particleId, 1u});
36  }
37  }
38  }
39 
40  // sort by hit count, i.e. majority particle first
41  auto compareHitCount = [](const ParticleHitCount& lhs,
42  const ParticleHitCount& rhs) {
43  return lhs.hitCount > rhs.hitCount;
44  };
45  std::sort(particleHitCount.begin(), particleHitCount.end(), compareHitCount);
46 }