# Storing data in TTree

**URL:** <https://root-forum.cern.ch/t/storing-data-in-ttree/47158>\
**Category:** Newbie\
**Created:** [October 7, 2021, 4:36pm UTC](https://root-forum.cern.ch/t/storing-data-in-ttree/47158 "2021-10-07T16:36:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![talgat](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@talgat](https://root-forum.cern.ch/u/talgat)\
**Post date:** [October 7, 2021, 4:36pm UTC](https://root-forum.cern.ch/t/storing-data-in-ttree/47158/1 "2021-10-07T16:36:32Z")

</div>

Hello, Dear rooters.  
How I can write data to tree from text file? I plot histogram from text file, but how to do with TTree.  
Thanks in advance

[60Co\_0cm.txt](https://root-forum.cern.ch/uploads/short-url/mjqRzUCMhbxQsVkEEtUopDRkDgg.txt) (66.8 KB)  
[hist.C](https://root-forum.cern.ch/uploads/short-url/4Q9JbWauVZzAOXGVbnRf9FMJWBR.C) (223 Bytes)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 7, 2021, 4:39pm UTC](https://root-forum.cern.ch/t/storing-data-in-ttree/47158/2 "2021-10-07T16:39:18Z")

</div>

[TTree::ReadFile](https://root.cern/doc/master/classTTree.html#a9c8da1fbc68221b31c21e55bddf72ce7)  
[${ROOTSYS}/tutorials/tree/basic2.C](https://root.cern/doc/master/basic2_8C.html)  
[${ROOTSYS}/tutorials/tree/temperature.C](https://root.cern/doc/master/temperature_8C.html)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [October 8, 2021, 7:00am UTC](https://root-forum.cern.ch/t/storing-data-in-ttree/47158/3 "2021-10-08T07:00:42Z")

</div>

Your file has only one column. You can simply do:

```auto
root [0] auto t = new TTree()
root [1] t->ReadFile("60Co_0cm.txt","x");
root [2] t->Print()
******************************************************************************
*Tree : : *
*Entries : 16384 : Total = 66708 bytes File Size = 0 *
* : : Tree compression factor = 1.00 *
******************************************************************************
*Br 0 :x : x/F *
*Entries : 16384 : Total Size= 66421 bytes All baskets in memory *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
root [3] t->Draw("x")
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [4] 

```

---

<div class="post-metadata">

**Author:** ![talgat](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@talgat](https://root-forum.cern.ch/u/talgat)\
**Post date:** [October 8, 2021, 10:52am UTC](https://root-forum.cern.ch/t/storing-data-in-ttree/47158/4 "2021-10-08T10:52:10Z")

</div>

Thank you. but I am unable to plot the correct histogram from the tree, as attached

 ![60Co](https://root-forum.cern.ch/uploads/default/original/3X/9/a/9a906e243a22185adac38df5ffc0d8a7bb36cdb5.png)  
[image]

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 8, 2021, 11:10am UTC](https://root-forum.cern.ch/t/storing-data-in-ttree/47158/5 "2021-10-08T11:10:43Z")

</div>

`t->Draw("x : Entry$", "", "L");`
