Fork me on GitHub

source: git/examples/Example5.py@ cc8716b

Last change on this file since cc8716b was 66b1770, checked in by Michele Selvaggi <michele.selvaggi@…>, 4 years ago

added python version of gen part print example

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#!/usr/bin/env python
2import sys
3import ROOT, math
4from collections import OrderedDict
5from ROOT import TLorentzVector
6import array
7
8#_________________________________________________________________________________________
9
10
11if len(sys.argv) < 2:
12 print " Usage: Example1.py input_file"
13 sys.exit(1)
14
15ROOT.gSystem.Load("libDelphes")
16
17try:
18 ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"')
19 ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"')
20except:
21 pass
22
23inputFile = sys.argv[1]
24outputFile = sys.argv[2]
25
26# Create chain of root trees
27chain = ROOT.TChain("Delphes")
28chain.Add(inputFile)
29
30# Create object of class ExRootTreeReader
31treeReader = ROOT.ExRootTreeReader(chain)
32numberOfEntries = treeReader.GetEntries()
33
34# Get pointers to branches used in this analysis
35
36branchParticle = treeReader.UseBranch("Particle")
37
38## fill histogram with particle status
39hStatus = ROOT.TH1F("hStatus", "hStatus", 101, -0.5, 100.5)
40
41debug = True
42if debug: numberOfEntries = 10
43
44
45# Loop over all events
46for entry in range(0, numberOfEntries):
47 # Load selected branches with data from specified event
48 treeReader.ReadEntry(entry)
49
50 if (entry+1)%100 == 0:
51 print ' ... processed {} events ...'.format(entry+1)
52 i=0
53
54 print '---------------------------------------------------------------------------------------'
55 print ''
56
57
58 for gen in branchParticle:
59 i +=1
60 print "N: ", i, ", St: ", gen.Status,", PID: ",gen.PID,", E: ",gen.E,", PT: ",gen.PT,", Eta: ",gen.Eta,", M: ",gen.Mass,", M1: ",gen.M1,", M2: ",gen.M2,", D1: ",gen.D1,", D2: ",gen.D2
61
62 hStatus.Fill(gen.Status)
63
64# Show resulting histograms
65out_root = ROOT.TFile(outputFile,"RECREATE")
66
67hStatus.Write()
Note: See TracBrowser for help on using the repository browser.