780 likes | 803 Views
Introduction to ROOT. Summer Students Lecture 16 July 2003 Ren é Brun CERN/EP/SFT. http://root.cern.ch. What is ROOT?. The ROOT system is an Object Oriented framework for large scale data handling applications Written in C++ Provides, among others, An efficient hierarchical OO database
E N D
Introduction to ROOT Summer Students Lecture 16 July 2003 René Brun CERN/EP/SFT http://root.cern.ch Introduction to ROOT
What is ROOT? • The ROOT system is an Object Oriented framework for large scale data handling applications • Written in C++ • Provides, among others, • An efficient hierarchical OO database • A C++ interpreter • Advanced statistical analysis (multi dimensional histogramming, fitting, minimization and cluster finding algorithms) • Visualization tools • And much, much more • 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
The ROOT Project ROOT X.0 functionality ROOT 3.0 LHC Large Hadron Collider ROOT 2.0 RHIC, FNAL/RUN II, Babar,KEK ROOT 1.0 LEP,HERA,SPS ROOT 0.5 1995 2000 2005 Introduction to ROOT
The ALICE detector(1100 physicists) Introduction to ROOT
A collision in CMS Introduction to ROOT
From the desktop to the GRID Online/Offline Farms Local/remote Storage Desktop New data analysis tools must be able to use in parallel remote CPUS, storage elements and networks in a transparent way for a user at a desktop GRID Introduction to ROOT
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 Introduction to ROOT
The Libraries • Over 700 classes • 950,000 lines of code • CORE (10 Mbytes) • CINT (3 Mbytes) • Green libraries linked on demand via plug-in manager (only a subset shown) Introduction to ROOT
ROOT: a Framework and a Library • User classes • User can define new classes interactively • Either using 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 normal operation mode Interesting feature for GUIs & event displays Script Compiler root > .x file.C++ Introduction to ROOT
Dynamic Linking • A Shared Library can be linked dynamically to a running executable module • either via explicit loading,- or automatically via plug-in manager Experiment libraries A Shared Library facilitates the development and maintenance phases User libraries General libraries Application Executable Module Introduction to ROOT
Plug-in Manager Exp Shared libs User Shared lib Exp Shared libs Exp Shared libs Basic Services, GUI, Math.. General Utility Shared lib Plug-in manager I/O manager I/O manager Interpreter Object Dictionary Introduction to ROOT
CINT Interpreter Introduction to ROOT
Command Line Options • > root -/? • Usage: root [-l] [-b] [-n] [-q] [file1.C ... fileN.C] • Options: • -b : run in batch mode without graphics • -n : do not execute logon and logoff macros as specified in .rootrc • -q : exit after processing command line macro files • -l : do not show splash screen Introduction to ROOT
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 90% of ANSI C++ • It is robust and complete enough to interpret itself (90000 lines of C, 5000 lines of C++) • Has good debugging facilities • Has a byte code compiler • In many cases it is faster than tcl, perl and python Introduction to ROOT
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
Scripts • Un-named Script • Start with "{" and end with "}" • All variables are in the global scope • No class definitions • No function declarations • No parameters • Named Script • C++ functions • Scope rules follow standard C++ • Function with the same name as the file is executed with a .x Parameters Class definitions (derived from a compiled class at your own risk) Introduction to ROOT
Scripts Examples • Un-named Macro:hello.C { cout << "Hello" << endl; } • Named Macro:say.C void say(char * what = "Hello") { cout << what << endl; } • Executing the Named Macro root [3].x say.C Hello root [4].x say.C("Hi there") Hi there Introduction to ROOT
The Object Dictionary Object Dictionary Data dictionary Functions dictionary Inspectors Browsers I/O Interpreted scripts GUI Command line Compiled code Introduction to ROOT
Providing Interactive Access • To provide interactive access to your classes from CINT you only need to generate a dictionary for your classes • No other instrumentation is needed Introduction to ROOT
rootcint –f MyDict.cxx –c MyClass.h MyDict.h MyDict.cxx compile and link libMyClass.so Generating a Dictionary MyClass.h MyClass.cxx Introduction to ROOT
Graphics & GUI Introduction to ROOT
Gui/Graphics strategy User/Root GUI and Graphics classes Applications see only Abstract Interfaces High level pad graphics TVirtualPad Low level screen graphics and GUI TVirtualX TPad TGWin32 TGQt TG?? TGX11 TGWin32GDK Introduction to ROOT
TPad: main graphics container Root > TLine line(.1,.9,.6,.6) Root > line.Draw() Root > TText text(.5,.2,”Hello”) Root > text.Draw() Hello The Draw function adds the object to the list of primitives of the current pad. If no pad exists, a pad is automatically created with a default range [0,1]. When the pad needs to be drawn or redrawn, the object Paint function is called. Only objects deriving from TObject may be drawn in a pad Root Objects or User objects Introduction to ROOT
Canvas pixmaps Need Help? Scroll bars 1200x800 600x400 Introduction to ROOT
Saving a pad/canvas • A pad/canvas may be saved in many formats using the GUI menu or via TPad::SaveAs • canvas.C : a C++ script is automatically generated. The canvas may be generated again via .x canvas.C • canvas.ps(eps) Postscript or encapsulated ps • canvas.svg : scalable vector graphics • canvas.gif • canvas.root: keep objects in a compressed and portable format. Introduction to ROOT
Full LateXsupport on screen and postscript latex3.C Formula or diagrams can be edited with the mouse Feynman.C TCurlyArc TCurlyLine TWavyLine and other building blocks for Feynmann diagrams Introduction to ROOT
Graphs TGraphErrors(n,x,y,ex,ey) TGraph(n,x,y) gerrors2.C TCutG(n,x,y) TMultiGraph TGraphAsymmErrors(n,x,y,exl,exh,eyl,eyh) Introduction to ROOT
Graphs zdemo.C Introduction to ROOT
The Histogram Package Introduction to ROOT
The Histogram Classes • Structure 1-Dim 2-Dim 3-Dim Introduction to ROOT
Histograms Introduction to ROOT
Peak Finder + Deconvolutions TSpectrum Introduction to ROOT
Fitting TMinuit TFumili TFitter TVirtualFitter TH1::Fit bin chisquare bin likelihood TTree::Fit unbinned likelihood TGraph::Fit unbinned chisquare User Introduction to ROOT
Fitting histograms • Histograms (1-D,2-D,3-D and Profiles) can be fitted with a user specified function via TH1::Fit. Two Fitting algorithms are supported: Chisquare method and Log Likelihood • The user functions may be of the following types: • standard functions: gaus, landau, expo, poln • combination of standard functions; poln + gaus • A C++ interpreted function or a C++ precompiled function • An option is provided to compute the integral of the function bin by bin instead of simply compute the function value at the center of the bin. • When an histogram is fitted, the resulting function with its parameters is added to the list of functions of this histogram. If the histogram is made persistent, the list of associated functions is also persistent. • One can retrieve the function/fit parameters with calls such as: • Double_t chi2 = myfunc->GetChisquare(); • Double_t par0 = myfunc->GetParameter(0); //value of 1st parameter • Double_t err0 = myfunc->GetParError(0); //error on first parameter Introduction to ROOT
Fitting Example Introduction to ROOT
Random Numbers and Histograms • TH1::FillRandom can be used to randomly fill an histogram using • the contents of an existing TF1 analytic function • another histogram (for all dimensions). • For example the following two statements create and fill an histogram 10000 times with a default gaussian distribution of mean 0 and sigma 1: • TH1F h1("h1","histo from a gaussian",100,-3,3); • h1.FillRandom("gaus",10000); • TH1::GetRandom can be used to return a random number distributed according the contents of an histogram. Introduction to ROOT
1-D drawing Options Any object in the canvas is clickable and editable Introduction to ROOT
2-D drawing options Introduction to ROOT
2-D drawing options Introduction to ROOT
2-D drawing Options All these plots can be rotated with the mouse Introduction to ROOT
2-D drawing Options Same output on the screen and with vector Postscript Introduction to ROOT
Filling with string variables Introduction to ROOT
3-D Graphics • Basic primitives • TPolyLine3D, TPolyMarker3D, THelix, TMarker3DBox,TAxis3D • Geant primitives • Support for all Geant3 volumes + a few new volume types • TBRIK,TCONE,TCONS,TCTUB,TELTU,TGTRA,THYPE,TPARA,TPCON, TPGON,TSPHE,TTUBE,TTUBS,TTRAP,TTRD1,TTRD2,TXTRU • Geometry package • Rendering with: • TPad • X3D (very fast. Unix only. Good on networks) • OpenGL • OpenInventor (new addition in 3.01) Introduction to ROOT
Some detectors in ROOT geometry Introduction to ROOT
Alice 3 million nodes Introduction to ROOT
Graphics : 1,2,3-D functions FittingDemo.C surfaces.C TF3 f3(“f3”,”sin(x*x+y*y+z*z-36)”,-2,2,-2,2,-2,2); f3->Draw(); Introduction to ROOT
GUI User example Example of GUI based on ROOT tools Each element is clickable Introduction to ROOT
GUI Examples Introduction to ROOT