Dear Rooters,
I have the feeling that the question is more C++ related than ROOT itself, but with the classes I handle is hard to find an answer.
I am creating a simple event display in 3D. The idea behind is read three std::vector (x,y,z information) from a rootfile, then fill a std:vector of TGraph2D which is sent to a function to plot all the graphs. Here is more or less what I am saying (I am omitting most of the lines, definitions).
vector< TGraph2D* > vGraph;
(...)
for(int j=0; j<numHits; j++)
{
xrec[steps] = xHits->at(j);
yrec[steps] = yHits->at(j);
zrec[steps] = zHits->at(j);
steps++;
}
vGraph.push_back(new TGraph2D(numHits, xrec, yrec, zrec) );
graph2dfile(vGraph);
(...)
void graph2dfile(vector<TGraph2D*> &vGraph)
{
TH3F *frame3d = new TH3F("frame3d","mTPC - Hits/Event",10,-0.15, 0.15, 10, -0.15, 0.15, 10,-0.28,0.28);
frame3d->GetXaxis()->SetTitle("X (mm)"); frame3d->GetXaxis()->SetTitleOffset(1.4); frame3d->GetXaxis()->CenterTitle() ;
frame3d->GetYaxis()->SetTitle("Y (mm)"); frame3d->GetYaxis()->SetTitleOffset(1.4); frame3d->GetYaxis()->CenterTitle() ;
frame3d->GetZaxis()->SetTitle("Z (mm)"); frame3d->GetZaxis()->SetTitleOffset(1.4); frame3d->GetZaxis()->CenterTitle() ;
frame3d->Draw();
for(int kk = 0; kk < NoG; kk++)
{
vGraph[kk] -> SetLineColor(color_wh[kk]);
vGraph[kk] -> SetLineWidth(4);
vGraph[kk] -> SetMarkerStyle(20);
vGraph[kk] -> SetMarkerSize(.9);
vGraph[kk] -> SetMarkerColor(color_wh[kk]);
vGraph[kk] -> Draw("PLINE same");
}
cGraph->Modified();
cGraph->Update();
return;
}
The program works smoothly when reads several events from the rootfile, BUT selecting one event, AND NOT always, just some events, I get the error (after the call of the function, in other words, after the return):
*** Error in
/home/USER/Builds/root6/bin/root.exeâ: free(): invalid pointer: 0x0000000006c921c8 ***`
It bugs me that it happens with just some events which donât have anything special and with others works fine.
If I put the whole function continuously after reading the branches instead of making a function, the error is:
*** Break *** bus error
I am running the code as a script, not compiled.
Any hint will be appreciated
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.22/03
Platform: Linux CENTOS 7
Compiler: gcc (GCC) 4.9.2