BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
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
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)
Definition: EvtValError.cc:130
EvtValError operator/(const EvtValError &x1, const EvtValError &x2)
Definition: EvtValError.cc:122
EvtValError accept_reject(InputIterator it, InputIterator end, Predicate pred)
Definition: EvtValError.hh:65
EvtValError operator*(const EvtValError &x1, const EvtValError &x2)
Definition: EvtValError.cc:115
int errorKnown() const
Definition: EvtValError.hh:32
void operator=(const EvtValError &other)
Definition: EvtValError.cc:44
double error() const
Definition: EvtValError.hh:33
void operator/=(const EvtValError &other)
Definition: EvtValError.cc:65
int valueKnown() const
Definition: EvtValError.hh:30
void operator+=(const EvtValError &other)
Definition: EvtValError.cc:90
void operator*=(const EvtValError &other)
Definition: EvtValError.cc:52
double prec() const
Definition: EvtValError.cc:38
double value() const
Definition: EvtValError.hh:31
void print(std::ostream &) const
Definition: EvtValError.cc:79