File indexing completed on 2026-04-08 07:47:10
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/TrackFitting/GainMatrixSmoother.hpp"
0010
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "Acts/EventData/TrackParameterHelpers.hpp"
0013 #include "Acts/EventData/detail/CovarianceHelper.hpp"
0014 #include "Acts/TrackFitting/KalmanFitterError.hpp"
0015
0016 namespace Acts {
0017
0018 Result<void> GainMatrixSmoother::calculate(AnyMutableTrackStateProxy ts,
0019 AnyConstTrackStateProxy prev_ts,
0020 const Logger& logger) const {
0021 auto prevPredictedCovariance = prev_ts.predictedCovariance();
0022 auto filteredCovariance = ts.filteredCovariance();
0023 auto prevJacobian = prev_ts.jacobian();
0024
0025 ACTS_VERBOSE("Prev. predicted covariance\n"
0026 << prevPredictedCovariance << "\n, inverse: \n"
0027 << prevPredictedCovariance.inverse());
0028
0029
0030
0031
0032 BoundMatrix G = filteredCovariance * prevJacobian.transpose() *
0033 prevPredictedCovariance.inverse();
0034
0035 if (G.hasNaN()) {
0036 ACTS_VERBOSE("Gain smoothing matrix G has NaNs");
0037
0038 ACTS_VERBOSE("Filtered covariance:\n" << filteredCovariance);
0039 ACTS_VERBOSE("Jacobian:\n" << prevJacobian);
0040 ACTS_VERBOSE("Predicted covariance:\n" << prevPredictedCovariance);
0041 ACTS_VERBOSE("Inverse of predicted covariance:\n"
0042 << prevPredictedCovariance.inverse());
0043
0044 ACTS_VERBOSE("Gain smoothing matrix G:\n" << G);
0045
0046 return KalmanFitterError::SmoothFailed;
0047 }
0048
0049 ACTS_VERBOSE("Gain smoothing matrix G:\n" << G);
0050
0051 auto prevPredicted = prev_ts.predicted();
0052 auto prevSmoothed = prev_ts.smoothed();
0053
0054 auto filtered = ts.filtered();
0055 auto smoothed = ts.smoothed();
0056 auto smoothedCovariance = ts.smoothedCovariance();
0057 auto prevSmoothedCovariance = prev_ts.smoothedCovariance();
0058
0059 ACTS_VERBOSE("Calculate smoothed parameters:");
0060 ACTS_VERBOSE("Filtered parameters: " << filtered.transpose());
0061 ACTS_VERBOSE("Prev. smoothed parameters: " << prevSmoothed.transpose());
0062 ACTS_VERBOSE("Prev. predicted parameters: " << prevPredicted.transpose());
0063
0064
0065 smoothed =
0066 filtered + G * subtractBoundParameters(prevSmoothed, prevPredicted);
0067
0068 smoothed = normalizeBoundParameters(smoothed);
0069
0070 ACTS_VERBOSE("Smoothed parameters are: " << smoothed.transpose());
0071 ACTS_VERBOSE("Calculate smoothed covariance:");
0072 ACTS_VERBOSE("Prev. smoothed covariance:\n" << prevSmoothedCovariance);
0073
0074
0075 smoothedCovariance =
0076 filteredCovariance +
0077 G * (prevSmoothedCovariance - prevPredictedCovariance) * G.transpose();
0078
0079 if (doCovCheckAndAttemptFix) {
0080
0081
0082
0083
0084 BoundMatrix smoothedCov = smoothedCovariance;
0085 if (!detail::CovarianceHelper<BoundMatrix>::validate(smoothedCov)) {
0086 ACTS_DEBUG(
0087 "Smoothed covariance is not positive definite. Could result in "
0088 "negative covariance!");
0089 }
0090
0091 smoothedCovariance = smoothedCov;
0092 }
0093
0094 ACTS_VERBOSE("Smoothed covariance is: \n" << smoothedCovariance);
0095
0096 return Result<void>::success();
0097 }
0098
0099 }