Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackParameterSelector.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackParameterSelector.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
14 
15 #include <cmath>
16 #include <cstdint>
17 #include <ostream>
18 #include <stdexcept>
19 #include <utility>
20 #include <vector>
21 
24  : IAlgorithm("TrackParameterSelector", level), m_cfg(config) {
25  if (m_cfg.inputTrackParameters.empty()) {
26  throw std::invalid_argument("Missing input track parameters");
27  }
28  if (m_cfg.outputTrackParameters.empty()) {
29  throw std::invalid_argument("Missing output track parameters");
30  }
31 
34 }
35 
37  const ActsExamples::AlgorithmContext& ctx) const {
38  // helper functions to select tracks
39  auto within = [](double x, double min, double max) {
40  return (min <= x) and (x < max);
41  };
42  auto isValidTrack = [&](const auto& trk) {
43  const auto theta = trk.template get<Acts::eBoundTheta>();
44  const auto eta = -std::log(std::tan(theta / 2));
45  // define charge selection
46  return within(trk.transverseMomentum(), m_cfg.ptMin, m_cfg.ptMax) and
47  within(std::abs(eta), m_cfg.absEtaMin, m_cfg.absEtaMax) and
48  within(eta, m_cfg.etaMin, m_cfg.etaMax) and
49  within(trk.template get<Acts::eBoundPhi>(), m_cfg.phiMin,
50  m_cfg.phiMax) and
51  within(trk.template get<Acts::eBoundLoc0>(), m_cfg.loc0Min,
52  m_cfg.loc0Max) and
53  within(trk.template get<Acts::eBoundLoc1>(), m_cfg.loc1Min,
54  m_cfg.loc1Max) and
55  within(trk.template get<Acts::eBoundTime>(), m_cfg.timeMin,
56  m_cfg.timeMax);
57  };
58 
59  const auto& inputTrackParameters = m_inputTrackParameters(ctx);
60  TrackParametersContainer outputTrackParameters;
61  outputTrackParameters.reserve(inputTrackParameters.size());
62 
63  // copy selected tracks and record initial track index
64  for (uint32_t i = 0; i < inputTrackParameters.size(); ++i) {
65  const auto& trk = inputTrackParameters[i];
66  if (isValidTrack(trk)) {
67  outputTrackParameters.push_back(trk);
68  }
69  }
70  outputTrackParameters.shrink_to_fit();
71 
72  ACTS_DEBUG("event " << ctx.eventNumber << " selected "
73  << outputTrackParameters.size() << " from "
74  << inputTrackParameters.size()
75  << " tracks in track parameters");
76 
77  m_outputTrackParameters(ctx, std::move(outputTrackParameters));
78 
79  return ProcessCode::SUCCESS;
80 }