Skip to content

Commit

Permalink
Merge branch 'main' into feat/measurement_it_forward
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 3, 2024
2 parents b5cd817 + b0fcfb4 commit ee60730
Show file tree
Hide file tree
Showing 35 changed files with 279 additions and 152 deletions.
33 changes: 27 additions & 6 deletions Core/include/Acts/Geometry/Extent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ struct ExtentEnvelope {
}
}

/// Constructor from an array of envelopes
/// @param values the array of envelopes
constexpr explicit ExtentEnvelope(
const std::array<Envelope, numBinningValues()>& values)
: m_values(values) {}

/// Static factory for a zero envelope
/// @return the zero envelope
constexpr static ExtentEnvelope Zero() {
Expand All @@ -74,6 +68,33 @@ struct ExtentEnvelope {
}};
}

/// Helper struct for designated initializer construction
struct Arguments {
Envelope x = zeroEnvelope;
Envelope y = zeroEnvelope;
Envelope z = zeroEnvelope;
Envelope r = zeroEnvelope;
Envelope phi = zeroEnvelope;
Envelope rPhi = zeroEnvelope;
Envelope h = zeroEnvelope;
Envelope eta = zeroEnvelope;
Envelope mag = zeroEnvelope;
};

/// Constructor using a helper struct for designated initializaion
/// @param args the arguments
constexpr explicit ExtentEnvelope(Arguments&& args) {
using enum BinningValue;
m_values[toUnderlying(binX)] = args.x;
m_values[toUnderlying(binY)] = args.y;
m_values[toUnderlying(binZ)] = args.z;
m_values[toUnderlying(binR)] = args.r;
m_values[toUnderlying(binPhi)] = args.phi;
m_values[toUnderlying(binH)] = args.h;
m_values[toUnderlying(binEta)] = args.eta;
m_values[toUnderlying(binMag)] = args.mag;
}

/// Comparison operator between envelope sets
/// @param lhs the left hand side
/// @param rhs the right hand side
Expand Down
15 changes: 12 additions & 3 deletions Core/include/Acts/Propagator/PropagatorOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ struct PurePropagatorPlainOptions {
/// Absolute maximum path length
double pathLimit = std::numeric_limits<double>::max();

/// Required tolerance to reach surface
double surfaceTolerance = s_onSurfaceTolerance;

/// Loop protection step, it adapts the pathLimit
bool loopProtection = true;
/// Allowed loop fraction, 1 is a full loop
double loopFraction = 0.5;

/// Required tolerance to reach surface
double surfaceTolerance = s_onSurfaceTolerance;

/// Constrain the propagation to selected volumes
/// @note ignored if empty
/// @note requires `VolumeConstraintAborter` aborter
std::vector<std::uint32_t> constrainToVolumeIds;
/// Additional volumes to be considered as end of world
/// @note ignored if empty
/// @note requires `VolumeConstraintAborter` aborter
std::vector<std::uint32_t> endOfWorldVolumeIds;
};

} // namespace detail
Expand Down
56 changes: 55 additions & 1 deletion Core/include/Acts/Propagator/StandardAborters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct ForcedSurfaceReached : SurfaceReached {
: SurfaceReached(std::numeric_limits<double>::lowest()) {}
};

/// This is the condition that the end of World has been reached
/// This is the condition that the end of world has been reached
/// it then triggers an propagation abort
struct EndOfWorldReached {
/// boolean operator for abort condition without using the result
Expand All @@ -181,6 +181,60 @@ struct EndOfWorldReached {
}
};

