User Tools

Site Tools


snowmass2013:analyse_d3

<<back

How to analyze in C++

This example shows how to run a C+= program over all Delphes ROOT files located in a certain directory, fill histograms (pT and jet mass) and save them in an output ROOT file.

Look at the workbook of Delphes3 Delphes3 workbook. To get started, install Delphes. You should see the library “libDelphes.so”. The you can browser the ROOT tree as:

gSystem->Load("libDelphes");
TFile::Open("delphes_output.root");
Delphes->Draw("Electron.PT");
TBrowser browser;

Advanced C++ example

This assumes that Delphes3 is already installed. You have the directory “Delphes3” with the shared file “libDelphes.so” inside.

Get the analysis file: antup.tgz

tar -zvxf antup.tgz
cd antup

So you will see 2 directories:

delphes3
antup

Now go to the directory “antup” and link the existing Delphes3 installation:

ln -s  ../Delphes3  delphes

In my case, it will look as:

analysis.h
A_RUN_TEST
data.in
delphes -> ../Delphes3/
main.cxx
Make_input
out

Check that you see the shared Delphes3 file

ls -l delphes/*so

You should see “delphes/libDelphes.so”

The main file which fills histograms is “main.cxx”. It fills some jet variables and save histograms in the ROOT file in “/out” directory.

To run the code, run “./A_RUN_TEST” which loops over the existing ROOT files. But before you do this, you will need to set “DATA_DIR” variable inside “A_RUN_TEST” to navigate to the directory with your “ROOT” files.

How to analyze in PyROOT

If ROOT was compiled using “python” option, you can use PyROOT to loop over events. Here is a small example to plot transverse moment of electrons (based on the original code of Peter Onyisi, with some modifications, see his talk):

test.py
#!/usr/bin/env python
# Based on P.Onyisi example
import sys,os,string
if len(sys.argv)<2:
    print "Usage: python test.py file.root"
    print "Exit.."
    sys.exit()
from ROOT import *
TH1D.SetDefaultSumw2()
gSystem.Load('libDelphes.so')
 
f=TFile(sys.argv[1])
t=f.Delphes # extract the tree
h=TH1D('ele','Electron #eta',8,-4,4) # initialize a histogram
c1=TCanvas() # build a canvas
 
n=0
for e in t:   # loop over all events
  if n%100==0: print "Event=",n
  n=n+1
  for electron in e.Electron: # loop over all electrons
     h.Fill(electron.Eta)
h.Draw()
c1.Print('electron.pdf')
if (raw_input("Press any key to exit") != "-9999"):
    c1.Close(); sys.exit(1);

Run this code as:

python test.py file.root

You will see this image:

How to analyze in Java

MC truth information and most of ROOT files with Delphes outputs are stored in the PROMC file format which can be analyzed on any platform. Read this this section.

Sergei Chekanov 2013/03/13 10:23

snowmass2013/analyse_d3.txt · Last modified: 2014/04/24 01:51 by 127.0.0.1