You are here

Meet a TTree

We have created an example ROOT file containing a TTree: a typical data container used e.g. by all LHC experiments.

Start ROOT (it will reply with root[0]) and open the file located at http://root.cern/files/introtutorials/eventdata.root

To do so, just copy and paste:

TFile::Open("http://root.cern/files/introtutorials/eventdata.root");

Whenever you quit ROOT during these tutorials, please re-open this file as the first step. For more information about TFile, see its documentation at http://root.cern.ch/root/htmldoc/TFile.html

This file contains a TTree, as you can see by typing .ls in the ROOT prompt:

filecontent.png
Figure 1: screenshot of the .ls command

As you can see, the TTree is called "EventTree". To inspect what's inside this tree, just type:

root[0] EventTree->Print()

For more information about TTree, see http://root.cern.ch/root/htmldoc/TTree.html

So let's see what is in this tree...

We have created two example classes, again to illustrate a typical (but very minimal) setup of an experiment's data. You don't need a library with these classes (though ROOT will print "Warning in : no dictionary for class EventData/Particle is available") because a TTree knows what data is stored inside. The EventData class contains a vector (std::vector) of particles represented by a "Particle" class and the total size (in bytes) of the event itself:

class EventData {
public:
   std::vector<Particle> fParticles; // particles of the event
   int fEventSize;                   // size (in bytes) of the event
};

The data members of the Particle class describe the particle properties as shown below:

class Particle {
public:
   double fPosX,fPosY,fPosZ; // particle position nearest to interaction point
   double fMomentum;         // particle momentum
   double fMomentumPhi;      // particle direction (phi)
   double fMomentumEta;      // particle direction (eta)
   Long64_t fTags[128];      // particle tags
};

The TTree contains a branch event, which in turn contains the branches fParticles and fEventSize. It simply reflects the layout of class EventData. Each TTree entry has one object of type class EventData, which in turn has a collection of particles. Each tree entry can have a different number of particles. There are 200 TTree entries containing a total of 22994 particles.

If you are curious how we generated the TTree: the script is in our git repository.