Analysis Software
Documentation for sPHENIX simulation 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 
17 
18 #include <algorithm>
19 #include <ostream>
20 #include <stdexcept>
21 #include <utility>
22 
23 namespace ActsExamples {
24 struct AlgorithmContext;
25 } // namespace ActsExamples
26 
27 using namespace ActsExamples;
28 
31  : IAlgorithm("TruthTrackFinder", level), m_cfg(config) {
32  if (m_cfg.inputParticles.empty()) {
33  throw std::invalid_argument("Missing input truth particles collection");
34  }
35  if (m_cfg.inputMeasurementParticlesMap.empty()) {
36  throw std::invalid_argument("Missing input hit-particles map collection");
37  }
38  if (m_cfg.outputProtoTracks.empty()) {
39  throw std::invalid_argument("Missing output proto tracks collection");
40  }
41 
45 }
46 
48  // prepare input collections
49  const auto& particles = m_inputParticles(ctx);
50  const auto& hitParticlesMap = m_inputMeasurementParticlesMap(ctx);
51  // compute particle_id -> {hit_id...} map from the
52  // hit_id -> {particle_id...} map on the fly.
53  const auto& particleHitsMap = invertIndexMultimap(hitParticlesMap);
54 
55  // prepare output collection
57  tracks.reserve(particles.size());
58 
59  ACTS_VERBOSE("Create prototracks for " << particles.size() << " particles");
60  for (const auto& particle : particles) {
61  // find the corresponding hits for this particle
62  const auto& hits =
63  makeRange(particleHitsMap.equal_range(particle.particleId()));
64  ACTS_VERBOSE(" - Prototrack from " << hits.size() << " hits");
65  // fill hit indices to create the proto track
66  ProtoTrack track;
67  track.reserve(hits.size());
68  for (const auto& hit : hits) {
69  track.emplace_back(hit.second);
70  }
71  // add proto track to the output collection
72  tracks.emplace_back(std::move(track));
73  }
74 
75  m_outputProtoTracks(ctx, std::move(tracks));
76  return ProcessCode::SUCCESS;
77 }