Skip to content

Commit e8d0998

Browse files
authored
ref: update random scatter only when material is non-zero (#967)
Update the track momentum and trigger re-navigation only when the surface has material with non-zero thickness.
1 parent 101a685 commit e8d0998

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

tests/include/detray/test/utils/simulation/random_scatterer.hpp

+26-24
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,32 @@ struct random_scatterer : actor {
149149
bound_params.dir(),
150150
bound_params.bound_local())};
151151

152-
sf.template visit_material<kernel>(simulator_state, ptc, bound_params,
153-
cos_inc_angle,
154-
bound_params.bound_local()[0]);
155-
156-
// Get the new momentum
157-
const auto new_mom =
158-
attenuate(simulator_state.e_loss_mpv, simulator_state.e_loss_sigma,
159-
ptc.mass(), bound_params.p(ptc.charge()),
160-
simulator_state.generator);
161-
162-
// Update Qop
163-
bound_params.set_qop(ptc.charge() / new_mom);
164-
165-
// Get the new direction from random scattering
166-
const auto new_dir = scatter(bound_params.dir(),
167-
simulator_state.projected_scattering_angle,
168-
simulator_state.generator);
169-
170-
// Update Phi and Theta
171-
stepping.bound_params().set_phi(vector::phi(new_dir));
172-
stepping.bound_params().set_theta(vector::theta(new_dir));
173-
174-
// Flag renavigation of the current candidate
175-
prop_state._navigation.set_high_trust();
152+
const bool success = sf.template visit_material<kernel>(
153+
simulator_state, ptc, bound_params, cos_inc_angle,
154+
bound_params.bound_local()[0]);
155+
156+
if (success) {
157+
// Get the new momentum
158+
const auto new_mom = attenuate(
159+
simulator_state.e_loss_mpv, simulator_state.e_loss_sigma,
160+
ptc.mass(), bound_params.p(ptc.charge()),
161+
simulator_state.generator);
162+
163+
// Update Qop
164+
bound_params.set_qop(ptc.charge() / new_mom);
165+
166+
// Get the new direction from random scattering
167+
const auto new_dir = scatter(
168+
bound_params.dir(), simulator_state.projected_scattering_angle,
169+
simulator_state.generator);
170+
171+
// Update Phi and Theta
172+
stepping.bound_params().set_phi(vector::phi(new_dir));
173+
stepping.bound_params().set_theta(vector::theta(new_dir));
174+
175+
// Flag renavigation of the current candidate
176+
prop_state._navigation.set_high_trust();
177+
}
176178
}
177179

178180
/// @brief Get the new momentum from the landau distribution

0 commit comments

Comments
 (0)