-
Notifications
You must be signed in to change notification settings - Fork 5
/
printMet_AOD.py
executable file
·83 lines (66 loc) · 2.53 KB
/
printMet_AOD.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
# Tai Sakuma <[email protected]>
import ROOT
import sys
import math
from optparse import OptionParser
ROOT.gROOT.SetBatch(1)
##____________________________________________________________________________||
parser = OptionParser()
parser.add_option('-i', '--inputPath', default = '/afs/cern.ch/cms/Tutorials/TWIKI_DATA/MET/TTJets_AODSIM_532_numEvent100.root', action = 'store', type = 'string')
(options, args) = parser.parse_args(sys.argv)
inputPath = options.inputPath
##____________________________________________________________________________||
def main():
printHeader()
if getNEvents(inputPath):
count(inputPath)
##____________________________________________________________________________||
def printHeader():
print '%6s' % 'run',
print '%10s' % 'lumi',
print '%9s' % 'event',
print '%10s' % 'met.pt',
print '%10s' % 'met.px',
print '%10s' % 'met.py',
print '%10s' % 'met.phi',
print
##____________________________________________________________________________||
def count(inputPath):
files = [inputPath]
events = Events(files)
handlePFMETs = Handle("std::vector<reco::PFMET>")
for event in events:
run = event.eventAuxiliary().run()
lumi = event.eventAuxiliary().luminosityBlock()
eventId = event.eventAuxiliary().event()
event.getByLabel(("pfMet", "", "RECO"), handlePFMETs)
met = handlePFMETs.product().front()
print '%6d' % run,
print '%10d' % lumi,
print '%9d' % eventId,
print '%10.3f' % met.pt(),
print '%10.3f' % met.px(),
print '%10.3f' % met.py(),
print '%10.2f' % (met.phi()/math.pi*180.0),
print
##____________________________________________________________________________||
def getNEvents(inputPath):
file = ROOT.TFile.Open(inputPath)
events = file.Get('Events')
return events.GetEntries()
##____________________________________________________________________________||
def loadLibraries():
argv_org = list(sys.argv)
sys.argv = [e for e in sys.argv if e != '-h']
ROOT.gSystem.Load("libFWCoreFWLite")
ROOT.AutoLibraryLoader.enable()
ROOT.gSystem.Load("libDataFormatsFWLite")
ROOT.gSystem.Load("libDataFormatsPatCandidates")
sys.argv = argv_org
##____________________________________________________________________________||
loadLibraries()
from DataFormats.FWLite import Events, Handle
##____________________________________________________________________________||
if __name__ == '__main__':
main()