@@ -101,35 +101,35 @@ struct two_filters_smoother {
101101
102102 // Eq (3.38) of "Pattern Recognition, Tracking and Vertex
103103 // Reconstruction in Particle Detectors"
104- const matrix_type<e_bound_size, 1u > smoothed_vec =
104+ matrix_type<e_bound_size, 1u > smoothed_vec =
105105 smoothed_cov *
106106 (filtered_cov_inv * trk_state.filtered_params ().vector () +
107107 predicted_cov_inv * predicted_vec);
108108
109- trk_state.smoothed_params ().set_vector (smoothed_vec);
110-
111109 // Return false if track is parallel to z-axis or phi is not finite
112- if (!std::isfinite (trk_state. smoothed_params (). theta ( ))) {
110+ if (!std::isfinite (getter::element (smoothed_vec, e_bound_theta, 0 ))) {
113111 TRACCC_ERROR_HOST_DEVICE (
114112 " Theta is infinite after smoothing (Matrix inversion)" );
115113 return kalman_fitter_status::ERROR_INVERSION;
116114 }
117115
118- if (!std::isfinite (trk_state. smoothed_params (). phi ( ))) {
116+ if (!std::isfinite (getter::element (smoothed_vec, e_bound_phi, 0 ))) {
119117 TRACCC_ERROR_HOST_DEVICE (
120118 " Phi is infinite after smoothing (Matrix inversion)" );
121119 return kalman_fitter_status::ERROR_INVERSION;
122120 }
123121
124- if (math::fabs (trk_state.smoothed_params ().qop ()) == 0 .f ) {
122+ if (math::fabs (getter::element (smoothed_vec, e_bound_qoverp, 0 )) ==
123+ 0 .f ) {
125124 TRACCC_ERROR_HOST_DEVICE (" q/p is zero after smoothing" );
126125 return kalman_fitter_status::ERROR_QOP_ZERO;
127126 }
128127
129- trk_state.smoothed_params ().set_covariance (smoothed_cov);
130-
131128 // Wrap the phi and theta angles in their valid ranges
132- normalize_angles (trk_state.smoothed_params ());
129+ if (!normalize_angles<algebra_t >(smoothed_vec)) {
130+ TRACCC_ERROR_HOST_DEVICE (" Hit theta pole after smoothing!" );
131+ return kalman_fitter_status::ERROR_THETA_POLE;
132+ }
133133
134134 const subspace<algebra_t , e_bound_size> subs (
135135 measurements.at (trk_state.measurement_index ()).subspace ());
@@ -192,8 +192,6 @@ struct two_filters_smoother {
192192 return kalman_fitter_status::ERROR_SMOOTHER_CHI2_NOT_FINITE;
193193 }
194194
195- trk_state.smoothed_chi2 () = getter::element (chi2_smt, 0 , 0 );
196-
197195 /* ************************************
198196 * Set backward filtered parameter
199197 *************************************/
@@ -222,45 +220,49 @@ struct two_filters_smoother {
222220 TRACCC_DEBUG_HOST (" K:\n " << K);
223221
224222 // Calculate the filtered track parameters
225- const matrix_type<6 , 1 > filtered_vec =
223+ matrix_type<6 , 1 > filtered_vec =
226224 predicted_vec + K * (meas_local - H * predicted_vec);
227- const matrix_type<6 , 6 > i_minus_kh = I66 - K * H;
228- matrix_type<6 , 6 > filtered_cov =
229- i_minus_kh * predicted_cov * matrix::transpose (i_minus_kh) +
230- K * V * matrix::transpose (K);
231-
232- // Check the covariance for consistency
233- // @TODO: Need to understand why negative variance happens
234- if (constexpr traccc::scalar min_var{-0 .01f };
235- !details::regularize_covariance<algebra_t >(filtered_cov, min_var)) {
236- TRACCC_ERROR_HOST_DEVICE (" Negative variance after filtering" );
237- return kalman_fitter_status::ERROR_SMOOTHER_INVALID_COVARIANCE;
238- }
239-
240- // Update the bound track parameters
241- bound_params.set_vector (filtered_vec);
242225
243226 // Return false if track is parallel to z-axis or phi is not finite
244- if (!std::isfinite (bound_params. theta ( ))) {
227+ if (!std::isfinite (getter::element (filtered_vec, e_bound_theta, 0 ))) {
245228 TRACCC_ERROR_HOST_DEVICE (
246229 " Theta is infinite after filering in smoother (Matrix "
247230 " inversion)" );
248231 return kalman_fitter_status::ERROR_INVERSION;
249232 }
250233
251- if (!std::isfinite (bound_params. phi ( ))) {
234+ if (!std::isfinite (getter::element (filtered_vec, e_bound_phi, 0 ))) {
252235 TRACCC_ERROR_HOST_DEVICE (
253236 " Phi is infinite after filering in smoother (Matrix "
254237 " inversion)" );
255238 return kalman_fitter_status::ERROR_INVERSION;
256239 }
257240
258- if (math::fabs (bound_params.qop ()) == 0 .f ) {
241+ if (math::fabs (getter::element (filtered_vec, e_bound_qoverp, 0 )) ==
242+ 0 .f ) {
259243 TRACCC_ERROR_HOST_DEVICE (" q/p is zero after filering in smoother" );
260244 return kalman_fitter_status::ERROR_QOP_ZERO;
261245 }
262246
263- bound_params.set_covariance (filtered_cov);
247+ // Wrap the phi and theta angles in their valid ranges
248+ if (!normalize_angles<algebra_t >(filtered_vec)) {
249+ TRACCC_ERROR_HOST_DEVICE (
250+ " Hit theta pole after filtering in smoother!" );
251+ return kalman_fitter_status::ERROR_THETA_POLE;
252+ }
253+
254+ const matrix_type<6 , 6 > i_minus_kh = I66 - K * H;
255+ matrix_type<6 , 6 > filtered_cov =
256+ i_minus_kh * predicted_cov * matrix::transpose (i_minus_kh) +
257+ K * V * matrix::transpose (K);
258+
259+ // Check the covariance for consistency
260+ // @TODO: Need to understand why negative variance happens
261+ if (constexpr traccc::scalar min_var{-0 .01f };
262+ !details::regularize_covariance<algebra_t >(filtered_cov, min_var)) {
263+ TRACCC_ERROR_HOST_DEVICE (" Negative variance after filtering" );
264+ return kalman_fitter_status::ERROR_SMOOTHER_INVALID_COVARIANCE;
265+ }
264266
265267 // Residual between measurement and (projected) filtered vector
266268 const matrix_type<D, 1 > residual = meas_local - H * filtered_vec;
@@ -291,21 +293,18 @@ struct two_filters_smoother {
291293 return kalman_fitter_status::ERROR_SMOOTHER_CHI2_NOT_FINITE;
292294 }
293295
294- // Set backward chi2
296+ // Update the smoothed track parameters
297+ trk_state.smoothed_params ().set_vector (smoothed_vec);
298+ trk_state.smoothed_params ().set_covariance (smoothed_cov);
299+ trk_state.smoothed_chi2 () = getter::element (chi2_smt, 0 , 0 );
295300 trk_state.backward_chi2 () = chi2_val;
296-
297- // Wrap the phi and theta angles in their valid ranges
298- normalize_angles (bound_params);
299-
300- const scalar theta = bound_params.theta ();
301- if (theta <= 0 .f || theta >= 2 .f * constant<traccc::scalar>::pi) {
302- TRACCC_ERROR_HOST_DEVICE (" Hit theta pole after smoothing : %f" ,
303- theta);
304- return kalman_fitter_status::ERROR_THETA_POLE;
305- }
306-
307301 trk_state.set_smoothed ();
308302
303+ // Update the filtered track parameters
304+ bound_params.set_vector (filtered_vec);
305+ bound_params.set_covariance (filtered_cov);
306+
307+ assert (!trk_state.smoothed_params ().is_invalid ());
309308 assert (!bound_params.is_invalid ());
310309
311310 return kalman_fitter_status::SUCCESS;
0 commit comments