Back to home page

EIC code displayed by LXR

 
 

    


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

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 // detray definitions
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/definitions/math.hpp"
0015 #include "detray/definitions/units.hpp"
0016 #include "detray/propagator/base_actor.hpp"
0017 
0018 // system includes
0019 #include <climits>
0020 
0021 namespace detray {
0022 
0023 /// Struct that represents the most conservative navigation policy: always re-
0024 /// initialize the current volume
0025 struct always_init : public base_actor {
0026   struct state {};
0027 
0028   /// Sets the navigation trust level to 'no trust'
0029   ///
0030   /// @param pol_state not used
0031   /// @param propagation state of the propagation
0032   template <typename propagator_state_t>
0033   DETRAY_HOST_DEVICE inline void operator()(
0034       const state & /*pol_state*/, propagator_state_t &propagation) const {
0035     propagation.navigation().set_no_trust();
0036   }
0037 };
0038 
0039 /// During guided navigation only the next surface should be re-evaluated. This
0040 /// maps to the 'high trust' level in the navigator
0041 struct guided_navigation : public base_actor {
0042   struct state {};
0043 
0044   /// Sets the navigation trust level to 'no trust'
0045   ///
0046   /// @param pol_state not used
0047   /// @param propagation state of the propagation
0048   template <typename propagator_state_t>
0049   DETRAY_HOST_DEVICE inline void operator()(
0050       const state & /*pol_state*/, propagator_state_t &propagation) const {
0051     propagation.navigation().set_high_trust();
0052   }
0053 };
0054 
0055 /// Default navigation update policy for the steppers: If a constraint has been
0056 /// hit, lower the trustlevel to 'fair trust', otherwise stay in 'high trust'.
0057 /// The reasoning is, that the track state might have changed much when a
0058 /// constraint was triggered.
0059 template <concepts::scalar scalar_t>
0060 struct stepper_default_policy : public base_actor {
0061   struct state {
0062     scalar_t tol{std::numeric_limits<scalar_t>::epsilon()};
0063   };
0064 
0065   /// Sets the navigation trust level depending on the step size limit
0066   ///
0067   /// @param pol_state not used
0068   /// @param propagation state of the propagation
0069   template <typename propagator_state_t>
0070   DETRAY_HOST_DEVICE inline void operator()(
0071       state &pol_state, propagator_state_t &propagation) const {
0072     const auto &stepping = propagation.stepping();
0073     auto &navigation = propagation.navigation();
0074 
0075     // Not a severe change to track state expected
0076     if (math::fabs(stepping.step_size()) <
0077         math::fabs(
0078             stepping.constraints().template size<>(stepping.direction())) -
0079             pol_state.tol) {
0080       // Re-evaluate only next candidate
0081       navigation.set_high_trust();
0082     }
0083     // Step size hit a constraint - the track state was probably changed a
0084     // lot
0085     else {
0086       // Re-evaluate all candidates
0087       navigation.set_fair_trust();
0088     }
0089   }
0090 };
0091 
0092 /// Specific navigation policy for the Runge-Kutta stepper: Use the relative
0093 /// amount of step size correction as a measure for the change in direction of
0094 /// the track state.
0095 template <concepts::scalar scalar_t>
0096 struct stepper_rk_policy : public base_actor {
0097   struct state {
0098     scalar_t m_threshold_fair_trust{0.05f};
0099     scalar_t m_threshold_no_trust{0.1f};
0100   };
0101 
0102   /// Sets the navigation trust level depending on the step size correction
0103   ///
0104   /// @param pol_state contains the thresholds
0105   /// @param propagation state of the propagation
0106   template <typename propagator_state_t>
0107   DETRAY_HOST_DEVICE inline void operator()(
0108       const state &pol_state, propagator_state_t &propagation) const {
0109     const auto &stepping = propagation.stepping();
0110     auto &navigation = propagation.navigation();
0111 
0112     // In case of an overlap, have navigator re-evaluate the next candidate
0113     if (math::fabs(navigation()) <= 1.f * unit<float>::um) {
0114       navigation.set_high_trust();
0115       return;
0116     }
0117 
0118     // How strongly did the RKN algorithm reduce the step size?
0119     const scalar_t rel_correction{(stepping.step_size() - navigation()) /
0120                                   navigation()};
0121 
0122     // Large correction to the stepsize - re-initialize the volume
0123     if (rel_correction > pol_state.m_threshold_no_trust) {
0124       navigation.set_no_trust();
0125     }
0126     // Medium correction - re-evaluate all current candidates
0127     else if (rel_correction > pol_state.m_threshold_fair_trust) {
0128       navigation.set_fair_trust();
0129     } else {
0130       // Small correction - re-evaluate only the next candidate
0131       navigation.set_high_trust();
0132     }
0133   }
0134 };
0135 
0136 }  // namespace detray