ECCE @ 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 // Workaround for building on clang+libstdc++
13 
14 #include <cmath>
15 #include <functional>
16 #include <memory>
17 #include <type_traits>
18 
19 #include <boost/algorithm/string.hpp>
20 
32 #include "Acts/Utilities/Units.hpp"
33 
34 namespace Acts {
35 
41 template <typename parameters_t, typename... result_list>
42 struct PropagatorResult : private detail::Extendable<result_list...> {
44  using detail::Extendable<result_list...>::get;
45 
47  std::unique_ptr<const parameters_t> endParameters = nullptr;
48 
50  std::unique_ptr<const BoundMatrix> transportJacobian = nullptr;
51 
53  unsigned int steps = 0;
54 
56  double pathLength = 0.;
57 };
58 
67 template <typename action_list_t = ActionList<>,
68  typename aborter_list_t = AbortList<>>
70  using action_list_type = action_list_t;
71  using aborter_list_type = aborter_list_t;
72 
74  PropagatorOptions() = delete;
75 
79 
81  PropagatorOptions(std::reference_wrapper<const GeometryContext> gctx,
82  std::reference_wrapper<const MagneticFieldContext> mctx)
83  : geoContext(gctx), magFieldContext(mctx) {}
84 
90  template <typename extended_aborter_list_t>
92  extended_aborter_list_t aborters) const {
95  // Copy the options over
96  eoptions.direction = direction;
97  eoptions.absPdgCode = absPdgCode;
98  eoptions.mass = mass;
99  eoptions.maxSteps = maxSteps;
102  eoptions.targetTolerance = targetTolerance;
103  eoptions.pathLimit = direction * std::abs(pathLimit);
104  eoptions.loopProtection = loopProtection;
105  eoptions.loopFraction = loopFraction;
106  // Output option
107  eoptions.debug = debug;
108  eoptions.debugString = debugString;
109  eoptions.debugPfxWidth = debugPfxWidth;
110  eoptions.debugMsgWidth = debugMsgWidth;
111  // Stepper options
112  eoptions.tolerance = tolerance;
113  eoptions.stepSizeCutOff = stepSizeCutOff;
114  // Action / abort list
115  eoptions.actionList = std::move(actionList);
116  eoptions.abortList = std::move(aborters);
117  // And return the options
118  return eoptions;
119  }
120 
123 
125  int absPdgCode = 211;
126 
128  double mass = 139.57018 * UnitConstants::MeV;
129 
131  unsigned int maxSteps = 1000;
132 
134  unsigned int maxRungeKuttaStepTrials = 10000;
135 
138 
141 
144 
146  bool loopProtection = true;
147  double loopFraction = 0.5;
148 
150  // -> @todo: move to a debug struct
151  // - the string where debug messages are stored (optionally)
152  // - it also has some formatting options
153  bool debug = false;
154  std::string debugString = "";
155  size_t debugPfxWidth = 30;
156  size_t debugMsgWidth = 50;
157 
158  // Configurations for Stepper
160  double tolerance = 1e-4;
161 
163  double stepSizeCutOff = 0.;
164 
166  action_list_t actionList;
167 
169  aborter_list_t abortList;
170 
172  std::reference_wrapper<const GeometryContext> geoContext;
173 
175  std::reference_wrapper<const MagneticFieldContext> magFieldContext;
176 };
177 
203 template <typename stepper_t, typename navigator_t = detail::VoidNavigator>
204 class Propagator final {
206  using BoundState = std::tuple<BoundParameters, Jacobian, double>;
207  using CurvilinearState = std::tuple<CurvilinearParameters, Jacobian, double>;
208 
209  static_assert(StepperStateConcept<typename stepper_t::State>,
210  "Stepper does not fulfill stepper concept.");
211  static_assert(StepperConcept<stepper_t>,
212  "Stepper does not fulfill stepper concept.");
213 
214  public:
216  using Stepper = stepper_t;
217 
219  using Navigator = navigator_t;
220 
222  using StepperState = typename Stepper::State;
223 
226 
231  explicit Propagator(stepper_t stepper, navigator_t navigator = navigator_t())
232  : m_stepper(std::move(stepper)), m_navigator(std::move(navigator)) {}
233 
241  template <typename propagator_options_t>
242  struct State {
250  template <typename parameters_t>
251  State(const parameters_t& start, const propagator_options_t& topts)
252  : options(topts),
253  stepping(topts.geoContext, topts.magFieldContext, start,
254  topts.direction, topts.maxStepSize, topts.tolerance),
255  geoContext(topts.geoContext) {
256  // Setting the start surface
257  navigation.startSurface = &start.referenceSurface();
258  }
259 
261  propagator_options_t options;
262 
265 
268 
270  std::reference_wrapper<const GeometryContext> geoContext;
271  };
272 
273  private:
283  template <typename parameters_t, typename action_list_t>
290  template <typename... args>
291  using this_result_type = PropagatorResult<parameters_t, args...>;
292 
294  using type = typename action_list_t::template result_type<this_result_type>;
295  };
296 
303  template <typename parameters_t, typename action_list_t>
304  using action_list_t_result_t =
305  typename result_type_helper<parameters_t, action_list_t>::type;
306 
324  template <typename result_t, typename propagator_state_t>
325  Result<result_t> propagate_impl(propagator_state_t& state) const;
326 
327  public:
346  template <typename parameters_t, typename propagator_options_t,
347  typename path_aborter_t = PathLimitReached>
349  CurvilinearParameters, typename propagator_options_t::action_list_type>>
350  propagate(const parameters_t& start,
351  const propagator_options_t& options) const;
352 
372  template <typename parameters_t, typename propagator_options_t,
373  typename target_aborter_t = SurfaceReached,
374  typename path_aborter_t = PathLimitReached>
376  BoundParameters, typename propagator_options_t::action_list_type>>
377  propagate(const parameters_t& start, const Surface& target,
378  const propagator_options_t& options) const;
379 
380  private:
382  stepper_t m_stepper;
383 
385  navigator_t m_navigator;
386 
397  template <typename propagator_state_t>
398  void debugLog(propagator_state_t& state,
399  const std::function<std::string()>& logAction) const;
400 };
401 
402 } // namespace Acts
403