Problem with SetBins and GetMaximum

Hi,
I have two trees in two different root files.
I want to get tree1, draw a histo.
Then I want to get tree2, draw a histo of the same variable
with nbins, xmin, xmax ( x axis range) same as the tree1 histo.
This is what I am doing :

[code]
tree1->Draw(“pt>>h1”);
h1 = (TH1F*)gDirectory->Get(“h1”);
double xmin = h1->GetXaxis()->GetXmin();
double xmax = h1->GetXaxis()->GetXmax();
double xbins = h1->GetNbinsX();

tree2->Draw(“pt>>h2”);
h2 = (TH1F*)gDirectory->Get(“h2”);
h2->SetBins( xbins,xmin,xmax );[/code]

After h2->SetBins( xbins,xmin,xmax ), if I do

it shows me the same maximum as it was before

Do I need to something else to ensure that the binscontents are evaluated again after
the nbins, xmin and xmax of h2 is changed?

I would like to mention that both h1 and h2 have different nbins, xmin and xmax
before doing

Thanks & Best Regards,
Shilpi

Instead of

[code]tree1->Draw(“pt>>h1”);
h1 = (TH1F*)gDirectory->Get(“h1”);
double xmin = h1->GetXaxis()->GetXmin();
double xmax = h1->GetXaxis()->GetXmax();
double xbins = h1->GetNbinsX();

tree2->Draw(“pt>>h2”);
h2 = (TH1F*)gDirectory->Get(“h2”);
h2->SetBins( xbins,xmin,xmax );[/code]
do

tree1->Draw("pt>>h1"); h1 = (TH1F*)gDirectory->Get("h1"); TH1 *h2 = (TH1*)h1->Clone("h2"); tree2->Draw("pt>>h2");
Rene

Hi Rene,

Thanks a lot. Its working now.

Best Regards,
Shilpi