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: Allow propagator initialization to fail #4036

Merged
merged 19 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 17 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
8 changes: 5 additions & 3 deletions Core/include/Acts/Navigation/DetectorNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class DetectorNavigator {
return state.navigationBreak;
}

void initialize(State& state, const Vector3& position,
const Vector3& direction,
Direction propagationDirection) const {
[[nodiscard]] Result<void> initialize(State& state, const Vector3& position,
const Vector3& direction,
Direction propagationDirection) const {
(void)propagationDirection;

ACTS_VERBOSE(volInfo(state) << posInfo(state, position) << "initialize");
Expand All @@ -140,6 +140,8 @@ class DetectorNavigator {
throw std::invalid_argument("DetectorNavigator: no current volume found");
}
updateCandidateSurfaces(state, position);

return Result<void>::success();
}

NavigationTarget nextTarget(State& state, const Vector3& position,
Expand Down
9 changes: 6 additions & 3 deletions Core/include/Acts/Propagator/DirectNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Intersection.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/Result.hpp"

#include <limits>
#include <memory>
Expand Down Expand Up @@ -171,9 +172,9 @@ class DirectNavigator {
/// @param position The start position
/// @param direction The start direction
/// @param propagationDirection The propagation direction
void initialize(State& state, const Vector3& position,
const Vector3& direction,
Direction propagationDirection) const {
[[nodiscard]] Result<void> initialize(State& state, const Vector3& position,
const Vector3& direction,
Direction propagationDirection) const {
(void)position;
(void)direction;

Expand Down Expand Up @@ -214,6 +215,8 @@ class DirectNavigator {
}

state.navigationBreak = false;

return Result<void>::success();
}

/// @brief Get the next target surface
Expand Down
45 changes: 32 additions & 13 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Propagator/NavigationTarget.hpp"
#include "Acts/Propagator/NavigatorError.hpp"
#include "Acts/Propagator/NavigatorOptions.hpp"
#include "Acts/Propagator/NavigatorStatistics.hpp"
#include "Acts/Surfaces/BoundaryTolerance.hpp"
Expand Down Expand Up @@ -260,17 +261,19 @@ class Navigator {
return state.navigationBreak;
}

/// @brief Initialize the navigator
/// @brief Initialize the navigator state
///
/// This function initializes the navigator for a new propagation.
/// This function initializes the navigator state for a new propagation.
///
/// @param state The navigation state
/// @param position The start position
/// @param direction The start direction
/// @param propagationDirection The propagation direction
void initialize(State& state, const Vector3& position,
const Vector3& direction,
Direction propagationDirection) const {
///
/// @return Indication if the initialization was successful
[[nodiscard]] Result<void> initialize(State& state, const Vector3& position,
const Vector3& direction,
Direction propagationDirection) const {
(void)propagationDirection;

ACTS_VERBOSE(volInfo(state) << "Initialization.");
Expand Down Expand Up @@ -326,9 +329,16 @@ class Navigator {
if (state.currentVolume != nullptr) {
ACTS_VERBOSE(volInfo(state) << "Start volume resolved "
<< state.currentVolume->geometryId());
assert(state.currentVolume->inside(position,
state.options.surfaceTolerance) &&
"We did not end up inside the volume.");

if (!state.currentVolume->inside(position,
state.options.surfaceTolerance)) {
ACTS_DEBUG(
volInfo(state)
<< "We did not end up inside the expected volume. position = "
<< position.transpose());

return Result<void>::failure(NavigatorError::NotInsideExpectedVolume);
}
}
if (state.currentLayer != nullptr) {
ACTS_VERBOSE(volInfo(state) << "Start layer resolved "
Expand All @@ -337,12 +347,21 @@ class Navigator {
if (state.currentSurface != nullptr) {
ACTS_VERBOSE(volInfo(state) << "Start surface resolved "
<< state.currentSurface->geometryId());
assert(state.currentSurface->isOnSurface(
state.options.geoContext, position, direction,
BoundaryTolerance::Infinite(),
state.options.surfaceTolerance) &&
"Stepper not on surface");

if (!state.currentSurface->isOnSurface(
state.options.geoContext, position, direction,
BoundaryTolerance::Infinite(), state.options.surfaceTolerance)) {
ACTS_DEBUG(volInfo(state)
<< "We did not end up on the expected surface. surface = "
<< state.currentSurface->geometryId()
<< " position = " << position.transpose()
<< " direction = " << direction.transpose());

return Result<void>::failure(NavigatorError::NotOnExpectedSurface);
}
}

return Result<void>::success();
}

/// @brief Get the next target surface
Expand Down
30 changes: 30 additions & 0 deletions Core/include/Acts/Propagator/NavigatorError.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 <system_error>
#include <type_traits>

namespace Acts {

enum class NavigatorError {
// ensure all values are non-zero
NotInsideExpectedVolume = 1,
NotOnExpectedSurface = 2,
};

std::error_code make_error_code(Acts::NavigatorError e);

} // namespace Acts

// register with STL
namespace std {
template <>
struct is_error_code_enum<Acts::NavigatorError> : std::true_type {};
} // namespace std
37 changes: 20 additions & 17 deletions Core/include/Acts/Propagator/Propagator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,44 +279,51 @@ class Propagator final
/// This function creates the propagator state object from the initial track
/// parameters and the propagation options.
///
/// @note This will also initialize the state
///
/// @tparam parameters_t Type of initial track parameters to propagate
/// @tparam propagator_options_t Type of the propagator options
/// @tparam path_aborter_t The path aborter type to be added
///
/// @param [in] start Initial track parameters to propagate
/// @param [in] options Propagation options
///
/// @return Propagator state object
template <typename parameters_t, typename propagator_options_t,
template <typename propagator_options_t,
typename path_aborter_t = PathLimitReached>
auto makeState(const parameters_t& start,
const propagator_options_t& options) const;
auto makeState(const propagator_options_t& options) const;
andiwand marked this conversation as resolved.
Show resolved Hide resolved

/// @brief Builds the propagator state object
///
/// This function creates the propagator state object from the initial track
/// parameters, the target surface, and the propagation options.
///
/// @note This will also initialize the state
///
/// @tparam parameters_t Type of initial track parameters to propagate
/// @tparam propagator_options_t Type of the propagator options
/// @tparam target_aborter_t The target aborter type to be added
/// @tparam path_aborter_t The path aborter type to be added
///
/// @param [in] start Initial track parameters to propagate
/// @param [in] target Target surface of to propagate to
/// @param [in] options Propagation options
///
/// @return Propagator state object
template <typename parameters_t, typename propagator_options_t,
template <typename propagator_options_t,
typename target_aborter_t = SurfaceReached,
typename path_aborter_t = PathLimitReached>
auto makeState(const parameters_t& start, const Surface& target,
auto makeState(const Surface& target,
const propagator_options_t& options) const;

/// @brief Initialize the propagator state
///
/// This function initializes the propagator state for a new propagation.
///
/// @tparam propagator_state_t Type of the propagator state object
/// @tparam path_aborter_t The path aborter type to be added
///
/// @param [in,out] state The propagator state object
/// @param [in] start Initial track parameters to propagate
///
/// @return Indication if the initialization was successful
template <typename propagator_state_t, typename parameters_t,
typename path_aborter_t = PathLimitReached>
[[nodiscard]] Result<void> initialize(propagator_state_t& state,
const parameters_t& start) const;

/// @brief Propagate track parameters
///
/// This function performs the propagation of the track parameters according
Expand Down Expand Up @@ -386,10 +393,6 @@ class Propagator final
private:
const Logger& logger() const { return *m_logger; }

template <typename propagator_state_t, typename parameters_t,
typename path_aborter_t>
void initialize(propagator_state_t& state, const parameters_t& start) const;

template <typename propagator_state_t, typename result_t>
void moveStateToResult(propagator_state_t& state, result_t& result) const;

Expand Down
Loading
Loading