I want to fit my histogram, I made a user defined fomula as the following, and everything in this formula defined before TF1 declare.
TF1 *f = new TF1("Correlation","(TMath::Log10(GAIN)*TMath::Log10(n+1))/(TMath::Log10(HV[hv])*n)");
GAINCorr->Fit(f);
However, I got this error !
input_line_134:1:82: error: use of undeclared identifier 'GAIN'
Double_t TFormula____id7729400694293341383(){ return (TMath::Power(TMath::Log10({GAIN}),TMath::Log10({n}+1)))//(TMath::Power(TMath::Log10({HV[hv]}),{n})) ; }
^
input_line_134:1:103: error: use of undeclared identifier 'n'
Double_t TFormula____id7729400694293341383(){ return (TMath::Power(TMath::Log10({GAIN}),TMath::Log10({n}+1)))//(TMath::Power(TMath::Log10({HV[hv]}),{n})) ; }
^
<<< cling interactive line includer >>>:1:1: error: expected '}'
^
input_line_134:1:45: note: to match this '{'
Double_t TFormula____id7729400694293341383(){ return (TMath::Power(TMath::Log10({GAIN}),TMath::Log10({n}+1)))//(TMath::Power(TMath::Log10({HV[hv]}),{n})) ; }
^
Error in <TFormula::Eval>: Can't find TFormula____id7729400694293341383 function prototype with arguments
Error in <TFormula::ProcessFormula>: "HV[hv]" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: "GAIN" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: "n" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: Formula "(pow(TMath::Log10(GAIN),TMath::Log10(n+1)))//(pow(TMath::Log10(HV[hv]),n))" is invalid !
Error in <Fit>: function Correlation has illegal number of parameters = 0
What’s wrong with this formula ?
Can anybody help me about this problem ?
There are some rules to follow for the variable and the parameters: see TF2 and TF1.
In particular, the variables on the axis are named ‘x’ and ‘y’, the parameters vector par[…] .
You try to fit a 2-dimensional histogram with a 1-dimensional function?
BTW. Do remember that you need to set “reasonable” initial values for all parameters of your function, before you try to fit your histogram (otherwise the fitting procedure may easily misbehave).
I have tried some initial values for fitting, which i chose them by visual inspection for a specific range according to theoretical formula, but, of course, the results of fit are different from each other for each initial value ! Is this a problem ?
Why doesn’t ROOT choose the best ‘optimised’ initial value for fitting ?
So, How might i choose the best optimised initial value for fitting with an user-defined function ?