Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:55

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