EvtGen
2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Toggle main menu visibility
Loading...
Searching...
No Matches
src
EvtGenBase
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
21
#include "
EvtGenBase/EvtValError.hh
"
22
23
#include <assert.h>
24
#include <iostream>
25
#include <math.h>
26
using
std::endl;
27
using
std::ostream;
28
29
EvtValError::EvtValError
() :
30
m_valKnown
( 0 ),
m_val
( 0. ),
m_errKnown
( 0 ),
m_err
( 0. )
31
{
32
}
33
34
EvtValError::EvtValError
(
double
val ) :
35
m_valKnown
( 1 ),
m_val
( val ),
m_errKnown
( 0 ),
m_err
( 0. )
36
{
37
}
38
39
EvtValError::EvtValError
(
double
val,
double
err ) :
40
m_valKnown
( 1 ),
m_val
( val ),
m_errKnown
( 1 ),
m_err
( err )
41
{
42
}
43
44
EvtValError::EvtValError
(
const
EvtValError
& other ) :
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
52
double
EvtValError::prec
()
const
53
{
54
assert(
m_valKnown
&&
m_errKnown
);
55
return
(
m_val
!= 0 ) ?
m_err
/
m_val
: 0;
56
}
57
58
void
EvtValError::operator=
(
const
EvtValError
& other )
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
66
void
EvtValError::operator*=
(
const
EvtValError
& other )
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
81
void
EvtValError::operator/=
(
const
EvtValError
& other )
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
96
void
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
110
void
EvtValError::operator+=
(
const
EvtValError
& other )
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
125
void
EvtValError::operator*=
(
double
c )
126
{
127
assert(
m_valKnown
);
128
m_val
*= c;
129
if
(
m_errKnown
)
130
m_err
*= c;
131
}
132
133
EvtValError
operator*
(
const
EvtValError
& x1,
const
EvtValError
& x2 )
134
{
135
EvtValError
ret( x1 );
136
ret *= x2;
137
return
ret;
138
}
139
140
EvtValError
operator/
(
const
EvtValError
& x1,
const
EvtValError
& x2 )
141
{
142
EvtValError
ret( x1 );
143
ret /= x2;
144
return
ret;
145
}
146
147
EvtValError
operator+
(
const
EvtValError
& x1,
const
EvtValError
& x2 )
148
{
149
EvtValError
ret( x1 );
150
ret += x2;
151
return
ret;
152
}
153
154
EvtValError
operator*
(
const
EvtValError
& x,
double
c )
155
{
156
EvtValError
ret( x );
157
ret *= c;
158
return
ret;
159
}
160
161
EvtValError
operator*
(
double
c,
const
EvtValError
& x )
162
{
163
EvtValError
ret( x );
164
ret *= c;
165
return
ret;
166
}
167
168
ostream&
operator<<
( ostream& os,
const
EvtValError
& other )
169
{
170
other.print( os );
171
return
os;
172
}
operator+
EvtValError operator+(const EvtValError &x1, const EvtValError &x2)
Definition
EvtValError.cpp:147
operator/
EvtValError operator/(const EvtValError &x1, const EvtValError &x2)
Definition
EvtValError.cpp:140
operator<<
ostream & operator<<(ostream &os, const EvtValError &other)
Definition
EvtValError.cpp:168
operator*
EvtValError operator*(const EvtValError &x1, const EvtValError &x2)
Definition
EvtValError.cpp:133
EvtValError.hh
EvtValError
Definition
EvtValError.hh:31
EvtValError::operator=
void operator=(const EvtValError &other)
Definition
EvtValError.cpp:58
EvtValError::EvtValError
EvtValError()
Definition
EvtValError.cpp:29
EvtValError::m_valKnown
int m_valKnown
Definition
EvtValError.hh:61
EvtValError::operator/=
void operator/=(const EvtValError &other)
Definition
EvtValError.cpp:81
EvtValError::operator+=
void operator+=(const EvtValError &other)
Definition
EvtValError.cpp:110
EvtValError::operator*=
void operator*=(const EvtValError &other)
Definition
EvtValError.cpp:66
EvtValError::m_val
double m_val
Definition
EvtValError.hh:62
EvtValError::prec
double prec() const
Definition
EvtValError.cpp:52
EvtValError::print
void print(std::ostream &) const
Definition
EvtValError.cpp:96
EvtValError::m_err
double m_err
Definition
EvtValError.hh:64
EvtValError::m_errKnown
int m_errKnown
Definition
EvtValError.hh:63
Generated by
1.17.0