Tree with custom class with 'slow' entries

Dear ROOTers,

I have a TTree containing essentially just my custom class (myEvent).

I want to store, among the various class members (i.e. run, event number, time, ntracks) some data that are “slower”: for example a temperature or something else that is retrieved with a much slower rate (wrt to the data rate).

Is there any smart way to have this type of data member (for example a temperature) “linked” to all the events in a given range (for example the temperature is retrieved every minute and so linked to alla the events in that minute) without adding a member to the class that will be written (wasting space…) for every single event even if it will be really the same for, for example, 10000 events?

I tried to think something like a std:map with the temperatures but I fail to understand how to link to ‘myEvent’: if I put this map (or even a TTree) in the same file as the main tree than, however, I don’t know how to retrieve, easily, from ‘myEvent’ the informations since ‘myEvent’ doesn’t know ‘the world outside’ (i.e. it doesn’t know about the fact that a TTree is holdind it and a TFile is holding the TTree…)

Thanks! Ciao!


One way to doing this is to use a TTree Friend that will contain the slow varying information. In addition to allow for reconnecting the two, you will need to give a ‘unique id’ to each range of event that match one of the slow varying piece of information. In the main and in the friend tree you would store this information (range-id) and you would build a TTreeIndex (see TTree::BuildIndex) on the friend tree based on this range-id. Then you can always retrieve the 2 related entries together.


Thank you!

Yes at the end I was able (my post is very old!) to manage how to do by my self.

Since we “reopened” this topic I can give an example that could be useful for other ROOTers. Of course if you want to comment, maybe correcting something is not correct, this is more than welcome.

I have a:

  • main tree with the events -> MainTree
  • “additional” tree with the same events (or maybe just a very relevant subset) but with more additional branches -> AddTree, friend of MainTree
  • a “slow” tree control with slow control information useful during the processing of the events --> SlowTree, friend of MainTree

Between the other branches I have:

  • “Event”, “Run” and “Time” for the MainTree
  • “Event” and “Run” for the AddTree
  • “Time” for the SlowTree

Then (during “production” of TTree’s, but can be done even just before reading…) I create the indexes:

  • No indexing for the MainTree
  • AddTree->BuildIndex(“Event”,“Run”)
  • SlowTree->BuildIndex(“Time”)

When I process the entry Nth from MainTree (MainTree->GetEntry(N)) the entry with the same Run and Event is retrieved from AddTree and the entry with the same Time is retrieved from SlowTree. If SlowTree is “slow” most likely the very same entry is retrieved for several MainTree events. This is correct and is exactly what we were needing for!

I hope this helps!