User Tools

Site Tools


snowmass2013:analyse_d36_promc

<<back

Reading Delphes output without ROOT

There were questions about how to analyze Delphs3 fast simulation output if ROOT is not installed (or cannot be installed). Well, better to install it! But you can also read Delphes data converted to the ProMC format which can be read in any programming language without ROOT. You can read such files natively using C++ (without ROOT), Python or Java using Windows, Linux or Mac platforms (or Android, in future). You can also use your favorite IDE, such as Netbeans or Eclipse. In this example, we will use plotting library from SCaVis data-analysis framework, which helps to make histograms, plots and create PDF/EPS figures.

All Delphes ROOT files, which are listened on MC fast simulation page have been converted to the ProMC format. For example, every dataset with 96 output ROOT files was converted to a single ProMC file. For the current conversion, ProMC files are typically x2-x3 times smaller than all 96 ROOT files combined (partially, due to very efficient compression of ProMC).

Below we will explain how to read such files and fill histograms using Java (you can also use C++ without ROOT, or CPython, since ProMC is fully multiplatform).

ProMC file repositories

You can view truth information in these files using Java (also works on windows):

wget http://atlaswww.hep.anl.gov/asc/promc/download/browser_promc.jar
http://mc.hep.anl.gov/asc/snowmass2013/delphes36/promc/MadGraph5Pythia_wjets/MadGraph5Pythia_wjets_mu0.promc
java -jar browser_promc.jar MadGraph5Pythia_wjets_mu0.promc

This brings up a GUI window to look at the stored events. Use Java7 (check as “java -version”). Read more about this browser here. To analyze truth particle information and reconstructed objects (jets, electrons, photons) use the approaches shown below.

Reading Delphes data in C++

Here are the steps to analyze data in C++, but without ROOT. Install ProMC library. Then generate analysis code from the ProMC input file and run it:

mkdir test
wget http://mc.hep.anl.gov/asc/snowmass2013/delphes36/promc/MadGraph5Pythia_wjets_mu0.promc
promc_proto # generate layout files in the directory proto
promc_code  # generate analysis code in C++/Java/Python
make        # compiles C++ reader.cc
./reader MadGraph5Pythia_wjets_mu0.promc # read the data 

Reading Delphes data in Java

The above example also generates Java code to read the data. Try this:

cd java/
run.sh MadGraph5Pythia_wjets_mu0.promc # read the data 

Reading Delphes data in Python

The above example also generates the Python code to read the ProMC files. Try this:

cd python/
python reader.py  MadGraph5Pythia_wjets_mu0.promc # read the data 

Look at the “modules” directory to learn about the methods,

Reading data using Java without ProMC

A more advanced code uses a Java histogramming package, without the ProMC installation:

wget http://mc.hep.anl.gov/asc/snowmass2013/delphes36/packages/delphes_read.tgz         # get analysis package
tar -zvxf delphes_read.tgz            # untar it
cd delphes_read                       # go to the analysis directory
wget http://mc.hep.anl.gov/asc/snowmass2013/delphes36/promc/MadGraph5Pythia_wjets/MadGraph5Pythia_wjets_mu0.promc
run.sh   MadGraph5Pythia_wjets_mu0.promc     # compile and run it. 

It fills a few histograms and show them in a canvas.

Browser the truth particle record

You can browser the events in the file using the same “lib/browser_promc.jar” file as:

java -jar lib/browser_promc.jar herwigpp_ttbar_mu0.promc

It will shows the header file. If you double click on even numbers (left), you will see particle records for a selected event.

For Windows: Go to “lib” and double click “browser_promc.jar”. Open any ProMC file as File→Open ProMC“.

You can setup a NetBeans or Eclipse to identify all methods for each class (for jets, electrons, muons). Look at the Java API of ProMCEvent which keeps all Jets, Particles etc. (and their methods). See more info below. You can also find all methods using Java API included in this example. Read Java API as:

firefox api/index.html

Make the needed modifications in the main Java class “ReadProMC.java” to make this example useful for your analysis.

Using Python/Jython

