How to access statistics box (of a histogram iterator)

Hi,

Using

to access the stats box works fine for simple histograms. However, I try the following (h1 is a standard list: std::list<TH1D*> h1;):

std::list<TH1D*>::iterator it1 = h1.begin();
(*it1)->Draw();
TPaveStats *st = (TPaveStats*)(*it1)->FindObject("stats");
cout << st << endl;

and get the output “0” - st is a null pointer, apparently the objects “stats” does not exist. Accessing st then obviously leads to segmentation faults…

Any solutions? Or maybe a simpler way to access the stats, e.g. something of the kind
h->GetStatsBox()->SetTextColor(2);
(What I want is to change position, and to change color of line and text).

I am using code compiled against root 5.12.

Thanks a lot!
Martin

example:

{
   TCanvas * c1 = new TCanvas("Canv1","Canv1");
                                                                                                 
   TH1F *h1 = new TH1F("h1","h1",100,-4,4);
   h1->FillRandom("gaus",20000);
   h1->SetFillColor(kRed);
   h1->Draw("");
   c1->Update();
                                                                                                 
   TH1F *h2 = new TH1F("h2","h2",100,-4,4);
   h2->FillRandom("gaus",15000);
   h2->SetFillColor(kBlue);
   h2->Draw("SAMES");
   c1->Update();
                                                                                                 
   TPaveStats *statsBox = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats");
   statsBox->SetY1NDC(0.1);
   statsBox->SetY2NDC(0.5);
   statsBox->SetTextColor(kRed);
   c1->Modified();
}

Hi,

Thanks for your reply - however, it does not solve my problem. As mentioned it works perfectly well for pointers at histograms, but for some reason it does not with the iterators over a TH1D std::list , as given in the example in my previous post.

Unfortunately I can’t provide a simple macro to reproduce the problem, somehow root crashes whenever I just declare a std::list<TH1*> object (works fine for compiled code, though).

Thankful for any suggestions!
Martin

Ok, but a simple macro showing the problem would be great help !!!