Home | News | Documentation | Download

Error in <TFormula::Eval>: Formula is invalid and not ready to execute, error in fitting

Dear all!

I’m trying to fit TH2F. I defined the fitting function as:

Double_t FitTWC(Double_t *x, Double_t *par){
   Double_t fitval;
   if (par[2] != x[0]) fitval = par[0]- par[1]/(x[0]-par[2]) +par[3]*x[0];
   return fitval;
}

and in main function I tried to fit TH2F:

TF1* fitf = new TF1 ("FitTWC", "FitTWC", 40, 1600, 4);
fitf->SetParameters(1,1,1,1);
h2DNorm->Fit(fitf);

Now I’m getting the error:

Error in <TFormula::Eval>: Formula is invalid and not ready to execute

and cannot understand what is wrong with the TF1. Can anyone help with this problem?
I suppose that fitf->SetParameters(1,1,1,1); only sets the initial values and built-in fitting corrects the values of these parameters. Is this correct?

TF1 *fitf = new TF1("FitTWC", FitTWC, 40., 1600., 4);

Thanks, Wile! I haven’t noticed it.