Skip to content

Commit a6c9291

Browse files
committed
Adapt actor chain for empty state and to produce actor state tuple if states are default constructible
1 parent fde92e5 commit a6c9291

15 files changed

+243
-399
lines changed

core/include/detray/navigation/policies.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct stepper_default_policy : actor {
7474

7575
// Not a severe change to track state expected
7676
// Policy is called after stepsize update -> use prev. step size
77-
if (math::fabs(stepping.prev_step_size()) <
77+
if (math::fabs(stepping.step_size()) <
7878
math::fabs(
7979
stepping.constraints().template size<>(stepping.direction())) -
8080
pol_state.tol) {
@@ -112,7 +112,7 @@ struct stepper_rk_policy : actor {
112112
auto &navigation = propagation._navigation;
113113

114114
// Policy is called after stepsize update -> use prev. step size
115-
const scalar rel_correction{(stepping.prev_step_size() - navigation()) /
115+
const scalar rel_correction{(stepping.step_size() - navigation()) /
116116
navigation()};
117117

118118
// Large correction to the stepsize - re-initialize the volume

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-40
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,14 +31,14 @@ struct parameter_resetter : actor {
6531
return;
6632
}
6733

68-
using geo_cxt_t =
69-
typename propagator_state_t::detector_type::geometry_context;
70-
const geo_cxt_t ctx{};
34+
typename propagator_state_t::detector_type::geometry_context ctx{};
7135

72-
// Surface
36+
// Update free params after bound params were changed by actors
7337
const auto sf = navigation.get_surface();
38+
stepping() = sf.bound_to_free_vector(ctx, stepping.bound_params());
7439

75-
sf.template visit_mask<kernel>(sf.transform(ctx), sf.index(), stepping);
40+
// Reset jacobian transport to identity matrix
41+
stepping.reset_transport_jacobian();
7642
}
7743
};
7844

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

+33-39
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,51 @@ struct parameter_transporter : actor {
9483
return;
9584
}
9685

97-
using detector_type = typename propagator_state_t::detector_type;
98-
using geo_cxt_t = typename detector_type::geometry_context;
99-
const geo_cxt_t ctx{};
86+
typename propagator_state_t::detector_type::geometry_context ctx{};
10087

10188
// Current Surface
10289
const auto sf = navigation.get_surface();
10390

91+
// Bound track params of departure surface
92+
auto& bound_params = stepping.bound_params();
93+
10494
// Covariance is transported only when the previous surface is an
10595
// actual tracking surface. (i.e. This disables the covariance transport
10696
// from curvilinear frame)
107-
if (!detail::is_invalid_value(stepping.prev_sf_index())) {
97+
if (!bound_params.surface_link().is_invalid()) {
10898

10999
// Previous surface
110-
tracking_surface<detector_type> prev_sf{navigation.detector(),
111-
stepping.prev_sf_index()};
100+
tracking_surface prev_sf{navigation.detector(),
101+
bound_params.surface_link()};
112102

113-
const bound_to_free_matrix<algebra_t> bound_to_free_jacobian =
114-
prev_sf.bound_to_free_jacobian(ctx, stepping.bound_params());
103+
const bound_to_free_matrix_t bound_to_free_jacobian =
104+
prev_sf.bound_to_free_jacobian(ctx, bound_params);
115105

106+
auto vol = navigation.get_volume();
107+
const auto vol_mat_ptr =
108+
vol.has_material() ? vol.material_parameters(stepping().pos())
109+
: nullptr;
116110
stepping.set_full_jacobian(
117111
sf.template visit_mask<get_full_jacobian_kernel>(
118-
sf.transform(ctx), bound_to_free_jacobian, propagation));
112+
sf.transform(ctx), bound_to_free_jacobian, vol_mat_ptr,
113+
propagation._stepping));
119114

120115
// Calculate surface-to-surface covariance transport
121116
const bound_matrix_t new_cov =
122-
stepping.full_jacobian() *
123-
stepping.bound_params().covariance() *
117+
stepping.full_jacobian() * bound_params.covariance() *
124118
matrix_operator().transpose(stepping.full_jacobian());
119+
125120
stepping.bound_params().set_covariance(new_cov);
126121
}
127122

128123
// Convert free to bound vector
129-
stepping.bound_params().set_parameter_vector(
124+
bound_params.set_parameter_vector(
130125
sf.free_to_bound_vector(ctx, stepping()));
131126

132127
// Set surface link
133-
stepping.bound_params().set_surface_link(sf.barcode());
134-
135-
return;
128+
bound_params.set_surface_link(sf.barcode());
136129
}
130+
137131
}; // namespace detray
138132

139133
} // 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)