I am trying to fit a function of the form f(x) = Integral g(x,y ; a,b )dy with a data set. The limits of the integral are (0,+inf) but instead of inf I can put a value at which the function g(x,y=value) is basically 0.
Of course the integrand cannot be solved analythically otherwise there were not be any problem.
N.B ‘a’ and ‘b’ are free parameters need to be calculated from the fit.
N.B.B: the function g is a function of two variables g(x,y) but after integrating over y i get a 1D function of x.
I tried the following lines but it does not seem to work (just returns the initialization parameters and the fit always converges, it seems like he’s not trying to work out the optimal parameters):
Double_t ef(Double_t *x, Double_t *p)
{
return ( sin(2.*2.13*sin(x[0]/2.)*x[1])*x[1] )/( 1. + exp( ( x[1] - p[0] )/p[1] ) );
}
Double_t funct(Double_t *x, Double_t *p)
{
TF2 *f1=new TF2("f1",ef,0,M_PI,0,10*0.55+4.37,2);
f1->SetParameters(p[0],p[1]);
TF12 *f12=new TF12("f12",f1,x[0],"y");
double B = 5.8e-4; //fm^-4
double momentum = 2.13; //fm^-1
Double_t sum=f12->Integral(0,10*0.55+4.37);
delete f1;
return (B/(momentum*momentum))*( pow(sum , 2) )/( pow( sin( x[0]/2. ) , 6 ));;
}
int main (){
.............
TF1 *myFun=new TF1("myFun",funct,0,M_PI,2);
myFun->SetParName(0,"R"); //par names
myFun->SetParName(1,"a");
myFun->SetParameter(0,4.37);
myFun->SetParLimits(0,0.1,10); //starting values and par limits
myFun->SetParameter(1,0.55);
..........
TFitResultPtr r = myGraph -> Fit("myFun", "S");
........
}
Does someone knows how to work this out?
Thank you in advance.
ROOT Version: 6.18
Compiler: c++