Hello!
I have a problem with TH2::Fit function.I am trying to fit a 2D histogram wtih a TF2 function.I call the TF2::Fit(“f2”) function several times in my source.I made an iteration of fitting several 2D histograms and when I run it I almost always got this message:
Warning in TH2F::Fit: Abnormal termination of minimization.
When sometimes the Root manages to fit the histos and gives back the parameters they are pretty good.Then I give those values for the initial parameters for the next fit in order to help the fitting rutin but after fitting the first histo the next fit in the loop always gives that message above and
does not even change the initial values at all - even if I give zeros to them:
FCN=0 FROM MIGRAD STATUS=CONVERGED 231 CALLS 232 TOTAL
EDM=0 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 100.0 per cent
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 0.00000e+00 1.41421e+00 0.00000e+00 0.00000e+00
2 p1 -1.00000e-07 1.41421e+00 0.00000e+00 0.00000e+00
3 p2 1.00000e-04 1.41421e+00 0.00000e+00 0.00000e+00
4 p3 6.55000e+03 1.41421e+00 0.00000e+00 0.00000e+00
5 p4 1.00000e+01 1.41421e+00 0.00000e+00 0.00000e+00
So why doesn’t the Root do anything at all to get the least chisquares in this TH2 case if I try to fit several histos in a loop using the same TF2 function and initial values, and why does the Root fit everything well when I fit only a single TH2F histo?
I have ROOT 4.00/06 under windows xp and cygwin.
(I use an array of TH2Fs and I made a class to handle the histos and
the energy ranges that is why h->getHisto(j) is there…)
{
…
TF2 * f2 = (TF2*)gROOT->FindObject(“f2”);
if(f2)delete f2;
f2 = new TF2(“f2”,"(1/[4])*exp(-(x-([1]yy+[2]y+[3]))(x-([1]yy+[2]*y+[3]))0.5/([4][4]))",0,10000,0,10000);
for(int j = 0;j<n;j++){
p1 = -1e-07;
p2 = 1e-04;
p3 = position[j];
p4 = 10;
f2->SetParameter(1,p1);
f2->SetParameter(2,p2);
f2->SetParameter(3,p3);
f2->SetParameter(4,p4);
while(1) {
input >> t >> t_abs >> energy;
if (!input.good()) break;
if((h->GetEmin(j) <= energy) && (h->GetEmax(j) >= energy)){
h->fill(j,energy,t);
}
}
cout << "Fitting #" << j+1 << "..." << endl;
(h->getHisto(j))->Fit("f2");
…
}