2007-10-18Joe Foster 1 This talk extends the one I gave in 2006 called Visualizing Data with ROOT. –http://www.hep.man.ac.uk/seminars/slides/Joe061026.ppthttp://www.hep.man.ac.uk/seminars/slides/Joe061026.ppt.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Joe Foster Visualizing Data with ROOT Joe Foster University of Manchester.
Must-Know ROOT Class I/O/TGraph/Tntuple/Ttree/…. 1.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
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,
R.Dubois D.Flath 4 Feb 20002nd Root Users Workshop Towards a Nicer User Interface The competition : JAS!
E906 Data Analysis Frame (II) Jia-Ye Chen
1 CS 177 Week 15 Recitation Slides Review. Announcements Final Exam on Sat. May 8th  PHY 112 from 8-10 AM Complete your online review of your classes.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
Guide To UNIX Using Linux Third Edition
Review of C++ Programming Part II Sheng-Fang Huang.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Sept 11, 2003ROOT Day1, Suzanne Panacek39 ROOT An object oriented HEP analysis framework. Day 1.
1 Arrays Chapter 13 Especially read 13.1 – 13.2 Text introduces vectors, which we will not cover, in 13.3.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
V0.05 ROOT 102 ROOT is an object oriented HEP analysis framework.
09-Jun-2005J. Adamczewski1 C++ course 2005 The ROOT framework 2.
Intro to C++ And Some Tools Opening Discussion zHave any questions come up since last class? Have you had a chance to look over the project.
21-Apr-2005J. Adamczewski1 DVEE C++ course 2005 The ROOT framework 1: Introduction.
By – Tanvir Alam.  This tutorial offers several things.  You’ll see some neat features of the language.  You’ll learn the right things to google. 
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
DATA STRUCTURES LAB 1 TA: Nouf Al-harbi
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Pointers OVERVIEW.
CS107 References and Arrays By Chris Pable Spring 2009.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 3 More About Classes Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
1 Control Software (CAT) Introduction USB Interface implementation Calorimeter Electronics Upgrade Meeting Frédéric Machefert Wednesday 5 th May, 2010.
10/31/2015PHYS 3446 DØ Data Analysis with ROOT Venkat (for Dr.Yu)
 Managing the heap  Resource acquisition is initialization (RAII)  Overriding operator new and delete  Class-based memory pools.
Looping and Counting Lecture 3 Hartmut Kaiser
Introduction to ROOT Practical Part Jan Fiete Grosse-Oetringhaus, CERN PH/ALICE Summer Student Lectures th July.
11 Introduction to Object Oriented Programming (Continued) Cats.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline Introduction Arrays Declaring Arrays Examples Using Arrays.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Argonne Jamboree January 2010 Esteban Fullana AOD example analysis.
Homework due Test the random number generator Create a 1D array of n ints Fill the array with random numbers between 0 and 100 Compute and report the average.
Containers Jason Goffeney 2/23/2006. Containers The STL is a standard part of probably all C++ implementations It features implementations of most of.
TTree::Draw What is it trying to be? Where is it going?
1 Linked Lists II Doubly Linked Lists Chapter 3. 2 Objectives You will be able to: Describe, implement, and use a Doubly Linked List of integers.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
LECTURE LECTURE 11 Constructors and destructors Copy constructor Textbook: p , 183.
CSC Java Programming, Fall, 2008 Week 3: Objects, Classes, Strings, Text I/O, September 11.
11 Introduction to Object Oriented Programming (Continued) Cats.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
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.
Object Oriented Programming in C++ Chapter 7 Dynamic Binding.
Trees: New Developments1 Trees: New Developments Folders and Tasks ROOT Workshop 2001 June 13 FNAL Ren é Brun CERN
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
STAR Collaboration DubnaSergey Panitkin 1 What do you need to write a PRL STAR Data (exists) Good Physics Idea (hopefully exists) Analysis Maker.
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
Go4 Workshop J.Adamczewski-Musch, S.Linev Go4 advanced features.
Axel Naumann, DØ University of Nijmegen, The Netherlands 6/20/2001 Dutch Morning Meeting 1 From n-Tuples to b-Tags ?
News on Rho PANDA Collaboration Meeting, Bochum K. Götzen, GSI 1.
HYDRA Framework. Setup of software environment Setup of software environment Using the documentation Using the documentation How to compile a program.
ROOT1 Hands-on Sami Kama. S.Kama ROOT1 Hands-On ISTAPP2011 Dogus Univ.07/02/ Download root file from indico.
AOD example analysis Argonne Jamboree January 2010
Introduction to ROOT Practical Part
Arrays Arrays A few types Structures of related data items
Introduction to ROOT (2/2) Practical Part
Pointers and References
4.1 Introduction Arrays A few types Structures of related data items
Data Structures & Programming
Presentation transcript:

