Introduction to ROOT Summer Students Lecture 27 July

  • Slides: 37
Download presentation
Introduction to ROOT Summer Students Lecture 27 July 2004 Philippe Canal (pcanal@fnal. gov) ROOT

Introduction to ROOT Summer Students Lecture 27 July 2004 Philippe Canal (pcanal@fnal. gov) ROOT Tutorials 1

ROOT in a nutshell w An efficient data storage and access system designed to

ROOT in a nutshell w An efficient data storage and access system designed to support structured data sets in very large distributed data bases (Petabytes). w A query system to extract information from these distributed data sets. w The query system is able to use transparently parallel systems on the GRID (PROOF). w A scientific visualisation system with 2 -D and 3 -D graphics. w An advanced Graphical User Interface w A C++ interpreter allowing calls to user defined classes. w An Open Source Project ROOT Tutorials 2

ROOT: An Open Source Project w The project is developed as a collaboration between

ROOT: An Open Source Project w The project is developed as a collaboration between : w Full time developers: n n n 6 people full time at CERN 1 key developer at Fermi. Lab 1 key developer in Japan (Agilent Technologies) 1 key developer at MIT 1 mathematician at CERN sponsored by a US Finance Company w Many contributors spending a substantial fraction of their time in specific areas (> 50). w Key developers in large experiments using ROOT as a framework. w Several thousand users given feedback and a very long list of small contributions. ROOT Tutorials 3

The ROOT Project ROOT 4. 0 functionality ROOT 3. 0 LHC Large Hadron Collider

The ROOT Project ROOT 4. 0 functionality ROOT 3. 0 LHC Large Hadron Collider ROOT 2. 0 RHIC, FNAL/RUN II, Babar, KEK ROOT 1. 0 ROOT 0. 5 1995 LEP, HERA, SPS 2000 2005 ROOT Tutorials 4

The ROOT web pages http: //root. cern. ch q. General Information and News q.

The ROOT web pages http: //root. cern. ch q. General Information and News q. Download source and binaries q. Howto & tutorials q. User Guide & Reference Guides q. Roottalk Digest & Forum ROOT Tutorials 5

ROOT Information @ Fermi w Detailed ROOT Courses: http: //www-cpd. fnal. gov/root w To

ROOT Information @ Fermi w Detailed ROOT Courses: http: //www-cpd. fnal. gov/root w To submit a bug report: n http: //pcroot. cern. ch/root-bugs w Mailing list: n roottalk http: //root. cern. ch/roottalk/About. Root. Talk. html w About ROOT at Fermi: about-root@fnal. gov n Archive: http: //listserv. fnal. gov/archives/about-root. html n 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. ROOT Tutorials 6

Batch/Interactive models Need experiment framework +widely available tools Batch Production Simulation reconstruction Interactive batch

Batch/Interactive models Need experiment framework +widely available tools Batch Production Simulation reconstruction Interactive batch model ROOT Tutorials Need only widely available tools Interactive Chaotic analysis 7

Data Volume & Processing Time Using technology available in 2004 100 MB 1 GB

Data Volume & Processing Time Using technology available in 2004 100 MB 1 GB 100 GB 1 TB 100 TB 1 PB ROOT 1 Processor P IV 2. 4 GHz 2004 : Time for one query using 10 per cent of data 1” 10” 1’ 10’ 1 h 10 h 1 day 1 month batch Interactive PROOF 10 Processors 1” 10 days 1” 10” 1’ 10’ 1 h 10 h 1 day 1” 10” 1’ 10’ 1 h 10 h PROOF 100 Processors 1” 1” 1 day PROOF/GLite 1000 Processors 1’ ROOT Tutorials 10’ 1 h 10 h 8

Data Volume & Processing Time Using technology available in 2010 100 MB 1 GB

