Analysis Software
Documentation for sPHENIX simulation 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-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 
11 // clang-format off
12 // Workaround for building on clang+libstdc++. Must be the first include.
14 // clang-format on
15 
30 
31 #include <optional>
32 
33 namespace Acts {
34 
40 template <typename parameters_t, typename... result_list>
41 struct PropagatorResult : private detail::Extendable<result_list...> {
43  using detail::Extendable<result_list...>::get;
44 
46  std::optional<parameters_t> endParameters = std::nullopt;
47 
49  std::optional<BoundMatrix> transportJacobian = std::nullopt;
50 
52  unsigned int steps = 0;
53 
55  double pathLength = 0.;
56 };
57 
63 
65  unsigned int maxSteps = 1000;
66 
68  unsigned int maxRungeKuttaStepTrials = 10000;
69 
71  double maxStepSize = std::numeric_limits<double>::max();
72 
74  double pathLimit = std::numeric_limits<double>::max();
75 
78 
80  bool loopProtection = true;
81  double loopFraction = 0.5;
82 
83  // Configurations for Stepper
85  double tolerance = 1e-4;
86 
88  double stepSizeCutOff = 0.;
89 };
90 
99 template <typename action_list_t = ActionList<>,
100  typename aborter_list_t = AbortList<>>
102  using action_list_type = action_list_t;
103  using aborter_list_type = aborter_list_t;
104 
106  PropagatorOptions() = delete;
107 
111 
114  const MagneticFieldContext& mctx)
115  : geoContext(gctx), magFieldContext(mctx) {}
116 
122  template <typename extended_aborter_list_t>
124  extended_aborter_list_t aborters) const {
127  // Copy the options over
128  eoptions.direction = direction;
129  eoptions.maxSteps = maxSteps;
131  eoptions.maxStepSize = maxStepSize;
132  eoptions.targetTolerance = targetTolerance;
133  eoptions.pathLimit = direction * std::abs(pathLimit);
134  eoptions.loopProtection = loopProtection;
135  eoptions.loopFraction = loopFraction;
136 
137  // Stepper options
138  eoptions.tolerance = tolerance;
139  eoptions.stepSizeCutOff = stepSizeCutOff;
140  // Action / abort list
141  eoptions.actionList = std::move(actionList);
142  eoptions.abortList = std::move(aborters);
143  // And return the options
144  return eoptions;
145  }
146 
150  void setPlainOptions(const PropagatorPlainOptions& pOptions) {
151  // Copy the options over
152  direction = pOptions.direction;
153  maxSteps = pOptions.maxSteps;
155  maxStepSize = pOptions.maxStepSize;
156  targetTolerance = pOptions.targetTolerance;
157  pathLimit = direction * std::abs(pOptions.pathLimit);
158  loopProtection = pOptions.loopProtection;
159  loopFraction = pOptions.loopFraction;
160  tolerance = pOptions.tolerance;
161  stepSizeCutOff = pOptions.stepSizeCutOff;
162  }
163 
165  action_list_t actionList;
166 
168  aborter_list_t abortList;
169 
171  std::reference_wrapper<const GeometryContext> geoContext;
172 
174  std::reference_wrapper<const MagneticFieldContext> magFieldContext;
175 };
176 
202 template <typename stepper_t, typename navigator_t = detail::VoidNavigator>
203 class Propagator final {
207  static_assert(
208  Concepts::BoundTrackParametersConcept<StepperBoundTrackParameters>,
209  "Stepper bound track parameters do not fulfill bound "
210  "parameters concept.");
211 
215  static_assert(
216  Concepts::BoundTrackParametersConcept<StepperCurvilinearTrackParameters>,
217  "Stepper bound track parameters do not fulfill bound "
218  "parameters concept.");
219 
221  using BoundState = std::tuple<StepperBoundTrackParameters, Jacobian, double>;
222  using CurvilinearState =
223  std::tuple<StepperCurvilinearTrackParameters, Jacobian, double>;
224 
225  static_assert(StepperStateConcept<typename stepper_t::State>,
226  "Stepper does not fulfill stepper concept.");
227  static_assert(StepperConcept<stepper_t>,
228  "Stepper does not fulfill stepper concept.");
229 
230  public:
232  using Stepper = stepper_t;
233 
235  using Navigator = navigator_t;
236 
238  using StepperState = typename Stepper::State;
239 
241  using NavigatorState = typename navigator_t::State;
242 
248  explicit Propagator(stepper_t stepper, navigator_t navigator = navigator_t(),
249  std::shared_ptr<const Logger> _logger =
250  getDefaultLogger("Propagator", Acts::Logging::INFO))
251  : m_stepper(std::move(stepper)),
252  m_navigator(std::move(navigator)),
253  m_logger{std::move(_logger)} {}
254 
262  template <typename propagator_options_t>
263  struct State {
271  State(const propagator_options_t& topts, StepperState steppingIn,
272  NavigatorState navigationIn)
273  : options(topts),
274  stepping{std::move(steppingIn)},
275  navigation{std::move(navigationIn)},
276  geoContext(topts.geoContext) {}
277 
279  propagator_options_t options;
280 
282  StepperState stepping;
283 
286 
288  std::reference_wrapper<const GeometryContext> geoContext;
289  };
290 
291  private:
301  template <typename parameters_t, typename action_list_t>
308  template <typename... args>
309  using this_result_type = PropagatorResult<parameters_t, args...>;
310 
312  using type = typename action_list_t::template result_type<this_result_type>;
313  };
314 
315  public:
322  template <typename parameters_t, typename action_list_t>
323  using action_list_t_result_t =
325 
326  private:
344  template <typename result_t, typename propagator_state_t>
345  Result<void> propagate_impl(propagator_state_t& state,
346  result_t& result) const;
347 
348  public:
367  template <typename parameters_t, typename propagator_options_t,
368  typename path_aborter_t = PathLimitReached>
369  Result<
371  typename propagator_options_t::action_list_type>>
372  propagate(const parameters_t& start, const propagator_options_t& options,
373  bool makeCurvilinear = true) const;
374 
394  template <typename parameters_t, typename propagator_options_t,
395  typename path_aborter_t = PathLimitReached>
396  Result<
398  typename propagator_options_t::action_list_type>>
399  propagate(
400  const parameters_t& start, const propagator_options_t& options,
401  bool makeCurvilinear,
403  typename propagator_options_t::action_list_type>&&
404  inputResult) const;
405 
424  template <typename parameters_t, typename propagator_options_t,
425  typename target_aborter_t = SurfaceReached,
426  typename path_aborter_t = PathLimitReached>
427  Result<
429  typename propagator_options_t::action_list_type>>
430  propagate(const parameters_t& start, const Surface& target,
431  const propagator_options_t& options) const;
432 
452  template <typename parameters_t, typename propagator_options_t,
453  typename target_aborter_t = SurfaceReached,
454  typename path_aborter_t = PathLimitReached>
455  Result<
457  typename propagator_options_t::action_list_type>>
458  propagate(
459  const parameters_t& start, const Surface& target,
460  const propagator_options_t& options,
462  typename propagator_options_t::action_list_type>
463  inputResult) const;
464 
465  private:
466  const Logger& logger() const { return *m_logger; }
467 
469  stepper_t m_stepper;
470 
472  navigator_t m_navigator;
473 
474  std::shared_ptr<const Logger> m_logger;
475 };
476 
477 } // namespace Acts
478