Fork me on GitHub

Ticket #1367: Jet_constituent.py

File Jet_constituent.py, 1.7 KB (added by Tae Kim, 6 years ago)
Line 
1#!/usr/bin/env python
2
3import sys
4import math
5import os
6from array import array
7import pandas as pd
8import ROOT
9
10try:
11 input = raw_input
12except:
13 pass
14
15if len(sys.argv) < 2:
16 print(" Usage: Jet_constituent.py input_file")
17 sys.exit(1)
18
19ROOT.gSystem.Load("libDelphes")
20
21try:
22 ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"')
23 ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"')
24 ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootResult.h"')
25except:
26 pass
27
28inputFile = sys.argv[1]
29
30# Create chain of root trees
31chain = ROOT.TChain("Delphes")
32chain.Add(inputFile)
33
34# Create object of class ExRootTreeReader
35treeReader = ROOT.ExRootTreeReader(chain)
36#numberOfEntries = treeReader.GetEntries()
37numberOfEntries = 1 # debug
38
39# Get pointers to branches used in this analysis
40branchJet = treeReader.UseBranch("Jet")
41
42event_jet = pd.DataFrame()
43
44# Loop over all events
45for entry in range(0, numberOfEntries):
46 # Load selected branches with data from jet event
47 treeReader.ReadEntry(entry)
48
49 for jetentry in range (0, branchJet.GetEntriesFast()):
50 jet = branchJet.At(jetentry)
51
52 for constit in range (0, jet.Constituents.GetEntriesFast()):
53 obj = jet.Constituents.At(constit)
54# print(jet.Constituents)
55 print(obj.IsA())
56# print(constit)
57# print(obj)
58# event_jet = event_jet.append({'Event' : entry,
59# 'jet number': jetentry,
60# 'jet constituent pT': obj.PT,
61# 'jet constituent Eta': obj.Eta,
62# 'jet constituent Phi': obj.Phi}, ignore_index=True)
63
64
65
66input("Press Enter to continue...")