09-Jun-2005J. Adamczewski1 C++ course 2005 The ROOT framework 2.

Slides:



Advertisements
Similar presentations
File management GAP Toolkit 5 Training in basic drug abuse data management and analysis Training session 2.
Advertisements

H.G.Essel: Go4 - J. Adamczewski, M. Al-Turany, D. Bertini, H.G.Essel, S.Linev CHEP 2004 Go4 v2.8 Analysis Design.
Joe Foster Visualizing Data with ROOT Joe Foster University of Manchester.
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
ROOT Root Commands and CINT Functions and Fitting (The Tree Viewer)
Why ROOT?. ROOT ROOT: is an object_oriented frame work aimed at solving the data analysis challenges of high energy physics Object _oriented: by encapsulation,
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Hands-On Microsoft Windows Server 2003 Administration Chapter 5 Administering File Resources.
Guide To UNIX Using Linux Third Edition
C++ fundamentals.
ROOT courses1 The ROOT System A Data Access & Analysis Framework February 2003 Ren é Brun/EP Trees.
Computer Systems Week 10: File Organisation Alma Whitfield.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Sept 11, 2003ROOT Day1, Suzanne Panacek39 ROOT An object oriented HEP analysis framework. Day 1.
ROOT An object oriented HEP analysis framework.. Computing in Physics Physics = experimental science =>Experiments (e.g. at CERN) Planning phase Physics.
XML I/O in ROOT S. Linev, R. Brun, H.G. Essel CHEP 2004.
Chapter 12: Adding Functionality to Your Classes.
CFT Offline Monitoring Michael Friedman. Contents Procedure  About the executable  Notes on how to run Results  What output there is and how to access.
Introduction to Shell Script Programming
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
V0.05 ROOT 102 ROOT is an object oriented HEP analysis framework.
Introduction to Matlab & Data Analysis
21-Apr-2005J. Adamczewski1 DVEE C++ course 2005 The ROOT framework 1: Introduction.
Chapter 6 SAS ® OLAP Cube Studio. Section 6.1 SAS OLAP Cube Studio Architecture.
Learning to Use Root for STAR Gene Van Buren (UCLA) for the STAR Collaboration Accessing STAR Data Programming for STAR (Makers) Star => Computing => Tutorials.
Oracle Data Integrator Procedures, Advanced Workflows.
10 – 12 APRIL 2005 Riyadh, Saudi Arabia. Building multi-lingual ASP.Net application that handle western languages and Arabic with a single code base.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
10/31/2015PHYS 3446 DØ Data Analysis with ROOT Venkat (for Dr.Yu)
Chapter 10 Chapter 10: Managing the Distributed File System, Disk Quotas, and Software Installation.
GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Go4 v3 - J.Adamczewski, H.G.Essel, S.Linev IT/EE Palaver Go4 version 3.
CHEP 2013, Amsterdam Reading ROOT files in a browser ROOT I/O IN JAVASCRIPT B. Bellenot, CERN, PH-SFT B. Linev, GSI, CS-EE.
H.G.Essel: Go4 - J. Adamczewski, M. Al-Turany, D. Bertini, H.G.Essel, S.Linev CHEP 2003 GSI Online Offline Object Oriented Go4.
| See the possibilities… Standard Report Management/Menu Changes.
ROOT Tutorials - Session 51 ROOT Tutorials – Session 5 Dictionary Generation, rootcint, Simple I/O, Hands-on Fons Rademakers.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
STAR Schema Evolution Implementation in ROOT I/O V. Perevoztchikov Brookhaven National Laboratory,USA.
PROOF and ALICE Analysis Facilities Arsen Hayrapetyan Yerevan Physics Institute, CERN.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
TTree::Draw What is it trying to be? Where is it going?
ROOT I/O in JavaScript Browsing ROOT Files on the Web For more information see: For any questions please use following address:
GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GGO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4GO4G.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Overloading operators C++ incorporates the option to use standard operators to perform operations with.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
9/28/2005Philippe Canal, ROOT Workshop TTree / SQL Philippe Canal (FNAL) 2005 Root Workshop.
CINT & Reflex – The Future CINT’s Future Layout Reflex API Work In Progress: Use Reflex to store dictionary data Smaller memory footprint First step to.
S.Linev: Go4 - J.Adamczewski, H.G.Essel, S.Linev ROOT 2005 New development in Go4.
Trees: New Developments1 Trees: New Developments Folders and Tasks ROOT Workshop 2001 June 13 FNAL Ren é Brun CERN
Perfecto Mobile Automation
1 G4UIRoot Isidro González ALICE ROOT /10/2002.
Go4 Workshop J.Adamczewski-Musch, S.Linev Go4 advanced features.
Joe Foster 1 This talk extends the one I gave in 2006 called Visualizing Data with ROOT. –
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Xxx Presentation, No 1 Copyright © TAC AB Engineering Classic Networks1.
HYDRA Framework. Setup of software environment Setup of software environment Using the documentation Using the documentation How to compile a program.
V0.02 The ROOT Collection Classes. V Collection Classes Group of related objects TObjects or descendants from TObject Abstract base class TCollection.
ROOT1 Hands-on Sami Kama. S.Kama ROOT1 Hands-On ISTAPP2011 Dogus Univ.07/02/ Download root file from indico.
Go4 v2.2 Status & Overview CHEP 2003
Distributed object monitoring for ROOT analyses with Go4 v.3
Creating and Modifying Text part 2
Java Programming Language
Coding Concepts (Basics)
Tonga Institute of Higher Education
Chapter 11: Inheritance and Composition
The Go4 eventloop framework: analysis steps
The ROOT framework 1: Introduction
ROOT Support and Developments at FNAL
J. Adamczewski, M. Al-Turany, D. Bertini, H.G. Essel
Presentation transcript:

