Belle II Software  release-05-01-25
test_KalmanCalculator.h
1 #pragma once
2 
3 #include <Eigen/Core>
4 #include <gtest/gtest.h>
5 
6 #include "analysis/VertexFitting/TreeFitter/FitParams.h"
7 #include "analysis/VertexFitting/TreeFitter/KalmanCalculator.h"
8 
9 namespace {
10 
12  class TreeFitterKalmanCalculatorTest : public ::testing::Test {
13  protected:
14  };
15 
17  TEST_F(TreeFitterKalmanCalculatorTest, Functions)
18  {
19  TreeFitter::KalmanCalculator kalman(3, 6);
20  TreeFitter::FitParams fitParDim6(6);
21 
22  fitParDim6.getStateVector() << Eigen::Matrix<double, 6, 1>::Zero(6, 1);
23 
24  fitParDim6.getCovariance() = 2 * Eigen::Matrix<double, 6, 6>::Identity(6, 6);
25 
26  Eigen::Matrix<double, 3, 6> G;
27 
28  // cppcheck-suppress constStatement
29  G << 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1;
30 
31  const Eigen::Matrix<double, 3, 6>& c_G = G;
32 
33  // The kalman matrix m_K should be this after calculation:
34  // 0.5 0 0
35  // 0 0.5 0
36  // 0 0 0.5
37  // 0.5 0 0
38  // 0 0.5 0
39  // 0 0 0.5
40  //
41  Eigen::Matrix<double, 3, 1> residuals;
42  // cppcheck-suppress constStatement
43  residuals << .1, .2, .3;
44  const Eigen::Matrix<double, 3, 1>& c_r = residuals;
45 
46  kalman.calculateGainMatrix(c_r, c_G, fitParDim6, nullptr, 0);
47 
48  kalman.updateState(fitParDim6);
49 
50  Eigen::Matrix<double, 6, 1> expectedUpdatedFitpars;
51  // cppcheck-suppress constStatement
52  expectedUpdatedFitpars << -0.05, -0.1, -0.15, -0.05, -0.1, -0.15;
53 
54  EXPECT_TRUE(expectedUpdatedFitpars.isApprox(fitParDim6.getStateVector().segment(0, 6))) << "fitpar update failed.";
55 
56  Eigen::Matrix<double, 6, 6> expectedUpdatedCov = Eigen::Matrix<double, 6, 6>::Identity(6, 6);
57  // cppcheck-suppress constStatement
58  expectedUpdatedCov.diagonal < -3 > () << -1, -1, -1;
59  // cppcheck-suppress constStatement
60  expectedUpdatedCov.diagonal<3>() << -1, -1, -1;
61 
62  kalman.updateCovariance(fitParDim6);
63  Eigen::Matrix<double, 6, 6> updatedCov = fitParDim6.getCovariance().selfadjointView<Eigen::Lower>();
64 
65 
66  EXPECT_TRUE(updatedCov.isApprox(expectedUpdatedCov)) << "covariance update failed.";
67 
68  }
69 
70 } // namespace
TreeFitter::KalmanCalculator
does the calculation of the gain matrix, updates the cov and fitpars
Definition: KalmanCalculator.h:34
TreeFitter::FitParams
Class to store and manage fitparams (statevector)
Definition: FitParams.h:29
Belle2::TEST_F
TEST_F(GlobalLabelTest, LargeNumberOfTimeDependentParameters)
Test large number of time-dep params for registration and retrieval.
Definition: globalLabel.cc:65