Re: [ROOT] Mean calculation in TH1

From: Victor Perevoztchikov (perev@bnl.gov)
Date: Wed Sep 15 2004 - 20:30:54 MEST


> The changing of the mean confuses people a little bit.
If  accept , that ROOT always use the most precise approach, then no
confusion at all.
Victor
Victor M. Perevoztchikov   perev@bnl.gov
Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
tel office : 631-344-7894; fax 631-344-4206;

----- Original Message ----- 
From: "Andrei Kuznetsov" <Andrei.Kouznetsov@cern.ch>
To: "Rene Brun" <Rene.Brun@cern.ch>
Cc: "Andrei Kuznetsov" <Andrei.Kouznetsov@cern.ch>; "Root Mailinglist"
<roottalk@cern.ch>
Sent: Wednesday, September 15, 2004 12:36 PM
Subject: Re: [ROOT] Mean calculation in TH1


>
> {
>   gROOT->Reset();
>   TCanvas *cr = new TCanvas("cr","Amplitude",200,10,800,600);
>   TH1D *h=new TH1D("Pixel","Pixel",13,0,13);
>   for(Int_t i=0;i<6;i++) h->Fill(10*gRandom->Rndm());
>   cout<<"Mean befor SetRange ="<<h->GetMean()<<endl;
>   h->GetXaxis()->SetRange(0,12);
>   cout<<"Mean after SetRange ="<<h->GetMean()<<endl;
>   h->Draw();
>   cr->Update();
>   cr->Pop();
> }
>
> The changing of the mean confuses people a little bit.
>
> Best regards,
> Andrei.
>
>
> On Wed, 15 Sep 2004, Rene Brun wrote:
>
> > Andrei,
> >
> > The member fTsumwx is incremented in the TH1::Fill methods using the
true
> > value of the x coordinate. TH1::GetMean returns the mean using this
value.
> >
> > However, when you zoom via TAxis::SetRange, ROOT recomputes the mean
value
> > using the bin contents and the center of each bin.
> >
> > I do not see any problems with this method. If you have evidence of the
> > contrary, please send the shortest possible running script showing the
> > problem.
> >
> > Rene Brun
> >
> > Andrei Kuznetsov wrote:
> > >
> > > Hello,
> > >
> > > it looks like ROOT calculates fTsumwx (and hence Mean of a histogram)
in
> > > TH1 incorrectly.
> > >
> > > But if you perform
> > > your_histogram->GetXaxis()->SetRange(a,b);
> > > after the filling (or "zoom" by hands) it works correctly.
> > >
> > > It looks likes in the first case it is not used the center of bin when
> > > fTsumwx is calculated.
> > >
> > > Best regards,
> > > Andrei.
> >
>



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET