Skip to content

Commit 69c1ef6

Browse files
Use the traccc track parameter types everywhere and allow templating of the algebra type (#867)
Co-authored-by: Stephen Nicholas Swatman <stephen.nicholas.swatman@cern.ch>
1 parent f2d66f1 commit 69c1ef6

File tree

50 files changed

+137
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+137
-121
lines changed

benchmarks/common/benchmarks/toy_detector_benchmark.hpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
6161

6262
// Detector type
6363
using detector_type = traccc::toy_detector::host;
64+
using algebra_type = typename detector_type::algebra_type;
6465
using scalar_type = detector_type::scalar_type;
6566

6667
// B field value and its type
6768
// @TODO: Set B field as argument
6869
using b_field_t = covfie::field<detray::bfield::const_bknd_t<scalar_type>>;
6970

70-
static constexpr traccc::vector3 B{0, 0,
71-
2 * traccc::unit<traccc::scalar>::T};
71+
static constexpr traccc::vector3 B{0, 0, 2 * traccc::unit<scalar_type>::T};
7272

7373
ToyDetectorBenchmark() {
7474

@@ -82,20 +82,18 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
8282

8383
// Use deterministic random number generator for testing
8484
using uniform_gen_t = detray::detail::random_numbers<
85-
traccc::scalar, std::uniform_real_distribution<traccc::scalar>>;
85+
scalar_type, std::uniform_real_distribution<scalar_type>>;
8686

8787
// Build the detector
8888
auto [det, name_map] =
89-
detray::build_toy_detector<traccc::default_algebra>(
90-
host_mr, get_toy_config());
89+
detray::build_toy_detector<algebra_type>(host_mr, get_toy_config());
9190

9291
// B field
9392
auto field = detray::bfield::create_const_field<scalar_type>(B);
9493

9594
// Origin of particles
96-
using generator_type =
97-
detray::random_track_generator<traccc::free_track_parameters,
98-
uniform_gen_t>;
95+
using generator_type = detray::random_track_generator<
96+
traccc::free_track_parameters<algebra_type>, uniform_gen_t>;
9997
generator_type::configuration gen_cfg{};
10098
gen_cfg.n_tracks(n_tracks);
10199
gen_cfg.phi_range(phi_range);
@@ -105,12 +103,12 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
105103

106104
// Smearing value for measurements
107105
traccc::measurement_smearer<traccc::default_algebra> meas_smearer(
108-
50 * traccc::unit<traccc::scalar>::um,
109-
50 * traccc::unit<traccc::scalar>::um);
106+
50 * traccc::unit<scalar_type>::um,
107+
50 * traccc::unit<scalar_type>::um);
110108

111109
// Type declarations
112-
using writer_type = traccc::smearing_writer<
113-
traccc::measurement_smearer<traccc::default_algebra>>;
110+
using writer_type =
111+
traccc::smearing_writer<traccc::measurement_smearer<algebra_type>>;
114112

115113
// Writer config
116114
typename writer_type::config smearer_writer_cfg{meas_smearer};
@@ -122,7 +120,7 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
122120

123121
auto sim = traccc::simulator<detector_type, b_field_t, generator_type,
124122
writer_type>(
125-
detray::muon<traccc::scalar>(), n_events, det, field,
123+
detray::muon<scalar_type>(), n_events, det, field,
126124
std::move(generator), std::move(smearer_writer_cfg), full_path);
127125

128126
// Same propagation configuration for sim and reco
@@ -143,14 +141,14 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
143141
detray::io::write_detector(det, name_map, writer_cfg);
144142
}
145143

