GetRMS () and GetMean() trouble

Hello everybody.

I used a TNtuple object to store data into a .root file. To read the data I used the function MakeClass() with create the .C and .h file to read the data.
I have modified the .C file to draw the histogram of the data witch interested me. But the only problem is that I want to know the mean and the RMS of the histogram. And when I use the function h1.GetMean() and h1.GetRMS(), the values return by this function is different to the value appearing on the histogram.
In addition, when I save the histogram on a .C file and reload it after, the mean and the RMS is also different.
So my question is, what the correct way to get the RMS and the mean ?

The version of Root we used is the : 5.26/00

Thank for your help.

[quote=“Pepe Le Pew”][/quote]
Thanks for your reply but I already looked at that.

The problem is that when I call the function GetRMS() and GetMean(), the results are different from what one can see in the histogram itself. The returned values are wrong.

When I save it as a .C file and open it again in ROOT, the values are different and seem to be right.
The question is: what causes this, and how can I get the correct values the first time?

It is an one-dimensional histogram by the way.

Maybe you could post that “.C” file here for inspection (and post the “values” you get / expect, too).

After some research I found out what the problem is.

I use the Loop() function in the .C file created by the MakeClass() function.
The computer calculates the GetMean() value for the first time. If the program is used a second time, the returned value for GetMean() is the same as for the first time. It remembers the value and doesn’t compute it again. How can this be solved?

And when it is saved as a .C file and reopened again, it also displays a different value.

Here’s the program:

[code]#define bigfile_cxx
#include “bigfile.h”
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

void bigfile::Loop(Int_t integrationnumber)
if (fChain == 0) return;

Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;

Double_t startRange50Mhz = (integrationnumber * 0.999 * 50e3);
Double_t endRange50Mhz = (integrationnumber * 1.001 * 50e3);

Double_t startRange20Mhz = (integrationnumber * 0.999 * 20e3);
Double_t endRange20Mhz = (integrationnumber * 1.001 * 20e3);

Double_t beamNumber20Mhz = endRange20Mhz- startRange20Mhz;
Double_t beamNumber50Mhz = endRange50Mhz- startRange50Mhz;

ULong_t fullRange = 0x100000000;


/* TH1D *h1 = new TH1D(“h1”,“50Mhz counter”,beamNumber20Mhz,startRange50Mhz,endRange50Mhz);
TCanvas *c2 = new TCanvas(“c2”,“50Mhz”);
h1->GetXaxis()->SetTitle(“Number of counts”);
h1->GetYaxis()->SetTitle(“Number of occurances”);

TH1D *h2 = new TH1D(“h2”,“20Mhz clock”,beamNumber50Mhz,startRange20Mhz,endRange20Mhz);
TCanvas *c3 = new TCanvas(“c3”,“20Mhz”);
h2->GetXaxis()->SetTitle(“Number of counts”);
h2->GetYaxis()->SetTitle(“Number of occurances”);

TH1D *h3 = new TH1D(“h3”,“Rho(50Mhz - 20Mhz)”,1000,-20,20);
TCanvas *c4 = new TCanvas(“c4”,“Rho”);
h3->GetXaxis()->SetTitle(“Time difference [ms]”);
h3->GetYaxis()->SetTitle(“Number of Occurances”);

if (integrationnumber<=5)
TH1D h4 = new TH1D(“h4”,“Delta N”,100,-5,5);
TH1D h4 = new TH1D(“h4”,“Delta N”,integrationnumber,(-0.5integrationnumber),(0.5

TCanvas *c5 = new TCanvas(“c5”,“Delta N”);
h4->GetXaxis()->SetTitle(“Number of counts”);
h4->GetYaxis()->SetTitle(“Number of occurances”);

Double_t oldCounterValue50Mhz = 0;
Double_t oldClockValue20Mhz = 0;

Double_t time20Mhz ;
Double_t time50Mhz ;

Double_t deltan ;
Double_t rho ;

Double_t differenceCounter50Mhz;
Double_t differenceClock20Mhz;

for (Long64_t jentry=integrationnumber-1; jentry<nentries; jentry=jentry+integrationnumber)

   //test if jentry is equal to an integer multiple integrationnumber

// if(jentry%integrationnumber==0 && jentry!=0)
// {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;

differenceCounter50Mhz = currentCounterValue50Mhz - oldCounterValue50Mhz;
oldCounterValue50Mhz = currentCounterValue50Mhz;

   // 20 Mhz part
   differenceClock20Mhz = currentClockValue20Mhz - oldClockValue20Mhz;
   oldClockValue20Mhz = currentClockValue20Mhz;

//Remove the first data which is not correct
// Convert number of counts to time
time50Mhz = differenceCounter50Mhz /5e4 ;
time20Mhz = differenceClock20Mhz /2e4 ;

   // Compare 50MHz counter to 20MHz clock
   deltan = differenceCounter50Mhz - (differenceClock20Mhz *(5.0/2.0));
   cout << differenceCounter50Mhz << "    "  << differenceClock20Mhz << endl;

// Compute rho
rho = (time50Mhz - time20Mhz)/(time50Mhz + time20Mhz);
// }
// end of adding





// h4->GetMean();
// h4->GetRMS(1);

The values for integrationnumber= 10 are
-2.13083478 for the mean.
8.85921696 . 10^-1 for the RMS.

And if I open the histogram from the .C file in which I stored it, it is:
-2.05700173 for the mean.
1.06430603 .10^-1 for the RMS.

Just in the beginning of your “Loop” method (before you create any histograms), try to add one line: TH1::SetDefaultSumw2(kTRUE);

This works for getting the same value when the stored histogram is reloaded. But it changes the histogram to a kind of scatter plot. And it also changes the value compared to when the line is not added. I’m not sure if I understand what the function does exactly. Could you please explain it?

Search for the string “Sumw2” in
In particular see and
For the histogram drawing options (in particular note the “HIST” option) see