# Using TGraphErrors

**URL:** <https://root-forum.cern.ch/t/using-tgrapherrors/33826>\
**Category:** Newbie\
**Created:** [April 30, 2019, 7:18am UTC](https://root-forum.cern.ch/t/using-tgrapherrors/33826 "2019-04-30T07:18:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thabo\_Lepota](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@Thabo\_Lepota](https://root-forum.cern.ch/u/Thabo_Lepota)\
**Post date:** [April 30, 2019, 7:18am UTC](https://root-forum.cern.ch/t/using-tgrapherrors/33826/1 "2019-04-30T07:18:43Z")

</div>

Hi All,

I would like to plot a graph with errors using the Tgrapherror function but i seem to be getting errors when i run this script [tidfit.c](https://root-forum.cern.ch/uploads/default/original/3X/b/f/bf43e8e76130ab3bf6660bef2013bbd659f65937.c) (2.5 KB)  
to read and plot this data [Run\_13-19.txt](https://root-forum.cern.ch/uploads/default/original/3X/2/a/2a97ca69ad21ca6d0a040b5bd6eb4f1bd34fece7.txt) (3.2 KB)  
i don’t know what am doing that is wrong

Your assistance is much appriciated

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 30, 2019, 9:24am UTC](https://root-forum.cern.ch/t/using-tgrapherrors/33826/2 "2019-04-30T09:24:19Z")

</div>

> [@Thabo\_Lepota](#):
>
> i seem to be getting errors

what kind of error do you get ? it runs without error for me.  
Or do you mean that you do not see the errors bars on the plots ?

---

<div class="post-metadata">

**Author:** ![Thabo\_Lepota](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@Thabo\_Lepota](https://root-forum.cern.ch/u/Thabo_Lepota)\
**Post date:** [April 30, 2019, 9:44am UTC](https://root-forum.cern.ch/t/using-tgrapherrors/33826/3 "2019-04-30T09:44:00Z")

</div>

i don’t see the errors bars in the plots and it’s suppose to be plotting 12 point at least but i only get three points

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 30, 2019, 11:09am UTC](https://root-forum.cern.ch/t/using-tgrapherrors/33826/4 "2019-04-30T11:09:22Z")

</div>

I have simplified your macro and put some printout to check what are the values you pass to the TGraphError constructor. It seems the reading of the txt file is not correct given the values you have.

```auto
#include "Riostream.h"
#include "TString.h"
#include "TNtuple.h"
#include "TSystem.h"

void tidfit() {

   ifstream in;
   in.open("Run_13-19.txt");

   Float_t Time,Vi_Brick1,Io_Brick1,Vo_Brick1,Vi_Brick2,Io_Brick2,Vo_Brick2,Vi_Brick3,Io_Brick3,Vo_Brick3,Vi_Brick4,Io_Brick4,Vo_Brick4,Vi_Brick1err,Vi_Brick2err,Vi_Brick3err,Vi_Brick4err,Io_Brick1err,Io_Brick2err,Io_Brick3err,Io_Brick4err,Vo_Brick1err,Vo_Brick2err,Vo_Brick3err,Vo_Brick4err;
   Int_t n1 = 12;

   while (1) {
      in >> Time >> Vi_Brick1 >> Vi_Brick1err >> Io_Brick1 >> Io_Brick1err >> Vo_Brick1 >> Vo_Brick1err >> Vi_Brick2 >> Vi_Brick2err >> Io_Brick2 >>Io_Brick2err >> Vo_Brick2 >>Vo_Brick2err >> Vi_Brick3 >>Vi_Brick3err >> Io_Brick3 >> Io_Brick3err >> Vo_Brick3 >> Vo_Brick3err >> Vi_Brick4 >> Vi_Brick4err >> Io_Brick4 >> Io_Brick4err >> Vo_Brick4 >> Vo_Brick4err;
      if(!in.good()) break;
   }

   Double_t time1[] = {Time};
   Double_t Vi_brk[] = {Vi_Brick1,Vi_Brick2,Vi_Brick3,Vi_Brick4};
   Double_t Io_brk[] = {Io_Brick1,Io_Brick2,Io_Brick3,Io_Brick4};
   Double_t Vo_brk[] = {Vo_Brick1,Vo_Brick2,Vo_Brick3,Vo_Brick4};

   Double_t Vi_brkerr [] = {Vi_Brick1err,Vi_Brick2err,Vi_Brick3err,Vi_Brick4err};
   Double_t Io_brkerr [] = {Io_Brick1err,Io_Brick2err,Io_Brick3err,Io_Brick4err};
   Double_t Vo_brkerr [] = {Vo_Brick1err,Vo_Brick2err,Vo_Brick3err,Vo_Brick4err};

   for (int i=0; i<n1; i++) printf("%d %g %g %g\n",i,time1[i],Vi_brk[i],Vi_brkerr[i]);

   TGraphErrors *g1 = new TGraphErrors(n1,time1,Vi_brk,0,Vi_brkerr);

   TCanvas *c1 = new TCanvas("c1","tidfit",700,500);
   g1->SetMarkerStyle(21);
   g1->SetMarkerColor(2);
   g1->Draw("ap");

   in.close();
}

```

check the way you read the txt file.

```auto
root [0] 
Processing tidfit.c...
0 4.4e-09 168 1.19e-06
1 2.25468e-314 2.5e-08 -3.02e-06
2 0 1.22e-08 3.71e-07
3 2.25468e-314 5.23e-09 -1.01e-06
4 6.95326e-310 1.00744e-84 3.04e-09
5 6.93164e-310 4.4e-09 1.8e-09
6 6.93164e-310 2.25468e-314 2.87e-09
7 6.93164e-310 0 6.34e-09
8 0 2.25468e-314 1.11e-06
9 0 6.95326e-310 8.29e-07
10 0 6.93164e-310 2.66e-06
11 6.93164e-310 6.93164e-310 2.36e-06

```

---

<div class="post-metadata">

**Author:** ![Thabo\_Lepota](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/58956e/32.png) [@Thabo\_Lepota](https://root-forum.cern.ch/u/Thabo_Lepota)\
**Post date:** [April 30, 2019, 12:25pm UTC](https://root-forum.cern.ch/t/using-tgrapherrors/33826/5 "2019-04-30T12:25:48Z")

</div>

Okay i’ll have a look at the text file, to see whats really wrong with text file
