ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
base_stepper.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s).
12#include "detray/core/concepts.hpp"
13#include "detray/definitions/algebra.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15#include "detray/definitions/pdg_particle.hpp"
16#include "detray/definitions/units.hpp"
17#include "detray/geometry/identifier.hpp"
18#include "detray/geometry/tracking_surface.hpp"
19#include "detray/propagator/constrained_step.hpp"
20#include "detray/propagator/detail/print_stepper_state.hpp"
21#include "detray/propagator/stepping_config.hpp"
22#include "detray/propagator/transport_jacobian.hpp"
23#include "detray/tracks/tracks.hpp"
24#include "detray/utils/curvilinear_frame.hpp"
25#include "detray/utils/logging.hpp"
26
27namespace detray {
28
29namespace stepping {
30
37 template <typename state_t>
38 DETRAY_HOST_DEVICE constexpr void operator()(const state_t & /*ignored*/,
39 const char * /*ignored*/) const {
40 /*Do nothing*/
41 }
42};
43
44} // namespace stepping
45
47template <concepts::algebra algebra_t, typename constraint_t, typename policy_t,
48 typename inspector_t = stepping::void_inspector>
50 public:
53
63 using magnetic_field_type = void;
64
66 using inspector_type = inspector_t;
68 using policy_type = policy_t;
69
73 template <typename internal_jacobian_t = free_matrix_type>
74 struct state {
76 using internal_jacobian_type = internal_jacobian_t;
77
80 DETRAY_HOST_DEVICE
81 explicit state(const free_track_parameters_type &free_params)
82 : m_track(free_params) {
83 assert(!m_track.is_invalid());
84
85 // HACK: When the overload resolution for the transport Jacobian
86 // type is resolved, turn this into a default member
87 // initialization.
89 m_jac_transport = internal_jacobian_type::identity();
90 } else {
91 m_jac_transport = matrix::identity<internal_jacobian_type>();
92 }
93 }
94
100 template <concepts::detector detector_t>
101 DETRAY_HOST_DEVICE state(const bound_track_parameters_type &bound_params,
102 const detector_t &det,
103 const typename detector_t::geometry_context &ctx) {
104 assert(!bound_params.is_invalid());
105 assert(!bound_params.surface_link().is_invalid());
106
107 // Departure surface
108 const auto sf = tracking_surface{det, bound_params.surface_link()};
109
110 // Set free track parameters for stepping/navigation
111 m_track = sf.bound_to_free_vector(ctx, bound_params);
112
113 assert(!m_track.is_invalid());
114
115 // HACK: When the overload resolution for the transport Jacobian
116 // type is resolved, turn this into a default member
117 // initialization.
119 m_jac_transport = internal_jacobian_type::identity();
120 } else {
121 m_jac_transport = matrix::identity<internal_jacobian_type>();
122 }
123 }
124
126 DETRAY_HOST_DEVICE
128
130 DETRAY_HOST_DEVICE
131 const free_track_parameters_type &operator()() const { return m_track; }
132
135 DETRAY_HOST_DEVICE
136 inline step::direction direction() const {
137 return m_step_size >= 0.f ? step::direction::e_forward
138 : step::direction::e_backward;
139 }
140
142 DETRAY_HOST_DEVICE inline void count_trials() { ++m_n_total_trials; }
143
146 DETRAY_HOST_DEVICE inline std::size_t n_total_trials() const {
147 return m_n_total_trials;
148 }
149
152 DETRAY_HOST_DEVICE
153 inline void set_step_size(const scalar_type step) {
154 assert(math::fabs(step) >= 1e-4f * unit<scalar_type>::mm);
155 m_step_size = step;
156 }
157
159 DETRAY_HOST_DEVICE
160 inline scalar_type step_size() const { return m_step_size; }
161
163 DETRAY_HOST_DEVICE
164 inline scalar_type path_length() const { return m_path_length; }
165
167 DETRAY_HOST_DEVICE
168 inline scalar_type abs_path_length() const { return m_abs_path_length; }
169
172 DETRAY_HOST_DEVICE inline void update_path_lengths(scalar_type seg) {
173 m_path_length += seg;
174 m_abs_path_length += math::fabs(seg);
175 }
176
180 template <step::constraint type = step::constraint::e_actor>
181 DETRAY_HOST_DEVICE inline void set_constraint(scalar_type step_size) {
182 m_constraint.template set<type>(step_size);
183 }
184
186 DETRAY_HOST_DEVICE
187 inline const constraint_t &constraints() const { return m_constraint; }
188
190 template <step::constraint type = step::constraint::e_actor>
191 DETRAY_HOST_DEVICE inline void release_step() {
192 m_constraint.template release<type>();
193 }
194
196 DETRAY_HOST_DEVICE
197 const auto &particle_hypothesis() const { return m_ptc; }
198
201 DETRAY_HOST_DEVICE
202 inline void set_particle(const pdg_particle<scalar_type> &ptc) {
203 m_ptc = ptc;
204 }
205
208 DETRAY_HOST_DEVICE
210 requires(!std::same_as<free_matrix_type, internal_jacobian_type>)
211 {
212 return m_jac_transport.operator dmatrix<algebra_t, 8, 8>();
213 }
214
216 DETRAY_HOST_DEVICE
218 requires std::same_as<free_matrix_type, internal_jacobian_type>
219 {
220 return m_jac_transport;
221 }
222
224 DETRAY_HOST_DEVICE
226 requires std::same_as<free_matrix_type, internal_jacobian_type>
227 {
228 return m_jac_transport;
229 }
230
232 DETRAY_HOST_DEVICE
234 return m_jac_transport;
235 }
236
238 DETRAY_HOST_DEVICE
240 return m_jac_transport;
241 }
242
244 DETRAY_HOST_DEVICE
246 // HACK: When the overload resolution for the transport Jacobian
247 // type is resolved, remove this conditional logic.
249 m_jac_transport = internal_jacobian_type::identity();
250 } else {
251 m_jac_transport = matrix::identity<internal_jacobian_type>();
252 }
253 }
254
256 DETRAY_HOST_DEVICE
257 inline typename policy_t::state &policy_state() { return m_policy_state; }
258
260 DETRAY_HOST
261 constexpr auto &inspector() { return m_inspector; }
262
267 DETRAY_HOST_DEVICE
268 inline void run_inspector([[maybe_unused]] const stepping::config &cfg,
269 [[maybe_unused]] const char *message,
270 [[maybe_unused]] const scalar_type dist) {
271 if constexpr (!std::is_same_v<inspector_t, stepping::void_inspector>) {
272 m_inspector(*this, cfg, message, dist);
273 }
274
275 DETRAY_DEBUG_HOST("" << message << "\n"
276 << detray::stepping::print_state(*this, dist));
277 }
278
279 private:
281 internal_jacobian_type m_jac_transport;
282
285
288
290 std::size_t m_n_total_trials{0u};
291
293 scalar_type m_step_size{0.f};
294
296 scalar_type m_path_length{0.f};
297
299 scalar_type m_abs_path_length{0.f};
300
302 DETRAY_NO_UNIQUE_ADDRESS constraint_t m_constraint = {};
303
305 DETRAY_NO_UNIQUE_ADDRESS typename policy_t::state m_policy_state = {};
306
308 DETRAY_NO_UNIQUE_ADDRESS inspector_type m_inspector;
309 };
310};
311
312} // namespace detray
Base stepper implementation.
Definition base_stepper.hpp:49
void magnetic_field_type
Magnetic-field type, absent for the base stepper.
Definition base_stepper.hpp:63
bound_track_parameters< algebra_t > bound_track_parameters_type
Bound track parameter representation.
Definition base_stepper.hpp:57
policy_t policy_type
Navigation and step-constraint policy type.
Definition base_stepper.hpp:68
free_matrix< algebra_t > free_matrix_type
Free-parameter covariance/Jacobian matrix type.
Definition base_stepper.hpp:59
bound_matrix< algebra_t > bound_matrix_type
Bound-parameter covariance/Jacobian matrix type.
Definition base_stepper.hpp:61
inspector_t inspector_type
Type of the configured step inspection callback.
Definition base_stepper.hpp:66
dscalar< algebra_t > scalar_type
Scalar type used by the stepper.
Definition base_stepper.hpp:52
free_track_parameters< algebra_t > free_track_parameters_type
Free track parameter representation.
Definition base_stepper.hpp:55
constexpr bool is_invalid() const noexcept
Check whether the identifier is valid to use.
Definition identifier.hpp:141
Facade for a detray detector surface with extra tracking capabilities.
Definition tracking_surface.hpp:25
constexpr auto bound_to_free_vector(const context &ctx, const bound_param_vector_type &bound_vec) const
Definition tracking_surface.hpp:90
Definition transport_jacobian.hpp:18
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
dmatrix< algebra_t, e_free_size, e_free_size > free_matrix
Covariance matrix type for free track parametrization.
Definition track_parametrization.hpp:73
dmatrix< algebra_t, e_bound_size, e_bound_size > bound_matrix
Covariance matrix type for bound track parametrization.
Definition track_parametrization.hpp:81
get_matrix_t< A, R, C, T > dmatrix
R by C matrix type for algebra A and value type T.
Definition algebra.hpp:88
free_parameters_vector< algebra_t > free_track_parameters
The free track parameters consist only of the parameter vector.
Definition free_track_parameters.hpp:249
free_matrix_type transport_jacobian() const
Definition base_stepper.hpp:209
std::size_t n_total_trials() const
Definition base_stepper.hpp:146
policy_t::state & policy_state()
Definition base_stepper.hpp:257
step::direction direction() const
Get stepping direction.
Definition base_stepper.hpp:136
void set_particle(const pdg_particle< scalar_type > &ptc)
Set new particle hypothesis.
Definition base_stepper.hpp:202
void set_step_size(const scalar_type step)
Set the current step size.
Definition base_stepper.hpp:153
void update_path_lengths(scalar_type seg)
Add a new segment to all path lengths (forward or backward).
Definition base_stepper.hpp:172
void release_step()
Remove [all] constraints.
Definition base_stepper.hpp:191
constexpr auto & inspector()
Definition base_stepper.hpp:261
const constraint_t & constraints() const
Definition base_stepper.hpp:187
free_track_parameters_type & operator()()
Definition base_stepper.hpp:127
const auto & particle_hypothesis() const
Definition base_stepper.hpp:197
scalar_type step_size() const
Definition base_stepper.hpp:160
state(const bound_track_parameters_type &bound_params, const detector_t &det, const typename detector_t::geometry_context &ctx)
Sets track parameters from bound track parameter.
Definition base_stepper.hpp:101
free_matrix_type & transport_jacobian()
Definition base_stepper.hpp:225
scalar_type path_length() const
Definition base_stepper.hpp:164
void reset_transport_jacobian()
Reset transport Jacbian.
Definition base_stepper.hpp:245
const free_matrix_type & transport_jacobian() const
Definition base_stepper.hpp:217
const internal_jacobian_type & internal_transport_jacobian() const
Definition base_stepper.hpp:239
internal_jacobian_t internal_jacobian_type
Internal representation used to accumulate the transport Jacobian.
Definition base_stepper.hpp:76
const free_track_parameters_type & operator()() const
Definition base_stepper.hpp:131
internal_jacobian_type & internal_transport_jacobian()
Definition base_stepper.hpp:233
state(const free_track_parameters_type &free_params)
Sets track parameters.
Definition base_stepper.hpp:81
scalar_type abs_path_length() const
Definition base_stepper.hpp:168
void run_inspector(const stepping::config &cfg, const char *message, const scalar_type dist)
Call the stepping inspector.
Definition base_stepper.hpp:268
void count_trials()
Updates the total number of step trials.
Definition base_stepper.hpp:142
void set_constraint(scalar_type step_size)
Set new step constraint.
Definition base_stepper.hpp:181
Combine the bound track parameter vector with the covariance and associated surface.
Definition bound_track_parameters.hpp:297
const geometry::identifier & surface_link() const
Definition bound_track_parameters.hpp:364
constexpr bool is_invalid(const bool do_check=true) const
Definition bound_track_parameters.hpp:397
Negative muon hypothesis.
Definition pdg_particle.hpp:111
Particle hypothesis identified by PDG number, mass, and electric charge.
Definition pdg_particle.hpp:24
Configuration flags and limits consumed by a stepper.
Definition stepping_config.hpp:29
A void inpector that does nothing.
Definition base_stepper.hpp:34
constexpr void operator()(const state_t &, const char *) const
No-op inspection callback used when inspection is disabled.
Definition base_stepper.hpp:38
static constexpr scalar_t mm
Native length unit, the millimetre.
Definition units.hpp:27