Joe Foster 1 This talk extends the one I gave in 2006 called Visualizing Data with ROOT. – Here I give simple solutions to two common problems: –How do you handle more complex loops when analyzing data in a TTree? –Once you have saved a collection of histograms in a.root file, how can you retrieve them all for further formatting + manipulation without knowing all their names? Other useful stuff –How to speed up the analysis with the ACLiC compiler. Data Analysis with ROOT

Joe Foster 2 Beyond TTree::Draw() With TTree::Draw() you can plot data stored in arrays or vectors. –Loops over all elements or just one element for each entry. –Even works for multidimensional arrays. –Can make selection cuts to individual elements. –Example: MyNtup->Draw(“PtGen”,”abs(Type)==11”) where PtGen is a vector, and Type is a vector. But suppose I want to match reconstructed electrons to truth particles? Too hard for TTree::Draw(). –Write my own loops in C++. –But how do I access the TTree data (branches)?

Joe Foster 3 TTree::MakeClass() TTree::MakeClass() writes out a C++ class which you can use as an analysis skeleton. Entering this: TFile* MyFile = new TFile(“mydir/myfile.root”) TTree* NyNt = (TTree*) MyFile->(“MyTree”) MyNt->MakeClass() –Produces MyTree.C and MyTree.h in the current directory. –Defines class MyTree, maps its branches to C++ variables. –Class member functions: MyNtup() // constructor ~MyNtup() // destructor Init() // Initialize pointers. GetEntry() // You can ignore or override the rest: LoadTree() Notify() Show() Cut() Loop()

Joe Foster 4 Example Analysis: Atlas CBNTAA The data: –Large TTree: CollectionTree, with MC truth + reconstructed events: evgen→digi→recon. My classes: –cbntAnalysis: ‘Master’ class to run analysis + write.root file –RecoElPlots: Book + fill reconstructed electron plots –TruthElPlots: Book + fill truth electron plots –RecoJetPlots: Book + fill reconstructed Jet plots... etc. –cbntHistos: Read, format, print histograms from.root file Standalone programs –RunCBNT.C: Instantiate CollectionTree, cbntAnalysis Run cbntAnalysis::Loop() to fill histograms and save results to.root file. –RunCBNT_Histos.C: Check inputs + run cbntHistos().

Joe Foster 5 Code from CollectionTree.h: class CollectionTree { public : TTree *fChain; //!pointer to the TTree or TChain Int_t fCurrent; //!current Tree number in a TChain // Declaration of leave types... Double_t Weight; // Simple integer branch Int_t IEvent; UInt_t NPar; vector *Type; // Pointer to vector of longs vector *PtGen; vector *PhiGen; vector *EtaGen; vector *MGen;... + ~2800 more branches

Joe Foster 6 Code from CollectionTree.C void CollectionTree::Loop() { if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; } Copy this into your own code and modify it.

Joe Foster 7 My cbntAnalysis Class (1) Private variable declarations from cbntAnalysis.h #include "CollectionTree.h" #include "RecoJetPlots.h" #include "TruthLQPlots.h" #include "RecoElPlots.h"... class cbntAnalysis { private:... CollectionTree*cbntTree; // Generated by MakeClass() stringm_FileName; TObjArray*HList; // ROOT collection class. // Holds a list of histos. RecoJetPlots* PJetPlots; // Pointers to TruthLQPlots* TruLQPlots; // my classes to RecoElPlots* RecElPlots; // book + fill histos...

Joe Foster 8 My cbntAnalysis Class (2) Member functions from cbntAnalysis.h... public : void Initialize() ; // Initialize counters, etc. void BookHistogram() ; // Calls RecoElPlots(),... void Loop(Long64_t evtNum); void ExecuteEvent(Int_t entry); // Calls RecoElPlots::Fill()... void Finalize() ; // Call RecoElPlots::Finalize()... cbntAnalysis(TTree* cbTree, string name); virtual ~cbntAnalysis();

Joe Foster 9 Booking the Histograms From cbntAnalysis::BookHistogram()... TH1::SetDefaultSumw2(kTRUE); HList=new TObjArray(0);... RecElPlots = new RecoElPlots(HList); From RecoElPlots::RecoElPlots(TObjArray* HList)... h_Et = new TH1F("ElRecoEt", "Reco Electron Et", 50, 0.0, 300); h_Et->SetXTitle("Et(GeV/c)"); h-Et->SetStats(1); HList->Add(h_Et);... Each histogram is added to the TObjArray when it is booked.

Joe Foster 10 Filling the Histograms (1) Calls from cbntAnalysis::ExecuteEvent(Int_t entry) –Called from Loop() for each event: RecElPlots->Fill( cbntTree->Ele_nc, // Reconstructed cbntTree->Weight, // quantities: cbntTree->Ele_e, cbntTree->Ele_phi, cbntTree->Ele_eta,... cbntTree->NPar, // MC truth: cbntTree->Type, cbntTree->KMothNt, cbntTree->PtGen, cbntTree->PhiGen, cbntTree->EtaGen ); This isolates RecoElPlots from changes to CollectionTree branch names if data type doesn’t change.

Joe Foster 11 Filling the Histograms (2) void RecoElPlots:: Fill( const Int_t N, const Double_t EventWt, vector * const E, vector * const phi, vector * const eta,... ) {... for (int ipart = 0; ipart < N; ipart++){ Et = (*(E))[ipart] / cosh( (*(eta))[ipart] ); if ( Et > EtCut &&... ) { h_Et->Fill( Et/1000.0, EventWt);... etc for (int iTruPart = 0; iTruPart < NPar; iTruPart++) { // --> Do truth matching... } } // End cuts } // End outer for loop }

Joe Foster 12 Write Histograms to File At the end of cbntAnalysis::Loop(Long64_t evtNum): cout << "writing outputs: " << m_FileName << endl; TFile outf(m_FileName.c_str(), "recreate"); // Expects char* outf.WriteObject(HList,"HList"); outf.Close(); Now the.root file contains a TObjArray which contains the histograms.

Joe Foster 13 Contents of.root File

Joe Foster 14 Running the Analysis From RunCBNT.C: void RunCBNT(string DataSetPath) { string ChainPath, OutFile;... TChain * cbntCh = new TChain("CollectionTree"); ChainPath = DataSetPath + "/NTUP.*.root*"; cbntCh->Add(ChainPath.c_str()); int cbntNum=cbntCh->GetEntries();... cbntAnalysis *cbntAna = new cbntAnalysis(cbntCh, OutFile.c_str()); TStopwatch BigBen; // Loop timer cbntAna->Loop(cbntNum); BigBen.Stop(); BigBen.Print(); delete cbntCh; // Don’t forget! delete cbntAna; }

Joe Foster 15 Reading in the Histograms From RunCBNT_Histos.C: void RunCBNT_Histos(string TestInFile) { TFile* TestHistoFile = new TFile( TestInFile.c_str() );... cbntHistos histos(TestHistoFile,tstpath); } From cbntHistos.h: class cbntHistos { private: TObjArray *TestHistoList;... } From cbntHistos.cxx: cbntHistos::cbntHistos(TFile* TestInFile, char* TestDataDir ) { TestHistoList = (TObjArray*) TestInFile->Get("HList");... PrintPlots(TestDataDir, "gif"); }

Joe Foster 16 Formatting and Drawing the Histograms From cbntHistos.cxx: void cbntHistos::PrintPlots(char* TestDataDir, char* FileFormat) { TCanvas cPlotsCanvas; cPlotsCanvas.cd(); TH1F *TestHist = (TH1F*) TestHistoList->First(); for (int iObj = 0; iObj GetEntries(); iObj++) { TestHist = (TH1F*) TestHistoList->At(iObj); TestHist->SetLineColor(4); TestHist->SetLineWidth(3); TestHist->Draw("E"); cPlotsCanvas.SetLogy(1); // Should depend on histo name?... cPlotsCanvas.Print(FileName,FileFormat); }

Joe Foster 17 Example.gif files

Joe Foster 18 Speeding Up The Analysis “It is easier to make a working program go fast than it is to make a fast program work.” You can use a TStopwatch object to time parts of your program. The ACLiC compiler is an easy way to compile C++ macros from within a ROOT session. –Typically about x5 faster execution. –No need for Makefile. –A good way to find bugs missed by CINT interpreter.

Joe Foster 19 The ACLiC Compiler Example: compile and link RecoElPlots.cxx.L RecoElPlots.cxx++ This produces RecoElPlots_cxx.so Example: macro to compile cbntAnalysis.C gSystem->AddIncludePath(" -I$TOPMC"); gSystem->AddIncludePath(" -I$TOPMC/cbntNewAnal"); gSystem->AddIncludePath(" -I$TOPMC/cbntAnalysis"); gROOT -> ProcessLine(".L./cpplib/CollectionTree.C++"); gROOT -> ProcessLine(".L RecoElPlots.cxx++");... gROOT -> ProcessLine(".L cbntAnalysis.C++"); ACLiC works best when an old version of library is not still loaded. – Quit ROOT, delete old libraries, restart ROOT + compile. – Quit + start again to verify if your rootlogon.C finds all the libraries.