TH1::Fit inside the FCN of TMinuitMinimizer


_ROOT Version:6.08/04
Platform: Fedora23
Compiler: gcc4.8.5


Hi, I am minimizing a custom function using TMinuitMinimizer. The custom function generates some histogram and then fits the histogram with gaussian function by TH1F::Fit(TF1 *f1 …) method. The problem is after successful iteration of Fcn of TMinuitMinimizer (including TH1F::Fit from inside Fcn), continuation of TMinuitMinimizer ::mnseek() crashes. The crash is definitely caused by TH1F::Fit since as I comment it out, there is no crash.
It seems TH1F::Fit changes the gMinuit created by TMinuitMinimizer. So when TMinuitMinimizer continues with it’s execution there is crash. What’s the solution ? The layout of code is something like this…

MyClass :: SomeFunction("minimizer algo")
{
fMinimizer = new TMinuitMinimizer("minimizer algo") ;
fMinimizer ->SetFunction(this,&MyClass::IterateFcn,ndim) ;
fMinimizer -> Minimize() ;
}
where, 
double MyClass::IterateFcn(const double*)
{
TH1F *hist = new TH1F() ;
... Some processing ....
hist -> Fill() ;
hist -> Fit("gaus") ;
return fitparameter ;
}

I thought of doing following thing. But not sure whether it is safe or not, since I went through the source code of TH1::Fit and saw some shared_ptr s there.

double MyClass::IterateFcn(const double*)
{
TH1F *hist = new TH1F() ;
... Some processing ....
hist -> Fill() ;
TMinuit *saveminuit = gMinuit ;
hist -> Fit("gaus") ;
gMinuit = saveminuit ;
return fitparameter ;
}

Hi,

There is a conflict with the static gMinuit.
Can you try to do before fitting TMinuitMinimizer::UseStaticMinuit( false) ?
Otherwise I would suggest you to use Minuit2 and Minuit2Minimizer,

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.