EZ question: can I write gr->Fit("pol1","N

Can I write


where gr is a TGraph object? I am asking this because I am getting segmentation violation when i execute the next statement:

TF1 *func=gr->GetFunction(“pol1”); //not plot fit
Doubel_t p0=func->GetParameter(0);
Double_t p1=func->GetParameter(1);

The thing is that I don’t want to see the linear Fit in my data, although I would like lo obtain the parameters p0 and p1 for analysis.

I try to write


and my program does not crash, but again, the linear fit is between my data :frowning:

There is a contradiction in your request. By specifying the option “N” you
tell TGraph::Fit TO NOT STORE the function in the list of functions of the graph. As a result gr->GetFunction returns a null pointer.
Instead of gr->Fit(“pol1”,“N”);
TF1 *pol1 = gROOT->GetFunctioon(“pol1”);
Double_t p0 = pol1->GetParameter(0);


Hi Rene

Thank you for your feedback. I really appreciate it. I had another solution to my problem. this is what I did:

linear = new TF1(“linear”,“pol1”,xTreme[0],xTreme[1]);

//get slope
e1 = linear->GetParError(1);

I forgot to mention I am working in c++, and I am not sure if I can use gROOT to do the fitting. However, by especifying the option zero in the Fit() function, it will do the fitting without plotting, plus I can still specified the range of the fitting.

thanks again,