Skip to content

Commit

Permalink
Update the navigation config to the ODD/ITk defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Oct 14, 2024
1 parent e0d1d15 commit c2c3736
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 63 deletions.
4 changes: 2 additions & 2 deletions core/include/detray/navigation/navigation_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ struct config {
/// Minimal tolerance: ~ position uncertainty on surface
float min_mask_tolerance{1e-5f * unit<float>::mm};
/// Maximal tolerance: loose tolerance when still far away from surface
float max_mask_tolerance{1.f * unit<float>::mm};
float max_mask_tolerance{3.f * unit<float>::mm};
/// Scale factor on the path used for the mask tolerance calculation
float mask_tolerance_scalor{5e-2f};
/// @}
/// Maximal absolute path distance for a track to be considered 'on surface'
float path_tolerance{1.f * unit<float>::um};
/// How far behind the track position to look for candidates
float overstep_tolerance{-100.f * unit<float>::um};
float overstep_tolerance{-300.f * unit<float>::um};
/// Search window size for grid based acceleration structures
/// (0, 0): only look at current bin
std::array<dindex, 2> search_window = {0u, 0u};
Expand Down
6 changes: 4 additions & 2 deletions core/include/detray/propagator/line_stepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class line_stepper final
/// @return returning the heartbeat, indicating if the stepping is alive
template <typename propagation_state_t>
DETRAY_HOST_DEVICE bool step(propagation_state_t& propagation,
const stepping::config& cfg = {}) const {
const stepping::config& cfg) const {
// Get stepper and navigator states
state& stepping = propagation._stepping;
auto& navigation = propagation._navigation;
Expand Down Expand Up @@ -125,7 +125,9 @@ class line_stepper final
stepping.advance_track();

// Advance jacobian transport
stepping.advance_jacobian();
if (cfg.do_covariance_transport) {
stepping.advance_jacobian();
}

// Count the number of steps
stepping.count_trials();
Expand Down
2 changes: 1 addition & 1 deletion core/include/detray/propagator/propagator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct propagator {

/// Construct from a propagator configuration
DETRAY_HOST_DEVICE
explicit constexpr propagator(const propagation::config &cfg = {})
explicit constexpr propagator(const propagation::config &cfg)
: m_cfg{cfg} {}

/// Propagation that state aggregates a stepping and a navigation state. It
Expand Down
14 changes: 10 additions & 4 deletions tests/integration_tests/cpu/material/material_interaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ GTEST_TEST(detray_material, telescope_geometry_energy_loss) {
using propagator_t = propagator<stepper_t, navigator_t, actor_chain_t>;

// Propagator is built from the stepper and navigator
propagator_t p{};
propagation::config prop_cfg{};
prop_cfg.navigation.overstep_tolerance = -100.f * unit<float>::um;
propagator_t p{prop_cfg};

constexpr scalar q{-1.f};
constexpr scalar iniP{10.f * unit<scalar>::GeV};
Expand Down Expand Up @@ -193,7 +195,7 @@ GTEST_TEST(detray_material, telescope_geometry_energy_loss) {
interactor_state, parameter_resetter_state);

// Propagator and its state
alt_propagator_t alt_p{};
alt_propagator_t alt_p{prop_cfg};
alt_propagator_t::state alt_state(alt_bound_param, det);

// Propagate
Expand Down Expand Up @@ -251,7 +253,9 @@ GTEST_TEST(detray_material, telescope_geometry_scattering_angle) {
using propagator_t = propagator<stepper_t, navigator_t, actor_chain_t>;

// Propagator is built from the stepper and navigator
propagator_t p{};
propagation::config prop_cfg{};
prop_cfg.navigation.overstep_tolerance = -100.f * unit<float>::um;
propagator_t p{prop_cfg};

constexpr scalar q{-1.f};
constexpr scalar iniP{10.f * unit<scalar>::GeV};
Expand Down Expand Up @@ -381,7 +385,9 @@ GTEST_TEST(detray_material, telescope_geometry_volume_material) {
using propagator_t = propagator<stepper_t, navigator_t, actor_chain_t>;

// Propagator is built from the stepper and navigator
propagator_t p{};
propagation::config prop_cfg{};
prop_cfg.navigation.overstep_tolerance = -100.f * unit<float>::um;
propagator_t p{prop_cfg};

propagator_t::state state(bound_param, const_bfield, det);

Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests/cpu/propagator/guided_navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ GTEST_TEST(detray_navigation, guided_navigator) {
pathlimit_aborter::state pathlimit{200.f * unit<scalar_t>::cm};

// Propagator
propagator_t p{};
propagation::config prop_cfg{};
propagator_t p{prop_cfg};
propagator_t::state guided_state(track, b_field, telescope_det);

// Propagate
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests/cpu/propagator/propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ GTEST_TEST(detray_propagator, propagator_line_stepper) {
const vector3 mom{1.f, 1.f, 0.f};
free_track_parameters<algebra_t> track(pos, 0.f, mom, -1.f);

propagator_t p{};
propagation::config prop_cfg{};
propagator_t p{prop_cfg};

propagator_t::state state(track, d);

Expand Down
72 changes: 40 additions & 32 deletions tests/unit_tests/cpu/navigation/navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,18 @@ inline void check_volume_switch(state_t &state, dindex vol_id) {
template <typename navigator_t, typename stepper_t, typename prop_state_t>
inline void step_and_check(navigator_t &nav, stepper_t &stepper,
prop_state_t &propagation,
const navigation::config &cfg, dindex vol_id,
const navigation::config &nav_cfg,
const stepping::config &step_cfg, dindex vol_id,
std::size_t n_candidates, dindex current_id,
dindex next_id) {
auto &navigation = propagation._navigation;

// Step onto the surface in volume
stepper.step(propagation);
stepper.step(propagation, step_cfg);
navigation.set_high_trust();
// Stepper reduced trust level
ASSERT_TRUE(navigation.trust_level() == navigation::trust_level::e_high);
ASSERT_TRUE(nav.update(propagation, cfg));
ASSERT_TRUE(nav.update(propagation, nav_cfg));
// Trust level is restored
ASSERT_EQ(navigation.trust_level(), navigation::trust_level::e_full);
// The status is on surface
Expand Down Expand Up @@ -143,8 +144,10 @@ GTEST_TEST(detray_navigation, navigator_toy_geometry) {

stepper_t stepper;
navigator_t nav;
navigation::config cfg{};
cfg.search_window = {3u, 3u};
navigation::config nav_cfg{};
nav_cfg.search_window = {3u, 3u};

stepping::config step_cfg{};

prop_state<stepper_t::state, navigator_t::state> propagation{
stepper_t::state{traj}, navigator_t::state(toy_det)};
Expand All @@ -167,7 +170,7 @@ GTEST_TEST(detray_navigation, navigator_toy_geometry) {

// Initialize navigation
// Test that the navigator has a heartbeat
ASSERT_TRUE(nav.init(propagation, cfg));
ASSERT_TRUE(nav.init(propagation, nav_cfg));
// The status is towards beampipe
// Two candidates: beampipe and portal
// First candidate is the beampipe
Expand All @@ -178,14 +181,14 @@ GTEST_TEST(detray_navigation, navigator_toy_geometry) {
// Let's make half the step towards the beampipe
stepping.template set_constraint<step::constraint::e_user>(navigation() *
0.5f);
stepper.step(propagation);
stepper.step(propagation, step_cfg);
// Navigation policy might reduce trust level to fair trust
navigation.set_fair_trust();
// Release user constraint again
stepping.template release_step<step::constraint::e_user>();
ASSERT_TRUE(navigation.trust_level() == trust_level::e_fair);
// Re-navigate
ASSERT_TRUE(nav.update(propagation, cfg));
ASSERT_TRUE(nav.update(propagation, nav_cfg));
// Trust level is restored
ASSERT_EQ(navigation.trust_level(), trust_level::e_full);
// The status remains: towards surface
Expand All @@ -194,20 +197,21 @@ GTEST_TEST(detray_navigation, navigator_toy_geometry) {
ASSERT_NEAR(navigation(), 9.5f, tol);

// Let's immediately update, nothing should change, as there is full trust
ASSERT_TRUE(nav.update(propagation, cfg));
ASSERT_TRUE(nav.update(propagation, nav_cfg));
check_towards_surface<navigator_t>(navigation, 0u, 2u, 0u);
ASSERT_NEAR(navigation(), 9.5f, tol);

// Now step onto the beampipe (idx 0)
step_and_check(nav, stepper, propagation, cfg, 0u, 1u, 0u, 8u);
step_and_check(nav, stepper, propagation, nav_cfg, step_cfg, 0u, 1u, 0u,
8u);
// New target: Distance to the beampipe volume cylinder portal
ASSERT_NEAR(navigation(), 6.f, tol);

// Step onto portal 7 in volume 0
stepper.step(propagation);
stepper.step(propagation, step_cfg);
navigation.set_high_trust();
ASSERT_TRUE(navigation.trust_level() == trust_level::e_high);
ASSERT_TRUE(nav.update(propagation, cfg))
ASSERT_TRUE(nav.update(propagation, nav_cfg))
<< navigation.inspector().to_string();
ASSERT_EQ(navigation.trust_level(), trust_level::e_full);
ASSERT_EQ(navigation.volume(), 8u);
Expand Down Expand Up @@ -264,17 +268,18 @@ GTEST_TEST(detray_navigation, navigator_toy_geometry) {
// Step through the module surfaces
for (std::size_t sf = 1u; sf < sf_seq.size() - 1u; ++sf) {
// Count only the currently reachable candidates
step_and_check(nav, stepper, propagation_cpy, cfg, vol_id,
n_candidates - sf, sf_seq[sf], sf_seq[sf + 1u]);
step_and_check(nav, stepper, propagation_cpy, nav_cfg, step_cfg,
vol_id, n_candidates - sf, sf_seq[sf],
sf_seq[sf + 1u]);
}

// Step onto the portal in volume
stepper.step(propagation_cpy);
stepper.step(propagation_cpy, step_cfg);
navigation_cpy.set_high_trust();

// Check agianst last volume
if (vol_id == last_vol_id) {
ASSERT_FALSE(nav.update(propagation_cpy, cfg));
ASSERT_FALSE(nav.update(propagation_cpy, nav_cfg));
// The status is: exited
ASSERT_EQ(navigation_cpy.status(), status::e_on_target);
// Switch to next volume leads out of the detector world -> exit
Expand All @@ -283,7 +288,7 @@ GTEST_TEST(detray_navigation, navigator_toy_geometry) {
// We know we went out of the detector
ASSERT_EQ(navigation_cpy.trust_level(), trust_level::e_full);
} else {
ASSERT_TRUE(nav.update(propagation_cpy, cfg));
ASSERT_TRUE(nav.update(propagation_cpy, nav_cfg));
}

// Update the propagation state with current step (test assignment op)
Expand Down Expand Up @@ -325,10 +330,12 @@ GTEST_TEST(detray_navigation, navigator_wire_chamber) {

stepper_t stepper;
navigator_t nav;
navigation::config cfg{};
cfg.mask_tolerance_scalor = 1e-2f;
cfg.path_tolerance = 1.f * unit<float>::um;
cfg.search_window = {3u, 3u};
navigation::config nav_cfg{};
nav_cfg.mask_tolerance_scalor = 1e-2f;
nav_cfg.path_tolerance = 1.f * unit<float>::um;
nav_cfg.search_window = {3u, 3u};

stepping::config step_cfg{};

prop_state<stepper_t::state, navigator_t::state> propagation{
stepper_t::state{traj}, navigator_t::state(wire_det)};
Expand All @@ -351,7 +358,7 @@ GTEST_TEST(detray_navigation, navigator_wire_chamber) {

// Initialize navigation
// Test that the navigator has a heartbeat
ASSERT_TRUE(nav.init(propagation, cfg));
ASSERT_TRUE(nav.init(propagation, nav_cfg));
// The status is towards portal
// One candidates: barrel cylinder portal
check_towards_surface<navigator_t>(navigation, 0u, 1u, 0u);
Expand All @@ -361,14 +368,14 @@ GTEST_TEST(detray_navigation, navigator_wire_chamber) {
// Let's make half the step towards the portal
stepping.template set_constraint<step::constraint::e_user>(navigation() *
0.5f);
stepper.step(propagation);
stepper.step(propagation, step_cfg);
// Navigation policy might reduce trust level to fair trust
navigation.set_fair_trust();
// Release user constraint again
stepping.template release_step<step::constraint::e_user>();
ASSERT_TRUE(navigation.trust_level() == trust_level::e_fair);
// Re-navigate
ASSERT_TRUE(nav.update(propagation, cfg));
ASSERT_TRUE(nav.update(propagation, nav_cfg));
// Trust level is restored
ASSERT_EQ(navigation.trust_level(), trust_level::e_full);
// The status remains: towards surface
Expand All @@ -377,15 +384,15 @@ GTEST_TEST(detray_navigation, navigator_wire_chamber) {
ASSERT_NEAR(navigation(), 250.f * unit<scalar>::mm, tol);

// Let's immediately update, nothing should change, as there is full trust
ASSERT_TRUE(nav.update(propagation, cfg));
ASSERT_TRUE(nav.update(propagation, nav_cfg));
check_towards_surface<navigator_t>(navigation, 0u, 1u, 0u);
ASSERT_NEAR(navigation(), 250.f * unit<scalar>::mm, tol);

// Step onto portal in volume 0
stepper.step(propagation);
stepper.step(propagation, step_cfg);
navigation.set_high_trust();
ASSERT_TRUE(navigation.trust_level() == trust_level::e_high);
ASSERT_TRUE(nav.update(propagation, cfg))
ASSERT_TRUE(nav.update(propagation, nav_cfg))
<< navigation.inspector().to_string();
ASSERT_EQ(navigation.trust_level(), trust_level::e_full);

Expand Down Expand Up @@ -431,17 +438,18 @@ GTEST_TEST(detray_navigation, navigator_wire_chamber) {
// Step through the module surfaces
for (std::size_t sf = 1u; sf < sf_seq.size() - 1u; ++sf) {
// Count only the currently reachable candidates
step_and_check(nav, stepper, propagation_cpy, cfg, vol_id,
n_candidates - sf, sf_seq[sf], sf_seq[sf + 1u]);
step_and_check(nav, stepper, propagation_cpy, nav_cfg, step_cfg,
vol_id, n_candidates - sf, sf_seq[sf],
sf_seq[sf + 1u]);
}

// Step onto the portal in volume
stepper.step(propagation_cpy);
stepper.step(propagation_cpy, step_cfg);
navigation_cpy.set_high_trust();

// Check agianst last volume
if (vol_id == last_vol_id) {
ASSERT_FALSE(nav.update(propagation_cpy, cfg));
ASSERT_FALSE(nav.update(propagation_cpy, nav_cfg));
// The status is: exited
ASSERT_EQ(navigation_cpy.status(), status::e_on_target);
// Switch to next volume leads out of the detector world -> exit
Expand All @@ -450,7 +458,7 @@ GTEST_TEST(detray_navigation, navigator_wire_chamber) {
// We know we went out of the detector
ASSERT_EQ(navigation_cpy.trust_level(), trust_level::e_full);
} else {
ASSERT_TRUE(nav.update(propagation_cpy, cfg))
ASSERT_TRUE(nav.update(propagation_cpy, nav_cfg))
<< navigation_cpy.inspector().to_string();
}

Expand Down
4 changes: 3 additions & 1 deletion tests/unit_tests/cpu/propagator/covariance_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ GTEST_TEST(detray_propagator, covariance_transport) {
parameter_transporter<algebra_t>::state bound_updater{};
parameter_resetter<algebra_t>::state rst{};

propagator_t p{};
propagation::config prop_cfg{};
prop_cfg.navigation.overstep_tolerance = -100.f * unit<float>::um;
propagator_t p{prop_cfg};
propagator_t::state propagation(bound_param0, det);

// Run propagator
Expand Down
10 changes: 6 additions & 4 deletions tests/unit_tests/cpu/propagator/line_stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ GTEST_TEST(detray_propagator, line_stepper) {
free_track_parameters<algebra_t> track(pos, 0.f, mom, -1.f);
free_track_parameters<algebra_t> c_track(pos, 0.f, mom, -1.f);

stepping::config step_cfg{};

line_stepper_t l_stepper;
cline_stepper_t cl_stepper;

Expand Down Expand Up @@ -121,10 +123,10 @@ GTEST_TEST(detray_propagator, line_stepper) {
0.5f * unit<scalar>::mm, tol);

// Run a few steps
ASSERT_TRUE(l_stepper.step(propagation));
ASSERT_TRUE(l_stepper.step(propagation, step_cfg));
// Step constraint to half step size
ASSERT_TRUE(cl_stepper.step(c_propagation));
ASSERT_TRUE(cl_stepper.step(c_propagation));
ASSERT_TRUE(cl_stepper.step(c_propagation, step_cfg));
ASSERT_TRUE(cl_stepper.step(c_propagation, step_cfg));

track = propagation._stepping();
ASSERT_NEAR(track.pos()[0], constant<scalar>::inv_sqrt2, tol);
Expand All @@ -136,7 +138,7 @@ GTEST_TEST(detray_propagator, line_stepper) {
ASSERT_NEAR(c_track.pos()[1], constant<scalar>::inv_sqrt2, tol);
ASSERT_NEAR(c_track.pos()[2], 0.f, tol);

ASSERT_TRUE(l_stepper.step(propagation));
ASSERT_TRUE(l_stepper.step(propagation, step_cfg));

track = propagation._stepping();
ASSERT_NEAR(track.pos()[0], constant<scalar>::sqrt2, tol);
Expand Down
Loading

0 comments on commit c2c3736

Please sign in to comment.