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!: Refactor navigator options #3182

Merged
merged 3 commits into from
Jul 15, 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
20 changes: 8 additions & 12 deletions Core/include/Acts/Navigation/DetectorNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ class DetectorNavigator {
/// created for every propagation/extrapolation step
/// and keep thread-local navigation information
struct State : public NavigationState {
/// Navigation state - external state: the start surface
const Surface* startSurface = nullptr;
Options options;

/// Navigation state - external state: the current surface
const Surface* currentSurface = nullptr;
/// Navigation state - external state: the target surface
const Surface* targetSurface = nullptr;
/// Indicator if the target is reached
bool targetReached = false;
/// Navigation state : a break has been detected
Expand All @@ -81,12 +79,10 @@ class DetectorNavigator {
Logging::Level::INFO))
: m_cfg{cfg}, m_logger{std::move(_logger)} {}

State makeState(const Surface* startSurface,
const Surface* targetSurface) const {
State result;
result.startSurface = startSurface;
result.targetSurface = targetSurface;
return result;
State makeState(const Options& options) const {
State state;
state.options = options;
return state;
}

const Surface* currentSurface(const State& state) const {
Expand All @@ -102,11 +98,11 @@ class DetectorNavigator {
}

const Surface* startSurface(const State& state) const {
return state.startSurface;
return state.options.startSurface;
}

const Surface* targetSurface(const State& state) const {
return state.targetSurface;
return state.options.targetSurface;
}

bool targetReached(const State& state) const { return state.targetReached; }
Expand Down
82 changes: 27 additions & 55 deletions Core/include/Acts/Propagator/DirectNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class DirectNavigator {

struct Config {};

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

/// @brief Nested Actor struct, called Initializer
///
/// This is needed for the initialization of the surface sequence.
Expand Down Expand Up @@ -76,10 +82,10 @@ class DirectNavigator {
// In case the start surface is in the list of nav surfaces
// we need to correct the iterator to point to the next surface
// in the vector
if (state.navigation.startSurface) {
if (state.navigation.options.startSurface) {
auto surfaceIter = std::find(state.navigation.navSurfaces.begin(),
state.navigation.navSurfaces.end(),
state.navigation.startSurface);
state.navigation.options.startSurface);
// if current surface in the list, point to the next surface
if (surfaceIter != state.navigation.navSurfaces.end()) {
state.navigation.navSurfaceIter = ++surfaceIter;
Expand All @@ -97,81 +103,56 @@ class DirectNavigator {
/// propagation/extrapolation step and keep thread-local navigation
/// information
struct State {
Options options;

/// Externally provided surfaces - expected to be ordered along the path
SurfaceSequence navSurfaces = {};

/// Iterator the next surface
SurfaceIter navSurfaceIter = navSurfaces.begin();

/// Navigation state - external interface: the start surface
const Surface* startSurface = nullptr;
/// Navigation state - external interface: the current surface
const Surface* currentSurface = nullptr;
/// Navigation state - external interface: the target surface
const Surface* targetSurface = nullptr;
/// Navigation state - starting layer
const Layer* startLayer = nullptr;
/// Navigation state - target layer
const Layer* targetLayer = nullptr;
/// Navigation state: the start volume
const TrackingVolume* startVolume = nullptr;
/// Navigation state: the current volume
const TrackingVolume* currentVolume = nullptr;
/// Navigation state: the target volume
const TrackingVolume* targetVolume = nullptr;

/// Navigation state - external interface: target is reached
bool targetReached = false;
/// Navigation state - external interface: a break has been detected
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;
result.startSurface = startSurface;
result.targetSurface = targetSurface;
return result;
State makeState(const Options& options) const {
State state;
state.options = options;
return state;
}

const Surface* currentSurface(const State& state) const {
return state.currentSurface;
}

const TrackingVolume* currentVolume(const State& state) const {
return state.currentVolume;
const TrackingVolume* currentVolume(const State& /*state*/) const {
return nullptr;
}

const IVolumeMaterial* currentVolumeMaterial(const State& state) const {
if (state.currentVolume == nullptr) {
return nullptr;
}
return state.currentVolume->volumeMaterial();
const IVolumeMaterial* currentVolumeMaterial(const State& /*state*/) const {
return nullptr;
}

const Surface* startSurface(const State& state) const {
return state.startSurface;
return state.options.startSurface;
}

const Surface* targetSurface(const State& state) const {
return state.targetSurface;
return state.options.targetSurface;
}

bool targetReached(const State& state) const { return state.targetReached; }

bool endOfWorldReached(State& state) const {
return state.currentVolume == nullptr;
}
bool endOfWorldReached(State& /*state*/) const { return false; }

bool navigationBreak(const State& state) const {
return state.navigationBreak;
Expand All @@ -198,13 +179,12 @@ class DirectNavigator {
template <typename propagator_state_t, typename stepper_t>
void initialize(propagator_state_t& state,
const stepper_t& /*stepper*/) const {
ACTS_VERBOSE(volInfo(state) << "initialize");
andiwand marked this conversation as resolved.
Show resolved Hide resolved
ACTS_VERBOSE("initialize");

// We set the current surface to the start surface
state.navigation.currentSurface = state.navigation.startSurface;
state.navigation.currentSurface = state.navigation.options.startSurface;
if (state.navigation.currentSurface) {
ACTS_VERBOSE(volInfo(state)
<< "Current surface set to start surface "
ACTS_VERBOSE("Current surface set to start surface "
<< state.navigation.currentSurface->geometryId());
}
}
Expand All @@ -218,7 +198,7 @@ class DirectNavigator {
/// @param [in] stepper Stepper in use
template <typename propagator_state_t, typename stepper_t>
void preStep(propagator_state_t& state, const stepper_t& stepper) const {
ACTS_VERBOSE(volInfo(state) << "pre step");
ACTS_VERBOSE("pre step");

// Navigator target always resets the current surface
state.navigation.currentSurface = nullptr;
Expand Down Expand Up @@ -258,7 +238,7 @@ class DirectNavigator {
// Set the navigation break
state.navigation.navigationBreak = true;
// If no externally provided target is given, the target is reached
if (state.navigation.targetSurface == nullptr) {
if (state.navigation.options.targetSurface == nullptr) {
state.navigation.targetReached = true;
// Announce it then
ACTS_VERBOSE("No target Surface, job done.");
Expand All @@ -275,7 +255,7 @@ class DirectNavigator {
/// @param [in] stepper Stepper in use
template <typename propagator_state_t, typename stepper_t>
void postStep(propagator_state_t& state, const stepper_t& stepper) const {
ACTS_VERBOSE(volInfo(state) << "post step");
ACTS_VERBOSE("post step");

// Navigator post step always resets the current surface
state.navigation.currentSurface = nullptr;
Expand Down Expand Up @@ -322,14 +302,6 @@ class DirectNavigator {
}

private:
template <typename propagator_state_t>
std::string volInfo(const propagator_state_t& state) const {
return (state.navigation.currentVolume != nullptr
? state.navigation.currentVolume->volumeName()
: "No Volume") +
" | ";
}

ObjectIntersection<Surface> chooseIntersection(
const GeometryContext& gctx, const Surface& surface,
const Vector3& position, const Vector3& direction,
Expand Down
16 changes: 9 additions & 7 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class Navigator {
/// It acts as an internal state which is created for every propagation and
/// meant to keep thread-local navigation information.
struct State {
Options options;

// Navigation on surface level
/// the vector of navigation surfaces to work through
NavigationSurfaces navSurfaces = {};
Expand Down Expand Up @@ -194,14 +196,14 @@ class Navigator {
getDefaultLogger("Navigator", Logging::Level::INFO))
: m_cfg{std::move(cfg)}, m_logger{std::move(_logger)} {}

State makeState(const Surface* startSurface,
const Surface* targetSurface) const {
assert(startSurface != nullptr && "Start surface must be set");
State makeState(const Options& options) const {
assert(options.startSurface != nullptr && "Start surface must be set");

State result;
result.startSurface = startSurface;
result.targetSurface = targetSurface;
return result;
State state;
state.options = options;
state.startSurface = options.startSurface;
state.targetSurface = options.targetSurface;
return state;
}

const Surface* currentSurface(const State& state) const {
Expand Down
7 changes: 6 additions & 1 deletion Core/include/Acts/Propagator/NavigatorOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

namespace Acts {

struct NavigatorPlainOptions {};
class Surface;

struct NavigatorPlainOptions {
const Surface *startSurface{};
const Surface *targetSurface{};
};

} // namespace Acts
10 changes: 7 additions & 3 deletions Core/include/Acts/Propagator/Propagator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,18 @@ auto Acts::Propagator<S, N>::makeState(

// The expanded options (including path limit)
auto eOptions = options.extend(abortList);
eOptions.navigation.startSurface = &start.referenceSurface();
eOptions.navigation.targetSurface = nullptr;
using OptionsType = decltype(eOptions);
// Initialize the internal propagator state
using StateType =
action_list_t_state_t<OptionsType,
typename propagator_options_t::action_list_type>;
// Initialize the internal propagator state
StateType state{
eOptions,
m_stepper.makeState(eOptions.geoContext, eOptions.magFieldContext, start,
eOptions.stepping.maxStepSize),
m_navigator.makeState(&start.referenceSurface(), nullptr)};
m_navigator.makeState(eOptions.navigation)};

static_assert(
Concepts::has_method<const S, Result<double>, Concepts::Stepper::step_t,
Expand Down Expand Up @@ -199,6 +201,8 @@ auto Acts::Propagator<S, N>::makeState(

// Create the extended options and declare their type
auto eOptions = options.extend(abortList);
eOptions.navigation.startSurface = &start.referenceSurface();
eOptions.navigation.targetSurface = &target;
using OptionsType = decltype(eOptions);

// Initialize the internal propagator state
Expand All @@ -209,7 +213,7 @@ auto Acts::Propagator<S, N>::makeState(
eOptions,
m_stepper.makeState(eOptions.geoContext, eOptions.magFieldContext, start,
eOptions.stepping.maxStepSize),
m_navigator.makeState(&start.referenceSurface(), &target)};
m_navigator.makeState(eOptions.navigation)};

static_assert(
Concepts::has_method<const S, Result<double>, Concepts::Stepper::step_t,
Expand Down
Loading
Loading