Skip to content

Commit bb3139f

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 a6c9291 commit bb3139f

File tree

21 files changed

+346
-315
lines changed

21 files changed

+346
-315
lines changed

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

Lines changed: 0 additions & 45 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

@@ -89,7 +153,7 @@ struct parameter_transporter : actor {
89153
const auto sf = navigation.get_surface();
90154

91155
// Bound track params of departure surface
92-
auto& bound_params = stepping.bound_params();
156+
auto& bound_params = transporter_state.bound_params();
93157

94158
// Covariance is transported only when the previous surface is an
95159
// actual tracking surface. (i.e. This disables the covariance transport
@@ -107,17 +171,17 @@ struct parameter_transporter : actor {
107171
const auto vol_mat_ptr =
108172
vol.has_material() ? vol.material_parameters(stepping().pos())
109173
: nullptr;
110-
stepping.set_full_jacobian(
174+
transporter_state.set_full_jacobian(
111175
sf.template visit_mask<get_full_jacobian_kernel>(
112176
sf.transform(ctx), bound_to_free_jacobian, vol_mat_ptr,
113177
propagation._stepping));
114178

115179
// Calculate surface-to-surface covariance transport
116-
const bound_matrix_t new_cov =
117-
stepping.full_jacobian() * bound_params.covariance() *
118-
matrix_operator().transpose(stepping.full_jacobian());
180+
const bound_matrix_type new_cov =
181+
transporter_state.full_jacobian() * bound_params.covariance() *
182+
matrix_operator().transpose(transporter_state.full_jacobian());
119183

120-
stepping.bound_params().set_covariance(new_cov);
184+
bound_params.set_covariance(new_cov);
121185
}
122186

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

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

133233
} // 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
// @Todo: Make context part of propagation state
133136
using detector_type = typename propagator_state_t::detector_type;
@@ -143,7 +146,7 @@ struct pointwise_material_interactor : actor {
143146
auto &stepping = prop_state._stepping;
144147

145148
this->update(geo_context_type{}, stepping.particle_hypothesis(),
146-
stepping.bound_params(), interactor_state,
149+
transporter_state.bound_params(), interactor_state,
147150
static_cast<int>(navigation.direction()),
148151
navigation.get_surface());
149152
}

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,31 +56,16 @@ 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,
83-
const detector_t &det)
84-
: m_bound_params(bound_params) {
68+
const detector_t &det) {
8569

8670
// Departure surface
8771
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)