Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TruthSeedSelector.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TruthSeedSelector.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 
18 
19 #include <functional>
20 #include <stdexcept>
21 #include <utility>
22 
23 namespace ActsExamples {
24 struct AlgorithmContext;
25 } // namespace ActsExamples
26 
27 using namespace ActsExamples;
28 
31  : IAlgorithm("TruthSeedSelector", 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.outputParticles.empty()) {
39  throw std::invalid_argument("Missing output truth particles collection");
40  }
41 
45 }
46 
48  // prepare input collections
49  const auto& inputParticles = 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
56  SimParticleContainer selectedParticles;
57  selectedParticles.reserve(inputParticles.size());
58 
59  auto within = [](double x, double min, double max) {
60  return (min <= x) and (x < max);
61  };
62  auto isValidparticle = [&](const auto& p) {
63  const auto eta = Acts::VectorHelpers::eta(p.direction());
64  const auto phi = Acts::VectorHelpers::phi(p.direction());
65  const auto rho = Acts::VectorHelpers::perp(p.position());
66  // find the corresponding hits for this particle
67  const auto& hits = makeRange(particleHitsMap.equal_range(p.particleId()));
68  // number of recorded hits
69  size_t nHits = hits.size();
70  return within(rho, 0., m_cfg.rhoMax) and
71  within(p.position().z(), m_cfg.zMin, m_cfg.zMax) and
72  within(std::abs(eta), m_cfg.absEtaMin, m_cfg.absEtaMax) and
73  within(eta, m_cfg.etaMin, m_cfg.etaMax) and
74  within(phi, m_cfg.phiMin, m_cfg.phiMax) and
75  within(p.transverseMomentum(), m_cfg.ptMin, m_cfg.ptMax) and
76  within(nHits, m_cfg.nHitsMin, m_cfg.nHitsMax) and
77  (m_cfg.keepNeutral or (p.charge() != 0));
78  };
79 
80  // create prototracks for all input particles
81  for (const auto& particle : inputParticles) {
82  if (isValidparticle(particle)) {
83  selectedParticles.insert(particle);
84  }
85  }
86 
87  m_outputParticles(ctx, std::move(selectedParticles));
88  return ProcessCode::SUCCESS;
89 }