BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesError.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: BesError.cxx,v 1.2 2009/12/23 02:59:56 zhangy Exp $
4//
5// Description:
6// Class BbrError
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author List:
12// Forest Rouse February 1996
13// Victoria Novotny August 1996
14//
15// Copyright Information:
16// Copyright (C) 1996 U.C. Davis
17//
18// History:
19// Migration for BESIII MDC
20//
21//------------------------------------------------------------------------
22// File BbrError.cc
23// Source file for class BesError
24//
25// For advice, input, or any questions then please contact either
26// Bob Jacobsen <Bob_Jacobsen@lbl.gov> or
27// Forest Rouse <rouse@ucdhep.ucdavis.edu>
28//
29// =====================================================================
30// Name Change description
31// Date
32// Version
33// =====================================================================
34// #include "BaBar/BaBar.hh"
35
36static const char rscid[] = "$Id: BesError.cxx,v 1.2 2009/12/23 02:59:56 zhangy Exp $";
37
38#include <assert.h>
39#include <ctype.h>
40#include <stdio.h>
41
42#include "CLHEP/Matrix/Matrix.h"
43#include "MdcRecoUtil/BesError.h"
44using std::istream;
45using std::ostream;
46
47const double BesError::chisqUndef = -1.;
48
49BesError BesError::similarity( const HepRotation& rot ) const {
50 HepMatrix mat( 3, 3 );
51 mat( 1, 1 ) = rot.xx();
52 mat( 1, 2 ) = rot.xy();
53 mat( 1, 3 ) = rot.xz();
54 mat( 2, 1 ) = rot.yx();
55 mat( 2, 2 ) = rot.yy();
56 mat( 2, 3 ) = rot.yz();
57 mat( 3, 1 ) = rot.zx();
58 mat( 3, 2 ) = rot.zy();
59 mat( 3, 3 ) = rot.zz();
60
61 HepSymMatrix w = similarity( mat );
62 return w;
63}
64
65BesError BesError::similarity( const HepLorentzRotation& rot ) const {
66 HepMatrix mat( 4, 4 );
67 mat( 1, 1 ) = rot.xx();
68 mat( 1, 2 ) = rot.xy();
69 mat( 1, 3 ) = rot.xz();
70 mat( 1, 4 ) = rot.xt();
71 mat( 2, 1 ) = rot.yx();
72 mat( 2, 2 ) = rot.yy();
73 mat( 2, 3 ) = rot.yz();
74 mat( 2, 4 ) = rot.yt();
75 mat( 3, 1 ) = rot.zx();
76 mat( 3, 2 ) = rot.zy();
77 mat( 3, 3 ) = rot.zz();
78 mat( 3, 4 ) = rot.zt();
79 mat( 4, 1 ) = rot.tx();
80 mat( 4, 2 ) = rot.ty();
81 mat( 4, 3 ) = rot.tz();
82 mat( 4, 4 ) = rot.tt();
83
84 HepSymMatrix w = similarity( mat );
85 return w;
86}
87
89 BesError mret( HepSymMatrix::similarity( E ) );
90 return mret;
91}
92
93BesError& BesError::similarityWith( const BesError& mat, const HepMatrix& m1 ) {
94 assert( num_row() == m1.num_row() );
95 HepMatrix temp = m1 * mat;
96 register double tmp;
97
98 for ( int r = 0; r < num_row(); r++ )
99 {
100 for ( int c = 0; c <= r; c++ )
101 {
102 tmp = 0.;
103 for ( int k = 0; k < m1.num_col(); k++ ) { tmp += temp[r][k] * m1[c][k]; }
104 ( *this )[r][c] = tmp;
105 }
106 }
107 return *this;
108}
109
110//----------------------------------------------------------------------
111// determineChisq
112// Compute v^T * V^(-1)*v - ie the chisq for this covariance
113// matrix and the difference vector v.
114//----------------------------------------------------------------------
115
116double BesError::determineChisq( const HepVector& diff ) const {
117 int ierr;
118 HepMatrix dMat( diff.num_row(), 1 );
119
120 for ( int i = 0; i < diff.num_row(); i++ ) dMat[i][0] = diff[i];
121
122 double chisq = ( inverse( ierr ).similarityT( dMat ) )[0][0];
123
124 if ( ierr == 0 ) return chisq;
125 else return chisqUndef;
126}
127
128ostream& operator<<( ostream& out, const BesError& mat ) {
129 out << "Bes Covariance Matrix:";
130 out << (HepSymMatrix&)mat;
131 return out;
132}
133
134istream& operator>>( istream& in, BesError& mat ) {
135 // Peek at the next non-space character:
136 char nextChar = ' ';
137 while ( isspace( nextChar ) ) { nextChar = in.get(); }
138 in.putback( nextChar );
139
140 if ( EOF != nextChar )
141 {
142 if ( !isdigit( nextChar ) )
143 {
144 // Remove the "Bes Covariance Matrix:" line:
145 const int DUMMY_SIZE = 1000;
146 char dummy[DUMMY_SIZE];
147 in.getline( dummy, DUMMY_SIZE );
148 }
149 // Read in the matrix:
150 for ( int row = 1; row <= mat.num_row(); ++row )
151 {
152 for ( int col = 1; col <= mat.num_col(); ++col ) { in >> mat( row, col ); }
153 }
154 }
155 return in;
156}
157
158BesError operator*( double t, const BesError& m1 ) {
159 BesError mret = m1;
160 mret *= t;
161 return mret;
162}
163
164BesError operator*( const BesError& m1, double t ) {
165 BesError mret = m1;
166 mret *= t;
167 return mret;
168}
169
170BesError operator/( double t, const BesError& m1 ) {
171 BesError mret = m1;
172 mret /= t;
173 return mret;
174}
175
176BesError operator/( const BesError& m1, double t ) {
177 BesError mret = m1;
178 mret /= t;
179 return mret;
180}
181
183 BesError mret = m1;
184 mret += m2;
185 return mret;
186}
187
189 BesError mret = m1;
190 mret -= m2;
191 return mret;
192}
ostream & operator<<(ostream &out, const BesError &mat)
Definition BesError.cxx:128
BesError operator-(const BesError &m1, const BesError &m2)
Definition BesError.cxx:188
BesError operator+(const BesError &m1, const BesError &m2)
Definition BesError.cxx:182
BesError operator*(double t, const BesError &m1)
Definition BesError.cxx:158
BesError operator/(double t, const BesError &m1)
Definition BesError.cxx:170
istream & operator>>(istream &in, BesError &mat)
Definition BesError.cxx:134
double w
BesError & similarityWith(const BesError &m, const HepMatrix &m1)
Definition BesError.cxx:93
BesError similarity(const HepRotation &rot) const
Definition BesError.cxx:49
double determineChisq(const HepVector &diff) const
Definition BesError.cxx:116
double double * m2
Definition qcdloop1.h:83
double * m1
Definition qcdloop1.h:83
int t()
Definition t.c:1