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

Update detray version to v0.73.0 #685

Merged
merged 1 commit into from
Aug 21, 2024
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
4 changes: 2 additions & 2 deletions benchmarks/common/benchmarks/toy_detector_benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class ToyDetectorBenchmark : public benchmark::Fixture {

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

// Set constrained step size to 1 mm
sim.get_config().propagation.stepping.step_constraint =
Expand Down
1 change: 0 additions & 1 deletion core/include/traccc/edm/track_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ using free_track_parameters =
using bound_track_parameters =
detray::bound_track_parameters<traccc::default_algebra>;
using free_vector = free_track_parameters::vector_type;
using free_covariance = free_track_parameters::covariance_type;
using bound_vector = bound_track_parameters::vector_type;
using bound_covariance = bound_track_parameters::covariance_type;

Expand Down
9 changes: 8 additions & 1 deletion core/include/traccc/finding/finding_algorithm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Project include(s).
#include "traccc/finding/candidate_link.hpp"
#include "traccc/sanity/contiguous_on.hpp"
#include "traccc/utils/particle.hpp"
#include "traccc/utils/projections.hpp"

// detray include(s).
Expand Down Expand Up @@ -138,7 +139,10 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
// Apply interactor
typename interactor_type::state interactor_state;
interactor_type{}.update(
ctx, in_param, interactor_state,
ctx,
detail::correct_particle_hypothesis(m_cfg.ptc_hypothesis,
in_param),
in_param, interactor_state,
static_cast<int>(detray::navigation::direction::e_forward), sf);

// Get barcode and measurements range on surface
Expand Down Expand Up @@ -247,6 +251,9 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
const auto& param = updated_params[link_id];
// Create propagator state
typename propagator_type::state propagation(param, field, det);
propagation.set_particle(detail::correct_particle_hypothesis(
m_cfg.ptc_hypothesis, param));

propagation._stepping
.template set_constraint<detray::step::constraint::e_accuracy>(
m_cfg.propagation.stepping.step_constraint);
Expand Down
8 changes: 8 additions & 0 deletions core/include/traccc/finding/finding_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

#pragma once

// traccc include(s).
#include "traccc/definitions/primitives.hpp"

// detray include(s).
#include "detray/definitions/pdg_particle.hpp"
#include "detray/definitions/units.hpp"
#include "detray/propagator/propagation_config.hpp"

Expand Down Expand Up @@ -41,6 +45,10 @@ struct finding_config {
/// Propagation configuration
detray::propagation::config propagation{};

/// Particle hypothesis
detray::pdg_particle<traccc::scalar> ptc_hypothesis =
detray::muon<traccc::scalar>();

/****************************
* GPU-specfic parameters
****************************/
Expand Down
5 changes: 5 additions & 0 deletions core/include/traccc/fitting/fitting_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

// detray include(s).
#include "detray/definitions/pdg_particle.hpp"
#include "detray/definitions/units.hpp"
#include "detray/propagator/propagation_config.hpp"

Expand All @@ -20,6 +21,10 @@ struct fitting_config {

/// Propagation configuration
detray::propagation::config propagation{};

/// Particle hypothesis
detray::pdg_particle<traccc::scalar> ptc_hypothesis =
detray::muon<traccc::scalar>();
};

} // namespace traccc
3 changes: 3 additions & 0 deletions core/include/traccc/fitting/kalman_filter/kalman_fitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "traccc/fitting/kalman_filter/kalman_actor.hpp"
#include "traccc/fitting/kalman_filter/kalman_step_aborter.hpp"
#include "traccc/fitting/kalman_filter/statistics_updater.hpp"
#include "traccc/utils/particle.hpp"

// detray include(s).
#include "detray/propagator/actor_chain.hpp"
Expand Down Expand Up @@ -171,6 +172,8 @@ class kalman_fitter {
// Create propagator state
typename propagator_type::state propagation(
seed_params, m_field, m_detector, std::move(nav_candidates));
propagation.set_particle(detail::correct_particle_hypothesis(
m_cfg.ptc_hypothesis, seed_params));

// @TODO: Should be removed once detray is fixed to set the
// volume in the constructor
Expand Down
102 changes: 102 additions & 0 deletions core/include/traccc/utils/particle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// traccc include(s).
#include "traccc/definitions/primitives.hpp"
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/edm/track_parameters.hpp"

// detray include(s).
#include "detray/definitions/pdg_particle.hpp"

// System include(s).
#include <stdexcept>

namespace traccc {

namespace detail {

template <typename scalar_t>
TRACCC_HOST_DEVICE inline detray::pdg_particle<scalar_t>
particle_from_pdg_number(const int pdg_num) {

switch (pdg_num) {
case 11:
return detray::electron<scalar_t>();
case -11:
return detray::positron<scalar_t>();
case 13:
return detray::muon<scalar_t>();
case -13:
return detray::antimuon<scalar_t>();
case 211:
return detray::pion_plus<scalar_t>();
case -211:
return detray::pion_minus<scalar_t>();
}

return detray::muon<scalar_t>();
}

// Apply the charge operator to return the antimatter
template <typename scalar_t>
TRACCC_HOST_DEVICE inline detray::pdg_particle<scalar_t> charge_conjugation(
const detray::pdg_particle<scalar_t>& ptc) {

const auto pdg_num = ptc.pdg_num();

switch (pdg_num) {
case 11:
return detray::positron<scalar_t>();
case -11:
return detray::electron<scalar_t>();
case 13:
return detray::antimuon<scalar_t>();
case -13:
return detray::muon<scalar_t>();
case 211:
return detray::pion_minus<scalar_t>();
case -211:
return detray::pion_plus<scalar_t>();
}

return detray::muon<scalar_t>();
}

// Return the consistent particle type based on the particle hypothesis and the
// charge of the track parameters
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) {

if (ptc_hypothesis.charge() * params.qop() > 0.f) {
return ptc_hypothesis;
} else {
return charge_conjugation(ptc_hypothesis);
}
}

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) {

if (ptc_hypothesis.charge() * params.qop() > 0.f) {
return ptc_hypothesis;
} else {
return charge_conjugation(ptc_hypothesis);
}
}

} // namespace detail

} // namespace traccc
7 changes: 5 additions & 2 deletions core/include/traccc/utils/seed_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ struct seed_generator {
/// @param stddevs standard deviations for track parameter smearing
bound_track_parameters operator()(
const detray::geometry::barcode surface_link,
const free_track_parameters& free_param) {
const free_track_parameters& free_param,
const detray::pdg_particle<scalar>& ptc_type) {

// Get bound parameter
const detray::tracking_surface sf{m_detector, surface_link};
Expand All @@ -66,11 +67,13 @@ struct seed_generator {
using interactor_type =
detray::pointwise_material_interactor<algebra_type>;

assert(ptc_type.charge() * bound_param.qop() > 0.f);

// Apply interactor
typename interactor_type::state interactor_state;
interactor_state.do_multiple_scattering = false;
interactor_type{}.update(
ctx, bound_param, interactor_state,
ctx, ptc_type, bound_param, interactor_state,
static_cast<int>(detray::navigation::direction::e_backward), sf);

for (std::size_t i = 0; i < e_bound_size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@

// Project include(s).
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/finding/finding_config.hpp"

namespace traccc::device {

/// Function applying the Pre material interaction to tracks spawned by bound
/// track parameters
///
/// @param[in] globalIndex The index of the current thread
/// @param[in] cfg Track finding config object
/// @param[in] det_data Detector view object
/// @param[in] n_params The number of parameters (or tracks)
/// @param[out] params_view Collection of output bound track_parameters
///
template <typename detector_t>
TRACCC_DEVICE inline void apply_interaction(
std::size_t globalIndex, typename detector_t::view_type det_data,
const int n_params,
std::size_t globalIndex, const finding_config& cfg,
typename detector_t::view_type det_data, const int n_params,
bound_track_parameters_collection_types::view params_view);

} // namespace traccc::device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// Project include(s).
#include "traccc/definitions/math.hpp"
#include "traccc/utils/particle.hpp"

// Detray include(s).
#include "detray/geometry/tracking_surface.hpp"
Expand All @@ -17,8 +18,8 @@ namespace traccc::device {

template <typename detector_t>
TRACCC_DEVICE inline void apply_interaction(
std::size_t globalIndex, typename detector_t::view_type det_data,
const int n_params,
std::size_t globalIndex, const finding_config& cfg,
typename detector_t::view_type det_data, const int n_params,
bound_track_parameters_collection_types::view params_view) {

// Type definitions
Expand All @@ -44,7 +45,9 @@ TRACCC_DEVICE inline void apply_interaction(
// Apply interactor
typename interactor_type::state interactor_state;
interactor_type{}.update(
ctx, bound_param, interactor_state,
ctx,
detail::correct_particle_hypothesis(cfg.ptc_hypothesis, bound_param),
bound_param, interactor_state,
static_cast<int>(detray::navigation::direction::e_forward), sf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
// Create propagator state
typename propagator_t::state propagation(
in_par, field_data, det, std::move(nav_candidates.at(globalIndex)));
propagation.set_particle(
detail::correct_particle_hypothesis(cfg.ptc_hypothesis, in_par));
propagation._stepping
.template set_constraint<detray::step::constraint::e_accuracy>(
cfg.propagation.stepping.step_constraint);
Expand Down
8 changes: 5 additions & 3 deletions device/cuda/src/finding/finding_algorithm.cu
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ __global__ void make_barcode_sequence(
/// CUDA kernel for running @c traccc::device::apply_interaction
template <typename detector_t>
__global__ void apply_interaction(
typename detector_t::view_type det_data, const int n_params,
typename detector_t::view_type det_data, const finding_config cfg,
const int n_params,
bound_track_parameters_collection_types::view params_view) {

int gid = threadIdx.x + blockIdx.x * blockDim.x;

device::apply_interaction<detector_t>(gid, det_data, n_params, params_view);
device::apply_interaction<detector_t>(gid, cfg, det_data, n_params,
params_view);
}

/// CUDA kernel for running @c traccc::device::count_measurements
Expand Down Expand Up @@ -351,7 +353,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
nThreads = m_warp_size * 2;
nBlocks = (n_in_params + nThreads - 1) / nThreads;
kernels::apply_interaction<detector_type>
<<<nBlocks, nThreads, 0, stream>>>(det_view, n_in_params,
<<<nBlocks, nThreads, 0, stream>>>(det_view, m_cfg, n_in_params,
in_params_buffer);
TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());

Expand Down
11 changes: 9 additions & 2 deletions examples/options/include/traccc/options/generation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
#pragma once

// Project include(s).
#include "traccc/definitions/primitives.hpp"
#include "traccc/options/details/interface.hpp"
#include "traccc/options/details/value_array.hpp"

// detray include(s).
#include "detray/definitions/pdg_particle.hpp"

// System include(s).
#include <cstddef>

Expand Down Expand Up @@ -38,8 +42,8 @@ class generation : public interface {
opts::value_array<float, 2> phi_range{-180.f, 180.f};
/// Range of eta
opts::value_array<float, 2> eta_range{-2.f, 2.f};
/// Charge of particles
float charge{-1.f};
/// PDG number for particle type (Default: muon)
int pdg_number = 13;

/// @}

Expand All @@ -48,6 +52,9 @@ class generation : public interface {

/// Range of theta [rad]
opts::value_array<float, 2> theta_range{0.f, 0.f};
/// Particle type
detray::pdg_particle<traccc::scalar> ptc_type =
detray::muon<traccc::scalar>();

/// @}

Expand Down
2 changes: 2 additions & 0 deletions examples/options/include/traccc/options/track_finding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class track_finding : public interface, public config_provider<finding_config> {
unsigned int nmax_per_seed = 10;
/// Maximum allowed number of skipped steps per candidate
unsigned int max_num_skipping_per_cand = 3;
/// PDG number for particle hypothesis (Default: muon)
int pdg_number = 13;
/// @}

/// Print the specific options of this class
Expand Down
Loading
Loading