# How to read data 2D array from a .txt file and make a ttree

**URL:** <https://root-forum.cern.ch/t/how-to-read-data-2d-array-from-a-txt-file-and-make-a-ttree/52208>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [November 3, 2022, 10:09am UTC](https://root-forum.cern.ch/t/how-to-read-data-2d-array-from-a-txt-file-and-make-a-ttree/52208 "2022-11-03T10:09:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [November 3, 2022, 10:09am UTC](https://root-forum.cern.ch/t/how-to-read-data-2d-array-from-a-txt-file-and-make-a-ttree/52208/1 "2022-11-03T10:09:19Z")

</div>

Hi,

I would like to read 2D array from a text file and would like to store the contents of the array in a TTree.

I am attaching the text file, where I have the mass and TKE of particles stored in a 2D array. I want to read the contents of the array and want to store the correlated mass and TKE in two separate branches of a TTree.

I don’t really understand how to do this (seeing the text file, which is the output from GEF calculations).  
Any help will be really appreciated.  
[test.txt](https://root-forum.cern.ch/uploads/short-url/mnJy09AwdTkMrDRYfTLc8FRukjb.txt) (29.4 KB)

Thank you.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [November 3, 2022, 10:32am UTC](https://root-forum.cern.ch/t/how-to-read-data-2d-array-from-a-txt-file-and-make-a-ttree/52208/2 "2022-11-03T10:32:20Z")

</div>

Hi @gini ,

you can split the problem in 2: reading your data from the txt file is a generic C++ (or Python) question and you can find a lot of resources on the web to help with it. Then once you have the data you have to write it into a TTree; for that this should help: [Trees - ROOT](https://root.cern/manual/trees/#writing-a-tree) as well as [the TTree tutorials](https://root.cern/doc/master/group __tutorial__ tree.html).

Cheers,  
Enrico
