Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:24:03

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/EventData/TrackParameters.hpp"
0012 #include "Acts/EventData/TrackParametersConcept.hpp"
0013 #include "Acts/Propagator/ActorList.hpp"
0014 #include "Acts/Propagator/PropagatorOptions.hpp"
0015 #include "Acts/Propagator/PropagatorResult.hpp"
0016 #include "Acts/Propagator/PropagatorState.hpp"
0017 #include "Acts/Propagator/PropagatorTraits.hpp"
0018 #include "Acts/Propagator/StandardAborters.hpp"
0019 #include "Acts/Propagator/StepperConcept.hpp"
0020 #include "Acts/Propagator/VoidNavigator.hpp"
0021 #include "Acts/Propagator/detail/ParameterTraits.hpp"
0022 #include "Acts/Utilities/Logger.hpp"
0023 #include "Acts/Utilities/Result.hpp"
0024 
0025 namespace Acts {
0026 
0027 /// Common simplified base interface for propagators.
0028 ///
0029 /// This class only supports propagation from start bound parameters to a target
0030 /// surface and returns only the end bound parameters.
0031 /// Navigation is performed if the underlying propagator is configured with an
0032 /// appropriate navigator. No custom actors or aborters are supported.
0033 class BasePropagator {
0034  public:
0035   /// Base propagator options
0036   using Options = PropagatorPlainOptions;
0037 
0038   /// Method to propagate start bound track parameters to a target surface.
0039   /// @param start The start bound track parameters.
0040   /// @param target The target surface.
0041   /// @param options The propagation options.
0042   /// @return The end bound track parameters.
0043   virtual Result<BoundTrackParameters> propagateToSurface(
0044       const BoundTrackParameters& start, const Surface& target,
0045       const Options& options) const = 0;
0046 
0047   virtual ~BasePropagator() = default;
0048 };
0049 
0050 namespace detail {
0051 class PropagatorStub {};
0052 
0053 template <typename derived_t>
0054 class BasePropagatorHelper : public BasePropagator {
0055  public:
0056   Result<BoundTrackParameters> propagateToSurface(
0057       const BoundTrackParameters& start, const Surface& target,
0058       const Options& options) const override;
0059 };
0060 }  // namespace detail
0061 
0062 /// @brief Propagator for particles (optionally in a magnetic field)
0063 ///
0064 /// The Propagator works with a state objects given at function call
0065 /// This state object contains the thread local state objects
0066 ///  - Navigator::state_type for object navigation and screen output
0067 ///  - Stepper::state_type state for the actual transport caching
0068 ///  (pos,dir,field)
0069 ///
0070 /// @tparam stepper_t Type of stepper implementation of the propagation
0071 /// @tparam naviagor_t Type of the navigator (optional)
0072 ///
0073 /// This Propagator class serves as high-level steering code for propagating
0074 /// track parameters. The actual implementation of the propagation has to be
0075 /// implemented in the stepper_t object, which has to provide the following:
0076 ///
0077 /// - a function for performing a single propagation step
0078 /// - a type mapping for: initial track parameter type -> type of final track
0079 ///   parameters
0080 /// - a type mapping for: (initial track parameter type and destination
0081 ///   surface type) -> type of final track parameters
0082 /// - a type mapping for: initial track parameter type -> type of internal
0083 ///   state object
0084 /// - a type mapping for: (initial track parameter type and destination
0085 ///   surface type) -> type of internal state object
0086 ///
0087 template <typename stepper_t, typename navigator_t = VoidNavigator>
0088 class Propagator final
0089     : public std::conditional_t<
0090           SupportsBoundParameters_v<stepper_t>,
0091           detail::BasePropagatorHelper<Propagator<stepper_t, navigator_t>>,
0092           detail::PropagatorStub> {
0093   /// Re-define bound track parameters dependent on the stepper
0094   using StepperBoundTrackParameters =
0095       detail::stepper_bound_parameters_type_t<stepper_t>;
0096   static_assert(BoundTrackParametersConcept<StepperBoundTrackParameters>,
0097                 "Stepper bound track parameters do not fulfill bound "
0098                 "parameters concept.");
0099 
0100   using Jacobian = BoundMatrix;
0101   using BoundState = std::tuple<StepperBoundTrackParameters, Jacobian, double>;
0102 
0103   static_assert(StepperStateConcept<typename stepper_t::State>,
0104                 "Stepper does not fulfill stepper concept.");
0105   static_assert(StepperConcept<stepper_t>,
0106                 "Stepper does not fulfill stepper concept.");
0107 
0108  public:
0109   /// Type of the stepper in use for public scope
0110   using Stepper = stepper_t;
0111 
0112   /// Type of the navigator in use for public scope
0113   using Navigator = navigator_t;
0114 
0115   /// Type of state object used by the propagation implementation
0116   using StepperState = typename Stepper::State;
0117 
0118   /// Typedef the navigator state
0119   using NavigatorState = typename navigator_t::State;
0120 
0121   /// Type alias for propagator state combining stepper and navigator states
0122   template <typename propagator_options_t, typename... extension_state_t>
0123   using State = PropagatorState<propagator_options_t, StepperState,
0124                                 NavigatorState, extension_state_t...>;
0125 
0126   /// Type alias for stepper configuration options
0127   using StepperOptions = typename stepper_t::Options;
0128 
0129   /// Type alias for navigator configuration options
0130   using NavigatorOptions = typename navigator_t::Options;
0131 
0132   /// Type alias for propagator configuration options with actor list
0133   template <typename actor_list_t = ActorList<>>
0134   using Options =
0135       PropagatorOptions<StepperOptions, NavigatorOptions, actor_list_t>;
0136 
0137   /// Constructor from implementation object
0138   ///
0139   /// @param stepper The stepper implementation is moved to a private member
0140   /// @param navigator The navigator implementation, moved to a private member
0141   /// @param _logger a logger instance
0142   explicit Propagator(stepper_t stepper, navigator_t navigator = navigator_t(),
0143                       std::shared_ptr<const Logger> _logger =
0144                           getDefaultLogger("Propagator", Acts::Logging::INFO))
0145       : m_stepper(std::move(stepper)),
0146         m_navigator(std::move(navigator)),
0147         m_logger{std::move(_logger)} {}
0148 
0149  private:
0150   /// @brief Helper struct determining the state's type
0151   ///
0152   /// @tparam propagator_options_t Propagator options type
0153   /// @tparam actor_list_t List of propagation action types
0154   ///
0155   /// This helper struct provides type definitions to extract the correct
0156   /// propagation state type from a given TrackParameter type and an
0157   /// ActorList.
0158   ///
0159   template <typename propagator_options_t, typename actor_list_t>
0160   struct state_type_helper {
0161     /// @brief Propagation state type for an arbitrary list of additional
0162     ///        propagation states
0163     ///
0164     /// @tparam args Parameter pack specifying additional propagation states
0165     ///
0166     template <typename... args>
0167     using this_state_type = State<propagator_options_t, args...>;
0168 
0169     /// @brief Propagation result type derived from a given action list
0170     using type = typename actor_list_t::template result_type<this_state_type>;
0171   };
0172 
0173   /// @brief Helper struct determining the result's type
0174   ///
0175   /// @tparam parameters_t Type of final track parameters
0176   /// @tparam actor_list_t List of propagation action types
0177   ///
0178   /// This helper struct provides type definitions to extract the correct
0179   /// propagation result type from a given TrackParameter type and an
0180   /// ActorList.
0181   ///
0182   template <typename parameters_t, typename actor_list_t>
0183   struct result_type_helper {
0184     /// @brief Propagation result type for an arbitrary list of additional
0185     ///        propagation results
0186     ///
0187     /// @tparam args Parameter pack specifying additional propagation results
0188     ///
0189     template <typename... args>
0190     using this_result_type = PropagatorResult<parameters_t, args...>;
0191 
0192     /// @brief Propagation result type derived from a given action list
0193     using type = typename actor_list_t::template result_type<this_result_type>;
0194   };
0195 
0196  public:
0197   /// @brief Short-hand type definition for propagation state derived from
0198   ///        an action list
0199   ///
0200   /// @tparam actor_list_t List of propagation action types
0201   ///
0202   template <typename propagator_options_t, typename actor_list_t>
0203   using actor_list_t_state_t =
0204       typename state_type_helper<propagator_options_t, actor_list_t>::type;
0205 
0206   /// @brief Short-hand type definition for propagation result derived from
0207   ///        an action list
0208   ///
0209   /// @tparam parameters_t Type of the final track parameters
0210   /// @tparam actor_list_t List of propagation action types
0211   ///
0212   template <typename parameters_t, typename actor_list_t>
0213   using actor_list_t_result_t =
0214       typename result_type_helper<parameters_t, actor_list_t>::type;
0215 
0216   /// @brief Propagate track parameters
0217   ///
0218   /// This function performs the propagation of the track parameters using the
0219   /// internal stepper implementation, until at least one abort condition is
0220   /// fulfilled or the maximum number of steps/path length provided in the
0221   /// propagation options is reached.
0222   ///
0223   /// @tparam parameters_t Type of initial track parameters to propagate
0224   /// @tparam propagator_options_t Type of the propagator options
0225   /// @tparam path_aborter_t The path aborter type to be added
0226   ///
0227   /// @param [in] start initial track parameters to propagate
0228   /// @param [in] options Propagation options, type Options<,>
0229   /// @param [in] createFinalParameters Whether to produce parameters at the end of the propagation
0230   ///
0231   /// @return Propagation result containing the propagation status, final
0232   ///         track parameters, and output of actions (if they produce any)
0233   ///
0234   template <typename parameters_t, typename propagator_options_t,
0235             typename path_aborter_t = PathLimitReached>
0236   Result<actor_list_t_result_t<StepperBoundTrackParameters,
0237                                typename propagator_options_t::actor_list_type>>
0238   propagate(const parameters_t& start, const propagator_options_t& options,
0239             bool createFinalParameters = true) const;
0240 
0241   /// @brief Propagate track parameters - User method
0242   ///
0243   /// This function performs the propagation of the track parameters according
0244   /// to the internal implementation object until at least one abort condition
0245   /// is fulfilled, the destination surface is hit or the maximum number of
0246   /// steps/path length as given in the propagation options is reached.
0247   ///
0248   /// @tparam parameters_t Type of initial track parameters to propagate
0249   /// @tparam propagator_options_t Type of the propagator options
0250   /// @tparam target_aborter_t The target aborter type to be added
0251   /// @tparam path_aborter_t The path aborter type to be added
0252   ///
0253   /// @param [in] start Initial track parameters to propagate
0254   /// @param [in] target Target surface of to propagate to
0255   /// @param [in] options Propagation options
0256   ///
0257   /// @return Propagation result containing the propagation status, final
0258   ///         track parameters, and output of actions (if they produce any)
0259   template <typename parameters_t, typename propagator_options_t,
0260             typename target_aborter_t = SurfaceReached,
0261             typename path_aborter_t = PathLimitReached>
0262   Result<actor_list_t_result_t<StepperBoundTrackParameters,
0263                                typename propagator_options_t::actor_list_type>>
0264   propagate(const parameters_t& start, const Surface& target,
0265             const propagator_options_t& options) const;
0266 
0267   /// @brief Builds the propagator state object
0268   ///
0269   /// This function creates the propagator state object from the initial track
0270   /// parameters and the propagation options.
0271   ///
0272   /// @tparam propagator_options_t Type of the propagator options
0273   /// @tparam path_aborter_t The path aborter type to be added
0274   ///
0275   /// @param [in] options Propagation options
0276   ///
0277   /// @return Propagator state object
0278   template <typename propagator_options_t,
0279             typename path_aborter_t = PathLimitReached>
0280   auto makeState(const propagator_options_t& options) const;
0281 
0282   /// @brief Builds the propagator state object
0283   ///
0284   /// This function creates the propagator state object from the initial track
0285   /// parameters, the target surface, and the propagation options.
0286   ///
0287   /// @tparam propagator_options_t Type of the propagator options
0288   /// @tparam target_aborter_t The target aborter type to be added
0289   /// @tparam path_aborter_t The path aborter type to be added
0290   ///
0291   /// @param [in] target Target surface of to propagate to
0292   /// @param [in] options Propagation options
0293   ///
0294   /// @return Propagator state object
0295   template <typename propagator_options_t,
0296             typename target_aborter_t = SurfaceReached,
0297             typename path_aborter_t = PathLimitReached>
0298   auto makeState(const Surface& target,
0299                  const propagator_options_t& options) const;
0300 
0301   /// @brief Initialize the propagator state
0302   ///
0303   /// This function initializes the propagator state for a new propagation.
0304   ///
0305   /// @tparam propagator_state_t Type of the propagator state object
0306   /// @tparam path_aborter_t The path aborter type to be added
0307   ///
0308   /// @param [in,out] state The propagator state object
0309   /// @param [in] start Initial track parameters to propagate
0310   ///
0311   /// @return Indication if the initialization was successful
0312   template <typename propagator_state_t, typename parameters_t,
0313             typename path_aborter_t = PathLimitReached>
0314   [[nodiscard]] Result<void> initialize(propagator_state_t& state,
0315                                         const parameters_t& start) const;
0316 
0317   /// @brief Propagate track parameters
0318   ///
0319   /// This function performs the propagation of the track parameters according
0320   /// to the internal implementation object until at least one abort condition
0321   /// is fulfilled, the destination surface is hit or the maximum number of
0322   /// steps/path length as given in the propagation options is reached.
0323   ///
0324   /// @note Does not (yet) convert into the return_type of the propagation
0325   ///
0326   /// @tparam propagator_state_t Type of the propagator state with options
0327   ///
0328   /// @param [in,out] state the propagator state object
0329   ///
0330   /// @return Propagation result
0331   template <typename propagator_state_t>
0332   Result<void> propagate(propagator_state_t& state) const;
0333 
0334   /// @brief Builds the propagator result object
0335   ///
0336   /// This function creates the propagator result object from the propagator
0337   /// state object. The `result` is passed to pipe a potential error from the
0338   /// propagation call. The `options` are used to determine the type of the
0339   /// result object. The `createFinalParameters` flag is used to determine if
0340   /// the result should contain final track parameters.
0341   ///
0342   /// @tparam propagator_state_t Type of the propagator state object
0343   /// @tparam propagator_options_t Type of the propagator options
0344   ///
0345   /// @param [in] state Propagator state object
0346   /// @param [in] result Result of the propagation
0347   /// @param [in] options Propagation options
0348   /// @param [in] createFinalParameters Whether to produce parameters at the end of the propagation
0349   ///
0350   /// @return Propagation result
0351   template <typename propagator_state_t, typename propagator_options_t>
0352   Result<actor_list_t_result_t<StepperBoundTrackParameters,
0353                                typename propagator_options_t::actor_list_type>>
0354   makeResult(propagator_state_t state, Result<void> result,
0355              const propagator_options_t& options,
0356              bool createFinalParameters) const;
0357 
0358   /// @brief Builds the propagator result object
0359   ///
0360   /// This function creates the propagator result object from the propagator
0361   /// state object. The `result` is passed to pipe a potential error from the
0362   /// propagation call. The `options` are used to determine the type of the
0363   /// result object.
0364   ///
0365   /// @tparam propagator_state_t Type of the propagator state object
0366   /// @tparam propagator_options_t Type of the propagator options
0367   ///
0368   /// @param [in] state Propagator state object
0369   /// @param [in] result Result of the propagation
0370   /// @param [in] target Target surface of to propagate to
0371   /// @param [in] options Propagation options
0372   ///
0373   /// @return Propagation result
0374   template <typename propagator_state_t, typename propagator_options_t>
0375   Result<actor_list_t_result_t<StepperBoundTrackParameters,
0376                                typename propagator_options_t::actor_list_type>>
0377   makeResult(propagator_state_t state, Result<void> result,
0378              const Surface& target, const propagator_options_t& options) const;
0379 
0380   /// Access to the stepper instance
0381   /// @return Const reference to the stepper
0382   const stepper_t& stepper() const { return m_stepper; }
0383 
0384   /// Access to the navigator instance
0385   /// @return Const reference to the navigator
0386   const navigator_t& navigator() const { return m_navigator; }
0387 
0388  private:
0389   const Logger& logger() const { return *m_logger; }
0390 
0391   template <typename propagator_state_t, typename result_t>
0392   void moveStateToResult(propagator_state_t& state, result_t& result) const;
0393 
0394   /// Implementation of propagation algorithm
0395   stepper_t m_stepper;
0396 
0397   /// Implementation of navigator
0398   navigator_t m_navigator;
0399 
0400   std::shared_ptr<const Logger> m_logger;
0401 };
0402 
0403 }  // namespace Acts
0404 
0405 #include "Acts/Propagator/Propagator.ipp"