/// This is the condition that the end of world has been reached
/// it then triggers a propagation abort
struct VolumeConstraintAborter {
/// boolean operator for abort condition without using the result
///
/// @tparam propagator_state_t Type of the propagator state
/// @tparam navigator_t Type of the navigator
///
/// @param [in,out] state The propagation state object
/// @param [in] navigator The navigator object
/// @param logger a logger instance
template <typename propagator_state_t, typename stepper_t,
typename navigator_t>
bool checkAbort(propagator_state_t& state, const stepper_t& /*stepper*/,
const navigator_t& navigator, const Logger& logger) const {
const auto& constrainToVolumeIds = state.options.constrainToVolumeIds;
const auto& endOfWorldVolumeIds = state.options.endOfWorldVolumeIds;

if (constrainToVolumeIds.empty() && endOfWorldVolumeIds.empty()) {
return false;
}
const auto* currentVolume = navigator.currentVolume(state.navigation);

// We need a volume to check its ID
if (currentVolume == nullptr) {
return false;
}

const auto currentVolumeId =
static_cast<std::uint32_t>(currentVolume->geometryId().volume());

if (!constrainToVolumeIds.empty() &&
std::find(constrainToVolumeIds.begin(), constrainToVolumeIds.end(),
currentVolumeId) == constrainToVolumeIds.end()) {
ACTS_VERBOSE(
"VolumeConstraintAborter aborter | Abort with volume constrain "
<< currentVolumeId);
return true;
}

if (!endOfWorldVolumeIds.empty() &&
std::find(endOfWorldVolumeIds.begin(), endOfWorldVolumeIds.end(),
currentVolumeId) != endOfWorldVolumeIds.end()) {
ACTS_VERBOSE(
"VolumeConstraintAborter aborter | Abort with additional end of "
"world volume "
<< currentVolumeId);
return true;
}

return false;
}
};

