BOSS 8.0.0
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, 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 <assert.h>
17#include <iostream>
18#include <math.h>
19
21
22public:
24 EvtValError( double val );
25 EvtValError( double val, double err );
26 EvtValError( const EvtValError& other );
28
29 inline int valueKnown() const { return _valKnown; }
30 inline double value() const {
31 assert( _valKnown );
32 return _val;
33 }
34 inline int errorKnown() const { return _errKnown; }
35 inline double error() const {
36 assert( _errKnown );
37 return _err;
38 }
39
40 double prec() const;
41 void operator=( const EvtValError& other );
42 void operator*=( const EvtValError& other );
43 void operator/=( const EvtValError& other );
44 void operator+=( const EvtValError& other );
45 void operator*=( double c );
46
47 void print( std::ostream& ) const;
48
49private:
50 int _valKnown;
51 double _val;
52 int _errKnown;
53 double _err;
54};
55
56EvtValError operator*( const EvtValError& x1, const EvtValError& x2 );
57EvtValError operator/( const EvtValError& x1, const EvtValError& x2 );
58EvtValError operator+( const EvtValError& x1, const EvtValError& x2 );
59EvtValError operator*( const EvtValError& x, double c );
60EvtValError operator*( double c, const EvtValError& x );
61
62std::ostream& operator<<( std::ostream&, const EvtValError& );
63
64// Perform an accept/reject fraction count
65
66template <class InputIterator, class Predicate>
67EvtValError accept_reject( InputIterator it, InputIterator end, Predicate pred ) {
68 int itsTried = 0;
69 int itsPassed = 0;
70 while ( it != end )
71 {
72
73 itsTried++;
74 if ( pred( *it++ ) ) itsPassed++;
75 }
76
77 return EvtValError( ( (double)itsPassed ) / ( (double)itsTried ),
78 sqrt( itsPassed ) / ( (double)itsTried ) );
79}
80
81#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)
int errorKnown() const
void operator=(const EvtValError &other)
double error() const
void operator/=(const EvtValError &other)
int valueKnown() const
void operator+=(const EvtValError &other)
void operator*=(const EvtValError &other)
double prec() const
double value() const
void print(std::ostream &) const