Skip to content

Commit 50776d5

Browse files
committed
Switch Kálmán filters to use Joseph form
This commit switches the Kálmán filters to use the Joseph form covariance update which is known to be usable for any gain matrix $K$ even if the gain matrix is distorted by numerical imprecision. Empirically, this seems to resolve quite a few issues with our filtering algorithms.
1 parent a5449ab commit 50776d5

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

core/include/traccc/fitting/kalman_filter/gain_matrix_updater.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ struct gain_matrix_updater {
121121
// Calculate the filtered track parameters
122122
const matrix_type<6, 1> filtered_vec =
123123
predicted_vec + K * (meas_local - H * predicted_vec);
124-
const matrix_type<6, 6> filtered_cov = (I66 - K * H) * predicted_cov;
124+
const matrix_type<6, 6> i_minus_kh = I66 - K * H;
125+
const matrix_type<6, 6> filtered_cov =
126+
i_minus_kh * predicted_cov * matrix::transpose(i_minus_kh) +
127+
K * V * matrix::transpose(K);
125128

126129
// Return false if track is parallel to z-axis or phi is not finite
127130
if (!std::isfinite(getter::element(filtered_vec, e_bound_theta, 0))) {
@@ -141,7 +144,13 @@ struct gain_matrix_updater {
141144
const matrix_type<D, 1> residual = meas_local - H * filtered_vec;
142145

143146
// Calculate the chi square
144-
const matrix_type<D, D> R = (I_m - H * K) * V;
147+
const matrix_type<D, D> i_minus_hk = I_m - H * K;
148+
// See
149+
// https://indico.cern.ch/event/1564924/contributions/6629447/attachments/3113201/5519076/asami_250731_acts.pdf
150+
const matrix_type<D, D> R =
151+
i_minus_hk * V * matrix::transpose(i_minus_hk) +
152+
H * i_minus_kh * predicted_cov * matrix::transpose(i_minus_kh) *
153+
matrix::transpose(H);
145154
const matrix_type<1, 1> chi2 =
146155
algebra::matrix::transposed_product<true, false>(
147156
residual, matrix::inverse(R)) *

core/include/traccc/fitting/kalman_filter/two_filters_smoother.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ struct two_filters_smoother {
197197
// Calculate the filtered track parameters
198198
const matrix_type<6, 1> filtered_vec =
199199
predicted_vec + K * (meas_local - H * predicted_vec);
200-
const matrix_type<6, 6> filtered_cov = (I66 - K * H) * predicted_cov;
200+
const matrix_type<6, 6> i_minus_kh = I66 - K * H;
201+
const matrix_type<6, 6> filtered_cov =
202+
i_minus_kh * predicted_cov * matrix::transpose(i_minus_kh) +
203+
K * V * matrix::transpose(K);
201204

202205
// Update the bound track parameters
203206
bound_params.set_vector(filtered_vec);
@@ -221,8 +224,14 @@ struct two_filters_smoother {
221224
const matrix_type<D, 1> residual = meas_local - H * filtered_vec;
222225

223226
// Calculate backward chi2
224-
const matrix_type<D, D> R = (I_m - H * K) * V;
225-
// assert(matrix::determinant(R) != 0.f); // @TODO: This fails
227+
const matrix_type<D, D> i_minus_hk = I_m - H * K;
228+
// See
229+
// https://indico.cern.ch/event/1564924/contributions/6629447/attachments/3113201/5519076/asami_250731_acts.pdf
230+
const matrix_type<D, D> R =
231+
i_minus_hk * V * matrix::transpose(i_minus_hk) +
232+
H * i_minus_kh * predicted_cov * matrix::transpose(i_minus_kh) *
233+
matrix::transpose(H);
234+
// assert(matrix::determinant(R) != 0.f);
226235
assert(std::isfinite(matrix::determinant(R)));
227236
const matrix_type<1, 1> chi2 =
228237
algebra::matrix::transposed_product<true, false>(

0 commit comments

Comments
 (0)