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
40 globalbin_to_axisbin = {}
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
76 Choose a random bin via get_random_bin, then pick a uniform random x
77 point in that bin (without any attempt at estimating the in-bin distribution).
80 axisids = globalbin_to_axisbin.get(irand)
81 assert axisids
is not None
82 xrand = random.uniform(h.GetXaxis().GetBinLowEdge(axisids[0]), h.GetXaxis().GetBinUpEdge(axisids[0]))
88 Choose a random bin via get_random_bin, then pick a uniform random x,y
89 point in that bin (without any attempt at estimating the in-bin distribution).
92 axisids = globalbin_to_axisbin.get(irand)
93 assert axisids
is not None
94 xrand = random.uniform(h2.GetXaxis().GetBinLowEdge(axisids[0]), h2.GetXaxis().GetBinUpEdge(axisids[0]))
95 yrand = random.uniform(h2.GetYaxis().GetBinLowEdge(axisids[1]), h2.GetYaxis().GetBinUpEdge(axisids[1]))
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...