BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtValError.cc
Go to the documentation of this file.
1#include "EvtPatches.hh"
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, dvoretsk@slac.stanford.edu, 2001-2002
7 *
8 * Copyright (C) 2002 Caltech
9 *******************************************************************************/
10
11#include "EvtValError.hh"
12#include <assert.h>
13#include <iostream>
14#include <math.h>
15using std::endl;
16using std::ostream;
17
18EvtValError::EvtValError() : _valKnown( 0 ), _val( 0. ), _errKnown( 0 ), _err( 0. ) {}
19
21 : _valKnown( 1 ), _val( val ), _errKnown( 0 ), _err( 0. ) {}
22
23EvtValError::EvtValError( double val, double err )
24 : _valKnown( 1 ), _val( val ), _errKnown( 1 ), _err( err ) {}
25
27 : _valKnown( other._valKnown )
28 , _val( other._val )
29 , _errKnown( other._errKnown )
30 , _err( other._err ) {}
31
33
34double EvtValError::prec() const {
35 assert( _valKnown && _errKnown );
36 return ( _val != 0 ) ? _err / _val : 0;
37}
38
39void EvtValError::operator=( const EvtValError& other ) {
40 _valKnown = other._valKnown;
41 _val = other._val;
42 _errKnown = other._errKnown;
43 _err = other._err;
44}
45
47 assert( _valKnown && other._valKnown );
48
49 // Relative errors add in quadrature
50 if ( _errKnown && other._errKnown )
51 _err = _val * other._val * sqrt( prec() * prec() + other.prec() * other.prec() );
52 else _errKnown = 0;
53
54 // Modify the value
55 _val *= other._val;
56}
57
59 assert( _valKnown && other._valKnown && other._val != 0. );
60
61 // Relative errors add in quadrature
62 if ( _errKnown && other._errKnown )
63 _err = _val / other._val * sqrt( prec() * prec() + other.prec() * other.prec() );
64 else _errKnown = 0;
65
66 // Modify the value
67 _val /= other._val;
68}
69
70void EvtValError::print( ostream& os ) const {
71 if ( _valKnown ) os << _val;
72 else os << "Undef";
73 os << " +/- ";
74 if ( _errKnown ) os << _err;
75 else os << "Undef";
76 os << endl;
77}
78
80 assert( _valKnown );
81 assert( other._valKnown );
82 _val += other._val;
83
84 // add errors in quadrature
85
86 if ( _errKnown && other._errKnown ) { _err = sqrt( _err * _err + other._err * other._err ); }
87 else { _errKnown = 0; }
88}
89
90void EvtValError::operator*=( double c ) {
91
92 assert( _valKnown );
93 _val *= c;
94 if ( _errKnown ) _err *= c;
95}
96
98 EvtValError ret( x1 );
99 ret *= x2;
100 return ret;
101}
102
104 EvtValError ret( x1 );
105 ret /= x2;
106 return ret;
107}
108
110 EvtValError ret( x1 );
111 ret += x2;
112 return ret;
113}
114
115EvtValError operator*( const EvtValError& x, double c ) {
116 EvtValError ret( x );
117 ret *= c;
118 return ret;
119}
120
121EvtValError operator*( double c, const EvtValError& x ) {
122 EvtValError ret( x );
123 ret *= c;
124 return ret;
125}
126
127ostream& operator<<( ostream& os, const EvtValError& other ) {
128 other.print( os );
129 return os;
130}
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