#include "Math/SVector.h" #include "Math/SMatrix.h" #include "TMatrixD.h" #include "TVectorD.h" #include "TRandom3.h" #include "matrix_util.h" #define TEST_SYM //#define HAVE_CLHEP #ifdef HAVE_CLHEP #include "CLHEP/Matrix/SymMatrix.h" #include "CLHEP/Matrix/Matrix.h" #include "CLHEP/Matrix/Vector.h" #endif // #include "SealUtil/SealTimer.h" // #include "SealUtil/SealHRRTChrono.h" // #include "SealUtil/TimingReport.h" #include #ifndef NDIM1 #define NDIM1 2 #endif #ifndef NDIM2 #define NDIM2 5 #endif #define NITER 1 // number of iterations #define NLOOP 1000000 // number of time the test is repeted using namespace ROOT::Math; #include "TestTimer.h" int test_smatrix_kalman() { // need to write explicitly the dimensions typedef SMatrix MnMatrixNN; typedef SMatrix MnMatrixMM; typedef SMatrix MnMatrixNM; typedef SMatrix MnMatrixMN; typedef SMatrix MnSymMatrixNN; typedef SMatrix MnSymMatrixMM; typedef SVector MnVectorN; typedef SVector MnVectorM; int first = NDIM1; //Can change the size of the matrices int second = NDIM2; std::cout << "************************************************\n"; std::cout << " SMatrix kalman test " << first << " x " << second << std::endl; std::cout << "************************************************\n"; int npass = NITER; TRandom3 r(111); double x2sum = 0, c2sum = 0; for (int k = 0; k < npass; k++) { MnMatrixNM H; MnMatrixMN K0; MnSymMatrixMM Cp; MnSymMatrixNN V; MnVectorN m; MnVectorM xp; { // fill matrices with random data fillRandomMat(r,H,first,second); fillRandomMat(r,K0,second,first); fillRandomSym(r,Cp,second); fillRandomSym(r,V,first); fillRandomVec(r,m,first); fillRandomVec(r,xp,second); } MnSymMatrixMM I; for(int i = 0; i < second; i++) I(i,i) = 1; #ifdef DEBUG std::cout << "pass " << k << std::endl; if (k == 0) { std::cout << " K0 = " << K0 << std::endl; std::cout << " H = " << K0 << std::endl; std::cout << " Cp = " << Cp << std::endl; std::cout << " V = " << V << std::endl; std::cout << " m = " << m << std::endl; std::cout << " xp = " << xp << std::endl; } #endif { double x2 = 0,c2 = 0; test::Timer t("SMatrix Kalman "); MnVectorM x; MnMatrixMN tmp; MnSymMatrixNN Rinv; MnMatrixMN K; MnSymMatrixMM C; MnVectorN vtmp1; MnVectorN vtmp; for (int l = 0; l < NLOOP; l++) { vtmp1 = H*xp -m; //x = xp + K0 * (m- H * xp); x = xp - K0 * vtmp1; tmp = Cp * Transpose(H); Rinv = V; Rinv += H * tmp; bool test = Rinv.Invert(); if(!test) { std::cout<<"inversion failed" <