TGraph constructor and plotting

I want to read in a data file (5 columns) and I have been trying to use the following constructor:
TGraph(const char* filename, const char* format = “”%lg %lg"", Option_t* option = “”"")
I tried using it on the ROOT command prompt (instead of writing a script) just so I may learn whether I am using the command properly. I used the basic:
TGraph *g = new TGraph(“fname.dat”)
how can I access the data to make sure this works and how can I get it to plot? I have tried g->Print() just to see if the data is being read but to no avail.
Thank you.

If your file fname.dat is readable and contains at least 2 columns of numbers, what you do should work. More details please.


My file is readable I am sure of it cause I can call it for making an ntuple and draw histograms. There are 5 columns of data. I just cant see how I may call TGraph in such a way that I can access the data. Is the following valid?
TGraph *g = new TGraph(“fname.dat”, “x y z t”)
I thought this way I was setting x to be column one and so on. This command gives me no errors. Then is it valid to say:
g->DrawGraph(x) ? (Apparently not but I dont know where I am going wrong).
Thank you.

an update:
I have noticed that the following:
TGraph *g = new TGraph(“fname.dat”)
only reads in the first two colmns (instead of 5) from the file. How do I get it to read all five?
Thank you.

TGraph is a class dealing with two vectors X and Y.

So, do not expect that you will have the x y z t vectors as this quote suggested.

It would be very helpful if you send a small macro (and data) showing what you are doing. But remember, TGraph has only 2 vectors !

attached are the data file and the script I am invoking.
What I am trying to do is to plot a graph of the 2nd, 3rd, 4th and 5th column vs the 1st, seperately. Finally I would also like to plot a 3D graph of the 2nd, 3rd and 4th columns. I would appracite any suggestions on how to deal with this.
Thank you very much.
Best Regards…
ode45.txt (2.38 KB)
ode45draw.C (248 Bytes)

Seems to me the best way is to read the file in 5 vectors: x y z t u
and then make all the TGraphs you need combining the vectors as you wish.