Data Volume & Processing Time Using technology available in 2010 100 MB 1 GB 100 GB 1 TB 100 TB 1 PB ROOT 1 Processor XXXXX 2010 : Time for one query using 10 per cent of data 1” 10 days. Interactive 1” 1’ 10’ 1 h 10 h 1 day batch PROOF 10 Processors 1” 1” 1” 10” 1’ 10’ 1 h 10 h 1 day 1” 1” 10” 1’ 10’ 1 h 10 h PROOF 100 Processors 1” 1” PROOF/GLite 1000 Processors 1’ ROOT Tutorials 10’ 1 h 9

ROOT Library Structure w ROOT libraries are a layered structure w The CORE classes

ROOT Library Structure w ROOT libraries are a layered structure w The CORE classes are always required (support for RTTI, basic I/O and interpreter) w 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. w Shared libraries reduce the application link time w Shared libraries reduce the application size w ROOT shared libraries can be used with other class libraries ROOT Tutorials 10

The Libraries w Over 1000 classes w 1250, 000 lines of code w CORE

The Libraries w Over 1000 classes w 1250, 000 lines of code w CORE (12 Mbytes) w CINT (3 Mbytes) w Green libraries linked on demand via plugin manager (only a subset shown) ROOT Tutorials 11

ROOT: a Framework and a Library w User classes n User can define new

ROOT: a Framework and a Library w User classes n User can define new classes interactively n Either using calling API or sub-classing API n These classes can inherit from ROOT classes w Dynamic linking n Interpreted code can call compiled code n Compiled code can call interpreted code n Macros can be dynamically compiled & linked ROOT Tutorials This is the normal operation mode Interesting feature for GUIs & event displays Script Compiler root >. x file. C++ 12

A Data Analysis & Visualisation tool ROOT Tutorials 13

A Data Analysis & Visualisation tool ROOT Tutorials 13

Graphics : 1, 2, 3 -D functions w ROOT Tutorials 14

Graphics : 1, 2, 3 -D functions w ROOT Tutorials 14

Full Late. X support on screen and postscript Formula or diagrams can be edited

Full Late. X support on screen and postscript Formula or diagrams can be edited with the mouse TCurly. Arc TCurly. Line TWavy. Line and other building blocks for Feynmann diagrams ROOT Tutorials 15

Alice 3 million nodes ROOT Tutorials 16

Alice 3 million nodes ROOT Tutorials 16

ROOT I/O : An Example Program Writing demoh. C TFile f(“example. root”, ”new”); TH

ROOT I/O : An Example Program Writing demoh. C TFile f(“example. root”, ”new”); TH 1 F h(“h”, ”My histogram”, 100, -3, 3); h. Fill. Random(“gaus”, 5000); h. Write(); Program Reading TFile f(“example. root”); demohr. C TH 1 F *h = (TH 1 F*)f. Get(“h”): h->Draw(); f. Map(); 20010831/171903 20010831/171941 20010831/171946 At: 64 At: 154 At: 607 At: 2971 At: 3067 At: 3123 N=90 N=453 N=2364 N=96 N=56 N=1 TFile TH 1 F Streamer. Info Keys. List Free. Segments END CX = ROOT Tutorials 2. 09 3. 25 17

A Root file pippa. root with two levels of directories ROOT Tutorials Objects in

A Root file pippa. root with two levels of directories ROOT Tutorials Objects in directory /pippa/DM/CJ eg: /pippa/DM/CJ/h 15 18

Memory <--> Tree Each Node is a branch in the Tree Memory 0 T.

Memory <--> Tree Each Node is a branch in the Tree Memory 0 T. Get. Entry(6) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 T. Fill() T ROOT Tutorials 19

