FairRoot/PandaRoot
RhoError.cxx
Go to the documentation of this file.
1 // //
3 // RhoError //
4 // //
5 // Error matrix class //
6 // //
7 // Author: Marcel Kunze, RUB, Nov. 99 //
8 // Copyright (C) 1999-2001, Ruhr-University Bochum. //
9 // Ralf Kliemt, HIM/GSI Feb.2013 (Cleanup & Restructuring) //
10 // //
12 
13 #include <stdio.h>
14 #include <assert.h>
15 
16 #include "RhoError.h"
17 
19 
20 #include <iostream>
21 using namespace std;
22 
23 const Double_t RhoError::chisqUndef = -1.;
24 
26 {
27  TMatrixD::Allocate ( n,n );
28  for ( int i1=0; i1<n; i1++ )
29  for ( int i2=0; i2<n; i2++ ) {
30  TMatrixD::operator() ( i1,i2 ) = init;
31  }
32 }
33 
35 TMatrixD(v)
36 {
37  TMatrixD::Allocate ( v.GetNrows(),v.GetNcols() );
38  TMatrixD::operator= ( v );
39 }
40 
42 {
43  TMatrixD::Allocate ( p.GetNrows(),p.GetNcols() );
44  TMatrixD::operator= ( p );
45 }
46 
48 {
49  TMatrixD::ResizeTo ( v );
50  TMatrixD::operator= ( v );
51  return *this;
52 }
53 
55 {
56  TMatrixD::ResizeTo ( v );
57  TMatrixD::operator= ( v );
58  return *this;
59 }
60 
62 {
63  return ( RhoError& ) TMatrixD::operator*= ( t );
64 }
65 /*
66 TError& TError::operator /= (Double_t t)
67 {return (TError&) TMatrixD::operator/=(t); }
68 
69 TError& TError::operator += (const TError& m2)
70 {
71 TMatrixD::operator+=(m2);
72 return *this;
73 }
74 
75 TError& TError::operator -= (const TError& m2)
76 {
77 TMatrixD::operator-=(m2);
78 return *this;
79 }
80 */
82 {
83  return *this;
84 }
85 // does nothing -- covariance Matrices have never negative entries on the
86 // main diagonal
87 
88 RhoError RhoError::Similarity ( const TRotation& rot ) const
89 {
90  TMatrixD mat ( 3,3 );
91  mat ( 0,0 ) =rot.XX();
92  mat ( 0,1 ) =rot.XY();
93  mat ( 0,2 ) =rot.XZ();
94  mat ( 1,0 ) =rot.YX();
95  mat ( 1,1 ) =rot.YY();
96  mat ( 1,2 ) =rot.YZ();
97  mat ( 2,0 ) =rot.ZX();
98  mat ( 2,1 ) =rot.ZY();
99  mat ( 2,2 ) =rot.ZZ();
100 
101  return Similarity ( mat );
102 }
103 
105 {
106  RhoError mret ( m1.GetNrows() );
107  mret.ResizeTo ( m1.GetNrows(),m1.GetNrows() );
108  mret.SimilarityWith ( *this, m1 );
109  return mret;
110 }
111 
112 RhoError RhoError::Similarity ( const TLorentzRotation& rot ) const
113 {
114  TMatrixD mat ( 4,4 );
115  mat ( 0,0 ) =rot.XX();
116  mat ( 0,1 ) =rot.XY();
117  mat ( 0,2 ) =rot.XZ();
118  mat ( 0,3 ) =rot.XT();
119  mat ( 1,0 ) =rot.YX();
120  mat ( 1,1 ) =rot.YY();
121  mat ( 1,2 ) =rot.YZ();
122  mat ( 1,3 ) =rot.YT();
123  mat ( 2,0 ) =rot.ZX();
124  mat ( 2,1 ) =rot.ZY();
125  mat ( 2,2 ) =rot.ZZ();
126  mat ( 2,3 ) =rot.ZT();
127  mat ( 3,0 ) =rot.TX();
128  mat ( 3,1 ) =rot.TY();
129  mat ( 3,2 ) =rot.TZ();
130  mat ( 3,3 ) =rot.TT();
131 
132  return Similarity ( mat );
133 }
134 /*
135 TError& TError::Similarity(const TError& E)
136 {
137  return Similarity(E);
138 }
139 */
141 {
142  assert ( GetNrows() == m1.GetNrows() );
143  TMatrixD temp;
144  temp.ResizeTo ( m1.GetNrows(),m1.GetNrows() );
145  temp.Mult ( m1,mat );
146  Double_t tmp;
147 
148  for ( int r = 0; r < GetNrows(); r++ ) {
149  for ( int c = 0; c <= r; c++ ) {
150  tmp = 0.;
151  for ( int k = 0; k < m1.GetNcols(); k++ ) {
152  tmp += temp ( r,k ) *m1 ( c,k );
153  }
154  ( *this ) ( r,c ) = tmp;
155  }
156  }
157  return *this;
158 }
159 
160 //----------------------------------------------------------------------
161 // determineChisq
162 // Compute v^T * V^(-1)*v - ie the chisq for this covariance
163 // matrix and the difference vector v.
164 //----------------------------------------------------------------------
165 
167 {
168  TMatrixD dMat ( diff.GetNrows(),diff.GetNrows() );
169  dMat.UnitMatrix();
170 
171  for ( int i = 0; i < diff.GetNrows(); i++ ) { dMat ( i,0 ) = diff ( i ); }
172 
173  Invert();
174  Double_t chisq = SimilarityT ( dMat ) ( 0,0 );
175 
176  return chisq;
177 }
178 
180 {
181  out << "Bbr Covariance Matrix:";
182  out << ( TMatrixD& ) mat;
183  return out;
184 }
185 
187 {
188  // Peek at the next non-space character:
189  char nextChar = ' ';
190  while ( isspace ( nextChar ) ) {
191  nextChar = in.get();
192  }
193  in.putback ( nextChar );
194 
195  if ( EOF != nextChar ) {
196  if ( !isdigit ( nextChar ) ) {
197  // Remove the "Bbr Covariance Matrix:" line:
198  const int DUMMY_SIZE = 1000;
199  char dummy[DUMMY_SIZE];
200  in.getline ( dummy, DUMMY_SIZE );
201  }
202  // Read in the matrix:
203  for ( int row = 1; row <= mat.GetNrows(); ++row ) {
204  for ( int col = 1; col <= mat.GetNcols(); ++col ) {
205  in >> mat ( row, col );
206  }
207  }
208  }
209  return in;
210 }
211 
212 
214 {
215  RhoError mret ( m1 );
216  //mret.ResizeTo ( m1 );
217  //mret = m1;
218  mret *= t;
219  return mret;
220 }
221 
223 {
224  RhoError mret ( m1 );
225  //mret.ResizeTo ( m1 );
226  //mret = m1;
227  mret *= t;
228  return mret;
229 }
230 /*
231 TError operator/(Double_t t, const TError& m1)
232 {
233 TError mret = m1;
234 mret /= t;
235 return mret;
236 }
237 
238 TError operator/(const TError& m1, Double_t t)
239 {
240 TError mret = m1;
241 mret /= t;
242 return mret;
243 }
244 */
245 RhoError operator+ ( const RhoError& m1, const RhoError& m2 )
246 {
247  RhoError mret ( m1 );
248  //mret.ResizeTo ( m1 );
249  //mret = m1;
250  mret += m2;
251  //std::cout<<" -- Adding two matrices: -- m1:"<<&m1<<" m2:"<<&m2<<std::endl;
252  return mret;
253 }
254 
255 RhoError operator- ( const RhoError& m1, const RhoError& m2 )
256 {
257  RhoError mret ( m1 );
258  //mret.ResizeTo ( m1 );
259  mret -= m2;
260  return mret;
261 }
262 
263 
265 {
266  Double_t mret = 0.0;
267  TVectorD temp ( m1 );
268  temp*= ( *this );
269  // If m1*(*this) has correct dimensions, then so will the m1.T multiplication.
270  // So there is no need to check dimensions again.
271  Double_t* a=&temp ( 0 );
272  Double_t* b=&m1 ( 0 );
273  Double_t* e=a+m1.GetNrows();
274  for ( ; a<e; ) { mret += ( * ( a++ ) ) * ( * ( b++ ) ); }
275  return mret;
276 }
277 
279 {
280  TMatrixD mret;
281  mret.ResizeTo ( m1 );
282  TMatrixD::Mult ( *this,m1 );
283  int n = m1.GetNcols();
284  Double_t* mrc = &mret ( 0,0 );
285  Double_t* temp1r = &TMatrixD::operator() ( 0,0 );
286  for ( int r=1; r<=mret.GetNrows(); r++ ) {
287  Double_t* m11c = &m1 ( 0,0 );
288  for ( int c=1; c<=r; c++ ) {
289  Double_t tmp = 0.0;
290  Double_t* tempir = temp1r;
291  Double_t* m1ic = m11c;
292  for ( int i=1; i<=m1.GetNrows(); i++ ) {
293  tmp+= ( * ( tempir ) ) * ( * ( m1ic ) );
294  tempir += n;
295  m1ic += n;
296  }
297  * ( mrc++ ) = tmp;
298  m11c++;
299  }
300  temp1r++;
301  }
302  return mret;
303 }
304 
305 
306 
307 
308 
309 
310 
int row
Definition: anaLmdDigi.C:67
RhoError operator-(const RhoError &m1, const RhoError &m2)
Definition: RhoError.cxx:255
Double_t p
Definition: anasim.C:58
RhoError & SimilarityWith(const RhoError &m, const TMatrixD &m1)
Definition: RhoError.cxx:140
Double_t DetermineChisq(TVectorD &diff)
Definition: RhoError.cxx:166
double r
Definition: RiemannTest.C:14
Int_t i
Definition: run_full.C:25
TTree * b
int col
Definition: anaLmdDigi.C:67
int n
std::ostream & operator<<(std::ostream &o, const PndEventInfo &a)
__m128 v
Definition: P4_F32vec4.h:4
static int init
Definition: ranlxd.cxx:374
static const Double_t chisqUndef
Definition: RhoError.h:39
RhoError operator+(const RhoError &m1, const RhoError &m2)
Definition: RhoError.cxx:245
friend void operator*=(F32vec1 &a, const F32vec1 &b)
RhoError & operator*=(Double_t t)
Definition: RhoError.cxx:61
TString m2(TString pts, TString exts="e px py pz")
Definition: invexp.C:117
Int_t a
Definition: anaLmdDigi.C:126
RhoError operator*(Double_t t, const RhoError &m1)
Definition: RhoError.cxx:213
Double_t
TMatrixD SimilarityT(TMatrixD &m1)
Definition: RhoError.cxx:278
RhoError(Int_t n, Double_t init=0.0)
Definition: RhoError.cxx:25
TFile * out
Definition: reco_muo.C:20
RhoError Similarity(const TMatrixD &m1) const
Definition: RhoError.cxx:104
TBuffer & operator>>(TBuffer &buf, PndAnaPidSelector *&obj)
ClassImp(PndAnaContFact)
TGeoRotation rot
TTree * t
Definition: bump_analys.C:13
RhoError & operator=(const RhoError &v)
Definition: RhoError.cxx:47
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52
RhoError & operator-()
Definition: RhoError.cxx:81