Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:14

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 // Project include(s).
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/propagator/actors/parameter_updater.hpp"
0015 #include "detray/propagator/base_actor.hpp"
0016 #include "detray/tracks/bound_track_parameters.hpp"
0017 #include "detray/tracks/free_track_parameters.hpp"
0018 
0019 namespace detray {
0020 
0021 namespace detail {
0022 /// Data for a single step
0023 template <concepts::algebra algebra_t>
0024 struct step_data {
0025   using scalar_type = dscalar<algebra_t>;
0026   using vector3_type = dvector3D<algebra_t>;
0027   using track_param_type = free_track_parameters<algebra_t>;
0028   using bound_param_type = bound_track_parameters<algebra_t>;
0029   using free_matrix_type = free_matrix<algebra_t>;
0030 
0031   scalar_type step_size{0.f};
0032   scalar_type path_length{0.f};
0033   std::size_t n_total_trials{0u};
0034   navigation::direction nav_dir = navigation::direction::e_forward;
0035   geometry::identifier identifier{};
0036   track_param_type track_params{};
0037   bound_param_type bound_params{};
0038   free_matrix_type jacobian{};
0039 };
0040 }  // namespace detail
0041 
0042 namespace actor {
0043 
0044 /// Collect information at every step
0045 template <concepts::algebra algebra_t, template <typename...> class vector_t>
0046 struct step_tracer : public base_actor {
0047   using step_data_t = detail::step_data<algebra_t>;
0048 
0049   /// Actor state that collects the data
0050   struct state {
0051     friend struct step_tracer;
0052 
0053     state() = delete;
0054 
0055     /// Construct the vector containers with a given resource
0056     /// @param resource
0057     DETRAY_HOST
0058     explicit state(vecmem::memory_resource& resource) : m_steps(&resource) {}
0059 
0060     /// Construct from externally provided vector for the @param steps
0061     DETRAY_HOST_DEVICE
0062     explicit state(vector_t<step_data_t>&& steps) : m_steps(std::move(steps)) {}
0063 
0064     /// Access to the recorded step data of every step along the track -
0065     /// const
0066     DETRAY_HOST_DEVICE
0067     const auto& get_step_data() const { return m_steps; }
0068 
0069     /// Move the recorded step data out of the actor
0070     DETRAY_HOST
0071     auto&& release_step_data() && { return std::move(m_steps); }
0072 
0073    private:
0074     /// The collected data for the steps
0075     vector_t<step_data_t> m_steps;
0076   };
0077 
0078   /// Collect data at every step
0079   /// @note Primary actor call
0080   template <typename propagator_state_t>
0081   DETRAY_HOST_DEVICE void operator()(state& tracer_state,
0082                                      propagator_state_t& prop_state) const {
0083     tracer_state.m_steps.push_back(collect_data(prop_state));
0084   }
0085 
0086   /// Collect only when transport to bound track parameters happens
0087   /// @note Observer to the parameter updater
0088   template <typename propagator_state_t>
0089   DETRAY_HOST_DEVICE void operator()(
0090       state& tracer_state, propagator_state_t& prop_state,
0091       const parameter_transporter_result<algebra_t>& res) const {
0092     const auto& navigation = prop_state.navigation();
0093     assert(navigation.is_on_surface());
0094 
0095     // If the state has already been collected by the other call operator,
0096     // update the bound track parameters
0097     if (!tracer_state.m_steps.empty() &&
0098         navigation.geometry_identifier() ==
0099             tracer_state.m_steps.back().identifier) {
0100       tracer_state.m_steps.back().bound_params = res.destination_params();
0101     } else {
0102       tracer_state.m_steps.push_back(
0103           collect_data(prop_state, res.destination_params()));
0104     }
0105   }
0106 
0107  private:
0108   /// Collect step data
0109   template <typename propagator_state_t>
0110   DETRAY_HOST_DEVICE step_data_t collect_data(
0111       propagator_state_t& prop_state,
0112       const bound_track_parameters<algebra_t>& bound_param = {}) const {
0113     const auto& navigation = prop_state.navigation();
0114     const auto& stepping = prop_state.stepping();
0115 
0116     const auto geo_id{navigation.is_on_surface()
0117                           ? navigation.geometry_identifier()
0118                           : geometry::identifier{}};
0119 
0120     return {stepping.step_size(),
0121             stepping.path_length(),
0122             stepping.n_total_trials(),
0123             navigation.direction(),
0124             geo_id,
0125             stepping(),
0126             bound_param,
0127             stepping.transport_jacobian()};
0128   }
0129 };
0130 
0131 }  // namespace actor
0132 
0133 }  // namespace detray