Skip to content

Commit

Permalink
Harmonize track parameters types
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Feb 13, 2025
1 parent 5412f1a commit 8d76632
Show file tree
Hide file tree
Showing 37 changed files with 116 additions and 101 deletions.
32 changes: 15 additions & 17 deletions benchmarks/common/benchmarks/toy_detector_benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,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 * detray::unit<traccc::scalar>::T};
static constexpr traccc::vector3 B{0, 0, 2 * detray::unit<scalar_type>::T};

ToyDetectorBenchmark() {

Expand All @@ -87,20 +87,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 @@ -109,13 +107,13 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
generator_type generator(gen_cfg);

// Smearing value for measurements
traccc::measurement_smearer<traccc::default_algebra> meas_smearer(
50 * detray::unit<traccc::scalar>::um,
50 * detray::unit<traccc::scalar>::um);
traccc::measurement_smearer<algebra_type> meas_smearer(
50 * detray::unit<scalar_type>::um,
50 * detray::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 @@ -127,7 +125,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 @@ -148,14 +146,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 * detray::unit<traccc::scalar>::mm);
toy_cfg.module_mat_thickness(0.11f * detray::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 @@ -23,6 +23,6 @@ using track_candidate = measurement;
using track_candidate_collection_types = collection_types<track_candidate>;
/// Declare a track candidates container type
using track_candidate_container_types =
container_types<bound_track_parameters, track_candidate>;
container_types<bound_track_parameters<>, track_candidate>;

} // namespace traccc
30 changes: 20 additions & 10 deletions core/include/traccc/edm/track_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,31 @@

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 = free_track_parameters<algebra_t>::vector_type;

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

template <detray::concepts::algebra algebra_t = traccc::default_algebra>
using bound_covariance = 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) {
inline void wrap_phi(bound_track_parameters<>& param) {

traccc::scalar phi = param.phi();
static constexpr traccc::scalar TWOPI =
Expand All @@ -50,7 +60,7 @@ 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,
inline void inflate_covariance(bound_track_parameters<>& param,
const traccc::scalar inf_fac) {
auto& cov = param.covariance();
for (unsigned int i = 0; i < e_bound_size; i++) {
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;

/// Number of degree of freedoms of fitted track
scalar_type ndf{0};
Expand Down Expand Up @@ -55,8 +55,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 @@ -154,11 +154,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 @@ -210,7 +210,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 @@ -137,11 +137,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 @@ -164,12 +164,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 @@ -24,8 +24,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 @@ -22,8 +22,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 @@ -40,7 +40,7 @@ struct gain_matrix_updater {
TRACCC_HOST_DEVICE inline bool 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 @@ -63,7 +63,7 @@ struct gain_matrix_updater {
template <size_type D, typename shape_t>
TRACCC_HOST_DEVICE inline bool 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 @@ -35,7 +35,7 @@ struct two_filters_smoother {
TRACCC_HOST_DEVICE inline bool 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 @@ -55,7 +55,7 @@ struct two_filters_smoother {
template <size_type D, typename shape_t>
TRACCC_HOST_DEVICE inline bool 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 @@ -75,7 +75,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 @@ -88,7 +88,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 @@ -47,19 +47,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 examples/simulation/simulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) {
detray::detail::random_numbers<scalar,
std::uniform_real_distribution<scalar>>;
using generator_type =
detray::random_track_generator<traccc::free_track_parameters,
detray::random_track_generator<traccc::free_track_parameters<>,
uniform_gen_t>;

// B field value and its type
Expand Down
2 changes: 1 addition & 1 deletion examples/simulation/simulate_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int simulate(const traccc::opts::generation& generation_opts,

// Origin of particles
using generator_type =
detray::random_track_generator<traccc::free_track_parameters,
detray::random_track_generator<traccc::free_track_parameters<>,
uniform_gen_t>;
generator_type::configuration gen_cfg{};
gen_cfg.n_tracks(generation_opts.gen_nparticles);
Expand Down
2 changes: 1 addition & 1 deletion examples/simulation/simulate_toy_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int simulate(const traccc::opts::generation& generation_opts,

// Origin of particles
using generator_type =
detray::random_track_generator<traccc::free_track_parameters,
detray::random_track_generator<traccc::free_track_parameters<>,
uniform_gen_t>;
generator_type::configuration gen_cfg{};
gen_cfg.n_tracks(generation_opts.gen_nparticles);
Expand Down
2 changes: 1 addition & 1 deletion examples/simulation/simulate_wire_chamber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int simulate(const traccc::opts::generation& generation_opts,

// Origin of particles
using generator_type =
detray::random_track_generator<traccc::free_track_parameters,
detray::random_track_generator<traccc::free_track_parameters<>,
uniform_gen_t>;
generator_type::configuration gen_cfg{};
gen_cfg.n_tracks(generation_opts.gen_nparticles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ namespace traccc::details {

/// @c traccc::is_same_object specialisation for
/// @c traccc::bound_track_parameters
template <>
class is_same_object<bound_track_parameters> {
template <detray::concepts::algebra algebra_t>
class is_same_object<bound_track_parameters<algebra_t>> {

public:
/// Constructor with a reference object, and an allowed uncertainty
is_same_object(const bound_track_parameters& ref,
is_same_object(const bound_track_parameters<algebra_t>& ref,
scalar unc = float_epsilon);

/// Specialised implementation for @c traccc::bound_track_parameters
bool operator()(const bound_track_parameters& obj) const;
bool operator()(const bound_track_parameters<algebra_t>& obj) const;

private:
/// The reference object
std::reference_wrapper<const bound_track_parameters> m_ref;
std::reference_wrapper<const bound_track_parameters<algebra_t>> m_ref;
/// The uncertainty
scalar m_unc;

Expand Down
Loading

0 comments on commit 8d76632

Please sign in to comment.