Must-Know ROOT Class I/O/TGraph/Tntuple/Ttree/…. 1.

Slides:



Advertisements
Similar presentations
Indexing Large Data COMP # 22
Advertisements

Joe Foster Visualizing Data with ROOT Joe Foster University of Manchester.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 8 – File Structures.
Hashing and Indexing John Ortiz.
File Systems.
2P13 Week 11. A+ Guide to Managing and Maintaining your PC, 6e2 RAID Controllers Redundant Array of Independent (or Inexpensive) Disks Level 0 -- Striped.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
File Management Chapter 12. File Management A file is a named entity used to save results from a program or provide data to a program. Access control.
Query Evaluation. An SQL query and its RA equiv. Employees (sin INT, ename VARCHAR(20), rating INT, age REAL) Maintenances (sin INT, planeId INT, day.
Chapter 12 File Management
Spreadsheets With Microsoft Excel ® as an example.
1 Data & Database Development. 2 Data File Bit Byte Field Record File Database Entity Attribute Key field Key file management concepts include:
1 External Sorting for Query Processing Yanlei Diao UMass Amherst Feb 27, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
ROOT courses1 The ROOT System A Data Access & Analysis Framework February 2003 Ren é Brun/EP Trees.
Chapter 6: The Traditional Approach to Requirements
School of Engineering and Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, VUW Indexing Large Data COMP
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
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.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall 9.1.
Databases and LINQ Visual Basic 2010 How to Program 1.
CS370 Spring 2007 CS 370 Database Systems Lecture 2 Overview of Database Systems.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
CHAPTER 8: MANAGING DATA RESOURCES. File Organization Terms Field: group of characters that represent something Record: group of related fields File:
ATLAS Peter van Gemmeren (ANL) for many. xAOD  Replaces AOD and DPD –Single, EDM – no T/P conversion when writing, but versioning Transient EDM is typedef.
CSC 213 – Large Scale Programming. What is “the BTree?”  Common multi-way tree implementation  Every BTree has an order (“BTree of order m ”) ‏  m.
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas associated with that data The “meaning” of data is implicit.
CSC 213 Lecture 10: BTrees. Announcements You should not need to do more than the lab exercise states  If only says add a CharRange, you should not need.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
UNIX Files File organization and a few primitives.
ROOT for Data Analysis1 Intel discussion meeting CERN 5 Oct 2003 Ren é Brun CERN Distributed Data Analysis.
Copyright 2006 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Third Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Chapter.
ROOT I/O for SQL databases Sergey Linev, GSI, Germany.
Introduction to ROOT Practical Part Jan Fiete Grosse-Oetringhaus, CERN PH/ALICE Summer Student Lectures th July.
Scheduling Policies and File Systems Operating Systems CS 550.
Microsoft Access.  What is Data ?  Data vs. Information  Database History.  What is a Database?  Examples for Small and Large Databases.  Types.
CE Operating Systems Lecture 17 File systems – interface and implementation.
ROOT Tutorials - Session 51 ROOT Tutorials – Session 5 Dictionary Generation, rootcint, Simple I/O, Hands-on Fons Rademakers.
Lecture 18 Windows – NT File System (NTFS)
I MPLEMENTING FILES. Contiguous Allocation:  The simplest allocation scheme is to store each file as a contiguous run of disk blocks (a 50-KB file would.
Lecture 10 Page 1 CS 111 Summer 2013 File Systems Control Structures A file is a named collection of information Primary roles of file system: – To store.
General Purpose ROOT Utilities Victor Perevoztchikov, BNL.
Chapter 10 Designing Databases. Objectives:  Define key database design terms.  Explain the role of database design in the IS development process. 
Session 1 Module 1: Introduction to Data Integrity
CIS 250 Advanced Computer Applications Database Management Systems.
Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.
Object storage and object interoperability
9/28/2005Philippe Canal, ROOT Workshop TTree / SQL Philippe Canal (FNAL) 2005 Root Workshop.
Postgraduate Computing Lectures PAW 1 PAW: Physicist Analysis Workstation What is PAW? –A tool to display and manipulate data. Learning PAW –See ref. in.
1 Geog 357: Data models and DBMS. Geographic Decision Making.
Introduction to Databases Angela Clark University of South Alabama.
Data Structure and Algorithms
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. –
Gaudi Framework Tutorial, April Histograms And N-tuples.
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.
ROOT: Functions & Histograms
Indexing Goals: Store large files Support multiple search keys
Introduction to ROOT Practical Part
Database Management Systems (CS 564)
Database Management Systems (CS 564)
REDCap Data Migration from CSV file
CS222/CS122C: Principles of Data Management Lecture #2 Storing Data: Disks and Files Instructor: Chen Li.
Introduction to ROOT (2/2) Practical Part
New I/O navigation scheme
Presentation transcript:

Must-Know ROOT Class I/O/TGraph/Tntuple/Ttree/…. 1

I/O : Saving Objects in ROOT Use the TFile class –we need first to create the class, which opens the file TFile* f = TFile::Open("file.root","NEW"); Write an object deriving from TObject: object->Write("optionalName") For any other object (but with dictionary) f->WriteObject(object, "name"); 2

TFile Class ROOT stores objects in TFiles: – TFile* f = TFile::Open("file.root", "NEW"); TFile behaves like file system: – f->mkdir("dir"); TFile has a current directory: – f->cd("dir"); You can browse the content: – f->ls(); TFile**! ! file.root! TFile*! ! file.root! TDirectoryFile*! dir! dir KEY: TDirectoryFile! dir;1!dir Tbrowser b; 3

TGraphErrors TGraphErrors() TGraphErrors(Int_t n)Int_t n) TGraphErrors(const TGraphErrors& gr)TGraphErrors& gr) TGraphErrors(const TH1* h)TH1* h) TGraphErrors(const char* filename, const char* format = "%lg %lg %lg %lg", Option_t* option = "")Option_t* option = "") TGraphErrors(Int_t n, const Double_t* x, const Double_t* y, const Double_t* ex = 0, const Double_t* ey = 0)Int_t n, const Double_t* x, const Double_t* y, const Double_t* ex = 0, const Double_t* ey = 0) 4

