Skip to content

Commit

Permalink
Merge branch 'main' into feat/grid-outputs-comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzburger authored Aug 7, 2024
2 parents 95aa173 + 0e9746a commit 6403bc9
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 140 deletions.
1 change: 1 addition & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
--preset=github-ci
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DCMAKE_CXX_FLAGS="-Werror"
-DACTS_BUILD_ODD=OFF
- name: Measure
run: cmakeperf collect build/compile_commands.json -o perf.csv
- name: Results
Expand Down
7 changes: 7 additions & 0 deletions Core/include/Acts/Detector/Detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ class Detector : public std::enable_shared_from_this<Detector> {
/// @return the map which can be queried with GeometryID for ranges
const GeometryHierarchyMap<const Surface*>& sensitiveHierarchyMap() const;

/// Search for a surface with the given identifier.
///
/// @param id is the geometry identifier of the surface
/// @retval nullptr if no such surface exists
/// @retval pointer to the found surface otherwise.
const Surface* findSurface(GeometryIdentifier id) const;

/// @brief Visit all reachable surfaces of the detector
///
/// @tparam visitor_t Type of the callable visitor
Expand Down
8 changes: 5 additions & 3 deletions Core/include/Acts/EventData/MeasurementHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ auto visit_measurement(A&& param, B&& cov, std::size_t dim, L&& lambda) {
/// @tparam L The generic lambda type to call
/// @param dim The runtime dimension of the measurement
/// @param lambda The generic lambda instance to call
/// @param args Additional arguments passed to @p lambda
/// @return Returns the lambda return value
template <typename L>
auto visit_measurement(std::size_t dim, L&& lambda) {
return template_switch_lambda<1, eBoundSize>(dim, lambda);
template <typename L, typename... Args>
auto visit_measurement(std::size_t dim, L&& lambda, Args&&... args) {
return template_switch_lambda<1, eBoundSize>(dim, lambda,
std::forward<Args>(args)...);
}

} // namespace Acts
32 changes: 25 additions & 7 deletions Core/include/Acts/EventData/detail/TestSourceLink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Detector/Detector.hpp"
#include "Acts/EventData/MultiTrajectory.hpp"
#include "Acts/EventData/SourceLink.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
Expand All @@ -27,6 +28,8 @@

namespace Acts::detail::Test {

struct TestSourceLinkSurfaceAccessor;

/// A minimal source link implementation for testing.
///
/// Instead of storing a reference to a measurement or raw data, the measurement
Expand All @@ -35,6 +38,8 @@ namespace Acts::detail::Test {
/// identifier is stored that can be used to store additional information. How
/// this is interpreted depends on the specific tests.
struct TestSourceLink final {
using SurfaceAccessor = TestSourceLinkSurfaceAccessor;

GeometryIdentifier m_geometryId{};
std::size_t sourceId = 0u;
// use eBoundSize to indicate unused indices
Expand Down Expand Up @@ -87,17 +92,30 @@ struct TestSourceLink final {
return os;
}
constexpr std::size_t index() const { return sourceId; }
};

struct SurfaceAccessor {
const Acts::TrackingGeometry& trackingGeometry;
struct TestSourceLinkSurfaceAccessor {
const TrackingGeometry& geometry;

const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
const auto& testSourceLink = sourceLink.get<TestSourceLink>();
return trackingGeometry.findSurface(testSourceLink.m_geometryId);
}
};
const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
const auto& testSourceLink = sourceLink.get<TestSourceLink>();
return geometry.findSurface(testSourceLink.m_geometryId);
}
};

namespace Experimental {

struct TestSourceLinkSurfaceAccessor {
const Acts::Experimental::Detector& geometry;

const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const {
const auto& testSourceLink = sourceLink.get<TestSourceLink>();
return geometry.findSurface(testSourceLink.m_geometryId);
}
};

} // namespace Experimental

inline std::ostream& operator<<(std::ostream& os,
const TestSourceLink& sourceLink) {
return sourceLink.print(os);
Expand Down
119 changes: 60 additions & 59 deletions Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,6 @@ class CombinatorialKalmanFilter {
TrackIndexType prevTip = currentBranch.tipIndex();

// Create trackstates for all source links (will be filtered later)
// Results are stored in result => no return value
using TrackStatesResult =
Acts::Result<CkfTypes::BranchVector<TrackIndexType>>;
TrackStatesResult tsRes = trackStateCandidateCreator(
Expand All @@ -745,64 +744,23 @@ class CombinatorialKalmanFilter {
const CkfTypes::BranchVector<TrackIndexType>& newTrackStateList =
*tsRes;

Result<std::pair<unsigned int, unsigned int>> procRes =
processNewTrackStates(state.geoContext, newTrackStateList, result);
if (!procRes.ok()) {
ACTS_ERROR("Processing of selected track states failed: "
<< procRes.error());
return procRes.error();
}
auto [nNewBranchesOnSurface, nStoppedBranches] = *procRes;
nBranchesOnSurface = nNewBranchesOnSurface;

if (nStoppedBranches >= newTrackStateList.size()) {
// All branches on the surface have been stopped. Reset happens at the
// end of the function
ACTS_VERBOSE("All branches on surface " << surface->geometryId()
<< " have been stopped");
} else if (nBranchesOnSurface > 0) {
if (currentBranch.outermostTrackState().typeFlags().test(
TrackStateFlag::OutlierFlag)) {
// We don't need to update the stepper given an outlier state
ACTS_VERBOSE("Outlier state detected on surface "
<< surface->geometryId());
} else {
// If there are measurement track states on this surface
ACTS_VERBOSE("Filtering step successful with " << nBranchesOnSurface
<< " branches");
// Update stepping state using filtered parameters of last track
// state on this surface
auto ts = result.activeBranches.back().outermostTrackState();
stepper.update(state.stepping,
MultiTrajectoryHelpers::freeFiltered(
state.options.geoContext, ts),
ts.filtered(), ts.filteredCovariance(), *surface);
ACTS_VERBOSE("Stepping state is updated with filtered parameter:");
ACTS_VERBOSE("-> " << ts.filtered().transpose()
<< " of track state with tip = " << ts.index());
}
} else { // nBranchesOnSurface == 0
if (newTrackStateList.empty()) {
ACTS_VERBOSE("Detected hole after measurement selection on surface "
<< surface->geometryId());

// After `processNewTrackStates` `currentBranch` is invalidated
currentBranch = result.activeBranches.back();
prevTip = currentBranch.tipIndex();

// Setting the number of branches on the surface to 1 as the hole
// still counts as a branch
nBranchesOnSurface = 1;

auto stateMask = PM::Predicted | PM::Jacobian;

currentBranch.nHoles()++;

// Add a hole track state to the multitrajectory
TrackIndexType currentTip = addNonSourcelinkState(
stateMask, boundState, result, true, prevTip);
auto nonSourcelinkState =
result.trackStates->getTrackState(currentTip);
currentBranch.tipIndex() = currentTip;
currentBranch.nHoles()++;

BranchStopperResult branchStopperResult =
m_extensions.branchStopper(currentBranch, nonSourcelinkState);
Expand All @@ -819,6 +777,49 @@ class CombinatorialKalmanFilter {
// Remove the branch from list
result.activeBranches.pop_back();
}
} else {
Result<unsigned int> procRes = processNewTrackStates(
state.geoContext, newTrackStateList, result);
if (!procRes.ok()) {
ACTS_ERROR("Processing of selected track states failed: "
<< procRes.error());
return procRes.error();
}
nBranchesOnSurface = *procRes;

if (nBranchesOnSurface == 0) {
// All branches on the surface have been stopped. Reset happens at
// the end of the function
ACTS_VERBOSE("All branches on surface " << surface->geometryId()
<< " have been stopped");
} else {
// `currentBranch` is invalidated after `processNewTrackStates`
currentBranch = result.activeBranches.back();
prevTip = currentBranch.tipIndex();

if (currentBranch.outermostTrackState().typeFlags().test(
TrackStateFlag::OutlierFlag)) {
// We don't need to update the stepper given an outlier state
ACTS_VERBOSE("Outlier state detected on surface "
<< surface->geometryId());
} else {
// If there are measurement track states on this surface
ACTS_VERBOSE("Filtering step successful with "
<< nBranchesOnSurface << " branches");
// Update stepping state using filtered parameters of last track
// state on this surface
auto ts = result.activeBranches.back().outermostTrackState();
stepper.update(state.stepping,
MultiTrajectoryHelpers::freeFiltered(
state.options.geoContext, ts),
ts.filtered(), ts.filteredCovariance(), *surface);
ACTS_VERBOSE(
"Stepping state is updated with filtered parameter:");
ACTS_VERBOSE("-> "
<< ts.filtered().transpose()
<< " of track state with tip = " << ts.index());
}
}
}

// Update state and stepper with post material effects
Expand All @@ -845,11 +846,6 @@ class CombinatorialKalmanFilter {
// measurement and filtered parameter
auto stateMask = PM::Predicted | PM::Jacobian;

if (isSensitive) {
// Increment of number of holes
currentBranch.nHoles()++;
}

// Transport the covariance to a curvilinear surface
stepper.transportCovarianceToCurvilinear(state.stepping);

Expand All @@ -873,6 +869,9 @@ class CombinatorialKalmanFilter {
auto nonSourcelinkState =
result.trackStates->getTrackState(currentTip);
currentBranch.tipIndex() = currentTip;
if (isSensitive) {
currentBranch.nHoles()++;
}

BranchStopperResult branchStopperResult =
m_extensions.branchStopper(currentBranch, nonSourcelinkState);
Expand Down Expand Up @@ -927,23 +926,27 @@ class CombinatorialKalmanFilter {
/// @param gctx The geometry context for this track finding/fitting
/// @param newTrackStateList index list of new track states
/// @param result which contains among others the new states, and the list of active branches
/// @return the number of newly added branches and number of stopped branches or an error
Result<std::pair<unsigned int, unsigned int>> processNewTrackStates(
/// @return the number of newly added branches or an error
Result<unsigned int> processNewTrackStates(
const Acts::GeometryContext& gctx,
const CkfTypes::BranchVector<TrackIndexType>& newTrackStateList,
result_type& result) const {
using PM = TrackStatePropMask;

unsigned int nBranchesOnSurface = 0;
unsigned int nStoppedBranches = 0;

auto rootBranch = result.activeBranches.back();

// Build the new branches by forking the root branch
// Build the new branches by forking the root branch. Reverse the order to
// process the best candidate first
CkfTypes::BranchVector<TrackProxy> newBranches;
for (auto [i, tipIndex] : enumerate(newTrackStateList)) {
auto newBranch = (i == 0) ? rootBranch : rootBranch.shallowCopy();
newBranch.tipIndex() = tipIndex;
for (auto it = newTrackStateList.rbegin(); it != newTrackStateList.rend();
++it) {
// Keep the root branch as the first branch, make a copy for the others
auto newBranch = (it == newTrackStateList.rbegin())
? rootBranch
: rootBranch.shallowCopy();
newBranch.tipIndex() = *it;
newBranches.push_back(newBranch);
}

Expand Down Expand Up @@ -978,7 +981,6 @@ class CombinatorialKalmanFilter {
newBranch.nMeasurements()++;
} else {
ACTS_WARNING("Cannot handle this track state flags");
nStoppedBranches++;
continue;
}

Expand All @@ -993,7 +995,6 @@ class CombinatorialKalmanFilter {
nBranchesOnSurface++;
} else {
// Record the number of stopped branches
nStoppedBranches++;
if (branchStopperResult == BranchStopperResult::StopAndKeep) {
storeLastActiveBranch(result);
}
Expand All @@ -1002,7 +1003,7 @@ class CombinatorialKalmanFilter {
}
}

return std::pair{nBranchesOnSurface, nStoppedBranches};
return nBranchesOnSurface;
}

/// @brief CombinatorialKalmanFilter actor operation: add a hole or material track state
Expand Down
4 changes: 4 additions & 0 deletions Core/include/Acts/TrackFitting/GainMatrixUpdater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class GainMatrixUpdater {
private:
std::tuple<double, std::error_code> visitMeasurement(
InternalTrackState trackState, const Logger& logger) const;

template <std::size_t N>
std::tuple<double, std::error_code> visitMeasurementImpl(
InternalTrackState trackState, const Logger& logger) const;
};

} // namespace Acts
Loading

0 comments on commit 6403bc9

Please sign in to comment.