diff --git a/tests/integration_tests/cpu/propagator/backward_propagation.cpp b/tests/integration_tests/cpu/propagator/backward_propagation.cpp index b5a4d36a2..286597261 100644 --- a/tests/integration_tests/cpu/propagator/backward_propagation.cpp +++ b/tests/integration_tests/cpu/propagator/backward_propagation.cpp @@ -15,6 +15,7 @@ #include "detray/propagator/actor_chain.hpp" #include "detray/propagator/actors/parameter_resetter.hpp" #include "detray/propagator/actors/parameter_transporter.hpp" +#include "detray/propagator/actors/pointwise_material_interactor.hpp" #include "detray/propagator/propagator.hpp" #include "detray/propagator/rk_stepper.hpp" #include "detray/tracks/tracks.hpp" @@ -37,40 +38,50 @@ using point2 = test::point2; using vector3 = test::vector3; using matrix_operator = test::matrix_operator; -constexpr test::scalar tol{5e-3f}; +// Test class for the backward propagation +// Input tuple: < std::vector, tolerance > +class BackwardPropagation + : public ::testing::TestWithParam< + std::tuple, test::scalar>> {}; -GTEST_TEST(detray_propagator, backward_propagation) { +TEST_P(BackwardPropagation, backward_propagation) { + + const test::scalar tol = std::get<1>(GetParam()); vecmem::host_memory_resource host_mr; // Build in x-direction from given module positions detail::ray traj{{0.f, 0.f, 0.f}, 0.f, {1.f, 0.f, 0.f}, -1.f}; - std::vector positions = {0.f, 10.f, 20.f, 30.f, 40.f, 50.f, - 60.f, 70.f, 80.f, 90.f, 100.f}; + std::vector positions = std::get<0>(GetParam()); tel_det_config tel_cfg{200.f * unit::mm, 200.f * unit::mm}; - tel_cfg.positions(positions).pilot_track(traj); + tel_cfg.positions(positions).pilot_track(traj).mat_thickness( + 10.f * unit::mm); // Build telescope detector with rectangular planes const auto [det, names] = build_telescope_detector(host_mr, tel_cfg); // Create b field using bfield_t = bfield::const_field_t; - vector3 B{1.f * unit::T, 1.f * unit::T, + vector3 B{0.f * unit::T, 0.f * unit::T, 1.f * unit::T}; const bfield_t hom_bfield = bfield::create_const_field(B); using navigator_t = navigator; using rk_stepper_t = rk_stepper; using actor_chain_t = actor_chain, + pointwise_material_interactor, parameter_resetter>; using propagator_t = propagator; + // Particle hypothesis + pdg_particle ptc = muon(); + // Bound vector bound_parameters_vector bound_vector{}; bound_vector.set_theta(constant::pi_2); - bound_vector.set_qop(-1.f); + bound_vector.set_qop(ptc.charge() / (1.f * unit::GeV)); // Bound covariance typename bound_track_parameters::covariance_type bound_cov = @@ -82,6 +93,7 @@ GTEST_TEST(detray_propagator, backward_propagation) { // Actors parameter_transporter::state bound_updater{}; + pointwise_material_interactor::state interactor{}; parameter_resetter::state rst{}; propagation::config prop_cfg{}; @@ -92,10 +104,11 @@ GTEST_TEST(detray_propagator, backward_propagation) { // Forward state propagator_t::state fw_state(bound_param0, hom_bfield, det, prop_cfg.context); + fw_state.set_particle(ptc); fw_state.do_debug = true; // Run propagator - p.propagate(fw_state, detray::tie(bound_updater, rst)); + p.propagate(fw_state, detray::tie(bound_updater, interactor, rst)); // Print the debug stream // std::cout << fw_state.debug_stream.str() << std::endl; @@ -108,16 +121,17 @@ GTEST_TEST(detray_propagator, backward_propagation) { EXPECT_EQ(bound_param0.surface_link().index(), 0u); EXPECT_EQ(bound_param1.surface_link().volume(), 0u); EXPECT_EQ(bound_param1.surface_link().id(), surface_id::e_sensitive); - EXPECT_EQ(bound_param1.surface_link().index(), 10u); + EXPECT_EQ(bound_param1.surface_link().index(), positions.size() - 1u); // Backward state propagator_t::state bw_state(bound_param1, hom_bfield, det, prop_cfg.context); + bw_state.set_particle(ptc); bw_state.do_debug = true; bw_state._navigation.set_direction(navigation::direction::e_backward); // Run propagator - p.propagate(bw_state, detray::tie(bound_updater, rst)); + p.propagate(bw_state, detray::tie(bound_updater, interactor, rst)); // Print the debug stream // std::cout << bw_state.debug_stream.str() << std::endl; @@ -140,6 +154,7 @@ GTEST_TEST(detray_propagator, backward_propagation) { } const auto bound_cov0 = bound_param0.covariance(); + const auto bound_cov1 = bound_param1.covariance(); const auto bound_cov2 = bound_param2.covariance(); // Check covaraince @@ -149,4 +164,32 @@ GTEST_TEST(detray_propagator, backward_propagation) { matrix_operator().element(bound_cov2, i, j), tol); } } + + // Some sanity checks + EXPECT_TRUE(bound_param0.p(ptc.charge()) > bound_param1.p(ptc.charge())); + EXPECT_TRUE(bound_param2.p(ptc.charge()) > bound_param1.p(ptc.charge())); + + EXPECT_TRUE(getter::element(bound_cov1, e_bound_qoverp, e_bound_qoverp) > + getter::element(bound_cov0, e_bound_qoverp, e_bound_qoverp)); + EXPECT_TRUE(getter::element(bound_cov1, e_bound_theta, e_bound_theta) > + getter::element(bound_cov0, e_bound_theta, e_bound_theta)); + EXPECT_TRUE(getter::element(bound_cov1, e_bound_phi, e_bound_phi) > + getter::element(bound_cov0, e_bound_phi, e_bound_phi)); + + EXPECT_TRUE(getter::element(bound_cov1, e_bound_qoverp, e_bound_qoverp) > + getter::element(bound_cov2, e_bound_qoverp, e_bound_qoverp)); + EXPECT_TRUE(getter::element(bound_cov1, e_bound_theta, e_bound_theta) > + getter::element(bound_cov2, e_bound_theta, e_bound_theta)); + EXPECT_TRUE(getter::element(bound_cov1, e_bound_phi, e_bound_phi) > + getter::element(bound_cov2, e_bound_phi, e_bound_phi)); } + +INSTANTIATE_TEST_SUITE_P( + telescope, BackwardPropagation, + ::testing::Values( + std::make_tuple(std::vector{0.f}, 1e-5f), + std::make_tuple(std::vector{0.f, 10.f}, 1e-3f), + std::make_tuple(std::vector{0.f, 10.f, 20.f, 30.f, 40.f, + 50.f, 60.f, 70.f, 80.f, 90.f, + 100.f}, + 1e-2f)));