I have written a C++ code that I compile with g++, and I am using ROOT libraries.
I have a code that looks at data files, does a simple curve fit, and outputs the parameters.
The code works fine for 1,000 sequential files without any errors.
If I try to do randomly addressed data files though, the code crashes around 350 files. I get the error
“Warning in : Fit data is empty”
after about 350 data files. Remember these are randomly selected data files, and it consistently generates this error around 350 files, so I think this is some kind of memory error.
What are the causes of that kind of error? How can I make sure there are no memory issues with TF1?
Here is the sub-loop. There is more code around this, but I think the memory management might be coming from in here:
for(int n = 0; n < length; n++) {
t1->GetEntry(n);
double fitpar[3];
TH1F* Leakage = new TH1F("Leakage","Leakage", 12, -0.5, 11.5);
for(int tbin = 0; tbin < 12; tbin++) {
double sigsum = 0;
double sigave = 0;
for(int det = 0; det < ndets; det++) {
double signal = detector[det]->EvalInstance(tbin);
sigsum += signal;
} // loop over detectors
sigave = sigsum/ndets;
Leakage->Fill(tbin,sigave);
}
TF1 *polyfit = new TF1("polyfit","pol3",0,11);
TCanvas* LCanvas=new TCanvas("Leakage","",1440,900);
Leakage->Fit("polyfit","q");
delete LCanvas;
polyfit->GetParameters(fitpar);
Poly0->Fill(fitpar[0]);
Poly1->Fill(fitpar[1]);
Poly2->Fill(fitpar[2]);
Poly3->Fill(fitpar[3]);
delete Leakage;
delete polyfit;
}
What could be causing this?