wiki:UserManual

Introductory remarks

ExRootAnalysis is a package designed to simplify ROOT tree production and analysis. The purpose of this tutorial is to present current functionality of this software.

Quick start with ExRootAnalysis

Make sure that ROOT is installed and ROOTSYS, PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH are configured correctly.

Command to unpack the source code:

   svn checkout https://server06.fynu.ucl.ac.be/sources/ExRootAnalysis/trunk ExRootAnalysis

Commands to create shared library for interactive ROOT session:

   cd ExRootAnalysis

   make

Simple analysis using TTree::Draw

Now we can start ROOT and look at the data stored in the ROOT tree.

Start ROOT and load shared library:

   root
   gSystem->Load("lib/libExRootAnalysis.so");

Open ROOT tree file and do some basic analysis using Draw or TBrowser:

   TFile::Open("pgs_events.root");
   LHCO->Draw("Electron.PT");
   TBrowser browser;

Note 1: LHCO - tree name, it can be learnt e.g. from TBrowser

Note 2: Electron - branch name; PT - variable (leaf) of this branch

Complete description of all branches can be found in

   ExRootAnalysis/doc/RootTreeDescription.html

Macro-based analysis

ExRootAnalysis provides a set of classes simplifying access to the root ROOT trees. The most interesting class is ExRootTreeReader. This class provides simple methods sufficient to access every branch in every event stored in a ROOT tree:

  • ExRootTreeReader(TTree*) – constructor takes ROOT tree as parameter
  • Long64_t GetEntries() – returns total number of events stored on the tree
  • TClonesArray *UseBranch(branchName) – returns pointer to collection of branch

elements and specifies branches needed for analysis

Analysis macro consists of histogram booking, event loop (histogram filling), histogram display

Basic analysis macro:

{
  // Load shared library
  gSystem->Load("lib/libExRootAnalysis.so");
  gSystem->Load("libPhysics");

  // Create chain of root trees
  TChain chain("LHCO");
  chain.Add("pgs_events.root");
  
  // Create object of class ExRootTreeReader
  ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
  Long64_t numberOfEntries = treeReader->GetEntries();
  
  // Get pointers to branches used in this analysis
  TClonesArray *branchJet = treeReader->UseBranch("Jet");
  TClonesArray *branchElectron = treeReader->UseBranch("Electron");
  
  // Book histograms
  TH1 *histJetPT = new TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0);
  TH1 *histMass = new TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0);

  // Loop over all events
  for(Int_t entry = 0; entry < numberOfEntries; ++entry) {

    // Load selected branches with data from specified event
    treeReader->ReadEntry(entry);
  
    // If event contains at least 1 jet
    if(branchJet->GetEntries() > 0) {

      // Take first jet
      TRootJet *jet = (TRootJet*) branchJet->At(0);
      
      // Plot jet transverse momentum
      histJetPT->Fill(jet->PT);
      
      // Print jet transverse momentum
      cout << jet->PT << endl;
    }

    TRootElectron *elec1, *elec2;
    TLorentzVector vec1, vec2;

    // If event contains at least 2 electrons
    if(branchElectron->GetEntries() > 1) {

      // Take first two electrons
      elec1 = (TRootElectron *) branchElectron->At(0);
      elec2 = (TRootElectron *) branchElectron->At(1);

      // Create two 4-vectors for the electrons
      vec1.SetPtEtaPhiM(elec1->PT, elec1->Eta, elec1->Phi, 0.0);
      vec2.SetPtEtaPhiM(elec2->PT, elec2->Eta, elec2->Phi, 0.0);

      // Plot their invariant mass
      histMass->Fill((vec1 + vec2).M());
    }
  }

  // Show resulting histograms
  histJetPT->Draw();
  histMass->Draw();
}

More advanced macro-based analysis

ExRootAnalysis/test contains macro Example.C using class ExRootTreeReader to access data and class ExRootResult to manage histograms booking and output

Here are commands to run this macro:

   cd ExRootAnalysis/test
   $EDITOR test.list
   root
   gSystem->Load("../lib/libExRootAnalysis.so");
   .X Example.C("test.list");

Note: file test.list should contain list of root files that you would like to analyse (one root file per line)

Last modified 6 years ago Last modified on 09/10/13 10:01:05