void setStyle() { //standard function which controls graphics
gROOT->SetStyle("Plain");
gStyle->SetOptStat(111110);
gStyle->SetOptFit(111);
//gStyle->SetPalette(57);
gStyle->SetOptTitle(1);
}
void grafico () {
TGraphErrors * graphC = new TGraphErrors("T^2-vs-L", "%lg%lg"); //%lg for each column in the file
graphC->SetTitle("Confronto T^{2} e L; L [m]; T^{2} [s^{2}]"); //graph title
graphC->GetXaxis()->CenterTitle();
graphC->GetXaxis()->SetTitleOffset(1.5);
graphC->GetYaxis()->CenterTitle();
graphC->GetYaxis()->SetTitleOffset(1.5);
graphC->SetMarkerStyle(kFullCircle); //graph markers
graphC->SetMarkerColor(kBlack); //markers color
TF1 *f1 = new TF1("Linear law", "[0]*x+[1]",600,600); //fitting function y=Ax+B
f1->SetLineColor(kRed); //fitting color
f1->SetLineStyle(2); //fitting graphics
f1->SetParNames("A", "B"); //name of the parameters in the legenda
graphC->Fit(f1); //fit the graph which contains the data
TCanvas *cC = new TCanvas(); //object of the type Canvas on which the graph will lay
cC-> cd(); //select the canvas
cC->SetGrid();
cC->SetLeftMargin(0.15);
cC->SetRightMargin(0.15);
cC->SetTopMargin(0.15);
cC->SetBottomMargin(0.15);
graphC->Draw("APE"); //draws the graph ("APE" = Axis, Points, Errors)
TLegend *legC = new TLegend(.1,.7,.3,.9,"Legenda"); //legenda
legC->SetFillColor(0);
graphC->SetFillColor(0);
legC->AddEntry(graphC, "punti sperimentali");
legC->AddEntry(f1, "Fit");
legC->Draw("Same");
TPaveStats *pvs = (TPaveStats*)(graphC->GetListOfFunctions()->FindObject("stats"));
pvs->SetOptFit(1);
gPad->Modified();
gPad->Update();
pvs->Draw();
TList *list = pvs->GetListOfLines();
TLatex *myt = new TLatex(0,0,TString::Format("R^{2} = %g", graphC->GetCorrelationFactor()));
list->Add(myt);
pvs->Draw();
cC->Modified();
cC->Update();
//cC->Print("");
cout << "x and y measurements correlation =" << graphC->GetCorrelationFactor()<<endl; //shows on the terminal the correlation factor
}