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!: Strongly typed enum for ConstrainedStep::Type and capital initial letter #4013

Merged
56 changes: 32 additions & 24 deletions Core/include/Acts/Propagator/ConstrainedStep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#pragma once

#include "Acts/Utilities/Helpers.hpp"

#include <algorithm>
#include <array>
#include <cassert>
Expand Down Expand Up @@ -45,34 +47,34 @@ class ConstrainedStep {
/// from navigator - this would be a navigation step
/// from actor - this would be an actor condition
/// from user - this is user given for what reason ever
enum Type : int { navigator = 0, actor = 1, user = 2 };
enum class Type : int { Navigator = 0, Actor = 1, User = 2 };
andiwand marked this conversation as resolved.
Show resolved Hide resolved

constexpr ConstrainedStep() = default;

/// constructor
/// @param value is the user given initial value
constexpr explicit ConstrainedStep(double value) { setUser(value); }
/// @param v is the user given initial value
constexpr explicit ConstrainedStep(double v) { setUser(v); }

/// set accuracy
///
/// this will set only the accuracy, as this is the most
/// exposed to the Propagator
///
/// @param value is the new accuracy value
constexpr void setAccuracy(double value) {
assert(value > 0 && "ConstrainedStep accuracy must be > 0.");
/// @param v is the new accuracy value
constexpr void setAccuracy(double v) {
assert(v > 0 && "ConstrainedStep accuracy must be > 0.");
// set the accuracy value
m_accuracy = value;
m_accuracy = v;
}

/// set user
///
/// @param value is the new user value
constexpr void setUser(double value) {
/// @param v is the new user value
constexpr void setUser(double v) {
// TODO enable assert; see https://github.com/acts-project/acts/issues/2543
// assert(value != 0 && "ConstrainedStep user must be != 0.");
// assert(v != 0 && "ConstrainedStep user must be != 0.");
// set the user value
m_values[user] = value;
setValue(Type::User, v);
}

/// returns the min step size
Expand All @@ -86,15 +88,17 @@ class ConstrainedStep {
/// Access a specific value
///
/// @param type is the requested parameter type
constexpr double value(Type type) const { return m_values[type]; }
constexpr double value(Type type) const {
return m_values[toUnderlying(type)];
}

/// Access the accuracy value
constexpr double accuracy() const { return m_accuracy; }

/// release a certain constraint value
///
/// @param type is the constraint type to be released
constexpr void release(Type type) { m_values[type] = kNotSet; }
constexpr void release(Type type) { setValue(type, kNotSet); }

/// release accuracy
constexpr void releaseAccuracy() { m_accuracy = kNotSet; }
Expand All @@ -104,38 +108,38 @@ class ConstrainedStep {
/// Only navigation and target abortion step size
/// updates may change the sign due to overstepping
///
/// @param value is the new value to be updated
/// @param v is the new value to be updated
/// @param type is the constraint type
constexpr void update(double value, Type type) {
constexpr void update(double v, Type type) {
// check the current value and set it if appropriate
// this will also allow signed values due to overstepping
if (std::abs(value) < std::abs(m_values[type])) {
if (std::abs(v) < std::abs(value(type))) {
// TODO enable assert; see
// https://github.com/acts-project/acts/issues/2543
// assert(value != 0 && "ConstrainedStep user must be != 0.");
m_values[type] = value;
setValue(type, v);
}
}

std::ostream& toStream(std::ostream& os) const {
// Helper method to avoid unreadable screen output
auto streamValue = [&](double val) {
auto streamValue = [&](double v) {
os << std::setw(5);
if (std::abs(val) == kNotSet) {
os << (val > 0 ? "+∞" : "-∞");
if (std::abs(v) == kNotSet) {
os << (v > 0 ? "+∞" : "-∞");
} else {
os << val;
os << v;
}
};

os << "(";
streamValue(m_accuracy);
os << ", ";
streamValue(value(navigator));
streamValue(value(Type::Navigator));
os << ", ";
streamValue(value(actor));
streamValue(value(Type::Actor));
os << ", ";
streamValue(value(user));
streamValue(value(Type::User));
os << ")";

return os;
Expand All @@ -154,6 +158,10 @@ class ConstrainedStep {
std::array<double, 3> m_values = {kNotSet, kNotSet, kNotSet};
/// the accuracy value - this can vary up and down given a good step estimator
double m_accuracy = kNotSet;

constexpr void setValue(Type type, double v) {
m_values[toUnderlying(type)] = v;
}
};

inline std::ostream& operator<<(std::ostream& os, const ConstrainedStep& step) {
Expand Down
11 changes: 6 additions & 5 deletions Core/include/Acts/Propagator/Propagator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ auto Acts::Propagator<S, N>::propagate(propagator_state_t& state) const
state.stepping, *nextTarget.surface,
nextTarget.surfaceIntersectionIndex, state.options.direction,
nextTarget.boundaryTolerance, state.options.surfaceTolerance,
ConstrainedStep::navigator, logger());
ConstrainedStep::Type::Navigator, logger());
if (preStepSurfaceStatus == IntersectionStatus::reachable ||
preStepSurfaceStatus == IntersectionStatus::onSurface) {
return nextTarget;
Expand Down Expand Up @@ -109,8 +109,8 @@ auto Acts::Propagator<S, N>::propagate(propagator_state_t& state) const
<< state.direction.transpose());

// release actor and aborter constrains after step was performed
m_stepper.releaseStepSize(state.stepping, ConstrainedStep::navigator);
m_stepper.releaseStepSize(state.stepping, ConstrainedStep::actor);
m_stepper.releaseStepSize(state.stepping, ConstrainedStep::Type::Navigator);
m_stepper.releaseStepSize(state.stepping, ConstrainedStep::Type::Actor);

// Post-stepping: check target status, call actors, check abort conditions
state.stage = PropagatorStage::postStep;
Expand All @@ -120,7 +120,7 @@ auto Acts::Propagator<S, N>::propagate(propagator_state_t& state) const
state.stepping, *nextTarget.surface,
nextTarget.surfaceIntersectionIndex, state.options.direction,
nextTarget.boundaryTolerance, state.options.surfaceTolerance,
ConstrainedStep::navigator, logger());
ConstrainedStep::Type::Navigator, logger());
if (postStepSurfaceStatus == IntersectionStatus::onSurface) {
m_navigator.handleSurfaceReached(state.navigation, state.position,
state.direction, *nextTarget.surface);
Expand Down Expand Up @@ -155,7 +155,8 @@ auto Acts::Propagator<S, N>::propagate(propagator_state_t& state) const

if (nextTarget.isNone()) {
// navigator step constraint is not valid anymore
m_stepper.releaseStepSize(state.stepping, ConstrainedStep::navigator);
m_stepper.releaseStepSize(state.stepping,
ConstrainedStep::Type::Navigator);

nextTargetResult = getNextTarget();
if (!nextTargetResult.ok()) {
Expand Down
5 changes: 3 additions & 2 deletions Core/include/Acts/Propagator/StandardAborters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ struct PathLimitReached {
<< distance);
return true;
}
stepper.updateStepSize(state.stepping, distance, ConstrainedStep::actor);
stepper.updateStepSize(state.stepping, distance,
ConstrainedStep::Type::Actor);
ACTS_VERBOSE("PathLimit aborter | "
<< "Target stepSize (path limit) updated to "
<< stepper.outputStepSize(state.stepping));
Expand Down Expand Up @@ -128,7 +129,7 @@ struct SurfaceReached {
detail::checkPathLength(intersection.pathLength(), nearLimit,
farLimit, logger)) {
stepper.updateStepSize(state.stepping, intersection.pathLength(),
ConstrainedStep::actor);
ConstrainedStep::Type::Actor);
ACTS_VERBOSE(
"SurfaceReached aborter | "
"Target stepSize (surface) updated to "
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Propagator/detail/SteppingHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Acts::detail {
/// @param stype [in] The step size type to be set
/// @param logger [in] A @c Logger instance
template <typename stepper_t>
Acts::IntersectionStatus updateSingleSurfaceStatus(
IntersectionStatus updateSingleSurfaceStatus(
const stepper_t& stepper, typename stepper_t::State& state,
const Surface& surface, std::uint8_t index, Direction direction,
const BoundaryTolerance& boundaryTolerance, double surfaceTolerance,
Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ class CombinatorialKalmanFilter {
boundParams.referenceSurface().getSharedPtr());
}

stepper.releaseStepSize(state.stepping, ConstrainedStep::navigator);
stepper.releaseStepSize(state.stepping,
ConstrainedStep::Type::Navigator);
}

// Record the active branch and remove it from the list
Expand Down
7 changes: 4 additions & 3 deletions Examples/Io/Root/src/RootPropagationStepsWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ ActsExamples::ProcessCode ActsExamples::RootPropagationStepsWriter::writeT(
m_dz.push_back(direction.z());

double accuracy = step.stepSize.accuracy();
double actor = step.stepSize.value(Acts::ConstrainedStep::navigator);
double aborter = step.stepSize.value(Acts::ConstrainedStep::actor);
double user = step.stepSize.value(Acts::ConstrainedStep::user);
double actor =
step.stepSize.value(Acts::ConstrainedStep::Type::Navigator);
double aborter = step.stepSize.value(Acts::ConstrainedStep::Type::Actor);
double user = step.stepSize.value(Acts::ConstrainedStep::Type::User);
double actAbs = std::abs(actor);
double accAbs = std::abs(accuracy);
double aboAbs = std::abs(aborter);
Expand Down
5 changes: 3 additions & 2 deletions Fatras/include/ActsFatras/Kernel/detail/SimulationActor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ struct SimulationActor {
const auto stepSize = properTimeDiff *
result.particle.absoluteMomentum() /
result.particle.mass();
stepper.releaseStepSize(state.stepping, Acts::ConstrainedStep::user);
stepper.releaseStepSize(state.stepping,
Acts::ConstrainedStep::Type::User);
stepper.updateStepSize(state.stepping, stepSize,
Acts::ConstrainedStep::user);
Acts::ConstrainedStep::Type::User);
}

// arm the point-like interaction limits in the first step
Expand Down
19 changes: 10 additions & 9 deletions Tests/UnitTests/Core/Propagator/AtlasStepperTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,11 @@ BOOST_AUTO_TEST_CASE(StepSize) {

Stepper::State state = stepper.makeState(options, cp);

stepper.updateStepSize(state, -5_cm, ConstrainedStep::navigator);
stepper.updateStepSize(state, -5_cm, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(state.previousStepSize, stepSize);
BOOST_CHECK_EQUAL(state.stepSize.value(), -5_cm);

stepper.releaseStepSize(state, ConstrainedStep::navigator);
stepper.releaseStepSize(state, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(state.stepSize.value(), stepSize);
}

Expand All @@ -609,10 +609,11 @@ BOOST_AUTO_TEST_CASE(StepSizeSurface) {
auto target = CurvilinearSurface(pos + navDir * distance * unitDir, unitDir)
.planeSurface();

stepper.updateSurfaceStatus(state, *target, 0, navDir,
BoundaryTolerance::Infinite(),
s_onSurfaceTolerance, ConstrainedStep::navigator);
BOOST_CHECK_EQUAL(state.stepSize.value(ConstrainedStep::navigator), distance);
stepper.updateSurfaceStatus(
state, *target, 0, navDir, BoundaryTolerance::Infinite(),
s_onSurfaceTolerance, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(state.stepSize.value(ConstrainedStep::Type::Navigator),
distance);

// test the step size modification in the context of a surface
stepper.updateStepSize(state,
Expand All @@ -621,19 +622,19 @@ BOOST_AUTO_TEST_CASE(StepSizeSurface) {
navDir * stepper.direction(state),
BoundaryTolerance::Infinite())
.closest(),
navDir, ConstrainedStep::navigator);
navDir, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(state.stepSize.value(), distance);

// start with a different step size
state.stepSize.setUser(navDir * stepSize);
stepper.releaseStepSize(state, ConstrainedStep::navigator);
stepper.releaseStepSize(state, ConstrainedStep::Type::Navigator);
stepper.updateStepSize(state,
target
->intersect(geoCtx, stepper.position(state),
navDir * stepper.direction(state),
BoundaryTolerance::Infinite())
.closest(),
navDir, ConstrainedStep::navigator);
navDir, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(state.stepSize.value(), navDir * stepSize);
}

Expand Down
16 changes: 8 additions & 8 deletions Tests/UnitTests/Core/Propagator/ConstrainedStepTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ BOOST_AUTO_TEST_CASE(ConstrainedStepTest) {

// All of the types should be 0.25 now
BOOST_CHECK_EQUAL(stepSize_p.accuracy(), std::numeric_limits<double>::max());
BOOST_CHECK_EQUAL(stepSize_p.value(ConstrainedStep::navigator),
BOOST_CHECK_EQUAL(stepSize_p.value(ConstrainedStep::Type::Navigator),
std::numeric_limits<double>::max());
BOOST_CHECK_EQUAL(stepSize_p.value(ConstrainedStep::actor),
BOOST_CHECK_EQUAL(stepSize_p.value(ConstrainedStep::Type::Actor),
std::numeric_limits<double>::max());
BOOST_CHECK_EQUAL(stepSize_p.value(ConstrainedStep::user), 0.25);
BOOST_CHECK_EQUAL(stepSize_p.value(ConstrainedStep::Type::User), 0.25);

// Check the cast operation to double
BOOST_CHECK_EQUAL(stepSize_p.value(), 0.25);
Expand All @@ -36,19 +36,19 @@ BOOST_AUTO_TEST_CASE(ConstrainedStepTest) {
BOOST_CHECK_EQUAL(stepSize_p.value(), 0.1);

// now we update the actor to smaller
stepSize_p.update(0.05, ConstrainedStep::navigator);
stepSize_p.update(0.05, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(stepSize_p.value(), 0.05);
// we increase the actor, but do not release the step size
stepSize_p.update(0.15, ConstrainedStep::navigator);
stepSize_p.update(0.15, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(stepSize_p.value(), 0.05);
// we increase the actor, but now DO release the step size
// it falls back to the accuracy
stepSize_p.release(ConstrainedStep::navigator);
stepSize_p.update(0.15, ConstrainedStep::navigator);
stepSize_p.release(ConstrainedStep::Type::Navigator);
stepSize_p.update(0.15, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(stepSize_p.value(), 0.1);

// now set two and update them
stepSize_p.update(0.05, ConstrainedStep::user);
stepSize_p.update(0.05, ConstrainedStep::Type::User);
stepSize_p.setAccuracy(0.03);
BOOST_CHECK_EQUAL(stepSize_p.value(), 0.03);

Expand Down
14 changes: 7 additions & 7 deletions Tests/UnitTests/Core/Propagator/EigenStepperTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ BOOST_AUTO_TEST_CASE(eigen_stepper_test) {
// Step size modifies
const std::string originalStepSize = esState.stepSize.toString();

es.updateStepSize(esState, -1337., ConstrainedStep::navigator);
es.updateStepSize(esState, -1337., ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(esState.previousStepSize, stepSize);
BOOST_CHECK_EQUAL(esState.stepSize.value(), -1337.);

es.releaseStepSize(esState, ConstrainedStep::navigator);
es.releaseStepSize(esState, ConstrainedStep::Type::Navigator);
BOOST_CHECK_EQUAL(esState.stepSize.value(), stepSize);
BOOST_CHECK_EQUAL(es.outputStepSize(esState), originalStepSize);

Expand Down Expand Up @@ -450,8 +450,8 @@ BOOST_AUTO_TEST_CASE(eigen_stepper_test) {
CurvilinearSurface(pos + navDir * 2. * dir, dir).planeSurface();
es.updateSurfaceStatus(esState, *targetSurface, 0, navDir,
BoundaryTolerance::Infinite(), s_onSurfaceTolerance,
ConstrainedStep::navigator);
CHECK_CLOSE_ABS(esState.stepSize.value(ConstrainedStep::navigator),
ConstrainedStep::Type::Navigator);
CHECK_CLOSE_ABS(esState.stepSize.value(ConstrainedStep::Type::Navigator),
navDir * 2., eps);

// Test the step size modification in the context of a surface
Expand All @@ -461,17 +461,17 @@ BOOST_AUTO_TEST_CASE(eigen_stepper_test) {
navDir * es.direction(esState),
BoundaryTolerance::Infinite())
.closest(),
navDir, ConstrainedStep::navigator);
navDir, ConstrainedStep::Type::Navigator);
CHECK_CLOSE_ABS(esState.stepSize.value(), 2., eps);
esState.stepSize.setUser(navDir * stepSize);
es.releaseStepSize(esState, ConstrainedStep::navigator);
es.releaseStepSize(esState, ConstrainedStep::Type::Navigator);
es.updateStepSize(esState,
targetSurface
->intersect(tgContext, es.position(esState),
navDir * es.direction(esState),
BoundaryTolerance::Infinite())
.closest(),
navDir, ConstrainedStep::navigator);
navDir, ConstrainedStep::Type::Navigator);
CHECK_CLOSE_ABS(esState.stepSize.value(), 2., eps);

// Test the bound state construction
Expand Down
Loading
Loading