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

feat: Add statistics to propagation #3450

Merged
merged 8 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Core/include/Acts/Navigation/DetectorNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Acts/Geometry/Layer.hpp"
#include "Acts/Navigation/NavigationState.hpp"
#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Propagator/NavigatorStatistics.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/Surface.hpp"
Expand Down Expand Up @@ -68,6 +69,9 @@ class DetectorNavigator {
bool targetReached = false;
/// Navigation state : a break has been detected
bool navigationBreak = false;

/// Navigation statistics
NavigatorStatistics statistics;
};

/// Constructor with configuration object
Expand Down
4 changes: 4 additions & 0 deletions Core/include/Acts/Propagator/AtlasStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Acts/MagneticField/MagneticFieldProvider.hpp"
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/StepperOptions.hpp"
#include "Acts/Propagator/StepperStatistics.hpp"
#include "Acts/Propagator/detail/SteppingHelper.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Intersection.hpp"
Expand Down Expand Up @@ -305,6 +306,9 @@ class AtlasStepper {
/// buffer & formatting for consistent output
std::size_t debugPfxWidth = 30;
std::size_t debugMsgWidth = 50;

/// The statistics of the stepper
StepperStatistics statistics;
};

explicit AtlasStepper(std::shared_ptr<const MagneticFieldProvider> bField)
Expand Down
4 changes: 4 additions & 0 deletions Core/include/Acts/Propagator/DirectNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Propagator/NavigatorStatistics.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/Surface.hpp"
Expand Down Expand Up @@ -75,6 +76,9 @@ class DirectNavigator {
/// Navigation state - external interface: a break has been detected
bool navigationBreak = false;

/// Navigation statistics
NavigatorStatistics statistics;

const Surface* navSurface() const {
return options.surfaces.at(surfaceIndex);
}
Expand Down
5 changes: 4 additions & 1 deletion Core/include/Acts/Propagator/EigenStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/Tolerance.hpp"
#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/detail/CorrectedTransformationFreeToBound.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
Expand All @@ -23,6 +22,7 @@
#include "Acts/Propagator/EigenStepperDefaultExtension.hpp"
#include "Acts/Propagator/PropagatorTraits.hpp"
#include "Acts/Propagator/StepperOptions.hpp"
#include "Acts/Propagator/StepperStatistics.hpp"
#include "Acts/Propagator/detail/SteppingHelper.hpp"
#include "Acts/Utilities/Intersection.hpp"
#include "Acts/Utilities/Result.hpp"
Expand Down Expand Up @@ -164,6 +164,9 @@ class EigenStepper {
/// k_i elements of the momenta
std::array<double, 4> kQoP{};
} stepData;

/// Statistics of the stepper
StepperStatistics statistics;
};

