2 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
3 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
4 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects
import Jet
6 from PhysicsTools.HeppyCore.statistics.counter
import Counter, Counters
7 from PhysicsTools.Heppy.physicsutils.JetReCalibrator
import JetReCalibrator
13 from ROOT
import TLorentzVector, TVectorD
17 from copy
import deepcopy
20 def __init__(self, cfg_ana, cfg_comp, looperName ):
21 super(METAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
25 self.handles[
'met'] = AutoHandle(
'slimmedMETs',
'std::vector<pat::MET>' )
26 self.handles[
'nopumet'] = AutoHandle(
'slimmedMETs',
'std::vector<pat::MET>' )
27 self.handles[
'cmgCand'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
28 self.handles[
'vertices'] = AutoHandle(
"offlineSlimmedPrimaryVertices",
'std::vector<reco::Vertex>', fallbackLabel=
"offlinePrimaryVertices" )
32 self.counters.addCounter(
'events')
33 count = self.counters.counter(
'events')
34 count.register(
'all events')
44 pfcands = self.handles[
'cmgCand'].product()
46 for i
in xrange(pfcands.size()):
50 if (pfcands.at(i).charge()!=0):
52 if abs(pfcands.at(i).dz())<=self.cfg_ana.dzMax:
53 charged.append(pfcands.at(i))
55 if pfcands.at(i).fromPV()>0:
56 chargedchs.append(pfcands.at(i))
58 if pfcands.at(i).fromPV()>1:
59 chargedPVLoose.append(pfcands.at(i))
61 if pfcands.at(i).fromPV()>2:
62 chargedPVTight.append(pfcands.at(i))
65 event.tkMet = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px()
for x
in charged])) , -1.*(sum([x.py()
for x
in charged])), 0, math.hypot((sum([x.px()
for x
in charged])),(sum([x.py()
for x
in charged]))) )
66 event.tkMetchs = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px()
for x
in chargedchs])) , -1.*(sum([x.py()
for x
in chargedchs])), 0, math.hypot((sum([x.px()
for x
in chargedchs])),(sum([x.py()
for x
in chargedchs]))) )
67 event.tkMetPVLoose = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px()
for x
in chargedPVLoose])) , -1.*(sum([x.py()
for x
in chargedPVLoose])), 0, math.hypot((sum([x.px()
for x
in chargedPVLoose])),(sum([x.py()
for x
in chargedPVLoose]))) )
68 event.tkMetPVTight = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px()
for x
in chargedPVTight])) , -1.*(sum([x.py()
for x
in chargedPVTight])), 0, math.hypot((sum([x.px()
for x
in chargedPVTight])),(sum([x.py()
for x
in chargedPVTight]))) )
73 event.metNoMu = copy.deepcopy(event.met)
74 event.metNoMuNoPU = copy.deepcopy(event.metNoPU)
79 for mu
in event.selectedMuons:
84 px,py = event.metNoMu.px()-mupx, event.metNoMu.py()-mupy
85 event.metNoMu.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
86 px,py = event.metNoMuNoPU.px()-mupx, event.metNoMuNoPU.py()-mupy
87 event.metNoMuNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
90 event.metNoPhoton = copy.deepcopy(event.met)
91 event.metNoPhotonNoPU = copy.deepcopy(event.metNoPU)
96 for pho
in event.selectedPhotons:
101 px,py = event.metNoPhoton.px()-phopx, event.metNoPhoton.py()-phopy
102 event.metNoPhoton.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
103 px,py = event.metNoPhotonNoPU.px()-phopx, event.metNoPhotonNoPU.py()-phopy
104 event.metNoPhotonNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
108 event.met = self.handles[
'met'].product()[0]
109 event.metNoPU = self.handles[
'nopumet'].product()[0]
113 for i
in range(event.met.METUncertaintySize):
114 m = ROOT.pat.MET(event.met)
117 m.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
118 setattr(event,
"met_shifted_{0}".
format(i), m)
119 event.met_sig = event.met.significance()
120 event.met_sumet = event.met.sumEt()
124 event.metraw = event.met.shiftedPt(12, 0)
125 event.metType1chs = event.met.shiftedPt(12, 1)
127 if self.cfg_ana.recalibrate
and hasattr(event,
'deltaMetFromJetSmearing'):
128 px,py = event.met.px()+event.deltaMetFromJetSmearing[0], event.met.py()+event.deltaMetFromJetSmearing[1]
129 event.met.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
130 px,py = event.metNoPU.px()+event.deltaMetFromJetSmearing[0], event.metNoPU.py()+event.deltaMetFromJetSmearing[1]
131 event.metNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
132 if self.cfg_ana.recalibrate
and hasattr(event,
'deltaMetFromJEC')
and event.deltaMetFromJEC[0] != 0
and event.deltaMetFromJEC[1] != 0:
133 px,py = event.met.px()+event.deltaMetFromJEC[0], event.met.py()+event.deltaMetFromJEC[1]
134 event.met.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
135 px,py = event.metNoPU.px()+event.deltaMetFromJEC[0], event.metNoPU.py()+event.deltaMetFromJEC[1]
136 event.metNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
138 if self.cfg_ana.doMetNoMu
and hasattr(event,
'selectedMuons'):
139 self.makeMETNoMu(event)
141 if self.cfg_ana.doMetNoPhoton
and hasattr(event,
'selectedPhotons'):
142 self.makeMETNoPhoton(event)
145 self.readCollections( event.input)
146 self.counters.counter(
'events').inc(
'all events')
151 if self.cfg_ana.doTkMet:
152 self.makeTkMETs(event);
159 setattr(METAnalyzer,
"defaultConfig", cfg.Analyzer(
160 class_object = METAnalyzer,
164 doMetNoPhoton =
False,
165 candidates=
'packedPFCandidates',
166 candidatesTypes=
'std::vector<pat::PackedCandidate>',
Abs< T >::type abs(const T &t)