View
222
Download
1
Category
Tags:
Preview:
Citation preview
Introduction to ROOT 1
Summer Students Lecture20 July 2005
Fons.Rademakers@cern.ch
ftp://root.cern.ch/root/SummerStudents2005.ppt
Introduction to ROOT
Introduction to ROOT 2
ROOT in a Nutshell The ROOT system is an Object Oriented framework for
large scale data handling applications Written in C++ Provides, among others,
an efficient data storage and access system designed to support structured data sets (PetaBytes)
a query system to extract data from these data sets a C++ interpreter advanced statistical analysis algorithms (multi dimensional
histogramming, fitting, minimization and cluster finding) scientific visualization tools with 2D and 3D graphics an advanced Graphical User Interface
The user interacts with ROOT via a graphical user interface, the command line or batch scripts
The command and scripting language is C++, thanks to the embedded CINT C++ interpreter and large scripts can be compiled and dynamically loaded
Introduction to ROOT 3
ROOT: An Open Source Project
The project is developed as a collaboration between:
Full time developers: 12 people full time at CERN 2 developers at FermiLab 1 developer in Japan (Agilent Technologies) 2 developers at MIT
Large number of part-time contributors Source freely available (cvs and tarballs) Release early, release often Several thousand users giving feedback
and providing many small contributions
Introduction to ROOT 4
27 binarytar balls+ source
Download Source and Binaries
Introduction to ROOT 5
Makefiles
3 major OS’es (Unix, Windows, Mac OS X) 32 and 64 bit little and big endian
10 different compilers gcc with many flavors on nearly all
platforms, Solaris: CC4,5, HPUX: aCC, SGI: CC, AIX:
xlC Alpha: CXX6, Windows: VC++6,7 Intel icc on Linux
37 Makefiles
Introduction to ROOT 6
ROOT Downloads
333,000 binaries
download
1,500,000 clicksper month
140,000user guides
1300 userssubscribed to
roottalk
Introduction to ROOT 7
The ROOT Project Evolution
1995 2000 2005
ROOT 0.5
ROOT 1.0
ROOT 2.0
ROOT 3.0
LEP,HERA,SPS
RHIC, FNAL/RUN II, Babar,KEK
LHCLarge Hadron Collider
functionality
ROOT 4.0ROOT 5.0
Introduction to ROOT 8
The ROOT Web Site
http://root.cern.ch General Information and News
Download sources and binaries
HowTo’s & Tutorials
User Guide & Reference Guide
Roottalk Digest & Forum
Printed copies of the user guide are available from
Ilka Antcheva, room 32-R-C13
Introduction to ROOT 9
Fundamental features of an Object-Oriented Data Analysis Framework
Object Persistency must be simple for simple applications:
histograms, simple simulations, test beams must be efficient for Perabytes of data
User Interface, must have command and script mode interpreted code <===> compiled code GUI and browsers
Class Dictionary is the vital element
Introduction to ROOT 10
ROOT: Framework & Library
User classes
user can define new classes interactively
either via calling API or sub-classing API
these classes can inherit from ROOT classes
Dynamic linking
interpreted code can call compiled code
compiled code can call interpreted code
macros can be dynamically compiled & linked
This is the normaloperation mode
Interesting featurefor GUIs,
config files, etc.
Script Compilerroot > .x file.C++
Introduction to ROOT 11
ROOT Library Structure ROOT libraries are a layered structure The CORE classes are always required (support for RTTI,
basic I/O and interpreter) The optional libraries (you load only what you use).
Separation between data objects and the high level classes acting on these objects. Example, a batch job uses only the histogram library, no need to link histogram painter library
Shared libraries reduce the application link time Shared libraries reduce the application size ROOT shared libraries can be used with other class libraries Shared libraries are mostly loaded via the plug-in manager
Introduction to ROOT 12
The ROOT Libraries Over 1000
classes
1,350,000 lines of code
CORE (12 Mbytes)
CINT (2 Mbytes) Green libraries
linked on demand via plug-in manager (only a subset shown)
Introduction to ROOT 13
C++ interpreter Data analysis and visualization tools 2D and 3D graphics, Postscript, PDF,
LateX Geometrical modeller Object persistency and Trees GUI Online services
Quick Overview
Introduction to ROOT 14
CINT CINT is a C and C++ interpreter Written by Masaharu Goto and available under an
Open Source license It implements about 95% of ANSI C and 95% of
ANSI C++ It is robust and complete enough to interpret
itself (85000 lines of C++) Has good debugging facilities In most cases it is faster than tcl, perl, python
Introduction to ROOT 15
CINT in ROOT
CINT is used in ROOT: as command line interpreter as script interpreter to generate class dictionaries to generate function/method calling
stubs The command line, script and
programming language become the same Large scripts can be compiled for optimal
performance
Introduction to ROOT 16
The dictionary provided by CINT is the nerve-centre of ROOT
The dictionary provides the Run Time Type Information (RTTI)
The rootcint program is used to parse the classes and generate the dictionaries
RTTI is used by the I/O services By definition the interpreter is based on it The GUI context sensitive menus The browsers, object inspectors The ROOT utilities to draw class diagrams The html documentation generator The signal/slot mechanism
The CINT Dictionary
Introduction to ROOT 17
CINT as Interpreter
CINT is used as command line interpreter:
And as script interpreter:
root[0] for (int i = 0; i < 10; i++) printf(“Hello\n”)root[1] TF1 *f = new TF1(“f”, “sin(x)/x”, 0, 10)root[2] f->Draw()
bash$ cat script.C{ for (int i = 0; i < 10; i++) printf(“Hello\n”); TF1 *f = new TF1(“f”, “sin(x)/x”, 0, 10); f->Draw();}root[0] .x script.C
Introduction to ROOT 18
A Data Analysis & Visualization Tools
Introduction to ROOT 19
Graphics: 1,2,3-D functions
Introduction to ROOT 20
Full LateX support
on screen and
postscript
TCurlyArcTCurlyLineTWavyLine
and other building blocks for Feynmann diagrams
Formula or
diagrams can beedited
with the mouse
Introduction to ROOT 21
Alice 3 million nodes
Introduction to ROOT 22
ROOT I/O : An Example
TFile f(“example.root”,”new”);
TH1F h(“h”,”My histogram”,100,-3,3);
h.FillRandom(“gaus”,5000);
h.Write();
TFile f(“example.root”);
TH1F *h = (TH1F*)f.Get(“h”):
h->Draw();
f.Map();
Program Writing
Program Reading
20010831/171903 At:64 N=90 TFile 20010831/171941 At:154 N=453 TH1F CX = 2.0920010831/171946 At:607 N=2364 StreamerInfo CX = 3.2520010831/171946 At:2971 N=96 KeysList 20010831/171946 At:3067 N=56 FreeSegments 20010831/171946 At:3123 N=1 END
demoh.C
demohr.C
Introduction to ROOT 23
A Root file pippa.rootwith two levels of
directories
Objects in directory/pippa/DM/CJ
eg:/pippa/DM/CJ/h15
Introduction to ROOT 24
Memory <--> TreeEach Node is a Branch in the Tree
0123456789101112131415161718
T.Fill()
T.GetEntry(6)
T
Memory
Introduction to ROOT 25
Example Writing a Treevoid demoe(int nevents) { //load shared lib with the Event class gSystem->Load("$ROOTSYS/test/libEvent"); //create a new ROOT file TFile f("demoe.root",”new"); //Create a ROOT Tree with one single top level branch int split = 99; //try also split=1 and split=0 int bufsize = 16000; Event *event = new Event; TTree T("T","Event demo tree"); T.Branch("event","Event",&event,bufsize,split); //Build Event in a loop and fill the Tree for (int i = 0; i < nevents; i++) { event->Build(i); T.Fill(); } T.Print(); //Print Tree statistics T.Write(); //Write Tree header to the file
}
All the examples can be executedwith CINTor the compiler
root > .x demoe.Croot > .x demoe.C++
Introduction to ROOT 26
Example Reading a Treevoid demoer() { //load shared lib with the Event class gSystem->Load("$ROOTSYS/test/libEvent"); //connect ROOT file TFile *f = new TFile("demoe.root"); //Read Tree header and set top branch address Event *event = 0; TTree *T = (TTree*)f->Get("T"); T->SetBranchAddress("event",&event); //Loop on events and fill an histogram TH1F *h = new TH1F("hntrack","Number of tracks",100,580,620); int nevents = (int)T->GetEntries(); for (int i = 0; i < nevents; i++) { T->GetEntry(i); h->Fill(event->GetNtrack()); } h->Draw();
}
Rebuilds the full eventin memory
Introduction to ROOT 27
8 Branches of T
8 leaves of branchElectrons
A double-clickto histogram
the leaf
Introduction to ROOT 28
The Tree Viewer & Analyzer
A very powerful classsupporting
complex cuts,event lists,
1-d,2-d, 3-d viewsparallelism
Introduction to ROOT 29
Tree Friends
0123456789101112131415161718
0123456789101112131415161718
0123456789101112131415161718
Public
read
Public
read
User
Write
Entry # 8
Introduction to ROOT 30
Basic GUI Widgets
Introduction to ROOT 31
GUI Example
Introduction to ROOT 32
ROOT now used in many DAQ environments Timers, shared memory, sockets GUI & event display Macros for rapid prototyping Histogramming Thread support
ROOT in Online
Introduction to ROOT 33
General Remarks In 1995, we had planned less than 50% of ROOT 2005.
importance of dictionary, RTTI automatic Schema Evolution effort in GUI online requirements (threads, timers, sockets, etc.)
Development of a system is driven by: ideas from authors ideas from users new ideas and techniques in computing OS development, in 1995, push for Windows, Linux not here language developments (e.g. template support, exception handling, Java) cooperation with other systems (e.g. Oracle, Corba, Qt, etc.) manpower
Users expect stable and working systems. Quality of a system should
improve with time. Often in contradiction with major new developments.
Introduction to ROOT 34
ROOT: an Evolving System
The ROOT system has been in continuous development since 1995 surviving major changes, major enhancements and an ever increasing number of users.
In the same way that ROOT 2005 is far from the original ROOT 1995, we expect that ROOT 2010 will include many contributions reflecting the continuous changes and new ideas in the field of computing.
This implies a strong cooperation between software developers and the software users.
ROOT is being developed in very close cooperation with a cloud of software developers in science but also in the commercial world.
Introduction to ROOT 35
Playing with ROOT on lxplus
Set the environment variables export
ROOTSYS=/afs/cern.ch/sw/root/v5.02.00/slc3_gcc3.2.3/root
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH
export PATH=$ROOTSYS/bin:$PATH Copy the ROOT tutorials
cd $HOME cp $ROOTSYS/tutorials . cd tutorials
Run ROOT root
Introduction to ROOT 36
Playing with ROOT on a PC Import a binary tar file from:
http://root.cern.ch/root/Version502.html E.g.: Intel x86 Linux for SLC 3 and gcc 3.2.3, version
5.02/00 Untar the file in your home directory
cd $HOME tar zxvf root_v5.02.00.Linux.slc3.gcc3.2.3.tar.gz
Set the environment variables export ROOTSYS=$HOME/root export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH export PATH=$ROOTSYS/bin:$PATH
Go to the ROOT tutorials cd $HOME cp $ROOTSYS/tutorials . cd tutorials
Run ROOT root
Introduction to ROOT 37
My first session
root [0] 344+76.8(const double)4.20800000000000010e+002root [1] float x=89.7;root [2] float y=567.8;root [3] x+sqrt(y)(double)1.13528550991510710e+002root [4] float z = x+2*sqrt(y/6);root [5] z(float)1.09155929565429690e+002root [6] .q
root
root
root [0] try up and down arrows
See file $HOME/.root_hist
Introduction to ROOT 38
My second session
root [0] .x session2.Cfor N=100000, sum= 45908.6
root [1] sum(double)4.59085828512453370e+004
Root [2] r.Rndm()(Double_t)8.29029321670533560e-001
root [3] .q
root
{ int N = 100000; TRandom r; double sum = 0; for (int i = 0; i < N; i++) { sum += sin(r.Rndm()); } printf("for N=%d, sum= %g\n",N,sum);}
session2.C
unnamed macroexecutes in global scope
Introduction to ROOT 39
My third session
root [0] .x session3.Cfor N=100000, sum= 45908.6
root [1] sumError: Symbol sum is not defined in current scope*** Interpreter error recovered ***
Root [2] .x session3.C(1000)for N=1000, sum= 460.311
root [3] .q
root
void session3 (int N=100000){ TRandom r; double sum = 0; for (int i = 0; i < N; i++) { sum += sin(r.Rndm()); } printf("for N=%d, sum= %g\n",N,sum);}
session3.C
Named macroNormal C++ scope
rules
Introduction to ROOT 40
My third session with ACLIC
root [0] gROOT->Time();root [1] .x session4.C(10000000)for N=10000000, sum= 4.59765e+006Real time 0:00:06, CP time 6.890
root [2] .x session4.C+(10000000)
for N=10000000, sum= 4.59765e+006 Real time 0:00:09, CP time 1.062
root [3] session4(10000000)for N=10000000, sum= 4.59765e+006Real time 0:00:01, CP time 1.052
root [4] .q
#include “TRandom.h”void session4 (int N) { TRandom r; double sum = 0; for (int i=0;i<N;i++) { sum += sin(r.Rndm()); } printf("for N=%d, sum= %g\n",N,sum);}
session4.C
File session4.CAutomatically compiled
and linked by thenative compiler.
Must be C++ compliant
Introduction to ROOT 41
Macros with more than one function
root [0] .x session5.C >session5.logroot [1] .q
void session5(int N=100) { session5a(N); session5b(N); gROOT->ProcessLine(“.x session4.C+(1000)”);}void session5a(int N) { for (int i=0;i<N;i++) { printf("sqrt(%d) = %g\n",i,sqrt(i)); }}void session5b(int N) { double sum = 0; for (int i=0;i<N;i++) { sum += i; printf("sum(%d) = %g\n",i,sum); }}
session5.C
.x session5.Cexecutes the function
session5 in session5.C
root [0] .L session5.Croot [1] session5(100); >session5.logroot [2] session5b(3)sum(0) = 0sum(1) = 1sum(2) = 3
root [3] .q
use gROOT->ProcessLineto execute a macro from a
macro or from compiled code
Introduction to ROOT 42
Interactive Demo
You can import the tar file with all demos fromftp://root.cern.ch/root/SummerStudents2005.tar.gz
root summershow.C
You can find more demos, examples, tests at
$ROOTSYS/tutorials
$ROOTSYS/test
$ROOTSYS/test/RootShower
Recommended