EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TruthTrackFinder.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TruthTrackFinder.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 
16 
17 #include <algorithm>
18 #include <stdexcept>
19 #include <vector>
20 
21 using namespace ActsExamples;
22 
24  : BareAlgorithm("TruthTrackFinder", lvl), m_cfg(cfg) {
25  if (m_cfg.inputParticles.empty()) {
26  throw std::invalid_argument("Missing input truth particles collection");
27  }
28  if (m_cfg.inputHitParticlesMap.empty()) {
29  throw std::invalid_argument("Missing input hit-particles map collection");
30  }
31  if (m_cfg.outputProtoTracks.empty()) {
32  throw std::invalid_argument("Missing output proto tracks collection");
33  }
34 }
35 
37  using HitParticlesMap = IndexMultimap<ActsFatras::Barcode>;
38 
39  // prepare input collections
40  const auto& particles =
42  const auto& hitParticlesMap =
43  ctx.eventStore.get<HitParticlesMap>(m_cfg.inputHitParticlesMap);
44  // compute particle_id -> {hit_id...} map from the
45  // hit_id -> {particle_id...} map on the fly.
46  const auto& particleHitsMap = invertIndexMultimap(hitParticlesMap);
47 
48  // prepare output collection
49  ProtoTrackContainer tracks;
50  tracks.reserve(particles.size());
51 
52  // create prototracks for all input particles
53  for (const auto& particle : particles) {
54  // find the corresponding hits for this particle
55  const auto& hits =
56  makeRange(particleHitsMap.equal_range(particle.particleId()));
57  // fill hit indices to create the proto track
58  ProtoTrack track;
59  track.reserve(hits.size());
60  for (const auto& hit : hits) {
61  track.emplace_back(hit.second);
62  }
63  // add proto track to the output collection
64  tracks.emplace_back(std::move(track));
65  }
66 
67  ctx.eventStore.add(m_cfg.outputProtoTracks, std::move(tracks));
68  return ProcessCode::SUCCESS;
69 }