Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 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

2 2007-10-18Joe 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)?

3 2007-10-18Joe 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()

4 2007-10-18Joe 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().

5 2007-10-18Joe 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

6 2007-10-18Joe 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.

7 2007-10-18Joe 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...

8 2007-10-18Joe 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();

9 2007-10-18Joe 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.

10 2007-10-18Joe 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.

11 2007-10-18Joe 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 }

12 2007-10-18Joe 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.

13 2007-10-18Joe Foster 13 Contents of.root File

14 2007-10-18Joe 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; }

15 2007-10-18Joe 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"); }

16 2007-10-18Joe 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); }

17 2007-10-18Joe Foster 17 Example.gif files

18 2007-10-18Joe 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.

19 2007-10-18Joe 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.


Download ppt "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."

Similar presentations


Ads by Google