2D histogram question


I create 2D histograms and then look at the statistic with

cout<GetEntries()<<" photons detected"<<endl;
cout<<"Mean x = "<ProjectionX()->GetMean()<<endl;
cout<<"Mean y = "<ProjectionY()->GetMean()<<endl;
cout<<"RMS x = "<ProjectionX()->GetRMS()<<endl;
cout<<"RMS y = "<ProjectionY()->GetRMS()<<endl;

The problem is that a typical output

1220 photons detected
Mean x = -0.0697131
Mean y = 0.0266393
RMS x = 1.79072
RMS y = 1.7959

is different from the label of that histogram in a rootfile, which state

Entries 1220
Mean x -0.07061
Mean y 0.02715
RMS x 1.791
RMS y 1.796
(see attachment)

The differences are tiny but still…
What is the problem?


When making a ProjectionX,Y, a new TH1 object is created and the statistics for this new object are computed from the bin contents
assuming the center of each bin, while in the original histogram,
the statistics had the full precision using the original x,y values when filling it.

In your case instead of calling
you should call

It will faster and more precise (no need to create the projection object if you do not need it)