{ c1 = new TCanvas("c1","A Simple Graph with error bars",200,10,700,500);TCanvas("c1","A Simple Graph with error bars",200,10,700,500); c1->SetFillColor(42);SetFillColor(42); c1->SetGrid(); c1->GetFrame()->SetFillColor(21);SetFillColor(21); c1->GetFrame()->SetBorderSize(12); const Int_t n = 10;Int_t n = 10; Double_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95}; Double_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1}; Double_t ex[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05}; Double_t ey[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8}; gr = new TGraphErrors(n,x,y,ex,ey);TGraphErrors(n,x,y,ex,ey); gr->SetTitle("TGraphErrors Example");SetTitle("TGraphErrors Example"); gr->SetMarkerColor(4);SetMarkerColor(4); gr->SetMarkerStyle(21);SetMarkerStyle(21); gr->Draw("ALP");Draw("ALP"); return c1; } 5

Ntuple/TTree Ntuple class – Tntuple For storing tabular data Eg. Excel talbe with numbers Tree class – Ttree For storing complex data types E.g Database tables 6

Building ROOT Ntuple Creating and Storing N-tuples –The ROOT class TNtuple can store only floating entries – each raw (record) must be composed only of floating types Specify the name (label) of the type when creating the object TNtuple data(“ntuple”,”Example N-tuple”,”x:y:z:t”); // fill it with random data for (int i = 0; i<10000; ++i) { float x = gRandom->Uniform(-10,10); float y = gRandom->Uniform(-10,10); float z = gRandom->Gaus(0,5); float t = gRandom->Exp(10); data.Fill(x,y,z,t); } // write in a file TFile f(“ntuple_data.root”,”RECREATE”); data.Write(); f.Close(); 7

Looking at the Ntuple 8

Getting The Entries Entries of a ROOT N-tuple can be retrieved using TNtuple::GetEntry(irow) TFile f("ntuple_data.root"); TNtuple *ntuple=0; f.GetObject("ntuple",ntuple); // loop on the ntuple entries for (int i = 0; i GetEntries(); ++i) { ntuple->GetEntry(i); float * raw_content = ntuple->GetArgs(); float x = raw_content[0]; float y = raw_content[1]; float z = raw_content[2]; float t = raw_content[3]; // do something with the data.. } 9

TTree ROOT N-tuple can store only floating point variables For storing complex types, i.e. objects we can use the ROOT tree class, TTree – TNtuple is a special case of a TTree (a derived class) The ROOT Tree is – extremely efficient write once, read many. – Designed to store >109 (HEP events) with same data structure. – Trees allow fast direct and random access to any entry (sequential access is the best). – Optimized for network access (read-ahead). 10

Why Ttrees ? object.Write() is convenient for simple objects like histograms, but inappropriate for saving collections of events containing complex objects Reading a collection: – read all elements (all events) With trees: – only one element in memory, – or even only a part of it (less I/O) Trees buffered to disk (TFile); – I/O is integral part of TTree concept 11

Tree Access Databases have row wise access – Can only access the full object (e.g. full event) ROOT trees have column wise access – Direct access to any event, any branch or any leaf even in the case of variable length structures – Designed to access only a subset of the object attributes (e.g. only particles’ energy) – Makes same members consecutive, e.g. for object with position in X, Y, Z, and energy E, all X are consecutive, then come Y, then Z, then E. A lot higher zip efficiency! 12

Building a ROOT Tree Steps to build a Tree – Create a TFile class – Tree can be huge  need file for swapping filled entries TFile*hfile=TFile::Open("AFile.root","RECREATE"); – Create a TTree class Add a Branch (TBranch) to the TTree Fill the tree with the data Write the tree to file 13

Examples

Next Lecture on.. A Simple MC code ( can be covered in Exercise session ) Pythia Event Generator – – PYTHIA is a program for the generation of high-energy physics events, i.e. for the description of collisions at high energies between elementary particles such as e+, e-, p and pbar in various combinations. It contains theory and models for a number of physics aspects, including hard and soft interactions, parton distributions, initial- and final-state parton showers, multiple interactions, fragmentation and decay. It is largely based on original research, but also borrows many formulae and other knowledge from the literature. 15