Stacking Histograms

Hey ROOTers,
I am trying to stack some histograms I grab from ntuple variables. The problem I am having is that the automatic drawing of the histograms means that they have different numbers of bins. So root sensibly complains.

Error in TH1F::Add: Attempt to add histograms with different number of bins

I have been trying various ways aroud this. But cannot seem to find a solution.
Surely this is possible? I show below my current attempt.
Cheers for any help!
Al

[code]{
TCanvas *c1 = new TCanvas(“Not c1”,“Fitter Output”,200,10,700,500);

// draw a frame to define the range
TLegend *legend = new TLegend(0.45,0.3,0.65,0.44,"");
legend->SetTextSize(0.04);

THStack *hs = new THStack(“hs”,“Di-jet Invariant Mass (Electron Channel)”);

TFile *data = TFile::Open("…/ElData/TopElFitter.data.Data.root");
data.cd();
TTree t_data = (TTree)data->Get(“ntup”);

t_data->Draw(“NJet”,"",“pe”);
double max = t_data->GetHistogram()->GetMaximum();
double min = t_data->GetHistogram()->GetMinimum();
t_data->GetHistogram()->SetFillColor(kGreen);
t_data->GetHistogram()->SetXTitle(“NJets”);
t_data->GetHistogram()->SetYTitle(“Events”);
legend->AddEntry(t_data->GetHistogram(), “Data A->I”, “P”);

TFile *ttbar = TFile::Open("…/ElMC/TopElFitter.MC.ttbar.root");
ttbar.cd();
TTree t_ttbar = (TTree)ttbar->Get(“ntup”);

t_ttbar->Draw(“NJet”,“EventWeight”,“goff”);
t_ttbar->GetHistogram()->SetBit(TH1::kCanRebin);
t_ttbar->GetHistogram()->SetMaximum(max);
t_ttbar->GetHistogram()->SetMinimum(min);
t_ttbar->GetHistogram()->SetFillColor(kRed);
t_ttbar->GetHistogram()->SetXTitle(“NJets”);
t_ttbar->GetHistogram()->SetYTitle(“Events”);

legend->AddEntry(t_ttbar->GetHistogram(), “ttbar”, “F”);

hs.Add(t_ttbar->GetHistogram());

TFile *wenu0_5 = TFile::Open("…/ElMC/WenuNp0_5.root");
wenu0_5.cd();
TTree t_Wenu = (TTree)wenu0_5->Get(“ntup”);

t_Wenu->Draw(“NJet”,“EventWeight”,“goff”);
t_Wenu->GetHistogram()->SetBit(TH1::kCanRebin);
t_Wenu->GetHistogram()->SetMaximum(max);
t_Wenu->GetHistogram()->SetMinimum(min);
t_Wenu->GetHistogram()->SetFillColor(kGreen);
t_Wenu->GetHistogram()->SetXTitle(“NJets”);
t_Wenu->GetHistogram()->SetYTitle(“Events”);

legend->AddEntry(t_Wenu->GetHistogram(), “WenuNp0-5”, “F”);

hs.Add(t_Wenu->GetHistogram());

hs.Draw(“hist same”);
data.cd();
t_data->Draw(“NJet”,"",“pe same”);

legend->Draw();
}[/code]

Impose the binning doing:

tree.Draw(“sqrt(x)>>hsqrt(500,10,20)”); // from TTree:Draw doc

see root.cern.ch/root/html/TTree.html#TTree:Draw%1 for the complete information.

Danke!
Works perfectly!