Skip to content

Commit

Permalink
feat: Scale backward filtering covariance (#1147)
Browse files Browse the repository at this point in the history
Add an option to scale up the covariance matrix before performing the backward filtering for the Kalman fitter. Scaling this covariance might be necessary to obtain a reasonable smoothed covariance at the end of the backward filtering and shouldn't affect the performance.
  • Loading branch information
Corentin-Allaire committed Feb 15, 2022
1 parent 73173e0 commit b8abfb5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Core/include/Acts/TrackFitting/KalmanFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ struct KalmanFitterOptions {
/// @param rSurface The reference surface for the fit to be expressed at
/// @param mScattering Whether to include multiple scattering
/// @param eLoss Whether to include energy loss
/// @param rFiltering Whether to run filtering in reversed direction as
/// smoothing
/// @param rFiltering Whether to run filtering in reversed direction as smoothing
/// @param rfScaling Scale factor for the covariance matrix before the backward filtering
KalmanFitterOptions(const GeometryContext& gctx,
const MagneticFieldContext& mctx,
std::reference_wrapper<const CalibrationContext> cctx,
KalmanFitterExtensions extensions_, LoggerWrapper logger_,
const PropagatorPlainOptions& pOptions,
const Surface* rSurface = nullptr,
bool mScattering = true, bool eLoss = true,
bool rFiltering = false)
bool rFiltering = false, double rfScaling = 1.0)
: geoContext(gctx),
magFieldContext(mctx),
calibrationContext(cctx),
Expand All @@ -123,6 +123,7 @@ struct KalmanFitterOptions {
multipleScattering(mScattering),
energyLoss(eLoss),
reversedFiltering(rFiltering),
reversedFilteringCovarianceScaling(rfScaling),
logger(logger_) {}
/// Contexts are required and the options must not be default-constructible.
KalmanFitterOptions() = delete;
Expand Down Expand Up @@ -152,6 +153,12 @@ struct KalmanFitterOptions {
/// ReverseFilteringLogic
bool reversedFiltering = false;

/// Factor by which the covariance of the input of the reversed filtering is
/// scaled. This is only used in the backwardfiltering (if reversedFiltering
/// is true or if the ReverseFilteringLogic return true for the track of
/// interest)
double reversedFilteringCovarianceScaling = 1.0;

/// Logger
LoggerWrapper logger;
};
Expand Down Expand Up @@ -273,6 +280,9 @@ class KalmanFitter {
/// Whether run reversed filtering
bool reversedFiltering = false;

// Scale the covariance before the reversed filtering
double reversedFilteringCovarianceScaling = 1.0;

/// @brief Kalman actor operation
///
/// @tparam propagator_state_t is the type of Propagagor state
Expand Down Expand Up @@ -470,9 +480,11 @@ class KalmanFitter {
auto st = result.fittedStates.getTrackState(result.lastMeasurementIndex);

// Update the stepping state
stepper.resetState(state.stepping, st.filtered(), st.filteredCovariance(),
st.referenceSurface(), state.stepping.navDir,
state.options.maxStepSize);
stepper.resetState(
state.stepping, st.filtered(),
reversedFilteringCovarianceScaling * st.filteredCovariance(),
st.referenceSurface(), state.stepping.navDir,
state.options.maxStepSize);

// For the last measurement state, smoothed is filtered
st.smoothed() = st.filtered();
Expand Down Expand Up @@ -1080,6 +1092,8 @@ class KalmanFitter {
kalmanActor.multipleScattering = kfOptions.multipleScattering;
kalmanActor.energyLoss = kfOptions.energyLoss;
kalmanActor.reversedFiltering = kfOptions.reversedFiltering;
kalmanActor.reversedFilteringCovarianceScaling =
kfOptions.reversedFilteringCovarianceScaling;
kalmanActor.extensions = std::move(kfOptions.extensions);

// Run the fitter
Expand Down Expand Up @@ -1173,6 +1187,8 @@ class KalmanFitter {
kalmanActor.multipleScattering = kfOptions.multipleScattering;
kalmanActor.energyLoss = kfOptions.energyLoss;
kalmanActor.reversedFiltering = kfOptions.reversedFiltering;
kalmanActor.reversedFilteringCovarianceScaling =
kfOptions.reversedFilteringCovarianceScaling;
kalmanActor.extensions = std::move(kfOptions.extensions);

// Set the surface sequence
Expand Down
3 changes: 3 additions & 0 deletions Tests/UnitTests/Core/TrackFitting/KalmanFitterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ BOOST_AUTO_TEST_CASE(ZeroFieldWithSurfaceForward) {

// reverse filtering instead of smoothing
kfOptions.reversedFiltering = true;
kfOptions.reversedFilteringCovarianceScaling = 100.0;
expected_reversed = true;
expected_smoothed = false;
tester.test_ZeroFieldWithSurfaceForward(kfZero, kfOptions, start, rng,
Expand All @@ -125,6 +126,7 @@ BOOST_AUTO_TEST_CASE(ZeroFieldWithSurfaceBackward) {

// reverse filtering instead of smoothing
kfOptions.reversedFiltering = true;
kfOptions.reversedFilteringCovarianceScaling = 100.0;
expected_reversed = true;
expected_smoothed = false;
tester.test_ZeroFieldWithSurfaceBackward(
Expand Down Expand Up @@ -190,6 +192,7 @@ BOOST_AUTO_TEST_CASE(ZeroFieldWithReverseFiltering) {
.connect<&TestReverseFilteringLogic::operator()>(&trfl);

kfOptions.reversedFiltering = reverse;
kfOptions.reversedFilteringCovarianceScaling = 100.0;

tester.test_ZeroFieldWithReverseFiltering(
kfZero, kfOptions, start, rng, expected_reversed, expected_smoothed);
Expand Down

0 comments on commit b8abfb5

Please sign in to comment.