430 likes | 467 Views
Introduction to ROOT. Summer Students Lecture 20 July 2005 Fons.Rademakers@cern.ch. ftp://root.cern.ch/root/SummerStudents2005.ppt. ROOT in a Nutshell. The ROOT system is an Object Oriented framework for large scale data handling applications Written in C++ Provides, among others,
E N D
Introduction to ROOT Summer Students Lecture 20 July 2005 Fons.Rademakers@cern.ch ftp://root.cern.ch/root/SummerStudents2005.ppt Introduction to ROOT
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
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
Download Source and Binaries • 27 binary • tar balls • + source Introduction to ROOT
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
ROOT Downloads 333,000 binaries download 1,500,000 clicks per month 140,000 user guides 1300 users subscribed to roottalk Introduction to ROOT
The ROOT Project Evolution ROOT 5.0 ROOT 4.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 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
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
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 normal operation mode Interesting feature for GUIs, config files, etc. Script Compiler root > .x file.C++ 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 • Shared libraries are mostly loaded via the plug-in manager Introduction to ROOT
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
Quick Overview • C++ interpreter • Data analysis and visualization tools • 2D and 3D graphics, Postscript, PDF, LateX • Geometrical modeller • Object persistency and Trees • GUI • Online services 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 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
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
The CINT Dictionary • 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 Introduction to ROOT
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
A Data Analysis & Visualization Tools Introduction to ROOT
Graphics: 1,2,3-D functions Introduction to ROOT
Full LateXsupport on screen and postscript Formula or diagrams can be edited with the mouse TCurlyArc TCurlyLine TWavyLine and other building blocks for Feynmann diagrams Introduction to ROOT
Alice 3 million nodes Introduction to ROOT
ROOT I/O : An Example Program Writing demoh.C TFile f(“example.root”,”new”); TH1F h(“h”,”My histogram”,100,-3,3); h.FillRandom(“gaus”,5000); h.Write(); Program Reading demohr.C TFile f(“example.root”); TH1F *h = (TH1F*)f.Get(“h”): h->Draw(); f.Map(); 20010831/171903 At:64 N=90 TFile 20010831/171941 At:154 N=453 TH1F CX = 2.09 20010831/171946 At:607 N=2364 StreamerInfo CX = 3.25 20010831/171946 At:2971 N=96 KeysList 20010831/171946 At:3067 N=56 FreeSegments 20010831/171946 At:3123 N=1 END Introduction to ROOT
Objects in directory /pippa/DM/CJ eg: /pippa/DM/CJ/h15 A Root file pippa.root with two levels of directories Introduction to ROOT
Memory <--> TreeEach Node is a Branch in the Tree Memory T.GetEntry(6) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 T.Fill() 18 T Introduction to ROOT tr
Example Writing a Tree All the examples can be executed with CINT or the compiler root > .x demoe.C root > .x demoe.C++ void 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 } Introduction to ROOT
Example Reading a Tree void 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 event in memory Introduction to ROOT
8 leaves of branch Electrons A double-click to histogram the leaf 8 Branches of T Introduction to ROOT
The Tree Viewer & Analyzer A very powerful class supporting complex cuts, event lists, 1-d,2-d, 3-d views parallelism Introduction to ROOT
0 1 2 3 4 5 0 6 0 1 7 1 2 2 8 3 3 9 4 4 10 5 5 6 6 11 7 7 12 8 8 13 9 9 10 14 10 11 15 11 12 16 12 13 13 17 14 14 15 18 16 15 17 16 18 17 18 Tree Friends Entry # 8 Public read User Write Public read Introduction to ROOT tr
Basic GUI Widgets Introduction to ROOT
GUI Example Introduction to ROOT
ROOT in Online • ROOT now used in many DAQ environments • Timers, shared memory, sockets • GUI & event display • Macros for rapid prototyping • Histogramming • Thread support Introduction to ROOT
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
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
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
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
My first session root root [0]344+76.8 (const double)4.20800000000000010e+002 root [1]float x=89.7; root [2]float y=567.8; root [3]x+sqrt(y) (double)1.13528550991510710e+002 root [4]float z = x+2*sqrt(y/6); root [5]z (float)1.09155929565429690e+002 root [6].q root See file $HOME/.root_hist root [0]try up and down arrows Introduction to ROOT
My second session root root [0].x session2.C for N=100000, sum= 45908.6 root [1]sum (double)4.59085828512453370e+004 Root [2] r.Rndm() (Double_t)8.29029321670533560e-001 root [3].q session2.C { 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); } unnamed macro executes in global scope Introduction to ROOT
My third session root root [0].x session3.C for N=100000, sum= 45908.6 root [1]sum Error: 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 session3.C 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); } Named macro Normal C++ scope rules Introduction to ROOT
My third session with ACLIC root [0] gROOT->Time(); root [1].x session4.C(10000000) for N=10000000, sum= 4.59765e+006 Real 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+006 Real time 0:00:01, CP time 1.052 root [4].q session4.C #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); } File session4.C Automatically compiled and linked by the native compiler. Must be C++ compliant Introduction to ROOT
Macros with more than one function root [0] .x session5.C >session5.log root [1].q root [0] .L session5.C root [1]session5(100); >session5.log root [2]session5b(3) sum(0) = 0 sum(1) = 1 sum(2) = 3 root [3].q session5.C 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); } } .x session5.C executes the function session5 in session5.C use gROOT->ProcessLine to execute a macro from a macro or from compiled code Introduction to ROOT
Interactive Demo You can import the tar file with all demos from ftp://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 Introduction to ROOT