Last Modified on
05/02/2019 09:27:59 by Todd
ROOT is an object-oriented data analysis framework used extensively in high energy physics. At its most basic level, it essentially provides a means to store and display data in a (relatively) easy to use format. ROOT is controlled by a scripting language which is a modified version of C++ and features tab completion which you can use to explore the available commands. More information can be found at the root website http://root.cern.ch/root
First fire up a ROOT session by typing root at the command prompt once you're in the MphysAnalysis directory.
Now we can open one of the Mphys project data
files by typing the following at the root prompt
TFile*
inputFile = new TFile("/data/cdfjpsi/jpmm0d/stripped/jpmm0d_stripped.root","READ");
TFile is a ROOT class which handles file input/output. Here we create a new
object of that class linked to the the ROOT file jpmm0d_stripped.root using the
C++ operator 'new'. 'new' tells the computer to create a pointer for a 'TFile'
and assign it to the name 'inputFile'. The second parameter "READ"
tells root to open the file in READ only mode as we want to make sure we don't
change the contents.
To get a feel for what is actually stored in the
files, you can bring up a graphical browser through which you can quickly
navigate through the file
TBrowser*
t = new TBrowser;
Click on ROOT Files->jpmm0d_stripped.root->prod;n
to explore the contents of the file (Note: there appears to be two copies of
prod in the file. ROOT writes to the file in stages, prod;n is
the nth and final write to the file while prod;(n-1) is the penultimate
write). In this root file, there are three types of objects: trees, branches
and leaves. A tree is is essentially a master container, it holds all the
branches which in turn hold the leaves and any sub-branches. The leaves are
the objects which contain the actual data. The structure of the file is that
the event data is written into the "prod" tree, which is divided into branches
and leaves to store different pieces of the data. Double clicking on any of the leaves (eg
MOM_ntk, MOM_pt) will produce a histogram of the entries- don't worry if it
is slow to load. Opening up
the branches (eg. COSMICRES) will let you see what leaves they contain.
While you can use this method to view any ROOT files you create, be aware that you will need to refresh the browser to see any changes you
have made to the data (i.e. by editing and rerunning your program). It can
be easier to view the file data by drawing histograms using ROOT's
interactive commands, as shown below.
We'll
create a histogram of some parameter, like the muon transverse momentum (pt).
You can do this quickly with this simple command, which specifies the
tree to be accessed ("prod"- note that this only works because the file
containing prod has already been opened with the TFile command) and the
leaf to be drawn (MOM_pt, the muon transverse momentum):
prod->Draw("MOM_pt");
ROOT will automatically put the histogram inside the browser
window, but you can create a separate "canvas" in which to draw the
histogram. These can be handy if you want to view multiple
histograms at the same time. You can create as many canvases as you want using
this command:
TCanvas* c1 = new TCanvas("c1","The c1 Canvas");
Just make sure that the canvas pointers (c1 in this case) are all
different! When you enter a Draw command, the histogram will be drawn
on whichever canvas is selected as the active one- you can switch to a different active canvas by
selecting it with the scroll wheel of your mouse (or alternatively, if you want to switch to c1, by typing c1->cd(); ).
You will notice that the
histogram created by your Draw command isn't very pretty- a few outlying
large pt values cause the majority of values to be pushed down into the zero
bin. This can be fixed by adding a cut to the data that is drawn:
prod->Draw("MOM_pt","MOM_pt<5");
That's all the basics you need to know to access the data in root. Play around with root and the data files till you feel comfortable with the root interface.