From e22fef9b9152a3f6f964ae025dec58f17dd28dbf Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Tue, 9 Apr 2024 11:35:49 +0200 Subject: [PATCH] refactor: Do not allocate smoothed track state components in CKF (#3086) Since the CKF is not responsible for smoothing anymore it should not allocate these components on the track state. #2722 --- .../include/Acts/EventData/TrackStateType.hpp | 12 +++++ .../CombinatorialKalmanFilter.hpp | 47 +++++++------------ .../Acts/TrackFitting/GainMatrixSmoother.hpp | 6 +++ 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/Core/include/Acts/EventData/TrackStateType.hpp b/Core/include/Acts/EventData/TrackStateType.hpp index 055354e2259..5e43d6cb20c 100644 --- a/Core/include/Acts/EventData/TrackStateType.hpp +++ b/Core/include/Acts/EventData/TrackStateType.hpp @@ -83,6 +83,18 @@ class TrackStateType { /// @param pos the position of the bit to change void reset(std::size_t pos) { set(pos, false); } + friend std::ostream& operator<<(std::ostream& os, TrackStateType t) { + assert(t.m_raw != nullptr); + std::bitset bs{*t.m_raw}; + std::bitset trunc; + for (std::size_t i = 0; i < TrackStateFlag::NumTrackStateFlags; i++) { + trunc[i] = bs[i]; + } + // SharedhitMaterialHoleOutlierParameterMeasurement + os << "SMHOPM=" << trunc; + return os; + } + private: raw_type* m_raw{nullptr}; }; diff --git a/Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp b/Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp index 1441237f830..47e27fd9893 100644 --- a/Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp +++ b/Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp @@ -359,10 +359,10 @@ class CombinatorialKalmanFilter { result.lastError = res.error(); } else { const auto& fittedState = *res; + std::size_t currentTip = result.activeTips.back().first; // Assign the fitted parameters result.fittedParameters.emplace( - result.lastMeasurementIndices.back(), - std::get(fittedState)); + currentTip, std::get(fittedState)); } navigator.navigationBreak(state.navigation, true); @@ -671,7 +671,8 @@ class CombinatorialKalmanFilter { // TrackState. No storage allocation for uncalibrated/calibrated // measurement and filtered parameter auto stateMask = - ~(TrackStatePropMask::Calibrated | TrackStatePropMask::Filtered); + ~(TrackStatePropMask::Calibrated | TrackStatePropMask::Filtered | + TrackStatePropMask::Smoothed); // Increment of number of processed states tipState.nStates++; @@ -776,10 +777,7 @@ class CombinatorialKalmanFilter { mask = PM::Calibrated; } - ACTS_VERBOSE( - "Create temp track state with mask: " << std::bitset< - sizeof(std::underlying_type_t) * 8>( - static_cast>(mask))); + ACTS_VERBOSE("Create temp track state with mask: " << mask); // CAREFUL! This trackstate has a previous index that is not in this // MultiTrajectory Visiting brackwards from this track state will // fail! @@ -834,29 +832,25 @@ class CombinatorialKalmanFilter { for (auto it = begin; it != end; ++it) { auto& candidateTrackState = *it; - PM mask = PM::All; + PM mask = PM::Predicted | PM::Filtered | PM::Jacobian | PM::Calibrated; if (it != begin) { - // subsequent track states don't need storage for these - mask = ~PM::Predicted & ~PM::Jacobian; + // subsequent track states don't need storage for these as they will + // be shared + mask &= ~PM::Predicted & ~PM::Jacobian; } if (isOutlier) { - mask &= ~PM::Filtered; // outlier won't have separate filtered - // parameters + // outlier won't have separate filtered parameters + mask &= ~PM::Filtered; } // copy this trackstate into fitted states MultiTrajectory typename traj_t::TrackStateProxy trackState = result.fittedStates->makeTrackState(mask, candidateTrackState.previous()); - ACTS_VERBOSE( - "Create SourceLink output track state #" - << trackState.index() << " with mask: " - << std::bitset) * - 8>{ - static_cast>( - mask)}); + ACTS_VERBOSE("Create SourceLink output track state #" + << trackState.index() << " with mask: " << mask); if (it != begin) { // assign indices pointing to first track state @@ -896,7 +890,6 @@ class CombinatorialKalmanFilter { // Set the filtered parameter index to be the same with predicted // parameter trackState.shareFrom(PM::Predicted, PM::Filtered); - } else { // Kalman update auto updateRes = m_extensions.updater( @@ -933,21 +926,17 @@ class CombinatorialKalmanFilter { /// @param prevTip The index of the previous state /// /// @return The tip of added state - std::size_t addNonSourcelinkState(const TrackStatePropMask& stateMask, + std::size_t addNonSourcelinkState(TrackStatePropMask stateMask, const BoundState& boundState, result_type& result, bool isSensitive, std::size_t prevTip) const { // Add a track state auto trackStateProxy = result.fittedStates->makeTrackState(stateMask, prevTip); - ACTS_VERBOSE( - "Create " - << (isSensitive ? "Hole" : "Material") << " output track state #" - << trackStateProxy.index() << " with mask: " - << std::bitset) * - 8>{ - static_cast>( - stateMask)}); + ACTS_VERBOSE("Create " << (isSensitive ? "Hole" : "Material") + << " output track state #" + << trackStateProxy.index() + << " with mask: " << stateMask); const auto& [boundParams, jacobian, pathLength] = boundState; // Fill the track state diff --git a/Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp b/Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp index 24052e0631e..8d8a731039f 100644 --- a/Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp +++ b/Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp @@ -82,6 +82,9 @@ class GainMatrixSmoother { ACTS_VERBOSE("Getting previous track state"); auto prev_ts = trajectory.getTrackState(entryIndex); + // ensure the track state has a smoothed component + prev_ts.addComponents(TrackStatePropMask::Smoothed); + prev_ts.smoothed() = prev_ts.filtered(); prev_ts.smoothedCovariance() = prev_ts.filteredCovariance(); @@ -111,6 +114,9 @@ class GainMatrixSmoother { ACTS_VERBOSE("Filtered covariance:\n" << ts.filteredCovariance()); ACTS_VERBOSE("Jacobian:\n" << prev_ts.jacobian()); + // ensure the track state has a smoothed component + ts.addComponents(TrackStatePropMask::Smoothed); + if (auto res = calculate(&ts, &prev_ts, filtered, filteredCovariance, smoothed, predicted, predictedCovariance, smoothedCovariance, jacobian, logger);