Plot best fit with errors

How can i plot and fit the data with first degree polynomial, reading in the data from an ascii file (see attached) Run_13-19.txt (1.7 KB)
i’m tryin to use this script basic.C (2.7 KB)
instead of plotting histogram : i’m not if its wise to use TGraph *h1 = new TGraph(nlines,time,Vi_brick1) ; gStyle->SetOptFit(0001);

i’m more interested in displaying the best fit line, with its parameters and excluding the points

Thank you in advance

  gStyle->SetStatStyle(0); // hollow
  TTree *t = new TTree("ntuple", "data from txt file");
  // t->Print();
  t->SetMarkerStyle(kFullStar); t->SetMarkerColor(kMagenta);
  if (gPad) {
    TGraph *g = (TGraph*)gPad->GetPrimitive("Graph");
    if (g) {
      g->Fit("pol1", "Q");
#if 0 /* 0 or 1 */
      TF1 *f = (TF1*)g->GetListOfFunctions()->FindObject("pol1");
      if (f) {
        f = new TF1(*f); // make a copy
        TLatex *l = new TLatex(); l->SetTextFont(42); l->SetTextSize(0.03);
        l->DrawLatexNDC(0.35, 0.85, Form("p0 = %g #pm %g", f->GetParameter(0), f->GetParError(0)));
        l->DrawLatexNDC(0.35, 0.80, Form("p1 = %g #pm %g", f->GetParameter(1), f->GetParError(1)));
        // f->Print();
#endif /* 0 or 1 */

I should incorporate this macro into the basic.C script?

If you want to display just the best fit line and exclude points on the graph, how would you go about doing that?

#if 1 /* 0 or 1 */

doing so it doesnt display the parameters of the best fit on the plot

In a case where by the each parameter (Vi_brick1,Io_brick1,Vo_brick1,…) have errors that accompanies them , how can i include them in the plots?