Skip to content

Commit 3bf3721

Browse files
committed
Terminate simulation if the particle goes below a certain energy and only if material was found
1 parent 64c9360 commit 3bf3721

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

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

+29-19
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ struct random_scatterer : actor {
4343
std::random_device rd{};
4444
std::mt19937_64 generator{rd()};
4545

46+
/// Minimum momentum before simulation is stopped
47+
scalar_type e_min_p = 10.f * unit<scalar_type>::MeV;
48+
4649
/// most probable energy loss
4750
scalar_type e_loss_mpv = 0.f;
4851

@@ -149,30 +152,37 @@ struct random_scatterer : actor {
149152
bound_params.dir(),
150153
bound_params.bound_local())};
151154

152-
sf.template visit_material<kernel>(simulator_state, ptc, bound_params,
153-
cos_inc_angle,
154-
bound_params.bound_local()[0]);
155+
const bool success = sf.template visit_material<kernel>(
156+
simulator_state, ptc, bound_params, cos_inc_angle,
157+
bound_params.bound_local()[0]);
155158

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);
159+
if (success) {
160+
// Get the new momentum
161+
const auto new_mom = attenuate(
162+
simulator_state.e_loss_mpv, simulator_state.e_loss_sigma,
163+
ptc.mass(), bound_params.p(ptc.charge()),
164+
simulator_state.generator);
161165

162-
// Update Qop
163-
bound_params.set_qop(ptc.charge() / new_mom);
166+
// Update Qop
167+
bound_params.set_qop(ptc.charge() / new_mom);
164168

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+
// Get the new direction from random scattering
170+
const auto new_dir = scatter(
171+
bound_params.dir(), simulator_state.projected_scattering_angle,
172+
simulator_state.generator);
169173

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));
174+
// Update Phi and Theta
175+
stepping.bound_params().set_phi(vector::phi(new_dir));
176+
stepping.bound_params().set_theta(vector::theta(new_dir));
173177

174-
// Flag renavigation of the current candidate
175-
prop_state._navigation.set_high_trust();
178+
if (bound_params.p(ptc.charge()) < simulator_state.e_min_p) {
179+
// Particle below minimum p for simulation: stop
180+
prop_state._heartbeat &= prop_state._navigation.abort();
181+
} else {
182+
// Flag renavigation of the current candidate
183+
prop_state._navigation.set_high_trust();
184+
}
185+
}
176186
}
177187

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

0 commit comments

Comments
 (0)