BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
BesEvtGen-00-04-08/src/EvtGen/EvtGenBase/EvtValError.hh
Go to the documentation of this file.
1/*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
3 * Package: EvtGenBase
4 * File: $Id: EvtValError.hh,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
5 * Author: Alexei Dvoretskii, [email protected], 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
20class EvtValError {
21
22public:
23
25 EvtValError(double val);
26 EvtValError(double val, double err);
27 EvtValError(const EvtValError& other);
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
44private:
45
46 int _valKnown;
47 double _val;
48 int _errKnown;
49 double _err;
50
51};
52
53
54EvtValError operator*(const EvtValError& x1, const EvtValError& x2);
55EvtValError operator/(const EvtValError& x1, const EvtValError& x2);
56EvtValError operator+(const EvtValError& x1, const EvtValError& x2);
57EvtValError operator*(const EvtValError& x,double c);
58EvtValError operator*(double c,const EvtValError& x);
59
60std::ostream& operator<<(std::ostream&, const EvtValError&);
61
62// Perform an accept/reject fraction count
63
64template <class InputIterator, class Predicate>
65EvtValError 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
std::ostream & operator<<(std::ostream &, const EvtValError &)
EvtValError operator+(const EvtValError &x1, const EvtValError &x2)
EvtValError operator/(const EvtValError &x1, const EvtValError &x2)
EvtValError accept_reject(InputIterator it, InputIterator end, Predicate pred)
EvtValError operator*(const EvtValError &x1, const EvtValError &x2)
void operator=(const EvtValError &other)
EvtValError(double val)
EvtValError(double val, double err)
void operator*=(double c)
void operator/=(const EvtValError &other)
void operator+=(const EvtValError &other)
void operator*=(const EvtValError &other)
double prec() const
void print(std::ostream &) const
EvtValError(const EvtValError &other)