Skip to content

Commit c044806

Browse files
committed
Move the bound track parameters and full jacobian to parameter transporter and merge the actors that modify the bound track parameters
1 parent 9c0f9af commit c044806

File tree

21 files changed

+346
-314
lines changed

21 files changed

+346
-314
lines changed

core/include/detray/propagator/actors/parameter_resetter.hpp

Lines changed: 0 additions & 44 deletions
This file was deleted.

core/include/detray/propagator/actors/parameter_transporter.hpp renamed to core/include/detray/propagator/actors/parameter_updater.hpp

Lines changed: 110 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "detray/geometry/tracking_surface.hpp"
1414
#include "detray/propagator/base_actor.hpp"
1515
#include "detray/propagator/detail/jacobian_engine.hpp"
16+
#include "detray/utils/curvilinear_frame.hpp"
1617

1718
namespace detray {
1819

@@ -24,19 +25,81 @@ struct parameter_transporter : actor {
2425
using scalar_type = dscalar<algebra_t>;
2526
// Transformation matching this struct
2627
using transform3_type = dtransform3D<algebra_t>;
28+
// The track parameters bound to the current sensitive/material surface
29+
using bound_track_parameters_type = bound_track_parameters<algebra_t>;
2730
// Matrix actor
2831
using matrix_operator = dmatrix_operator<algebra_t>;
2932
// bound matrix type
30-
using bound_matrix_t = bound_matrix<algebra_t>;
33+
using bound_matrix_type = bound_matrix<algebra_t>;
3134
// Matrix type for bound to free jacobian
3235
using bound_to_free_matrix_t = bound_to_free_matrix<algebra_t>;
3336
/// @}
3437

38+
struct state {
39+
40+
friend parameter_transporter;
41+
42+
state() = default;
43+
44+
/// Start from free track parameters
45+
DETRAY_HOST_DEVICE
46+
explicit state(const free_track_parameters<algebra_t>& free_params) {
47+
48+
curvilinear_frame<algebra_t> cf(free_params);
49+
50+
// Set bound track parameters
51+
m_bound_params.set_parameter_vector(cf.m_bound_vec);
52+
53+
// A dummy covariance - should not be used
54+
m_bound_params.set_covariance(
55+
matrix_operator()
56+
.template identity<e_bound_size, e_bound_size>());
57+
58+
// An invalid barcode - should not be used
59+
m_bound_params.set_surface_link(geometry::barcode{});
60+
}
61+
62+
/// Start from bound track parameters
63+
DETRAY_HOST_DEVICE
64+
explicit state(const bound_track_parameters_type& bound_params)
65+
: m_bound_params{bound_params} {}
66+
67+
/// @returns bound track parameters - const access
68+
DETRAY_HOST_DEVICE
69+
bound_track_parameters_type& bound_params() { return m_bound_params; }
70+
71+
/// @returns bound track parameters.
72+
DETRAY_HOST_DEVICE
73+
const bound_track_parameters_type& bound_params() const {
74+
return m_bound_params;
75+
}
76+
77+
/// @returns the current full Jacbian.
78+
DETRAY_HOST_DEVICE
79+
inline const bound_matrix_type& full_jacobian() const {
80+
return m_full_jacobian;
81+
}
82+
83+
private:
84+
/// Set new full Jacbian.
85+
DETRAY_HOST_DEVICE
86+
inline void set_full_jacobian(const bound_matrix_type& jac) {
87+
m_full_jacobian = jac;
88+
}
89+
90+
/// Full jacobian
91+
bound_matrix_type m_full_jacobian =
92+
matrix_operator().template identity<e_bound_size, e_bound_size>();
93+
94+
/// bound covariance
95+
bound_track_parameters_type m_bound_params;
96+
};
97+
3598
struct get_full_jacobian_kernel {
3699

37100
template <typename mask_group_t, typename index_t,
38101
typename stepper_state_t>
39-
DETRAY_HOST_DEVICE inline bound_matrix_t operator()(
102+
DETRAY_HOST_DEVICE inline bound_matrix_type operator()(
40103
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
41104
const transform3_type& trf3,
42105
const bound_to_free_matrix_t& bound_to_free_jacobian,
@@ -73,7 +136,8 @@ struct parameter_transporter : actor {
73136
};
74137

75138
template <typename propagator_state_t>
76-
DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const {
139+
DETRAY_HOST_DEVICE void operator()(state& transporter_state,
140+
propagator_state_t& propagation) const {
77141
auto& stepping = propagation._stepping;
78142
const auto& navigation = propagation._navigation;
79143

@@ -90,7 +154,7 @@ struct parameter_transporter : actor {
90154
const auto sf = navigation.get_surface();
91155

92156
// Bound track params of departure surface
93-
auto& bound_params = stepping.bound_params();
157+
auto& bound_params = transporter_state.bound_params();
94158

95159
// Covariance is transported only when the previous surface is an
96160
// actual tracking surface. (i.e. This disables the covariance transport
@@ -108,17 +172,17 @@ struct parameter_transporter : actor {
108172
const auto vol_mat_ptr =
109173
vol.has_material() ? vol.material_parameters(stepping().pos())
110174
: nullptr;
111-
stepping.set_full_jacobian(
175+
transporter_state.set_full_jacobian(
112176
sf.template visit_mask<get_full_jacobian_kernel>(
113177
sf.transform(gctx), bound_to_free_jacobian, vol_mat_ptr,
114178
propagation._stepping));
115179

116180
// Calculate surface-to-surface covariance transport
117-
const bound_matrix_t new_cov =
118-
stepping.full_jacobian() * bound_params.covariance() *
119-
matrix_operator().transpose(stepping.full_jacobian());
181+
const bound_matrix_type new_cov =
182+
transporter_state.full_jacobian() * bound_params.covariance() *
183+
matrix_operator().transpose(transporter_state.full_jacobian());
120184

121-
stepping.bound_params().set_covariance(new_cov);
185+
bound_params.set_covariance(new_cov);
122186
}
123187

124188
// Convert free to bound vector
@@ -128,7 +192,43 @@ struct parameter_transporter : actor {
128192
// Set surface link
129193
bound_params.set_surface_link(sf.barcode());
130194
}
195+
};
196+
197+
/// Update the stepper state after the bound track parameters were updated
198+
template <typename algebra_t>
199+
struct parameter_resetter : actor {
200+
201+
template <typename propagator_state_t>
202+
DETRAY_HOST_DEVICE void operator()(
203+
const parameter_transporter<algebra_t>::state& transporter_state,
204+
propagator_state_t& propagation) const {
131205

132-
}; // namespace detray
206+
const auto& navigation = propagation._navigation;
207+
auto& stepping = propagation._stepping;
208+
209+
// Do covariance transport when the track is on surface
210+
if (!(navigation.is_on_sensitive() ||
211+
navigation.encountered_sf_material())) {
212+
return;
213+
}
214+
215+
typename propagator_state_t::detector_type::geometry_context ctx{};
216+
217+
// Update free params after bound params were changed by actors
218+
const auto sf = navigation.get_surface();
219+
stepping() =
220+
sf.bound_to_free_vector(ctx, transporter_state.bound_params());
221+
222+
// Reset jacobian transport to identity matrix
223+
stepping.reset_transport_jacobian();
224+
}
225+
};
226+
227+
/// Call actors that depend on the bound track parameters safely together with
228+
/// the parameter transporter and parameter resetter
229+
template <typename algebra_t, typename... transporter_observers>
230+
using parameter_updater =
231+
composite_actor<detray::tuple, parameter_transporter<algebra_t>,
232+
transporter_observers..., parameter_resetter<algebra_t>>;
133233

134234
} // namespace detray

core/include/detray/propagator/actors/pointwise_material_interactor.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "detray/materials/detail/concepts.hpp"
1515
#include "detray/materials/detail/material_accessor.hpp"
1616
#include "detray/materials/interaction.hpp"
17+
#include "detray/propagator/actors/parameter_updater.hpp"
1718
#include "detray/propagator/base_actor.hpp"
1819
#include "detray/tracks/bound_track_parameters.hpp"
1920
#include "detray/utils/ranges.hpp"
@@ -127,7 +128,9 @@ struct pointwise_material_interactor : actor {
127128

128129
template <typename propagator_state_t>
129130
DETRAY_HOST_DEVICE inline void operator()(
130-
state &interactor_state, propagator_state_t &prop_state) const {
131+
state &interactor_state,
132+
parameter_transporter<algebra_t>::state &transporter_state,
133+
propagator_state_t &prop_state) const {
131134

132135
interactor_state.reset();
133136

@@ -139,7 +142,7 @@ struct pointwise_material_interactor : actor {
139142
auto &stepping = prop_state._stepping;
140143

141144
this->update(prop_state._context, stepping.particle_hypothesis(),
142-
stepping.bound_params(), interactor_state,
145+
transporter_state.bound_params(), interactor_state,
143146
static_cast<int>(navigation.direction()),
144147
navigation.get_surface());
145148
}

core/include/detray/propagator/base_actor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class composite_actor final : public actor_impl_t {
4949
/// derived from another composition (final).
5050
using actor_type = actor_impl_t;
5151
using state = typename actor_type::state;
52+
using observer_states = detray::tuple<typename observers::state...>;
5253

5354
/// Call to the implementation of the actor (the actor possibly being an
5455
/// observer itself)

core/include/detray/propagator/base_stepper.hpp

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "detray/propagator/constrained_step.hpp"
1818
#include "detray/propagator/stepping_config.hpp"
1919
#include "detray/tracks/tracks.hpp"
20-
#include "detray/utils/curvilinear_frame.hpp"
2120

2221
namespace detray {
2322

@@ -57,32 +56,17 @@ class base_stepper {
5756
/// @note It has to cast into a const track via the call operation.
5857
struct state {
5958

60-
/// Sets track parameters.
61-
DETRAY_HOST_DEVICE
62-
explicit state(const free_track_parameters_type &free_params)
63-
: m_track(free_params) {
64-
65-
curvilinear_frame<algebra_t> cf(free_params);
66-
67-
// Set bound track parameters
68-
m_bound_params.set_parameter_vector(cf.m_bound_vec);
69-
70-
// A dummy covariance - should not be used
71-
m_bound_params.set_covariance(
72-
matrix_operator()
73-
.template identity<e_bound_size, e_bound_size>());
74-
75-
// An invalid barcode - should not be used
76-
m_bound_params.set_surface_link(geometry::barcode{});
77-
}
59+
/// Construct state from free track parameters.
60+
DETRAY_HOST_DEVICE explicit state(
61+
const free_track_parameters_type &free_params)
62+
: m_track{free_params} {}
7863

79-
/// Sets track parameters from bound track parameter.
64+
/// Sets track parameters from bound track parameters.
8065
template <typename detector_t>
8166
DETRAY_HOST_DEVICE state(
8267
const bound_track_parameters_type &bound_params,
8368
const detector_t &det,
84-
const typename detector_t::geometry_context &ctx)
85-
: m_bound_params(bound_params) {
69+
const typename detector_t::geometry_context &ctx) {
8670

8771
// Departure surface
8872
const auto sf = tracking_surface{det, bound_params.surface_link()};
@@ -99,16 +83,6 @@ class base_stepper {
9983
DETRAY_HOST_DEVICE
10084
const free_track_parameters_type &operator()() const { return m_track; }
10185

102-
/// @returns bound track parameters - const access
103-
DETRAY_HOST_DEVICE
104-
bound_track_parameters_type &bound_params() { return m_bound_params; }
105-
106-
/// @returns bound track parameters - non-const access
107-
DETRAY_HOST_DEVICE
108-
const bound_track_parameters_type &bound_params() const {
109-
return m_bound_params;
110-
}
111-
11286
/// Get stepping direction
11387
DETRAY_HOST_DEVICE
11488
inline step::direction direction() const {
@@ -181,18 +155,6 @@ class base_stepper {
181155
return m_jac_transport;
182156
}
183157

184-
/// @returns the current full Jacbian.
185-
DETRAY_HOST_DEVICE
186-
inline const bound_matrix_type &full_jacobian() const {
187-
return m_full_jacobian;
188-
}
189-
190-
/// Set new full Jacbian.
191-
DETRAY_HOST_DEVICE
192-
inline void set_full_jacobian(const bound_matrix_type &jac) {
193-
m_full_jacobian = jac;
194-
}
195-
196158
/// Reset transport Jacbian.
197159
DETRAY_HOST_DEVICE
198160
inline void reset_transport_jacobian() {
@@ -231,13 +193,6 @@ class base_stepper {
231193
free_matrix_type m_jac_transport =
232194
matrix_operator().template identity<e_free_size, e_free_size>();
233195

234-
/// Full jacobian
235-
bound_matrix_type m_full_jacobian =
236-
matrix_operator().template identity<e_bound_size, e_bound_size>();
237-
238-
/// Bound covariance
239-
bound_track_parameters_type m_bound_params;
240-
241196
/// Free track parameters
242197
free_track_parameters_type m_track;
243198

0 commit comments

Comments
 (0)