Two Stat Boxes Question

Hi all,
I would like to draw two histograms in one canvas with two stat boxes as well.
I am using Python and the code is like this:

name='hpPi1'
hdt=rfile.Get(name)
if hdt==None:print "Can't find",name
stat1 = TPaveStats (hdt.GetListOfFunctions().FindObject("stats"))
stat1.SetX1NDC(0.2);
stat1.SetX2NDC(0.4);
stat1.SetY1NDC(0.2);
stat1.SetY2NDC(0.4);
hdt.Draw()
c.Update()

name='hpPi2'
hdt=rfile.Get(name)
if hdt==None:print "Can't find",name
hdt.SetLineColor(2)
stat2 = TPaveStats (hdt.GetListOfFunctions().FindObject("stats"))
stat2.SetX1NDC(0.1);
stat2.SetX2NDC(0.3);
stat2.SetY1NDC(0.1);
stat2.SetY2NDC(0.3);
hdt.Draw("sames")
c.Update()
c.SetTitle("P(Pi1 vs Pi2)")

Histograms are drawn well but only the second stat boxes (stat2) is shown. What’s the problem?

Cheers,
Yi

See: root.cern.ch/root/html/tutorials … pad.C.html

I think you first need to draw your histogram and only then you can FindObject(“stats”): [code]# …
hdt.Draw()
c.Update() # make sure it’s really drawn
stat1 = TPaveStats (hdt.GetListOfFunctions().FindObject(“stats”))

hdt.Draw(“sames”)
c.Update() # make sure it’s really drawn
stat2 = TPaveStats (hdt.GetListOfFunctions().FindObject(“stats”))

…[/code]

I have attached a mini-module that I wrote for myself for plotting multiple histograms on the same canvas, with reasonably good auto-placement of the stats boxes (and colorizing). You will definitely need to adapt it to your case, but it would at least show you which methods and names are useful. Take a look especially at the colourize_statbox, draw_stacked, movestatbox, findstatcoords, and colourize functions.

Hopefully those are useful.

Jean-François
histoprint.py (11.6 KB)