09-Jun-2005J. Adamczewski1 C++ course 2005 The ROOT framework 2

09-Jun-2005J. Adamczewski2 Schedule of part 2 ROOT framework as class hierarchy Collection classes TFile and TDirectory TTree class (set up; read and analyse data ) (Adding own classes to ROOT)

09-Jun-2005J. Adamczewski3 The ROOT system C++ based framework for (high energy-) physics (developed at CERN by R.Brun et al. since 1997) C++ as script language with interpreter CINT GUI for interactive visualization (TCanvas, TBrowser,...) I/O and analysis of large amount of data (TFile, TTree,...) Histograming, plotting, fits (TH1x, TGraph, TF1,...) Physics and mathematics (TMatrix, TLorentzVector, TMath,..) Object organisation (TCollection, TDirectory, TFolder,...) Parallel analysis via network (TProof)... see for further info!

09-Jun-2005J. Adamczewski4 TObject: ROOT top base class defines interface of fundamental virtual methods: Draw(), Print(), Dump(), GetName(), Clear(), Compare(), Streamer(), Clone(), Write(),... base type for root collections TObject* ob= new TH1F(“hpx“,“title“,2048,0,2047); TList* list=new TList; list->Add(ob); TObject* ob2=list->FindObject(“hpx“); IO (via TObject::Streamer()): ob->Write(); ob->Clone(); runtime class introspection: TClass* cl=ob->Class(); // full info on methods and datamembers in memory if(ob->InheritsFrom(“TH1“))... // check type

09-Jun-2005J. Adamczewski5 TH1: example of class hierarchy “inherits from”, “implements” base classes subclasses

09-Jun-2005J. Adamczewski6 Class hierarchy: some facts Subclass objects are of parent class type: a TH1D histogram „is a“ TObject Subclasses have all members /methods of parent classes TH1D* his=new TH1D(“hpx“,“example“,100,0,10); cout GetName()<<endl; TH1D uses name property of TNamed Subclasses may redefine virtual methods: TObject::Print() overridden by TH1::Print() TObject* ob=new TH2I(“map“, “example“, 50, 0, 1000, 50, 0, 1000); ob->Print(); // C++ automatically calls TH2I::Print();

09-Jun-2005J. Adamczewski7 Root collections Example of polymorphic containers A ROOT collection keeps any TObject objects (different classes may be in same collection!) Different types of collections as hierarchy, base classes: TCollection, TIterator Ordered: TList, TObjArray, THashList,... Sorted: TBtree, TSortedList Unordered: TMap, THashTable Methods to search contents by name; iterate, sort,...

09-Jun-2005J. Adamczewski8 Root collections

09-Jun-2005J. Adamczewski9 Example: filling a collection TCollection* mylist=new TList; TObject* h1= new TH1F(“hpx“,“title“,2048,0,2047); mylist->Add(h1); TObject* g1= new TGraph(50,&a,&b); mylist->Add(g1); TObject* n1= new TNamed(“Remark1“,“a short description“); mylist->Add(n1);.... Other TCollection methods: Remove(), Clear(), Delete(), Draw(), Print(), Write()...

