Skip to content

Commit

Permalink
Merge branch 'main' into feat/extent-designated-init
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzburger authored Oct 3, 2024
2 parents 8014d8c + e7dceab commit fee8388
Show file tree
Hide file tree
Showing 36 changed files with 281 additions and 148 deletions.
4 changes: 2 additions & 2 deletions CI/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def call(cmd):

ret, gcovr_version_text = check_output(["gcovr", "--version"])
gcovr_version = tuple(
map(int, re.match("gcovr (\d+\.\d+)", gcovr_version_text).group(1).split("."))
map(int, re.match(r"gcovr (\d+\.\d+)", gcovr_version_text).group(1).split("."))
)

extra_flags = []
Expand All @@ -63,7 +63,7 @@ def call(cmd):
if not os.path.exists(coverage_dir):
os.makedirs(coverage_dir)

excludes = ["-e", "../Tests/", "-e", ".*json\.hpp"]
excludes = ["-e", "../Tests/", "-e", r".*json\.hpp"]

# create the html report
call(
Expand Down
20 changes: 20 additions & 0 deletions Core/include/Acts/Geometry/TrackingVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,25 @@ class TrackingVolume : public Volume {
/// @param portal The portal to add
void addPortal(std::shared_ptr<Portal> portal);

using MutableSurfaceRange =
detail::TransformRange<detail::Dereference,
std::vector<std::shared_ptr<Surface>>>;
using SurfaceRange =
detail::TransformRange<detail::ConstDereference,
const std::vector<std::shared_ptr<Surface>>>;

/// Return all surfaces registered under this tracking volume
/// @return the range of surfaces
SurfaceRange surfaces() const;

/// Return mutable view of the registered surfaces under this tracking volume
/// @return the range of surfaces
MutableSurfaceRange surfaces();

/// Add a surface to this tracking volume
/// @param surface The surface to add
void addSurface(std::shared_ptr<Surface> surface);

/// Add a child volume to this tracking volume
/// @param volume The volume to add
/// @note The @p volume will have its mother volume assigned to @p this.
Expand Down Expand Up @@ -516,6 +535,7 @@ class TrackingVolume : public Volume {

std::vector<std::unique_ptr<TrackingVolume>> m_volumes;
std::vector<std::shared_ptr<Portal>> m_portals;
std::vector<std::shared_ptr<Surface>> m_surfaces;
};

} // namespace Acts
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
18 changes: 18 additions & 0 deletions Core/src/Geometry/TrackingVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,25 @@ TrackingVolume::MutablePortalRange TrackingVolume::portals() {
}

void TrackingVolume::addPortal(std::shared_ptr<Portal> portal) {
if (portal == nullptr) {
throw std::invalid_argument("Portal is nullptr");
}
m_portals.push_back(std::move(portal));
}

TrackingVolume::SurfaceRange TrackingVolume::surfaces() const {
return SurfaceRange{m_surfaces};
}

TrackingVolume::MutableSurfaceRange TrackingVolume::surfaces() {
return MutableSurfaceRange{m_surfaces};
}

void TrackingVolume::addSurface(std::shared_ptr<Surface> surface) {
if (surface == nullptr) {
throw std::invalid_argument("Surface is nullptr");
}
m_surfaces.push_back(std::move(surface));
}

} // namespace Acts
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 fee8388

Please sign in to comment.