TGraph fit problem

Hello,
I’m trying to fit a TGraph, but I get the following error several times:

Error: G__CallFunc::SetArgArray() must be initialized with ‘G__CallFunc::SetFunc(G__ClassInfo* cls,char* fname,char* args,long* poffset)’ first…

Here’s the sample script:

//-----------------------------------------

int adc0_test()
{
gROOT->SetStyle(“Plain”);
gStyle->SetOptTitle(0);

TCanvas c1 = new TCanvas(“c1”,“With NIM”,200,10,700,500);
//c1->Divide(2,2);
c1->SetFillColor(10);
c1->SetFrameFillColor(10);
c1->SetBorderSize(2);
//
***************************************************************
static Double_t deltaPhi_360[19] = { 0., 48., 58.5, 70.5,
79.5, 87., 97.5,
109.5, 118.5, 130.5,
154.5, 162., 174.,
183., 208.5, 244.5, 285,
328.5, 360 };
static Double_t adc0_360[19] = { 96., 32., 21., 22., 35.,
56., 66., 80.,
95., 108., 140.,150., 161.,
175., 206.,
236., 191., 136., 96.};
//****************************************************************
Int_t n = 19;
TGraph g0360 = new TGraph( n, deltaPhi_360, adc0_360 );
g0360->Draw("A
");

TF1 *f = new TF1(“f”, fitf, 0, 360, 3);
f->SetParameters(65, 1.1, 20);
f->SetParLimits(0, 1.0, 1.3);
f->SetParLimits(1, 50., 70.);
f->SetParLimits(2, 20, 20);

f->SetParNames(“m”, “phi0”, “ped”);
g0360->Fit(f,“R”);
return 0;

}

Double_t fitf( Double_t *x, Double_t par){
Double_t m = par[0];
Double_t phi0 = par[1];
Double_t ped = par[2];
Double_t fitval = 0;

if( (x[0] >= 0) && (x[0] <= phi0) ){
fitval = -m * (x[0] - phi0) + ped;
}else if( (x[0] > phi0) && (x[0] <= (phi0 + 180)) ){
fitval = m * (x[0] - phi0) + ped;
}else if( (x[0] > (phi0 + 180)) && (x[0] <= (360 - phi0)) ){
fitval = -m*(x[0] - phi0) + ped;
}
return fitval;
}
//---------------------------------------------------------

From the root forum (http://root.cern.ch/phpBB2/viewtopic.php?t=842&highlight=gcallfunc)

it seems that there is a problem with my fit function, although I cannot detect it.

Thanks in advance,
Angela.

Hi Angela,

You have an error in your definition of the function fitf. Instead of
Double_t fitf( Double_t *x, Double_t par){
do
Double_t fitf( Double_t *x, Double_t *par){

Rene