09-Jun-2005J. Adamczewski10 Getting objects from collection TIter liter(mylist); // TIter wraps correct TIterator TObject* out=0; while((out=liter.Next()) !=0) { out->Print(); // implemented for each TObject TH1* histo=dynamic_cast (out); if(histo) histo->Fill(5); // only for TH1 } Find by name: Scan all with Iterator: TObject* ob=mylist->FindObject(“hpx“); if(ob->InheritsFrom(„TH1“)){ TH1* histo=dynamic_cast (ob); if(histo) histo->Fill(5); // works only for TH1 }

09-Jun-2005J. Adamczewski11 TFile and TDirectory TDirectory: logical organisation of TObjects (ownership, subdirectory structure,...) TFile is a TDirectory related to a storage medium (disk, tape, remote server,...) Last created TFile is current file: TH1 and TTrees created afterwards are owned by file and deleted on file close! (default, can be changed by user) TObject::Write() saves to current file A Root object belongs to one TDirectory only, but may be in several collections and TFolder

09-Jun-2005J. Adamczewski12 TTree features Designed to store large number of events (buffering, compression, IO with TFile) Data organized hierarchically into “branches“ Branches may be read back partially (performance!) TTree::Draw(“...“) – implicit analysis loop by string expression TTree::MakeClass() – automatic code generation for explicit analysis loop TChain : public TTree– process sequentially trees of same structure in several files TTree::AddFriend – access parallel events of a friend tree with different branch structure (for TTree::Draw() expression)

09-Jun-2005J. Adamczewski13 Creating a TTree TFile* hfile = new TFile("AFile.root","RECREATE","Example"); TTree* mytree = new TTree(”Mytree”,”cppworkshop”); TXXXEvent *event = new TXXXEvent(); // structure to save myTree->Branch("EventBranch",“TXXXEvent",&event, 32000,99); eventclass name address of pointer to eventobject buffersize splitlevel =0 =99 branch name

