# Time in TTree

**URL:** <https://root-forum.cern.ch/t/time-in-ttree/23770>\
**Category:** ROOT\
**Created:** [February 16, 2017, 11:44am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770 "2017-02-16T11:44:05Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![booghimen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@booghimen](https://root-forum.cern.ch/u/booghimen)\
**Post date:** [February 16, 2017, 11:44am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/1 "2017-02-16T11:44:05Z")

</div>

Dear rooters,

I have a data stored in a file. So i read the data into a TTree. An exaple of data are below, where the first column are date, and the other columns are number (here only 1 columns to simplify):

01/10/2015 2008  
16/06/2016 2120.5  
02/11/2016 2115.09  
03/11/2016 2111.69

I read the data from file into a TTree:

tree= TTree (“tree”,“tree”)  
tree.ReadFile(“myfile.csv”,“time/C:data/F”,’\t’)

Now I want to plot the values in function of the time, but I know that have to be in TDatime format (y,m,d,h,m,s). So my question is: how can I modify the data inside the branches?  
And also, if I want to store the data from a branches into a list o array, how can I do?

Thanks in advance!! 🙂

---

<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:** [February 16, 2017, 12:00pm UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/2 "2017-02-16T12:00:29Z")

</div>

In fact you can already get meaningful plots having the date as a string. Just try:

tree.Draw(“data:time”,"",“box”);

---

<div class="post-metadata">

**Author:** ![booghimen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@booghimen](https://root-forum.cern.ch/u/booghimen)\
**Post date:** [February 16, 2017, 1:49pm UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/3 "2017-02-16T13:49:49Z")

</div>

Yes this work in sense that I have the plot, but the time line is not correct, I mean the distance between october 2015 and june 2016 is same of the distance betwee june 2016 and november 2016…  
And 2nd thing I need also to store the data from each branch in array or list.

thanks!! 🙂

---

<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:** [February 16, 2017, 2:03pm UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/4 "2017-02-16T14:03:25Z")

</div>

In that case you will need to create a histogram with time axis as shown in the examples here:  
[root.cern/doc/master/dir\_dd3949 … a3468.html](https://root.cern/doc/master/dir_dd394962f94ea9e12529a927168a3468.html)  
may be instead of storing the date as a string in the ntuple it will be better to store the value returned by TDatime::Convert (see examples above).

---

<div class="post-metadata">

**Author:** ![booghimen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@booghimen](https://root-forum.cern.ch/u/booghimen)\
**Post date:** [February 17, 2017, 10:05pm UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/5 "2017-02-17T22:05:58Z")

</div>

ok thanks 🙂  
And to copy the values from the braches to a list or array how I can do?

thanks in advance 😉

---

<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:** [February 20, 2017, 8:57am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/6 "2017-02-20T08:57:41Z")

</div>

[root.cern/doc/master/treegetval\_8C.html](https://root.cern/doc/master/treegetval_8C.html)

---

<div class="post-metadata">

**Author:** ![booghimen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@booghimen](https://root-forum.cern.ch/u/booghimen)\
**Post date:** [February 21, 2017, 10:04pm UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/7 "2017-02-21T22:04:17Z")

</div>

I tried to use to store the data in a list doing:

x= tree.GetVal( 3)  
print x

but I can not see the data values but this: Double\_t buffer, size 2147483647

---

<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:** [February 22, 2017, 7:57am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/8 "2017-02-22T07:57:13Z")

</div>

Sorry but I do not really understand what you mean.  
Can you provide a small example reproducing the problem you encounter ?

---

<div class="post-metadata">

**Author:** ![booghimen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@booghimen](https://root-forum.cern.ch/u/booghimen)\
**Post date:** [February 22, 2017, 8:38am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/9 "2017-02-22T08:38:50Z")

</div>

Yes sorry… So I have a tree with different branches… now I want manage the values which are inside the branches… For example I would like copy the values from branches 2 to a list… so as you told me I used GetVal(2):

tree= TTree (“tree”,“tree”)  
tree.ReadFile(“myfile.csv”,“time/C:data/F”,’\t’)

x= tree.GetVal( 2)  
print x

What I did, probably wrong, is copy the values from branches 2 of tree into the x list. Then I printed the list, but don’t see the values but is printed: \<Double\_t buffer, size 2147483647\>

I tried also the command GetV2() but also in this case I have: \<ROOT.MethodProxy object at 0x7f4386f24f90\>  
but not the values.

---

<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:** [February 22, 2017, 8:45am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/10 "2017-02-22T08:45:32Z")

</div>

Start from the example I pointed to you.  
See how it works…  
GetVal is not enough, no you need a Draw Before… have a closer look to the example.

---

<div class="post-metadata">

**Author:** ![booghimen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@booghimen](https://root-forum.cern.ch/u/booghimen)\
**Post date:** [February 22, 2017, 9:14am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/11 "2017-02-22T09:14:16Z")

</div>

I forgot to write it, but I draw a graph before to use GetVal…

tree= TTree (“tree”,“tree”)  
tree.ReadFile(“myfile.csv”,“time/C:data/F”,’\t’)

N=tree.Draw(“data:time”,"",“goff”)

grB2 = TGraphErrors(N,tree.GetV2(),tree.GetV1())

grB2.SetMarkerStyle(26)  
grB2.SetMarkerSize(0.9)  
grB2.SetMarkerColor(4)  
grB2.SetLineColor(4)  
grB2.Draw( ‘AP’ )

x= tree.GetVal( 2)  
print x

I look the example, I tried to do the same…

---

<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:** [February 22, 2017, 9:47am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/12 "2017-02-22T09:47:45Z")

</div>

```auto
{
   TTree *tree = new TTree ("tree","tree");
   tree->ReadFile("myfile.csv","time/C:data/F",'\t');

   Int_t N = tree->Draw("data:time","","goff");

   Double_t *x = tree->GetVal(0);

   for (Int_t i = 0 ; i< N ; i++) printf("x(%d) = %g\n",i,x[i]);
}
```

gives:

```auto
$ root boog2.C 
   -----------------------------------------------------------------
  | Welcome to ROOT 6.09/01 http://root.cern.ch |
  | (c) 1995-2016, The ROOT Team |
  | Built for macosx64 |
  | From heads/master@v6-09-01-1587-gce992d9, Feb 21 2017, 09:29:21 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   -----------------------------------------------------------------

root [0] 
Processing boog2.C...
x(0) = 2008
x(1) = 2120.5
x(2) = 2115.09
x(3) = 2111.69
root [1] 

```

---

<div class="post-metadata">

**Author:** ![booghimen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/f07891/32.png) [@booghimen](https://root-forum.cern.ch/u/booghimen)\
**Post date:** [February 22, 2017, 10:29am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/13 "2017-02-22T10:29:03Z")

</div>

Ahhh ok now I understand how it works!!  
But I have another problem… if insted to take the GetVal(1) I take the GetVal(0) where I have the “time” and not a float values, instead to obtain the time values stored in tree I obtain this number:

0.5  
1.5  
2.5  
3.5

why??

---

<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:** [February 22, 2017, 10:35am UTC](https://root-forum.cern.ch/t/time-in-ttree/23770/14 "2017-02-22T10:35:32Z")

</div>

GetVal returns a double ([root.cern/doc/master/classTTree … 40b8fcc717](https://root.cern/doc/master/classTTree.html#a3ad3433f279c1b6f54083e40b8fcc717))  
I told you already it is not a good idea to store the date à a string … see above…
