Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AdaptiveMultiVertexFitter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AdaptiveMultiVertexFitter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-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 
9 #pragma once
10 
22 
23 #include <functional>
24 
25 namespace Acts {
26 
38 template <typename input_track_t, typename linearizer_t>
40  static_assert(LinearizerConcept<linearizer_t>,
41  "Linearizer does not fulfill linearizer concept.");
42 
43  public:
44  using InputTrack_t = input_track_t;
45  using Propagator_t = typename linearizer_t::Propagator_t;
47 
48  private:
50 
51  public:
53  struct State {
55  const Acts::MagneticFieldContext& magContext)
56  : ipState(field.makeCache(magContext)),
57  linearizerState(field.makeCache(magContext)) {}
58  // Vertex collection to be fitted
59  std::vector<Vertex<InputTrack_t>*> vertexCollection;
60 
61  // Annealing state
63 
64  // IPEstimator state
65  typename IPEstimator::State ipState;
66 
67  // Linearizer state
68  typename Linearizer_t::State linearizerState;
69 
70  // Map to store vertices information
71  std::map<Vertex<InputTrack_t>*, VertexInfo<InputTrack_t>> vtxInfoMap;
72 
73  std::multimap<const InputTrack_t*, Vertex<InputTrack_t>*>
75 
76  std::map<std::pair<const InputTrack_t*, Vertex<InputTrack_t>*>,
79 
81  State() = default;
82 
83  // Adds a vertex to trackToVerticesMultiMap
85  for (auto trk : vtxInfoMap[&vtx].trackLinks) {
86  trackToVerticesMultiMap.emplace(trk, &vtx);
87  }
88  }
89 
90  // Removes a vertex from trackToVerticesMultiMap
92  for (auto iter = trackToVerticesMultiMap.begin();
93  iter != trackToVerticesMultiMap.end();) {
94  if (iter->second == &vtx) {
95  iter = trackToVerticesMultiMap.erase(iter);
96  } else {
97  ++iter;
98  }
99  }
100  }
101  };
102 
103  struct Config {
107  Config(const IPEstimator& est) : ipEst(est) {}
108 
109  // ImpactPointEstimator
111 
122 
123  // Number of max iterations
124  unsigned int maxIterations{30};
125 
126  // Max distance to linearization point allowed
127  // without relinearization
128  double maxDistToLinPoint{0.5};
129 
130  // Minimum track weight needed for track to be considered
131  double minWeight{0.0001};
132 
133  // Max relative shift of vertex during one iteration
134  double maxRelativeShift{0.01};
135 
136  // Do smoothing after multivertex fit
137  bool doSmoothing{false};
138 
139  // Use time information when calculating the vertex compatibility
140  bool useTime{false};
141  };
142 
147  template <
148  typename T = InputTrack_t,
151  std::unique_ptr<const Logger> logger =
152  getDefaultLogger("AdaptiveMultiVertexFitter",
153  Logging::INFO))
154  : m_cfg(std::move(cfg)),
155  m_extractParameters([](T params) { return params; }),
157 
166  Config& cfg, std::function<BoundTrackParameters(InputTrack_t)> func,
167  std::unique_ptr<const Logger> logger =
168  getDefaultLogger("AdaptiveMultiVertexFitter", Logging::INFO))
169  : m_cfg(std::move(cfg)),
170  m_extractParameters(func),
171  m_logger(std::move(logger)) {}
172 
183  State& state, const std::vector<Vertex<InputTrack_t>*>& verticesToFit,
184  const Linearizer_t& linearizer,
185  const VertexingOptions<InputTrack_t>& vertexingOptions) const;
186 
203  State& state, Vertex<InputTrack_t>& newVertex,
204  const Linearizer_t& linearizer,
205  const VertexingOptions<InputTrack_t>& vertexingOptions) const;
206 
207  private:
209  const Config m_cfg;
210 
214  std::function<BoundTrackParameters(InputTrack_t)> m_extractParameters;
215 
217  std::unique_ptr<const Logger> m_logger;
218 
220  const Logger& logger() const { return *m_logger; }
221 
231  State& state, const Linearizer_t& linearizer,
232  const VertexingOptions<InputTrack_t>& vertexingOptions) const;
233 
240  bool isAlreadyInList(
242  const std::vector<Vertex<InputTrack_t>*>& verticesVec) const;
243 
253  State& state, Vertex<InputTrack_t>* vtx,
254  const VertexingOptions<InputTrack_t>& vertexingOptions) const;
255 
263  State& state, Vertex<InputTrack_t>* currentVtx,
264  const VertexingOptions<input_track_t>& vertexingOptions) const;
265 
273  State& state, const Linearizer_t& linearizer,
274  const VertexingOptions<input_track_t>& vertexingOptions) const;
275 
283  std::vector<double> collectTrackToVertexCompatibilities(
284  State& state, const InputTrack_t* trk) const;
285 
292  bool checkSmallShift(State& state) const;
293 
298  void doVertexSmoothing(State& state) const;
299 };
300 
301 } // namespace Acts
302