Manipulating stat box

I am having some trouble manipulating the stat. box for a histogram from within a macro.

If I attach a file with an ntuple and do the following at the command line,

TPaveStatsst=(TPaveStats)theHist->FindObject(“stats”) ;
st->SetX1NDC(0.80);
st->SetY1NDC(0.85)

It works fine.

However, if I write a macro, it complains because the pointer “st” is not defined. Any ideas?

The macro:

{
gROOT->Reset() ;
gROOT->SetStyle(“Plain”) ;

gStyle->SetOptStat(111111) ;

TFile* f = TFile::Open(“file.root”) ;

TCanvas *c1 = new TCanvas(“c1”,“performance”,10,10,800,600) ;

c1->Clear() ;
c1->Divide(1,2) ;

c1->cd(1) ;
theHist->Draw() ;

TPaveStats *st = (TPaveStats)theHist->FindObject(“stats”) ;
st->SetX1NDC(0.80);
st->SetY1NDC(0.85) ;

c1->cd(2) ;
theHist->Draw() ;

c1->Update() ;
}

working example using the file generated by $ROOTSYS/tutorials/hsimple.C :

{
   gStyle->SetOptStat(111111) ;
   TFile f("hsimple.root");
   TCanvas *c1 = new TCanvas("c1","performance",10,10,800,600) ;
   c1->Clear() ;
   c1->Divide(1,2) ;
   c1->cd(1) ;
   hpx->Draw() ;
   TPaveStats *st = (TPaveStats*)hpx->GetListOfFunctions()->FindObject("stats") ;
   st->SetX1NDC(0.80);
   st->SetY1NDC(0.85) ;
   c1->cd(2) ;
   hpx->Draw() ;
}

this example works, but if I substitute the name of my root file and histogram name, I get the same “illegal pointer” error. My root file and hist. are valid names, since the macro recognizes both of them.

As far as I can see, there are no typos in the lines where I use my histogram. Not sure what else I can check.

very bizarre!

You must add
c1->Update();
after drawing your histogram and before accessing the “stats” box.
The “stats” box is only produced when the histogram is effecivlely paint
in the pad. gPad->Update() forces painting.

Rene

Rene, that did the trick.