Using Root for interactive analysis of a Root file
and peeking at Kanga files
NOTE: These pages are still being worked on. They do contain errors. Please send me a note when something does not work for you.
These pages are not meant as a substitute for the excellent tutorials 101 and 102 found at Fermilab (have a look at their `Getting started with ROOT', too). Rather, these pages should provide (1) a crashcourse in how to get started with ROOT in BaBar and (2) a cookbook where you can find answers to questions on how to get things done in ROOT.
is a hypernews
where you can and should ask questions on the interactive usage of
A mailing list provides information on what releases of ROOT are available at SLAC.
Another webpage collects (links to) information on ROOT.
The following sections are covered in this tutorial:
Environment - a few
definitions and concepts
Starting and terminating ROOT - the essentials
GUIs: Looking at the Output of the Beta Tutorial - to play around and get started
CINT in brief - look at the TAB features provided by ROOT
Customizing your environment - get rid of the default style by switching to "Plain"
How to get things done in ROOT - all the stuff you need to know to make plots within a reasonable time
How to look at KANGA files - plot tag contents and check for MC truth
What do people mean when talking about ROOT?
ROOT is a set of OO frameworks that allow a programmer to build applications (or store data, e.g. Kanga). The ROOT frameworks provide an integrated environment for data storage and all necessary analysis and display tools.
An interactive stand-aloneapplication root, which gives access to all ROOT classes via a command libe interpreter or GUIs.
This tutorial is on the interactive usage of ROOT which can happen in several ways, among them
GUIs - pop-up menus, context menus, e.g.
- interactive GUI-based operations on ROOT-files
TreeViewer - interactive GUI-based operations on ROOT-Trees
Editor - add graphics elements to a Canvas
DrawPanel - GUI to draw histograms
FitPanel - GUI to simple-minded fitting
Inspect - peek at attributes of objects
The following is an oversimplification, but good enough for a start:
a zone in the HIGZ window
CINT - a C++ interpreter. It contains the following three extensions to standard C++:
interactive usage, the semicolon at the end of a statement is not
required (but it is required in macros!)
-> can be abbreviated with . (example: hist->Draw() is equivalent to hist.Draw())
The following two lines are equivalent by definition and in order to save typing
= new TClass(...);
TClass *b = new TClass(...);
If an object is not declared upon first usage, CINT searches ROOT's global scope for an object with an identical name and sets up a pointer to it.
Macros, shared libs, ...
and terminating ROOT
Start ROOT (best after having done a srtpath in a testrelease) with
Terminate ROOT with
Note the '.' (a dot) in front of the 'q'.
You can suppress the startup logo with bbrroot -l. (It can be useful when you have programs running that took most of the colormap of your computer, the logo will show it immediately and you won't ponder on that very strange appearance of a 2-d histogram you might be looking at later.)
Looking at the Output of the Beta Tutorial
The output of your Beta tutorial should be a rootfile called framework.root. (You can copy it from ~ursl/tutorial/framework.root, if you did not make it yourself.) If you prefer to look at another file, you can convert any of your hbook files to a rootfile with
Start ROOT in the directory where your output rootfile is and then start the ROOT Browser with
root TBrowser b
Open the file by selecting File->Open in the menu bar and choosing the rootfilename. You'll see something similar to (the small gifs are links to full-size html pages. Click on them in case you can't read the details.)
Look at the contents of this file by double-clicking on ROOT files and then double-clicking on the filename of your rootfile. The display will now contain several objects in the right hand side of the browser:
Display a histogram by double clicking on its name,e.g. h1d3:
Click on Options in the menu bar and select Event Status. Click on the Canvas again and point to the histogram line with the mouse pointer. You should see a display of the bin contents (and other things) in the lowest row of the canvas.
Get the Editor by clicking on Edit->Editor in the menu bar of the canvas containing the histogram:
Get a DrawPanel by moving the mouse pointer to the histogram line in any bin (the pointer should change from a cross to a pointer), clicking the right mouse button and choosing DrawPanel:
Get a FitPanel by moving the mouse pointer to the histogram line in any bin (the pointer should change from a cross to a pointer), clicking the right mouse button and choosing FitPanel:
Back in the ROOT Browser: Show the variables contained in the tree by double clicking on the tree icon (ntp1):
Display the variable by double-clicking on its name:
Try clicking the right mouse button on the ntp1 icon, you'll get a context menu. To start the GUI for working with Trees, choose StartViewer from this context menu and select OK in the window prompting you for the width (ww) and height (wh) of the GUI.
and start playing (and read the FermiLab tutorials on how to work with this ...)
CINT in brief
CINT is quite sophisticated, but not perfect. You can crash it badly. You will restart ROOT much more often than PAW. You need some experience to know when you can continue with CINT after having had an error. Some people (sometimes) would not bet on results obtained with CINT.Keep that in mind when your macro gets complicated. Nothing beats the security and reassurance of a trustworthy C++ compiler.
That said, CINT is just wonderful for all the interactive display stuff usually needed for getting plots into a form suited for presentation.
CINT commands always start with a dot `.'. The most important ones include
Load and evaluate statements in the file bla.C
Load macro bla.C
Execute shellcommand in shell
Get list of CINT commands
CINT completes partially typed commands (absolutely wonderful!), provides you with a list of arguments a given function expects (wonderful, again!) and completes filenames you have to enter (how could PAW have survived so long without these essential features?). Try
root TFile f(<TAB>
root TFile f("fr<TAB>
where <TAB> indicates you have to hit the TAB key.
CINT allows you to scroll through your history of commands with the arrow keys (just like PAW). It keeps this history between sessions and you can scroll through previous sessions (unlike PAW). Very handy.
CINT also provides you with a search facility in its history, accessible with <Ctrl-r>. Try
root <CTRL-r> TF
Customizing your setup
ROOT version: BaBar's releases are tied to specific root versions (or vice versa). This infomation is kept in SoftRelTools/arch_spec_ROOT.mk. SLAC's ROOT installations are decoupled from BaBar software and are kept in
$ROOTSYS: Messing around with $ROOTSYS can be dangerous and time consuming - there are plenty of incompatibilities between different ROOT versions ... But: ROOT advances quite fast and sometimes you need the latest and greatest release (which is usually installed at SLAC within a reasonable time). In this case you need to set $ROOTSYS manually and make sure that LD_LIBRARY_PATH contains the correct shlib path. The following is an imperfect way to achieve this:
addpath2 PATH $ROOTSYS/bin
setenv LD_LIBRARY_PATH $ROOTSYS/lib
Altering you LD_LIBRARY_PATH in such a simple-minded way can have
If you decide to set $ROOTSYS yourself, it's best to have it point to a specific version and not to /afs/slac/package/cernroot/newroot, which can change at short notice and is not guaranteed to work.
.rootrc: A file used for setting up system defaults. Keep it as short as possible. Information contained therein can include
# Path used by dynamic loader to find shared libraries and macros
# Path where to look for TrueType fonts
rootlogon.C: The equivalent of pawlogon.kumac. Keep it as short as possible. The following can serve as an example (note the braces):
gROOT->LoadMacro("/u/ec/ursl/macros/functions.C"); // Have some (interpreted) functions predefined
gSystem.Load("/u/ec/ursl/macros/lib/libEmcUtil.so"); // Load some pre-compiled functions
gROOT->SetStyle("Default"); // just keep this and the next three for information al purposes
gROOT->SetStyle("Plain"); // still the best
gROOT->ForceStyle(); // Let this determine what style to use, not with what the rootfile was saved.
gStyle->SetOptStat(111111);// Show overflow and underflow as well
gStyle->SetPalette(1); // Get better colors than in the (useless) default
get things done in ROOT:
If you are looking for examples on how to define functions: Functions
Looking for (simple) operations for manipulating and histogramming from trees: Trees
Introductory howto's for working with histograms:Histograms
The fine points of transforming a histogram to something presentable: Making Plots
Stuff that does not fit into any category: Miscellaneous
How to peek at Kanga files
Thanks to Marcel Kunze, Leif Wilden and Rolf Dubitzky for providing the following:
root  f.ls()
KEY: TTree microDST;1 ROOT output stream
... lots of output ...
root microDST->Print(); > bla.txt // to dump it into a file (note the semicolon)
root cout << microDST->GetEntries() << endl; // How many entries are in this file?
Looking at the tag database:
// Draws R2 for all events
root microDST->Draw("TAG_f_R2","TAG_b_isBBbarLike>0"); // Draws R2 for all events with tag isBBbarLike
root microDST->Draw("TAG_f_R2:TAG_f_thrustMag","TAG_b_isBBbarLike>0", "box"); // a 2-d example
and the micro (nobody claims that this is sensible):
Does it contain MC truth?