146-
detray::toy_det_config<traccc::scalar> get_toy_config() const {
144+
detray::toy_det_config<scalar_type> get_toy_config() const {
147145

148146
// Create the toy geometry
149-
detray::toy_det_config<traccc::scalar> toy_cfg{};
147+
detray::toy_det_config<scalar_type> toy_cfg{};
150148
toy_cfg.n_brl_layers(4u).n_edc_layers(7u).do_check(false);
151149

152150
// @TODO: Increase the material budget again
153-
toy_cfg.module_mat_thickness(0.11f * traccc::unit<traccc::scalar>::mm);
151+
toy_cfg.module_mat_thickness(0.11f * traccc::unit<scalar_type>::mm);
154152

155153
return toy_cfg;
156154
}

core/include/traccc/edm/track_candidate.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace traccc {
1818
struct finding_result {
1919

2020
/// Seed track parameter
21-
traccc::bound_track_parameters seed_params;
21+
traccc::bound_track_parameters<> seed_params;
2222

2323
/// Track summary
2424
traccc::track_quality trk_quality;

core/include/traccc/edm/track_parameters.hpp

+25-13
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,33 @@
2020

2121
namespace traccc {
2222

23-
using free_track_parameters =
24-
detray::free_track_parameters<traccc::default_algebra>;
25-
using bound_track_parameters =
26-
detray::bound_track_parameters<traccc::default_algebra>;
27-
using free_vector = free_track_parameters::vector_type;
28-
using bound_vector = bound_track_parameters::vector_type;
29-
using bound_covariance = bound_track_parameters::covariance_type;
23+
template <detray::concepts::algebra algebra_t = traccc::default_algebra>
24+
using free_track_parameters = detray::free_track_parameters<algebra_t>;
25+
26+
template <detray::concepts::algebra algebra_t = traccc::default_algebra>
27+
using bound_track_parameters = detray::bound_track_parameters<algebra_t>;
28+
29+
template <detray::concepts::algebra algebra_t = traccc::default_algebra>
30+
using free_vector = typename free_track_parameters<algebra_t>::vector_type;
31+
32+
template <detray::concepts::algebra algebra_t = traccc::default_algebra>
33+
using bound_vector = typename bound_track_parameters<algebra_t>::vector_type;
34+
35+
template <detray::concepts::algebra algebra_t = traccc::default_algebra>
36+
using bound_covariance =
37+
typename bound_track_parameters<algebra_t>::covariance_type;
38+
39+
template <detray::concepts::algebra algebra_t = traccc::default_algebra>
40+
using bound_matrix = detray::bound_matrix<algebra_t>;
3041

3142
/// Declare all track_parameters collection types
3243
using bound_track_parameters_collection_types =
33-
collection_types<bound_track_parameters>;
44+
collection_types<bound_track_parameters<>>;
3445

3546
// Wrap the phi of track parameters to [-pi,pi]
36-
TRACCC_HOST_DEVICE
37-
inline void wrap_phi(bound_track_parameters& param) {
47+
template <detray::concepts::algebra algebra_t>
48+
TRACCC_HOST_DEVICE inline void wrap_phi(
49+
bound_track_parameters<algebra_t>& param) {
3850

3951
traccc::scalar phi = param.phi();
4052
static constexpr traccc::scalar TWOPI =
@@ -49,9 +61,9 @@ inline void wrap_phi(bound_track_parameters& param) {
4961
}
5062

5163
/// Covariance inflation used for track fitting
52-
TRACCC_HOST_DEVICE
53-
inline void inflate_covariance(bound_track_parameters& param,
54-
const traccc::scalar inf_fac) {
64+
template <detray::concepts::algebra algebra_t>
65+
TRACCC_HOST_DEVICE inline void inflate_covariance(
66+
bound_track_parameters<algebra_t>& param, const traccc::scalar inf_fac) {
5567
auto& cov = param.covariance();
5668
for (unsigned int i = 0; i < e_bound_size; i++) {
5769
for (unsigned int j = 0; j < e_bound_size; j++) {

core/include/traccc/edm/track_state.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct fitting_result {
2626
using scalar_type = detray::dscalar<algebra_t>;
2727

2828
/// Fitted track parameter
29-
detray::bound_track_parameters<algebra_t> fit_params;
29+
traccc::bound_track_parameters<algebra_t> fit_params;
3030

3131
/// Track quality
3232
traccc::track_quality trk_quality;
@@ -40,8 +40,8 @@ struct track_state {
4040
using size_type = detray::dsize_type<algebra_t>;
4141

4242
using bound_track_parameters_type =
43-
detray::bound_track_parameters<algebra_t>;
44-
using bound_matrix = detray::bound_matrix<algebra_t>;
43+
traccc::bound_track_parameters<algebra_t>;
44+
using bound_matrix_type = traccc::bound_matrix<algebra_t>;
4545
template <size_type ROWS, size_type COLS>
4646
using matrix_type = detray::dmatrix<algebra_t, ROWS, COLS>;
4747

@@ -139,11 +139,11 @@ struct track_state {
139139

140140
/// @return the non-const transport jacobian
141141
TRACCC_HOST_DEVICE
142-
inline bound_matrix& jacobian() { return m_jacobian; }
142+
inline bound_matrix_type& jacobian() { return m_jacobian; }
143143

144144
/// @return the const transport jacobian
145145
TRACCC_HOST_DEVICE
146-
inline const bound_matrix& jacobian() const { return m_jacobian; }
146+
inline const bound_matrix_type& jacobian() const { return m_jacobian; }
147147

148148
/// @return the non-const chi square of filtered parameter
149149
TRACCC_HOST_DEVICE
@@ -195,7 +195,7 @@ struct track_state {
195195
private:
196196
detray::geometry::barcode m_surface_link;
197197
measurement m_measurement;
198-
bound_matrix m_jacobian = matrix::zero<bound_matrix>();
198+
bound_matrix_type m_jacobian = matrix::zero<bound_matrix_type>();
199199
bound_track_parameters_type m_predicted;
200200
scalar_type m_filtered_chi2 = 0.f;
201201
bound_track_parameters_type m_filtered;

core/include/traccc/finding/details/find_tracks.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ track_candidate_container_types::host find_tracks(
134134
bound_track_parameters_collection_types::const_device seeds{seeds_view};
135135

136136
// Copy seed to input parameters
137-
std::vector<bound_track_parameters> in_params(seeds.size());
137+
std::vector<bound_track_parameters<algebra_type>> in_params(seeds.size());
138138
std::copy(seeds.begin(), seeds.end(), in_params.begin());
139139
std::vector<unsigned int> n_trks_per_seed(seeds.size());
140140

141-
std::vector<bound_track_parameters> out_params;
141+
std::vector<bound_track_parameters<algebra_type>> out_params;
142142

143143
for (unsigned int step = 0u; step < config.max_track_candidates_per_track;
144144
step++) {
@@ -161,12 +161,13 @@ track_candidate_container_types::host find_tracks(
161161
std::fill(n_trks_per_seed.begin(), n_trks_per_seed.end(), 0u);
162162

163163
// Parameters updated by Kalman fitter
164-
std::vector<bound_track_parameters> updated_params;
164+
std::vector<bound_track_parameters<algebra_type>> updated_params;
165165

166166
for (unsigned int in_param_id = 0; in_param_id < n_in_params;
167167
in_param_id++) {
168168

169-
bound_track_parameters& in_param = in_params[in_param_id];
169+
bound_track_parameters<algebra_type>& in_param =
170+
in_params[in_param_id];
170171
const unsigned int orig_param_id =
171172
(step == 0
172173
? in_param_id

core/include/traccc/fitting/kalman_filter/gain_matrix_smoother.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ struct gain_matrix_smoother {
2828
using size_type = detray::dsize_type<algebra_t>;
2929
template <size_type ROWS, size_type COLS>
3030
using matrix_type = detray::dmatrix<algebra_t, ROWS, COLS>;
31-
using bound_vector_type = detray::bound_vector<algebra_t>;
32-
using bound_matrix_type = detray::bound_matrix<algebra_t>;
31+
using bound_vector_type = traccc::bound_vector<algebra_t>;
32+
using bound_matrix_type = traccc::bound_matrix<algebra_t>;
3333

3434
/// Gain matrix smoother operation
3535
///

core/include/traccc/fitting/kalman_filter/gain_matrix_updater.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ struct gain_matrix_updater {
2626
using size_type = detray::dsize_type<algebra_t>;
2727
template <size_type ROWS, size_type COLS>
2828
using matrix_type = detray::dmatrix<algebra_t, ROWS, COLS>;
29-
using bound_vector_type = detray::bound_vector<algebra_t>;
30-
using bound_matrix_type = detray::bound_matrix<algebra_t>;
29+
using bound_vector_type = traccc::bound_vector<algebra_t>;
30+
using bound_matrix_type = traccc::bound_matrix<algebra_t>;
3131

3232
/// Gain matrix updater operation
3333
///
@@ -44,7 +44,7 @@ struct gain_matrix_updater {
4444
TRACCC_HOST_DEVICE [[nodiscard]] inline kalman_fitter_status operator()(
4545
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
4646
track_state<algebra_t>& trk_state,
47-
const bound_track_parameters& bound_params) const {
47+
const bound_track_parameters<algebra_t>& bound_params) const {
4848

4949
using shape_type = typename mask_group_t::value_type::shape;
5050

@@ -67,7 +67,7 @@ struct gain_matrix_updater {
6767
template <size_type D, typename shape_t>
6868
TRACCC_HOST_DEVICE [[nodiscard]] inline kalman_fitter_status update(
6969
track_state<algebra_t>& trk_state,
70-
const bound_track_parameters& bound_params) const {
70+
const bound_track_parameters<algebra_t>& bound_params) const {
7171

7272
static_assert(((D == 1u) || (D == 2u)),
7373
"The measurement dimension should be 1 or 2");

core/include/traccc/fitting/kalman_filter/two_filters_smoother.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct two_filters_smoother {
3636
TRACCC_HOST_DEVICE [[nodiscard]] inline kalman_fitter_status operator()(
3737
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
3838
track_state<algebra_t>& trk_state,
39-
bound_track_parameters& bound_params) const {
39+
bound_track_parameters<algebra_t>& bound_params) const {
4040

4141
using shape_type = typename mask_group_t::value_type::shape;
4242

@@ -56,7 +56,7 @@ struct two_filters_smoother {
5656
template <size_type D, typename shape_t>
5757
TRACCC_HOST_DEVICE [[nodiscard]] inline kalman_fitter_status smoothe(
5858
track_state<algebra_t>& trk_state,
59-
bound_track_parameters& bound_params) const {
59+
bound_track_parameters<algebra_t>& bound_params) const {
6060

6161
assert(trk_state.filtered().surface_link() ==
6262
bound_params.surface_link());

core/include/traccc/seeding/track_params_estimation_helper.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ inline TRACCC_HOST_DEVICE vector2 uv_transform(const scalar& x,
3939
/// @param bfield is the magnetic field
4040
/// @param mass is the mass of particle
4141
template <typename spacepoint_collection_t>
42-
inline TRACCC_HOST_DEVICE bound_vector
43-
seed_to_bound_vector(const spacepoint_collection_t& sp_collection,
44-
const seed& seed, const vector3& bfield) {
42+
inline TRACCC_HOST_DEVICE bound_vector<> seed_to_bound_vector(
43+
const spacepoint_collection_t& sp_collection, const seed& seed,
44+
const vector3& bfield) {
4545

46-
bound_vector params = matrix::zero<bound_vector>();
46+
bound_vector<> params = matrix::zero<bound_vector<>>();
4747

4848
const auto& spB =
4949
sp_collection.at(static_cast<unsigned int>(seed.spB_link));

core/include/traccc/utils/particle.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ template <typename scalar_t>
7777
TRACCC_HOST_DEVICE inline detray::pdg_particle<scalar_t>
7878
correct_particle_hypothesis(
7979
const detray::pdg_particle<scalar_t>& ptc_hypothesis,
80-
const bound_track_parameters& params) {
80+
const bound_track_parameters<>& params) {
8181

8282
if (ptc_hypothesis.charge() * params.qop() > 0.f) {
8383
return ptc_hypothesis;
@@ -90,7 +90,7 @@ template <typename scalar_t>
9090
TRACCC_HOST_DEVICE inline detray::pdg_particle<scalar_t>
9191
correct_particle_hypothesis(
9292
const detray::pdg_particle<scalar_t>& ptc_hypothesis,
93-
const free_track_parameters& params) {
93+
const free_track_parameters<>& params) {
9494

9595
if (ptc_hypothesis.charge() * params.qop() > 0.f) {
9696
return ptc_hypothesis;

core/include/traccc/utils/seed_generator.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ struct seed_generator {
4242
///
4343
/// @param vertex vertex of particle
4444
/// @param stddevs standard deviations for track parameter smearing
45-
bound_track_parameters operator()(
45+
bound_track_parameters<algebra_type> operator()(
4646
const detray::geometry::barcode surface_link,
47-
const free_track_parameters& free_param,
47+
const free_track_parameters<algebra_type>& free_param,
4848
const detray::pdg_particle<scalar>& ptc_type) {
4949

5050
// Get bound parameter
5151
const detray::tracking_surface sf{m_detector, surface_link};
5252

5353
const cxt_t ctx{};
5454
auto bound_vec = sf.free_to_bound_vector(ctx, free_param);
55-
auto bound_cov = matrix::zero<detray::bound_matrix<algebra_type>>();
55+
auto bound_cov = matrix::zero<traccc::bound_matrix<algebra_type>>();
5656

57-
bound_track_parameters bound_param{surface_link, bound_vec, bound_cov};
57+
bound_track_parameters<algebra_type> bound_param{surface_link,
58+
bound_vec, bound_cov};
5859

5960
// Type definitions
6061
using interactor_type =

core/src/seeding/track_params_estimation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ track_params_estimation::output_type track_params_estimation::operator()(
2525
output_type result(num_seeds, &m_mr.get());
2626

2727
for (seed_collection_types::host::size_type i = 0; i < num_seeds; ++i) {
28-
bound_track_parameters track_params;
28+
bound_track_parameters<> track_params;
2929
track_params.set_vector(
3030
seed_to_bound_vector(spacepoints, seeds[i], bfield));
3131

device/common/include/traccc/edm/device/sort_key.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ namespace traccc::device {
1616

1717
using sort_key = traccc::scalar;
1818

19-
TRACCC_HOST_DEVICE
20-
inline sort_key get_sort_key(const bound_track_parameters& params) {
19+
template <detray::concepts::algebra algebra_t>
20+
TRACCC_HOST_DEVICE inline sort_key get_sort_key(
21+
const bound_track_parameters<algebra_t>& params) {
2122
// key = |theta - pi/2|
2223
return math::fabs(params.theta() - constant<traccc::scalar>::pi_2);
2324
}

device/common/include/traccc/finding/device/impl/find_tracks.ipp

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ TRACCC_DEVICE inline void find_tracks(
195195
owner_local_thread_id +
196196
thread_id.getBlockDimX() * thread_id.getBlockIdX();
197197
assert(in_params_liveness.at(owner_global_thread_id) != 0u);
198-
const bound_track_parameters& in_par =
198+
const bound_track_parameters<>& in_par =
199199
in_params.at(owner_global_thread_id);
200200
const unsigned int meas_idx =
201201
shared_payload.shared_candidates[thread_id.getLocalThreadIdX()]

device/common/include/traccc/finding/device/impl/propagate_to_next_surface.ipp

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
7474
}
7575

7676
// Input bound track parameter
77-
const bound_track_parameters in_par = params.at(param_id);
77+
const bound_track_parameters<> in_par = params.at(param_id);
7878

7979
// Create propagator
8080
propagator_t propagator(cfg.propagation);

device/common/include/traccc/seeding/device/impl/estimate_track_params.ipp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ inline void estimate_track_params(
3535
const seed& this_seed = seeds_device.at(globalIndex);
3636

3737
// Get bound track parameter
38-
bound_track_parameters track_params;
38+
bound_track_parameters<> track_params;
3939
track_params.set_vector(
4040
seed_to_bound_vector(spacepoints_device, this_seed, bfield));
4141

examples/run/alpaka/seeding_example_alpaka.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
246246
vecmem::get_data(seeds_alpaka));
247247

248248
// Compare the track parameters made on the host and on the device.
249-
traccc::collection_comparator<traccc::bound_track_parameters>
249+
traccc::collection_comparator<traccc::bound_track_parameters<>>
250250
compare_track_parameters{"track parameters"};
251251
compare_track_parameters(vecmem::get_data(params),
252252
vecmem::get_data(params_alpaka));

0 commit comments

Comments
 (0)