GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
convert.py
Go to the documentation of this file.
1 
2 import ROOT
3 from array import array
4 
5 
6 def 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 
17 def 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 
28 def 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 
def list2hist
Definition: convert.py:6
def hist2list
Definition: convert.py:17
def eval_func
Definition: convert.py:28