-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathROOTTools.py
More file actions
73 lines (56 loc) · 1.77 KB
/
Copy pathROOTTools.py
File metadata and controls
73 lines (56 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Some generic ROOT Tools.
"""
import math
class TemplateFitter:
"""
Class to allow a TH1D (template) + TF1 to be fitted to a TH1.
tempfunc = TemplateFitter(th1d_template, tf1_name)
fit = ROOT.TF1("f", tempfunc, 2, 25, 4) #Fir params = 2+th1 params
note fit params are p[0]*template + p[1]*function + function params
"""
def __init__(self, template, function):
"""
Constructor, saves histogram and template objects.
"""
self.template = template
self.function = function
def __call__(self, x, par):
"""
Performs the fit using the parameters...
[0] Multiple of template
[1] Multiple of function
[2:] Function parameters.
"""
x=x[0]
# Evaluate Histogram
template_bin = self.template.FindBin(x)
template_value = self.template.GetBinContent(template_bin)
# Evaluate Fit Function
for i in range(self.function.GetNpar()):
self.function.SetParameter(i, par[2+i])
function_value = self.function(x)
return template_value*par[0] + function_value*par[1]
def IntegrateExpErr(a, a_error, start, stop):
"""
Calculat the inegral of e(ax) integrated between
start and stop.
"""
integral = 1/a*(math.exp(a*stop) - math.exp(a*start))
dida = -1/a/a*(math.exp(a*stop) - math.exp(a*start))\
+ 1/a*(stop*math.exp(a*stop) - start*math.exp(a*start))
error = a_error*dida
return integral, error
def CombinedNorm(hists):
"""
Normalise an array of histograms to 1 over all
"""
entries = 0
for h in hists:
entries += h.GetEntries()
try:
rescale = 1/entries
except:
rescale = 1
for h in hists:
h.Scale(rescale)