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;
cout.precision(10);
/* 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);
}
else
{
TH1D h4 = new TH1D(“h4”,“Delta N”,integrationnumber,(-0.5integrationnumber),(0.5integrationnumber));
}
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;
//added
differenceCounter50Mhz = currentCounterValue50Mhz - oldCounterValue50Mhz;
oldCounterValue50Mhz = currentCounterValue50Mhz;
// 20 Mhz part
differenceClock20Mhz = currentClockValue20Mhz - oldClockValue20Mhz;
oldClockValue20Mhz = currentClockValue20Mhz;
/*
//Remove the first data which is not correct
if(jentry!=integrationnumber)
{
h1->Fill(differenceCounter50Mhz);
h2->Fill(differenceClock20Mhz);
}
else{
continue;
}
*/
// 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;
h4->Fill(deltan);
/*
// Compute rho
rho = (time50Mhz - time20Mhz)/(time50Mhz + time20Mhz);
h3->Fill(rho);
*/
// }
// end of adding
}
/*
c2->cd();
h1->Draw();
c3->cd();
h2->Draw();
c4->cd();
h3->Draw();
*/
c5->cd();
h4->Draw();
// h4->GetMean();
// h4->GetRMS(1);
}
[/code]
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.