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

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: DifNumber.cxx,v 1.3 2010/03/25 09:55:57 zhangy Exp $
00004 //
00005 // Description:
00006 //      Class Implementation for |DifNumber| 
00007 //      What do i do ?
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Author List:
00012 //      A. Snyder
00013 //
00014 // Copyright Information:
00015 //      Copyright (C) 1996      SLAC
00016 // 
00017 // History:
00018 //      Migration for BESIII MDC
00019 //
00020 //------------------------------------------------------------------------
00021 
00022 #include "MdcRecoUtil/DifNumber.h"
00023 #include "MdcRecoUtil/DifIndepPar.h"
00024 using std::endl;
00025 //CHANGE using std::ostream;
00026 using std::cout;
00027 
00028 extern const DifNumber zero(0.0);
00029 extern const DifNumber one(1.0);
00030 
00031 
00032 double DifNumber::error(const HepSymMatrix& e)const {
00033   return sqrt(correlation(*this,e));
00034 }
00035 
00036 double DifNumber::error()const{
00037   if(indepPar()==0) {return 0.0;}
00038   return error(indepPar()->covariance());
00039 }
00040 
00041 void DifNumber::fetchDerivatives(HepVector& v)const {
00042   assert(v.num_row()==nPar());
00043   for(int i=1; i<=nPar(); i++) {v(i)=derivative(i);}
00044 }
00045 
00046 HepVector DifNumber::derivatives()const{
00047     HepVector temp(nPar());
00048     fetchDerivatives(temp);
00049     return temp;
00050 }
00051 
00052 double 
00053 DifNumber::correlation(const DifNumber& b,const HepSymMatrix &e) const {
00054   assert(e.num_col()==nPar());
00055   assert(e.num_row()==b.nPar());
00056   double error = 0.;
00057   for(int i=1; i<=nPar(); i++) {
00058     for(int j=1; j<=b.nPar(); j++) {
00059       error+=derivative(i)*e(i,j)*b.derivative(j);
00060     }
00061   }
00062   return error;
00063 }
00064 
00065 double
00066 DifNumber::correlation(const DifNumber& b)const {
00067   if(indepPar()==0) return 0.0;
00068   if(b.indepPar()!=indepPar()) return 0.0;
00069   return correlation(b,indepPar()->covariance());
00070 }
00071 
00072 double correlation(const DifNumber& a,const DifNumber& b) // correlation from default matrix
00073 { 
00074   return (a.indepPar()==0||b.indepPar()==0||a.indepPar()!=b.indepPar())?0:a.correlation(b,a.indepPar()->covariance()); 
00075 }
00076 
00077 // FIXME: This function should be inlined, but that would require checking out additional packages...
00078 double correlation(const DifNumber& a,const DifNumber& b,const HepSymMatrix& e) // correlation for specified error
00079 { return a.correlation(b,e); }
00080 
00081 void DifNumber::print(/*ostream& o*/)const {
00082   cout << "number:" << number() << endl;
00083   cout << "npar:" << nPar() << endl;
00084   for(int i=1; i<=nPar(); i++) {
00085     cout << "derivative(" << i << "):" << derivative(i) << endl;
00086   }
00087 }
00088 
00089  
00090 extern DifNumber solveQuad
00091 (const DifNumber& a,            // quadratic term
00092  const DifNumber& b,            // linear term
00093  const DifNumber& c,            // const term
00094  int pref,                      // solution preference
00095  Code& code)                    // error code
00096 {
00097   DifNumber descr=b*b-4.0*a*c;
00098   if(descr<0.0) {               // solution not real
00099     code.setFail(1341);
00100     return DifNumber(0.0);
00101   }
00102   if(a.number()==0.0){
00103     if(b.number()==0.0) {
00104       code.setFail(1342);
00105       return DifNumber(0.0);
00106     }
00107     code.setSuccess(40);
00108     return -c/b+a*c/pow(b,3);
00109   }
00110   code.setSuccess(40);
00111   descr=sqrt(descr);
00112   DifNumber s=-b;
00113 
00114   if(pref==+1) {                // positive solution
00115     s+=descr;
00116   }else if(pref==-1){           // negative solution
00117     s-=descr;
00118   }else if(pref==0) {           // smallest solution
00119     if(s>0.0) {s-=descr;}else {s+=descr;}
00120   }else {                       // illegal prefrence
00121     code.setFail(1343);
00122     return DifNumber(0.0);
00123   }
00124   s/=2.0*a;
00125   return s;
00126 }
00127 

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