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 def __init__(self, cfg_ana, cfg_comp, looperName ):
18 super(METAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
22 self.handles[
'met'] = AutoHandle(
'slimmedMETs',
'std::vector<pat::MET>' )
23 self.handles[
'nopumet'] = AutoHandle(
'slimmedMETs',
'std::vector<pat::MET>' )
24 self.handles[
'cmgCand1'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
25 self.handles[
'cmgCand2'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
26 self.handles[
'cmgCand3'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
27 self.handles[
'cmgCand4'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
28 self.handles[
'cmgCand5'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
29 self.handles[
'cmgCand6'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
30 self.handles[
'cmgCand7'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
31 self.handles[
'cmgCand8'] = AutoHandle( self.cfg_ana.candidates, self.cfg_ana.candidatesTypes )
32 self.handles[
'vertices'] = AutoHandle(
"offlineSlimmedPrimaryVertices",
'std::vector<reco::Vertex>', fallbackLabel=
"offlinePrimaryVertices" )
36 self.counters.addCounter(
'events')
37 count = self.counters.counter(
'events')
38 count.register(
'all events')
44 pfcands = self.handles[
'cmgCand'].product()
46 for i
in xrange(pfcands.size()):
50 if (pfcands.at(i).charge()!=0
and (
abs(pfcands.at(i).dz())<=self.cfg_ana.dzMax )):
52 charged.append(pfcands.at(i))
55 event.tkMet = ROOT.reco.Particle.LorentzVector(-1.*(sum([x.px()
for x
in charged])) , -1.*(sum([x.py()
for x
in charged])), 0, 0 )
60 event.metNoMu = copy.deepcopy(self.handles[
'met'].product()[0])
61 event.metNoMuNoPU = copy.deepcopy(self.handles[
'nopumet'].product()[0])
66 for mu
in event.selectedMuons:
71 if self.cfg_ana.recalibrate
and hasattr(event,
'deltaMetFromJetSmearing'):
73 px,py = event.metNoMu.px()+event.deltaMetFromJetSmearing[0]-mupx, event.metNoMu.py()+event.deltaMetFromJetSmearing[1]-mupy
74 event.metNoMu.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
75 px,py = event.metNoMuNoPU.px()+event.deltaMetFromJetSmearing[0]-mupx, event.metNoMuNoPU.py()+event.deltaMetFromJetSmearing[1]-mupy
76 event.metNoMuNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, hypot(px,py)))
77 if self.cfg_ana.recalibrate
and hasattr(event,
'deltaMetFromJEC')
and event.deltaMetFromJEC[0] != 0
and event.deltaMetFromJEC[1] != 0:
79 px,py = event.metNoMu.px()+event.deltaMetFromJEC[0]-mupx, event.metNoMu.py()+event.deltaMetFromJEC[1]-mupy
80 event.met.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
81 px,py = event.metNoMuNoPU.px()+event.deltaMetFromJEC[0]-mupx, event.metNoMuNoPU.py()+event.deltaMetFromJEC[1]-mupy
82 event.metNoMuNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
86 event.met = self.handles[
'met'].product()[0]
87 event.metNoPU = self.handles[
'nopumet'].product()[0]
88 if self.cfg_ana.recalibrate
and hasattr(event,
'deltaMetFromJetSmearing'):
90 px,py = event.met.px()+event.deltaMetFromJetSmearing[0], event.met.py()+event.deltaMetFromJetSmearing[1]
91 event.met.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
92 px,py = event.metNoPU.px()+event.deltaMetFromJetSmearing[0], event.metNoPU.py()+event.deltaMetFromJetSmearing[1]
93 event.metNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
94 if self.cfg_ana.recalibrate
and hasattr(event,
'deltaMetFromJEC')
and event.deltaMetFromJEC[0] != 0
and event.deltaMetFromJEC[1] != 0:
96 px,py = event.met.px()+event.deltaMetFromJEC[0], event.met.py()+event.deltaMetFromJEC[1]
97 event.met.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
98 px,py = event.metNoPU.px()+event.deltaMetFromJEC[0], event.metNoPU.py()+event.deltaMetFromJEC[1]
99 event.metNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, math.hypot(px,py)))
103 self.readCollections( event.input)
104 self.counters.counter(
'events').inc(
'all events')
109 if self.cfg_ana.doTkMet:
110 self.makeTkMETs(event);
112 if self.cfg_ana.doMetNoMu
and hasattr(event,
'selectedMuons'):
113 self.makeMETNoMu(event)
118 setattr(METAnalyzer,
"defaultConfig", cfg.Analyzer(
119 class_object = METAnalyzer,
123 candidates=
'packedPFCandidates',
124 candidatesTypes=
'std::vector<pat::PackedCandidate>',
Abs< T >::type abs(const T &t)