Skip to content

Commit

Permalink
Merge branch 'main' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 17, 2024
2 parents b46994c + c862d2d commit 06338b8
Show file tree
Hide file tree
Showing 27 changed files with 365 additions and 145 deletions.
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"inherits": "common",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_FLAGS": "-Werror",
"CMAKE_COMPILE_WARNING_AS_ERROR": "ON",
"ACTS_FORCE_ASSERTIONS": "ON",
"ACTS_ENABLE_LOG_FAILURE_THRESHOLD": "ON",
"ACTS_BUILD_BENCHMARKS": "ON",
Expand Down
1 change: 1 addition & 0 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ add_subdirectory(src/MagneticField)
add_subdirectory(src/Material)
add_subdirectory(src/Navigation)
add_subdirectory(src/Propagator)
add_subdirectory(src/Seeding)
add_subdirectory(src/Surfaces)
add_subdirectory(src/TrackFinding)
add_subdirectory(src/TrackFitting)
Expand Down
11 changes: 11 additions & 0 deletions Core/include/Acts/EventData/GenericBoundTrackParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ class GenericBoundTrackParameters {
return m_surface->referenceFrame(geoCtx, position(geoCtx), momentum());
}

/// Reflect the parameters in place.
void reflectInPlace() { m_params = reflectBoundParameters(m_params); }

/// Reflect the parameters.
/// @return Reflected parameters.
GenericBoundTrackParameters<ParticleHypothesis> reflect() const {
GenericBoundTrackParameters<ParticleHypothesis> reflected = *this;
reflected.reflectInPlace();
return reflected;
}

private:
BoundVector m_params;
std::optional<BoundSquareMatrix> m_cov;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ class GenericCurvilinearTrackParameters
Vector3 position() const {
return GenericBoundTrackParameters<ParticleHypothesis>::position({});
}

/// Reflect the parameters.
/// @return Reflected parameters.
GenericCurvilinearTrackParameters<ParticleHypothesis> reflect() const {
GenericCurvilinearTrackParameters<ParticleHypothesis> reflected = *this;
reflected.reflectInPlace();
return reflected;
}
};

} // namespace Acts
12 changes: 12 additions & 0 deletions Core/include/Acts/EventData/GenericFreeTrackParameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Acts/Definitions/Common.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/TrackParametersConcept.hpp"
#include "Acts/EventData/TransformationHelpers.hpp"
#include "Acts/EventData/detail/PrintParameters.hpp"
#include "Acts/Utilities/MathHelpers.hpp"
#include "Acts/Utilities/UnitVectors.hpp"
Expand Down Expand Up @@ -175,6 +176,17 @@ class GenericFreeTrackParameters {
return m_particleHypothesis;
}

/// Reflect the parameters in place.
void reflectInPlace() { m_params = reflectFreeParameters(m_params); }

/// Reflect the parameters.
/// @return Reflected parameters.
GenericFreeTrackParameters<ParticleHypothesis> reflect() const {
GenericFreeTrackParameters<ParticleHypothesis> reflected = *this;
reflected.reflectInPlace();
return reflected;
}

private:
FreeVector m_params;
std::optional<FreeSquareMatrix> m_cov;
Expand Down
28 changes: 28 additions & 0 deletions Core/include/Acts/EventData/TransformationHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,39 @@
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Utilities/Result.hpp"
#include "Acts/Utilities/detail/periodic.hpp"

