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

Refactor the Parameter interface for Kalman fitting test #774

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
45 changes: 36 additions & 9 deletions tests/common/tests/kalman_fitting_telescope_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,35 @@

namespace traccc {

/// Combinatorial Kalman Finding Test with Sparse tracks
class KalmanFittingTelescopeTests : public KalmanFittingTests {
/// Kalman Fitting Test with Telescope Detector
///
/// Test parameters:
/// (1) name
/// (2) origin
/// (3) origin stddev
/// (4) momentum range
/// (5) eta range
/// (6) phi range
/// (7) particle type
/// (8) number of tracks per event
/// (9) number of events
/// (10) random charge
/// (11) offset from origin of the first plane in mm
/// (12) Number of planes
/// (13) Spacing between planes in mm
class KalmanFittingTelescopeTests
: public KalmanFittingTests,
public testing::WithParamInterface<std::tuple<
std::string, std::array<scalar, 3u>, std::array<scalar, 3u>,
std::array<scalar, 2u>, std::array<scalar, 2u>,
std::array<scalar, 2u>, detray::pdg_particle<scalar>, unsigned int,
unsigned int, bool, scalar, unsigned int, scalar>> {

public:
/// Plane alignment direction (aligned to x-axis)
static const inline detray::detail::ray<traccc::default_algebra> traj{
{0, 0, 0}, 0, {1, 0, 0}, -1};

/// Position of planes (in mm unit)
/// @NOTE: Increasing the number of planes will make
/// test_ckf_combinatorics_telescope take too much time
static const inline std::vector<scalar> plane_positions = {
0.f, 20.f, 40.f, 60.f, 80.f, 100.f, 120.f, 140.f, 160.f};

/// B field value and its type
static constexpr vector3 B{2 * detray::unit<scalar>::T, 0, 0};

Expand Down Expand Up @@ -62,19 +77,31 @@ class KalmanFittingTelescopeTests : public KalmanFittingTests {

// The nubmer of track states is supposed be equal to the number
// of planes
ASSERT_EQ(track_states_per_track.size(), plane_positions.size());
ASSERT_EQ(track_states_per_track.size(), std::get<11>(GetParam()));
}

protected:
virtual void SetUp() override {

vecmem::host_memory_resource host_mr;

const scalar offset = std::get<10>(GetParam());
const unsigned int n_planes = std::get<11>(GetParam());
const scalar spacing = std::get<12>(GetParam());

std::vector<scalar> plane_positions;
for (unsigned int i = 0; i < n_planes; i++) {
plane_positions.push_back(offset * unit<scalar>::mm +
static_cast<scalar>(i) * spacing *
unit<scalar>::mm);
}

detray::tel_det_config<> tel_cfg{rectangle};
tel_cfg.positions(plane_positions);
tel_cfg.module_material(mat);
tel_cfg.mat_thickness(thickness);
tel_cfg.pilot_track(traj);
tel_cfg.envelope(offset * 2.f);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good enough


// Create telescope detector
auto [det, name_map] = build_telescope_detector(host_mr, tel_cfg);
Expand Down
21 changes: 1 addition & 20 deletions tests/common/tests/kalman_fitting_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,7 @@

namespace traccc {

/// Kalman Fitting Test with Telescope Geometry
///
/// Test parameters:
/// (1) name
/// (2) origin
/// (3) origin stddev
/// (4) momentum range
/// (5) eta range
/// (6) phi range
/// (7) particle type
/// (8) number of tracks per event
/// (9) number of events
/// (10) random charge
class KalmanFittingTests
: public ::testing::TestWithParam<std::tuple<
std::string, std::array<scalar, 3u>, std::array<scalar, 3u>,
std::array<scalar, 2u>, std::array<scalar, 2u>,
std::array<scalar, 2u>, detray::pdg_particle<scalar>, unsigned int,
unsigned int, bool>> {

class KalmanFittingTests : public testing::Test {
public:
/// Type declarations
using host_detector_type = detray::detector<detray::default_metadata,
Expand Down
22 changes: 20 additions & 2 deletions tests/common/tests/kalman_fitting_toy_detector_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,26 @@

namespace traccc {

/// Kalman Finding Test for toy geometry
class KalmanFittingToyDetectorTests : public KalmanFittingTests {
/// Kalman Fitting Test with Toy Geometry
///
/// Test parameters:
/// (1) name
/// (2) origin
/// (3) origin stddev
/// (4) momentum range
/// (5) eta range
/// (6) phi range
/// (7) particle type
/// (8) number of tracks per event
/// (9) number of events
/// (10) random charge
class KalmanFittingToyDetectorTests
: public KalmanFittingTests,
public testing::WithParamInterface<std::tuple<
std::string, std::array<scalar, 3u>, std::array<scalar, 3u>,
std::array<scalar, 2u>, std::array<scalar, 2u>,
std::array<scalar, 2u>, detray::pdg_particle<scalar>, unsigned int,
unsigned int, bool>> {

public:
/// Number of barrel layers
Expand Down
22 changes: 20 additions & 2 deletions tests/common/tests/kalman_fitting_wire_chamber_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,26 @@

namespace traccc {

/// Combinatorial Kalman Finding Test with Sparse tracks
class KalmanFittingWireChamberTests : public KalmanFittingTests {
/// Kalman Fitting Test with Wire Chamber
///
/// Test parameters:
/// (1) name
/// (2) origin
/// (3) origin stddev
/// (4) momentum range
/// (5) eta range
/// (6) phi range
/// (7) particle type
/// (8) number of tracks per event
/// (9) number of events
/// (10) random charge
class KalmanFittingWireChamberTests
: public KalmanFittingTests,
public testing::WithParamInterface<std::tuple<
std::string, std::array<scalar, 3u>, std::array<scalar, 3u>,
std::array<scalar, 2u>, std::array<scalar, 2u>,
std::array<scalar, 2u>, detray::pdg_particle<scalar>, unsigned int,
unsigned int, bool>> {

public:
/// Number of layers
Expand Down
28 changes: 13 additions & 15 deletions tests/cpu/test_ckf_combinatorics_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ TEST_P(CpuCkfCombinatoricsTelescopeTests, Run) {
// Make sure that the number of found tracks = n_track ^ (n_planes + 1)
ASSERT_TRUE(track_candidates.size() > track_candidates_limit.size());
ASSERT_EQ(track_candidates.size(),
std::pow(n_truth_tracks, plane_positions.size() + 1));
std::pow(n_truth_tracks, std::get<11>(GetParam()) + 1));
ASSERT_EQ(track_candidates_limit.size(),
n_truth_tracks * cfg_limit.max_num_branches_per_seed);
}
Expand All @@ -181,21 +181,19 @@ TEST_P(CpuCkfCombinatoricsTelescopeTests, Run) {
// Testing two identical tracks
INSTANTIATE_TEST_SUITE_P(
CpuCkfCombinatoricsTelescopeValidation0, CpuCkfCombinatoricsTelescopeTests,
::testing::Values(std::make_tuple("telescope_combinatorics_twin",
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{100.f, 100.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 2, 1, false)));
::testing::Values(std::make_tuple(
"telescope_combinatorics_twin", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{100.f, 100.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, detray::muon<scalar>(), 2, 1, false,
20.f, 9u, 20.f)));

// Testing three identical tracks
INSTANTIATE_TEST_SUITE_P(
CpuCkfCombinatoricsTelescopeValidation1, CpuCkfCombinatoricsTelescopeTests,
::testing::Values(std::make_tuple("telescope_combinatorics_trio",
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{100.f, 100.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 3, 1, false)));
::testing::Values(std::make_tuple(
"telescope_combinatorics_trio", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{100.f, 100.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, detray::muon<scalar>(), 3, 1, false,
20.f, 9u, 20.f)));
55 changes: 26 additions & 29 deletions tests/cpu/test_ckf_sparse_tracks_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,43 +209,39 @@ TEST_P(CkfSparseTrackTelescopeTests, Run) {

INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation0, CkfSparseTrackTelescopeTests,
::testing::Values(std::make_tuple("telescope_single_tracks",
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 1, 5000, false)));
::testing::Values(std::make_tuple(
"telescope_single_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, detray::muon<scalar>(), 1, 5000,
false, 20.f, 9u, 20.f)));

INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation1, CkfSparseTrackTelescopeTests,
::testing::Values(std::make_tuple("telescope_double_tracks",
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 2, 2500, false)));
::testing::Values(std::make_tuple(
"telescope_double_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, detray::muon<scalar>(), 2, 2500,
false, 20.f, 9u, 20.f)));

INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation2, CkfSparseTrackTelescopeTests,
::testing::Values(std::make_tuple("telescope_quadra_tracks",
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 4, 1250, false)));
::testing::Values(std::make_tuple(
"telescope_quadra_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, detray::muon<scalar>(), 4, 1250,
false, 20.f, 9u, 20.f)));

INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation3, CkfSparseTrackTelescopeTests,
::testing::Values(std::make_tuple("telescope_decade_tracks",
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 10, 500, false)));
::testing::Values(std::make_tuple(
"telescope_decade_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, detray::muon<scalar>(), 10, 500,
false, 20.f, 9u, 20.f)));

INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation4, CkfSparseTrackTelescopeTests,
Expand All @@ -255,4 +251,5 @@ INSTANTIATE_TEST_SUITE_P(
std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 10, 500, true)));
detray::muon<scalar>(), 10, 500, true,
20.f, 9u, 20.f)));
10 changes: 5 additions & 5 deletions tests/cpu/test_kalman_fitter_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ INSTANTIATE_TEST_SUITE_P(
"telescope_1_GeV_0_phi_muon", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f}, std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f}, std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 100, 100, false)));
detray::muon<scalar>(), 100, 100, false, 20.f, 9u, 20.f)));

INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation1, KalmanFittingTelescopeTests,
Expand All @@ -196,7 +196,7 @@ INSTANTIATE_TEST_SUITE_P(
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{10.f, 10.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, detray::muon<scalar>(), 100, 100,
false)));
false, 20.f, 9u, 20.f)));

INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation2, KalmanFittingTelescopeTests,
Expand All @@ -205,7 +205,7 @@ INSTANTIATE_TEST_SUITE_P(
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{100.f, 100.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, detray::muon<scalar>(), 100, 100,
false)));
false, 20.f, 9u, 20.f)));

INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation3, KalmanFittingTelescopeTests,
Expand All @@ -214,7 +214,7 @@ INSTANTIATE_TEST_SUITE_P(
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f}, std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f}, std::array<scalar, 2u>{0.f, 0.f},
detray::antimuon<scalar>(), 100, 100, false)));
detray::antimuon<scalar>(), 100, 100, false, 20.f, 9u, 20.f)));

INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation4, KalmanFittingTelescopeTests,
Expand All @@ -223,4 +223,4 @@ INSTANTIATE_TEST_SUITE_P(
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f}, std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f}, std::array<scalar, 2u>{0.f, 0.f},
detray::antimuon<scalar>(), 100, 100, true)));
detray::antimuon<scalar>(), 100, 100, true, 20.f, 9u, 20.f)));
8 changes: 5 additions & 3 deletions tests/cuda/test_ckf_combinatorics_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ TEST_P(CudaCkfCombinatoricsTelescopeTests, Run) {
ASSERT_TRUE(track_candidates_cuda.size() >
track_candidates_limit_cuda.size());
ASSERT_EQ(track_candidates_cuda.size(),
std::pow(n_truth_tracks, plane_positions.size() + 1));
std::pow(n_truth_tracks, std::get<11>(GetParam()) + 1));
ASSERT_EQ(track_candidates_limit_cuda.size(),
n_truth_tracks * cfg_limit.max_num_branches_per_seed);
}
Expand All @@ -246,11 +246,13 @@ INSTANTIATE_TEST_SUITE_P(
std::array<scalar, 2u>{100.f, 100.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 2, 1, false),
detray::muon<scalar>(), 2, 1, false, 20.f,
9u, 20.f),
std::make_tuple("telescope_combinatorics_trio",
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{100.f, 100.f},
std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f},
detray::muon<scalar>(), 3, 1, false)));
detray::muon<scalar>(), 3, 1, false, 20.f,
9u, 20.f)));
Loading
Loading