Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Harmonize track parameters types #867

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions benchmarks/common/benchmarks/toy_detector_benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ class ToyDetectorBenchmark : public benchmark::Fixture {

// Detector type
using detector_type = traccc::toy_detector::host;
using algebra_type = typename detector_type::algebra_type;
using scalar_type = detector_type::scalar_type;

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

static constexpr traccc::vector3 B{0, 0,
2 * traccc::unit<traccc::scalar>::T};
static constexpr traccc::vector3 B{0, 0, 2 * traccc::unit<scalar_type>::T};

ToyDetectorBenchmark() {

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

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

// Build the detector
auto [det, name_map] =
detray::build_toy_detector<traccc::default_algebra>(
host_mr, get_toy_config());
detray::build_toy_detector<algebra_type>(host_mr, get_toy_config());

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

// Origin of particles
using generator_type =
detray::random_track_generator<traccc::free_track_parameters,
uniform_gen_t>;
using generator_type = detray::random_track_generator<
traccc::free_track_parameters<algebra_type>, uniform_gen_t>;
generator_type::configuration gen_cfg{};
gen_cfg.n_tracks(n_tracks);
gen_cfg.phi_range(phi_range);
Expand All @@ -105,12 +103,12 @@ class ToyDetectorBenchmark : public benchmark::Fixture {

// Smearing value for measurements
traccc::measurement_smearer<traccc::default_algebra> meas_smearer(
50 * traccc::unit<traccc::scalar>::um,
50 * traccc::unit<traccc::scalar>::um);
50 * traccc::unit<scalar_type>::um,
50 * traccc::unit<scalar_type>::um);

// Type declarations
using writer_type = traccc::smearing_writer<
traccc::measurement_smearer<traccc::default_algebra>>;
using writer_type =
traccc::smearing_writer<traccc::measurement_smearer<algebra_type>>;

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

auto sim = traccc::simulator<detector_type, b_field_t, generator_type,
writer_type>(
detray::muon<traccc::scalar>(), n_events, det, field,
detray::muon<scalar_type>(), n_events, det, field,
std::move(generator), std::move(smearer_writer_cfg), full_path);

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

detray::toy_det_config<traccc::scalar> get_toy_config() const {
detray::toy_det_config<scalar_type> get_toy_config() const {

// Create the toy geometry
detray::toy_det_config<traccc::scalar> toy_cfg{};
detray::toy_det_config<scalar_type> toy_cfg{};
toy_cfg.n_brl_layers(4u).n_edc_layers(7u).do_check(false);

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

return toy_cfg;
}
Expand Down
2 changes: 1 addition & 1 deletion core/include/traccc/edm/track_candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace traccc {
struct finding_result {

/// Seed track parameter
traccc::bound_track_parameters seed_params;
traccc::bound_track_parameters<> seed_params;

/// Track summary
traccc::track_quality trk_quality;
Expand Down
38 changes: 25 additions & 13 deletions core/include/traccc/edm/track_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,33 @@

namespace traccc {

using free_track_parameters =
detray::free_track_parameters<traccc::default_algebra>;
using bound_track_parameters =
detray::bound_track_parameters<traccc::default_algebra>;
using free_vector = free_track_parameters::vector_type;
using bound_vector = bound_track_parameters::vector_type;
using bound_covariance = bound_track_parameters::covariance_type;
template <detray::concepts::algebra algebra_t = traccc::default_algebra>
using free_track_parameters = detray::free_track_parameters<algebra_t>;

template <detray::concepts::algebra algebra_t = traccc::default_algebra>
using bound_track_parameters = detray::bound_track_parameters<algebra_t>;

template <detray::concepts::algebra algebra_t = traccc::default_algebra>
using free_vector = typename free_track_parameters<algebra_t>::vector_type;

template <detray::concepts::algebra algebra_t = traccc::default_algebra>
using bound_vector = typename bound_track_parameters<algebra_t>::vector_type;

template <detray::concepts::algebra algebra_t = traccc::default_algebra>
using bound_covariance =
typename bound_track_parameters<algebra_t>::covariance_type;

template <detray::concepts::algebra algebra_t = traccc::default_algebra>
using bound_matrix = detray::bound_matrix<algebra_t>;

/// Declare all track_parameters collection types
using bound_track_parameters_collection_types =
collection_types<bound_track_parameters>;
collection_types<bound_track_parameters<>>;

// Wrap the phi of track parameters to [-pi,pi]
TRACCC_HOST_DEVICE
inline void wrap_phi(bound_track_parameters& param) {
template <detray::concepts::algebra algebra_t>
TRACCC_HOST_DEVICE inline void wrap_phi(
bound_track_parameters<algebra_t>& param) {

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

/// Covariance inflation used for track fitting
TRACCC_HOST_DEVICE
inline void inflate_covariance(bound_track_parameters& param,
const traccc::scalar inf_fac) {
template <detray::concepts::algebra algebra_t>
TRACCC_HOST_DEVICE inline void inflate_covariance(
bound_track_parameters<algebra_t>& param, const traccc::scalar inf_fac) {
auto& cov = param.covariance();
for (unsigned int i = 0; i < e_bound_size; i++) {
for (unsigned int j = 0; j < e_bound_size; j++) {
Expand Down
12 changes: 6 additions & 6 deletions core/include/traccc/edm/track_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct fitting_result {
using scalar_type = detray::dscalar<algebra_t>;

/// Fitted track parameter
detray::bound_track_parameters<algebra_t> fit_params;
traccc::bound_track_parameters<algebra_t> fit_params;

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

using bound_track_parameters_type =
detray::bound_track_parameters<algebra_t>;
using bound_matrix = detray::bound_matrix<algebra_t>;
traccc::bound_track_parameters<algebra_t>;
using bound_matrix_type = traccc::bound_matrix<algebra_t>;
template <size_type ROWS, size_type COLS>
using matrix_type = detray::dmatrix<algebra_t, ROWS, COLS>;

Expand Down Expand Up @@ -139,11 +139,11 @@ struct track_state {

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

/// @return the const transport jacobian
TRACCC_HOST_DEVICE
inline const bound_matrix& jacobian() const { return m_jacobian; }
inline const bound_matrix_type& jacobian() const { return m_jacobian; }

/// @return the non-const chi square of filtered parameter
TRACCC_HOST_DEVICE
Expand Down Expand Up @@ -195,7 +195,7 @@ struct track_state {
private:
detray::geometry::barcode m_surface_link;
measurement m_measurement;
bound_matrix m_jacobian = matrix::zero<bound_matrix>();
bound_matrix_type m_jacobian = matrix::zero<bound_matrix_type>();
bound_track_parameters_type m_predicted;
scalar_type m_filtered_chi2 = 0.f;
bound_track_parameters_type m_filtered;
Expand Down
9 changes: 5 additions & 4 deletions core/include/traccc/finding/details/find_tracks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ track_candidate_container_types::host find_tracks(
bound_track_parameters_collection_types::const_device seeds{seeds_view};

// Copy seed to input parameters
std::vector<bound_track_parameters> in_params(seeds.size());
std::vector<bound_track_parameters<algebra_type>> in_params(seeds.size());
std::copy(seeds.begin(), seeds.end(), in_params.begin());
std::vector<unsigned int> n_trks_per_seed(seeds.size());

std::vector<bound_track_parameters> out_params;
std::vector<bound_track_parameters<algebra_type>> out_params;

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

// Parameters updated by Kalman fitter
std::vector<bound_track_parameters> updated_params;
std::vector<bound_track_parameters<algebra_type>> updated_params;

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

bound_track_parameters& in_param = in_params[in_param_id];
bound_track_parameters<algebra_type>& in_param =
in_params[in_param_id];
const unsigned int orig_param_id =
(step == 0
? in_param_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ struct gain_matrix_smoother {
using size_type = detray::dsize_type<algebra_t>;
template <size_type ROWS, size_type COLS>
using matrix_type = detray::dmatrix<algebra_t, ROWS, COLS>;
using bound_vector_type = detray::bound_vector<algebra_t>;
using bound_matrix_type = detray::bound_matrix<algebra_t>;
using bound_vector_type = traccc::bound_vector<algebra_t>;
using bound_matrix_type = traccc::bound_matrix<algebra_t>;

/// Gain matrix smoother operation
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct gain_matrix_updater {
using size_type = detray::dsize_type<algebra_t>;
template <size_type ROWS, size_type COLS>
using matrix_type = detray::dmatrix<algebra_t, ROWS, COLS>;
using bound_vector_type = detray::bound_vector<algebra_t>;
using bound_matrix_type = detray::bound_matrix<algebra_t>;
using bound_vector_type = traccc::bound_vector<algebra_t>;
using bound_matrix_type = traccc::bound_matrix<algebra_t>;

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

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

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

static_assert(((D == 1u) || (D == 2u)),
"The measurement dimension should be 1 or 2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct two_filters_smoother {
TRACCC_HOST_DEVICE [[nodiscard]] inline kalman_fitter_status operator()(
const mask_group_t& /*mask_group*/, const index_t& /*index*/,
track_state<algebra_t>& trk_state,
bound_track_parameters& bound_params) const {
bound_track_parameters<algebra_t>& bound_params) const {

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

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

assert(trk_state.filtered().surface_link() ==
bound_params.surface_link());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ inline TRACCC_HOST_DEVICE vector2 uv_transform(const scalar& x,
/// @param bfield is the magnetic field
/// @param mass is the mass of particle
template <typename spacepoint_collection_t>
inline TRACCC_HOST_DEVICE bound_vector
seed_to_bound_vector(const spacepoint_collection_t& sp_collection,
const seed& seed, const vector3& bfield) {
inline TRACCC_HOST_DEVICE bound_vector<> seed_to_bound_vector(
const spacepoint_collection_t& sp_collection, const seed& seed,
const vector3& bfield) {

bound_vector params = matrix::zero<bound_vector>();
bound_vector<> params = matrix::zero<bound_vector<>>();

const auto& spB =
sp_collection.at(static_cast<unsigned int>(seed.spB_link));
Expand Down
4 changes: 2 additions & 2 deletions core/include/traccc/utils/particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ template <typename scalar_t>
TRACCC_HOST_DEVICE inline detray::pdg_particle<scalar_t>
correct_particle_hypothesis(
const detray::pdg_particle<scalar_t>& ptc_hypothesis,
const bound_track_parameters& params) {
const bound_track_parameters<>& params) {

if (ptc_hypothesis.charge() * params.qop() > 0.f) {
return ptc_hypothesis;
Expand All @@ -90,7 +90,7 @@ template <typename scalar_t>
TRACCC_HOST_DEVICE inline detray::pdg_particle<scalar_t>
correct_particle_hypothesis(
const detray::pdg_particle<scalar_t>& ptc_hypothesis,
const free_track_parameters& params) {
const free_track_parameters<>& params) {

if (ptc_hypothesis.charge() * params.qop() > 0.f) {
return ptc_hypothesis;
Expand Down
9 changes: 5 additions & 4 deletions core/include/traccc/utils/seed_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@ struct seed_generator {
///
/// @param vertex vertex of particle
/// @param stddevs standard deviations for track parameter smearing
bound_track_parameters operator()(
bound_track_parameters<algebra_type> operator()(
const detray::geometry::barcode surface_link,
const free_track_parameters& free_param,
const free_track_parameters<algebra_type>& free_param,
const detray::pdg_particle<scalar>& ptc_type) {

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

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

bound_track_parameters bound_param{surface_link, bound_vec, bound_cov};
bound_track_parameters<algebra_type> bound_param{surface_link,
bound_vec, bound_cov};

// Type definitions
using interactor_type =
Expand Down
2 changes: 1 addition & 1 deletion core/src/seeding/track_params_estimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ track_params_estimation::output_type track_params_estimation::operator()(
output_type result(num_seeds, &m_mr.get());

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

Expand Down
5 changes: 3 additions & 2 deletions device/common/include/traccc/edm/device/sort_key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ namespace traccc::device {

using sort_key = traccc::scalar;

TRACCC_HOST_DEVICE
inline sort_key get_sort_key(const bound_track_parameters& params) {
template <detray::concepts::algebra algebra_t>
TRACCC_HOST_DEVICE inline sort_key get_sort_key(
const bound_track_parameters<algebra_t>& params) {
// key = |theta - pi/2|
return math::fabs(params.theta() - constant<traccc::scalar>::pi_2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ TRACCC_DEVICE inline void find_tracks(
owner_local_thread_id +
thread_id.getBlockDimX() * thread_id.getBlockIdX();
assert(in_params_liveness.at(owner_global_thread_id) != 0u);
const bound_track_parameters& in_par =
const bound_track_parameters<>& in_par =
in_params.at(owner_global_thread_id);
const unsigned int meas_idx =
shared_payload.shared_candidates[thread_id.getLocalThreadIdX()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
}

// Input bound track parameter
const bound_track_parameters in_par = params.at(param_id);
const bound_track_parameters<> in_par = params.at(param_id);

// Create propagator
propagator_t propagator(cfg.propagation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ inline void estimate_track_params(
const seed& this_seed = seeds_device.at(globalIndex);

// Get bound track parameter
bound_track_parameters track_params;
bound_track_parameters<> track_params;
track_params.set_vector(
seed_to_bound_vector(spacepoints_device, this_seed, bfield));

Expand Down
2 changes: 1 addition & 1 deletion examples/run/alpaka/seeding_example_alpaka.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
vecmem::get_data(seeds_alpaka));

// Compare the track parameters made on the host and on the device.
traccc::collection_comparator<traccc::bound_track_parameters>
traccc::collection_comparator<traccc::bound_track_parameters<>>
compare_track_parameters{"track parameters"};
compare_track_parameters(vecmem::get_data(params),
vecmem::get_data(params_alpaka));
Expand Down
Loading
Loading