Fitting problem - a function not recognized

Hello all,

I tried to Fit the TGraphErrors with the following:

gROOT->Reset();

Double_t fitf(Double_t *x, Double_t *par)
{
Double_t arg = (1/211.4/211.4)*TMath::Power((1/x[0]),par[0]);

return arg;
}

void myfit()
{
TFile *f = new TFile(“xxxxx.root”);

TCanvas *c1 = new TCanvas(“c1”,“the fit canvas”,500,400);

TGraphErrors gr1 = (TGraphErrors)f->Get(“Graph;13”);

TF1 *func = new TF1(“fitf”,fitf,0.0001,0.0007,1);

func->SetParameters(1.2);
func->SetParNames(“Par0”);

gr1->Fit(“fitf”,“r”);

gr1->Draw(“AP”);
func->Draw(“same”);
}

Unfortunately, the ROOT seems to have problem with
func:
The output is

root [3] myfit()
Error: Can’t call TF1::SetParameters(0.3) in current scope FILE:fits_cross.C LINE:21
Possible candidates are…
filename line:size busy function type and name (in TF1)
filename line:size busy function type and name (in TFormula)
(compiled) 0:0 0 public: virtual void SetParameters(const Double_t* params);
(compiled) 0:0 0 public: virtual void SetParameters(Double_t p0,Double_t p1,Double_t p2=0,Double_t p3=0,Double_t p4=0,Double_t p5=0,Double_t p6=0,Double_t p7=0,Double_t p8=0,Double_t p9=0,Double_t p10=0); //MENU
filename line:size busy function type and name (in TNamed)
filename line:size busy function type and name (in TObject)
filename line:size busy function type and name (in TAttLine)
filename line:size busy function type and name (in TAttFill)
filename line:size busy function type and name (in TAttMarker)
Error: Symbol func is not defined in current scope FILE:fits_cross.C LINE:21
Error: Failed to evaluate func->SetParameters(0.3)Possible candidates are…
filename line:size busy function type and name
*** Interpreter error recovered ***

I don’t understand, I have the func defined right there, but it doesn’t work :frowning:

Thank you for any idea…

Tomas

To set parameters, you have two functions, SetParameter and SetParameters (with two prototypes).
In your case, you should call
func->SetParameter(0,1.2);
or
func->SetParameters(1.2,0); //second argument is dummy
or
double par[1] = {1.2}
func->SetParameters(par);

Also remove the statement gROOT->Reset();
This statement should never be used in a named script

Rene

Thank you very much Rene, it works now!
I didn’t notice the different functions.

Thanks again,
Tomas