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?
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.
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