Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackModifier.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackModifier.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 <cstdint>
19 #include <stdexcept>
20 #include <utility>
21 #include <vector>
22 
23 namespace ActsExamples {
24 struct AlgorithmContext;
25 } // namespace ActsExamples
26 
29  : IAlgorithm("TrackModifier", level), m_cfg(config) {
30  if (m_cfg.inputTrajectories.empty() == m_cfg.inputTrackParameters.empty()) {
31  throw std::invalid_argument(
32  "Exactly one of trajectories or track parameters input must be set");
33  }
34  if (m_cfg.outputTrajectories.empty() == m_cfg.outputTrackParameters.empty()) {
35  throw std::invalid_argument(
36  "Exactly one of trajectories or track parameters output must be set");
37  }
38  if (m_cfg.inputTrajectories.empty() != m_cfg.outputTrajectories.empty()) {
39  throw std::invalid_argument(
40  "Input and output for trajectories and track parameters have to be "
41  "used consistently");
42  }
43 
48 }
49 
51  const ActsExamples::AlgorithmContext& ctx) const {
52  auto modifyTrack = [this](auto trk) {
53  {
54  auto& params = trk.parameters();
55 
56  if (m_cfg.killTime) {
57  params[Acts::eBoundTime] = 0;
58  }
59  }
60 
61  {
62  auto& optCov = trk.covariance();
63 
64  if (optCov) {
65  auto& cov = *optCov;
66 
67  if (m_cfg.dropCovariance) {
68  cov = Acts::BoundSquareMatrix(cov.diagonal().asDiagonal());
69  }
70  if (m_cfg.covScale != 1) {
71  cov *= m_cfg.covScale;
72  }
73  if (m_cfg.killTime) {
74  cov.row(Acts::eBoundTime).setZero();
75  cov.col(Acts::eBoundTime).setZero();
77  }
78  }
79  }
80 
81  return trk;
82  };
83 
84  if (!m_cfg.inputTrackParameters.empty()) {
85  const auto& inputTrackParameters = m_inputTrackParameters(ctx);
86  TrackParametersContainer outputTrackParameters;
87  outputTrackParameters.reserve(inputTrackParameters.size());
88 
89  for (uint32_t i = 0; i < inputTrackParameters.size(); ++i) {
90  const auto& trk = inputTrackParameters[i];
91  outputTrackParameters.push_back(modifyTrack(trk));
92  }
93 
94  m_outputTrackParameters(ctx, std::move(outputTrackParameters));
95  } else if (!m_cfg.inputTrajectories.empty()) {
96  const auto& inputTrajectories = m_inputTrajectories(ctx);
98  outputTrajectories.reserve(inputTrajectories.size());
99 
100  for (const auto& trajectories : inputTrajectories) {
101  std::vector<Acts::MultiTrajectoryTraits::IndexType> tips;
102  tips.reserve(trajectories.tips().size());
104 
105  for (auto tip : trajectories.tips()) {
106  if (!trajectories.hasTrackParameters(tip)) {
107  continue;
108  }
109  const auto& trk = trajectories.trackParameters(tip);
110  tips.push_back(tip);
111  parameters.emplace(tip, modifyTrack(trk));
112  }
113 
114  outputTrajectories.emplace_back(trajectories.multiTrajectory(), tips,
115  parameters);
116  }
117 
118  m_outputTrajectories(ctx, std::move(outputTrajectories));
119  }
120 
121  return ProcessCode::SUCCESS;
122 }