Skip to content

Commit 9c0f9af

Browse files
authored
Adapt actor chain for empty state and to produce actor state tuple if states are default constructible (#879)
Shift the update of the step size in the stepper, so that we go from a "previous step size" to a "next step size". - Remove the volume material pointer from the state and instead get it from the navigator hand it through to the functions that need it - Remove the "path from surface" and reimplement it in the actors that use it - Remove the next_surface_aborter, which is superseded by the ckf_aborter in traccc (need to move the test to traccc) - Remove the previous surface index and instead use the surface link on the bound track parameters before they are updated - Remove the stepping direction and calculate it on the fly Also streamlines the parameter resetter, as the jacobians are already default initialized correctly and a separate kernel is not needed, since the relevant functionality already exists on the tracking_surface
1 parent 626966b commit 9c0f9af

15 files changed

+248
-403
lines changed

core/include/detray/navigation/policies.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ struct stepper_default_policy : actor {
7373
auto &navigation = propagation._navigation;
7474

7575
// Not a severe change to track state expected
76-
// Policy is called after stepsize update -> use prev. step size
77-
if (math::fabs(stepping.prev_step_size()) <
76+
if (math::fabs(stepping.step_size()) <
7877
math::fabs(
7978
stepping.constraints().template size<>(stepping.direction())) -
8079
pol_state.tol) {
@@ -111,20 +110,19 @@ struct stepper_rk_policy : actor {
111110
const auto &stepping = propagation._stepping;
112111
auto &navigation = propagation._navigation;
113112

114-
// Policy is called after stepsize update -> use prev. step size
115-
const scalar rel_correction{(stepping.prev_step_size() - navigation()) /
113+
// How strongly did the RKN algorithm reduce the step size?
114+
const scalar rel_correction{(stepping.step_size() - navigation()) /
116115
navigation()};
117116

118117
// Large correction to the stepsize - re-initialize the volume
119118
if (rel_correction > pol_state.m_threshold_no_trust) {
120-
// Re-evaluate only next candidate
121119
navigation.set_no_trust();
122120
}
123-
// Medium correction - re-evaluate the current candidates
121+
// Medium correction - re-evaluate all current candidates
124122
else if (rel_correction > pol_state.m_threshold_fair_trust) {
125-
// Re-evaluate all candidates
126123
navigation.set_fair_trust();
127124
} else {
125+
// Small correction - re-evaluate only the next candidate
128126
navigation.set_high_trust();
129127
}
130128
}

core/include/detray/propagator/actor_chain.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,19 @@ class actor_chain {
6060
// Only possible if each state is default initializable
6161
if constexpr ((std::default_initializable<typename actors_t::state> &&
6262
...)) {
63-
tuple_t<typename actors_t::state...> states{};
64-
65-
return std::make_tuple(
66-
states,
67-
make_ref_tuple(
68-
states, std::make_index_sequence<sizeof...(actors_t)>{}));
63+
return tuple_t<typename actors_t::state...>{};
6964
} else {
7065
return std::nullopt;
7166
}
7267
}
7368

69+
/// @returns a tuple of reference for every state in the tuple @param t
70+
DETRAY_HOST_DEVICE static constexpr state make_ref_tuple(
71+
tuple_t<typename actors_t::state...> &t) {
72+
return make_ref_tuple(t,
73+
std::make_index_sequence<sizeof...(actors_t)>{});
74+
}
75+
7476
private:
7577
/// Call the actors. Either single actor or composition.
7678
///

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

-24
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,4 @@ struct target_aborter : actor {
9595
}
9696
};
9797

98-
/// Aborter triggered when the next surface is reached
99-
struct next_surface_aborter : actor {
100-
struct state {
101-
// minimal step length to prevent from staying on the same surface
102-
scalar min_step_length = 0.f;
103-
bool success = false;
104-
};
105-
106-
template <typename propagator_state_t>
107-
DETRAY_HOST_DEVICE void operator()(state &abrt_state,
108-
propagator_state_t &prop_state) const {
109-
110-
auto &navigation = prop_state._navigation;
111-
auto &stepping = prop_state._stepping;
112-
113-
// Abort at the next sensitive surface
114-
if (navigation.is_on_sensitive() &&
115-
stepping.path_from_surface() > abrt_state.min_step_length) {
116-
prop_state._heartbeat &= navigation.abort();
117-
abrt_state.success = true;
118-
}
119-
}
120-
};
121-
12298
} // namespace detray

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

+6-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Detray library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2022-2023 CERN for the benefit of the ACTS project
3+
* (c) 2022-2024 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -19,40 +19,6 @@ namespace detray {
1919
template <typename algebra_t>
2020
struct parameter_resetter : actor {
2121

22-
using scalar_type = dscalar<algebra_t>;
23-
24-
/// Mask store visitor
25-
struct kernel {
26-
27-
// Matrix actor
28-
using transform3_type = dtransform3D<algebra_t>;
29-
using matrix_operator = dmatrix_operator<algebra_t>;
30-
31-
template <typename mask_group_t, typename index_t,
32-
typename stepper_state_t>
33-
DETRAY_HOST_DEVICE inline void operator()(
34-
const mask_group_t& mask_group, const index_t& index,
35-
const transform3_type& trf3, const dindex sf_idx,
36-
stepper_state_t& stepping) const {
37-
38-
// Note: How is it possible with "range"???
39-
const auto& mask = mask_group[index];
40-
41-
// Reset the free vector
42-
stepping() = detail::bound_to_free_vector(trf3, mask,
43-
stepping.bound_params());
44-
45-
// Reset the path length
46-
stepping.reset_path_from_surface();
47-
48-
// Reset jacobian transport to identity matrix
49-
stepping.reset_transport_jacobian();
50-
51-
// Reset the surface index
52-
stepping.set_prev_sf_index(sf_idx);
53-
}
54-
};
55-
5622
template <typename propagator_state_t>
5723
DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const {
5824

@@ -65,11 +31,13 @@ struct parameter_resetter : actor {
6531
return;
6632
}
6733

68-
// Surface
34+
// Update free params after bound params were changed by actors
6935
const auto sf = navigation.get_surface();
36+
stepping() = sf.bound_to_free_vector(propagation._context,
37+
stepping.bound_params());
7038

71-
sf.template visit_mask<kernel>(sf.transform(propagation._context),
72-
sf.index(), stepping);
39+
// Reset jacobian transport to identity matrix
40+
stepping.reset_transport_jacobian();
7341
}
7442
};
7543

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

+35-40
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,27 @@ struct parameter_transporter : actor {
2121

2222
/// @name Type definitions for the struct
2323
/// @{
24-
24+
using scalar_type = dscalar<algebra_t>;
2525
// Transformation matching this struct
2626
using transform3_type = dtransform3D<algebra_t>;
27-
// scalar_type
28-
using scalar_type = dscalar<algebra_t>;
2927
// Matrix actor
3028
using matrix_operator = dmatrix_operator<algebra_t>;
31-
// 2D matrix type
32-
template <std::size_t ROWS, std::size_t COLS>
33-
using matrix_type = dmatrix<algebra_t, ROWS, COLS>;
3429
// bound matrix type
3530
using bound_matrix_t = bound_matrix<algebra_t>;
31+
// Matrix type for bound to free jacobian
32+
using bound_to_free_matrix_t = bound_to_free_matrix<algebra_t>;
3633
/// @}
3734

3835
struct get_full_jacobian_kernel {
3936

4037
template <typename mask_group_t, typename index_t,
41-
typename propagator_state_t>
38+
typename stepper_state_t>
4239
DETRAY_HOST_DEVICE inline bound_matrix_t operator()(
4340
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
4441
const transform3_type& trf3,
45-
const bound_to_free_matrix<algebra_t>& bound_to_free_jacobian,
46-
const propagator_state_t& propagation) const {
42+
const bound_to_free_matrix_t& bound_to_free_jacobian,
43+
const material<scalar_type>* vol_mat_ptr,
44+
const stepper_state_t& stepping) const {
4745

4846
using frame_t = typename mask_group_t::value_type::shape::
4947
template local_frame_type<algebra_t>;
@@ -54,32 +52,23 @@ struct parameter_transporter : actor {
5452
using free_to_bound_matrix_t =
5553
typename jacobian_engine_t::free_to_bound_matrix_type;
5654

57-
// Stepper and Navigator states
58-
auto& stepping = propagation._stepping;
59-
60-
// Free vector
61-
const auto& free_params = stepping();
62-
6355
// Free to bound jacobian at the destination surface
6456
const free_to_bound_matrix_t free_to_bound_jacobian =
65-
jacobian_engine_t::free_to_bound_jacobian(trf3, free_params);
66-
67-
// Transport jacobian in free coordinate
68-
const free_matrix_t& free_transport_jacobian =
69-
stepping.transport_jacobian();
57+
jacobian_engine_t::free_to_bound_jacobian(trf3, stepping());
7058

7159
// Path correction factor
72-
free_matrix_t path_correction = jacobian_engine_t::path_correction(
73-
stepping().pos(), stepping().dir(), stepping.dtds(),
74-
stepping.dqopds(), trf3);
60+
const free_matrix_t path_correction =
61+
jacobian_engine_t::path_correction(
62+
stepping().pos(), stepping().dir(), stepping.dtds(),
63+
stepping.dqopds(vol_mat_ptr), trf3);
7564

7665
const free_matrix_t correction_term =
7766
matrix_operator()
7867
.template identity<e_free_size, e_free_size>() +
7968
path_correction;
8069

8170
return free_to_bound_jacobian * correction_term *
82-
free_transport_jacobian * bound_to_free_jacobian;
71+
stepping.transport_jacobian() * bound_to_free_jacobian;
8372
}
8473
};
8574

@@ -94,46 +83,52 @@ struct parameter_transporter : actor {
9483
return;
9584
}
9685

97-
using detector_type = typename propagator_state_t::detector_type;
86+
// Geometry context for this track
87+
const auto& gctx = propagation._context;
9888

9989
// Current Surface
10090
const auto sf = navigation.get_surface();
10191

92+
// Bound track params of departure surface
93+
auto& bound_params = stepping.bound_params();
94+
10295
// Covariance is transported only when the previous surface is an
10396
// actual tracking surface. (i.e. This disables the covariance transport
10497
// from curvilinear frame)
105-
if (!detail::is_invalid_value(stepping.prev_sf_index())) {
98+
if (!bound_params.surface_link().is_invalid()) {
10699

107100
// Previous surface
108-
tracking_surface<detector_type> prev_sf{navigation.detector(),
109-
stepping.prev_sf_index()};
101+
tracking_surface prev_sf{navigation.detector(),
102+
bound_params.surface_link()};
110103

111-
const bound_to_free_matrix<algebra_t> bound_to_free_jacobian =
112-
prev_sf.bound_to_free_jacobian(propagation._context,
113-
stepping.bound_params());
104+
const bound_to_free_matrix_t bound_to_free_jacobian =
105+
prev_sf.bound_to_free_jacobian(gctx, bound_params);
114106

107+
auto vol = navigation.get_volume();
108+
const auto vol_mat_ptr =
109+
vol.has_material() ? vol.material_parameters(stepping().pos())
110+
: nullptr;
115111
stepping.set_full_jacobian(
116112
sf.template visit_mask<get_full_jacobian_kernel>(
117-
sf.transform(propagation._context), bound_to_free_jacobian,
118-
propagation));
113+
sf.transform(gctx), bound_to_free_jacobian, vol_mat_ptr,
114+
propagation._stepping));
119115

120116
// Calculate surface-to-surface covariance transport
121117
const bound_matrix_t new_cov =
122-
stepping.full_jacobian() *
123-
stepping.bound_params().covariance() *
118+
stepping.full_jacobian() * bound_params.covariance() *
124119
matrix_operator().transpose(stepping.full_jacobian());
120+
125121
stepping.bound_params().set_covariance(new_cov);
126122
}
127123

128124
// Convert free to bound vector
129-
stepping.bound_params().set_parameter_vector(
130-
sf.free_to_bound_vector(propagation._context, stepping()));
125+
bound_params.set_parameter_vector(
126+
sf.free_to_bound_vector(gctx, stepping()));
131127

132128
// Set surface link
133-
stepping.bound_params().set_surface_link(sf.barcode());
134-
135-
return;
129+
bound_params.set_surface_link(sf.barcode());
136130
}
131+
137132
}; // namespace detray
138133

139134
} // namespace detray

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

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct pointwise_material_interactor : actor {
3535

3636
struct state {
3737

38-
/// @TODO: Consider using the particle information in stepping::config
3938
/// Evaluated energy loss
4039
scalar_type e_loss{0.f};
4140
/// Evaluated projected scattering angle

0 commit comments

Comments
 (0)