Using TGraphErrors

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 (2.5 KB)
to read and plot this data Run_13-19.txt (3.2 KB)
i don’t know what am doing that is wrong

Your assistance is much appriciated

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 ?

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

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.

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

void tidfit() {

   ifstream in;"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);


check the way you read the txt file.

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

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