Skip to content

Commit a320992

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

16 files changed

+287
-398
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

+49-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
/** Detray library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2022 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
*/
77

88
#pragma once
99

10-
#include <type_traits>
11-
#include <utility>
12-
10+
// Project include(s)
1311
#include "detray/definitions/detail/containers.hpp"
1412
#include "detray/definitions/detail/qualifiers.hpp"
13+
#include "detray/propagator/base_actor.hpp"
1514
#include "detray/utils/tuple_helpers.hpp"
1615

16+
// System include(s)
17+
#include <concepts>
18+
#include <optional>
19+
#include <type_traits>
20+
#include <utility>
21+
1722
namespace detray {
1823

1924
/// The interface to the actors and aborters in the propagation.
@@ -44,7 +49,29 @@ class actor_chain {
4449
}
4550

4651
/// @returns the actor list
47-
DETRAY_HOST_DEVICE const actor_list_type &actors() const { return _actors; }
52+
DETRAY_HOST_DEVICE const actor_list_type &actors() const {
53+
return m_actors;
54+
}
55+
56+
/// @returns a tuple of default constructible actor states and a
57+
/// corresponding tuple of references
58+
DETRAY_HOST_DEVICE
59+
static constexpr auto make_actor_states() {
60+
// Only possible if each state is default initializable
61+
if constexpr ((std::default_initializable<typename actors_t::state> &&
62+
...)) {
63+
return tuple_t<typename actors_t::state...>{};
64+
} else {
65+
return std::nullopt;
66+
}
67+
}
68+
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+
}
4875

