Introduction to ROOT
Last time and today Last time we took a quick look at LATEX Today we will start the second half of the course ROOT A basic introduction. We start with really using ROOT next time when we talk about histograms.
What is ROOT? ROOT is a data analysis package It contains many useful tools Data analysis Histograms Fitting Plotting Mathematical libraries Data storage Data formats
ROOT and C++ ROOT is written in C++ It uses fully object oriented code. ROOT can be though of as a collection of libraries in C++ These can be used in your C++ code to do analysis tasks. ROOT input is in C++ It uses a C++ interpreter call CINT
Long long ago in a Before ROOT there came PAW This is part of CernLib This did a similar job Data Analysis Data Formats Data Storage It was written in FORTRAN Root is the extension of PAW into the object orientated ed world and is much more powerful. The writers knew PAWs strengths and weaknesses.
Documentation As with everything in this course there is good documentation on the WEB. In the case of ROOT there is one specific place. http://root.cern.ch This is the place to download d root from should you need it. There is lots of documentation and examples. I recommend you work through the tutorials that cover the material covered in these lectures.
Example root files. For this section of the course I have prepared some sample root files. These can be found in.. There are the following files. atlas_z0.root Z 0 events in ATLAS. sno_16n.root A calibration run from SNO.
Starting with root You need to have the environment variable ROOTSYS set to the root install directory. This will typically y be /usr/local/root But you (or your experiment) may have your own version of root installed. You will need to set ROOTSYS accordingly. You may also need to use LD_LIBRARY_PATH This tells programs where to look for libraries For vanilla root you shouldn t need to use this For expanded d version as with many experiment extra libraries may need to be specified It does depend on the build.
Launching and Quiting Root. To launch root just type: $ROOTSYS/bin/root You may want to add $ROOTSYS/bin to your path. You should see a splash screen appear, and then root start t up in your terminal. To quit use:.q
Loading a file To load a file you type. TFile f ( my_root_tree.root tree.root ) This creates a TFile object called f. The object f is attached to the file my_root_tree.root fi is a real object and dtherefore you can use all of fthe TFile member functions. f->close() close the file. f->ls() list the objects in a file.
Browsing a file. To easily browse a file we use TBrowser. TBrowser b This makes a TBroswer object called b Lets now take a quick look at TBrowser in Lets now take a quick look at TBrowser in action.
CINT and Macros CINT is somewhat loose in it s C++syntax. You can use either f.close() or f->close(). You ll be better off if you use the correct structure anyway. When typing in root you don t need the ; A macro is set of CINT instructions enclosed in { } at. These are at the start and end of the file. You now need ; Run a macro by.x my_macro.c Precompile the macro :.x my_macro.c+
.rootlogon.c The file.rootlogon.c in your home directory can be used to configure root to your liking. This can be used to set the system to what ever defaults you want. We can return to these when we know what a few of these things are. It works just like any other root macro and uses the same syntax.
Data Storage in ROOT There are a number of ways to store and present data in ROOT: Graphs A bit like EXCEL: plot x vs y Hisograms Binned data Ntuples Tables Trees Extensions of ntuples
Ntuples Trees Ntuples were the standard d way of storing data in PAW Each entry was an event Each event was a collection of variables In paw all floating point. The same variables for each event. Not generalizable. In root you can use a TNtuple class. A tree is a generalization of an ntuple. Ntuples are now special root trees.
Trees, Branches and Leaves A Tree is a collection of branches. Each branch corresponds to a variables, or collection of variables. Generally independent variables on different branches. Like variables (eg position x,y,z) on the same branch. Using a object such as a TVector3. The data on the branches are called Leaves These can be floating point, integer Or any object (with it s own member functions) you care to define.
Accessing my data inside a Tree. You need to know how to access the data inside your tree. Generally you will loop through the tree in a macro. We will talk about this in a basic way today and get more complex in later lectures.
Loading the root tree First you need to load the file. You then setup a pointer to the tree in the file and attach it to the tree you want. This gives you a TTree object. TFile f ( mytree.root ); Load the file into object f TTree *intree = (TTree*)f.Get( MyTree ); ( ); Create a pointer to a TTree object. Name of the Tree
Getting to the data. Say the data is in a variable energy and it s double precision. You need to define that variable, and then point it to the variable in the tree. Define the variable Double_t energy; The address of my variable. intree->setbranchaddress( energy energy,&energy); Point it to my variable in the tree. The name in the tree.
Looping through the Tree. You can now loop through the Tree. Loop index Use TTree member function GetEntries() to get loop limit for (Int _ t indx=0;indx<intree->getentries();indx++){ ){ intree->getentry(indx); cout << energy << endl; Load the current event. } You can now access your variable.
TTree::Print and TTree::Scan You can use the Print method to print out the variables in a tree. Tree->Print(); This will show each branch and how much data is stored there. The scan method will show the value of the specified variables for each event. Tree->Scan( var1:var2:var3 ); Useful if you want to see what s going on event by event.
TTree::Draw( () Once you have a pointer to your tree you can also directly plot variables. intree->draw( var1 ); intree->draw( var1:var2 ); intree->draw( var1, var2>10 ); intree->draw( var1, var2>10,options); The options are as for histograms and we ll cover these next time.
Exercises Make sure you can run root. Load it and quit. Take a look at the standard root files for the course with TBrowser to see what type of data we have. Try and plot some variables using TTree::Draw()