Re: root : strange behaviour of AddBinContent()

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Fri, 2 Sep 2011 15:59:42 +0000


Hi,

 TH1::Fill(x), finds the right bin number, add the bin content and update the histogram statistics (entries, total sum of weights , etc.._ ) and in case of weighted histogram the bin sum of weight square. If you want to be faster (like calling AddBinContent) you need to give up some of the other information. You can always set the entries later using SetEntries

Cheers,
 Lorenzo
On Sep 2, 2011, at 4:24 PM, Marc Escalier wrote:

> Hello,
>
> it seems that there is a strange behavior of TH1::AddBinContent()
>
> intuitively, i would think that adding a content to a bin would mean that the number of entries should increase,
> as it is when one does TH1::Fill(1) (apart that this last comment is very slow)
>
> but :
>
> root [0] TH1F *hist_initial_events=new TH1F("hist_initial_events","hist_initial_events",20,0.5,20.5);
> root [1] hist_initial_events.GetEntries()
> (const Double_t)0.00000000000000000e+00
> root [3] hist_initial_events->AddBinContent(1)
> root [4] hist_initial_events.GetEntries()
> (const Double_t)0.00000000000000000e+00
>
> root [5] hist_initial_events.GetBinContent(1)
> (const Double_t)1.00000000000000000e+00
>
> -->
> *is the fact that AddBinContent() does not increase the number of entries expected ?
>
> *On other subject, is there a way to find a much faster command that TH1::Fill to add 1 to an histogram ?
>
> (i see that a simple counter "int" is much more faster, but i need a TH1 for proof, because TH1 derivates from a TObject and the fOutput needs derivatives from TObject : it can not deal with common counters ; and recreating a class derivated from TObject with an integer is rather painful for a clean implementation)
>
> thanks for your help
>
Received on Fri Sep 02 2011 - 17:59:51 CEST

This archive was generated by hypermail 2.2.0 : Fri Sep 02 2011 - 23:50:02 CEST