Build a tree with text files

Hi,

Please consider that I am new to ROOT

I want to create a tree with two different branches corresponding to two different data sets, and fill these two branches with two leaves: one for all the x coordinates and the second one for all the y coordinates. The issue is that I have huge data sets stored in 4 different text files.

I hence have two questions:
1)Does it make sense to proceed this way (two branches with two leaves each for the 4 coordinates)?
2)If yes, how could I fill the leaves with my text files?

Thank you very much.

Hi, if you haven’t already, take a look at the TTree tutorials, in particular basic2.C reads data from a text file using TTree::ReadFile (you can read more about it in the ROOT reference).

In first approximation. branches are ROOT’s name for table “columns” (except they can contain structured data instead of simple alphanumerical values); so in general it would probably not be a good idea to store each one of your data-sets in a different branch: you would end up with columns of different lengths!

Depending on your problem it might make sense to store each data-set in a separate TTree (and then maybe store both TTrees in the same TFile), or store all of the data in a single TTree with just two branches x and y.

Hi,

Thank you very much for your answer.

Both data sets have the same size.
I will briefly explain what my problem is about:
Basically, I’m working on a project with one of my teachers that involves neural networks; I will be using the ROOT libraries for that (the “mlpHiggs.C” classification neural network, you can find the program at the following address: C:\root\tutorials\mlp).
To get familiar with ROOT and the neural network used, he asked me to execute this very simple task of generating two data sets of N points with x and y coordinate, each data set of points is basically fluctuating has coordinates fluctuation around a given center with a given radius (as a circle filled with points). The point is to train the network so that when I test it with random coordinates, it tells me from which data set it comes from. As simple as that.
The code for generating the points is done, I now have to deal with the network and generating the right tree to work with it. And I’m kinda stuck.

Thanks again for your answer!

I would start simple and pre-process your files so that you have all values in the same file (e.g. using paste on linux). Then you can read the four values inside four separate branches with TTree::ReadFile (why adding the complication of having branches and leaves if you don’t need it). At that point you have a flat TTree with x1, y1, x2 and y2 values and you can use it for whatever purpose.

1 Like

Great!! It worked!!

Thank you for your time!

Yassine.

Great :smiley: marking this as solved

Hi,

perhaps this could be done with TDataFrame in a simple way: how are your files writen? Can you share them? I can prototype a solution for you…

D

1 Like

Hi !

Thank you very much for your answer, but I have figured out a way to solve my problem with another method: I avoided the text file.

Thanks again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.