Statistical box on Canvas using THStack

hello to everyone !
I want to use THStack to put two histogram on the same Canvas. The histograms are drawn but the statistical box is not drawn. I used [quote]TPaveStats ps1 = (TPaveStats)h1->GetListOfFunctions()->FindObject(“stats”);[/quote] without success. How can I make so that the statistical box is drawn on the canvas. here my program.

[quote]// Ce programme permet de mettre deux histogrammes
// sur le meme graphique pour les comparer : exemple
// une acquisition et son pedestal

#include “Riostream.h”
#include “TFile.h”
#include “TH1F.h”
#include “THStack.h”
#include “TPaveStats.h"
void dam()
{
// on définit le fichier du pedestal
const Char_t* pedest= “C:/root/R111755.dat”; const Char_t* pedroot=” R111755.root";

// on définit le fichier d’acquisition
const Char_t* event= “C:/root/R111753.dat”; const Char_t* evenroot=" R111753.root";

Float_t x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16;

ifstream in;
in.open(pedest);
if (!in.is_open()) cout<<" impossible to open the file "<<endl;
else
{
{ Int_t nlines = 0;
//TFile *f = new TFile(“pedroot”,“RECREATE”);

TH1F *h1 = new TH1F(“ADC1”," TME ch1 ",300, 200,600);

TH1F *h2 = new TH1F(“ADC2”," TME ch2 ",300, 200,600);

while (1) {
in >> x1 >> x2 >>x3 >>x4 >>x5 >>x6 >>x7 >>x8 >>x9 >>x10 >>x11 >>x12 >>x13 >>x14 >>x15 >>x16;
if (!in.good()) break;

h1->Fill(x1); h2->Fill(x2);
nlines++;
}
cout<<" "<<endl;
cout<<"First data: ";

printf(" found %d points",nlines);
cout<<" “<<endl;
in.close();
// f->Write();
}
ifstream in;
in.open(event);
if (!in.is_open()) cout<<” impossible to open the file "<<endl;
else
{
{
Int_t nlines = 0;

//TFile *ff = new TFile(“evenroot”,“RECREATE”);

TH1F *h5 = new TH1F(“5X”," TME ch1 “,300, 200,600);
TH1F *h6 = new TH1F(“6X”,” TME ch2 ",300, 200,600);

while (1) {
in >> x1 >> x2 >>x3 >>x4 >>x5 >>x6 >>x7 >>x8 >>x9 >>x10 >>x11 >>x12 >>x13 >>x14 >>x15 >>x16;
if (!in.good()) break;

h5->Fill(x1); h6->Fill(x2);

  nlines++;

}

cout<<“Second Data: “;
printf(” found %d points”,nlines);
cout<<" "<<endl;

in.close();
// ff->Write();

THStack *hs1= new THStack(“hs1”," 1X: Pedestal (blue) Events (red)");
hs1->Add(h1);
hs1->Add(h5);
THStack *hs2= new THStack(“hs2”," 2X: Pedestal (blue) Events (red)");
hs2->Add(h2);
hs2->Add(h6);

TCanvas *C1 = new TCanvas("1X ",“1X”,1);

hs1->Draw(“nostack”);
h1->SetLineColor(4);
h1->SetFillColor(kGreen);
h1->SetLineWidth(1);

h5->SetLineColor(2);
h5->SetLineWidth(1);

C1->Update(); //this will force the generation of the “stats” box
TPaveStats ps1 = (TPaveStats)h1->GetListOfFunctions()->FindObject(“stats”);
ps1->SetX1NDC(0.4); ps1->SetX2NDC(0.6);
C1->Modified();
ps1->Draw();
gPad->SetGrid();
}
}
}
}[/quote]

Right now when a stack is painted the statistics are not drawn because, I guess, it is hard to decide which stats should be drawn. But in your example I see that you are drawing your THStack with the option “nostats” which means (see the THStack help):

" If option “nostack” is specified, histograms are all paint in the same pad as if the option “same” had been specified."

In that case why don’t you draw the histograms one after each other use the “same” option ?
That way you can draw the stats box.