/// Constructor requires knowledge of the detector's magnetic field
Expand Down
15 changes: 14 additions & 1 deletion Core/include/Acts/Propagator/EigenStepper.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "Acts/Definitions/Direction.hpp"
#include "Acts/EventData/TransformationHelpers.hpp"
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/EigenStepperError.hpp"
Expand Down Expand Up @@ -259,7 +260,9 @@ Acts::Result<double> Acts::EigenStepper<E>::step(
// Select and adjust the appropriate Runge-Kutta step size as given
// ATL-SOFT-PUB-2009-001
while (true) {
nStepTrials++;
++nStepTrials;
++state.stepping.statistics.nAttemptedSteps;

auto res = tryRungeKuttaStep(h);
if (!res.ok()) {
return res.error();
Expand All @@ -268,6 +271,8 @@ Acts::Result<double> Acts::EigenStepper<E>::step(
break;
}

++state.stepping.statistics.nRejectedSteps;

const double stepSizeScaling = calcStepSizeScaling(errorEstimate);
h *= stepSizeScaling;

Expand Down Expand Up @@ -351,6 +356,14 @@ Acts::Result<double> Acts::EigenStepper<E>::step(
++state.stepping.nSteps;
state.stepping.nStepTrials += nStepTrials;

++state.stepping.statistics.nSuccessfulSteps;
if (state.options.direction !=
Direction::fromScalarZeroAsPositive(initialH)) {
++state.stepping.statistics.nReverseSteps;
}
state.stepping.statistics.pathLength += h;
state.stepping.statistics.absolutePathLength += std::abs(h);

const double stepSizeScaling = calcStepSizeScaling(errorEstimate);
const double nextAccuracy = std::abs(h * stepSizeScaling);
const double previousAccuracy = std::abs(state.stepping.stepSize.accuracy());
Expand Down
4 changes: 4 additions & 0 deletions Core/include/Acts/Propagator/MultiEigenStepperLoop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Acts/Propagator/MultiStepperError.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Propagator/StepperOptions.hpp"
#include "Acts/Propagator/StepperStatistics.hpp"
#include "Acts/Propagator/detail/LoopStepperUtils.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Intersection.hpp"
Expand Down Expand Up @@ -219,6 +220,9 @@ class MultiEigenStepperLoop : public EigenStepper<extension_t> {
/// reached a surface
std::optional<std::size_t> stepCounterAfterFirstComponentOnSurface;

/// The stepper statistics
StepperStatistics statistics;

/// No default constructor is provided
State() = delete;

Expand Down
11 changes: 7 additions & 4 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

#pragma once

#include "Acts/Definitions/Units.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/Layer.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Propagator/NavigatorStatistics.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Logger.hpp"
Expand Down Expand Up @@ -176,9 +176,12 @@ class Navigator {
bool targetReached = false;
/// Navigation state : a break has been detected
bool navigationBreak = false;
// The navigation stage (@todo: integrate break, target)
/// The navigation stage (@todo: integrate break, target)
Stage navigationStage = Stage::undefined;

/// Navigation statistics
NavigatorStatistics statistics;

void reset() {
navSurfaces.clear();
navSurfaceIndex = navSurfaces.size();
Expand Down Expand Up @@ -427,6 +430,7 @@ class Navigator {
<< "No targets found, we got lost! Attempt renavigation.");

state.navigation.reset();
++state.navigation.statistics.nRenavigations;

// We might have punched through a boundary and entered another volume
// so we have to reinitialize
Expand Down Expand Up @@ -576,6 +580,7 @@ class Navigator {
state.navigation.navBoundaries.clear();
state.navigation.navBoundaryIndex =
state.navigation.navBoundaries.size();
++state.navigation.statistics.nVolumeSwitches;
}
} else {
// Set the navigation stage back to boundary target
Expand Down Expand Up @@ -772,8 +777,6 @@ class Navigator {
/// @return boolean return triggers exit to stepper
template <typename propagator_state_t, typename stepper_t>
bool targetLayers(propagator_state_t& state, const stepper_t& stepper) const {
using namespace UnitLiterals;

if (state.navigation.navigationBreak) {
return false;
}
Expand Down
26 changes: 26 additions & 0 deletions Core/include/Acts/Propagator/NavigatorStatistics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#pragma once

#include <cstddef>

namespace Acts {

/// @struct NavigatorStatistics
///
/// @brief A struct to hold statistics of the navigator
struct NavigatorStatistics {
/// Number of renavigation attempts
std::size_t nRenavigations = 0;
andiwand marked this conversation as resolved.
Show resolved Hide resolved

/// Number of volume switches
std::size_t nVolumeSwitches = 0;
};

} // namespace Acts
3 changes: 3 additions & 0 deletions Core/include/Acts/Propagator/Propagator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ void Acts::Propagator<S, N>::moveStateToResult(propagator_state_t& state,

result.steps = state.steps;
result.pathLength = state.pathLength;

result.statistics.stepping = state.stepping.statistics;
result.statistics.navigation = state.navigation.statistics;
}

template <typename derived_t>
Expand Down
4 changes: 4 additions & 0 deletions Core/include/Acts/Propagator/PropagatorResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Propagator/PropagatorStatistics.hpp"
#include "Acts/Utilities/detail/Extendable.hpp"

#include <optional>
Expand Down Expand Up @@ -36,6 +37,9 @@ struct PropagatorResult : private detail::Extendable<result_list...> {

/// Signed distance over which the parameters were propagated
double pathLength = 0.;

/// Propagator statistics
PropagatorStatistics statistics;
};

} // namespace Acts
4 changes: 4 additions & 0 deletions Core/include/Acts/Propagator/PropagatorState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Propagator/PropagatorStatistics.hpp"
#include "Acts/Utilities/detail/Extendable.hpp"

#include <functional>
Expand Down Expand Up @@ -72,6 +73,9 @@ struct PropagatorState : private detail::Extendable<extension_state_t...> {

/// Signed distance over which the parameters were propagated
double pathLength = 0.;

/// Statistics of the propagation
PropagatorStatistics statistics;
};

} // namespace Acts
26 changes: 26 additions & 0 deletions Core/include/Acts/Propagator/PropagatorStatistics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#pragma once

#include <Acts/Propagator/NavigatorStatistics.hpp>
#include <Acts/Propagator/StepperStatistics.hpp>

namespace Acts {

/// @struct PropagatorStatistics
///
/// @brief A struct to hold statistics of the propagator
struct PropagatorStatistics {
/// Statistics of the stepper
StepperStatistics stepping;
/// Statistics of the navigator
NavigatorStatistics navigation;
};

} // namespace Acts
34 changes: 34 additions & 0 deletions Core/include/Acts/Propagator/StepperStatistics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#pragma once

#include <cstddef>

namespace Acts {

/// @struct StepperStatistics
///
/// @brief A struct to hold statistics of the stepper
struct StepperStatistics {
/// Number of attempted steps
std::size_t nAttemptedSteps = 0;
/// Number of rejected steps
std::size_t nRejectedSteps = 0;
/// Number of successful steps
std::size_t nSuccessfulSteps = 0;
/// Number of steps that were reversed
std::size_t nReverseSteps = 0;

/// Signed sum of the step lengths
double pathLength = 0;
/// Unsigned sum of the step lengths
double absolutePathLength = 0;
};

} // namespace Acts
14 changes: 13 additions & 1 deletion Core/include/Acts/Propagator/StraightLineStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/PropagatorTraits.hpp"
#include "Acts/Propagator/StepperOptions.hpp"
#include "Acts/Propagator/StepperStatistics.hpp"
#include "Acts/Propagator/detail/SteppingHelper.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/Surface.hpp"
Expand Down Expand Up @@ -142,6 +143,9 @@ class StraightLineStepper {

// Cache the geometry context of this propagation
std::reference_wrapper<const GeometryContext> geoContext;

/// Statistics of the stepper
StepperStatistics statistics;
};

StraightLineStepper() = default;
Expand Down Expand Up @@ -430,6 +434,7 @@ class StraightLineStepper {
Vector3 dir = direction(state.stepping);
state.stepping.pars.template segment<3>(eFreePos0) += h * dir;
state.stepping.pars[eFreeTime] += h * dtds;

// Propagate the jacobian
if (state.stepping.covTransport) {
// The step transport matrix in global coordinates
Expand All @@ -450,7 +455,14 @@ class StraightLineStepper {
++state.stepping.nSteps;
++state.stepping.nStepTrials;

// return h
++state.stepping.statistics.nAttemptedSteps;
++state.stepping.statistics.nSuccessfulSteps;
if (state.options.direction != Direction::fromScalarZeroAsPositive(h)) {
++state.stepping.statistics.nReverseSteps;
}
state.stepping.statistics.pathLength += h;
state.stepping.statistics.absolutePathLength += std::abs(h);

return h;
}
};
Expand Down
12 changes: 3 additions & 9 deletions Core/include/Acts/Propagator/SympyStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/PropagatorTraits.hpp"
#include "Acts/Propagator/StepperOptions.hpp"
#include "Acts/Propagator/StepperStatistics.hpp"
#include "Acts/Propagator/detail/SteppingHelper.hpp"

namespace Acts {
Expand Down Expand Up @@ -132,15 +133,8 @@ class SympyStepper {
/// The geometry context
std::reference_wrapper<const GeometryContext> geoContext;

/// @brief Storage of magnetic field and the sub steps during a RKN4 step
struct {
/// Magnetic field evaulations
Vector3 B_first, B_middle, B_last;
/// k_i of the RKN4 algorithm
Vector3 k1, k2, k3, k4;
/// k_i elements of the momenta
std::array<double, 4> kQoP{};
} stepData;
andiwand marked this conversation as resolved.
Show resolved Hide resolved
/// Statistics of the stepper
StepperStatistics statistics;
};

/// Constructor requires knowledge of the detector's magnetic field
Expand Down
Loading
Loading