namespace Acts {

class Surface;

/// Reflect bound track parameters.
///
/// @param boundParams Bound track parameters vector
/// @return Reflected bound track parameters vector
inline BoundVector reflectBoundParameters(const BoundVector& boundParams) {
BoundVector reflected = boundParams;
auto [phi, theta] = detail::normalizePhiTheta(
boundParams[eBoundPhi] - M_PI, M_PI - boundParams[eBoundTheta]);
reflected[eBoundPhi] = phi;
reflected[eBoundTheta] = theta;
reflected[eBoundQOverP] = -boundParams[eBoundQOverP];
return reflected;
}

/// Reflect free track parameters.
///
/// @param freeParams Free track parameters vector
/// @return Reflected free track parameters vector
inline FreeVector reflectFreeParameters(const FreeVector& freeParams) {
FreeVector reflected = freeParams;
reflected[eFreeDir0] = -freeParams[eFreeDir0];
reflected[eFreeDir1] = -freeParams[eFreeDir1];
reflected[eFreeDir2] = -freeParams[eFreeDir2];
reflected[eFreeQOverP] = -freeParams[eFreeQOverP];
return reflected;
}

/// Transform bound track parameters into equivalent free track parameters.
///
/// @param surface Surface onto which the input parameters are bound
Expand Down
99 changes: 78 additions & 21 deletions Core/include/Acts/Propagator/DirectNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include "Acts/Definitions/Direction.hpp"
#include "Acts/Geometry/BoundarySurfaceT.hpp"
#include "Acts/Geometry/Layer.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
Expand All @@ -17,6 +18,7 @@
#include "Acts/Surfaces/BoundaryTolerance.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Intersection.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <algorithm>
#include <iterator>
Expand Down Expand Up @@ -63,7 +65,7 @@ class DirectNavigator {
Options options;

/// Index of the next surface to try
std::size_t surfaceIndex = 0;
int surfaceIndex = 0;

/// Navigation state - external interface: the current surface
const Surface* currentSurface = nullptr;
Expand All @@ -72,6 +74,35 @@ class DirectNavigator {
bool targetReached = false;
/// Navigation state - external interface: a break has been detected
bool navigationBreak = false;

const Surface* navSurface() const {
return options.surfaces.at(surfaceIndex);
}

void nextSurface(Direction direction) {
if (direction == Direction::Forward) {
++surfaceIndex;
} else {
--surfaceIndex;
}
}

bool endOfSurfaces() const {
return surfaceIndex < 0 ||
surfaceIndex >= static_cast<int>(options.surfaces.size());
}

int remainingSurfaces(Direction direction) const {
if (direction == Direction::Forward) {
return options.surfaces.size() - surfaceIndex;
}
return surfaceIndex + 1;
}

void resetSurfaceIndex(Direction direction) {
surfaceIndex =
direction == Direction::Forward ? 0 : options.surfaces.size() - 1;
}
};

explicit DirectNavigator(std::unique_ptr<const Logger> _logger =
Expand Down Expand Up @@ -135,17 +166,41 @@ class DirectNavigator {
void initialize(propagator_state_t& state,
const stepper_t& /*stepper*/) const {
ACTS_VERBOSE("Initialize. Surface sequence for navigation:");
for (auto surface : state.navigation.options.surfaces) {
for (const Surface* surface : state.navigation.options.surfaces) {
ACTS_VERBOSE(surface->geometryId()
<< " - " << surface->center(state.geoContext).transpose());
}

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

// Reset the surface index
state.navigation.resetSurfaceIndex(state.options.direction);
for (const Surface* surface : state.navigation.options.surfaces) {
// make sure we skip over the start surface
state.navigation.nextSurface(state.options.direction);
if (surface == state.navigation.currentSurface) {
break;
}
}
ACTS_VERBOSE("Start surface index set to "
<< state.navigation.surfaceIndex);
if (state.navigation.endOfSurfaces()) {
ACTS_DEBUG(
"Did not find the start surface in the sequence. Assuming it is not "
"part of the sequence. Trusting the correctness of the input "
"sequence. Resetting the surface index.");
state.navigation.resetSurfaceIndex(state.options.direction);
}

state.navigation.navigationBreak = false;
state.navigation.targetReached = false;
}

/// @brief Navigator pre step call
Expand All @@ -157,21 +212,25 @@ 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 {
if (state.navigation.navigationBreak) {
return;
}

ACTS_VERBOSE("pre step");

// Navigator target always resets the current surface
state.navigation.currentSurface = nullptr;

// Output the position in the sequence
ACTS_VERBOSE((state.navigation.options.surfaces.size() -
state.navigation.surfaceIndex)
ACTS_VERBOSE(state.navigation.remainingSurfaces(state.options.direction)
<< " out of " << state.navigation.options.surfaces.size()
<< " surfaces remain to try.");

if (state.navigation.surfaceIndex >=
state.navigation.options.surfaces.size()) {
if (state.navigation.endOfSurfaces()) {
// Set the navigation break
ACTS_VERBOSE("End of surfaces reached, navigation break.");
state.navigation.navigationBreak = true;
stepper.releaseStepSize(state.stepping, ConstrainedStep::actor);
// If no externally provided target is given, the target is reached
if (state.navigation.options.targetSurface == nullptr) {
state.navigation.targetReached = true;
Expand All @@ -183,8 +242,7 @@ class DirectNavigator {

// Establish & update the surface status
// TODO we do not know the intersection index - passing the closer one
const auto& surface =
*state.navigation.options.surfaces.at(state.navigation.surfaceIndex);
const auto& surface = *state.navigation.navSurface();
const double farLimit = std::numeric_limits<double>::max();
const auto index =
chooseIntersection(
Expand All @@ -202,7 +260,7 @@ class DirectNavigator {
"Surface not reachable anymore, switching to next one in "
"sequence");
// Move the sequence to the next surface
++state.navigation.surfaceIndex;
state.navigation.nextSurface(state.options.direction);
} else {
ACTS_VERBOSE("Navigation stepSize set to "
<< stepper.outputStepSize(state.stepping));
Expand All @@ -218,26 +276,27 @@ 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 {
if (state.navigation.navigationBreak) {
return;
}

ACTS_VERBOSE("post step");

// Navigator post step always resets the current surface
state.navigation.currentSurface = nullptr;

// Output the position in the sequence
ACTS_VERBOSE((state.navigation.options.surfaces.size() -
state.navigation.surfaceIndex)
ACTS_VERBOSE(state.navigation.remainingSurfaces(state.options.direction)
<< " out of " << state.navigation.options.surfaces.size()
<< " surfaces remain to try.");

if (state.navigation.surfaceIndex >=
state.navigation.options.surfaces.size()) {
if (state.navigation.endOfSurfaces()) {
return;
}

// Establish the surface status
// TODO we do not know the intersection index - passing the closer one
const auto& surface =
*state.navigation.options.surfaces.at(state.navigation.surfaceIndex);
const auto& surface = *state.navigation.navSurface();
const double farLimit = std::numeric_limits<double>::max();
const auto index =
chooseIntersection(
Expand All @@ -252,14 +311,12 @@ class DirectNavigator {
*m_logger);
if (surfaceStatus == Intersection3D::Status::onSurface) {
// Set the current surface
state.navigation.currentSurface =
state.navigation.options.surfaces.at(state.navigation.surfaceIndex);
state.navigation.currentSurface = state.navigation.navSurface();
ACTS_VERBOSE("Current surface set to "
<< state.navigation.currentSurface->geometryId());
// Move the sequence to the next surface
++state.navigation.surfaceIndex;
if (state.navigation.surfaceIndex <
state.navigation.options.surfaces.size()) {
state.navigation.nextSurface(state.options.direction);
if (!state.navigation.endOfSurfaces()) {
ACTS_VERBOSE("Next surface candidate is "
<< state.navigation.options.surfaces
.at(state.navigation.surfaceIndex)
Expand Down
5 changes: 3 additions & 2 deletions Core/include/Acts/Propagator/MultiStepperAborters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ struct MultiStepperSurfaceReached : public SurfaceReached {
}

ACTS_VERBOSE(
"MultiStepperSurfaceReached aborter | "
"Target intersection not found. Maybe next time?");
"MultiStepperSurfaceReached aborter | Average distance to target: "
<< sIntersection.pathLength());
}

bool reached = true;
Expand All @@ -84,6 +84,7 @@ struct MultiStepperSurfaceReached : public SurfaceReached {

if (!SurfaceReached::checkAbort(singleState, singleStepper, navigator,
logger)) {
cmp.status() = Acts::Intersection3D::Status::reachable;
reached = false;
} else {
cmp.status() = Acts::Intersection3D::Status::onSurface;
Expand Down
2 changes: 0 additions & 2 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ class Navigator {
: m_cfg{std::move(cfg)}, m_logger{std::move(_logger)} {}

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

State state;
state.options = options;
state.startSurface = options.startSurface;
Expand Down
4 changes: 0 additions & 4 deletions Core/include/Acts/Propagator/TryAllNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ class TryAllNavigatorBase {
: m_cfg(std::move(cfg)), m_logger{std::move(_logger)} {}

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

State state;
state.options = options;
state.startSurface = options.startSurface;
Expand Down Expand Up @@ -587,8 +585,6 @@ class TryAllOverstepNavigator : public TryAllNavigatorBase {
: TryAllNavigatorBase(std::move(cfg), std::move(logger)) {}

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

State state;
state.options = options;
state.startSurface = options.startSurface;
Expand Down
Loading

0 comments on commit 06338b8

Please sign in to comment.