/// Aborter that checks if the propagation has reached any surface
struct AnySurfaceReached {
template <typename propagator_state_t, typename stepper_t,
Expand Down
9 changes: 8 additions & 1 deletion Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,19 @@ class CombinatorialKalmanFilter {

const bool isEndOfWorldReached =
endOfWorldReached.checkAbort(state, stepper, navigator, logger());
const bool isVolumeConstraintReached = volumeConstraintAborter.checkAbort(
state, stepper, navigator, logger());
const bool isPathLimitReached = result.pathLimitReached.checkAbort(
state, stepper, navigator, logger());
const bool isTargetReached =
targetReached.checkAbort(state, stepper, navigator, logger());
const bool allBranchesStopped = result.activeBranches.empty();
if (isEndOfWorldReached || isPathLimitReached || isTargetReached ||
allBranchesStopped) {
allBranchesStopped || isVolumeConstraintReached) {
if (isEndOfWorldReached) {
ACTS_VERBOSE("End of world reached");
} else if (isVolumeConstraintReached) {
ACTS_VERBOSE("Volume constraint reached");
} else if (isPathLimitReached) {
ACTS_VERBOSE("Path limit reached");
} else if (isTargetReached) {
Expand Down Expand Up @@ -1173,6 +1177,9 @@ class CombinatorialKalmanFilter {
/// End of world aborter
EndOfWorldReached endOfWorldReached;

/// Volume constraint aborter
VolumeConstraintAborter volumeConstraintAborter;

/// Actor logger instance
const Logger* actorLogger{nullptr};
/// Updater logger instance
Expand Down
7 changes: 2 additions & 5 deletions Core/include/Acts/TrackFitting/KalmanFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,8 @@ class KalmanFitter {
result.fittedStates->applyBackwards(
result.lastMeasurementIndex, [&](auto trackState) {
auto fSurface = &trackState.referenceSurface();
auto surface_it = std::find_if(
result.passedAgainSurfaces.begin(),
result.passedAgainSurfaces.end(),
[=](const Surface* s) { return s == fSurface; });
if (surface_it == result.passedAgainSurfaces.end()) {
if (!rangeContainsValue(result.passedAgainSurfaces,
fSurface)) {
// If reversed filtering missed this surface, then there is
// no smoothed parameter
trackState.unset(TrackStatePropMask::Smoothed);
Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Acts/Vertexing/VertexingError.hpp"
#include "Acts/Vertexing/VertexingOptions.hpp"

#include <algorithm>
#include <functional>

namespace Acts {
Expand Down Expand Up @@ -81,8 +82,7 @@ class AdaptiveMultiVertexFitter {

Result<void> removeVertexFromCollection(Vertex& vtxToRemove,
const Logger& logger) {
auto it = std::find(vertexCollection.begin(), vertexCollection.end(),
&vtxToRemove);
auto it = std::ranges::find(vertexCollection, &vtxToRemove);
// Check if the value was found before erasing
if (it == vertexCollection.end()) {
ACTS_ERROR("vtxToRemove is not part of vertexCollection.");
Expand Down
21 changes: 9 additions & 12 deletions Core/src/Geometry/CylinderVolumeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,17 @@ Acts::CylinderVolumeBuilder::trackingVolume(
double tolerance = m_cfg.ringTolerance;
// Search for the rmin value - and insert if necessary
double rMin = discBounds->rMin();
auto innerSearch = std::find_if(
innerRadii.begin(), innerRadii.end(), [&](double reference) {
return std::abs(rMin - reference) < tolerance;
});
auto innerSearch = std::ranges::find_if(innerRadii, [&](double r) {
return std::abs(rMin - r) < tolerance;
});
if (innerSearch == innerRadii.end()) {
innerRadii.push_back(rMin);
}
// Search for the rmax value - and insert if necessary
double rMax = discBounds->rMax();
auto outerSearch = std::find_if(
outerRadii.begin(), outerRadii.end(), [&](double reference) {
return std::abs(rMax - reference) < tolerance;
});
auto outerSearch = std::ranges::find_if(outerRadii, [&](double r) {
return std::abs(rMax - r) < tolerance;
});
if (outerSearch == outerRadii.end()) {
outerRadii.push_back(rMax);
}
Expand Down Expand Up @@ -356,10 +354,9 @@ Acts::CylinderVolumeBuilder::trackingVolume(
double test = elay->surfaceRepresentation().binningPositionValue(
gctx, BinningValue::binR);
// Find the right bin
auto ringVolume = std::find_if(
volumeRminRmax.begin(), volumeRminRmax.end(),
[&](const auto& reference) {
return (test > reference.first && test < reference.second);
auto ringVolume =
std::ranges::find_if(volumeRminRmax, [&](const auto& vrr) {
return (test > vrr.first && test < vrr.second);
});
if (ringVolume != volumeRminRmax.end()) {
unsigned int ringBin =
Expand Down
10 changes: 4 additions & 6 deletions Core/src/Geometry/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ Acts::Layer::compatibleSurfaces(
double farLimit = options.farLimit;

auto isUnique = [&](const SurfaceIntersection& b) {
auto find_it = std::find_if(
sIntersections.begin(), sIntersections.end(), [&b](const auto& a) {
return a.object() == b.object() && a.index() == b.index();
});
return find_it == sIntersections.end();
return std::ranges::none_of(sIntersections, [&b](const auto& a) {
return a.object() == b.object() && a.index() == b.index();
});
};

// lemma 0 : accept the surface
Expand All @@ -140,7 +138,7 @@ Acts::Layer::compatibleSurfaces(
if (sensitive && options.resolveSensitive) {
return true;
}
// next option: it's a material surface and you want to have it
// next option: it's a material surface, and you want to have it
if (options.resolveMaterial && sf.surfaceMaterial() != nullptr) {
return true;
}
Expand Down
6 changes: 2 additions & 4 deletions Core/src/Surfaces/VerticesHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ std::vector<Acts::ActsScalar> Acts::detail::VerticesHelper::phiSegments(
if (!phiRefs.empty()) {
for (const auto& phiRef : phiRefs) {
// Trying to find the right patch
auto match = std::find_if(
phiSegments.begin(), phiSegments.end(), [&](ActsScalar phiSeg) {
if (std::ranges::none_of(phiSegments, [&](ActsScalar phiSeg) {
return std::abs(phiSeg - phiRef) < phiTolerance;
});
if (match == phiSegments.end()) {
})) {
phiSegments.push_back(phiRef);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Core/src/TrackFinding/MeasurementSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ MeasurementSelector::Cuts MeasurementSelector::getCutsByTheta(
// look at the positive half of the Z axis
const double constrainedTheta = std::min(theta, M_PI - theta);

auto it = std::find_if(config.begin(), config.end(),
[constrainedTheta](const InternalCutBin& cuts) {
return constrainedTheta < cuts.maxTheta;
});
auto it = std::ranges::find_if(
config, [constrainedTheta](const InternalCutBin& cuts) {
return constrainedTheta < cuts.maxTheta;
});
assert(it != config.end());
return {it->maxNumMeasurements, it->maxChi2Measurement, it->maxChi2Outlier};
}
Expand Down
3 changes: 1 addition & 2 deletions Core/src/Utilities/BinningType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const std::vector<BinningValue>& allBinningValues() {
}

BinningValue binningValueFromName(const std::string& name) {
auto it =
std::find(s_binningValueNames.begin(), s_binningValueNames.end(), name);
auto it = std::ranges::find(s_binningValueNames, name);
if (it == s_binningValueNames.end()) {
throw std::invalid_argument("Unknown binning value name: " + name);
}
Expand Down
15 changes: 5 additions & 10 deletions Core/src/Vertexing/AdaptiveMultiVertexFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "Acts/Vertexing/IVertexFinder.hpp"
#include "Acts/Vertexing/VertexingError.hpp"

#include <algorithm>

namespace Acts {

Result<std::vector<Vertex>> AdaptiveMultiVertexFinder::find(
Expand Down Expand Up @@ -364,10 +366,7 @@ std::pair<int, bool> AdaptiveMultiVertexFinder::checkVertexAndCompatibleTracks(
!m_cfg.useFastCompatibility)) {
// TODO: Understand why looking for compatible tracks only in seed tracks
// and not also in all tracks
auto foundIter =
std::find_if(seedTracks.begin(), seedTracks.end(),
[&trk](auto seedTrk) { return trk == seedTrk; });
if (foundIter != seedTracks.end()) {
if (rangeContainsValue(seedTracks, trk)) {
nCompatibleTracks++;
ACTS_DEBUG("Compatible track found.");

Expand Down Expand Up @@ -399,9 +398,7 @@ auto AdaptiveMultiVertexFinder::removeCompatibleTracksFromSeedTracks(
trkAtVtx.chi2Track < m_cfg.maxVertexChi2 &&
!m_cfg.useFastCompatibility)) {
// Find and remove track from seedTracks
auto foundSeedIter =
std::find_if(seedTracks.begin(), seedTracks.end(),
[&trk](auto seedTrk) { return trk == seedTrk; });
auto foundSeedIter = std::ranges::find(seedTracks, trk);
if (foundSeedIter != seedTracks.end()) {
seedTracks.erase(foundSeedIter);
removedSeedTracks.push_back(trk);
Expand All @@ -425,9 +422,7 @@ bool AdaptiveMultiVertexFinder::removeTrackIfIncompatible(
double compatibility = trkAtVtx.vertexCompatibility;
if (compatibility > maxCompatibility) {
// Try to find track in seed tracks
auto foundSeedIter =
std::find_if(seedTracks.begin(), seedTracks.end(),
[&trk](auto seedTrk) { return trk == seedTrk; });
auto foundSeedIter = std::ranges::find(seedTracks, trk);
if (foundSeedIter != seedTracks.end()) {
maxCompatibility = compatibility;
maxCompSeedIt = foundSeedIter;
Expand Down
Loading

0 comments on commit ee60730

Please sign in to comment.