evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
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 
31 class EvtValError final {
32  public:
33  EvtValError();
34  EvtValError( double val );
35  EvtValError( double val, double err );
36  EvtValError( const EvtValError& other );
37 
38  inline int valueKnown() const { return _valKnown; }
39  inline double value() const
40  {
41  assert( _valKnown );
42  return _val;
43  }
44  inline int errorKnown() const { return _errKnown; }
45  inline double error() const
46  {
47  assert( _errKnown );
48  return _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:
61  int _valKnown;
62  double _val;
63  int _errKnown;
64  double _err;
65 };
66 
67 EvtValError operator*( const EvtValError& x1, const EvtValError& x2 );
68 EvtValError operator/( const EvtValError& x1, const EvtValError& x2 );
69 EvtValError operator+( const EvtValError& x1, const EvtValError& x2 );
70 EvtValError operator*( const EvtValError& x, double c );
71 EvtValError operator*( double c, const EvtValError& x );
72 
73 std::ostream& operator<<( std::ostream&, const EvtValError& );
74 
75 // Perform an accept/reject fraction count
76 
77 template <class InputIterator, class Predicate>
78 EvtValError 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
double _val
Definition: EvtValError.hh:62
void operator *=(const EvtValError &other)
Definition: EvtValError.cpp:68
int errorKnown() const
Definition: EvtValError.hh:44
EvtValError operator *(const EvtValError &x1, const EvtValError &x2)
double prec() const
Definition: EvtValError.cpp:54
void print(std::ostream &) const
Definition: EvtValError.cpp:98
std::ostream & operator<<(std::ostream &, const EvtValError &)
EvtValError accept_reject(InputIterator it, InputIterator end, Predicate pred)
Definition: EvtValError.hh:78
void operator/=(const EvtValError &other)
Definition: EvtValError.cpp:83
EvtValError operator+(const EvtValError &x1, const EvtValError &x2)
double value() const
Definition: EvtValError.hh:39
EvtValError operator/(const EvtValError &x1, const EvtValError &x2)
double error() const
Definition: EvtValError.hh:45
void operator+=(const EvtValError &other)
double _err
Definition: EvtValError.hh:64
int valueKnown() const
Definition: EvtValError.hh:38
void operator=(const EvtValError &other)
Definition: EvtValError.cpp:60
Index other(Index i, Index j)
Definition: EvtCyclic3.cpp:156