00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
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