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

fix: Fix Fatras end of world #2580

Merged
merged 8 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Navigator {

bool targetReached(const State& state) const { return state.targetReached; }

bool endOfWorldReached(State& state) const {
bool endOfWorldReached(const State& state) const {
return state.currentVolume == nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class FatrasSimulation final : public IAlgorithm {
/// have associated material.
bool generateHitsOnPassive = false;

/// Absolute maximum step size
double maxStepSize = 1 * Acts::UnitConstants::m;
/// Absolute maximum path length
double pathLimit = 10 * Acts::UnitConstants::m;
andiwand marked this conversation as resolved.
Show resolved Hide resolved

/// Expected average number of hits generated per particle.
///
/// This is just a performance optimization hint and has no impact on the
Expand Down
5 changes: 5 additions & 0 deletions Examples/Algorithms/Fatras/src/FatrasSimulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ struct FatrasSimulationT final : ActsExamples::detail::FatrasSimulation {
simulation.charged.selectHitSurface.sensitive = cfg.generateHitsOnSensitive;
simulation.charged.selectHitSurface.material = cfg.generateHitsOnMaterial;
simulation.charged.selectHitSurface.passive = cfg.generateHitsOnPassive;

simulation.charged.maxStepSize = cfg.maxStepSize;
simulation.charged.pathLimit = cfg.pathLimit;
simulation.neutral.maxStepSize = cfg.maxStepSize;
simulation.neutral.pathLimit = cfg.pathLimit;
}
~FatrasSimulationT() final = default;

Expand Down
6 changes: 6 additions & 0 deletions Fatras/include/ActsFatras/Kernel/Simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ template <typename propagator_t, typename interactions_t,
struct SingleParticleSimulation {
/// How and within which geometry to propagate the particle.
propagator_t propagator;
/// Absolute maximum step size
double maxStepSize = std::numeric_limits<double>::max();
/// Absolute maximum path length
double pathLimit = std::numeric_limits<double>::max();
/// Decay module.
decay_t decay;
/// Interaction list containing the simulated interactions.
Expand Down Expand Up @@ -83,6 +87,8 @@ struct SingleParticleSimulation {

// Construct per-call options.
PropagatorOptions options(geoCtx, magCtx);
options.maxStepSize = maxStepSize;
options.pathLimit = pathLimit;
// setup the interactor as part of the propagator options
auto &actor = options.actionList.template get<Actor>();
actor.generator = &generator;
Expand Down
15 changes: 12 additions & 3 deletions Fatras/include/ActsFatras/Kernel/detail/SimulationActor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

#include "Acts/Material/ISurfaceMaterial.hpp"
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/StandardAborters.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "ActsFatras/EventData/Hit.hpp"
#include "ActsFatras/EventData/Particle.hpp"
#include "ActsFatras/Kernel/SimulationResult.hpp"

#include <algorithm>
#include <cassert>
#include <cmath>
#include <limits>

namespace ActsFatras {
Expand Down Expand Up @@ -84,14 +86,19 @@ struct SimulationActor {
typename navigator_t>
void operator()(propagator_state_t &state, stepper_t &stepper,
navigator_t &navigator, result_type &result,
const Acts::Logger & /*logger*/) const {
const Acts::Logger &logger) const {
assert(generator and "The generator pointer must be valid");

// actors are called once more after the propagation terminated
if (not result.isAlive) {
return;
}

if (Acts::EndOfWorldReached{}(state, stepper, navigator, logger)) {
result.isAlive = false;
return;
}

// check if we are still on the start surface and skip if so
if ((navigator.startSurface(state.navigation) != nullptr) &&
(navigator.startSurface(state.navigation) ==
Expand All @@ -116,8 +123,9 @@ struct SimulationActor {
}

// decay check. needs to happen at every step, not just on surfaces.
if (result.properTimeLimit - result.particle.properTime() <
result.properTimeLimit * properTimeRelativeTolerance) {
if (std::isfinite(result.properTimeLimit) &&
(result.properTimeLimit - result.particle.properTime() <
result.properTimeLimit * properTimeRelativeTolerance)) {
auto descendants = decay.run(generator, result.particle);
for (auto &&descendant : descendants) {
result.generatedParticles.emplace_back(std::move(descendant));
Expand All @@ -128,6 +136,7 @@ struct SimulationActor {

// Regulate the step size
if (std::isfinite(result.properTimeLimit)) {
assert(result.particle.mass() > 0.0 && "Particle must have mass");
// beta² = p²/E²
// gamma = 1 / sqrt(1 - beta²) = sqrt(m² + p²) / m = E / m
// time = proper-time * gamma
Expand Down
8 changes: 8 additions & 0 deletions Tests/UnitTests/Fatras/Kernel/SimulationActorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,21 @@ struct MockNavigator {
return state.targetReached;
}

void targetReached(MockNavigatorState &state, bool reached) const {
state.targetReached = reached;
}

const Acts::Surface *startSurface(const MockNavigatorState &state) const {
return state.startSurface;
}

const Acts::Surface *currentSurface(const MockNavigatorState &state) const {
return state.currentSurface;
}

bool endOfWorldReached(const MockNavigatorState & /*state*/) const {
return false;
}
};

struct MockPropagatorState {
Expand Down
Loading