You can also use Jython (Python implemented in Java), instead of Java, and run the code on any platform (Windows, Mac, Linux). Install SCaVis, and copy an additional jar file “browser_promc.jar” to the ScaVis directory “lib/users”. This is how to do this:

cd scavis/lib/user
wget http://mc.hep.anl.gov/asc/snowmass2013/delphes36/packages/delphes_read/lib/browser_promc.jar

Restart SCaVis IDE.

Now you can make a simple Python script which reads data in the ProMC format: Here is a small Python/Jython example which plots jet pT. Save this file as “delphes.py” and open it in the ScaVis IDE. Then press “run”.

delphes.py
# Reading Delphes file in the ProMC format using ScaVis http://jwork.org/scavis
# S.Chekanov (ANL)
from java.io import *
from java.awt import *
from promc.io import *
from proto import *   # import FileMC
from jhplot import *  # import ScaVis graphics
 
file = FileMC("herwigpp_ttbar_mu0.promc")
version=file.getVersion()
print "ProMC version=",version
header = file.getHeader()
unit=float(header.getMomentumUnit())
lunit=float(header.getLengthUnit())
print "Momentum unit=",unit
print "Length unit=",lunit
 
h1= H1D("PT (ele)",50,0,1000)   # create a histogram
print "File size=",file.size()
for i in range(file.size()):
      if (i%1000==0): print "Event=",i 
      entry = file.read(i)
      jets = entry.getJets()                   # get jets
      for j in range(jets.getPTCount()): 
            h1.fill(jets.getPT(j)/unit)            
c1 = HPlot("Canvas",600,400) # plot histogram
c1.visible()
c1.setAutoRange()
c1.draw(h1)
c1.export("jetpt.pdf")                          # create PDF file

You will see a plot of jet pT in a pop-up window. The example uses two classes:

  • H1D histogram class
  • HPlot canvas to show the histogram

Note that we use unit (unit for energy) and lunit (unit for length) to convert internal (Google's “variant”) representation of ProMC into real numbers representing GeV. Here is the rule:

  • Energy-related variables, such as E,Mass,PT,and Px,Py,Pz should be divided by unit.
  • Length-related based (X,Y,Z,T) and Eta and Phi should be divided by lunit.

We map ROOT branches to Java classes in the following way:

Use methods of these classes to access the needed variables.

Useful methods

As in ROOT, there are a high-level Java classes included to the library to manipulate with particles or jets (i.e. similar to TLorenzVector in ROOT). Look at the Java API of the following classes:

Some examples using Python (and Java) are shown here.

To create LParticle from the classes of the ProMC format with viable byte compression, do this:

If you know px,py,pz,and energy in the integer representation from ProMC, simply do this:

p=LParticle(px,py,pz,energy)
p.dividePxPyPzE(unit);

where unit=float(header.getMomentumUnit()) (can be defined at the beginning of this file). This converts integer representation of momenta to the GeV representation.

If you know PT,Eta,Phi and mass of a jet or other object from the ProMC, create the LParticle object as:

p=LParticle()
p.setPtEtaPhiM(pt/unit, eta/lunit, phi/lunit, mass/unit);

Note we use “unit” for pt and mass, while lunit is used for eta and phi.

Reading Delphes ProMC files in C++

You can read Delphes ProMC files in C++ (still can be without installing ROOT). Install ProMC library.

wget http://mc.hep.anl.gov/asc/snowmass2013/delphes36/packages/delphes_read_cpp.tgz
tar -zvxf delphes_read_cpp.tgz
cd delphes_read_cpp
wget http://mc.hep.anl.gov/asc/snowmass2013/delphes36/promc/MadGraph5Pythia_wjets_mu0.promc
promc_proto MadGraph5Pythia_wjets_mu0.promc # generates data templates
promc_code                                  # generates source code from the data
make                                        # compiles
delphes_read_cpp MadGraph5Pythia_wjets_mu0.promc

Sergei Chekanov 2013/04/27 23:02

snowmass2013/analyse_d36_promc.txt · Last modified: 2014/04/24 01:51 (external edit)