After translating your code to pyROOT, it did not initially work because the histograms are not named h1, h2 ⌠They have the names of the previous histograms I added to the stack. To get around this and not have to worry about what they are named I did:
c = TCanvas(name, title, 200, 10, canvasW, canvasH)
hs.Draw()
leg.Draw()
c.Update()
# arrange stats
histListForStats = []
if showStats:
for j in range(numHists-1, -1, -1):
histListForStats.append( hs.GetStack().At(j) )
# end of for loop
self.arrangeStats(histListForStats, statBoxW, statBoxH)
self.saveCanvas(c, logy)
arrangeStats is a function I wrote that moves the stat boxes one below the other.
def arrangeStats(self, hists,
statBoxW=0.16, statBoxH=0.10):
i=0
for h in hists:
statBox = h.GetListOfFunctions().FindObject("stats")
statBox.SetName('statBox' + str(i))
statBox.SetX1NDC(0.99 - statBoxW)
statBox.SetY1NDC(0.99 - i*(statBoxH + 0.01) - statBoxH)
statBox.SetX2NDC(0.99)
statBox.SetY2NDC(0.99 - i*(statBoxH + 0.01))
statBox.SetTextColor(h.GetFillColor())
statBox.SetBorderSize(2)
i+=1
The problem is that the stat boxes are obviously wrong. I have attached a plot. The red histogram has much fewer entries than the blue, even though the statbox doesnât reflect that.
Secondly, the graphs axis is draw on top of th statboxes for some reason.
Please see attached.
It seems like this whole business of messing with stats is very awkward. Why doesnât ROOT cater to what a typical user would want?
And just a general criticism:
I would recommend that ROOT get away from passing any options in a string that has to be parsed at runtime. I would think that all options for any ROOT class could be controlled by a series of bools or enums, which would be much less awkward. (I realize that runtime issues are not relevant for pyROOT, but I also write compiled C++ code using ROOT.)
Thanks very much for your help.
OS_TauTau_mass_stack.pdf (16.8 KB)