Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:21:28

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/detail/CorrectedTransformationFreeToBound.hpp>
0012 #include <Acts/Propagator/detail/CovarianceEngine.hpp>
0013 #include <Acts/Surfaces/Surface.hpp>
0014 #include <Acts/Utilities/Result.hpp>
0015 
0016 #include <type_traits>
0017 
0018 namespace Acts::detail {
0019 
0020 /// A helper type for providinig a propagation state which can be used with
0021 /// functions expecting single-component steppers and states
0022 template <typename stepping_t, typename navigation_t, typename options_t,
0023           typename geoctx_t>
0024 struct SinglePropState {
0025   stepping_t& stepping;
0026   navigation_t& navigation;
0027   options_t& options;
0028   geoctx_t& geoContext;
0029 
0030   SinglePropState(stepping_t& s, navigation_t& n, options_t& o, geoctx_t& g)
0031       : stepping(s), navigation(n), options(o), geoContext(g) {}
0032 };
0033 
0034 /// A template class which contains all const member functions, that should be
0035 /// available both in the mutable ComponentProxy and the ConstComponentProxy.
0036 /// @tparam component_t Must be a const or mutable State::Component.
0037 template <typename component_t, typename loop_stepper_t>
0038 struct LoopComponentProxyBase {
0039   using SingleStepper = typename loop_stepper_t::SingleStepper;
0040   using SingleState = typename loop_stepper_t::SingleState;
0041 
0042   static_assert(std::is_same_v<std::remove_const_t<component_t>,
0043                                typename loop_stepper_t::State::Component>);
0044 
0045   component_t& cmp;
0046 
0047   LoopComponentProxyBase(component_t& c) : cmp(c) {}
0048 
0049   // These are the const accessors, which are shared between the mutable
0050   // ComponentProxy and the ConstComponentProxy
0051   const auto& state() const { return cmp.state; }
0052   auto status() const { return cmp.status; }
0053   auto weight() const { return cmp.weight; }
0054   auto pathAccumulated() const { return cmp.state.pathAccumulated; }
0055   const auto& pars() const { return cmp.state.pars; }
0056   const auto& derivative() const { return cmp.state.derivative; }
0057   const auto& jacTransport() const { return cmp.state.jacTransport; }
0058   const auto& cov() const { return cmp.state.cov; }
0059   const auto& jacobian() const { return cmp.state.jacobian; }
0060   const auto& jacToGlobal() const { return cmp.state.jacToGlobal; }
0061 
0062   template <typename propagator_state_t>
0063   auto singleState(const propagator_state_t& state) const {
0064     using DeducedStepping = decltype(state.stepping.components.front().state);
0065     static_assert(std::is_same_v<SingleState, DeducedStepping>);
0066 
0067     return SinglePropState<const SingleState, const decltype(state.navigation),
0068                            const decltype(state.options),
0069                            const decltype(state.geoContext)>(
0070         cmp.state, state.navigation, state.options, state.geoContext);
0071   }
0072 
0073   const auto& singleStepper(const loop_stepper_t& stepper) const {
0074     return static_cast<const SingleStepper&>(stepper);
0075   }
0076 };
0077 
0078 /// A proxy struct which allows access to a single component of the
0079 /// multi-component state. It has the semantics of a mutable reference, i.e.
0080 /// it requires a mutable reference of the single-component state it
0081 /// represents
0082 template <typename component_t, typename loop_stepper_t>
0083 struct LoopComponentProxy
0084     : LoopComponentProxyBase<component_t, loop_stepper_t> {
0085   using State = typename loop_stepper_t::State;
0086   using Base = LoopComponentProxyBase<component_t, loop_stepper_t>;
0087 
0088   using SingleState = typename loop_stepper_t::SingleState;
0089   using SingleStepper = typename loop_stepper_t::SingleStepper;
0090   using Covariance = typename loop_stepper_t::Covariance;
0091 
0092   // Import the const accessors from ComponentProxyBase
0093   using Base::cmp;
0094   using Base::cov;
0095   using Base::derivative;
0096   using Base::jacobian;
0097   using Base::jacToGlobal;
0098   using Base::jacTransport;
0099   using Base::pars;
0100   using Base::pathAccumulated;
0101   using Base::singleState;
0102   using Base::singleStepper;
0103   using Base::state;
0104   using Base::status;
0105   using Base::weight;
0106 
0107   // The multi-component state of the stepper
0108   const State& all_state;
0109 
0110   LoopComponentProxy(typename State::Component& c, const State& s)
0111       : Base(c), all_state(s) {}
0112 
0113   // These are the mutable accessors, the const ones are inherited from the
0114   // ComponentProxyBase
0115   auto& state() { return cmp.state; }
0116   auto& status() { return cmp.status; }
0117   auto& weight() { return cmp.weight; }
0118   auto& pathAccumulated() { return cmp.state.pathAccumulated; }
0119   auto& pars() { return cmp.state.pars; }
0120   auto& derivative() { return cmp.state.derivative; }
0121   auto& jacTransport() { return cmp.state.jacTransport; }
0122   auto& cov() { return cmp.state.cov; }
0123   auto& jacobian() { return cmp.state.jacobian; }
0124   auto& jacToGlobal() { return cmp.state.jacToGlobal; }
0125 
0126   template <typename propagator_state_t>
0127   auto singleState(propagator_state_t& state) {
0128     using DeducedStepping = decltype(state.stepping.components.front().state);
0129     static_assert(std::is_same_v<SingleState, DeducedStepping>);
0130 
0131     return SinglePropState<SingleState, decltype(state.navigation),
0132                            decltype(state.options), decltype(state.geoContext)>(
0133         cmp.state, state.navigation, state.options, state.geoContext);
0134   }
0135 
0136   Result<typename SingleStepper::BoundState> boundState(
0137       const Surface& surface, bool transportCov,
0138       const FreeToBoundCorrection& freeToBoundCorrection) {
0139     return detail::boundState(
0140         all_state.options.geoContext, surface, cov(), jacobian(),
0141         jacTransport(), derivative(), jacToGlobal(), pars(),
0142         all_state.particleHypothesis, all_state.covTransport && transportCov,
0143         cmp.state.pathAccumulated, freeToBoundCorrection);
0144   }
0145 
0146   void update(const FreeVector& freeParams, const BoundVector& boundParams,
0147               const Covariance& covariance, const Surface& surface) {
0148     cmp.state.pars = freeParams;
0149     cmp.state.cov = covariance;
0150     cmp.state.jacToGlobal =
0151         surface.boundToFreeJacobian(all_state.geoContext, boundParams);
0152   }
0153 };
0154 
0155 }  // namespace Acts::detail