09-Jun-2005J. Adamczewski14 Filling the TTree for(Int_t i=0; i<500000; ++i){ Float_t random = gRandom->::Rndm(1); event->fValue=random*3; // put values into event structure event->fSum+=random;... mytree->Fill(); // will write event into tree basket buffer } mytree->Write(); // will write tree buffers and header to file delete myfile; // destructor of TFile will close it TTree::Fill will write data from all active branches (deactivate branch with TTree::SetBranchStatus) Different TTree::Branch() methods for data from simple variables, collections, folders, class objects (see ROOT doc)

09-Jun-2005J. Adamczewski15 Reading a TTree explicitely TFile hfile("AFile.root"); TTree* tr= dynamic_cast (hfile.Get(“Mytree“)); if(tr==0){ cerr << “error: did not find tree!”; return 1; // or may throw exception here... } TObject* h1= new TH1F(“hpx“,“title“,2048,0,2047); TXXXEvent* eve= new TXXXEvent; tr->SetBranchAddress(“EventBranch”,&eve); // by branchname! Int_t all=tr->GetEntries(); // number of events for(Int_t i=0; i<all; ++i){ tr->GetEntry(i); // read event #i into memory h1->Fill(eve->fValue); // do analysis on members of event class here! //... }

09-Jun-2005J. Adamczewski16 Reading Tree explicitely (cont.) Event object at SetBranchAddress must match the structure used on writing the tree TTree::GetEntry will read data from active branches only (deactivate branch with SetBranchStatus(“branchname“,0)) Use TChain instead of TTree to sum trees of same structure in different files (see ROOT doc). TTree::MakeClass() generates sourcecode for event reading from given TTree (eventclass need not be known!) See example below... Explicit reading of events is not necessary for simple analysis, use TTree::Draw() feature (GUI: treeviewer)!

09-Jun-2005J. Adamczewski17 TTree::Draw() examples TTree* tr=.. // got from file tr->Draw(“fValue“,“fValue>100 && fValue<500“); // fill default histogram htemp with fValue if // condition is true; draw htemp tr->Draw(“fX:fY >> hpxpy”,””,”lego”); // fill existing 2d histogram of name “hpxpy” // and display as “lego” plot tr->Draw(“fMatrix[][]/fValue >>+hmatrix”,””); // continue filling histogram hmatrix // with sum of all elements of matrix by fValue tr->Draw(“>>myeventlist”,”sqrt(fValue)>fMatrix[0][2]”); // mark all events in tree that fulfill // the condition into TEventList “myeventlist”

09-Jun-2005J. Adamczewski18 TTree::Draw() (cont.) TTree::Draw(expression,selection,option) May fill histogram/graph from expression, or will mark matching events in a TEventList Expression may contain any combination of known branch names Expression may specify output histogram name and dimensions, or output eventlist Selection gives condition between branch values of one event; this must be true to execute expression Option may contain draw option for result histogram SEE ROOT DOC for complete list of features!

09-Jun-2005J. Adamczewski19 The treeviewer TTree::Draw by click / drag and drop of tree leaves From TBrowser: rmb menu on tree icon in file -> „StartViewer“

09-Jun-2005J. Adamczewski20 TTree::MakeClass() Generates code sceleton for analysis of any TTree (files MyAnalysis.h, MyAnalysis.C) Tree is analyzed by generated class MyAnalysis: members contain each branch/leaf found in tree constructor initializes tree/chain from file(s) Init(TTree*) sets branch addresses to members Show(int num) dumps entry #num Loop() – here user can put own analysis code TFile hfile("AFile.root"); TTree* tr= dynamic_cast (hfile.Get(“Mytree“)); if(tr!=0) tr->MakeClass(“MyAnalysis”);

09-Jun-2005J. Adamczewski21 TTree::MakeClass() Class MyAnalysis may be used from CINT or can be compiled Quick code generation even for unknown data structures! Substructure of original event class may be lost, all tree branches are mapped flat to MyAnalysis data members See Root users guide for further description... root>.L MyAnalysis.C root> MyAnalysis an; // should initialize tree root> an.Loop(); // run implicit analysis loop

09-Jun-2005J. Adamczewski22 Adding own classes to ROOT Motivation: User subclasses of TObject may benefit from ROOT IO, collections, runtime introspection,... (event structure, analysis parameters,...) Interpreter: just load class definition (see MakeClass example), but no IO for new class possible! Compiled into user library: Add ClassImp / ClassDef statements in class sources prepare LinkDef.h file provide dictionary generation in Makefile

09-Jun-2005J. Adamczewski23 Adding own classes to ROOT class MyEvent : public TObject{ public: MyEvent(); fValue; fMatrix[100][100]; // lots of data members here... ClassDef(MyEvent,1) }; ClassImp(MyEvent) MyEvent::MyEvent(){} // may contain othermethod definitions... MyEvent.h MyEvent.cxx Macros, create code for Streamer, type information, etc.

09-Jun-2005J. Adamczewski24 Adding own classes to ROOT LinkDef.h #ifdef __CINT__ #pragma link off all globals; #pragma link off all classes; #pragma link off all functions; #pragma link C++ class MyEvent; #endif Class name may have Options: #pragma link C++ class MyEvent-; do not generate automatic streamer ( for objects with customized streamers) #pragma link C++ class MyEvent!; do not generate the operator >> (for classes not inheriting from TObject) #pragma link C++ class MyEvent+; enable new ROOT IO (from Root >v.3)

09-Jun-2005J. Adamczewski25 Adding own classes to ROOT in Makefile (for generation and linking of ROOT dictionary): libMyEvent.so: MyEvent.o MyEventDict.o g++ -shared –Wl –soname libMyEvent.so –O MyEvent.o MyEventDict.o –o libMyEvent.so #.... MyEventDict.cxx MyEvent.h LinkDef.h $(ROOTSYS)/bin/rootcint -f MyEventDict.cxx -c MyEvent.h LinkDef.h

09-Jun-2005J. Adamczewski26 Summary and outlook ROOT offers collections, folders, directories and files for organization of TObjects TTree is powerful class for keeping and analyzing eventdata (Draw(), MakeClass(), MakeSelector(),..) User can „ROOTify“ own classes with a simple recipe (ClassImp, ClassDef, LinkDef.h, Makefile)

09-Jun-2005J. Adamczewski27 Exercises 1. Create different TH1 and put them into a TObjArray. Use TIterator to fill/modify all of them, or do something under certain conditions. Try collection methods: FindObject(), Draw(), Print(), Write(), Clear(), Delete() Open existing TTree from file in CINT. Play with treeviewer. Write macro that uses TTree::Draw to fill histogram with defined binning 3.Open TTree from file in CINT and use MakeClass() to produce analysis skeleton. Edit the Loop() method to do something with leaves and run this in CINT/ACliC. Try to compile this to library. 4.Define an own event structure class (TObject subclass) and compile it into library. Use this class to fill a TTree with random numbers (or real data) and save it to TFile. Get back events from tree with explicit eventloop. Enjoy!