/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Generator/BesEvtGen/BesEvtGen-00-03-58/src/EvtGen/EvtGenBase/EvtValError.cc

Go to the documentation of this file.
00001 #include "EvtGenBase/EvtPatches.hh"
00002 /*******************************************************************************
00003  * Project: BaBar detector at the SLAC PEP-II B-factory
00004  * Package: EvtGenBase
00005  *    File: $Id: EvtValError.cc,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
00006  *  Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
00007  *
00008  * Copyright (C) 2002 Caltech
00009  *******************************************************************************/
00010 
00011 #include <assert.h>
00012 #include <math.h>
00013 #include <iostream>
00014 #include "EvtGenBase/EvtValError.hh"
00015 using std::endl;
00016 using std::ostream;
00017 
00018 EvtValError::EvtValError() 
00019   : _valKnown(0), _val(0.), _errKnown(0), _err(0.)
00020 {}
00021 
00022 EvtValError::EvtValError(double val)
00023   : _valKnown(1), _val(val), _errKnown(0), _err(0.)
00024 {}
00025 
00026 EvtValError::EvtValError(double val, double err)
00027   : _valKnown(1), _val(val), _errKnown(1), _err(err)
00028 {}
00029   
00030 EvtValError::EvtValError(const EvtValError& other) 
00031   : _valKnown(other._valKnown), _val(other._val), 
00032   _errKnown(other._errKnown), _err(other._err)
00033 {}
00034 
00035 EvtValError::~EvtValError()
00036 {}
00037 
00038 double EvtValError::prec() const 
00039 { 
00040   assert(_valKnown && _errKnown); 
00041   return ( _val != 0) ? _err/_val : 0; 
00042 }
00043 
00044 void EvtValError::operator=(const EvtValError& other)
00045 {
00046   _valKnown = other._valKnown;
00047   _val = other._val;
00048   _errKnown = other._errKnown;
00049   _err = other._err;
00050 }
00051 
00052 void EvtValError::operator*=(const EvtValError& other)
00053 {
00054   assert(_valKnown && other._valKnown);
00055 
00056   // Relative errors add in quadrature
00057   if(_errKnown && other._errKnown)
00058     _err = _val * other._val * sqrt(prec()*prec() + other.prec() * other.prec());
00059   else _errKnown = 0;
00060   
00061   // Modify the value  
00062   _val *= other._val;
00063 }
00064 
00065 void EvtValError::operator/=(const EvtValError& other)
00066 {
00067   assert(_valKnown && other._valKnown && other._val != 0.);
00068 
00069   // Relative errors add in quadrature
00070   if(_errKnown && other._errKnown)
00071     _err = _val/other._val * sqrt(prec()*prec() + other.prec() * other.prec());
00072   else _errKnown = 0;
00073   
00074   // Modify the value  
00075   _val /= other._val;
00076 }
00077 
00078 
00079 void EvtValError::print(ostream& os) const
00080 {
00081   if(_valKnown) os << _val;
00082   else os << "Undef";
00083   os << " +/- ";
00084   if(_errKnown) os << _err;
00085   else os << "Undef";
00086   os << endl;
00087 }
00088 
00089 
00090 void EvtValError::operator+=(const EvtValError& other)
00091 {
00092   assert(_valKnown); assert(other._valKnown);
00093   _val += other._val;
00094   
00095     // add errors in quadrature
00096   
00097   if(_errKnown && other._errKnown) {
00098 
00099     _err = sqrt(_err*_err + other._err*other._err);
00100   }
00101   else {
00102     
00103       _errKnown = 0;
00104   }
00105 }
00106 
00107 void EvtValError::operator*=(double c) {
00108   
00109   assert(_valKnown);
00110   _val *= c;
00111   if(_errKnown) _err*=c;
00112 }
00113 
00114 
00115 EvtValError operator*(const EvtValError& x1, const EvtValError& x2)
00116 {
00117   EvtValError ret(x1);
00118   ret *= x2;
00119   return ret;
00120 }
00121 
00122 EvtValError operator/(const EvtValError& x1, const EvtValError& x2)
00123 {
00124   EvtValError ret(x1);
00125   ret /= x2;
00126   return ret;
00127 }
00128 
00129 
00130 EvtValError operator+(const EvtValError& x1, const EvtValError& x2)
00131 {
00132   EvtValError ret(x1);
00133   ret += x2;
00134   return ret;
00135 }
00136 
00137 
00138 EvtValError operator*(const EvtValError& x,double c) 
00139 {
00140   EvtValError ret(x);
00141   ret*=c;
00142   return ret;
00143 }
00144 
00145 
00146 EvtValError operator*(double c,const EvtValError& x) 
00147 {
00148   EvtValError ret(x);
00149   ret*=c;
00150   return ret;
00151 }
00152 
00153 
00154 ostream& operator<<(ostream& os, const EvtValError& other)
00155 {
00156   other.print(os);
00157   return os;
00158 }
00159 
00160 

Generated on Tue Nov 29 23:12:16 2016 for BOSS_7.0.2 by  doxygen 1.4.7