Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackFindingAlgorithm.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackFindingAlgorithm.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 
9 #pragma once
10 
31 
32 #include <atomic>
33 #include <cstddef>
34 #include <functional>
35 #include <limits>
36 #include <memory>
37 #include <string>
38 #include <vector>
39 
40 #include <tbb/combinable.h>
41 
42 namespace Acts {
43 class MagneticFieldProvider;
44 class TrackingGeometry;
45 } // namespace Acts
46 
47 namespace ActsExamples {
48 struct AlgorithmContext;
49 
50 class TrackFindingAlgorithm final : public IAlgorithm {
51  public:
54  using TrackFinderOptions =
57  using TrackFinderResult =
59 
64  public:
65  virtual ~TrackFinderFunction() = default;
67  const TrackFinderOptions&,
68  TrackContainer&) const = 0;
69  };
70 
75  static std::shared_ptr<TrackFinderFunction> makeTrackFinderFunction(
76  std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
77  std::shared_ptr<const Acts::MagneticFieldProvider> magneticField,
78  const Acts::Logger& logger);
79 
80  struct Config {
89 
91  std::shared_ptr<TrackFinderFunction> findTracks;
95  bool computeSharedHits = false;
97  std::optional<Acts::TrackSelector::Config> trackSelectorCfg = std::nullopt;
99  bool backward = false;
101  unsigned int maxSteps = 100000;
102  };
103 
109 
115  const ActsExamples::AlgorithmContext& ctx) const final;
116 
118  const Config& config() const { return m_cfg; }
119 
120  private:
121  template <typename source_link_accessor_container_t>
122  void computeSharedHits(const source_link_accessor_container_t& sourcelinks,
123  TrackContainer& tracks) const;
124 
126 
127  private:
129  std::optional<Acts::TrackSelector> m_trackSelector;
130 
132  "InputMeasurements"};
134  this, "InputSourceLinks"};
135 
137  this, "InputInitialTrackParameters"};
138 
140 
141  mutable std::atomic<size_t> m_nTotalSeeds{0};
142  mutable std::atomic<size_t> m_nFailedSeeds{0};
143 
144  mutable tbb::combinable<Acts::VectorMultiTrajectory::Statistics>
146  auto mtj = std::make_shared<Acts::VectorMultiTrajectory>();
147  return mtj->statistics();
148  }};
149 };
150 
151 // TODO this is somewhat duplicated in AmbiguityResolutionAlgorithm.cpp
152 // TODO we should make a common implementation in the core at some point
153 template <typename source_link_accessor_container_t>
155  const source_link_accessor_container_t& sourceLinks,
156  TrackContainer& tracks) const {
157  // Compute shared hits from all the reconstructed tracks
158  // Compute nSharedhits and Update ckf results
159  // hit index -> list of multi traj indexes [traj, meas]
160 
161  std::vector<std::size_t> firstTrackOnTheHit(
162  sourceLinks.size(), std::numeric_limits<std::size_t>::max());
163  std::vector<std::size_t> firstStateOnTheHit(
164  sourceLinks.size(), std::numeric_limits<std::size_t>::max());
165 
166  for (auto track : tracks) {
167  for (auto state : track.trackStatesReversed()) {
168  if (not state.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
169  continue;
170  }
171 
172  std::size_t hitIndex = state.getUncalibratedSourceLink()
173  .template get<IndexSourceLink>()
174  .index();
175 
176  // Check if hit not already used
177  if (firstTrackOnTheHit.at(hitIndex) ==
178  std::numeric_limits<std::size_t>::max()) {
179  firstTrackOnTheHit.at(hitIndex) = track.index();
180  firstStateOnTheHit.at(hitIndex) = state.index();
181  continue;
182  }
183 
184  // if already used, control if first track state has been marked
185  // as shared
186  int indexFirstTrack = firstTrackOnTheHit.at(hitIndex);
187  int indexFirstState = firstStateOnTheHit.at(hitIndex);
188 
189  auto firstState = tracks.getTrack(indexFirstTrack)
190  .container()
191  .trackStateContainer()
192  .getTrackState(indexFirstState);
193  if (not firstState.typeFlags().test(
195  firstState.typeFlags().set(Acts::TrackStateFlag::SharedHitFlag);
196  }
197 
198  // Decorate this track state
200  }
201  }
202 }
203 
204 } // namespace ActsExamples