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.cpp
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 
22 
23 #include "EvtGenBase/EvtPatches.hh"
24 
25 #include <assert.h>
26 #include <iostream>
27 #include <math.h>
28 using std::endl;
29 using std::ostream;
30 
32  _valKnown( 0 ), _val( 0. ), _errKnown( 0 ), _err( 0. )
33 {
34 }
35 
36 EvtValError::EvtValError( double val ) :
37  _valKnown( 1 ), _val( val ), _errKnown( 0 ), _err( 0. )
38 {
39 }
40 
41 EvtValError::EvtValError( double val, double err ) :
42  _valKnown( 1 ), _val( val ), _errKnown( 1 ), _err( err )
43 {
44 }
45 
47  _valKnown( other._valKnown ),
48  _val( other._val ),
49  _errKnown( other._errKnown ),
50  _err( other._err )
51 {
52 }
53 
54 double EvtValError::prec() const
55 {
56  assert( _valKnown && _errKnown );
57  return ( _val != 0 ) ? _err / _val : 0;
58 }
59 
61 {
62  _valKnown = other._valKnown;
63  _val = other._val;
64  _errKnown = other._errKnown;
65  _err = other._err;
66 }
67 
69 {
70  assert( _valKnown && other._valKnown );
71 
72  // Relative errors add in quadrature
73  if ( _errKnown && other._errKnown )
74  _err = _val * other._val *
75  sqrt( prec() * prec() + other.prec() * other.prec() );
76  else
77  _errKnown = 0;
78 
79  // Modify the value
80  _val *= other._val;
81 }
82 
84 {
85  assert( _valKnown && other._valKnown && other._val != 0. );
86 
87  // Relative errors add in quadrature
88  if ( _errKnown && other._errKnown )
89  _err = _val / other._val *
90  sqrt( prec() * prec() + other.prec() * other.prec() );
91  else
92  _errKnown = 0;
93 
94  // Modify the value
95  _val /= other._val;
96 }
97 
98 void EvtValError::print( ostream& os ) const
99 {
100  if ( _valKnown )
101  os << _val;
102  else
103  os << "Undef";
104  os << " +/- ";
105  if ( _errKnown )
106  os << _err;
107  else
108  os << "Undef";
109  os << endl;
110 }
111 
113 {
114  assert( _valKnown );
115  assert( other._valKnown );
116  _val += other._val;
117 
118  // add errors in quadrature
119 
120  if ( _errKnown && other._errKnown ) {
121  _err = sqrt( _err * _err + other._err * other._err );
122  } else {
123  _errKnown = 0;
124  }
125 }
126 
127 void EvtValError::operator*=( double c )
128 {
129  assert( _valKnown );
130  _val *= c;
131  if ( _errKnown )
132  _err *= c;
133 }
134 
136 {
137  EvtValError ret( x1 );
138  ret *= x2;
139  return ret;
140 }
141 
143 {
144  EvtValError ret( x1 );
145  ret /= x2;
146  return ret;
147 }
148 
150 {
151  EvtValError ret( x1 );
152  ret += x2;
153  return ret;
154 }
155 
156 EvtValError operator*( const EvtValError& x, double c )
157 {
158  EvtValError ret( x );
159  ret *= c;
160  return ret;
161 }
162 
163 EvtValError operator*( double c, const EvtValError& x )
164 {
165  EvtValError ret( x );
166  ret *= c;
167  return ret;
168 }
169 
170 ostream& operator<<( ostream& os, const EvtValError& other )
171 {
172  other.print( os );
173  return os;
174 }
EvtValError operator/(const EvtValError &x1, const EvtValError &x2)
ostream & operator<<(ostream &os, const EvtValError &other)
double _val
Definition: EvtValError.hh:62
void operator *=(const EvtValError &other)
Definition: EvtValError.cpp:68
double prec() const
Definition: EvtValError.cpp:54
void print(std::ostream &) const
Definition: EvtValError.cpp:98
void operator/=(const EvtValError &other)
Definition: EvtValError.cpp:83
void operator+=(const EvtValError &other)
double _err
Definition: EvtValError.hh:64
EvtValError operator+(const EvtValError &x1, const EvtValError &x2)
EvtValError operator *(const EvtValError &x1, const EvtValError &x2)
void operator=(const EvtValError &other)
Definition: EvtValError.cpp:60
Index other(Index i, Index j)
Definition: EvtCyclic3.cpp:156