Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 07:49:39

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