18 #include "CLHEP/Matrix/SymMatrix.h" 19 #include "CLHEP/Matrix/Matrix.h" 20 #include "CLHEP/Matrix/Vector.h" 36 #define NITER 1 // number of iterations 38 #define NLOOP 1000000 // number of time the test is repeted 64 std::cout <<
"************************************************\n";
65 std::cout <<
" SMatrix kalman test " << first <<
" x " << second << std::endl;
66 std::cout <<
"************************************************\n";
73 double x2sum = 0, c2sum = 0;
74 for (
int k = 0; k <
npass; k++) {
98 for(
int i = 0; i < second; i++)
102 std::cout <<
"pass " << k << std::endl;
104 std::cout <<
" K0 = " << K0 << std::endl;
105 std::cout <<
" H = " << K0 << std::endl;
106 std::cout <<
" Cp = " << Cp << std::endl;
107 std::cout <<
" V = " << V << std::endl;
108 std::cout <<
" m = " << m << std::endl;
109 std::cout <<
" xp = " << xp << std::endl;
115 double x2 = 0,
c2 = 0;
135 Rinv = V; Rinv += H * tmp;
137 bool test = Rinv.Invert();
139 std::cout<<
"inversion failed" <<std::endl;
140 std::cout << Rinv << std::endl;
148 x2 =
Dot(vtmp, Rinv*vtmp);
154 for (
int i=0; i<
NDIM2; ++i)
155 for (
int j=0; j<
NDIM2; ++j)
162 std::cerr <<
"SMatrix: x2sum = " << x2sum <<
"\tc2sum = " << c2sum << std::endl;
190 std::cout <<
"************************************************\n";
191 std::cout <<
" SMatrix_SyM kalman test " << first <<
" x " << second << std::endl;
192 std::cout <<
"************************************************\n";
199 double x2sum = 0, c2sum = 0;
200 for (
int k = 0; k <
npass; k++) {
224 for(
int i = 0; i < second; i++)
228 std::cout <<
"pass " << k << std::endl;
230 std::cout <<
" K0 = " << K0 << std::endl;
231 std::cout <<
" H = " << K0 << std::endl;
232 std::cout <<
" Cp = " << Cp << std::endl;
233 std::cout <<
" V = " << V << std::endl;
234 std::cout <<
" m = " << m << std::endl;
235 std::cout <<
" xp = " << xp << std::endl;
241 double x2 = 0,
c2 = 0;
245 MnSymMatrixNN RinvSym;
251 #define OPTIMIZED_SMATRIX_SYM 252 #ifdef OPTIMIZED_SMATRIX_SYM 260 #ifdef OPTIMIZED_SMATRIX_SYM 269 bool test = RinvSym.Invert();
271 std::cout<<
"inversion failed" <<std::endl;
272 std::cout << RinvSym << std::endl;
282 x2 =
Dot(vtmp, RinvSym*vtmp);
289 bool test = RinvSym.Invert();
291 std::cout<<
"inversion failed" <<std::endl;
292 std::cout << RinvSym << std::endl;
305 for (
int i=0; i<
NDIM2; ++i)
306 for (
int j=0; j<
NDIM2; ++j)
313 std::cerr <<
"SMatrixSym: x2sum = " << x2sum <<
"\tc2sum = " << c2sum << std::endl;
340 std::cout <<
"************************************************\n";
341 std::cout <<
" TMatrix Kalman test " << first <<
" x " << second << std::endl;
342 std::cout <<
"************************************************\n";
349 double x2sum = 0,c2sum = 0;
351 for (
int k = 0; k <
npass; k++)
354 MnMatrix
H(first,second);
355 MnMatrix K0(second,first);
356 MnMatrix Cp(second,second);
357 MnMatrix V(first,first);
370 MnMatrix
I(second,second);
371 for (
int i = 0; i < second; i++)
372 for(
int j = 0; j <second; j++) {
374 if (i==j)
I(i,i) = 1.0;
383 double x2 = 0,
c2 = 0;
393 #define OPTIMIZED_TMATRIX 394 #ifndef OPTIMIZED_TMATRIX 402 #ifdef OPTIMIZED_TMATRIX 403 tmp1 =
m;
Add(tmp1,-1.0,H,xp);
404 x = xp;
Add(x,+1.0,K0,tmp1);
420 Rinv = V; Rinv += H * tmp2;
431 for (
int i=0; i<
NDIM2; ++i)
432 for (
int j=0; j<
NDIM2; ++j)
440 std::cerr <<
"TMatrix: x2sum = " << x2sum <<
"\tc2sum = " << c2sum << std::endl;
449 int test_clhep_kalman() {
453 typedef HepSymMatrix MnSymMatrix;
454 typedef HepMatrix MnMatrix;
455 typedef HepVector MnVector;
466 std::cout <<
"************************************************\n";
467 std::cout <<
" CLHEP Kalman test " << first <<
" x " << second << std::endl;
468 std::cout <<
"************************************************\n";
474 double x2sum = 0,c2sum = 0;
476 for (
int k = 0; k <
npass; k++)
480 MnMatrix
H(first,second);
481 MnMatrix K0(second,first);
482 MnMatrix Cp(second,second);
483 MnMatrix V(first,first);
495 MnSymMatrix
I(second,1);
498 double x2 = 0,
c2 = 0;
500 MnMatrix Rinv(first,first);
501 MnSymMatrix RinvSym(first);
502 MnMatrix
K(second,first);
503 MnSymMatrix
C(second);
504 MnVector vtmp1(first);
505 MnMatrix tmp(second,first);
517 Rinv = V; Rinv += H * tmp;
518 RinvSym.assign(Rinv);
519 RinvSym.invert(ifail);
520 if (ifail !=0) { std::cout <<
"Error inverting Rinv" << std::endl;
break; }
524 C.assign( (I-K*H)*Cp );
525 x2= RinvSym.similarity(vtmp1);
526 if(ifail!=0) { std::cout <<
"Error inverting Rinv" << std::endl;
break; }
532 for (
int i=1; i<=
NDIM2; ++i)
533 for (
int j=1; j<=
NDIM2; ++j)
541 std::cerr <<
"x2sum = " << x2sum <<
"\tc2sum = " << c2sum << std::endl;
T Dot(const SVector< T, D > &lhs, const SVector< T, D > &rhs)
Vector dot product.
T Similarity(const SMatrix< T, D, D, R > &lhs, const SVector< T, D > &rhs)
Similarity Vector - Matrix Product: v^T * A * v returning a scalar value of type T ...
int test_tmatrix_kalman()
Random number generator class based on M.
void fillRandomSym(TRandom &r, M &m, unsigned int first, unsigned int start=0, double offset=1)
int test_smatrix_kalman()
TMatrixT< Element > & Transpose(const TMatrixT< Element > &source)
Transpose matrix source.
TMatrixTSym< Element > & Use(Int_t row_lwb, Int_t row_upb, Element *data)
virtual const Element * GetMatrixArray() const
Expr< TransposeOp< SMatrix< T, D1, D2, R >, T, D1, D2 >, T, D2, D1, typename TranspPolicy< T, D1, D2, R >::RepType > Transpose(const SMatrix< T, D1, D2, R > &rhs)
Matrix Transpose B(i,j) = A(j,i) returning a matrix expression.
void Minus(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
General matrix summation. Create a matrix C such that C = A - B.
static const double x2[5]
SMatrix: a generic fixed size D1 x D2 Matrix class.
void MultT(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
General matrix multiplication. Create a matrix C such that C = A * B^T.
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
RooCmdArg Timer(Bool_t flag=kTRUE)
int test_smatrix_sym_kalman()
R__EXTERN Int_t gMatrixCheck
static void Evaluate(SMatrix< T, D, D, MatRepSym< T, D > > &lhs, const Expr< A, T, D, D, R > &rhs)
assign a symmetric matrix from an expression
void fillRandomMat(TRandom &r, M &m, unsigned int first, unsigned int second, unsigned int start=0, double offset=1)
TMatrixTSym< Element > & InvertFast(Double_t *det=0)
Invert the matrix and calculate its determinant.
void fillRandomVec(TRandom &r, V &v, unsigned int len, unsigned int start=0, double offset=1)
TMatrixTSym< Element > & Similarity(const TMatrixT< Element > &n)
Calculate B * (*this) * B^T , final matrix will be (nrowsb x nrowsb) This is a similarity transform w...
void Plus(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
General matrix summation. Create a matrix C such that C = A + B.
SMatrix< T, D2, D2, MatRepSym< T, D2 > > SimilarityT(const SMatrix< T, D1, D2, R > &lhs, const SMatrix< T, D1, D1, MatRepSym< T, D1 > > &rhs)
Transpose Similarity Matrix Product : B = U^T * A * U for A symmetric returning a symmetric matrix ex...
void Mult(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
General matrix multiplication. Create a matrix C such that C = A * B.
SVector: a generic fixed size Vector class.