5 tfile = ROOT.TFile.Open(fileuri, mode)
7 raise IOError(
'failed to open %s' % fileuri)
14 raise IOError(
'failed to get hist "%s" from %s' % (name, fileuri))
20 tfile = ROOT.TFile.Open(fname,
"recreate")
22 raise IOError(
'failed to open %s' % fname)
23 obj.SetDirectory(tfile)
29 if obj.InheritsFrom(
"TKey"):
30 return obj.GetClassName()[:3]
in [
"TH1",
"TH2",
"TH3"]
31 return obj.InheritsFrom(
"TH1")
35 Return data structure summarizing the histogram. 37 ndim =
int(hist.ClassName()[2])
39 for idim
in range(ndim):
41 nbins = getattr(hist,
"GetNbins"+letter)()
42 axis = getattr(hist,
"Get"+letter+
"axis")()
43 lo = axis.GetBinLowEdge(1);
44 hi = axis.GetBinUpEdge(nbins);
45 dim = dict(letter=letter, nbins=nbins, min=lo, max=hi, rms=hist.GetRMS(idim+1))
48 return dict(axis=dims, name=hist.GetName(), title=hist.GetTitle(),
49 integ=hist.Integral(),
50 min=hist.GetMinimum(), max=hist.GetMaximum())
55 Rebin 2D histogram. This is dog slow. 57 xaxis = hist.GetXaxis()
58 nbinsx = hist.GetNbinsX()
59 yaxis = hist.GetYaxis()
60 nbinsy = hist.GetNbinsY()
62 h = ROOT.TH2F(hist.GetName(), hist.GetTitle(),
63 int(round(nbinsx/xrebin)), xaxis.GetBinLowEdge(1), xaxis.GetBinUpEdge(nbinsx),
64 int(round(nbinsy/yrebin)), yaxis.GetBinLowEdge(1), yaxis.GetBinUpEdge(nbinsy))
66 xaxis_new = h.GetXaxis()
67 yaxis_new = h.GetYaxis()
69 for ixbin
in range(hist.GetNbinsX()):
70 x = xaxis.GetBinCenter(ixbin+1)
71 ix = xaxis_new.FindBin(x)
73 for iybin
in range(hist.GetNbinsY()):
74 y = yaxis.GetBinCenter(iybin+1)
75 iy = yaxis_new.FindBin(y)
76 val = hist.GetBinContent(ixbin+1, iybin+1)
77 ibin = h.GetBin(ix,iy)
78 h.AddBinContent(ibin, val)
def load_obj(tfile, name)
def open_file(fileuri, mode="READONLY")
def resize_hist2f(hist, xrebin, yrebin)