Skip to content

Commit

Permalink
implement
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Nov 16, 2024
1 parent 714320e commit 7d5b701
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 98 deletions.
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
23 changes: 18 additions & 5 deletions 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.nFailedSteps;

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

Expand All @@ -286,6 +291,18 @@ Acts::Result<double> Acts::EigenStepper<E>::step(
}
}

state.stepping.pathAccumulated += h;
++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);

// When doing error propagation, update the associated Jacobian matrix
if (state.stepping.covTransport) {
// using the direction before updated below
Expand Down Expand Up @@ -347,10 +364,6 @@ Acts::Result<double> Acts::EigenStepper<E>::step(
state.stepping.derivative.template segment<3>(4) = sd.k4;
}

state.stepping.pathAccumulated += h;
++state.stepping.nSteps;
state.stepping.nStepTrials += nStepTrials;

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
22 changes: 3 additions & 19 deletions Core/include/Acts/Propagator/NavigatorStatistics.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// This file is part of the Acts project.
// This file is part of the ACTS project.
//
// Copyright (C) 2024 CERN for the benefit 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 http://mozilla.org/MPL/2.0/.
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

Expand All @@ -16,22 +16,6 @@ struct NavigatorStatistics {
std::size_t nRenavigations = 0;

std::size_t nVolumeSwitches = 0;

std::size_t nBoundaryCandidates = 0;
std::size_t nBoundaryHits = 0;
std::size_t nBoundaryDiscards = 0;

std::size_t nLayerCandidates = 0;
std::size_t nLayerHits = 0;
std::size_t nLayerDiscards = 0;

std::size_t nSurfaceCandidates = 0;
std::size_t nSurfaceHits = 0;
std::size_t nSurfaceDiscards = 0;

std::size_t nTotalCandidates = 0;
std::size_t nTotalHits = 0;
std::size_t nTotalDiscards = 0;
};

} // namespace Acts
6 changes: 2 additions & 4 deletions Core/include/Acts/Propagator/Propagator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,8 @@ void Acts::Propagator<S, N>::moveStateToResult(propagator_state_t& state,
result_t& result) const {
result.tuple() = std::move(state.tuple());

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

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

template <typename derived_t>
Expand Down
1 change: 1 addition & 0 deletions Core/include/Acts/Propagator/PropagatorResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct PropagatorResult : private detail::Extendable<result_list...> {
/// Signed distance over which the parameters were propagated
double pathLength = 0.;

/// Propagator statistics
PropagatorStatistics statistics;
};

Expand Down
7 changes: 4 additions & 3 deletions Core/include/Acts/Propagator/StepperStatistics.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// This file is part of the Acts project.
// This file is part of the ACTS project.
//
// Copyright (C) 2024 CERN for the benefit 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 http://mozilla.org/MPL/2.0/.
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

Expand All @@ -16,6 +16,7 @@ struct StepperStatistics {
std::size_t nAttemptedSteps = 0;
std::size_t nFailedSteps = 0;
std::size_t nSuccessfulSteps = 0;
std::size_t nReverseSteps = 0;

double pathLength = 0;
double absolutePathLength = 0;
Expand Down
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;
/// Statistics of the stepper
StepperStatistics statistics;
};

/// Constructor requires knowledge of the detector's magnetic field
Expand Down
4 changes: 4 additions & 0 deletions Core/include/Acts/Propagator/TryAllNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Propagator/NavigatorStatistics.hpp"
#include "Acts/Propagator/detail/NavigationHelpers.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/Surface.hpp"
Expand Down Expand Up @@ -86,6 +87,9 @@ class TryAllNavigatorBase {
bool targetReached = false;
/// If 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/VoidNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Propagator/NavigatorStatistics.hpp"
namespace Acts {

class Surface;
Expand All @@ -30,6 +31,9 @@ struct VoidNavigator {
/// @brief Nested State struct, minimal requirement
struct State {
Options options;

/// Navigation statistics
NavigatorStatistics statistics;
};

State makeState(const Options& options) const {
Expand Down
Loading

0 comments on commit 7d5b701

Please sign in to comment.