Skip to content

fix: toy detector benchmark #951

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
16 changes: 9 additions & 7 deletions benchmarks/common/benchmarks/toy_detector_benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
apply_propagation_config(finding_cfg.propagation);
apply_propagation_config(fitting_cfg.propagation);

// Prevent segmentation fault in the Kalman Fitter
fitting_cfg.covariance_inflation_factor = 1.f;

finding_cfg.chi2_max = 30.f;

// Use deterministic random number generator for testing
using uniform_gen_t = detray::detail::random_numbers<
scalar_type, std::uniform_real_distribution<scalar_type>>;
Expand All @@ -101,7 +106,8 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
gen_cfg.n_tracks(n_tracks);
gen_cfg.phi_range(phi_range);
gen_cfg.eta_range(eta_range);
gen_cfg.mom_range(mom_range);
gen_cfg.pT_range(mom_range);
gen_cfg.randomize_charge(true);
generator_type generator(gen_cfg);

// Smearing value for measurements
Expand Down Expand Up @@ -151,18 +157,14 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
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<scalar_type>::mm);

return toy_cfg;
}

void apply_propagation_config(detray::propagation::config& cfg) const {
// Configure the propagation for the toy detector
// @NOTE: currently Non-{0,0} search windows cause an error during CKF
// cfg.navigation.search_window = {3, 3};
cfg.navigation.search_window = {3, 3};
cfg.navigation.overstep_tolerance = -1000.f * traccc::unit<float>::um;
cfg.navigation.min_mask_tolerance = 1e-5f * traccc::unit<float>::mm;
cfg.navigation.min_mask_tolerance = 1e-2f * traccc::unit<float>::mm;
cfg.navigation.max_mask_tolerance = 3.f * traccc::unit<float>::mm;
cfg.navigation.mask_tolerance_scalor = 0.05f;
}
Expand Down
9 changes: 9 additions & 0 deletions benchmarks/cpu/toy_detector_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ BENCHMARK_DEFINE_F(ToyDetectorBenchmark, CPU)(benchmark::State& state) {
// Track fitting with KF
auto track_states =
host_fitting(det, field, traccc::get_data(track_candidates));

#ifndef NDEBUG
std::cout << "EVENT " << i_evt << ":\n Seeds:" << params.size()
<< "/" << n_tracks
<< "\n Found tracks: " << track_candidates.size() << "/"
<< n_tracks
<< "\n Fitted tracks: " << track_states.size() << "/"
<< n_tracks << std::endl;
#endif
}
}

Expand Down
10 changes: 8 additions & 2 deletions benchmarks/cuda/toy_detector_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ BENCHMARK_DEFINE_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
track_states_cuda_buffer = device_fitting(
det_view, field, track_candidates_cuda_buffer);

#ifndef NDEBUG
// Create a temporary buffer that will receive the device memory.
/*auto size = track_states_cuda_buffer.headers.size();
auto size = track_states_cuda_buffer.headers.size();
std::vector<std::size_t> capacities(size, 0);
std::transform(track_states_cuda_buffer.items.host_ptr(),
track_states_cuda_buffer.items.host_ptr() + size,
Expand All @@ -153,7 +154,12 @@ BENCHMARK_DEFINE_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {

// Copy the track states back to the host.
traccc::track_state_container_types::host track_states_host =
track_state_d2h(track_states_cuda_buffer);*/
track_state_d2h(track_states_cuda_buffer);

std::cout << "EVENT " << i_evt
<< ":\n Fitted tracks: " << track_states_host.size()
<< "/" << n_tracks << std::endl;
#endif
}
}

Expand Down
3 changes: 3 additions & 0 deletions core/include/traccc/definitions/primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ namespace getter = detray::getter;
namespace vector = detray::vector;
namespace matrix = detray::matrix;

// Pull in the print operator definitions for the algebra types
using algebra::operator<<;

} // namespace traccc
15 changes: 11 additions & 4 deletions core/include/traccc/finding/actors/ckf_aborter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
// detray include(s)
#include <detray/propagator/base_actor.hpp>

// System include(s)
#include <limits>

namespace traccc {

/// Aborter triggered when the next surface is reached
Expand All @@ -38,7 +35,7 @@ struct ckf_aborter : detray::actor {
propagator_state_t &prop_state) const {

auto &navigation = prop_state._navigation;
auto &stepping = prop_state._stepping;
const auto &stepping = prop_state._stepping;

abrt_state.count++;
abrt_state.path_from_surface += stepping.step_size();
Expand All @@ -61,6 +58,16 @@ struct ckf_aborter : detray::actor {
"CKF: Maximum number of steps to reach next sensitive surface "
"exceeded");
}

const auto &track = stepping();
const scalar q{stepping.particle_hypothesis().charge()};
const scalar mag{track.pT(q)};

if (mag <= 500.f * traccc::unit<scalar>::MeV) {
// Stop navigation
prop_state._heartbeat &= navigation.abort();
abrt_state.success = false;
}
}
};

Expand Down
1 change: 1 addition & 0 deletions tests/cpu/test_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ GTEST_TEST(traccc_simulation, toy_detector_simulation) {
local0_diff.push_back(truth_local[0] - measurements[i].local0);
local1_diff.push_back(truth_local[1] - measurements[i].local1);

ASSERT_EQ(measurements[i].geometry_id, hits[i].geometry_id);
ASSERT_EQ(meas_hit_ids[i].hit_id, i);
ASSERT_EQ(meas_hit_ids[i].measurement_id, i);
}
Expand Down
Loading