Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-16 08:17: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 // Project include(s).
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/definitions/navigation.hpp"
0015 #include "detray/propagator/actors/parameter_updater.hpp"
0016 #include "detray/tracks/bound_track_parameters.hpp"
0017 #include "detray/tracks/free_track_parameters.hpp"
0018 
0019 // System include(s)
0020 #include <optional>
0021 
0022 namespace detray {
0023 
0024 /// Record of a surface intersection along a track
0025 template <typename detector_t>
0026 struct intersection_record {
0027   using algebra_type = typename detector_t::algebra_type;
0028   using scalar_type = dscalar<algebra_type>;
0029   using point3_type = dpoint3D<algebra_type>;
0030   using vector3_type = dvector3D<algebra_type>;
0031   using intersection_type =
0032       intersection2D<typename detector_t::surface_type, algebra_type,
0033                      intersection::contains_pos>;
0034 
0035   constexpr intersection_record() = default;
0036 
0037   /// The particle charge is not known in the navigation, but might be
0038   /// provided in a different context
0039   DETRAY_HOST_DEVICE
0040   constexpr intersection_record(
0041       const point3_type& position, const vector3_type& direction,
0042       const intersection_type& intr,
0043       const scalar_type q = detray::detail::invalid_value<scalar_type>(),
0044       const scalar_type p = detray::detail::invalid_value<scalar_type>(),
0045       dindex v_idx = dindex_invalid)
0046       : pos{position},
0047         dir{direction},
0048         intersection{intr},
0049         vol_idx{v_idx},
0050         charge{q},
0051         p_mag{p} {}
0052 
0053   /// Current global track position
0054   point3_type pos{0.f, 0.f, 0.f};
0055   /// Current global track direction
0056   vector3_type dir{0.f, 0.f, 1.f};
0057   /// The intersection result
0058   intersection_type intersection{};
0059   /// Index of the volume the intersection was found in
0060   dindex vol_idx{dindex_invalid};
0061   /// Charge hypothesis of the particle (invalid value if not known)
0062   scalar_type charge{detray::detail::invalid_value<scalar_type>()};
0063   /// Current momentum magnitude of the particle
0064   scalar_type p_mag{1.f * unit<scalar_type>::GeV};
0065 
0066   /// @returns the information as free track parameters
0067   DETRAY_HOST_DEVICE
0068   free_track_parameters<algebra_type> track_param() const {
0069     assert(p_mag > 0.f);
0070     return {pos, detail::invalid_value<scalar_type>(), p_mag * dir, charge};
0071   }
0072 };
0073 
0074 /// Data for a single step
0075 template <concepts::algebra algebra_t>
0076 struct step_record {
0077   using scalar_type = dscalar<algebra_t>;
0078   using vector3_type = dvector3D<algebra_t>;
0079   using track_param_type = free_track_parameters<algebra_t>;
0080   using bound_param_type = bound_track_parameters<algebra_t>;
0081   using free_matrix_type = free_matrix<algebra_t>;
0082 
0083   scalar_type step_size{0.f};
0084   scalar_type path_length{0.f};
0085   std::size_t n_total_trials{0u};
0086   navigation::direction nav_dir = navigation::direction::e_forward;
0087   geometry::identifier identifier{};
0088   track_param_type free_params{};
0089   bound_param_type bound_params{};
0090   free_matrix_type jacobian{};
0091 };
0092 
0093 /// Contains the material parameters and the pathlength
0094 template <concepts::scalar scalar_t>
0095 struct material_record {
0096   /// The surface the material belongs to
0097   geometry::identifier geo_id{};
0098   /// Pathlength of the track through the material
0099   scalar_t path{detail::invalid_value<scalar_t>()};
0100   /// Material thickness/radius
0101   scalar_t thickness{detail::invalid_value<scalar_t>()};
0102   /// Radiation length
0103   scalar_t mat_X0{0.f};
0104   /// Interaction length
0105   scalar_t mat_L0{0.f};
0106 };
0107 
0108 /// Data for a single step
0109 template <typename detector_t>
0110 struct propagation_record {
0111   using algebra_type = typename detector_t::algebra_type;
0112   using scalar_type = dscalar<algebra_type>;
0113   using free_param_type = free_track_parameters<algebra_type>;
0114   using bound_param_type = bound_track_parameters<algebra_type>;
0115   using free_matrix_type = free_matrix<algebra_type>;
0116   using intersection_type = intersection_record<detector_t>::intersection_type;
0117 
0118   /// @returns the free track parameters
0119   DETRAY_HOST_DEVICE
0120   scalar_type step_size() const { return m_step_record.step_size; }
0121   /// Set the new step size @param step_size
0122   DETRAY_HOST_DEVICE
0123   void step_size(scalar_type step_size) { m_step_record.step_size = step_size; }
0124 
0125   /// @returns the free track parameters
0126   DETRAY_HOST_DEVICE
0127   scalar_type path_length() const { return m_step_record.path_length; }
0128   /// Set the new path length @param path_length
0129   DETRAY_HOST_DEVICE
0130   void path_length(scalar_type path_length) {
0131     m_step_record.path_length = path_length;
0132   }
0133 
0134   /// @returns the free track parameters
0135   DETRAY_HOST_DEVICE
0136   std::size_t n_rkn_trials() const { return m_step_record.n_total_trials; }
0137   /// Set the new number of RKN iterations @param n_rkn_trials
0138   DETRAY_HOST_DEVICE
0139   void n_rkn_trials(std::size_t n_rkn_trials) {
0140     m_step_record.n_total_trials = n_rkn_trials;
0141   }
0142 
0143   /// @returns the free track parameters
0144   DETRAY_HOST_DEVICE
0145   scalar_type charge() const { return m_intersection_record.charge; }
0146   /// Set the new charge @param charge
0147   DETRAY_HOST_DEVICE
0148   void charge(scalar_type charge) { m_intersection_record.charge = charge; }
0149 
0150   /// @returns the current total momentum magnitude
0151   DETRAY_HOST_DEVICE
0152   scalar_type p_mag() const { return m_intersection_record.p_mag; }
0153   /// Set the new total momentum magnitude @param p_mag
0154   DETRAY_HOST_DEVICE
0155   void p_mag(scalar_type p_mag) { m_intersection_record.p_mag = p_mag; }
0156 
0157   /// @returns the current geometry identifier if the step landed on surface
0158   DETRAY_HOST_DEVICE
0159   geometry::identifier identifier() const {
0160     assert(intersection().is_outside() &&
0161            m_step_record.bound_params.surface_link() ==
0162                intersection().surface().identifier());
0163     return m_step_record.bound_params.surface_link();
0164   }
0165 
0166   /// Set the new geometry identifier @param geo_id
0167   DETRAY_HOST_DEVICE
0168   void identifier(geometry::identifier geo_id) {
0169     m_step_record.bound_params.surface_link() = geo_id;
0170   }
0171 
0172   /// @returns the intersection data on the current surface (if any) - const
0173   DETRAY_HOST_DEVICE
0174   const intersection_type& intersection() const {
0175     return m_intersection_record.intersection;
0176   }
0177   /// @returns the intersection data on the current surface (if any)
0178   DETRAY_HOST_DEVICE
0179   intersection_type& intersection() {
0180     return m_intersection_record.intersection;
0181   }
0182   /// Set the new intersection data @param intr
0183   DETRAY_HOST_DEVICE
0184   void intersection(const intersection_type& intr) {
0185     m_intersection_record.intersection = intr;
0186   }
0187 
0188   /// @returns the free track parameters
0189   DETRAY_HOST_DEVICE
0190   free_param_type free_track_param() const { return m_step_record.free_params; }
0191   /// Set the new free track parameters @param free_param
0192   DETRAY_HOST_DEVICE
0193   void free_track_param(const free_param_type& free_param) {
0194     m_step_record.free_params = free_param;
0195   }
0196 
0197   /// @returns the bound track parameters at the current surface (if any) - const
0198   DETRAY_HOST_DEVICE
0199   bound_param_type& bound_track_param() { return m_step_record.bound_params; }
0200   /// Set the new bound parameters @param bound_param
0201   DETRAY_HOST_DEVICE
0202   void bound_track_param(const bound_param_type& bound_param) {
0203     m_step_record.bound_params = bound_param;
0204   }
0205   /// @returns the bound track parameters at the current surface (if any)
0206   DETRAY_HOST_DEVICE
0207   const bound_param_type& bound_track_param() const {
0208     return m_step_record.bound_params;
0209   }
0210 
0211   /// @returns transport Jacobian since the last surface - const
0212   DETRAY_HOST_DEVICE
0213   free_matrix_type& jacobian() { return m_step_record.jacobian; }
0214   /// @returns transport Jacobian since the last surface
0215   DETRAY_HOST_DEVICE
0216   const free_matrix_type& jacobian() const { return m_step_record.jacobian; }
0217   /// Set the new Jacobian @param jac
0218   DETRAY_HOST_DEVICE
0219   void jacobian(const free_matrix_type& jac) { m_step_record.jacobian = jac; }
0220 
0221  private:
0222   /// Data that is collected at every step
0223   step_record<algebra_type> m_step_record;
0224   /// Data that is collected when the propagation reached a surface
0225   std::optional<intersection_record<detector_t>> m_intersection_record{};
0226   /// Data that is collected when the propagation reached a material surface
0227   std::optional<material_record<scalar_type>> m_material_record{};
0228 };
0229 
0230 }  // namespace detray