In my macro I first define my function “PeakFit” and want to call it my main part - but always root says something like: "Bad numerical expression : “PeakFit”"
My code looks like:
Double_t PeakFit(Double_t *x, Double_t *par) {
...//MyFunction with 5 parameters
}
void MyFit(){
Double_t par[11];
g1 = new TF1("g1","pol2",-0.3,-0.1);
g2 = new TF1("g2","pol2",0.1,0.3);
signal = new TF1("signal","PeakFit",-0.1,0.1);
TF1* fitFcn = new TF1("fitFcn","PeakFit+g1+g2",-0.3,0.3,11);
Histo2fit_DeltaE->Fit("g1","ERL");
Histo2fit_DeltaE->Fit("g2","ERL+");
Histo2fit_DeltaE->Fit("signal","ERL+");
g1->GetParameters(&par[0]);
g2->GetParameters(&par[3]);
signal->GetParameters(&par[6]);
fitFcn->SetParameters(par);
Histo2fit_DeltaE->Fit("fitFcn","ERL+");
Histo2fit_DeltaE->Draw();
...
}
I already used this example for defining my own functions but I could not manage to combine:
FittingDemo.C - self-defined functions fitted over the whole range and
multifit.C - pre defined functions fitted in single sub-ranges
into a macro fitting self-defined functions in sub-ranges.
I defined a function as in FittingDemo.C and tried to use it according to multifit.C instead of the pre-defined gaussian.
Apparently I cannot simply replace in TF1(const char* name, const char* formula, Double_t xmin = 0, Double_t xmax = 1) the formula character (i.e. “gaus”) by an own functions, which leads to a “Bad numerical expression” error.
Did you look carefully to FittingDemo.C ?
In particular note the different TF1 constructors for simple functions
where the function is given by name (“name”)
and the others where you give a function pointer (without the “”) and
tha additional argument giving the number of parameters.
If you still have problems, please send the shortest possible script
that we can execute.