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

refactor!: Split propagator options #3181

Merged
merged 11 commits into from
Jul 12, 2024
4 changes: 3 additions & 1 deletion Core/include/Acts/Material/PropagatorMaterialAssigner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ class PropagatorMaterialAssigner final : public IAssignmentFinder {
using ActionList =
ActionList<MaterialSurfaceCollector, InteractionVolumeCollector>;
using AbortList = AbortList<EndOfWorldReached>;
using PropagatorOptions =
typename propagator_t::template Options<ActionList, AbortList>;

PropagatorOptions<ActionList, AbortList> options(gctx, mctx);
PropagatorOptions options(gctx, mctx);

const auto& result = m_propagator.propagate(start, options).value();

Expand Down
7 changes: 7 additions & 0 deletions Core/include/Acts/Navigation/DetectorNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/Layer.hpp"
#include "Acts/Navigation/NavigationState.hpp"
#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/Surface.hpp"
Expand Down Expand Up @@ -46,6 +47,12 @@ class DetectorNavigator {
bool resolvePassive = false;
};

struct Options : public NavigatorPlainOptions {
void setPlainOptions(const NavigatorPlainOptions& options) {
static_cast<NavigatorPlainOptions&>(*this) = options;
andiwand marked this conversation as resolved.
Show resolved Hide resolved
}
};

/// Nested State struct
///
/// It acts as an internal state which is
Expand Down
17 changes: 15 additions & 2 deletions Core/include/Acts/Propagator/AtlasStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Acts/MagneticField/MagneticFieldContext.hpp"
#include "Acts/MagneticField/MagneticFieldProvider.hpp"
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/StepperOptions.hpp"
#include "Acts/Propagator/detail/SteppingHelper.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Intersection.hpp"
Expand All @@ -40,6 +41,16 @@ class AtlasStepper {
using CurvilinearState =
std::tuple<CurvilinearTrackParameters, Jacobian, double>;

struct Config {
std::shared_ptr<const MagneticFieldProvider> bField;
};

struct Options : public StepperPlainOptions {
void setPlainOptions(const StepperPlainOptions& options) {
static_cast<StepperPlainOptions&>(*this) = options;
}
};

/// @brief Nested State struct for the local caching
struct State {
/// Default constructor - deleted
Expand Down Expand Up @@ -296,9 +307,11 @@ class AtlasStepper {
std::size_t debugMsgWidth = 50;
};

AtlasStepper(std::shared_ptr<const MagneticFieldProvider> bField)
explicit AtlasStepper(std::shared_ptr<const MagneticFieldProvider> bField)
: m_bField(std::move(bField)) {}

explicit AtlasStepper(const Config& config) : m_bField(config.bField) {}

State makeState(std::reference_wrapper<const GeometryContext> gctx,
std::reference_wrapper<const MagneticFieldContext> mctx,
const BoundTrackParameters& par,
Expand Down Expand Up @@ -1258,7 +1271,7 @@ class AtlasStepper {
2. * h *
(std::abs((A1 + A6) - (A3 + A4)) + std::abs((B1 + B6) - (B3 + B4)) +
std::abs((C1 + C6) - (C3 + C4)));
if (std::abs(EST) > std::abs(state.options.stepTolerance)) {
if (std::abs(EST) > std::abs(state.options.stepping.stepTolerance)) {
h = h * .5;
// neutralize the sign of h again
state.stepping.stepSize.setAccuracy(h * state.options.direction);
Expand Down
66 changes: 6 additions & 60 deletions Core/include/Acts/Propagator/DenseEnvironmentExtension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct DenseEnvironmentExtension {
// Check for valid particle properties
if (absQ == 0. || mass == 0. ||
stepper.absoluteMomentum(state.stepping) <
state.options.momentumCutOff) {
state.options.stepping.dense.momentumCutOff) {
return 0;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ struct DenseEnvironmentExtension {
} else {
// Update parameters and check for momentum condition
updateEnergyLoss(mass, h, state, stepper, i);
if (currentMomentum < state.options.momentumCutOff) {
if (currentMomentum < state.options.stepping.dense.momentumCutOff) {
return false;
}
// Evaluate k
Expand Down Expand Up @@ -183,7 +183,7 @@ struct DenseEnvironmentExtension {
(h / 6.) * (dPds[0] + 2. * (dPds[1] + dPds[2]) + dPds[3]);

// Break propagation if momentum becomes below cut-off
if (newMomentum < state.options.momentumCutOff) {
if (newMomentum < state.options.stepping.dense.momentumCutOff) {
return false;
}

Expand Down Expand Up @@ -395,7 +395,7 @@ struct DenseEnvironmentExtension {
// use unit length as thickness to compute the energy loss per unit length
Acts::MaterialSlab slab(material, 1);
// Use the same energy loss throughout the step.
if (state.options.meanEnergyLoss) {
if (state.options.stepping.dense.meanEnergyLoss) {
g = -computeEnergyLossMean(slab, absPdg, mass, static_cast<float>(qop[0]),
absQ);
} else {
Expand All @@ -410,8 +410,8 @@ struct DenseEnvironmentExtension {
if (state.stepping.covTransport) {
// Calculate the change of the energy loss per path length and
// inverse momentum
if (state.options.includeGradient) {
if (state.options.meanEnergyLoss) {
if (state.options.stepping.dense.includeGradient) {
if (state.options.stepping.dense.meanEnergyLoss) {
dgdqopValue = deriveEnergyLossMeanQOverP(
slab, absPdg, mass, static_cast<float>(qop[0]), absQ);
} else {
Expand Down Expand Up @@ -458,58 +458,4 @@ struct DenseEnvironmentExtension {
}
};

template <typename action_list_t = ActionList<>,
typename aborter_list_t = AbortList<>>
struct DenseStepperPropagatorOptions
: public PropagatorOptions<action_list_t, aborter_list_t> {
/// Copy Constructor
DenseStepperPropagatorOptions(
const DenseStepperPropagatorOptions<action_list_t, aborter_list_t>&
dspo) = default;

/// Constructor with GeometryContext
///
/// @param gctx The current geometry context object, e.g. alignment
/// @param mctx The current magnetic fielc context object
DenseStepperPropagatorOptions(const GeometryContext& gctx,
const MagneticFieldContext& mctx)
: PropagatorOptions<action_list_t, aborter_list_t>(gctx, mctx) {}

/// Toggle between mean and mode evaluation of energy loss
bool meanEnergyLoss = true;

/// Boolean flag for inclusion of d(dEds)d(q/p) into energy loss
bool includeGradient = true;

/// Cut-off value for the momentum in SI units
double momentumCutOff = 0.;

/// @brief Expand the Options with extended aborters
///
/// @tparam extended_aborter_list_t Type of the new aborter list
///
/// @param aborters The new aborter list to be used (internally)
template <typename extended_aborter_list_t>
DenseStepperPropagatorOptions<action_list_t, extended_aborter_list_t> extend(
extended_aborter_list_t aborters) const {
DenseStepperPropagatorOptions<action_list_t, extended_aborter_list_t>
eoptions(this->geoContext, this->magFieldContext);

// Copy the options over
eoptions.setPlainOptions(*this);

// Action / abort list
eoptions.actionList = std::move(this->actionList);
eoptions.abortList = std::move(aborters);

// Copy dense environment specific parameters
eoptions.meanEnergyLoss = meanEnergyLoss;
eoptions.includeGradient = includeGradient;
eoptions.momentumCutOff = momentumCutOff;

// And return the options
return eoptions;
}
};

} // namespace Acts
15 changes: 12 additions & 3 deletions Core/include/Acts/Propagator/DirectNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Acts/Geometry/Layer.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Intersection.hpp"
Expand All @@ -35,9 +36,7 @@ class DirectNavigator {
using SurfaceSequence = std::vector<const Surface*>;
using SurfaceIter = std::vector<const Surface*>::iterator;

DirectNavigator(std::unique_ptr<const Logger> _logger =
getDefaultLogger("DirectNavigator", Logging::INFO))
: m_logger{std::move(_logger)} {}
struct Config {};

/// @brief Nested Actor struct, called Initializer
///
Expand Down Expand Up @@ -127,6 +126,16 @@ class DirectNavigator {
bool navigationBreak = false;
};

struct Options : public NavigatorPlainOptions {
void setPlainOptions(const NavigatorPlainOptions& options) {
static_cast<NavigatorPlainOptions&>(*this) = options;
}
};

DirectNavigator(std::unique_ptr<const Logger> _logger =
getDefaultLogger("DirectNavigator", Logging::INFO))
: m_logger{std::move(_logger)} {}

State makeState(const Surface* startSurface,
const Surface* targetSurface) const {
State result;
Expand Down
16 changes: 16 additions & 0 deletions Core/include/Acts/Propagator/EigenStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Acts/Propagator/EigenStepperError.hpp"
#include "Acts/Propagator/PropagatorTraits.hpp"
#include "Acts/Propagator/StepperExtensionList.hpp"
#include "Acts/Propagator/StepperOptions.hpp"
#include "Acts/Propagator/detail/Auctioneer.hpp"
#include "Acts/Propagator/detail/SteppingHelper.hpp"
#include "Acts/Utilities/Intersection.hpp"
Expand Down Expand Up @@ -57,6 +58,16 @@ class EigenStepper {
using CurvilinearState =
std::tuple<CurvilinearTrackParameters, Jacobian, double>;

struct Config {
std::shared_ptr<const MagneticFieldProvider> bField;
};

struct Options : public StepperPlainOptions {
void setPlainOptions(const StepperPlainOptions& options) {
static_cast<StepperPlainOptions&>(*this) = options;
}
};

/// @brief State for track parameter propagation
///
/// It contains the stepping information and is provided thread local
Expand Down Expand Up @@ -165,6 +176,11 @@ class EigenStepper {
/// @param bField The magnetic field provider
explicit EigenStepper(std::shared_ptr<const MagneticFieldProvider> bField);

/// @brief Constructor with configuration
///
/// @param [in] config The configuration of the stepper
explicit EigenStepper(const Config& config) : m_bField(config.bField) {}
andiwand marked this conversation as resolved.
Show resolved Hide resolved

State makeState(std::reference_wrapper<const GeometryContext> gctx,
std::reference_wrapper<const MagneticFieldContext> mctx,
const BoundTrackParameters& par,
Expand Down
9 changes: 5 additions & 4 deletions Core/include/Acts/Propagator/EigenStepper.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Acts::Result<double> Acts::EigenStepper<E, A>::step(
// Whether to use fast power function if available
constexpr bool tryUseFastPow{false};

double x = state.options.stepTolerance / errorEstimate_;
double x = state.options.stepping.stepTolerance / errorEstimate_;

if constexpr (exponent == 0.25 && !tryUseFastPow) {
// This is 3x faster than std::pow
Expand All @@ -206,7 +206,8 @@ Acts::Result<double> Acts::EigenStepper<E, A>::step(
// For details about these values see ATL-SOFT-PUB-2009-001
constexpr double marginFactor = 4.0;

return errorEstimate_ <= marginFactor * state.options.stepTolerance;
return errorEstimate_ <=
marginFactor * state.options.stepping.stepTolerance;
};

// The following functor starts to perform a Runge-Kutta step of a certain
Expand Down Expand Up @@ -284,14 +285,14 @@ Acts::Result<double> Acts::EigenStepper<E, A>::step(

// If step size becomes too small the particle remains at the initial
// place
if (std::abs(h) < std::abs(state.options.stepSizeCutOff)) {
if (std::abs(h) < std::abs(state.options.stepping.stepSizeCutOff)) {
// Not moving due to too low momentum needs an aborter
return EigenStepperError::StepSizeStalled;
}

// If the parameter is off track too much or given stepSize is not
// appropriate
if (nStepTrials > state.options.maxRungeKuttaStepTrials) {
if (nStepTrials > state.options.stepping.maxRungeKuttaStepTrials) {
// Too many trials, have to abort
return EigenStepperError::StepSizeAdjustmentFailed;
}
Expand Down
30 changes: 24 additions & 6 deletions Core/include/Acts/Propagator/MultiEigenStepperLoop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Acts/Propagator/EigenStepper.hpp"
#include "Acts/Propagator/EigenStepperError.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Propagator/StepperOptions.hpp"
#include "Acts/Propagator/detail/LoopStepperUtils.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Intersection.hpp"
Expand Down Expand Up @@ -256,12 +257,15 @@ class MultiEigenStepperLoop
/// @brief How many components can this stepper manage?
static constexpr int maxComponents = std::numeric_limits<int>::max();

/// Constructor from a magnetic field and a optionally provided Logger
MultiEigenStepperLoop(std::shared_ptr<const MagneticFieldProvider> bField,
std::unique_ptr<const Logger> logger =
getDefaultLogger("GSF", Logging::INFO))
: EigenStepper<extensionlist_t, auctioneer_t>(std::move(bField)),
m_logger(std::move(logger)) {}
struct Config {
std::shared_ptr<const MagneticFieldProvider> bField;
};

struct Options : public StepperPlainOptions {
void setPlainOptions(const StepperPlainOptions& options) {
static_cast<StepperPlainOptions&>(*this) = options;
}
};

struct State {
/// The struct that stores the individual components
Expand Down Expand Up @@ -332,6 +336,20 @@ class MultiEigenStepperLoop
}
};

/// Constructor from a magnetic field and a optionally provided Logger
MultiEigenStepperLoop(std::shared_ptr<const MagneticFieldProvider> bField,
std::unique_ptr<const Logger> logger =
getDefaultLogger("GSF", Logging::INFO))
: EigenStepper<extensionlist_t, auctioneer_t>(std::move(bField)),
m_logger(std::move(logger)) {}

/// Constructor from a configuration and optionally provided Logger
MultiEigenStepperLoop(const Config& config,
std::unique_ptr<const Logger> logger =
getDefaultLogger("GSF", Logging::INFO))
: EigenStepper<extensionlist_t, auctioneer_t>(config),
m_logger(std::move(logger)) {}

/// Construct and initialize a state
State makeState(std::reference_wrapper<const GeometryContext> gctx,
std::reference_wrapper<const MagneticFieldContext> mctx,
Expand Down
9 changes: 8 additions & 1 deletion Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2016-2020 CERN for the benefit of the Acts project
// Copyright (C) 2016-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -14,6 +14,7 @@
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/StringHelpers.hpp"
Expand Down Expand Up @@ -111,6 +112,12 @@ class Navigator {
bool resolvePassive = false;
};

struct Options : public NavigatorPlainOptions {
void setPlainOptions(const NavigatorPlainOptions& options) {
static_cast<NavigatorPlainOptions&>(*this) = options;
}
};

/// @brief Nested State struct
///
/// It acts as an internal state which is created for every propagation and
Expand Down
15 changes: 15 additions & 0 deletions Core/include/Acts/Propagator/NavigatorOptions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file is part of the Acts project.
//
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

namespace Acts {

struct NavigatorPlainOptions {};

} // namespace Acts
Loading
Loading