Question about TTrees

Dear ROOTers,

I am writing a Monte Carlo code in which, for each event, I evaluate the induced current signals on a detector and I want to store these signals in a ROOT tree.

For each event, I have a vector of N time values (let’s call them t_k) and, at each time t_k I evaluate the corresponding current i_k=i(t_k).

To save my data in a TTree, I defined a structure with the time and the current vectors, and, at the end of each event, I fill my tree with the command tree->Fill(). This procedure works, but, since the time vector is the same for all the simulated events, I am wondering whether there is a smarter way to fill the tree. Now I am storing the same time values at each event, while I would like to store them only once. Can I do that? And, in positive case, can you suggest me any example that I can use as a guide?

Thanks for your help
Francesco

If your TTree is stored in a TFile, it should be compressed intelligently enough that static values from entry to entry do not significantly add to the size of the TFile. Similarly if you have a TBranch that just stores mostly-contiguous sequences of numbers (like event numbers), these should compress to a very small size.

If you are really worried about redundant data, you can store the data as separate objects in the TFile alongside the TTree (like TObjStrings). There is also a way to set the so-called “User Info” in a TList in the TTree itself. I don’t know more than that, but it should give you some useful search terms to find out.

Jean-François

Hi Jean-Francois,

thanks for your help. Indeed I needed to store the times because, when making plots, I want to build a current vs time graph for each event, and I thought that the easiest way to do this was with tree->Draw().

However I found that I can bypass this problem without storing the times in my tree, just defining a vector of times only when I read the tree and make the plots.