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”);
do
TF1 *pol1 = gROOT->GetFunctioon(“pol1”);
gr->Fit(pol1,“N”);
Double_t p0 = pol1->GetParameter(0);
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.