1 /*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
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
7 * Copyright (C) 2002 Caltech
8 *******************************************************************************/
10 // Value and its associated error. E.g. this could be interval size and
11 // the error associated with numerical integration.
13 #ifndef EVT_VAL_ERROR_HH
14 #define EVT_VAL_ERROR_HH
25 EvtValError(double val);
26 EvtValError(double val, double err);
27 EvtValError(const EvtValError& other);
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; }
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);
42 void print(std::ostream&) const;
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);
60 std::ostream& operator<<(std::ostream&, const EvtValError&);
62 // Perform an accept/reject fraction count
64 template <class InputIterator, class Predicate>
65 EvtValError accept_reject(InputIterator it, InputIterator end, Predicate pred)
72 if(pred(*it++)) itsPassed++;
75 return EvtValError(((double) itsPassed)/((double) itsTried),sqrt(itsPassed)/((double) itsTried));