Re: histogram statistcs

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Apr 30 1997 - 08:46:08 MEST


Robert Loke wrote:
> 
> Hi !
> 
> I tried to copy a part of a histogram h1 to another histogram h2. The
> (straight forward) way to do this is:
> 
> for(int ii=int(lower_bin);ii<int(upper_bin);ii++)
>   h2->SetBinContent(ii,h1->GetBinContent(ii));
> 
> with h1 and h2 defined as TH1Ds.
> 
> Doing it this way leads to the problem that the statistics of h2 is not
> calculated. Therefore you've no access to data like mean value and rms.
> 
> Is there a better (=working) way to perform this?
>

The SetBinContent function, as you say, does not increment histogram statistics.
To copy histograms (or make operations between histograms) you can use the normal
C++ operators.
  Example1:
    Assume a TH1F object h1
    Root > TH1F h2 = h1 ; h2 is a new object and is a copy of h1
    Root > TH1H h3 = 2.5*h1 + 3.2*h2

  Example2:
    Assume a pointer to a TH1F.  TH1F *h1;
    Root > TH1F h2 = (*h1);  You must use the dereferencing operator * to get the object
    Root > TH1F h3 = 2.5*(*h1) + 3.2*h2;
Note that in case of pointers to histograms (TH1F *h1, *h2)
it would be wrong doing: TH1F h3 = h1+h2  (adding two pointers!!!)

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:18 MET