CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/TrackingTools/GsfTools/interface/GsfMatrixTools.h

Go to the documentation of this file.
00001 #ifndef GsfMatrixTools_h_
00002 #define GsfMatrixTools_h_
00003 
00004 #include "Math/SVector.h"
00005 #include "Math/SMatrix.h"
00006 
00007 namespace GsfMatrixTools {
00008   
00009 //   template <unsigned int N>
00010 //   double similarity (ROOT::Math::SMatrix<double, N, N, ROOT::Math::MatRepSym<double, N> >,
00011 //                   ROOT::Math::SVector<double, N> vector) {
00012 //     return vector*matrix*vector;
00013 //   }
00014 
00015   template <unsigned int N>
00016   double trace (const ROOT::Math::SMatrix<double, N, N>& matrix) {
00017     double result(0.);
00018     for ( unsigned int i=0; i<N; i++ )  result += matrix(i,i);
00019     return result;
00020   }
00021 
00022 
00023   /* compute the trace of a product of two sym matrices
00024    *   a(i,j)*b(j,i) = a(i,j)*b(i,j) sum over i and j
00025    */
00026   template<typename T, unsigned int N>
00027   double trace(ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > const & a,
00028                ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > const & b) {
00029     typedef typename ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> >::const_iterator CI;
00030     CI i1 = a.begin();
00031     CI e1 = a.end();
00032     CI i2 = b.begin();
00033     //  CI e2 = b.end();
00034   
00035     T res =0;
00036     // sum of the lower triangle;
00037     for (;i1!=e1; i1++, i2++)
00038       res += (*i1)*(*i2);
00039     res *=2.;
00040     // remove the duplicated diagonal...
00041     for (unsigned int i=0;i<N;i++)
00042       res -= a(i,i)*b(i,i);
00043   return res;
00044   }
00045   
00046 }
00047 #endif
00048