Dear Rooters,
For my work, I was using valgrind to debug and check some of the leaks. I’m still kinda new to this…
I would appreciate any help. It is such a comprehensive code. So i’d like to understand how fix other similar issues.
Valgrind gave me the following errors:
==2619== Conditional jump or move depends on uninitialised value(s)
==2619== at 0x551A0FC: TObject::TObject() (in /cr/augerdata/OfflineSource/Externals/ev17/s4/External/root/5.34.00-14d831f5b4/lib/root/libCore.so)
==2619== by 0x4F9B96C: TFile::Close(char const*) (in /cr/augerdata/OfflineSource/Externals/ev17/s4/External/root/5.34.00-14d831f5b4/lib/root/libRIO.so)
==2619== by 0x450BCA: ToyShowerNS::ToyShower::SetMPD(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&) (ToyShower.cc:1683)
==2619== by 0x436472: treatSubBlock(float*, int) (resampler.cc:267)
==2619== by 0x435A02: main (resampler.cc:170)
(>> some other stuff)
==2619== 1,081 (576 direct, 505 indirect) bytes in 1 blocks are definitely lost in loss record 33,723 of 34,288
==2619== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2619== by 0x559AA28: TStorage::ObjectAlloc(unsigned long) (in /cr/augerdata/OfflineSource/Externals/ev17/s4/External/root/5.34.00-14d831f5b4/lib/root/libCore.so)
==2619== by 0x4592C5: TObject::operator new(unsigned long) (TObject.h:156)
==2619== by 0x450590: ToyShowerNS::ToyShower::SetMPD(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&) (ToyShower.cc:1642)
==2619== by 0x436472: treatSubBlock(float*, int) (resampler.cc:267)
==2619== by 0x435A02: main (resampler.cc:170)
(>> some other stuff)
==2619== 12,193 (184 direct, 12,009 indirect) bytes in 1 blocks are definitely lost in loss record 34,161 of 34,288
==2619== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2619== by 0x559AA28: TStorage::ObjectAlloc(unsigned long) (in /cr/augerdata/OfflineSource/Externals/ev17/s4/External/root/5.34.00-14d831f5b4/lib/root/libCore.so)
==2619== by 0x4592C5: TObject::operator new(unsigned long) (TObject.h:156)
==2619== by 0x4506E5: ToyShowerNS::ToyShower::SetMPD(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&) (ToyShower.cc:1646)
==2619== by 0x436472: treatSubBlock(float*, int) (resampler.cc:267)
==2619== by 0x435A02: main (resampler.cc:170)
The function ToyShower::SetMPD(…) is:
void ToyShower::SetMPD(std::vector< std::vector<double> >& vMPD) {
TH1D *hMPD = new TH1D("hMPD","hMPD",600.,0.,3000.); //bin size of 5 [g/cm2]
double hX = UNDEF, h = UNDEF, theta = UNDEF, weight = UNDEF;
double minX = UNDEF, maxX = UNDEF;
double Xmumax = UNDEF, Nmumax = UNDEF, hmumax = UNDEF, chi2 = UNDEF;
for(int i =0 ; i< vMPD.size(); i++){
theta = acos(vMPD[i][1]);
h = vMPD[i][2];
weight = vMPD[i][3];
hX = fatm.HeightToSlantDepth(h,theta); //inclined X
if( ToyUtilsNS::X_AugerGroundLevel(hX,theta) ) continue;
hMPD->Fill(hX, weight);
}
minX = hMPD->GetBinCenter(hMPD->GetMaximumBin()) - 200./cos(theta);
maxX = hMPD->GetBinCenter(hMPD->GetMaximumBin()) + 300./cos(theta);
maxX = (maxX > 875/cos(theta) ? 875/cos(theta) : maxX);
TF1 *ghFunc = new TF1("ghFunc",ToyShowerNS::GHFunc, minX , maxX , 4);
ghFunc->SetParameters(3*hMPD->GetMaximum(), hMPD->GetBinCenter(hMPD->GetMaximumBin()) , -1. , 70.);
//--- ROOT5 has some issues calculating chi2 with TH1. It is somehow resolved with ROOT6 (i use tgraph as a workaround for ROOT5)
TGraphErrors *grMPD = new TGraphErrors();
grMPD->SetName(Form("%dMPD",GetShowerId()));
int nbinsx = hMPD->GetXaxis()->GetNbins();
double rebin_x = 0., rebin_y = 0.,rebin_yerr = 0., bincnt = 0.;
for(int ih1 = 0; ih1 < nbinsx; ih1++){
int ihgr = grMPD->GetN();
bincnt++;
rebin_x += hMPD->GetBinCenter(ih1);
rebin_y += hMPD->GetBinContent(ih1);
rebin_yerr += (hMPD->GetBinContent(ih1)) * (hMPD->GetBinContent(ih1));
if ((int) bincnt == 3 || ih1 == (nbinsx-1)) {
rebin_x = rebin_x / bincnt;
rebin_yerr = sqrt( (bincnt/ (bincnt-1.)) * (rebin_yerr/ bincnt - (rebin_y / bincnt)*(rebin_y / bincnt)) ); //variance of those those bins
grMPD->SetPoint(ihgr,rebin_x,rebin_y);
grMPD->SetPointError(ihgr,0.,rebin_yerr);
rebin_x = 0., rebin_y = 0.,rebin_yerr = 0., bincnt = 0.;
}
}
grMPD->Fit("ghFunc", "QR");
//---
//ghFunc->SetParameters(hMPD->GetMaximum(), hMPD->GetBinCenter(hMPD->GetMaximumBin()) , -1. , 70.);
//hMPD->Fit("ghFunc", "R");
chi2 = (ghFunc->GetChisquare()) / ( ((maxX - minX) / 15.) - 4.);
Nmumax = ghFunc->GetParameter(0);
Xmumax = ghFunc->GetParameter(1);
hmumax = fatm.SlantDepthToHeight(Xmumax, theta);
printf("Xmumax from GH-fit: %lf[g/cm2] with chi2: %lf \n" , Xmumax , chi2);
TFile *f = new TFile(Form("%s/%d.rLONG",ProductionDataPath,GetShowerId()),"update");
grMPD->Write();
f->Close();
delete hMPD, ghFunc, grMPD, f;
cinfo.Xmumax = Xmumax;
cinfo.Chi2Xmumax = chi2;
cinfo.hmumax = hmumax;
cinfo.Nmumax = Nmumax;
}