# A problem when fit a 2D graph

// this is the fit function
[color=red]Double_t fit_5( Double_t *x,Double_t *y ,Double_t *par)
{
Double_t fitval=(par[0]*TMath::Exp(par[1]*x[0])+par[2]*TMath::Exp(par[3]*x[0]))*ROOT::Math::assoc_legendre(5,0,cos(y[0]*TMath::Pi()/180));
return fitval;
}

[color=black]// fitf is the combined function function. Function fit_1,fit_2,fit_3,fit_4 is
// like fit_5[/color]
[color=red]Double_t fitf( Double_t *x,Double_t *y, Double_t *par)
{
Double_t fitval=fit_5(x,y,&par[24])+fit_4(x,y,&par[20])+fit_3(x,y,&par[16])+fit_2(x,y,&par[12])+ fit_1(x,y,&par[8])+fit_0(x,y,par);
;

return fitval;

}[/color]

[color=red]TGraph2DErrors *f=new TGraph2DErrors(counter,en,angle,cs,ex,ey,cserror);

f->Draw(“surf1”);[/color]

[color=black]// the graph is drawn correctly

//fit
[/color]

[color=red] TF2 *f2=new TF2(“fit”,fit_0,4,150,0,180,28);

f->Fit("fit");[/color]

but when i fit it ,i got error, said:

[color=blue]Error: G_CallFunc::SetArgArry() must be initialized with ‘G_CallFunc::SetFunc(G_ClassInfo* cls,char fname,char args,long*poffset)’ first [/color]

[code]// this is the fit function
Double_t fit_5( Double_t *x,Double_t *par)
{
Double_t fitval=(par[0]*TMath::Exp(par[1]*x[0])+par[2]*TMath::Exp(par[3]x[0]))
ROOT::Math::assoc_legendre(5,0,cos(x[1]*TMath::Pi()/180));
return fitval;
}

// fitf is the combined function function. Function fit_1,fit_2,fit_3,fit_4 is
// like fit_5
Double_t fitf( Double_t *x, Double_t *par) {
Double_t fitval=fit_5(x,&par[24])+fit_4(x,&par[20])+fit_3(x,&par[16])+fit_2(x,&p
ar[12])+ fit_1(x,&par[8])+fit_0(x,par); ;

return fitval;
}

void fit4() {
//TGraph2DErrors *f=new TGraph2DErrors(counter,en,angle,cs,ex,ey,cserror);

//f->Draw(“surf1”);

// the graph is drawn correctly

//fit

TF2 *f2=new TF2(“fit”,fitf,4,150,0,180,28);

//f->Fit(“fit”);
}[/code]

Rene

Hi Rene ,

the fit function have 2 variable.but in your code ,only 1 variable x .

i use the Double_t fitf(Double_t *x,Double_t *par) likefunction fit TGraph correctly.

i attach my code file .

Thanks a lot!

Wang
fit2Dg_of_diff.c (3.73 KB)

Hi
i got it, x[1] ,is the second variable.

Thanks a lot!