CMS 3D CMS Logo

value.py
Go to the documentation of this file.
1 # Copyright (C) 2014 Colin Bernet
2 # https://github.com/cbernet/heppy/blob/master/LICENSE
3 
4 import math
5 import copy
6 
7 class Value(object):
8  def __init__(self, val, err):
9  self.val = val
10  self.err = err
11 
12  def relerr(self):
13  return abs(self.err / self.val)
14 
15  def __eq__(self, other):
16  return self.val == other.val and self.err == other.err
17 
18  def __iadd__(self, other):
19  self.val += other.val
20  self.err = math.sqrt( self.err*self.err + other.err*other.err)
21  return self
22 
23  def __add__(self, other):
24  new = copy.deepcopy(self)
25  new += other
26  return new
27 
28  def __isub__(self, other):
29  self.val -= other.val
30  self.err = math.sqrt( self.err*self.err + other.err*other.err)
31  return self
32 
33  def __sub__(self, other):
34  new = copy.deepcopy(self)
35  new -= other
36  return new
37 
38  def __idiv__(self, other):
39  relerr = math.sqrt( self.relerr()*self.relerr() + other.relerr()*other.relerr())
40  self.val /= other.val
41  self.err = relerr * self.val
42  return self
43 
44  def __div__(self, other):
45  new = copy.deepcopy(self)
46  new /= other
47  return new
48 
49  def __str__(self):
50  return '{val:10.3f} +- {err:8.3f} ({relerr:5.2f}%)'.format(val=self.val,
51  err=self.err,
52  relerr=self.relerr()*100)
value.Value.err
err
Definition: value.py:10
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
value.Value.relerr
def relerr(self)
Definition: value.py:12
value.Value.__eq__
def __eq__(self, other)
Definition: value.py:15
value.Value.__div__
def __div__(self, other)
Definition: value.py:44
value.Value.val
val
Definition: value.py:9
value.Value.__sub__
def __sub__(self, other)
Definition: value.py:33
value.Value.__idiv__
def __idiv__(self, other)
Definition: value.py:38
value.Value
Definition: value.py:7
value.Value.__init__
def __init__(self, val, err)
Definition: value.py:8
format
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
value.Value.__str__
def __str__(self)
Definition: value.py:49
value.Value.__isub__
def __isub__(self, other)
Definition: value.py:28
value.Value.__add__
def __add__(self, other)
Definition: value.py:23
value.Value.__iadd__
def __iadd__(self, other)
Definition: value.py:18