ROOT Toolkit (I)
description
Transcript of ROOT Toolkit (I)
ROOT TOOLKIT (I)
Técnicas Fundamentales de
Simulación, Reconstrucción y
Análisis de Datos en Física
Experimental de Partículas
Isidro González Caballero (Universidad de Oviedo)
Valencia, 07-11/05/20102
66
ROOT (http://root.cern.ch) 2
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
ROOT in a Nutshell3
The ROOT system is an Object Oriented framework for large scale data handling applications. It is 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 scripts
The command and scripting language is C++, thanks to the embedded CINT C++ interpreter, and large scripts can be compiled and dynamically loaded.
A Python shell is also provided.
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
The ROOT Libraries
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
4
Over 1500 classes
1,550,000 lines of code
CORE (8 Mbytes) CINT (2 Mbytes)
Green libraries linked on demand via plug-in manager (only a subset shown)
100 shared libs
ROOT: An Open Source Project
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
5
The project was started in 1995.
The project is developed as a collaboration between: Full time developers:
11 people full time at CERN (PH/SFT) +4 developers at Fermilab/USA, Protvino , JINR/Dubna (Russia)
Large number of part-time contributors (155 in CREDITS file)
A long list of users giving feedback, comments, bug fixes and many small contributions 2400 registered to RootForum 10,000 posts per year
An Open Source Project, source available under the LGPL license
ROOT: a Framework and a Library
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
6
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 normaloperation mode
Interesting featurefor GUIs & event displays
Script Compilerroot > .x file.C++
ROOT Application Domains7
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
Data Storage: Local, Network
Data Analysis & Visualization
General Fram
ework
Three User Interfaces
GUIwindows, buttons, menus
Command lineCINT (C++ interpreter)
Macros, applications, libraries (C++ compiler and interpreter)
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos
en F. Exp. de Partículas
8
CINT Interpreter
CINT in ROOT
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
10
CINT is used in ROOT: As command line interpreter As script interpreter To generate class dictionaries To generate function/method calling stubs Signals/Slots with the GUI
The command line, script and programming language become the same
Large scripts can be compiled for optimal performance
Compiled versus Interpreted
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
11
Why compile? Faster execution, CINT has limitations…
Why interpret? Faster Edit → Run → Check result → Edit
cycles ("rapid prototyping"). Scripting is sometimes just easier.
Are Makefiles dead? No! if you build/compile a very large
application Yes! ACLiC is even platform independent!
Starting ROOT
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
12
1. Open a terminal2. Set the ROOT
environment3. Launch ROOT through
the root command.
Command parameters:1. -l: Do not show splash
screen2. -b: Run in batch mode
without graphics3. -q: Exit after
processing command line macro files
4. -n: Do not execute logon and logoff macros as specified in .rootrc
$ source /opt/root/bin/thisroot.sh$ root ******************************************* * * * W E L C O M E to R O O T * * * * Version 5.32/00 2 December 2011 * * * * You are welcome to visit our Web site * * http://root.cern.ch * * * *******************************************
ROOT 5.32/00 (tags/v5-32-00@42375, Dec 02 2011, 12:42:25 on linuxx8664gcc)
CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010Type ? for help. Commands must be C++ statements.Enclose multiple statements between { }.root [0]
Running Code
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
13
To run function mycode() in file mycode.C:root [0] .x mycode.C
Equivalent: load file and run function:root [1] .L mycode.C
root [2] mycode()
All of CINT's commands (help):root [3] .h
Running Code
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
14
Macro: file that is interpreted by CINT (.x)
Execute with .x mymacro1.C(42)
Also unnamed macros in next slide
int mymacro1(int value) { int ret = 42; ret += value; return ret;}
Unnamed Macros
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
15
No functions, just statements
Execute with .x mymacro2.C No functions thus no arguments!
Named macro recommended!Compiler prefers it, too…
{ float ret = 0.42; return sin(ret);} No need to include
math header or library
Running Code – Libraries
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
16
“library” here refers to both compiled code and actual shared libraries CINT can call its functions, classes, …!
To build a library from a macro we use ACLiC!(Automatic Compiler of Libraries for CINT)
Option 1: Compile only if “needed” by checking modification dates.x mymacro.C+(42)
Use "+" instead of writing a Makefile… Option 2: Compile in any case
.x mymacro.C++(42)
CINT will know all functions in mymacro_C.so
My first session17
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
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
My second session18
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
root [0] .x session2.Cfor N=100000, sum= 45908.6root [1] sum(double)4.59085828512453370e+004Root [2] r.Rndm()(Double_t)8.29029321670533560e-001root [3] .q
root
{ int N = 100000; TRandom r; double sum = 0; for (int i=0; i < N; i++) { sum += sin(r.Rndm()); } cout << "for N=" << N << ", sum=“ << sum << endl;}
session2.C
Unnamed macro executes in global scope
My third session19
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
root [0] .x session3.Cfor N=100000, sum= 45908.6root [1] sumError: Symbol sum is not defined in current scope*** Interpreter error recovered ***Root [2] .x session3.C(1000)for N=1000, sum= 460.311root [3] .q
ROOT
void session3 (int N=100000) { TRandom r; double sum = 0; for (int i=0; I < N; i++) { sum += sin(r.Rndm()); } cout << "for N=" << N << ", sum=“ << sum << endl;}
session3.C
Named macro: Normal C++ scope
rules
My third session with ACLIC20
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
root [0] gROOT->Time();root [1] .x session4.C(10000000)for N=10000000, sum= 4.59765e+006Real time 0:00:06, CP time 6.890root [2] .x session4.C+(10000000)for N=10000000, sum= 4.59765e+006 Real time 0:00:09, CP time 1.062root [3] session4(10000000)for N=10000000, sum= 4.59765e+006Real time 0:00:01, CP time 1.052root [4] .q
#include "TRandom.h“#include <iostream>using namespace std;void session4 (int N) { TRandom r; double sum = 0; for (int i = 0; i < N; i++) { sum += sin(r.Rndm()); } cout << "for N=" << N << ", sum=" << sum << endl;}
session4.C
File session4.CAutomatically compiled and linked by the native compiler.Must be C++ compliant
root [0] .L session5.Croot [1] session5(100); >session5.logroot [2] session5b(3)sum(0) = 0sum(1) = 1sum(2) = 3root [3] .q
Macros with more than one function
21
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
root [0] .x session5.C >session5.logroot [1] .q
session5.C
.x session5.CExecutes the function session5 in 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++) { cout << "sqrt(" << i << ") = " << sqrt(i) << endl; }}void session5b(int N) { double sum = 0; for (int i = 0; i < N; i++) { sum += i; cout << "sum(" << i << ") = " << sum << endl; }}
Use gROOT->ProcessLine() to execute a macro from a macro or from compiled code
Generating a Dictionary22
Téc. Fund. de Simulación, Reconstrucción y Análisis de datos en F. Exp. de Partículas
MyClass.h
MyClass.cxx rootcint –f MyDict.cxx –c MyClass.h
compile and link
libMyClass.so
MyDict.hMyDict.cxx