10#include <analysis/VertexFitting/TreeFitter/KalmanCalculator.h>
21 m_G(sizeRes, sizeState),
22 m_R(sizeRes, sizeRes),
23 m_Rinverse(sizeRes, sizeRes),
24 m_K(sizeState, sizeRes),
25 m_CGt(sizeState, sizeRes)
32 const Eigen::Matrix < double, -1, 1, 0, 7, 1 > & residuals,
33 const Eigen::Matrix < double, -1, -1, 0, 7, MAX_MATRIX_SIZE > & G,
35 const Eigen::Matrix < double, -1, -1, 0, 7, 7 > * V,
41 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > C = fitparams.
getCovariance().triangularView<Eigen::Lower>();
43 m_CGt = C.selfadjointView<Eigen::Lower>() * G.transpose();
44 Eigen::Matrix < double, -1, -1, 0, 7, 7 > Rtemp = G *
m_CGt;
45 if (V && (weight) && ((*V).diagonal().array() != 0).all()) {
47 const Eigen::Matrix < double, -1, -1, 0, 7, 7 > weightedV =
48 weight * (*V).selfadjointView<Eigen::Lower>();
50 m_R = Rtemp + weightedV;
53 m_R = Rtemp.triangularView<Eigen::Lower>();
56 Eigen::Matrix < double, -1, -1, 0, 7, 7 > RInvtemp;
57 RInvtemp =
m_R.selfadjointView<Eigen::Lower>();
62 return ErrCode(ErrCode::Status::success);
67 double eps = Eigen::NumTraits<double>::epsilon();
75 double eps = Eigen::NumTraits<double>::epsilon();
76 Eigen::Matrix < double, -1, 1, 0, 7, 1 > res_prime =
82 m_chisq = res_prime.transpose() *
m_Rinverse.selfadjointView<Eigen::Lower>() * res_prime;
85 TREEFITTER_NO_STACK_WARNING
89 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > fitCov =
92 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > GRinvGt =
96 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > deltaCov =
97 fitCov.selfadjointView<Eigen::Lower>() * GRinvGt * fitCov.selfadjointView<Eigen::Lower>();
99 double eps = Eigen::NumTraits<double>::epsilon();
100 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > delta =
101 (fitCov.array() - deltaCov.array()).matrix() + eps * Eigen::MatrixXd::Identity(fitCov.rows(), fitCov.cols());
103 fitparams.
getCovariance().triangularView<Eigen::Lower>() = delta.triangularView<Eigen::Lower>();
107 TREEFITTER_RESTORE_WARNINGS
abstract errorocode be aware that the default is success
Class to store and manage fitparams (statevector)
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector()
getter for the fit parameters/statevector
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
void updateState(FitParams &fitparams)
update statevector
ErrCode calculateGainMatrix(const Eigen::Matrix< double, -1, 1, 0, 7, 1 > &residuals, const Eigen::Matrix< double, -1, -1, 0, 7, MAX_MATRIX_SIZE > &G, const FitParams &fitparams, const Eigen::Matrix< double, -1, -1, 0, 7, 7 > *V=0, double weight=1)
init the kalman machienery
Eigen::Matrix< double, -1, -1, 0, 7, 7 > m_Rinverse
R inverse.
KalmanCalculator(int sizeRes, int sizeState)
constructor
Eigen::Matrix< double, -1, -1, 0, 7, 7 > m_R
R residual covariance.
Eigen::Matrix< double, -1, -1, 0, 7, MAX_MATRIX_SIZE > m_G
G former H, transforms covraince of {residuals}<->{x,p,E}.
Eigen::Matrix< double, -1, 1, 0, 7, 1 > m_res
we know the max sizes of the matrices we assume the tree is smaller than MAX_MATRIX_SIZE parameters a...
void updateCovariance(FitParams &fitparams)
update the statevectors covariance
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, 7 > m_K
K kalman gain matrix.
int m_constrDim
dimension of the constraint
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, 7 > m_CGt
C times G^t