Time in TTree

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!! :slight_smile:

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

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

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!! :slight_smile:

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
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).

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

thanks in advance :wink:

root.cern/doc/master/treegetval_8C.html

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

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

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.

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.

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…

{
   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:

$ 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] 

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??

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