A routine that alwas locks the computer

Hi, is there something wrong with this method? Always when Neven > 1e6 this starts reading the hd and freeze my computer. It read the hd because its using too much memory? Because i just see that using processor, and i can’t get what is the problem.

Thanks,
Gabriel

TH2D* TPDF::GenerateH(ULong_t Neven, TString name, Int_t xbin, Double_t xmin, Double_t xmax, Int_t ybin, Double_t ymin, Double_t ymax)
{

Double_t x, y;
Double_t M;

TH2D* h=new TH2D(name,“histo”,xbin,xmin,xmax,ybin,ymin,ymax);

TRandom3 r(0);

for (ULong_t i=0; i< Neven; i++) {

for (;;)    {
                                                                                                                         
x=(xmax-xmin)*r.Rndm()+xmin;
y=(ymax-ymin)*r.Rndm()+ymin;
                                                                                                                         
//Get a signal random M and return a,b under pdf
M=decay->GetMRandSig();
                                                                                                                         
if (decay->IsPS(x,y,M)) {
    if (r.Rndm() <= Pdf(x,y))   {
        h->Fill(x,y);
        break;
        }
    }
}

}

TPDF::h=h;
return h;
}

Hi Gabriel,

I can’t see anything wrong with it. Try to debug it using a process viewer (“top” on linux, “Ctrl-Alt-Del, tab processes” on windows, look at root.exe). If that shows large mem usage by root.exe then there is something wrong. Comment all the statements in your macro but the ones constructing a new and empty TH2D, setting it for TPDF, and returning it. If the mem usage doesn’t drop then the problem is not in this method. Otherwise add back statement by statement, by un-commenting line by line, and find out which one causes it.

Cheers, Axel.

Hi Axel,
when I uncommented the random number generation, it worked fine.
So first i tried to use the GSL library random routine. This gives the same problem.
After that i tried to delete the random number and create again for each 100k events. Dont work.
Tried to coment de decay methods, that was not the problem.
The top is indicating 70% mem usage (this oc have 1Gb ram).

The actual code is:

TH2D* TPDF::GenerateH(ULong_t Neven, TString name, Int_t xbin, Double_t xmin, Double_t xmax, Int_t ybin, Double_t ymin, Double_t ymax)
{
//Print begin
cout << "Generating " << Neven << “events:” <<endl;

Double_t x, y;
Double_t M;

TH2D* h=new TH2D(name,“histo”,xbin,xmin,xmax,ybin,ymin,ymax);

TDatime *t=new TDatime();

TRandom3 *r=new TRandom3(t->GetTime());

ULong_t i=0;
ULong_t j=0;

Double_t deltax=xmax-xmin;
Double_t deltay=ymax-ymin;

for (i=0; i< Neven; i++) {

if (j > 1e4)    {
    delete t;
    delete r;
    TDatime *t=new TDatime();
    TRandom3 *r=new TRandom3(t->GetTime());
                                                                                                                         
    j=0;
    cout << "10k" << endl;
    }
                                                                                                                         
for (;;)    {
                                                                                                                        
x=deltax * r->Rndm() + xmin;
y=deltay * r->Rndm() + ymin;
                                                                                                                                                                                                                                                     
//Get a signal random M and return a,b under pdf
M=decay->GetMRandSig();
                                                                                                                         
if (decay->IsPS(x,y,M)) {
    if (r->Rndm() <= Pdf(x,y))   {
        h->Fill(x,y);
        j++;
        break;
        }
    }
}

}

delete r;
delete t;

//Print end
cout << “DONE” <<endl;

TPDF::h=h;
return h;
}

Thanks for the help, the problem was in the Pdf(x,y) method. I was deleting the allocated pointers outside the loop… Becareful people, this is a easy error to make!

for (Int_t i=0; i < Namp; i++) {
TComplex* c=new TComplex(A[i]->Mag(), A[i]->Phase(), true);
sum+= *c * A[i]->Amp(x, y) / sqrt(ANorm[i]);
}
delete c; //MEMORY LEAK!!!