TGraph* gr = new TGraph(n,x,y); TF1* f1 = new TF1("f1","pol1",xmin,xmax); gr->Fit("f1","R");
TGraph* gr = new TGraph(n,x,y); TF1* f1 = new TF1("f1","gaus",xmin,xmax); f1->SetParameters(1,mean,sigma); gr->Fit("f1","R");
TGraph* gr = new TGraph(n,x,y); TF1* f1 = new TF1("f1",myfunction,xmin,xmax,npar); gr->SetLineColor(kRed); gr->Fit("f1","R");In the code above, TGraph library is used to create a graph with n data points on it. The graph is then fitted to a custom curve using the function myfunction which is defined by the user. The fit is performed in the range [xmin,xmax]. The number of parameters required by the custom function is passed as npar. The color of the graph is set to red and the fit is performed using the Fit function. The package library used for TGraph Fit in C++ is ROOT Data Analysis Framework.