CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ErrorPropogationTypes.h
Go to the documentation of this file.
1 #ifndef ErrorPropogationTypes_h
2 #define ErrorPropogationTypes_h
3 
4 #include "boost/operators.hpp"
5 #include <cmath>
6 
7 class count_t :
8 boost::addable<count_t,
9 boost::incrementable<count_t,
10 boost::totally_ordered<count_t,
11 boost::equivalent<count_t> > > > {
12 
13  private:
14  unsigned long count;
15  public:
16  count_t() : count(0) {}
17  count_t(unsigned long n) : count(n) {}
18  bool operator<(const count_t& R) const { return count < R.count;}
19  count_t operator++() {++count; return *this;}
20  count_t operator+=(const count_t& R) {count += R.count; return *this;}
21  unsigned long operator()() const {return count;}
22  unsigned long error2() const {return count;}
23  double error() const {return sqrt(count);}
24  double relative_error() const {return 1/sqrt(count);}
25 };
26 
27 template <class charT, class traits>
28  inline
29  std::basic_ostream<charT,traits>& operator<<(std::basic_ostream<charT,traits>& strm, const count_t& f)
30 { strm << f() << "("<< f.error()<< ")"; return strm;}
31 
32 template<class T>
33 class stats_t :
34  boost::arithmetic1<stats_t<T>,
35  boost::arithmetic2<stats_t<T>, T,
36  boost::partially_ordered<stats_t<T>,
37  boost::partially_ordered<stats_t<T>,count_t,
38  boost::equality_comparable<stats_t<T>,
39  boost::equality_comparable<stats_t<T>,count_t> > > > > > {
40  private:
42  public:
43  stats_t() : value(0), err2(1) {}
44  stats_t(count_t c) : value(c()), err2(c.error2()) {}
45  stats_t(T q, T e2) : value(q), err2(e2) {}
46  static stats_t from_relative_uncertainty2(T q, T re2) { return stats_t(q,q*q*re2);}
47 
48  bool operator<(const stats_t& R) const { return value < R.value ;}
49  bool operator<(const count_t& R) const { return value < R() ;}
50  bool operator==(const stats_t& R) const { return value == R.value && err2 == R.err2;}
51  bool operator==(const count_t& R) const { return value == R() && err2 == R.error2();}
52 
53  stats_t operator+=(const stats_t& R) { value += R.value; err2 += R.err2; return *this;}
54  stats_t operator-=(const stats_t& R) { value -= R.value; err2 += R.err2; return *this;}
55  stats_t operator*=(const stats_t& R) { err2 = R.err2*value*value + err2*R.value*R.value; value *= R.value; return *this;}
56  stats_t operator/=(const stats_t& R) { value /= R.value; err2 = (err2 + value*value*R.err2) / (R.value*R.value); return *this;}
57 
58  stats_t operator+=(const T& r) { value += r; return *this;}
59  stats_t operator-=(const T& r) { value -= r; return *this;}
60  stats_t operator*=(const T& r) { value *= r; err2 *= r*r; return *this;}
61  stats_t operator/=(const T& r) { value /= r; err2 /= r*r; return *this;}
62 
63  stats_t inverse() const { return stats_t(1./value, err2/pow(value,4));}
64 
65  T operator()() const {return value;}
66  T error2() const {return err2;}
67  T error() const {return sqrt(err2);}
68  T relative_error() const {return sqrt(err2)/value;}
69  T sigmaFrom(const T& x) const {return fabs(value-x)/error();}
70 };
71 
72 template <class charT, class traits, class T> inline
73  std::basic_ostream<charT,traits>& operator<<(std::basic_ostream<charT,traits>& strm, const stats_t<T>& f)
74 { strm << f() << "("<< f.error()<< ")"; return strm; }
75 
76 #endif
count_t(unsigned long n)
double relative_error() const
bool operator<(const count_t &R) const
unsigned long operator()() const
stats_t inverse() const
T operator()() const
bool operator<(const count_t &R) const
unsigned long error2() const
stats_t(T q, T e2)
T error2() const
stats_t operator+=(const stats_t &R)
T relative_error() const
stats_t operator*=(const T &r)
stats_t operator+=(const T &r)
count_t operator++()
T sqrt(T t)
Definition: SSEVec.h:46
static stats_t from_relative_uncertainty2(T q, T re2)
T error() const
double f[11][100]
bool operator<(const stats_t &R) const
stats_t operator*=(const stats_t &R)
bool operator==(const count_t &R) const
stats_t(count_t c)
stats_t operator-=(const stats_t &R)
bool operator==(const stats_t &R) const
stats_t operator/=(const stats_t &R)
T sigmaFrom(const T &x) const
unsigned long count
double error() const
x
Definition: VDTMath.h:216
count_t operator+=(const count_t &R)
long double T
stats_t operator/=(const T &r)
stats_t operator-=(const T &r)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40