CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GsfMatrixTools.h
Go to the documentation of this file.
1 #ifndef GsfMatrixTools_h_
2 #define GsfMatrixTools_h_
3 
4 #include "Math/SVector.h"
5 #include "Math/SMatrix.h"
6 
7 namespace GsfMatrixTools {
8 
9 // template <unsigned int N>
10 // double similarity (ROOT::Math::SMatrix<double, N, N, ROOT::Math::MatRepSym<double, N> >,
11 // ROOT::Math::SVector<double, N> vector) {
12 // return vector*matrix*vector;
13 // }
14 
15  template <unsigned int N>
16  double trace (const ROOT::Math::SMatrix<double, N, N>& matrix) {
17  double result(0.);
18  for ( unsigned int i=0; i<N; i++ ) result += matrix(i,i);
19  return result;
20  }
21 
22 
23  /* compute the trace of a product of two sym matrices
24  * a(i,j)*b(j,i) = a(i,j)*b(i,j) sum over i and j
25  */
26  template<typename T, unsigned int N>
27  double trace(ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > const & a,
28  ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > const & b) {
29  typedef typename ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> >::const_iterator CI;
30  CI i1 = a.begin();
31  CI e1 = a.end();
32  CI i2 = b.begin();
33  // CI e2 = b.end();
34 
35  T res =0;
36  // sum of the lower triangle;
37  for (;i1!=e1; i1++, i2++)
38  res += (*i1)*(*i2);
39  res *=2.;
40  // remove the duplicated diagonal...
41  for (unsigned int i=0;i<N;i++)
42  res -= a(i,i)*b(i,i);
43  return res;
44  }
45 
46 }
47 #endif
48 
int i
Definition: DBlmapReader.cc:9
tuple result
Definition: query.py:137
double trace(const ROOT::Math::SMatrix< double, N, N > &matrix)
#define N
Definition: blowfish.cc:9
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
long double T