]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TEvtGen/EvtGenBase/EvtValError.hh
New plots for trending injector efficiencies (Melinda)
[u/mrichter/AliRoot.git] / TEvtGen / EvtGenBase / EvtValError.hh
1 /*******************************************************************************
2  * Project: BaBar detector at the SLAC PEP-II B-factory
3  * Package: EvtGenBase
4  *    File: $Id: EvtValError.hh,v 1.6 2004/08/06 06:08:26 bartoldu Exp $
5  *  Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
6  *
7  * Copyright (C) 2002 Caltech
8  *******************************************************************************/
9
10 // Value and its associated error. E.g. this could be interval size and 
11 // the error associated with numerical integration.
12
13 #ifndef EVT_VAL_ERROR_HH
14 #define EVT_VAL_ERROR_HH
15
16 #include <iostream>
17 #include <assert.h>
18 #include <math.h>
19
20 class EvtValError {
21
22 public:
23
24   EvtValError();
25   EvtValError(double val);
26   EvtValError(double val, double err);
27   EvtValError(const EvtValError& other);
28   ~EvtValError();
29
30   inline int valueKnown() const { return _valKnown; }
31   inline double value() const { assert(_valKnown); return _val; }
32   inline int errorKnown() const { return _errKnown; }
33   inline double error() const { assert(_errKnown); return _err; }
34
35   double prec() const;
36   void operator=(const EvtValError& other);
37   void operator*=(const EvtValError& other);
38   void operator/=(const EvtValError& other);
39   void operator+=(const EvtValError& other);
40   void operator*=(double c);
41
42   void print(std::ostream&) const;
43
44 private:
45
46   int    _valKnown;
47   double _val;
48   int    _errKnown;
49   double _err;
50
51 };
52
53
54 EvtValError operator*(const EvtValError& x1, const EvtValError& x2);
55 EvtValError operator/(const EvtValError& x1, const EvtValError& x2);
56 EvtValError operator+(const EvtValError& x1, const EvtValError& x2);
57 EvtValError operator*(const EvtValError& x,double c);
58 EvtValError operator*(double c,const EvtValError& x);
59
60 std::ostream& operator<<(std::ostream&, const EvtValError&);
61
62 // Perform an accept/reject fraction count
63
64 template <class InputIterator, class Predicate>
65 EvtValError accept_reject(InputIterator it, InputIterator end, Predicate pred)
66 {
67   int itsTried = 0;
68   int itsPassed = 0;
69   while(it != end) {
70     
71     itsTried++;
72     if(pred(*it++)) itsPassed++;
73   }
74
75   return EvtValError(((double) itsPassed)/((double) itsTried),sqrt(itsPassed)/((double) itsTried));
76 }
77
78 #endif