Skip to content

Commit

Permalink
Merge branch 'main' into remove-navigator-target-estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Nov 2, 2023
2 parents 373b413 + 3fd6166 commit 8270e7d
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 130 deletions.
11 changes: 7 additions & 4 deletions Core/include/Acts/Navigation/DetectorNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ class DetectorNavigator {
// Estimate the surface status
bool boundaryCheck = c.boundaryCheck;
auto surfaceStatus = stepper.updateSurfaceStatus(
state.stepping, surface, state.options.direction, boundaryCheck,
state.options.targetTolerance, logger());
state.stepping, surface, c.objectIntersection.index(),
state.options.direction, boundaryCheck, state.options.targetTolerance,
logger());
if (surfaceStatus == Intersection3D::Status::reachable) {
ACTS_VERBOSE(volInfo(state)
<< posInfo(state, stepper)
Expand Down Expand Up @@ -296,8 +297,10 @@ class DetectorNavigator {

// TODO not sure about the boundary check
auto surfaceStatus = stepper.updateSurfaceStatus(
state.stepping, *nextSurface, state.options.direction, boundaryCheck,
state.options.targetTolerance, logger());
state.stepping, *nextSurface,
nState.surfaceCandidate->objectIntersection.index(),
state.options.direction, boundaryCheck, state.options.targetTolerance,
logger());

// Check if we are at a surface
if (surfaceStatus == Intersection3D::Status::onSurface) {
Expand Down
7 changes: 4 additions & 3 deletions Core/include/Acts/Propagator/AtlasStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,18 @@ class AtlasStepper {
///
/// @param [in,out] state The stepping state (thread-local cache)
/// @param [in] surface The surface provided
/// @param [in] index The surface intersection index
/// @param [in] navDir The navigation direction
/// @param [in] bcheck The boundary check for this status update
/// @param [in] surfaceTolerance Surface tolerance used for intersection
/// @param [in] logger Logger instance to use
Intersection3D::Status updateSurfaceStatus(
State& state, const Surface& surface, Direction navDir,
const BoundaryCheck& bcheck,
State& state, const Surface& surface, std::uint8_t index,
Direction navDir, const BoundaryCheck& bcheck,
ActsScalar surfaceTolerance = s_onSurfaceTolerance,
const Logger& logger = getDummyLogger()) const {
return detail::updateSingleSurfaceStatus<AtlasStepper>(
*this, state, surface, navDir, bcheck, surfaceTolerance, logger);
*this, state, surface, index, navDir, bcheck, surfaceTolerance, logger);
}

/// Update step size
Expand Down
86 changes: 79 additions & 7 deletions Core/include/Acts/Propagator/DirectNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Intersection.hpp"

#include <algorithm>
#include <iterator>
#include <limits>
#include <memory>
#include <vector>

Expand Down Expand Up @@ -73,6 +75,20 @@ class DirectNavigator {
// Initialize the surface sequence
state.navigation.navSurfaces = navSurfaces;
state.navigation.navSurfaceIter = state.navigation.navSurfaces.begin();

// 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) {
auto surfaceIter = std::find(state.navigation.navSurfaces.begin(),
state.navigation.navSurfaces.end(),
state.navigation.startSurface);
// if current surface in the list, point to the next surface
if (surfaceIter != state.navigation.navSurfaces.end()) {
state.navigation.navSurfaceIter = ++surfaceIter;
}
}

r.initialized = true;
}
}
Expand Down Expand Up @@ -197,8 +213,18 @@ class DirectNavigator {
/// @param [in] stepper Stepper in use
template <typename propagator_state_t, typename stepper_t>
void initialize(propagator_state_t& state, const stepper_t& stepper) const {
(void)state;
(void)stepper;

// Call the navigation helper prior to actual navigation
ACTS_VERBOSE(volInfo(state) << "Initialization.");

// We set the current surface to the start surface
state.navigation.currentSurface = state.navigation.startSurface;
if (state.navigation.currentSurface) {
ACTS_VERBOSE(volInfo(state)
<< "Current surface set to start surface "
<< state.navigation.currentSurface->geometryId());
}
}

/// @brief Navigator pre step call
Expand All @@ -223,10 +249,19 @@ class DirectNavigator {

if (state.navigation.navSurfaceIter != state.navigation.navSurfaces.end()) {
// Establish & update the surface status
// TODO we do not know the intersection index - passing the closer one
const auto& surface = **state.navigation.navSurfaceIter;
const auto index =
chooseIntersection(
state.geoContext, surface, stepper.position(state.stepping),
state.options.direction * stepper.direction(state.stepping),
false, std::numeric_limits<double>::max(),
stepper.overstepLimit(state.stepping),
state.options.targetTolerance)
.index();
auto surfaceStatus = stepper.updateSurfaceStatus(
state.stepping, **state.navigation.navSurfaceIter,
state.options.direction, false, state.options.targetTolerance,
*m_logger);
state.stepping, surface, index, state.options.direction, false,
state.options.targetTolerance, *m_logger);
if (surfaceStatus == Intersection3D::Status::unreachable) {
ACTS_VERBOSE(
"Surface not reachable anymore, switching to next one in "
Expand Down Expand Up @@ -272,10 +307,19 @@ class DirectNavigator {
// Check if we are on surface
if (state.navigation.navSurfaceIter != state.navigation.navSurfaces.end()) {
// Establish the surface status
// TODO we do not know the intersection index - passing the closer one
const auto& surface = **state.navigation.navSurfaceIter;
const auto index =
chooseIntersection(
state.geoContext, surface, stepper.position(state.stepping),
state.options.direction * stepper.direction(state.stepping),
false, std::numeric_limits<double>::max(),
stepper.overstepLimit(state.stepping),
state.options.targetTolerance)
.index();
auto surfaceStatus = stepper.updateSurfaceStatus(
state.stepping, **state.navigation.navSurfaceIter,
state.options.direction, false, state.options.targetTolerance,
*m_logger);
state.stepping, surface, index, state.options.direction, false,
state.options.targetTolerance, *m_logger);
if (surfaceStatus == Intersection3D::Status::onSurface) {
// Set the current surface
state.navigation.currentSurface = *state.navigation.navSurfaceIter;
Expand All @@ -297,6 +341,34 @@ class DirectNavigator {
}

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

ObjectIntersection<Surface> chooseIntersection(const GeometryContext& gctx,
const Surface& surface,
const Vector3& position,
const Vector3& direction,
const BoundaryCheck& bcheck,
double pLimit, double oLimit,
double tolerance) const {
auto intersections =
surface.intersect(gctx, position, direction, bcheck, tolerance);

for (auto& intersection : intersections.split()) {
if (detail::checkIntersection(intersection, pLimit, oLimit, tolerance,
logger())) {
return intersection;
}
}

return ObjectIntersection<Surface>::invalid();
}

const Logger& logger() const { return *m_logger; }

std::unique_ptr<const Logger> m_logger;
Expand Down
7 changes: 4 additions & 3 deletions Core/include/Acts/Propagator/EigenStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,18 @@ class EigenStepper {
///
/// @param [in,out] state The stepping state (thread-local cache)
/// @param [in] surface The surface provided
/// @param [in] index The surface intersection index
/// @param [in] navDir The navigation direction
/// @param [in] bcheck The boundary check for this status update
/// @param [in] surfaceTolerance Surface tolerance used for intersection
/// @param [in] logger A @c Logger instance
Intersection3D::Status updateSurfaceStatus(
State& state, const Surface& surface, Direction navDir,
const BoundaryCheck& bcheck,
State& state, const Surface& surface, std::uint8_t index,
Direction navDir, const BoundaryCheck& bcheck,
ActsScalar surfaceTolerance = s_onSurfaceTolerance,
const Logger& logger = getDummyLogger()) const {
return detail::updateSingleSurfaceStatus<EigenStepper>(
*this, state, surface, navDir, bcheck, surfaceTolerance, logger);
*this, state, surface, index, navDir, bcheck, surfaceTolerance, logger);
}

/// Update step size
Expand Down
11 changes: 6 additions & 5 deletions Core/include/Acts/Propagator/MultiEigenStepperLoop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,23 +690,24 @@ class MultiEigenStepperLoop
///
/// @param [in,out] state The stepping state (thread-local cache)
/// @param [in] surface The surface provided
/// @param [in] index The surface intersection index
/// @param [in] navDir The navigation direction
/// @param [in] bcheck The boundary check for this status update
/// @param [in] surfaceTolerance Surface tolerance used for intersection
/// @param [in] logger A @c Logger instance
Intersection3D::Status updateSurfaceStatus(
State& state, const Surface& surface, Direction navDir,
const BoundaryCheck& bcheck,
State& state, const Surface& surface, std::uint8_t index,
Direction navDir, const BoundaryCheck& bcheck,
ActsScalar surfaceTolerance = s_onSurfaceTolerance,
const Logger& logger = getDummyLogger()) const {
using Status = Intersection3D::Status;

std::array<int, 4> counts = {0, 0, 0, 0};
std::array<int, 3> counts = {0, 0, 0};

for (auto& component : state.components) {
component.status = detail::updateSingleSurfaceStatus<SingleStepper>(
*this, component.state, surface, navDir, bcheck, surfaceTolerance,
logger);
*this, component.state, surface, index, navDir, bcheck,
surfaceTolerance, logger);
++counts[static_cast<std::size_t>(component.status)];
}

Expand Down
34 changes: 21 additions & 13 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,15 @@ class Navigator {
if (navSurfaces.empty() || navIndex == navSurfaces.size()) {
return false;
}
const auto& intersection = navSurfaces.at(navIndex);
// Take the current surface
auto surface = navSurfaces.at(navIndex).representation();
auto surface = intersection.representation();
// Check if we are at a surface
// If we are on the surface pointed at by the index, we can make
// it the current one to pass it to the other actors
auto surfaceStatus = stepper.updateSurfaceStatus(
state.stepping, *surface, state.options.direction, true,
state.options.targetTolerance, logger());
state.stepping, *surface, intersection.index(), state.options.direction,
true, state.options.targetTolerance, logger());
if (surfaceStatus == Intersection3D::Status::onSurface) {
ACTS_VERBOSE(volInfo(state)
<< "Status Surface successfully hit, storing it.");
Expand Down Expand Up @@ -671,8 +672,9 @@ class Navigator {
state.navigation.navSurfaceIndex)
<< " out of " << state.navigation.navSurfaces.size()
<< " surfaces remain to try.");
const auto& intersection = state.navigation.navSurface();
// Take the surface
auto surface = state.navigation.navSurface().object();
const auto* surface = intersection.object();
// Screen output which surface you are on
ACTS_VERBOSE(volInfo(state) << "Next surface candidate will be "
<< surface->geometryId());
Expand All @@ -686,8 +688,9 @@ class Navigator {
}
}
auto surfaceStatus = stepper.updateSurfaceStatus(
state.stepping, *surface, state.options.direction, boundaryCheck,
state.options.targetTolerance, logger());
state.stepping, *surface, intersection.index(),
state.options.direction, boundaryCheck, state.options.targetTolerance,
logger());
if (surfaceStatus == Intersection3D::Status::reachable) {
ACTS_VERBOSE(volInfo(state)
<< "Surface reachable, step size updated to "
Expand Down Expand Up @@ -839,8 +842,9 @@ class Navigator {
// loop over the available navigation layer candidates
while (state.navigation.navLayerIndex !=
state.navigation.navLayers.size()) {
const auto& intersection = state.navigation.navLayer();
// The layer surface
auto layerSurface = state.navigation.navLayer().representation();
const auto* layerSurface = intersection.representation();
// We are on the layer
if (state.navigation.currentSurface == layerSurface) {
ACTS_VERBOSE(volInfo(state) << "We are on a layer, resolve Surfaces.");
Expand All @@ -855,8 +859,9 @@ class Navigator {
}
// Try to step towards it
auto layerStatus = stepper.updateSurfaceStatus(
state.stepping, *layerSurface, state.options.direction, true,
state.options.targetTolerance, logger());
state.stepping, *layerSurface, intersection.index(),
state.options.direction, true, state.options.targetTolerance,
logger());
if (layerStatus == Intersection3D::Status::reachable) {
ACTS_VERBOSE(volInfo(state) << "Layer reachable, step size updated to "
<< stepper.outputStepSize(state.stepping));
Expand Down Expand Up @@ -986,12 +991,14 @@ class Navigator {
// Loop over the boundary surface
while (state.navigation.navBoundaryIndex !=
state.navigation.navBoundaries.size()) {
const auto& intersection = state.navigation.navBoundary();
// That is the current boundary surface
auto boundarySurface = state.navigation.navBoundary().representation();
const auto* boundarySurface = intersection.representation();
// Step towards the boundary surfrace
auto boundaryStatus = stepper.updateSurfaceStatus(
state.stepping, *boundarySurface, state.options.direction, true,
state.options.targetTolerance, logger());
state.stepping, *boundarySurface, intersection.index(),
state.options.direction, true, state.options.targetTolerance,
logger());
if (boundaryStatus == Intersection3D::Status::reachable) {
ACTS_VERBOSE(volInfo(state)
<< "Boundary reachable, step size updated to "
Expand Down Expand Up @@ -1214,8 +1221,9 @@ class Navigator {
if (state.navigation.targetReached || !state.navigation.targetSurface) {
return true;
}
// TODO we do not know the intersection index - passing 0
auto targetStatus = stepper.updateSurfaceStatus(
state.stepping, *state.navigation.targetSurface,
state.stepping, *state.navigation.targetSurface, 0,
state.options.direction, true, state.options.targetTolerance,
logger());
// the only advance could have been to the target
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Propagator/StepperConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ constexpr bool MultiStepperStateConcept= require<
constexpr static bool covariance_transport_exists = require<has_method<const S, void, covariance_transport_curvilinear_t, state&>,
has_method<const S, void, covariance_transport_bound_t, state&, const Surface&, const FreeToBoundCorrection&>>;
static_assert(covariance_transport_exists, "covarianceTransport method not found");
constexpr static bool update_surface_exists = has_method<const S, Intersection3D::Status, update_surface_status_t, state&, const Surface&, Direction, const BoundaryCheck&, ActsScalar, const Logger&>;
constexpr static bool update_surface_exists = has_method<const S, Intersection3D::Status, update_surface_status_t, state&, const Surface&, std::uint8_t, Direction, const BoundaryCheck&, ActsScalar, const Logger&>;
static_assert(update_surface_exists, "updateSurfaceStatus method not found");
constexpr static bool set_step_size_exists = has_method<const S, void, set_step_size_t, state&, double, ConstrainedStep::Type, bool>;
static_assert(set_step_size_exists, "setStepSize method not found");
Expand Down
7 changes: 4 additions & 3 deletions Core/include/Acts/Propagator/StraightLineStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,18 @@ class StraightLineStepper {
///
/// @param [in,out] state The stepping state (thread-local cache)
/// @param [in] surface The surface provided
/// @param [in] index The surface intersection index
/// @param [in] navDir The navigation direction
/// @param [in] bcheck The boundary check for this status update
/// @param [in] surfaceTolerance Surface tolerance used for intersection
/// @param [in] logger A logger instance
Intersection3D::Status updateSurfaceStatus(
State& state, const Surface& surface, Direction navDir,
const BoundaryCheck& bcheck,
State& state, const Surface& surface, std::uint8_t index,
Direction navDir, const BoundaryCheck& bcheck,
ActsScalar surfaceTolerance = s_onSurfaceTolerance,
const Logger& logger = getDummyLogger()) const {
return detail::updateSingleSurfaceStatus<StraightLineStepper>(
*this, state, surface, navDir, bcheck, surfaceTolerance, logger);
*this, state, surface, index, navDir, bcheck, surfaceTolerance, logger);
}

/// Update step size
Expand Down
Loading

0 comments on commit 8270e7d

Please sign in to comment.