forked from TaiSakuma/WorkBookMet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printMet_corrMet.py
executable file
·112 lines (92 loc) · 3.77 KB
/
printMet_corrMet.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
# Tai Sakuma <sakuma@fnal.gov>
import ROOT
import sys
import math
import json
import re
from optparse import OptionParser
ROOT.gROOT.SetBatch(1)
##____________________________________________________________________________||
parser = OptionParser()
parser.add_option('-i', '--inputPath', default = './corrMet.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 '%18s' % 'module',
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)
handleGenMETs = Handle("std::vector<reco::GenMET>")
handlePFMETs = Handle("std::vector<reco::PFMET>")
handleCaloMETs = Handle("std::vector<reco::CaloMET>")
handleMETs = Handle("std::vector<reco::MET>")
METCollections = (
("pfMet", "", "RECO", handlePFMETs ),
("pfMetT0rt", "", "CORR", handlePFMETs ),
("pfMetT0rtT1", "", "CORR", handlePFMETs ),
("pfMetT0pc", "", "CORR", handlePFMETs ),
("pfMetT0pcT1", "", "CORR", handlePFMETs ),
("pfMetT1", "", "CORR", handlePFMETs ),
("pfMetT0rtTxy", "", "CORR", handlePFMETs ),
("pfMetT0rtT1Txy", "", "CORR", handlePFMETs ),
("pfMetT0pcTxy", "", "CORR", handlePFMETs ),
("pfMetT0pcT1Txy", "", "CORR", handlePFMETs ),
("pfMetT1Txy", "", "CORR", handlePFMETs ),
# ("met", "", "RECO", handleCaloMETs ),
# ("caloMetT1", "", "CORR", handleCaloMETs ),
# ("caloMetT1T2", "", "CORR", handleCaloMETs ),
# ("genMetTrue", "" ,"SIM", handleGenMETs ),
)
for event in events:
run = event.eventAuxiliary().run()
lumi = event.eventAuxiliary().luminosityBlock()
eventId = event.eventAuxiliary().event()
for METCollection in METCollections:
handle = METCollection[3]
event.getByLabel(METCollection[0:3], handle)
met = handle.product().front()
print '%6d' % run,
print '%10d' % lumi,
print '%9d' % eventId,
print '%18s' % METCollection[0],
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()