4976
private:
5077
/// Call the actors. Either single actor or composition.
@@ -58,7 +85,13 @@ class actor_chain {
5885
actor_states_t &states,
5986
propagator_state_t &p_state) const {
6087
if constexpr (!typename actor_t::is_comp_actor()) {
61-
actr(detail::get<typename actor_t::state &>(states), p_state);
88+
// No actor state defined (empty)
89+
if constexpr (std::same_as<typename actor_t::state,
90+
detray::actor::state>) {
91+
actr(p_state);
92+
} else {
93+
actr(detail::get<typename actor_t::state &>(states), p_state);
94+
}
6295
} else {
6396
actr(states, p_state);
6497
}
@@ -73,11 +106,19 @@ class actor_chain {
73106
DETRAY_HOST_DEVICE inline void run(
74107
actor_states_t &states, propagator_state_t &p_state,
75108
std::index_sequence<indices...> /*ids*/) const {
76-
(run(detail::get<indices>(_actors), states, p_state), ...);
109+
(run(detail::get<indices>(m_actors), states, p_state), ...);
110+
}
111+
112+
/// @returns a tuple of reference for every state in the tuple @param t
113+
template <std::size_t... indices>
114+
DETRAY_HOST_DEVICE static constexpr state make_ref_tuple(
115+
tuple_t<typename actors_t::state...> &t,
116+
std::index_sequence<indices...> /*ids*/) {
117+
return detray::tie(detail::get<indices>(t)...);
77118
}
78119

79120
/// Tuple of actors
80-
actor_list_type _actors = {};
121+
actor_list_type m_actors = {};
81122
};
82123

83124
/// Empty actor chain (placeholder)

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

+7-44
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,45 +19,8 @@ namespace detray {
1919
template <typename algebra_t>
2020
struct parameter_resetter : actor {
2121

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

6225
const auto& navigation = propagation._navigation;
6326
auto& stepping = propagation._stepping;
@@ -68,14 +31,14 @@ struct parameter_resetter : actor {
6831
return;
6932
}
7033

71-
using geo_cxt_t =
72-
typename propagator_state_t::detector_type::geometry_context;
73-
const geo_cxt_t ctx{};
34+
typename propagator_state_t::detector_type::geometry_context ctx{};
7435

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

78-
sf.template visit_mask<kernel>(sf.transform(ctx), sf.index(), stepping);
40+
// Reset jacobian transport to identity matrix
41+
stepping.reset_transport_jacobian();
7942
}
8043
};
8144

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

+34-43
Original file line numberDiff line numberDiff line change
@@ -21,31 +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

38-
struct state {};
39-
4035
struct get_full_jacobian_kernel {
4136

4237
template <typename mask_group_t, typename index_t,
43-
typename propagator_state_t>
38+
typename stepper_state_t>
4439
DETRAY_HOST_DEVICE inline bound_matrix_t operator()(
4540
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
4641
const transform3_type& trf3,
47-
const bound_to_free_matrix<algebra_t>& bound_to_free_jacobian,
48-
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 {
4945

5046
using frame_t = typename mask_group_t::value_type::shape::
5147
template local_frame_type<algebra_t>;
@@ -56,38 +52,28 @@ struct parameter_transporter : actor {
5652
using free_to_bound_matrix_t =
5753
typename jacobian_engine_t::free_to_bound_matrix_type;
5854

59-
// Stepper and Navigator states
60-
auto& stepping = propagation._stepping;
61-
62-
// Free vector
63-
const auto& free_params = stepping();
64-
6555
// Free to bound jacobian at the destination surface
6656
const free_to_bound_matrix_t free_to_bound_jacobian =
67-
jacobian_engine_t::free_to_bound_jacobian(trf3, free_params);
68-
69-
// Transport jacobian in free coordinate
70-
const free_matrix_t& free_transport_jacobian =
71-
stepping.transport_jacobian();
57+
jacobian_engine_t::free_to_bound_jacobian(trf3, stepping());
7258

7359
// Path correction factor
74-
free_matrix_t path_correction = jacobian_engine_t::path_correction(
75-
stepping().pos(), stepping().dir(), stepping.dtds(),
76-
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);
7764

7865
const free_matrix_t correction_term =
7966
matrix_operator()
8067
.template identity<e_free_size, e_free_size>() +
8168
path_correction;
8269

8370
return free_to_bound_jacobian * correction_term *
84-
free_transport_jacobian * bound_to_free_jacobian;
71+
stepping.transport_jacobian() * bound_to_free_jacobian;
8572
}
8673
};
8774

8875
template <typename propagator_state_t>
89-
DETRAY_HOST_DEVICE void operator()(state& /*actor_state*/,
90-
propagator_state_t& propagation) const {
76+
DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const {
9177
auto& stepping = propagation._stepping;
9278
const auto& navigation = propagation._navigation;
9379

@@ -97,46 +83,51 @@ struct parameter_transporter : actor {
9783
return;
9884
}
9985

100-
using detector_type = typename propagator_state_t::detector_type;
101-
using geo_cxt_t = typename detector_type::geometry_context;
102-
const geo_cxt_t ctx{};
86+
typename propagator_state_t::detector_type::geometry_context ctx{};
10387

10488
// Current Surface
10589
const auto sf = navigation.get_surface();
10690

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

11299
// Previous surface
113-
tracking_surface<detector_type> prev_sf{navigation.detector(),
114-
stepping.prev_sf_index()};
100+
tracking_surface prev_sf{navigation.detector(),
101+
bound_params.surface_link()};
115102

116-
const bound_to_free_matrix<algebra_t> bound_to_free_jacobian =
117-
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);
118105

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

123115
// Calculate surface-to-surface covariance transport
124116
const bound_matrix_t new_cov =
125-
stepping.full_jacobian() *
126-
stepping.bound_params().covariance() *
117+
stepping.full_jacobian() * bound_params.covariance() *
127118
matrix_operator().transpose(stepping.full_jacobian());
119+
128120
stepping.bound_params().set_covariance(new_cov);
129121
}
130122

131123
// Convert free to bound vector
132-
stepping.bound_params().set_parameter_vector(
124+
bound_params.set_parameter_vector(
133125
sf.free_to_bound_vector(ctx, stepping()));
134126

135127
// Set surface link
136-
stepping.bound_params().set_surface_link(sf.barcode());
137-
138-
return;
128+
bound_params.set_surface_link(sf.barcode());
139129
}
130+
140131
}; // namespace detray
141132

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