/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/MdcRecoUtil/MdcRecoUtil-00-01-08/src/BesError.cxx

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: BesError.cxx,v 1.2 2009/12/23 02:59:56 zhangy Exp $
00004 //
00005 // Description:
00006 //      Class BbrError
00007 //
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Author List:
00012 //      Forest Rouse            February 1996
00013 //      Victoria Novotny        August   1996
00014 //
00015 // Copyright Information:
00016 //      Copyright (C) 1996      U.C. Davis 
00017 // 
00018 // History:
00019 //      Migration for BESIII MDC
00020 //
00021 //------------------------------------------------------------------------
00022 // File BbrError.cc
00023 // Source file for class BesError
00024 //
00025 // For advice, input, or any questions then please contact either
00026 // Bob Jacobsen <Bob_Jacobsen@lbl.gov> or
00027 // Forest Rouse <rouse@ucdhep.ucdavis.edu>
00028 //
00029 // =====================================================================
00030 // Name           Change description
00031 // Date
00032 // Version
00033 // =====================================================================
00034 //#include "BaBar/BaBar.hh"
00035 
00036 static const char rscid[] = "$Id: BesError.cxx,v 1.2 2009/12/23 02:59:56 zhangy Exp $";
00037 
00038 
00039 #include <stdio.h>
00040 #include <assert.h>
00041 #include <ctype.h>
00042 
00043 
00044 #include "MdcRecoUtil/BesError.h"
00045 #include "CLHEP/Matrix/Matrix.h"
00046 using std::istream;
00047 using std::ostream;
00048 
00049 const double BesError::chisqUndef = -1.;
00050 
00051 BesError BesError::similarity(const HepRotation& rot) const
00052 {
00053   HepMatrix mat(3,3); 
00054   mat(1,1)=rot.xx(); mat(1,2)=rot.xy(); mat(1,3)=rot.xz();
00055   mat(2,1)=rot.yx(); mat(2,2)=rot.yy(); mat(2,3)=rot.yz();
00056   mat(3,1)=rot.zx(); mat(3,2)=rot.zy(); mat(3,3)=rot.zz();
00057 
00058   HepSymMatrix w = similarity(mat);
00059   return w;
00060 }
00061 
00062 
00063 BesError BesError::similarity(const HepLorentzRotation& rot) const
00064 {
00065   HepMatrix mat(4,4); 
00066   mat(1,1)=rot.xx(); mat(1,2)=rot.xy(); mat(1,3)=rot.xz(); mat(1,4)=rot.xt();
00067   mat(2,1)=rot.yx(); mat(2,2)=rot.yy(); mat(2,3)=rot.yz(); mat(2,4)=rot.yt();
00068   mat(3,1)=rot.zx(); mat(3,2)=rot.zy(); mat(3,3)=rot.zz(); mat(3,4)=rot.zt();
00069   mat(4,1)=rot.tx(); mat(4,2)=rot.ty(); mat(4,3)=rot.tz(); mat(4,4)=rot.tt();
00070 
00071   HepSymMatrix w = similarity(mat);
00072   return w;
00073 }
00074 
00075 BesError BesError::similarity(const BesError& E)
00076 {
00077   BesError mret(HepSymMatrix::similarity(E));
00078   return mret;
00079 }
00080 
00081 BesError& BesError::similarityWith(const BesError& mat,
00082                                            const HepMatrix& m1)
00083 {
00084   assert(num_row() == m1.num_row());
00085   HepMatrix temp = m1*mat;
00086   register double tmp;
00087 
00088   for (int r = 0; r < num_row(); r++) {
00089     for (int c = 0; c <= r; c++) {
00090       tmp = 0.;
00091       for (int k = 0; k < m1.num_col(); k++) {
00092         tmp += temp[r][k]*m1[c][k];
00093       }
00094       (*this)[r][c] = tmp;
00095     }
00096   }
00097   return *this;
00098 }
00099 
00100 
00101 
00102 
00103 //----------------------------------------------------------------------
00104 // determineChisq
00105 //      Compute v^T * V^(-1)*v - ie the chisq for this covariance
00106 //      matrix and the difference vector v.
00107 //----------------------------------------------------------------------
00108 
00109 double BesError::determineChisq(const HepVector& diff) const 
00110 {
00111   int ierr;
00112   HepMatrix dMat(diff.num_row(), 1);
00113 
00114   for (int i = 0; i < diff.num_row(); i++) dMat[i][0] = diff[i];
00115   
00116   double chisq = (inverse(ierr).similarityT(dMat))[0][0];
00117 
00118   if (ierr == 0) return chisq;
00119   else           return chisqUndef;
00120 }
00121 
00122 ostream& operator<<(ostream& out, const BesError& mat)
00123 {
00124     out << "Bes Covariance Matrix:";
00125     out << (HepSymMatrix&) mat;
00126     return out;
00127 }
00128 
00129 istream& operator>>(istream& in, BesError& mat) {
00130   // Peek at the next non-space character:
00131   char nextChar = ' ';
00132   while (isspace(nextChar)){
00133     nextChar = in.get();
00134   }
00135   in.putback(nextChar);
00136 
00137   if (EOF != nextChar){
00138     if (!isdigit(nextChar)){
00139       // Remove the "Bes Covariance Matrix:" line:
00140       const int DUMMY_SIZE = 1000;
00141       char dummy[DUMMY_SIZE];
00142       in.getline(dummy, DUMMY_SIZE);
00143     }
00144     // Read in the matrix:
00145     for (int row = 1; row <= mat.num_row(); ++row){
00146       for (int col = 1; col <= mat.num_col(); ++col){
00147         in >> mat(row, col);
00148       }
00149     }
00150   }
00151   return in;
00152 }
00153 
00154 
00155 BesError operator*(double t, const BesError& m1)
00156   {
00157     BesError mret = m1;
00158     mret *= t;
00159     return mret;
00160   }
00161 
00162 BesError operator*(const BesError& m1, double t)
00163   {
00164     BesError mret = m1;
00165     mret *= t;
00166     return mret;
00167   }
00168 
00169 BesError operator/(double t, const BesError& m1)
00170   {
00171     BesError mret = m1;
00172     mret /= t;
00173     return mret;
00174   }
00175 
00176 BesError operator/(const BesError& m1, double t)
00177   {
00178     BesError mret = m1;
00179     mret /= t;
00180     return mret;
00181   }
00182 
00183 BesError operator+(const BesError& m1, const BesError& m2)
00184   {
00185     BesError mret = m1;
00186     mret += m2;
00187     return mret;
00188   }
00189 
00190 BesError operator-(const BesError& m1, const BesError& m2)
00191   {
00192     BesError mret = m1;
00193     mret -= m2;
00194     return mret;
00195   }
00196   
00197  
00198 
00199 
00200 
00201 
00202 
00203 
00204 

Generated on Tue Nov 29 23:13:32 2016 for BOSS_7.0.2 by  doxygen 1.4.7