'Fit' using only fixed parameters fails


I am a bit confused by my fit – I try to fit a 2D histogram using two uncorrelated functions. As start parameters I am using fit results from the 1D projection fits.

Since the 2D fit failed I fixed all parameters just to see, who the 2D function would look like with the given start parameters (and then let one by one parameter float). But even the ‘fit’ with only fixed parameters fails and returns as additional error message:

Warning in <TCanvas::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.
Warning in <TCanvas::ResizePad>: cMinvLCPi width changed from 0 to 10
Warning in <TCanvas::ResizePad>: cMinvLCPi height changed from 0 to 10
Error in <TPainter3dAlgorithms::FindLevelLines>: number of points for line not equal 2
Error in <TPainter3dAlgorithms::FindLevelLines>: number of points for line not equal 2
Error in <TPainter3dAlgorithms::FindLevelLines>: number of points for line not equal 2

I would have expected that at least with all parameters fixed the fit should ‘converge’ or do I misconceive Root’s fit here?

Cheers & Thanks for ideas,

Please post a running script (and data file) Noting that we can do without.


Hi Rene,

I create a 2D fit function (consisting of a Gaussian and a function uncorrelated to the Gaussian)

Double_t PeakFit(Double_t *x, Double_t *par) 
  Double_t ParX = x[0], ParY = x[1];
  Double_t Nev = par[0], mu1 = par[1], sigma1 = par[2];
  Double_t ParA = par[3], ParB = par[4], ParC = par[5], ParX2425 = x[0]-2.425;
  Double_t BinWidthX = par[6], BinWidthY = par[7]
  Double_t BinArea= BinWidthX*BinWidthY;

  return BinArea*Nev*(
			 1/TMath::Max(1.e-10,(TMath::Sqrt(2*TMath::Pi()) * TMath::Max(1.e-10,sigma1)) )
		 *  TMath::Exp(
			      -0.5 * pow(((ParX-mu1)/TMath::Max(1.e-10,sigma1)),2.) )

In my main I use this function to fit my (TH2D) histogram (I think it is pretty straightforward )

 [code]   TF2* fitFcn = new TF2("fitFcn",PeakFit,5.2,5.35,2.45,3.4,8); 

    TH2D* Histo2fit=(TH2D*) hMinvLCplPipl_1->Clone();
    TAxis *xaxis = Histo2fit_Mes->GetXaxis();
    TAxis *yaxis = Histo2fit_Mes->GetYaxis();

    fitFcn->SetParameter(0,70000);   // ~N

    fitFcn->FixParameter(1,5.2792);  // Gauss ~Mean1
    fitFcn->FixParameter(2,0.001); // Gaus ~Breite1

    fitFcn->FixParameter(3,3.5);  // Poly ParA
    fitFcn->FixParameter(4,1.4); // Poly ParB
    fitFcn->FixParameter(5,0.7); // Poly ParB
    fitFcn->FixParameter(6,xaxis->GetBinWidth(1)); // BinWidthX
    fitFcn->FixParameter(7,yaxis->GetBinWidth(1)); // BinWidthY

    Int_t iFitResult= Histo2fit  -> Fit("fitFcn","VERML");
    TString sMinuitErgebnis = gMinuit->fCstatu;

But the fit dies every time regardless fixed or floating parameters?

I cannot execute your script because your histogram is missing.
I suggest to put print statements in your function PeakFit to find out the elements that generate a NaN