You are here

TTree and Its Data

TTree

A TTree is a large, structured chunk of data on disk. The trick is that only selected parts of it are in memory at any given time. Here, with the help of some illustrations by our colleague Ioannis, we see how to extract these parts. Sit back and enjoy - in this step there is nothing for you to run. Too much data! Let's assume a TTree holds "all the worlds' newspapers of all times". That's a lot, and no way would you want to have that delivered in one serving. So how you can make access to the newspapers more reasonable?

TBranch

Of course you don't care about all newspapers. You want only one or two - say we take the Tribune de Geneve. You create a subscription - that's the TBranch in ROOT's world. You can of course have as many subscriptions as you need. Pick a subscription!

The subscription manager is called the TTreeReader. You subscribe to a branch by creating a TTreeReaderValue (or TTreeReaderArray for arrays of any sort) and register it with the TTreeReader:

// Our subscription manager:
TTreeReader subscriptionManager(theTree);
// Tell the manager that we want to subscribe to the branch "TribuneDeGeneve",
// and that we expect to get an object of type Newspaper.
TTreeReaderValue<Newspaper> myTribuneDeGeneve(subscriptionManager, "TribuneDeGeneve");

TTreeReader::Next()

You would not want to have all issues of the Tribune de Geneve at once, but only one, say today's. You do that by requesting delivery of an issue from the subscription manager: Data delivery

// In this example, we loop over all entries on the TTree.
while (subscriptionManager.Next()) {
  // Now myTribuneDeGeneve has loaded its data and we can access it.
  // TTreeReaderValue behaves like an iterator; you need to use "->" on
  // it to access the data it refers to.
  myTribuneDeGeneve->read();
  ...
}

Summary

As you saw, TTree is about

  • Chunking up similar, disconnected entries of which typically only one needs to be available, just like newspaper issues or data from High Energy Physics collisions, also known as the entries of a TTree
  • Selecting which data the TTree should provide, i.e. subscribing to certain branches only. Branches can be nested, so depending on the tree you could even subscribe to only the sports section or even only an article, reducing data transfer.

A precedure like this is actually what most physicists do to analyze data from a series of TTrees. So let's try it in practice!