BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtValError.cc
Go to the documentation of this file.
2/*******************************************************************************
3 * Project: BaBar detector at the SLAC PEP-II B-factory
4 * Package: EvtGenBase
5 * File: $Id: EvtValError.cc,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
6 * Author: Alexei Dvoretskii, [email protected], 2001-2002
7 *
8 * Copyright (C) 2002 Caltech
9 *******************************************************************************/
10
11#include <assert.h>
12#include <math.h>
13#include <iostream>
15using std::endl;
16using std::ostream;
17
19 : _valKnown(0), _val(0.), _errKnown(0), _err(0.)
20{}
21
23 : _valKnown(1), _val(val), _errKnown(0), _err(0.)
24{}
25
26EvtValError::EvtValError(double val, double err)
27 : _valKnown(1), _val(val), _errKnown(1), _err(err)
28{}
29
31 : _valKnown(other._valKnown), _val(other._val),
32 _errKnown(other._errKnown), _err(other._err)
33{}
34
36{}
37
38double EvtValError::prec() const
39{
40 assert(_valKnown && _errKnown);
41 return ( _val != 0) ? _err/_val : 0;
42}
43
45{
46 _valKnown = other._valKnown;
47 _val = other._val;
48 _errKnown = other._errKnown;
49 _err = other._err;
50}
51
53{
54 assert(_valKnown && other._valKnown);
55
56 // Relative errors add in quadrature
57 if(_errKnown && other._errKnown)
58 _err = _val * other._val * sqrt(prec()*prec() + other.prec() * other.prec());
59 else _errKnown = 0;
60
61 // Modify the value
62 _val *= other._val;
63}
64
66{
67 assert(_valKnown && other._valKnown && other._val != 0.);
68
69 // Relative errors add in quadrature
70 if(_errKnown && other._errKnown)
71 _err = _val/other._val * sqrt(prec()*prec() + other.prec() * other.prec());
72 else _errKnown = 0;
73
74 // Modify the value
75 _val /= other._val;
76}
77
78
79void EvtValError::print(ostream& os) const
80{
81 if(_valKnown) os << _val;
82 else os << "Undef";
83 os << " +/- ";
84 if(_errKnown) os << _err;
85 else os << "Undef";
86 os << endl;
87}
88
89
91{
92 assert(_valKnown); assert(other._valKnown);
93 _val += other._val;
94
95 // add errors in quadrature
96
97 if(_errKnown && other._errKnown) {
98
99 _err = sqrt(_err*_err + other._err*other._err);
100 }
101 else {
102
103 _errKnown = 0;
104 }
105}
106
108
109 assert(_valKnown);
110 _val *= c;
111 if(_errKnown) _err*=c;
112}
113
114
116{
117 EvtValError ret(x1);
118 ret *= x2;
119 return ret;
120}
121
123{
124 EvtValError ret(x1);
125 ret /= x2;
126 return ret;
127}
128
129
131{
132 EvtValError ret(x1);
133 ret += x2;
134 return ret;
135}
136
137
139{
140 EvtValError ret(x);
141 ret*=c;
142 return ret;
143}
144
145
147{
148 EvtValError ret(x);
149 ret*=c;
150 return ret;
151}
152
153
154ostream& operator<<(ostream& os, const EvtValError& other)
155{
156 other.print(os);
157 return os;
158}
159
160
Double_t x[10]
EvtValError operator+(const EvtValError &x1, const EvtValError &x2)
Definition: EvtValError.cc:130
EvtValError operator/(const EvtValError &x1, const EvtValError &x2)
Definition: EvtValError.cc:122
ostream & operator<<(ostream &os, const EvtValError &other)
Definition: EvtValError.cc:154
EvtValError operator*(const EvtValError &x1, const EvtValError &x2)
Definition: EvtValError.cc:115
void operator=(const EvtValError &other)
Definition: EvtValError.cc:44
void operator/=(const EvtValError &other)
Definition: EvtValError.cc:65
void operator+=(const EvtValError &other)
Definition: EvtValError.cc:90
void operator*=(const EvtValError &other)
Definition: EvtValError.cc:52
double prec() const
Definition: EvtValError.cc:38
void print(std::ostream &) const
Definition: EvtValError.cc:79