EIC 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 
16 
17 #include <algorithm>
18 #include <stdexcept>
19 #include <vector>
20 
21 using namespace ActsExamples;
22 
25  : BareAlgorithm("TruthSeedSelector", lvl), m_cfg(cfg) {
26  if (m_cfg.inputParticles.empty()) {
27  throw std::invalid_argument("Missing input truth particles collection");
28  }
29  if (m_cfg.inputHitParticlesMap.empty()) {
30  throw std::invalid_argument("Missing input hit-particles map collection");
31  }
32  if (m_cfg.outputParticles.empty()) {
33  throw std::invalid_argument("Missing output truth particles collection");
34  }
35 }
36 
38  using HitParticlesMap = IndexMultimap<ActsFatras::Barcode>;
39 
40  // prepare input collections
41  const auto& inputParticles =
43  const auto& hitParticlesMap =
44  ctx.eventStore.get<HitParticlesMap>(m_cfg.inputHitParticlesMap);
45  // compute particle_id -> {hit_id...} map from the
46  // hit_id -> {particle_id...} map on the fly.
47  const auto& particleHitsMap = invertIndexMultimap(hitParticlesMap);
48 
49  // prepare output collection
50  SimParticleContainer selectedParticles;
51  selectedParticles.reserve(inputParticles.size());
52 
53  auto within = [](double x, double min, double max) {
54  return (min <= x) and (x < max);
55  };
56  auto isValidparticle = [&](const auto& p) {
57  const auto eta = Acts::VectorHelpers::eta(p.unitDirection());
58  const auto phi = Acts::VectorHelpers::phi(p.unitDirection());
59  const auto rho = Acts::VectorHelpers::perp(p.position());
60  // find the corresponding hits for this particle
61  const auto& hits = makeRange(particleHitsMap.equal_range(p.particleId()));
62  // number of recorded hits
63  size_t nHits = hits.size();
64  return within(rho, 0., m_cfg.rhoMax) and
65  within(std::abs(p.position().z()), 0., m_cfg.absZMax) and
66  within(std::abs(eta), m_cfg.absEtaMin, m_cfg.absEtaMax) and
67  within(eta, m_cfg.etaMin, m_cfg.etaMax) and
68  within(phi, m_cfg.phiMin, m_cfg.phiMax) and
69  within(p.transverseMomentum(), m_cfg.ptMin, m_cfg.ptMax) and
70  within(nHits, m_cfg.nHitsMin, m_cfg.nHitsMax) and
71  (m_cfg.keepNeutral or (p.charge() != 0));
72  };
73 
74  // create prototracks for all input particles
75  for (const auto& particle : inputParticles) {
76  if (isValidparticle(particle)) {
77  selectedParticles.insert(particle);
78  }
79  }
80 
81  ctx.eventStore.add(m_cfg.outputParticles, std::move(selectedParticles));
82  return ProcessCode::SUCCESS;
83 }