12#include "detray/definitions/algebra.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14#include "detray/definitions/track_parametrization.hpp"
15#include "detray/geometry/tracking_surface.hpp"
16#include "detray/propagator/base_actor.hpp"
17#include "detray/propagator/composite_actor.hpp"
18#include "detray/propagator/detail/codegen/covariance_transport.hpp"
19#include "detray/propagator/detail/codegen/full_jacobian.hpp"
20#include "detray/propagator/detail/jacobian_engine.hpp"
21#include "detray/propagator/detail/noise_estimation.hpp"
22#include "detray/propagator/propagation_config.hpp"
23#include "detray/utils/curvilinear_frame.hpp"
24#include "detray/utils/logging.hpp"
25#include "detray/utils/type_registry.hpp"
27namespace detray::actor {
29template <concepts::algebra algebra_t>
32template <concepts::algebra algebra_t>
47template <concepts::algebra algebra_t>
63 : m_full_jacobian(full_jac),
64 m_cfg{cfg.navigation.accumulated_error,
65 cfg.navigation.n_scattering_stddev,
66 cfg.navigation.estimate_scattering_noise} {}
77 : m_full_jacobian(full_jac),
78 m_cfg{cfg.navigation.accumulated_error,
79 cfg.navigation.n_scattering_stddev,
80 cfg.navigation.estimate_scattering_noise} {
83 m_bound_params.set_parameter_vector(cf.
m_bound_vec);
98 m_full_jacobian(full_jac),
99 m_cfg{cfg.navigation.accumulated_error,
100 cfg.navigation.n_scattering_stddev,
101 cfg.navigation.estimate_scattering_noise} {}
109 m_bound_params.set_parameter_vector(cf.
m_bound_vec);
117 assert(!m_bound_params.is_invalid());
133 m_always_update = do_update;
141 m_notify_on_initial = do_notify;
156 return m_bound_params;
163 return m_bound_params;
169 return m_full_jacobian !=
nullptr;
176 return *m_full_jacobian;
184 *m_full_jacobian = jac;
192 m_full_jacobian = jac_ptr;
203 bool m_always_update{
false};
205 bool m_notify_on_initial{
true};
209template <concepts::algebra algebra_t>
220 : actor::
result{stat}, m_destination_params_ptr{params_ptr} {
221 assert(m_destination_params_ptr);
230 : actor::
result{stat}, m_destination_params_ptr{¶ms} {
231 assert(m_destination_params_ptr);
238 assert(this->
status == actor::status::e_unknown ||
239 m_destination_params_ptr);
240 return *m_destination_params_ptr;
246 assert(this->
status == actor::status::e_unknown ||
247 m_destination_params_ptr);
248 return *m_destination_params_ptr;
256 os << static_cast<actor::result>(res) << std::endl;
268template <concepts::algebra algebra_t>
289 template <
typename mask_t>
290 using type =
typename mask_t::local_frame;
301 template <
typename frame_t>
305 return detail::jacobian_engine<algebra_t>::
306 template bound_to_free_jacobian_submatrix_dpos_dloc<frame_t>(
307 trf3, params.
pos(), params.
dir());
319 template <
typename frame_t>
324 return detail::jacobian_engine<algebra_t>::
325 template bound_to_free_jacobian_submatrix_dpos_dangle<frame_t>(
326 trf3, params.
pos(), params.
dir(), ddir_dangle);
338 template <
typename frame_t,
typename stepper_state_t>
341 const stepper_state_t& stepping)
const {
342 return detail::jacobian_engine<algebra_t>::
343 template free_to_bound_jacobian_submatrix_dloc_dpos<frame_t>(
344 trf3, stepping().pos(), stepping().dir());
354 template <
typename propagator_state_t>
356 propagator_state_t& propagation)
const {
357 const auto& navigation = propagation.navigation();
360 if (!(navigation.is_on_sensitive() ||
361 navigation.encountered_sf_material())) {
364 assert(navigation.is_on_surface());
367 auto& stepping = propagation.stepping();
370 const auto dest_sf = navigation.current_surface();
376 result res{actor::status::e_notify, departure_params};
381 if (!departure_params.surface_link().is_invalid()) {
383 "Actor: Departure surface: " << departure_params.surface_link());
386 assert(!dest_sf.identifier().is_invalid());
387 if (departure_params.surface_link() == dest_sf.identifier()) {
388 DETRAY_VERBOSE_HOST_DEVICE(
389 "Actor: On initial surface (%d), parameter transport not required",
393 if (!updater_state.m_notify_on_initial) {
394 res.
status = actor::status::e_unknown;
400 DETRAY_DEBUG_HOST(
"Actor: Destination surface: " << dest_sf.identifier());
401 DETRAY_VERBOSE_HOST_DEVICE(
402 "Actor: Transport track covariance to surface %d", dest_sf.index());
404 DETRAY_DEBUG_HOST(
"Actor: Departure bound param.: " << departure_params);
411 if (math::fabs(stepping.path_length()) > 0.f) {
418 stepping.reset_transport_jacobian();
425 detray::detail::transport_covariance_to_bound_impl(
426 old_cov, propagation_step_jacobian, new_cov);
428 DETRAY_VERBOSE_HOST_DEVICE(
"Actor: Departure surface link invalid");
431 DETRAY_VERBOSE_HOST_DEVICE(
432 "Actor: Convert track parameter vector to local for surface %d",
437 dest_sf.free_to_bound_vector(propagation.context(), stepping()));
444 DETRAY_DEBUG_HOST(
"Actor: Transported bound param.:\n"
455 template <
typename propagator_state_t>
457 propagator_state_t& propagation,
460 using detector_t =
typename propagator_state_t::detector_type;
461 using frame_registry_t =
464 const auto& gctx = propagation.context();
465 const auto& stepping = propagation.stepping();
466 const auto& navigation = propagation.navigation();
517 const auto& dep_trf3 = dep_sf.
transform(gctx);
519 types::visit<frame_registry_t, get_bound_to_free_dpos_dloc_visitor>(
520 dep_sf.
shape_id(), dep_trf3, dep_free_params);
523 detail::jacobian_engine<algebra_t>::
524 bound_to_free_jacobian_submatrix_ddir_dangle(departure_params);
527 types::visit<frame_registry_t, get_bound_to_free_dpos_dangle_visitor>(
528 dep_sf.
shape_id(), dep_trf3, dep_free_params, b2f_ddir_dangle);
550 auto vol = navigation.current_volume();
551 const auto vol_mat_ptr =
552 vol.has_material() ? vol.material_parameters(dest_glob_pos) :
nullptr;
554 const auto path_to_free_derivative =
555 detail::jacobian_engine<algebra_t>::path_to_free_derivative(
556 dest_glob_dir, stepping.dtds(), stepping.dqopds(vol_mat_ptr));
559 gctx, dest_glob_pos, dest_glob_dir, stepping.dtds());
576 types::visit<frame_registry_t, get_free_to_bound_dloc_dpos_visitor>(
580 algebra_t>::free_to_bound_jacobian_submatrix_dangle_ddir(dest_glob_dir);
586 if constexpr (std::decay_t<propagator_state_t>::stepper_uses_gradient) {
587 detail::update_full_jacobian_with_gradient_impl(
588 stepping.internal_transport_jacobian(), b2f_dpos_dloc,
589 b2f_ddir_dangle, b2f_dpos_dangle, path_to_free_derivative,
590 free_to_path_derivative, f2b_dloc_dpos, f2b_dangle_ddir,
593 detail::update_full_jacobian_without_gradient_impl(
594 stepping.internal_transport_jacobian(), b2f_dpos_dloc,
595 b2f_ddir_dangle, b2f_dpos_dangle, path_to_free_derivative,
596 free_to_path_derivative, f2b_dloc_dpos, f2b_dangle_ddir,
600 return full_jacobian;
606template <concepts::algebra algebra_t>
616 template <
typename propagator_state_t>
618 state& updater_state, propagator_state_t& propagation,
621 if (res.
status != actor::status::e_success &&
622 !updater_state.m_always_update) {
626 const auto& navigation = propagation.navigation();
627 auto& stepping = propagation.stepping();
630 assert(navigation.is_on_surface() || !navigation.is_alive());
632 DETRAY_VERBOSE_HOST_DEVICE(
"Actor: Update the track parameters");
644 assert(!stepping().is_invalid());
650 detail::estimate_external_mask_tolerance(
651 bound_params, propagation,
655 DETRAY_DEBUG_HOST(
"Actor: Updated bound param.:\n" << bound_params);
661template <
typename algebra_t,
typename... transporter_observers>
662using parameter_updater =
664 parameter_setter<algebra_t>>;
Composition of actors.
Definition composite_actor.hpp:37
Unique identifier for geometry objects, based on the ACTS GeometryIdentifier.
Definition identifier.hpp:36
constexpr auto shape_id() const
Definition surface.hpp:142
constexpr auto transform(const context &ctx) const -> const transform3_type &
Definition surface.hpp:197
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
constexpr auto free_to_path_derivative(const context &ctx, const vector3_type &pos, const vector3_type &dir, const vector3_type &dtds) const
Definition tracking_surface.hpp:137
Select a number of types from another registry and map their IDs to a continuous range of new type in...
Definition type_registry.hpp:102
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
get_vector3D_t< A, T > dvector3D
Three-dimensional vector type for algebra A and value type T.
Definition algebra.hpp:80
dmatrix< algebra_t, e_bound_size, e_bound_size > bound_matrix
Covariance matrix type for bound track parametrization.
Definition track_parametrization.hpp:81
get_transform3D_t< A, T > dtransform3D
Three-dimensional transform type for algebra A and value type T.
Definition algebra.hpp:84
get_matrix_t< A, R, C, T > dmatrix
R by C matrix type for algebra A and value type T.
Definition algebra.hpp:88
get_point3D_t< A, T > dpoint3D
Three-dimensional point type for algebra A and value type T.
Definition algebra.hpp:72
free_parameters_vector< algebra_t > free_track_parameters
The free track parameters consist only of the parameter vector.
Definition free_track_parameters.hpp:249
Configuration of noise estimation.
Definition parameter_updater.hpp:36
bool estimate_scattering_noise
Estimate mask tolerance for navigation to for compensate scattering.
Definition parameter_updater.hpp:42
float accumulated_error
Percentage of total track path to assume as accumulated error.
Definition parameter_updater.hpp:38
int n_stddev
Number of standard deviations to assume to model the scattering noise.
Definition parameter_updater.hpp:40
Set the free track parameters in the stepper state, in case observing actors (e.g.
Definition parameter_updater.hpp:607
parameter_updater_state< algebra_t > state
Access the same parameter updater state as the parameter transporter.
Definition parameter_updater.hpp:609
void operator()(state &updater_state, propagator_state_t &propagation, const parameter_transporter_result< algebra_t > &res) const
Actor interface: Observer to the parameter transporter and its observers.
Definition parameter_updater.hpp:617
Visitor computing position derivatives with respect to direction angles.
Definition parameter_updater.hpp:312
constexpr dmatrix< algebra_t, 3, 2 > operator()(const frame_t &, const transform3_type &trf3, const free_track_parameters_type ¶ms, const dmatrix< algebra_t, 3, 2 > &ddir_dangle) const
Compute position derivatives with respect to direction angles.
Definition parameter_updater.hpp:320
Visitors to the surface local coordinate frameCompute position derivatives with respect to local coor...
Definition parameter_updater.hpp:296
constexpr dmatrix< algebra_t, 3, 2 > operator()(const frame_t &, const transform3_type &trf3, const free_track_parameters_type ¶ms) const
Definition parameter_updater.hpp:302
Visitor computing local-coordinate derivatives with respect to position.
Definition parameter_updater.hpp:331
constexpr dmatrix< algebra_t, 2, 3 > operator()(const frame_t &, const transform3_type &trf3, const stepper_state_t &stepping) const
Compute local-coordinate derivatives with respect to position.
Definition parameter_updater.hpp:339
Filter the masks of a detector according to the local frame type.
Definition parameter_updater.hpp:285
typename mask_t::local_frame type
Extract the local frame associated with a mask.
Definition parameter_updater.hpp:290
Result of the param. transporter: bound track parameters at dest. sf.
Definition parameter_updater.hpp:210
constexpr bound_track_parameters< algebra_t > & destination_params()
Definition parameter_updater.hpp:245
constexpr const bound_track_parameters< algebra_t > & destination_params() const
Definition parameter_updater.hpp:236
constexpr parameter_transporter_result()=default
Construct an empty transporter result.
constexpr parameter_transporter_result(actor::status stat, bound_track_parameters< algebra_t > ¶ms)
Parameterized constructor using destination parameters.
Definition parameter_updater.hpp:228
friend std::ostream & operator<<(std::ostream &os, const parameter_transporter_result< algebra_t > &res)
Definition parameter_updater.hpp:254
constexpr parameter_transporter_result(actor::status stat, bound_track_parameters< algebra_t > *params_ptr)
Parameterized constructor using a pointer to the destination parameters.
Definition parameter_updater.hpp:218
Transport the free track parameters at the destination surface and the covariance at the departure su...
Definition parameter_updater.hpp:269
bound_matrix< algebra_t > bound_matrix_type
Bound matrix type (bound covariance).
Definition parameter_updater.hpp:277
dtransform3D< algebra_t > transform3_type
Transformation type used for surface-frame Jacobians.
Definition parameter_updater.hpp:271
free_track_parameters< algebra_t > free_track_parameters_type
The current free track parameters in the stepper algorithm.
Definition parameter_updater.hpp:273
constexpr bound_matrix_type get_full_jacobian(propagator_state_t &propagation, const bound_track_parameters_type &departure_params) const
Assemble the full bound-to-bound Jacobian for this propagation step.
Definition parameter_updater.hpp:456
result operator()(state &updater_state, propagator_state_t &propagation) const
Actor interface.
Definition parameter_updater.hpp:355
bound_track_parameters< algebra_t > bound_track_parameters_type
The track parameters bound to the current sensitive/material surface.
Definition parameter_updater.hpp:275
parameter_updater_state< algebra_t > state
Use the parameter updater state.
Definition parameter_updater.hpp:280
parameter_transporter_result< algebra_t > result
Result returned to observers after transporting parameters.
Definition parameter_updater.hpp:282
State of the parameter updater.
Definition parameter_updater.hpp:48
noise_cfg & noise_estimation_cfg()
Definition parameter_updater.hpp:150
constexpr void set_full_jacobian(const bound_matrix< algebra_t > &jac)
Set new full Jacbian.
Definition parameter_updater.hpp:182
constexpr void init(const free_track_parameters< algebra_t > &free_params)
Initialize the state from free track parameters.
Definition parameter_updater.hpp:106
const noise_cfg & noise_estimation_cfg() const
Definition parameter_updater.hpp:146
void notify_on_initial(const bool do_notify=true)
Notify the observing actors on the initial propagation surface (i.e.
Definition parameter_updater.hpp:140
constexpr void init(const bound_track_parameters< algebra_t > &bound_params)
Initialize the state from bound track parameters.
Definition parameter_updater.hpp:123
constexpr bound_track_parameters< algebra_t > & bound_params()
Definition parameter_updater.hpp:162
constexpr void set_full_jacobian(bound_matrix< algebra_t > *jac_ptr)
Set new full Jacbian.
Definition parameter_updater.hpp:190
void always_update(const bool do_update=true)
Always update the track parameters in the stepper state.
Definition parameter_updater.hpp:132
constexpr const bound_matrix< algebra_t > & full_jacobian() const
Definition parameter_updater.hpp:174
constexpr parameter_updater_state()=default
Construct an empty updater state.
constexpr parameter_updater_state(const propagation::config &cfg, const free_track_parameters< algebra_t > &free_params, bound_matrix< algebra_t > *full_jac=nullptr)
Start from free track parameters.
Definition parameter_updater.hpp:73
constexpr const bound_track_parameters< algebra_t > & bound_params() const
Definition parameter_updater.hpp:155
constexpr parameter_updater_state(const propagation::config &cfg, const bound_track_parameters< algebra_t > &bound_params, bound_matrix< algebra_t > *full_jac=nullptr)
Start from bound track parameters.
Definition parameter_updater.hpp:93
constexpr bool has_full_jacobian() const
Definition parameter_updater.hpp:168
constexpr parameter_updater_state(const propagation::config &cfg, bound_matrix< algebra_t > *full_jac=nullptr)
Start without explicit track parameters.
Definition parameter_updater.hpp:60
Result of the principal actor to be passed to the obsevers.
Definition base_actor.hpp:34
actor::status status
Navigation status reported by the principal actor.
Definition base_actor.hpp:36
Base class actor implementation.
Definition base_actor.hpp:20
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
Frame and Jacobian data associated with a free track's curvilinear frame.
Definition curvilinear_frame.hpp:25
bound_vector_type m_bound_vec
Bound curvilinear parameters of the reference track.
Definition curvilinear_frame.hpp:68
vector3_type dir() const
Definition free_track_parameters.hpp:128
point3_type pos() const
Definition free_track_parameters.hpp:110
Configuration of the propagation.
Definition propagation_config.hpp:23