CGEM BOSS 6.6.5.f
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 <[email protected]> or
27// Forest Rouse <[email protected]>
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
39#include <stdio.h>
40#include <assert.h>
41#include <ctype.h>
42
43
44#include "MdcRecoUtil/BesError.h"
45#include "CLHEP/Matrix/Matrix.h"
46using std::istream;
47using std::ostream;
48
49const double BesError::chisqUndef = -1.;
50
51BesError BesError::similarity(const HepRotation& rot) const
52{
53 HepMatrix mat(3,3);
54 mat(1,1)=rot.xx(); mat(1,2)=rot.xy(); mat(1,3)=rot.xz();
55 mat(2,1)=rot.yx(); mat(2,2)=rot.yy(); mat(2,3)=rot.yz();
56 mat(3,1)=rot.zx(); mat(3,2)=rot.zy(); mat(3,3)=rot.zz();
57
58 HepSymMatrix w = similarity(mat);
59 return w;
60}
61
62
63BesError BesError::similarity(const HepLorentzRotation& rot) const
64{
65 HepMatrix mat(4,4);
66 mat(1,1)=rot.xx(); mat(1,2)=rot.xy(); mat(1,3)=rot.xz(); mat(1,4)=rot.xt();
67 mat(2,1)=rot.yx(); mat(2,2)=rot.yy(); mat(2,3)=rot.yz(); mat(2,4)=rot.yt();
68 mat(3,1)=rot.zx(); mat(3,2)=rot.zy(); mat(3,3)=rot.zz(); mat(3,4)=rot.zt();
69 mat(4,1)=rot.tx(); mat(4,2)=rot.ty(); mat(4,3)=rot.tz(); mat(4,4)=rot.tt();
70
71 HepSymMatrix w = similarity(mat);
72 return w;
73}
74
76{
77 BesError mret(HepSymMatrix::similarity(E));
78 return mret;
79}
80
82 const HepMatrix& m1)
83{
84 assert(num_row() == m1.num_row());
85 HepMatrix temp = m1*mat;
86 register double tmp;
87
88 for (int r = 0; r < num_row(); r++) {
89 for (int c = 0; c <= r; c++) {
90 tmp = 0.;
91 for (int k = 0; k < m1.num_col(); k++) {
92 tmp += temp[r][k]*m1[c][k];
93 }
94 (*this)[r][c] = tmp;
95 }
96 }
97 return *this;
98}
99
100
101
102
103//----------------------------------------------------------------------
104// determineChisq
105// Compute v^T * V^(-1)*v - ie the chisq for this covariance
106// matrix and the difference vector v.
107//----------------------------------------------------------------------
108
109double BesError::determineChisq(const HepVector& diff) const
110{
111 int ierr;
112 HepMatrix dMat(diff.num_row(), 1);
113
114 for (int i = 0; i < diff.num_row(); i++) dMat[i][0] = diff[i];
115
116 double chisq = (inverse(ierr).similarityT(dMat))[0][0];
117
118 if (ierr == 0) return chisq;
119 else return chisqUndef;
120}
121
122ostream& operator<<(ostream& out, const BesError& mat)
123{
124 out << "Bes Covariance Matrix:";
125 out << (HepSymMatrix&) mat;
126 return out;
127}
128
129istream& operator>>(istream& in, BesError& mat) {
130 // Peek at the next non-space character:
131 char nextChar = ' ';
132 while (isspace(nextChar)){
133 nextChar = in.get();
134 }
135 in.putback(nextChar);
136
137 if (EOF != nextChar){
138 if (!isdigit(nextChar)){
139 // Remove the "Bes Covariance Matrix:" line:
140 const int DUMMY_SIZE = 1000;
141 char dummy[DUMMY_SIZE];
142 in.getline(dummy, DUMMY_SIZE);
143 }
144 // Read in the matrix:
145 for (int row = 1; row <= mat.num_row(); ++row){
146 for (int col = 1; col <= mat.num_col(); ++col){
147 in >> mat(row, col);
148 }
149 }
150 }
151 return in;
152}
153
154
155BesError operator*(double t, const BesError& m1)
156 {
157 BesError mret = m1;
158 mret *= t;
159 return mret;
160 }
161
162BesError operator*(const BesError& m1, double t)
163 {
164 BesError mret = m1;
165 mret *= t;
166 return mret;
167 }
168
169BesError operator/(double t, const BesError& m1)
170 {
171 BesError mret = m1;
172 mret /= t;
173 return mret;
174 }
175
176BesError operator/(const BesError& m1, double t)
177 {
178 BesError mret = m1;
179 mret /= t;
180 return mret;
181 }
182
183BesError operator+(const BesError& m1, const BesError& m2)
184 {
185 BesError mret = m1;
186 mret += m2;
187 return mret;
188 }
189
190BesError operator-(const BesError& m1, const BesError& m2)
191 {
192 BesError mret = m1;
193 mret -= m2;
194 return mret;
195 }
196
197
198
199
200
201
202
203
204
ostream & operator<<(ostream &out, const BesError &mat)
Definition: BesError.cxx:122
BesError operator-(const BesError &m1, const BesError &m2)
Definition: BesError.cxx:190
BesError operator*(double t, const BesError &m1)
Definition: BesError.cxx:155
BesError operator/(double t, const BesError &m1)
Definition: BesError.cxx:169
istream & operator>>(istream &in, BesError &mat)
Definition: BesError.cxx:129
BesError & similarityWith(const BesError &m, const HepMatrix &m1)
Definition: BesError.cxx:81
BesError similarity(const HepRotation &rot) const
Definition: BesError.cxx:51
friend BesError operator+(const BesError &m1, const BesError &m2)
Definition: BesError.cxx:183
double determineChisq(const HepVector &diff) const
Definition: BesError.cxx:109
int t()
Definition: t.c:1