10#include <analysis/VertexFitting/TreeFitter/KalmanCalculator.h>
11#include <analysis/VertexFitting/TreeFitter/FitParams.h>
22 m_G(sizeRes, sizeState),
23 m_R(sizeRes, sizeRes),
25 m_K(sizeState, sizeRes),
26 m_CGt(sizeState, sizeRes)
33 const Eigen::Matrix < double, -1, 1, 0, 7, 1 > & residuals,
34 const Eigen::Matrix < double, -1, -1, 0, 7, MAX_MATRIX_SIZE > & G,
36 const Eigen::Matrix < double, -1, -1, 0, 7, 7 > * V,
42 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > C = fitparams.
getCovariance().triangularView<Eigen::Lower>();
44 m_CGt = C.selfadjointView<Eigen::Lower>() * G.transpose();
45 Eigen::Matrix < double, -1, -1, 0, 7, 7 > Rtemp = G *
m_CGt;
46 if (V && (weight) && ((*V).diagonal().array() != 0).all()) {
48 const Eigen::Matrix < double, -1, -1, 0, 7, 7 > weightedV =
49 weight * (*V).selfadjointView<Eigen::Lower>();
51 m_R = Rtemp + weightedV;
54 m_R = Rtemp.triangularView<Eigen::Lower>();
57 Eigen::Matrix < double, -1, -1, 0, 7, 7 > RInvtemp;
58 RInvtemp =
m_R.selfadjointView<Eigen::Lower>();
63 return ErrCode(ErrCode::Status::success);
68 double eps = Eigen::NumTraits<double>::epsilon();
76 double eps = Eigen::NumTraits<double>::epsilon();
77 Eigen::Matrix < double, -1, 1, 0, 7, 1 > res_prime =
83 m_chisq = res_prime.transpose() *
m_Rinverse.selfadjointView<Eigen::Lower>() * res_prime;
86 TREEFITTER_NO_STACK_WARNING
90 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > fitCov =
93 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > GRinvGt =
97 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > deltaCov =
98 fitCov.selfadjointView<Eigen::Lower>() * GRinvGt * fitCov.selfadjointView<Eigen::Lower>();
100 double eps = Eigen::NumTraits<double>::epsilon();
101 Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > delta =
102 (fitCov.array() - deltaCov.array()).matrix() + eps * Eigen::MatrixXd::Identity(fitCov.rows(), fitCov.cols());
104 fitparams.
getCovariance().triangularView<Eigen::Lower>() = delta.triangularView<Eigen::Lower>();
108 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.