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