EvtGen 2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Loading...
Searching...
No Matches
EvtValError.hh
Go to the documentation of this file.
1
2/***********************************************************************
3* Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4* *
5* This file is part of EvtGen. *
6* *
7* EvtGen is free software: you can redistribute it and/or modify *
8* it under the terms of the GNU General Public License as published by *
9* the Free Software Foundation, either version 3 of the License, or *
10* (at your option) any later version. *
11* *
12* EvtGen is distributed in the hope that it will be useful, *
13* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15* GNU General Public License for more details. *
16* *
17* You should have received a copy of the GNU General Public License *
18* along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19***********************************************************************/
20
21#ifndef EVT_VAL_ERROR_HH
22#define EVT_VAL_ERROR_HH
23
24#include <assert.h>
25#include <iostream>
26#include <math.h>
27
28// Value and its associated error. E.g. this could be interval size and
29// the error associated with numerical integration.
30
31class EvtValError final {
32 public:
34 EvtValError( double val );
35 EvtValError( double val, double err );
36 EvtValError( const EvtValError& other );
37
38 inline int valueKnown() const { return m_valKnown; }
39 inline double value() const
40 {
41 assert( m_valKnown );
42 return m_val;
43 }
44 inline int errorKnown() const { return m_errKnown; }
45 inline double error() const
46 {
47 assert( m_errKnown );
48 return m_err;
49 }
50
51 double prec() const;
52 void operator=( const EvtValError& other );
53 void operator*=( const EvtValError& other );
54 void operator/=( const EvtValError& other );
55 void operator+=( const EvtValError& other );
56 void operator*=( double c );
57
58 void print( std::ostream& ) const;
59
60 private:
62 double m_val;
64 double m_err;
65};
66
67EvtValError operator*( const EvtValError& x1, const EvtValError& x2 );
68EvtValError operator/( const EvtValError& x1, const EvtValError& x2 );
69EvtValError operator+( const EvtValError& x1, const EvtValError& x2 );
70EvtValError operator*( const EvtValError& x, double c );
71EvtValError operator*( double c, const EvtValError& x );
72
73std::ostream& operator<<( std::ostream&, const EvtValError& );
74
75// Perform an accept/reject fraction count
76
77template <class InputIterator, class Predicate>
78EvtValError accept_reject( InputIterator it, InputIterator end, Predicate pred )
79{
80 int itsTried = 0;
81 int itsPassed = 0;
82 while ( it != end ) {
83 itsTried++;
84 if ( pred( *it++ ) )
85 itsPassed++;
86 }
87
88 return EvtValError( ( (double)itsPassed ) / ( (double)itsTried ),
89 sqrt( itsPassed ) / ( (double)itsTried ) );
90}
91
92#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