33def get_sampling_vars(h):
34 """
35 Get the following from a histogram h, since the ROOT API sucks:
36 * list of global bin IDs (not even contiguous for 2D, gee thanks ROOT)
37 * dict mapping global bin IDs to a tuple of axis bin IDs
38 * list of nbins+1 cumulative bin values, in the same order as globalbins
39 """
40 globalbin_to_axisbin = {}
41 globalbins = []
42 cheights = [0]
43 if issubclass(
type(h), ROOT.TH1):
44 for ix in range(1, h.GetNbinsX()+1):
45 iglobal = h.GetBin(ix)
46 globalbins.append(iglobal)
47 globalbin_to_axisbin[iglobal] = (ix,)
48 cheights.append(cheights[-1] + h.GetBinContent(iglobal))
49 elif issubclass(
type(h), ROOT.TH2):
50 for ix in range(1, h.GetNbinsX()+1):
51 for iy in range(1, h.GetNbinsY()+1):
52 iglobal = h.GetBin(ix, iy)
53 globalbins.append(iglobal)
54 globalbin_to_axisbin[iglobal] = (ix, iy)
55 cheights.append(cheights[-1] + h.GetBinContent(iglobal))
56 return globalbins, globalbin_to_axisbin, cheights
57
58