EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Propagator.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Propagator.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2019 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 
11 // clang-format off
12 // Workaround for building on clang+libstdc++. Must be the first include.
14 // clang-format on
15 
28 #include "Acts/Utilities/Units.hpp"
29 
30 #include <cmath>
31 #include <functional>
32 #include <memory>
33 #include <type_traits>
34 
35 #include <boost/algorithm/string.hpp>
36 
37 namespace Acts {
38 
44 template <typename parameters_t, typename... result_list>
45 struct PropagatorResult : private detail::Extendable<result_list...> {
47  using detail::Extendable<result_list...>::get;
48 
50  std::unique_ptr<const parameters_t> endParameters = nullptr;
51 
53  std::unique_ptr<const BoundMatrix> transportJacobian = nullptr;
54 
56  unsigned int steps = 0;
57 
59  double pathLength = 0.;
60 };
61 
67 
69  int absPdgCode = 211;
70 
72  double mass = 139.57018 * UnitConstants::MeV;
73 
75  unsigned int maxSteps = 1000;
76 
78  unsigned int maxRungeKuttaStepTrials = 10000;
79 
82 
85 
88 
90  bool loopProtection = true;
91  double loopFraction = 0.5;
92 
93  // Configurations for Stepper
95  double tolerance = 1e-4;
96 
98  double stepSizeCutOff = 0.;
99 };
100 
109 template <typename action_list_t = ActionList<>,
110  typename aborter_list_t = AbortList<>>
112  using action_list_type = action_list_t;
113  using aborter_list_type = aborter_list_t;
114 
116  PropagatorOptions() = delete;
117 
121 
123  PropagatorOptions(std::reference_wrapper<const GeometryContext> gctx,
124  std::reference_wrapper<const MagneticFieldContext> mctx,
125  LoggerWrapper logger_)
126  : geoContext(gctx), magFieldContext(mctx), logger(logger_) {}
127 
133  template <typename extended_aborter_list_t>
135  extended_aborter_list_t aborters) const {
138  // Copy the options over
139  eoptions.direction = direction;
140  eoptions.absPdgCode = absPdgCode;
141  eoptions.mass = mass;
142  eoptions.maxSteps = maxSteps;
145  eoptions.targetTolerance = targetTolerance;
146  eoptions.pathLimit = direction * std::abs(pathLimit);
147  eoptions.loopProtection = loopProtection;
148  eoptions.loopFraction = loopFraction;
149 
150  // Stepper options
151  eoptions.tolerance = tolerance;
152  eoptions.stepSizeCutOff = stepSizeCutOff;
153  // Action / abort list
154  eoptions.actionList = std::move(actionList);
155  eoptions.abortList = std::move(aborters);
156  // And return the options
157  return eoptions;
158  }
159 
163  void setPlainOptions(const PropagatorPlainOptions& pOptions) {
164  // Copy the options over
165  direction = pOptions.direction;
166  absPdgCode = pOptions.absPdgCode;
167  mass = pOptions.mass;
168  maxSteps = pOptions.maxSteps;
171  targetTolerance = pOptions.targetTolerance;
172  pathLimit = direction * std::abs(pOptions.pathLimit);
173  loopProtection = pOptions.loopProtection;
174  loopFraction = pOptions.loopFraction;
175  tolerance = pOptions.tolerance;
176  stepSizeCutOff = pOptions.stepSizeCutOff;
177  }
178 
180  action_list_t actionList;
181 
183  aborter_list_t abortList;
184 
186  std::reference_wrapper<const GeometryContext> geoContext;
187 
189  std::reference_wrapper<const MagneticFieldContext> magFieldContext;
190 
192 };
193 
219 template <typename stepper_t, typename navigator_t = detail::VoidNavigator>
220 class Propagator final {
222  using BoundState = std::tuple<BoundTrackParameters, Jacobian, double>;
223  using CurvilinearState =
224  std::tuple<CurvilinearTrackParameters, Jacobian, double>;
225 
226  static_assert(StepperStateConcept<typename stepper_t::State>,
227  "Stepper does not fulfill stepper concept.");
228  static_assert(StepperConcept<stepper_t>,
229  "Stepper does not fulfill stepper concept.");
230 
231  public:
233  using Stepper = stepper_t;
234 
236  using Navigator = navigator_t;
237 
239  using StepperState = typename Stepper::State;
240 
242  using NavigatorState = typename navigator_t::State;
243 
248  explicit Propagator(stepper_t stepper, navigator_t navigator = navigator_t())
249  : m_stepper(std::move(stepper)), m_navigator(std::move(navigator)) {}
250 
258  template <typename propagator_options_t>
259  struct State {
267  template <typename parameters_t>
268  State(const parameters_t& start, const propagator_options_t& topts)
269  : options(topts),
270  stepping(topts.geoContext, topts.magFieldContext, start,
271  topts.direction, topts.maxStepSize, topts.tolerance),
272  geoContext(topts.geoContext) {
273  // Setting the start surface
274  navigation.startSurface = &start.referenceSurface();
275  }
276 
278  propagator_options_t options;
279 
282 
285 
287  std::reference_wrapper<const GeometryContext> geoContext;
288  };
289 
290  private:
300  template <typename parameters_t, typename action_list_t>
307  template <typename... args>
308  using this_result_type = PropagatorResult<parameters_t, args...>;
309 
311  using type = typename action_list_t::template result_type<this_result_type>;
312  };
313 
320  template <typename parameters_t, typename action_list_t>
321  using action_list_t_result_t =
322  typename result_type_helper<parameters_t, action_list_t>::type;
323 
341  template <typename result_t, typename propagator_state_t>
342  Result<result_t> propagate_impl(propagator_state_t& state) const;
343 
344  public:
363  template <typename parameters_t, typename propagator_options_t,
364  typename path_aborter_t = PathLimitReached>
365  Result<
367  typename propagator_options_t::action_list_type>>
368  propagate(const parameters_t& start,
369  const propagator_options_t& options) const;
370 
390  template <typename parameters_t, typename propagator_options_t,
391  typename target_aborter_t = SurfaceReached,
392  typename path_aborter_t = PathLimitReached>
394  BoundTrackParameters, typename propagator_options_t::action_list_type>>
395  propagate(const parameters_t& start, const Surface& target,
396  const propagator_options_t& options) const;
397 
398  private:
400  stepper_t m_stepper;
401 
403  navigator_t m_navigator;
404 };
405 
406 } // namespace Acts
407