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

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Project: BaBar detector at the SLAC PEP-II B-factory
00003  * Package: EvtGenBase
00004  *    File: $Id: EvtValError.hh,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
00005  *  Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
00006  *
00007  * Copyright (C) 2002 Caltech
00008  *******************************************************************************/
00009 
00010 // Value and its associated error. E.g. this could be interval size and 
00011 // the error associated with numerical integration.
00012 
00013 #ifndef EVT_VAL_ERROR_HH
00014 #define EVT_VAL_ERROR_HH
00015 
00016 #include <iostream>
00017 #include <assert.h>
00018 #include <math.h>
00019 
00020 class EvtValError {
00021 
00022 public:
00023 
00024   EvtValError();
00025   EvtValError(double val);
00026   EvtValError(double val, double err);
00027   EvtValError(const EvtValError& other);
00028   ~EvtValError();
00029 
00030   inline int valueKnown() const { return _valKnown; }
00031   inline double value() const { assert(_valKnown); return _val; }
00032   inline int errorKnown() const { return _errKnown; }
00033   inline double error() const { assert(_errKnown); return _err; }
00034 
00035   double prec() const;
00036   void operator=(const EvtValError& other);
00037   void operator*=(const EvtValError& other);
00038   void operator/=(const EvtValError& other);
00039   void operator+=(const EvtValError& other);
00040   void operator*=(double c);
00041 
00042   void print(std::ostream&) const;
00043 
00044 private:
00045 
00046   int    _valKnown;
00047   double _val;
00048   int    _errKnown;
00049   double _err;
00050 
00051 };
00052 
00053 
00054 EvtValError operator*(const EvtValError& x1, const EvtValError& x2);
00055 EvtValError operator/(const EvtValError& x1, const EvtValError& x2);
00056 EvtValError operator+(const EvtValError& x1, const EvtValError& x2);
00057 EvtValError operator*(const EvtValError& x,double c);
00058 EvtValError operator*(double c,const EvtValError& x);
00059 
00060 std::ostream& operator<<(std::ostream&, const EvtValError&);
00061 
00062 // Perform an accept/reject fraction count
00063 
00064 template <class InputIterator, class Predicate>
00065 EvtValError accept_reject(InputIterator it, InputIterator end, Predicate pred)
00066 {
00067   int itsTried = 0;
00068   int itsPassed = 0;
00069   while(it != end) {
00070     
00071     itsTried++;
00072     if(pred(*it++)) itsPassed++;
00073   }
00074 
00075   return EvtValError(((double) itsPassed)/((double) itsTried),sqrt(itsPassed)/((double) itsTried));
00076 }
00077 
00078 #endif

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