TMinuit memory problems

Hello!

I am trying to use TMinuit to get a position corresponding to minimum chi square value. My memory usage seems to be steadily increasing when the code is in the TMinuit part. I do create and delete the TMinuit objects as far as I can see. Am I not doing something right here or am I not doing enough to clear and release memory?

Here’s my code-
global_excl_cheaT3 = new MyClassName(); //this is used to trick TMinuit to thinking it is using a stand alone function; At the end here, I show how this is done.
global_excl_cheaT3 = this;

TMinuit *minuit= new TMinuit(4);
minuit->SetFCN(fcn);

global_excl_cheaT3->Clear();

minuit->SetPrintLevel(-1);
arglist[0]=1;
minuit->mnexcm(“SET NOW”, arglist ,1,ierflg);

for (Int_t i=0; i<4; i++){
minuit->mnparm((Int_t) nprm[i], (TString) pnam[i][0], (Double_t) vstrt[i], (Double_t) stp[i], (Double_t) bmin[i], (Double_t) bmax[i], ierflg);
}
//Simplex
minuit->mnsimp();
//Migrad
arglist[0] = 500;
minuit->mnexcm(“MIGRAD”, arglist ,1,ierflg_Migrad);
//Minos
minuit->mnexcm(“MINOS”,arglist,1,ierflg_Minos);

if (ierflg_Migrad==0){
for (Int_t i=0; i<4; i++){
minuit->GetParameter(i,position[i],position[i+4]);
minuit->mnerrs(i,position[i+8],position[i+12],toto,toto);
}
}

==============================
and here’s how I feed a stand alone function to TMinuit
MyClassName *global_excl_cheaT3;

void fcn(Int_t &npar,Double_t *gin, Double_t &f, Double_t *par, Int_t iflag) {

/*
“TMinuit::SetFCN can not take a member functions as argument. You need to use a free standing function.”
– from ROOT Talk forum
so this is a way to trick TMinuit::SetFCN to think that it’s taking a free standing function as an argument
*/

global_excl_cheaT3->minifcn(npar,gin, f, par, iflag);

}

=============================
And the minifcn itself is like this-
void MyClassName::minifcn(Int_t &npar,Double_t *gin, Double_t &f, Double_t *par, Int_t iflag) {

Double_t *th; th = new Double_t[num_chan];

for (Int_t i=0; i<num_chan; i++){
th[i]=sqrt( TMath::Power((par[0]-xi[i][0]),2.) + TMath::Power((par[1]-xi[i][1]),2.) + TMath::Power((par[2]-xi[i][2]),2.) )/v;
}

f=0;
for (Int_t i=0; i<num_chan; i++){
f=f+(TMath::Power(( ( (result[i+0]-par[3])-(th[i]) )/result[i+2] ),2.));
}
delete [] th; th = NULL;

return ;
}

Thank you!

  • Sujeewa

ok, I think I fixed it; it was some other object that I had not deleted. Thanks and sorry for the bother!