GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
convert.py
Go to the documentation of this file.
2import ROOT
3from array import array
4
5
6def list2hist(xs, ys, name="anonymous", title=""):
7 """
8 Create a ROOT.TH1I with xs as bins (low edges) and ys as their content
9 name and title will be used for the new histogram
10 """
11 h = ROOT.TH1I(name, title, len(xs), array('d', xs))
12 for i, y in enumerate(ys):
13 h.SetBinContent(i+1, y)
14 return h
15
16
17def hist2list(h):
18 """
19 Read points from histogram h into two lists (x and y coordinates)
20 Format is chosen such that matplotlib.pyplot.step() can be used for plotting
21 hence (x, y) == (low edges, contents)
22 """
23 tmp = ((h.GetBinLowEdge(i+1), h.GetBinContent(i+1)) for i in range(h.GetNbinsX()))
24 return zip(*tmp)
25
26
27
28def eval_func(xs, tf):
29 """
30 Evaluate the TF1 tf for all values in xs, return list of y values
31 """
32 return [tf.Eval(x) for x in xs]
33
34
35
list2hist(xs, ys, name="anonymous", title="")
Definition convert.py:6
eval_func(xs, tf)
Definition convert.py:28