Reading and drawing multi-columns data

Hi Rooters,

I was wondering if you know any fast method to read a multi-columns data file and draw one column versus other. I used Tree but I couldn’t produce good quality figure and I didn’t know if it is possible to pass a branch of a tree to a Graph and then deal with the Graph. I then wrote this little code which seems it has a problem I can’t honestly resolve.

Thanks in advance for your time,
Bahman.
PD.cpp (1.35 KB)

Suppose a data file exam.dat containing 3 columns that you name “x”,“y”,“z”.
With interactive ROOT, you can do

root > TNtuple T("T","test"); root > T.ReadFile("exam.dat","x:y:z"); root > T.Draw("x:y","z>0");
see doc of TTree::Draw to create a TGraph using the data points selected by TTree::Draw using TTree::GetV1,2,3,etc

Rene

Thanks Brun. I was looking for a function like GetV1, but is there anyway I can get the nth branch without drawing TTree/TNtuple beforehand? The number of columns I have, could vary and become very big. Moreover, to my understanding you have to always specify the number of column in the data set in order to use ReadFile method such as “n” in the following, t->ReadFile(“filename”,“V[n]”). Is there anyway to avoid this?

[quote]I was looking for a function like GetV1, but is there anyway I can get the nth branch without drawing TTree/TNtuple beforehand? [/quote]What do you mean? The ‘drawing’ is the part that retrieve the information from the file so I do not see how/why you would want to skip that step (i.e. I don’t understand your question :slight_smile: ).

Cheers,
Philippe.

Ok, so all I want to do is to read a multi-columns data in a tree or ntuple, then pass each of its branches to Graph methods so I could create my graph at the end.

Here there are steps I have to perform:
1-TNtuple T(“T”,“test”);
2-T.ReadFile(“exam.dat”,“x:y:z”);
3-T.Draw(“x:y”,“z>0”);
4-TGraph *g = new TGraph(T.GetSelectedRows(), T.GetV2(), T.GetV1());
5-g->Draw(“AL”);

The line 4 can not be performed without line 3 as you mentioned. I wanted to know, if there is any method like GetV1 which retrieve the branch values as an array without the extra Draw call in line 3.

You can specify the option “goff” in tree.Draw. see doc

Rene