Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TracksToTrajectories.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TracksToTrajectories.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 
19 
20 #include <optional>
21 #include <utility>
22 #include <vector>
23 
24 namespace ActsExamples {
25 struct AlgorithmContext;
26 
28  : IAlgorithm("TracksToTrajectories", lvl), m_cfg(std::move(cfg)) {
31 }
32 
34  const auto& tracks = m_inputTracks(ctx);
35 
36  // Prepare the output data with MultiTrajectory
37  TrajectoriesContainer trajectories;
38  trajectories.reserve(tracks.size());
39 
40  static const Acts::ConstTrackAccessor<unsigned int> seedNumber("trackGroup");
41 
42  if (tracks.hasColumn(Acts::hashString("trackGroup"))) {
43  // track group by seed is available, produce grouped trajectories
44  std::optional<unsigned int> lastSeed;
45 
47  std::vector<Acts::MultiTrajectoryTraits::IndexType> tips;
48 
49  for (const auto& track : tracks) {
50  if (!lastSeed) {
51  lastSeed = seedNumber(track);
52  }
53 
54  if (seedNumber(track) != lastSeed.value()) {
55  // make copies and clear vectors
56  trajectories.emplace_back(tracks.trackStateContainer(), tips,
57  parameters);
58  tips.clear();
59  parameters.clear();
60  }
61 
62  lastSeed = seedNumber(track);
63 
64  tips.push_back(track.tipIndex());
65  parameters.emplace(
66  std::pair{track.tipIndex(),
68  track.parameters(), track.covariance(),
69  track.particleHypothesis()}});
70  }
71 
72  if (tips.empty()) {
73  ACTS_DEBUG("Last trajectory is empty");
74  }
75 
76  // last entry: move vectors
77  trajectories.emplace_back(tracks.trackStateContainer(), std::move(tips),
78  std::move(parameters));
79 
80  } else {
81  // no grouping by seed, make one trajectory per track
82 
83  for (const auto& track : tracks) {
84  if (not track.hasReferenceSurface()) {
85  ACTS_WARNING("Unable to convert track with tip "
86  << track.tipIndex()
87  << " because no reference surface is set");
88  continue;
89  }
91  parameters.reserve(1);
92  std::vector<Acts::MultiTrajectoryTraits::IndexType> tips;
93  tips.reserve(1);
94 
95  tips.push_back(track.tipIndex());
96  parameters.emplace(
97  std::pair{track.tipIndex(),
99  track.parameters(), track.covariance(),
100  track.particleHypothesis()}});
101 
102  trajectories.emplace_back(tracks.trackStateContainer(), std::move(tips),
103  std::move(parameters));
104  }
105  }
106 
107  m_outputTrajectories(ctx, std::move(trajectories));
108 
109  return ProcessCode::SUCCESS;
110 }
111 } // namespace ActsExamples