Skip to content

Commit

Permalink
refactor: Do not allocate smoothed track state components in CKF (#3086)
Browse files Browse the repository at this point in the history
Since the CKF is not responsible for smoothing anymore it should not allocate these components on the track state. #2722
  • Loading branch information
andiwand authored Apr 9, 2024
1 parent 6a36ee4 commit e22fef9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
12 changes: 12 additions & 0 deletions Core/include/Acts/EventData/TrackStateType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<kRawBits> bs{*t.m_raw};
std::bitset<TrackStateFlag::NumTrackStateFlags> 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};
};
Expand Down
47 changes: 18 additions & 29 deletions Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoundTrackParameters>(fittedState));
currentTip, std::get<BoundTrackParameters>(fittedState));
}

navigator.navigationBreak(state.navigation, true);
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -776,10 +777,7 @@ class CombinatorialKalmanFilter {
mask = PM::Calibrated;
}

ACTS_VERBOSE(
"Create temp track state with mask: " << std::bitset<
sizeof(std::underlying_type_t<TrackStatePropMask>) * 8>(
static_cast<std::underlying_type_t<TrackStatePropMask>>(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!
Expand Down Expand Up @@ -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<sizeof(std::underlying_type_t<TrackStatePropMask>) *
8>{
static_cast<std::underlying_type_t<TrackStatePropMask>>(
mask)});
ACTS_VERBOSE("Create SourceLink output track state #"
<< trackState.index() << " with mask: " << mask);

if (it != begin) {
// assign indices pointing to first track state
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<sizeof(std::underlying_type_t<TrackStatePropMask>) *
8>{
static_cast<std::underlying_type_t<TrackStatePropMask>>(
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
Expand Down
6 changes: 6 additions & 0 deletions Core/include/Acts/TrackFitting/GainMatrixSmoother.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e22fef9

Please sign in to comment.