Tree example Event (write) void demoe(int nevents) { //load shared lib with the Event

Tree example Event (write) void demoe(int nevents) { //load shared lib with the Event class g. System->Load("$ROOTSYS/test/lib. Event"); //create a new ROOT file TFile f("demoe. root", ”new"); All the examples can be executed with CINT or the compiler root >. x demoe. C++ //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(); T. Write(); //Print Tree statistics //Write Tree header to the file } ROOT Tutorials 20

Tree example Event (read 1) void demoer() { //load shared lib with the Event

Tree example Event (read 1) void demoer() { //load shared lib with the Event class g. System->Load("$ROOTSYS/test/ lib. Event"); //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->Set. Branch. Address("event", &event); //Loop on events and fill an histogram TH 1 F *h = new TH 1 F("hntrack", "Number of tracks", 100, 580, 620); int nevents = (int)T->Get. Entries(); for (int i=0; i<nevents; i++) { Rebuild the full event T->Get. Entry(i); in memory h->Fill(event->Get. Ntrack()); } h->Draw(); } ROOT Tutorials 21

8 leaves of branch Electrons A double-click to histogram the leaf 8 Branches of

8 leaves of branch Electrons A double-click to histogram the leaf 8 Branches of T ROOT Tutorials 22

The Tree Viewer & Analyzer A very powerful class supporting complex cuts, event lists,

The Tree Viewer & Analyzer A very powerful class supporting complex cuts, event lists, 1 -d, 2 -d, 3 -d views parallelism ROOT Tutorials 23

Tree Friends 01 23 45 67 89 10 11 12 13 14 15 16

Tree Friends 01 23 45 67 89 10 11 12 13 14 15 16 17 18 0 1 2 3 4 5 6 7 8 Entry # 8 01 23 45 67 89 10 11 12 13 14 15 16 17 18 Public User read Write ROOT Tutorials 24

Tree Friends Analysis group protected Collaboration-wide public read user private Processing time independent of

Tree Friends Analysis group protected Collaboration-wide public read user private Processing time independent of the number of friends unlike table joins in RDBMS x Root > TFile f 1(“tree 1. root”); Root > tree. Add. Friend(“tree 2”, “tree 2. root”) Root > tree. Add. Friend(“tree 3”, “tree 3. root”); Root > tree. Draw(“x: a”, ”k<c”); Root > tree. Draw(“x: tree 2. x”, ”sqrt(p)<b”); ROOT Tutorials 25

GRID: Interactive Analysis Case 1 w Data transfer to user’s laptop w Optional Run/File

GRID: Interactive Analysis Case 1 w Data transfer to user’s laptop w Optional Run/File catalog w Optional GRID software ROOT Tutorials 26

GRID: Interactive Analysis Case 2 w Remote data processing w Optional Run/File catalog w

GRID: Interactive Analysis Case 2 w Remote data processing w Optional Run/File catalog w Optional GRID software ROOT Tutorials 27

GRID: Interactive Analysis Case 3 w Remote data processing w Run/File catalog w Full

GRID: Interactive Analysis Case 3 w Remote data processing w Run/File catalog w Full GRID software ROOT Tutorials 28

Trends Summary More and more GRID oriented data analysis More and more experiment-independent software

Trends Summary More and more GRID oriented data analysis More and more experiment-independent software Parallelism on the GRID Batch/Interactive Access to Catalogs Efficient Access to large and structured event collections Histogram Ntuple viewers Data Presenters Interaction with user & experiment classes ROOT Tutorials Resource Brokers Process migration Progress Monitors Proxies/caches Virtual data sets 29

Google: a good model Make it simple Simple interface Available everywhere Hidden Parallelism Distributed

Google: a good model Make it simple Simple interface Available everywhere Hidden Parallelism Distributed DB Don’t know a priori the data location Fast ROOT Tutorials 30

Playing with ROOT on a PC w Import a binary tar file from: n

Playing with ROOT on a PC w Import a binary tar file from: n n http: //root. cern. ch/root/Version 400. html Eg: Intel x 86 Linux for Redhat 7. 3 and gcc 3. 2, version 4. 00/08 w Untar the file in your home directory n n cd $HOME tar zxvf root_v 4. 00. 08. Linux. RH 7. 3. gcc 32. tar. gz w Set the environment variables n n n setenv ROOTSYS $HOME/root setenv LD_LIBRARY_PATH $ROOTSYS/lib: $LD_LIBRARY_PATH setenv PATH $ROOTSYS/bin: $PATH w Go to the ROOT tutorials n n n cd $HOME cp $ROOTSYS/tutorials. cd tutorials w Run ROOT n root ROOT Tutorials 31

My first session root [0] 344+76. 8 (const double)4. 20800000010 e+002 root [1] float

My first session root [0] 344+76. 8 (const double)4. 20800000010 e+002 root [1] float x=89. 7; root [2] float y=567. 8; root [3] x+sqrt(y) (double)1. 13528550991510710 e+002 root [4] float z = x+2*sqrt(y/6); root [5] z (float)1. 09155929565429690 e+002 root [6]. q root See file $HOME/. root_hist root [0] try up and down arrows ROOT Tutorials 32

My second session root [0]. x session 2. C for N=100000, sum= 45908. 6

My second session root [0]. x session 2. C for N=100000, sum= 45908. 6 root [1] sum (double)4. 59085828512453370 e+004 Root [2] r. Rndm() (Double_t)8. 29029321670533560 e-001 root [3]. q session 2. 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= %gn", N, sum); unnamed macro executes in global scope } ROOT Tutorials 33

My third session root [0]. x session 3. C for N=100000, sum= 45908. 6

My third session root [0]. x session 3. 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 session 3. C(1000) for N=1000, sum= 460. 311 root [3]. q session 3. C Named macro Normal C++ scope rules void session 3 (int N=100000) { TRandom r; double sum = 0; for (int i=0; i<N; i++) { sum += sin(r. Rndm()); } printf("for N=%d, sum= %gn", N, sum); } ROOT Tutorials 34

My third session with ACLIC root [0] g. ROOT->Time(); root [1]. x session 4.

My third session with ACLIC root [0] g. ROOT->Time(); root [1]. x session 4. C(10000000) for N=10000000, sum= 4. 59765 e+006 Real time 0: 06, CP time 6. 890 root [2]. x session 4. C+(10000000) for N=10000000, sum= 4. 59765 e+006 Real time 0: 09, CP time 1. 062 root [3] session 4(10000000) for N=10000000, sum= 4. 59765 e+006 Real time 0: 01, CP time 1. 052 root [4]. q File session 4. C Automatically compiled and linked by the native compiler. Must be C++ compliant session 4. C #include “TRandom. h” void session 4 (int N) { TRandom r; double sum = 0; for (int i=0; i<N; i++) { sum += sin(r. Rndm()); } printf("for N=%d, sum= %gn", N, sum); } ROOT Tutorials 35

Macros with more than one function root [0]. x session 5. C >session 5.

Macros with more than one function root [0]. x session 5. C >session 5. log root [1]. q root [0]. L session 5. C root [1] session 5(100); >session 5. log root [2] session 5 b(3) sum(0) = 0 sum(1) = 1 sum(2) = 3 root [3]. q. x session 5. C executes the function session 5 in session 5. C use g. ROOT->Process. Line to execute a macro from a macro or from compiled code session 5. C void session 5(int N=100) { session 5 a(N); session 5 b(N); g. ROOT->Process. Line(“. x session 4. C+(1000)”); } void session 5 a(int N) { for (int i=0; i<N; i++) { printf("sqrt(%d) = %gn", i, sqrt(i)); } } void session 5 b(int N) { double sum = 0; for (int i=0; i<N; i++) { sum += i; printf("sum(%d) = %gn", i, sum); } } ROOT Tutorials 36

Interactive Demo You can import the tar file with all demos from ftp: //root.

Interactive Demo You can import the tar file with all demos from ftp: //root. cern. ch/root/Summer. Students 2004. tar. gz root summershow. C You can find more demos, examples, tests at $ROOTSYS/tutorials $ROOTSYS/test/Root. Shower ROOT Tutorials 37