Updating Statistic Box

Dear all,
I’m drawing an histogram whith this command:

t->Draw(“ntracks >> h(45,0,45)”,“ntracks>0”);

After this I want to add entries to the first bin by the command:

h->AddBinContent(1,150);

But when I draw the histogram with the command:

h->Draw()

the statistic box always shows the “Entries” before the call to the command AddBinContent.
How can I have the correct number of entries in the statistic box?

Another question:
I’m drawing a 1-D histogram which bin content ranges from 0 to 120, so the Y axis has more or less this range; but later I want to draw an histo on the same canvas which bin content is from 0 to 140, so I cannot see some bins for which the bin content exceeds the limit on Y axis given by the first histogram.
How can I expand the range of the Y axis?

Thanks a lot,
Fabio

Draw first the frame using gPad->DrawFrame(…) . And then draw the two histograms on top of it using the option SAME.
Or put the 2 histrograms in a THStack and draw it using “nostack”.

-first problem; update the stats box
after SetBinContent, add
gPad->Modified();

-setting the maximum along y
myhist->SetMaximum(140);
see also THStack that takes care of computing automatically the best scale for a set of histograms.

Rene

Thanks a lot to both of you for the fast and clear reply!

Renè,

[quote]-setting the maximum along y
myhist->SetMaximum(140);
see also THStack that takes care of computing automatically the best scale for a set of histograms.[/quote]
it worked!

[quote]-first problem; update the stats box
after SetBinContent, add
gPad->Modified();[/quote]
I’ve done like this:

root [66] t->Draw("ntracks >> h(45,0,45)","ntracks>0") (Long64_t)1145 root [67] h->AddBinContent(1,435) root [68] gPad->Modified() root [69] h->Draw()
but the number of entris after the AddBinContent call is always the same as before (1145) and not 1580 as I should expect…
Any suggestion?

The second argument to AddBinContent is not a number of entries, but the weight such that the new bin content will be old_bin_content+weight. This function does not increment the number of entries.
If you want to increment the bin content and also the total number of entries in the histogram, you should do something like

int n = t->Draw("ntracks >> h(45,0,45)","ntracks>0"); double binc1 = h->GetBinContent(1); h->SetBinContent(1,binc1+435); h->SetEntries(n+435);
Rene

Ok Renè,
now it works, but I have another question related to the Y Axis
If I draw a normalized copy of my histogram with the command:

h->DrawNormalized("",389)

after I cannot change the maximum range on Y with the commands

h->SetMaximum(150);
gPad->Modified();

Any other suggestion?

Thanks a lot!
Fabio

TH1::DrawNormalized returns a TH1*, so you should do something like

TH1 *h2 = hpx.DrawNormalized("",389); h2->SetMaximum(15); //or whatever you want
Rene

Thank you very much Renè,
now everything is fine!

Regards,
Fabio