# Presentation: 177015

## ROOT

- An object oriented HEP analysis framework.

- Day 1

- ROOT Day1, Suzanne Panacek

## ROOT User's Workshop

- Fermilab
- June 13-15, 2001
- http://patwww/root/root2001/

- ROOT Day1, Suzanne Panacek

## The ROOT Team

- ROOT Day1, Suzanne Panacek

## ROOT contacts at Fermi

- Philippe Canal , x2545	pcanal@fnal.gov
- Suzanne Panacek, x8334	spanacek@fnal.gov
- Jeff Kallenbach, x2210
-   jeffk@fnal.gov

- ROOT Day1, Suzanne Panacek

## Mailing Lists

- the ROOT mailing list:
- _[roottalk@root.](mailto:roottalk@root.cern.ch)__[cern](mailto:roottalk@root.cern.ch)__[.](mailto:roottalk@root.cern.ch)__[ch ](mailto:roottalk@root.cern.ch)_
- archives:
- _[http://root.](http://root.cern.ch/root/roottalk/AboutRootTalk.html)__[cern](http://root.cern.ch/root/roottalk/AboutRootTalk.html)__[.](http://root.cern.ch/root/roottalk/AboutRootTalk.html)__[ch](http://root.cern.ch/root/roottalk/AboutRootTalk.html)__[/root/roottalk/](http://root.cern.ch/root/roottalk/AboutRootTalk.html)__[AboutRootTalk](http://root.cern.ch/root/roottalk/AboutRootTalk.html)__[.html](http://root.cern.ch/root/roottalk/AboutRootTalk.html)_
- Fermilab mailing list:
- _[about-root@fnal.gov](mailto:about-root@fnal.gov)_
- archives:
- _[http://listserv.fnal.gov/archives/about-root.html](http://listserv.fnal.gov/archives/about-root.html)_

- ROOT Day1, Suzanne Panacek

## Class Schedule:

- Day 2:
- Monday, 3/19/01 : 9AM – 11AM in EOC Large Class Room
- Day 3:
- Tuesday, 3/20/01 : 1PM- 3PM in EOC Large Class Room

- ROOT Day1, Suzanne Panacek

## Class Schedule - Day 1

- Overview of the ROOT Framework
- GUI basics
- Command line basics
- Finding Information (class reference guide)
- Getting started with the exercises

- ROOT Day1, Suzanne Panacek

## Class Schedule - Day 2 

- Root Commands and CINT
- Discuss Exercises
- Functions and Fitting
- The Tree Viewer

- ROOT Day1, Suzanne Panacek

## Class Schedule - Day 3 

- Building ROOT Trees
- Reading Trees
- Using Trees in Analysis
- TTree->Draw
- TTree->MakeClass
- Chains
- Exercise discussion
- How to add your Own Class
- With the Interpreter
- With the compiler (shared library)
- With ACLiC

- ROOT Day1, Suzanne Panacek

## ROOT Overview

- What about PAW
- Concepts: Object Oriented Design, Frameworks
- Services and Utilities
- Libraries
- Physical Organization

- ROOT Day1, Suzanne Panacek

## Differences from PAW 

- Regular grammar (C++) on command line
- Single language (compiled and interpreted)
- Object Oriented (use your class in the interpreter)
- Advanced Interactive User Interface
- Well Documented code. HTML class descriptions for every class.
- Object I/O including Schema Evolution
- 3-d interfaces with OpenGL and X3D.

- ROOT Day1, Suzanne Panacek

**Notes:**
Regular grammar (C++) on command line
Single languageWe have one single language C++ instead of a scripting and restricted language KUIP. The macros can be interpreted or dynamically executed via the compiler
Object OrientedThe main point is that from the interpreter one can call functions from the user classes if these classes have been run through rootcint. Because a full object dictionary is available we can do all kinds of things with the objects; All what is called reflection or introspection with Java is available in ROOT. This is an extremely important addition on top of C++. The dictionary is the heart of the system. It is with the dictionary that we can do automatic schema evolution for example or have the automatic context menus.
Interactive User Interface PAW had also an interactive interface (command line and also a mouse interface). The ROOT interface and the GUI is more advanced than PAW. This interface is user oriented. Picking is automatic in the pad.
Well Documented code. HTML class descriptions for every class.The Root code is better documented than the PAW code. Html documentation for the source is generated automatically and available from the Web. User classes can also be documented automatically via the THtml class.
Object I/O including Schema EvolutionI/O in ROOT cannot be compared with PAW I/O. PAW I/O was limited to simple histograms or ntuples. ROOT can be used as the main I/O engine for user classes including automatic schema evolution.
Root supports network classes (TCP/IP sockets, remote I/O via rootd) 

## PAW to ROOT File Conversion

- Get the example PAW file from http://www-pat.fnal.gov/root/examples/toyz.rz
- At the system prompt type
- > h2root toyz.rz  toyz.root
- Once you've done the conversion, you can then start a ROOT session and open toyz.root
- Also see: _http://root.cern.ch/root/HowtoConvert.html_

- ROOT Day1, Suzanne Panacek

## Object Oriented Concepts

- Members: a “has a” relationship to the class.
- Inheritance: an “is a” relationship to the class.

-  Class: the description of a “thing” in the system
-  Object: instance of a class
-  Methods: functions for a class

- ROOT Day1, Suzanne Panacek

**Notes:**
If you would like to refresh or even learn C++, we have a C++ on-line tutorial available at:
		www-pat/fnal/gov/root/CPlusPlus/index.html
Or you can read the chapter "A little C++" in the ROOT User's Guide

## A Framework

- provides utilities and services.

- ROOT Day1, Suzanne Panacek

## ROOT's Services/Utilities

- Histogramming and Fitting
- Graphics (2D, 3D)
- I/O to file or socket: specialized for histograms, Ntuples (Trees)
- Collection Classes and Run Time Type Identification
- User Interface
- GUI: Browsers, Panels, Tree Viewer
- Command Line interface: C++ interpreter CINT
- Script Processor (C++ compiled   C++ interpreted)

- ROOT Day1, Suzanne Panacek

## The Libraries

- Over 350 classes
- Core
- CINT
- Libraries loaded at startup: Hist, Tree ...
- Libraries loaded when needed: HistPainter, TreePlayer,...
- Special purpose libraries: EG, Physics...

- ROOT Day1, Suzanne Panacek

**Notes:**
There are several ways to use ROOT, one way is to run the executable by typing root at the system prompt another way is to link with the ROOT libraries and make the ROOT classes available in your own program. The libraries are designed and organized to minimize dependencies, such that you can include just enough code for the task at hand rather than having to include all libraries or one monolithic chunk.  
The core library (libCore.so) contains the essentials; it needs to be included for all ROOT applications.  In the diagram, you see that libCore is made up of Base classes, Container classes, Meta information classes, Networking classes, Operating system specific classes, and the ZIP algorithm used for compression of the ROOT files.

The CINT library (libCint.so) is also needed in all ROOT applications, but libCint can be used independently of libCore, in case you only need the C++ interpreter and not ROOT. That is the reason these two are separate. 

A batch program, one that does not have a graphic display, which creates, fills, and saves histograms and trees, only needs the core (libCore and libCint), libHist and libTree. If other libraries are needed ROOT loads them at runtime. For example if the TreeViewer is used, libTreePlayer and all the libraries the TreePlayer box has an arrow to, are loaded also. In this case: GPad, Graf3d, Graf, HistPainter, Hist, Tree, and Proof. The difference between libHist and libHistPainter is that the former needs to be explicitly linked and the latter will be loaded automatically at runtime when needed. In the diagram, the dark boxes outside of the core are automatically loaded libraries, and the light colored ones are not automatic. Of course, if one wants to access an automatic library directly, it has to be explicitly linked also. 

## The Framework Organization

- ROOT Day1, Suzanne Panacek

**Notes:**
$ROOTSYS/bin
The bin directory contains several executables. The main ones are:
root shows the ROOT splash screen and calls root.exe.
root.exe is the executable that root calls, if you use a debugger such as gdb, you will need to run root.exe directly.
rootcint is the utility root uses to create a class dictionary for CINT. You will see how this utility is used is the section about adding your own class to ROOT. 
cint is the C++ interpreter executable that is independent of ROOT.
$ROOTSYS/lib
There are several ways to use ROOT, one way is to run the executable by typing root at the system prompt another way is to link with the ROOT libraries and make the ROOT classes available in your own program. The libraries are designed and organized to minimize dependencies, such that you can include just enough code for the task at hand rather than having to include all libraries or one monolithic chunk.  
$ROOTSYS/tutorials
The tutorials directory contains many example macros.
$ROOTSYS/test
The test directory contains a set of examples that represent all areas of the framework. When a new release is cut, the examples in this directory are compiled and run to test the new release's backward compatibility. The $ROOTSYS/ test directory is a gold mine of ROOT-wisdom nuggets, and we encourage you to explore and exploit it.  
$ROOTSYS/include
The include directory contains the header files, this is especially important because the header files contain the class definitions. 

## Three User Interfaces

- GUIwindows, buttons, menus
- Root Command lineCINT (C++ interpreter)
- Macros, applications, libraries (C++ compiler and interpreter)

- ROOT Day1, Suzanne Panacek

## ROOT Overview Summary

- PAW
- Concepts: Object Oriented Design, Frameworks
- Services and Utilities
- Libraries
- Physical Organization

- ROOT Day1, Suzanne Panacek

## GUI Basics

- Browsing and opening files
- Drawing histograms
- Right click, left click, middle click
- Draw Panel
- Fit Panel
- Adding Color and Zooming
- Adding text and other objects
- Dividing the canvas
- Setting the log scale

- ROOT Day1, Suzanne Panacek

## GUI  Basics 

- Display the browser
- TBrowser b;

- Start root
- > root
- Quit root (just in case)
- root[0]>.q

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step:
  Start ROOT
> root  
Quit Root
root[0]> .q
Start Root again and create a browser object. The constructor of the browser will automatically draw the browser

> root
root[0]> TBrowser b;

## Displaying a Histogram 

- Display a histogram The Canvas

- Open the root file
- Browse the file

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step:
  1. select the Open menu item from the File menu
  2. select “Example.root” and click on Open
  3. Select the Refresh menu item in the View menu
  4. Double click on Example.root
  5. double click on myTree
  6. double click on the xs1

## Basic Navigation by Clicking

- Left Click
- select the object
- drag the object
- resize the object
- Right Click
- context menu
- class::name
- methods
- Middle Click
- activate canvas
- freezes event status bar

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step
  To bring up the context menu
	Right Click on the object 
  To drag an object
	Left Click, hold, and drag the mouse
 To select an object
	Left Click and hold
 To resize an object
	Place mouse over object border
	Left Click
	Drag the mouse
To create a new canvas and activate a canvas
	Select the New Canvas item in the File menu on the c1 canvas
	Use the middle mouse button to activate the old canvas c1
	Use the middle mouse button to activate the new canvas c1_n2
	Note the colored frame around the canvas that is active

## The Draw Panel

- The Event Status

- Adding Error bars
- Slider
- Defaults

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step
To show the Event Status bar:
  - Select the Event Status menu item in the Options menu.
  - The Event Status bar shows the title of the selected object , the name, the coordinate in pixels, and other object specific information.

To bring up the Draw Panel for the histogram
  - Select the horizontal part of the histogram
  - Right click to get the context menu
  - Select the Draw Panel
To draw the error bars
   - On the Draw Panel select “E1:errors/edges” and “Same Picture”
   - Click Draw
To zoom the histogram
    - select the left edge of the slider (the gray bar at the bottom) 
    - drag it to the right, this moves the left edge of the histogram 
    - do the same with the right side
    - select the slider and move it left or right to move the range
To return to the defaults
   - On the Draw Panel select Defaults
   - Click Draw

## Fitting, Coloring, and Zooming

- Adding a gaussian fit
- Coloring the histogram
- Zooming/unzooming

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step
To add a gaussian fit:
 - Select the horizontal part of the histogram outline
 - Right click to get the context menu
 - Select the Fit Panel
- Select “gaus” and “Same Picture” 
- Select Fit
To add color and fill 
     - Select the horizontal part of the histogram
 - Right click to get the context menu
 - Select the “SetFillAttributes”
- Select a color and your favorite pattern
- Select Apply
To zoom the X-Axis
- Left click on the left axis point (the cursor changes to a hand)
- Drag the mouse to the right axis point
- Release
To un zoom:
- Right click on the X-axis. This brings up the context menu for the X axis.
- Select unzoom from the context menu.

## Adding Objects to the Canvas

- The Editor
- Adding an Arrow
- Adding Text

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step
To add an Arrow
- Select the Editor menu item from the Edit menu, this brings up the Editor pallet
- Select the Arrow
- Place the mouse on the canvas where you want the arrow to begin and left click and hold
- Drag the mouse to where you want the arrow to end. Release. Now you should see an arrow.
To add Text
- From the Editor palette select the Text/Latex button
- Place the mouse on the canvas where you want the text to begin and left click.
- Type your text and type “Enter”.
- now you should have text displayed on the canvas
To delete an object
- Bring up the context menu by right clicking
- Select Delete

## Adding another Pad

- Add a Pad
- Select the new Pad
- Draw a histogram
- Add a title for the axis

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step
To add a Pad and draw a histogram in it
  - Select the Editor menu item from the Edit menu, this brings up the Editor. If you have the Editor already open just click on it to bring it into the foreground
  - Select the Pad from the Editor
  - Left Click and hold on the canvas where you want the upper left corner of the new Pad to be.
  - Drag until the outline fits the size you want for the new Pad
  - Make the new pad the active one by clicking on it with the middle mouse button
- Go to your browser and double click on xmain.
- Check your canvas and you should see a histogram in your new Pad. 
To add a title to the axis:
  - Right click on the axis (x or y) to display the context menu
  - Select SetTitle from the context menu.
  - Type the string you want to appear on the axis. In this example “X-Axis”
  - To center the title, right click on the axis to display the context menu.
  - Select CenterTitle. The dialog shows the value kTrue, click OK.

## Modifying the Statistics

- The Canvas in the Browser
- Setting the (7) statistics options
- default = 0001111

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step
To set the statistics options from the browser
- Bring the Browser window to the foreground by clicking on it
- Double click on the Canvases directory in the left panel
- Click on c1 to display the object that are on the c1 canvas
- Right click on “stats” to bring up the context menu for the statistics panel
- Select SetOptStat. This brings up a new dialog called “TPaveStats::SetOptStat”
- Enter “111111” in the text field in the dialog
- Select OK
Bring the canvas c1 to the foreground by clicking on it to see the new statistics.

The mode has up to seven digits that can be set to on (1) or off (0). Mode = iourmen  (default = 0001111)
·         n	=	1  	the name of histogram is printed
·         e	= 	1  	the number of entries printed
·         m	=	1  	the mean value printed
·         r	=	1  	the root mean square printed
·         u	=	1  	the number of underflows printed
·         o	=	1  	the number of overflows printed
·         i	=	1  	the integral of bins printed
When trailing digits is left out, they are assumed 0 

## Dividing the Canvas

- Create a new Canvas
- Divide it in 2
- Draw two histograms.
- 1. Lego plot
- 2. LogY

- ROOT Day1, Suzanne Panacek

**Notes:**
Step by Step
To create a new canvas:
On the Browser, select the File menu and New Canvas. 
To divide the canvas in two 
Right click on the new canvas. This will bring up the context menu.
Select Divide from the context menu. This brings up the divide dialog.
Enter 2 for the nx parameter and leave 1 for the ny parameter. These are the first two text fields in the dialog. 
To display the left histogram
Activate the left canvas by middle clicking on it.
Display the same histogram and select the Draw Panel for it.
On the Draw panel select lego1 and Draw.
To display the right histogram
Activate the right canvas by middle clicking on it.
Display the same histogram.
Right click on lower right canvas. The context menu should say TPad::c1_2.
Select the SetLogy item.

## Command Line Basics

- Use up and down arrows to recall commands
- $HOME/.root_hist
- Use emacs commands to navigate

- ROOT Day1, Suzanne Panacek

## Open a File

- Open a file for reading
- root [] TFile f("Example.root")
- Look at the contents of the file
- root [] f.ls()
- TFile**         Example.root    ROOT file
-  TFile*         Example.root    ROOT file
-   KEY: TTree    myTree;1        Example ROOT tree
-   KEY: TH1F     totalHistogram;1        Total Distribution
-   KEY: TH1F     mainHistogram;1 Main Contributor
-   KEY: TH1F     s1Histogram;1   First Signal
-   KEY: TH1F     s2Histogram;1   Second Signal

- ROOT Day1, Suzanne Panacek

## Plotting a Variable

- Plot a variable
- root [] myTree->Draw("xs1")
- Where did _myTree_ come from?
- ROOT executed an implicit gROOT->FindObject("myTree")
- And now..
- root[] f.ls()
- ... OBJ: TTree myTree  Example ROOT tree: 0 KEY: TTree myTree;1 Example ROOT tree

- ROOT Day1, Suzanne Panacek

## The ROOT File

- A TFile is a directory structure like UNIX
- Object in Memory (OBJ) Object on Disk (KEY)

- ROOT Day1, Suzanne Panacek

**Notes:**
This picture shows a TFile with five objects in the top directory (kObjA;1, kObjA;2, kObjB;1, kObjC;1 and kObjD;1). ObjA is on file twice with two different cycle numbers.  It also shows four objects in memory (mObjE, mObjeF, mObjM, mObjL).  It also shows several subdirectories. 

## The ROOT Tree

- Stores large quantities of same class objects:
- Optimize disk space
- Optimize access speed
- Had analysis methods (TTree::Draw)
- TNtuple is a TTree limited to floating point numbers.
- More details later ...

- ROOT Day1, Suzanne Panacek

**Notes:**
Why use Trees
We can use an example to illustrate the difference in saving individual objects vs. filling and saving the tree. Let's assume we have one million events and we write each one to a file, not using a tree. The TFile, being unaware that an event is always an event and the header information is always the same, will contain one million copies of the header. This header is about 60 bytes long, and contains information about the class, such as its name and title. For one million events, we would have 60,000,000 bytes of redundant information. For this reason, ROOT gives us the TTree class. A TTree is smart enough not to duplicate the object header, and is able to reduce the header information to about four bytes per object. 

## Fitting

- To add a Gaussian Fit
- root [] htemp->Fit("gaus")
- Where did _htemp_ come from?
- automatically generated histogram by the TTree::Draw command.

- ROOT Day1, Suzanne Panacek

## Color and Error Bars

- To add color
- root [] htemp->SetFillColor(9)
- See pg. 134 of the Users Guide for color index
- Or on any Canvas choose View:Colors
- Drawing Error Bars
- root[] htemp->Draw("E1,same")
- Many Draw Options
- See the User's Guide

- ROOT Day1, Suzanne Panacek

## Command Line Basics

- Open and browse a file
- Drawing histograms
- Adding a Fit
- Adding Error bars
- Adding Color

- ROOT Day1, Suzanne Panacek

## Where to Find Information

- The ROOT Home: _[http://root.](http://root.cern.ch/)__[cern](http://root.cern.ch/)__[.](http://root.cern.ch/)__[ch](http://root.cern.ch/)_
- Talks and publications on ROOT: _[http://root.cern.ch/root/Publications.html](http://root.cern.ch/root/Publications.html)_
- To get information on a specific class : _[http://root.cern.ch/root/html/ClassIndex.html](http://root.cern.ch/root/html/ClassIndex.html)_

- ROOT Day1, Suzanne Panacek

## Class Reference Guide

- Find the class in the index, for example TH1.
- Class Inheritance
- _[class ](file:///../../ROOT%20101/TDirectory.html)__[TH1](http://root.cern.ch/root/htmldoc/TH1.h)__[ : public ](file:///../../ROOT%20101/TDirectory.html)__[TNamed](http://root.cern.ch/root/htmldoc/TNamed.html)__[, public ](file:///../../ROOT%20101/TDirectory.html)__**TAttLine, public TAttFill, public TAttMarker**_
- Class Description
- Private members
- Public methods
- Code

- ROOT Day1, Suzanne Panacek

## Finding Examples

- The ROOT Tutorials: _[http://root.cern.ch/root/Tutorials.html](http://root.cern.ch/root/Tutorials.html)__ _
- The ROOT How To's: _[http://root.cern.ch/root/](http://root.cern.ch/root/Howto.html)__[Howto](http://root.cern.ch/root/Howto.html)__[.html](http://root.cern.ch/root/Howto.html)__ _
- For on-line help for a particular topic it's very useful to use their facility to search the ROOT site. _[http://root.cern.ch/root](http://root.cern.ch/root)_

- ROOT Day1, Suzanne Panacek

## More Information

- To subscribe to roottalk: _[http://root.cern.ch/root/roottalk/](http://root.cern.ch/root/roottalk/AboutRootTalk.html)__[AboutRootTalk](http://root.cern.ch/root/roottalk/AboutRootTalk.html)__[.html](http://root.cern.ch/root/roottalk/AboutRootTalk.html)_
- To submit a bug report:_[http://pcroot.cern.ch/root-bugs](http://pcroot.cern.ch/root-bugs)_
- About ROOT at Fermi: _[about-root@fnal.gov](mailto:about-root@fnal.gov)_
- 	_[http://ods.fnal.gov/ods/root-eval/current/](http://ods.fnal.gov/ods/root-eval/current/)_
- To subscribe to the about-root mailing list send mail to _[listserv@fnal.gov](mailto:mailserv@fnal.gov)_ with the body of the email: ***subscribe about-root email@addresses.***

- ROOT Day1, Suzanne Panacek

**Notes:**
To subscribe to the about-root mailing list send mail to listserv@fnal.gov with the body of the email: subscribe about-root email@addresses.

## Summary

- Overview of ROOT
- GUI Basics
- Command line basics
- Using the Class reference guide
- PAW to ROOT conversion

- ROOT Day1, Suzanne Panacek

## Getting started with the Exercises

- Go to: _[http://patwww.fnal.gov/root/class/Setup.htm](http://patwww.fnal.gov/root/class/Setup.htm)_ for setup instructions using Reflection and ssh on fcdfsgi2 and d0mino and minos1.
- Find the exercises on line at:
- _[http://patwww.fnal.gov/root/class/exercises.htm](http://patwww.fnal.gov/root/class/exercises.htm)_

- ROOT Day1, Suzanne Panacek