File indexing completed on 2026-05-27 07:24:03
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/definitions/math.hpp"
0015 #include "detray/material/material.hpp"
0016 #include "detray/navigation/policies.hpp"
0017 #include "detray/propagator/base_stepper.hpp"
0018 #include "detray/utils/logging.hpp"
0019
0020 namespace detray {
0021
0022
0023 template <concepts::algebra algebra_t,
0024 typename constraint_t = unconstrained_step<dscalar<algebra_t>>,
0025 typename policy_t = stepper_default_policy<dscalar<algebra_t>>,
0026 typename inspector_t = stepping::void_inspector>
0027 class line_stepper final
0028 : public base_stepper<algebra_t, constraint_t, policy_t, inspector_t> {
0029 using base_type =
0030 base_stepper<algebra_t, constraint_t, policy_t, inspector_t>;
0031
0032 public:
0033 static constexpr bool uses_gradient = true;
0034
0035 using algebra_type = algebra_t;
0036 using scalar_type = dscalar<algebra_t>;
0037 using vector3_type = dvector3D<algebra_t>;
0038 using transform3_type = dtransform3D<algebra_t>;
0039 using free_track_parameters_type =
0040 typename base_type::free_track_parameters_type;
0041 using bound_track_parameters_type =
0042 typename base_type::bound_track_parameters_type;
0043 template <std::size_t ROWS, std::size_t COLS>
0044 using matrix_type = dmatrix<algebra_t, ROWS, COLS>;
0045
0046 struct state : public base_type::template state<> {
0047 static constexpr const stepping::id id = stepping::id::e_linear;
0048
0049 using base_state = typename base_type::template state<>;
0050
0051
0052 using base_state::base_state;
0053
0054
0055 DETRAY_HOST_DEVICE
0056 inline void advance_track() {
0057 auto& track = (*this)();
0058 track.set_pos(track.pos() + track.dir() * this->step_size());
0059
0060 this->update_path_lengths(this->step_size());
0061 }
0062
0063 DETRAY_HOST_DEVICE
0064 inline void advance_jacobian() {
0065 DETRAY_VERBOSE_HOST_DEVICE("Advance Jacobian");
0066
0067
0068 free_matrix<algebra_t> D = matrix::identity<free_matrix<algebra_t>>();
0069
0070
0071 matrix_type<3, 3> dxdn =
0072 this->step_size() * matrix::identity<matrix_type<3, 3>>();
0073 getter::set_block(D, dxdn, e_free_pos0, e_free_dir0);
0074
0075
0076
0077 this->transport_jacobian() = D * this->transport_jacobian();
0078 }
0079
0080 DETRAY_HOST_DEVICE
0081 constexpr vector3_type dtds() const { return {0.f, 0.f, 0.f}; }
0082
0083 DETRAY_HOST_DEVICE
0084 constexpr scalar_type dqopds(
0085 const material<scalar_type>* ) const {
0086 return 0.f;
0087 }
0088 };
0089
0090
0091
0092
0093
0094
0095
0096
0097 DETRAY_HOST_DEVICE bool step(
0098 const scalar_type dist_to_next, state& stepping,
0099 const stepping::config& cfg, const bool = true,
0100 const material<scalar_type>* = nullptr) const {
0101
0102 if (math::fabs(dist_to_next) <= 1.f * unit<scalar_type>::um) {
0103 stepping.run_inspector(cfg, "Step skipped (Overlap): ", dist_to_next);
0104 return true;
0105 }
0106
0107
0108 stepping.set_step_size(dist_to_next);
0109
0110 DETRAY_VERBOSE_HOST_DEVICE("Take step: %f mm", stepping.step_size());
0111
0112
0113 if (const scalar_type max_step =
0114 stepping.constraints().template size<>(stepping.direction());
0115 math::fabs(stepping.step_size()) > math::fabs(max_step)) {
0116
0117 stepping.run_inspector(cfg, "Before constraint: ", dist_to_next);
0118
0119 stepping.set_step_size(max_step);
0120 }
0121
0122
0123 stepping.advance_track();
0124
0125
0126 if (cfg.do_covariance_transport) {
0127 stepping.advance_jacobian();
0128 }
0129
0130
0131 stepping.count_trials();
0132
0133
0134 stepping.run_inspector(cfg, "Step complete: ", dist_to_next);
0135
0136 return true;
0137 }
0138 };
0139
0140 }