Mean of projections in ROOT

Hi,

I notice that if you fill a TH1, ROOT will use the left bin edge to
calculate the mean. However if you fill a TH2, then project
ROOT will use the bin center to calculate the mean.

Here is a simple macro to illustrate.

{ TCanvas canvas ; canvas.Divide(2) ; TH2D h2("h2","h2",5,0,5,5,0,5) ; TH1D h1("h1","h1",5,0,5) ; for (Int_t i=0; i<9; i++) { h2.Fill(0,0) ; h1.Fill(0) ;} for (Int_t i=0; i<1; i++) { h2.Fill(1,1) ; h1.Fill(1) ;} TH1 * hp = (TH1D*)h2.ProjectionX() ; canvas.cd(1) ; h1.DrawCopy() ; canvas.cd(2) ; hp->DrawCopy() ; }

We fill a TH1 with 0 9 times and with 1 1 time, so the mean should
be 1/10 = 0.1 (left plot). We fill a TH2 with (0,0) 9 times and (1,1) 1 time.
So, a projection of either axis will give the same histogram. However,
the mean in the plot on the left is (90.5 + 11.5)/10 = 0.6. WHY???

You can easily get around this by subtracting half the bin width from the
mean (0.6 - 0.5 = 0.1). However, this effect is inherent in any profile
plots drawn from the TH2.

Is there in option when drawing profile plots to tell ROOT to use
the left bin edge rather than the center?

Chris

The code of the projection functions assume the general case where one projects a subset of all channels.
In this case the information collected at filling time cannot be used for the projection and the statistics are recomputed taking the centre of each bin.
In case one projects all channels, one could of course use the precise information. We will try to implement it in a future version.

Rene