//C++ include #include #include #include using namespace std; int linear() { vector x, y, ex, ey; double auxx, auxy, auxex, auxey; ifstream arquivo("data.txt"); for(int i = 0; !arquivo.eof(); i++) { arquivo >> auxx >> auxy >> auxex >> auxey; x.push_back(auxx); y.push_back(auxy); ex.push_back(auxex); ey.push_back(auxey); } int n = x.size(); double *px = &x[0]; double *py = &y[0]; double *pex = &ex[0]; double *pey = &ey[0]; TCanvas c1("Canvas"); c1.SetTickx(); c1.SetTicky(); c1.SetGrid(); gROOT -> SetStyle("Classic"); TGraphErrors *pontos = new TGraphErrors(n, px, py, pex, pey); pontos -> SetMarkerColor(kBlack); pontos -> SetMarkerStyle(21); pontos -> SetMarkerSize(0.5); pontos -> SetTitle("Electric Field and Distance"); pontos -> GetXaxis() -> SetTitle("d [m]"); pontos -> GetYaxis() -> SetTitle("E [N/C]"); pontos -> Draw("APE"); TF1 *f = new TF1("Linear law","[0]*x + [1]", 0, 100); f -> SetNpx(700); pontos -> Fit(f, "R"); TPaveText stats(0.5, 0.75, 0.7, 0.83,"blrtNDC"); stats.SetTextSize(0.035); stats.SetBorderSize(0.4); stats.SetFillColorAlpha(10,0.2); double a = f->GetParameter(0); double b = f->GetParError(0); double c = f->GetParameter(1); double d = f->GetParError(1); char arr1[100]; sprintf(arr1,"V = (%.0f #pm %.0f)d + (%.0f #pm %.0f) ", a, b, c, d); TText *input2 = stats.AddText(arr1); stats.Draw("Same"); c1.Print("image5_1.png"); return 0; }