CMS 3D CMS Logo

Classes | Functions | Variables
objects.METAnalyzer Namespace Reference

Classes

class  METAnalyzer
 

Functions

def makeGenTkMet (self, event)
 
def makeMETNoEle (self, event)
 
def makeMETNoMu (self, event)
 
def makeMETNoPhoton (self, event)
 
def makeMETs (self, event)
 
def process (self, event)
 
def sumXY (pxys)
 

Variables

 applyJetSmearing
 
 candidates
 
 candidatesTypes
 
 class_object
 
 collectionPostFix
 
 copyMETsByValue
 
 doMetNoEle
 
 doMetNoMu
 
 doMetNoPhoton
 
 doMetNoPU
 
 doTkMet
 
 dzMax
 
 includeTkMetCHS
 
 includeTkMetPVLoose
 
 includeTkMetPVTight
 
 jetAnalyzerPostFix
 
 makeShiftedMETs
 
 met
 
 met_raw
 
 met_sig
 
 met_sumet
 
 metCollection
 
 metNoEle
 
 metNoEleNoPU
 
 metNoMu
 
 metNoMuNoPU
 
 metNoPhoton
 
 metNoPhotonNoPU
 
 metNoPU
 
 noPUMetCollection
 
 old74XMiniAODs
 
 pvflag
 ===> require the Track Candidate charge and with a minimum dz More...
 
 pxy
 
 recalibrate
 
 recalibrateMET
 
 sumEt
 

Function Documentation

◆ makeGenTkMet()

def objects.METAnalyzer.makeGenTkMet (   self,
  event 
)

Definition at line 109 of file METAnalyzer.py.

109  def makeGenTkMet(self, event):
110  genCharged = [ (x.px(),x.py()) for x in self.mchandles['packedGen'].product() if x.charge() != 0 and abs(x.eta()) < 2.4 ]
111  px, py = sum(x[0] for x in genCharged), sum(x[1] for x in genCharged)
112  setattr(event,"tkGenMet"+self.cfg_ana.collectionPostFix, ROOT.reco.Particle.LorentzVector(-px , -py, 0, hypot(px,py)))
113 

References funct.abs().

◆ makeMETNoEle()

def objects.METAnalyzer.makeMETNoEle (   self,
  event 
)

Definition at line 134 of file METAnalyzer.py.

134  def makeMETNoEle(self, event):
135  self.metNoEle = copy.deepcopy(self.met)
136  if self.cfg_ana.doMetNoPU: self.metNoEleNoPU = copy.deepcopy(self.metNoPU)
137 
138  elepx = 0
139  elepy = 0
140  #sum electron momentum
141  for ele in event.selectedElectrons:
142  elepx += ele.px()
143  elepy += ele.py()
144 
145  #subtract electron momentum and construct met
146  px,py = self.metNoEle.px()+elepx, self.metNoEle.py()+elepy
147  self.metNoEle.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, hypot(px,py)))
148 
149  px,py = self.metNoEleNoPU.px()+elepx, self.metNoEleNoPU.py()+elepy
150  self.metNoEleNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, hypot(px,py)))
151  setattr(event, "metNoEle"+self.cfg_ana.collectionPostFix, self.metNoEle)
152  if self.cfg_ana.doMetNoPU: setattr(event, "metNoEleNoPU"+self.cfg_ana.collectionPostFix, self.metNoEleNoPU)
153 

◆ makeMETNoMu()

def objects.METAnalyzer.makeMETNoMu (   self,
  event 
)

Definition at line 114 of file METAnalyzer.py.

114  def makeMETNoMu(self, event):
115  self.metNoMu = copy.deepcopy(self.met)
116  if self.cfg_ana.doMetNoPU: self.metNoMuNoPU = copy.deepcopy(self.metNoPU)
117 
118  mupx = 0
119  mupy = 0
120  #sum muon momentum
121  for mu in event.selectedMuons:
122  mupx += mu.px()
123  mupy += mu.py()
124 
125  #subtract muon momentum and construct met
126  px,py = self.metNoMu.px()+mupx, self.metNoMu.py()+mupy
127  self.metNoMu.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, hypot(px,py)))
128  px,py = self.metNoMuNoPU.px()+mupx, self.metNoMuNoPU.py()+mupy
129  self.metNoMuNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, hypot(px,py)))
130  setattr(event, "metNoMu"+self.cfg_ana.collectionPostFix, self.metNoMu)
131  if self.cfg_ana.doMetNoPU: setattr(event, "metNoMuNoPU"+self.cfg_ana.collectionPostFix, self.metNoMuNoPU)
132 
133 

◆ makeMETNoPhoton()

def objects.METAnalyzer.makeMETNoPhoton (   self,
  event 
)

Definition at line 154 of file METAnalyzer.py.

154  def makeMETNoPhoton(self, event):
155  self.metNoPhoton = copy.deepcopy(self.met)
156 
157  phopx = 0
158  phopy = 0
159  #sum photon momentum
160  for pho in event.selectedPhotons:
161  phopx += pho.px()
162  phopy += pho.py()
163 
164  #subtract photon momentum and construct met
165  px,py = self.metNoPhoton.px()+phopx, self.metNoPhoton.py()+phopy
166  self.metNoPhoton.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, hypot(px,py)))
167  setattr(event, "metNoPhoton"+self.cfg_ana.collectionPostFix, self.metNoPhoton)
168  if self.cfg_ana.doMetNoPU:
169  self.metNoPhotonNoPU = copy.deepcopy(self.metNoPU)
170  px,py = self.metNoPhotonNoPU.px()+phopx, self.metNoPhotonNoPU.py()+phopy
171  self.metNoPhotonNoPU.setP4(ROOT.reco.Particle.LorentzVector(px,py, 0, hypot(px,py)))
172  setattr(event, "metNoPhotonNoPU"+self.cfg_ana.collectionPostFix, self.metNoPhotonNoPU)
173 
174 

◆ makeMETs()

def objects.METAnalyzer.makeMETs (   self,
  event 
)

Definition at line 175 of file METAnalyzer.py.

175  def makeMETs(self, event):
176  import ROOT
177  if self.cfg_ana.copyMETsByValue:
178  self.met = ROOT.pat.MET(self.handles['met'].product()[0])
179  if self.cfg_ana.doMetNoPU: self.metNoPU = ROOT.pat.MET(self.handles['nopumet'].product()[0])
180  else:
181  self.met = self.handles['met'].product()[0]
182  if self.cfg_ana.doMetNoPU: self.metNoPU = self.handles['nopumet'].product()[0]
183 
184  if self.recalibrateMET == "type1":
185  type1METCorr = getattr(event, 'type1METCorr'+self.jetAnalyzerPostFix)
186  self.type1METCorrector.correct(self.met, type1METCorr)
187  elif self.recalibrateMET == True:
188  deltaMetJEC = getattr(event, 'deltaMetFromJEC'+self.jetAnalyzerPostFix)
189  self.applyDeltaMet(self.met, deltaMetJEC)
190  if self.applyJetSmearing:
191  deltaMetSmear = getattr(event, 'deltaMetFromJetSmearing'+self.jetAnalyzerPostFix)
192  self.applyDeltaMet(self.met, deltaMetSmear)
193 
194 
195  if (not self.cfg_ana.copyMETsByValue) and getattr(self.cfg_ana, 'makeShiftedMETs', True):
196  shifts = []
197  for obj in 'JetEn', 'JetRes', 'MuonEn', 'ElectronEn', 'PhotonEn', 'TauEn', 'UnclusteredEn':
198  for sh in 'Up', 'Down':
199  shifts.append( (obj+sh, getattr(self.met,obj+sh)) )
200  shifts.append( ('NoShift', self.met.NoShift) )
201  for name,i in shifts:
202  key = i
203  m = ROOT.pat.MET(self.met)
204  if self.old74XMiniAODs:
205  if key > 12: key = 12
206  elif key <= 3: key = { 'JetEnUp':0, 'JetEnDown':1, 'JetResUp':2, 'JetResDown':3 }[name]
207  m.setP4(self.met.shiftedP4(key))
208  setattr(event, "met{0}_shifted_{1}".format(self.cfg_ana.collectionPostFix, i),m)
209  setattr(event, "met{0}_shifted_{1}".format(self.cfg_ana.collectionPostFix, name),m)
210 
211  self.met_sig = self.met.significance()
212  self.met_sumet = self.met.sumEt()
213 
214  if self.old74XMiniAODs and self.recalibrateMET != "type1":
215  oldraw = self.met.shiftedP2_74x(12,0);
216  setFakeRawMETOnOldMiniAODs( self.met, oldraw.px, oldraw.py, self.met.shiftedSumEt_74x(12,0) )
217  px, py = oldraw.px, oldraw.py
218  else:
219  px, py = self.met.uncorPx(), self.met.uncorPy()
220  self.met_raw = ROOT.reco.Particle.LorentzVector(px,py,0,hypot(px,py))
221 
222  if hasattr(event,'zll_p4'):
223  self.adduParaPerp(self.met,event.zll_p4,"_zll")
224  self.adduParaPerp(self.met_raw, event.zll_p4,"_zll")
225  setattr(event,"met_raw"+self.cfg_ana.collectionPostFix, self.met_raw)
226  setattr(event,"met_raw.upara_zll"+self.cfg_ana.collectionPostFix, self.met_raw.upara_zll)
227  setattr(event,"met_raw.uperp_zll"+self.cfg_ana.collectionPostFix, self.met_raw.uperp_zll)
228 
229  if hasattr(event,'gamma_p4'):
230  self.adduParaPerp(self.met,event.gamma_p4,"_gamma")
231  self.adduParaPerp(self.met_raw, event.gamma_p4,"_gamma")
232  setattr(event,"met_raw"+self.cfg_ana.collectionPostFix, self.met_raw)
233  setattr(event,"met_raw.upara_gamma"+self.cfg_ana.collectionPostFix, self.met_raw.upara_gamma)
234  setattr(event,"met_raw.uperp_gamma"+self.cfg_ana.collectionPostFix, self.met_raw.uperp_gamma)
235 
236  if hasattr(event,"met"+self.cfg_ana.collectionPostFix): raise RuntimeError("Event already contains met with the following postfix: "+self.cfg_ana.collectionPostFix)
237  setattr(event, "met"+self.cfg_ana.collectionPostFix, self.met)
238  if self.cfg_ana.doMetNoPU: setattr(event, "metNoPU"+self.cfg_ana.collectionPostFix, self.metNoPU)
239  setattr(event, "met_sig"+self.cfg_ana.collectionPostFix, self.met_sig)
240  setattr(event, "met_sumet"+self.cfg_ana.collectionPostFix, self.met_sumet)
241 
242  genMET = self.met.genMET()
243  if genMET:
244  setattr(event, "met_genPt"+self.cfg_ana.collectionPostFix, genMET.pt())
245  setattr(event, "met_genPhi"+self.cfg_ana.collectionPostFix, genMET.phi())
246  else:
247  setattr(event, "met_genPt"+self.cfg_ana.collectionPostFix, float('nan'))
248  setattr(event, "met_genPhi"+self.cfg_ana.collectionPostFix, float('nan'))
249 
250  if self.cfg_ana.doMetNoMu and hasattr(event, 'selectedMuons'):
251  self.makeMETNoMu(event)
252 
253  if self.cfg_ana.doMetNoEle and hasattr(event, 'selectedElectrons'):
254  self.makeMETNoEle(event)
255 
256  if self.cfg_ana.doMetNoPhoton and hasattr(event, 'selectedPhotons'):
257  self.makeMETNoPhoton(event)
258 

◆ process()

def objects.METAnalyzer.process (   self,
  event 
)

Definition at line 259 of file METAnalyzer.py.

259  def process(self, event):
260  self.readCollections( event.input)
261  self.counters.counter('events').inc('all events')
262 
263  self.makeMETs(event)
264 
265  if self.cfg_ana.doTkMet:
266  self.makeTkMETs(event);
267 
268  if getattr(self.cfg_ana,"doTkGenMet",self.cfg_ana.doTkMet) and self.cfg_comp.isMC and hasattr(event, 'genParticles'):
269  self.makeGenTkMet(event)
270 
271  return True
272 
273 
274 setattr(METAnalyzer,"defaultConfig", cfg.Analyzer(

◆ sumXY()

def objects.METAnalyzer.sumXY (   pxys)

Definition at line 90 of file METAnalyzer.py.

90  def sumXY(pxys):
91  px, py = sum(x[0] for x in pxys), sum(x[1] for x in pxys)
92  return ROOT.reco.Particle.LorentzVector(-px, -py, 0, hypot(px,py))

Variable Documentation

◆ applyJetSmearing

objects.METAnalyzer.applyJetSmearing

Definition at line 280 of file METAnalyzer.py.

◆ candidates

objects.METAnalyzer.candidates

Definition at line 292 of file METAnalyzer.py.

◆ candidatesTypes

objects.METAnalyzer.candidatesTypes

Definition at line 293 of file METAnalyzer.py.

◆ class_object

objects.METAnalyzer.class_object

Definition at line 275 of file METAnalyzer.py.

◆ collectionPostFix

objects.METAnalyzer.collectionPostFix

Definition at line 295 of file METAnalyzer.py.

◆ copyMETsByValue

objects.METAnalyzer.copyMETsByValue

Definition at line 278 of file METAnalyzer.py.

◆ doMetNoEle

objects.METAnalyzer.doMetNoEle

Definition at line 290 of file METAnalyzer.py.

◆ doMetNoMu

objects.METAnalyzer.doMetNoMu

Definition at line 289 of file METAnalyzer.py.

◆ doMetNoPhoton

objects.METAnalyzer.doMetNoPhoton

Definition at line 291 of file METAnalyzer.py.

◆ doMetNoPU

objects.METAnalyzer.doMetNoPU

Definition at line 288 of file METAnalyzer.py.

◆ doTkMet

objects.METAnalyzer.doTkMet

Definition at line 284 of file METAnalyzer.py.

◆ dzMax

objects.METAnalyzer.dzMax

Definition at line 294 of file METAnalyzer.py.

◆ includeTkMetCHS

objects.METAnalyzer.includeTkMetCHS

Definition at line 285 of file METAnalyzer.py.

◆ includeTkMetPVLoose

objects.METAnalyzer.includeTkMetPVLoose

Definition at line 286 of file METAnalyzer.py.

◆ includeTkMetPVTight

objects.METAnalyzer.includeTkMetPVTight

Definition at line 287 of file METAnalyzer.py.

◆ jetAnalyzerPostFix

objects.METAnalyzer.jetAnalyzerPostFix

Definition at line 281 of file METAnalyzer.py.

◆ makeShiftedMETs

objects.METAnalyzer.makeShiftedMETs

Definition at line 283 of file METAnalyzer.py.

◆ met

objects.METAnalyzer.met

Definition at line 178 of file METAnalyzer.py.

◆ met_raw

objects.METAnalyzer.met_raw

Definition at line 220 of file METAnalyzer.py.

◆ met_sig

objects.METAnalyzer.met_sig

Definition at line 211 of file METAnalyzer.py.

◆ met_sumet

objects.METAnalyzer.met_sumet

Definition at line 212 of file METAnalyzer.py.

◆ metCollection

objects.METAnalyzer.metCollection

Definition at line 276 of file METAnalyzer.py.

◆ metNoEle

objects.METAnalyzer.metNoEle

Definition at line 135 of file METAnalyzer.py.

◆ metNoEleNoPU

objects.METAnalyzer.metNoEleNoPU

Definition at line 136 of file METAnalyzer.py.

◆ metNoMu

objects.METAnalyzer.metNoMu

Definition at line 115 of file METAnalyzer.py.

◆ metNoMuNoPU

objects.METAnalyzer.metNoMuNoPU

Definition at line 116 of file METAnalyzer.py.

◆ metNoPhoton

objects.METAnalyzer.metNoPhoton

Definition at line 155 of file METAnalyzer.py.

◆ metNoPhotonNoPU

objects.METAnalyzer.metNoPhotonNoPU

Definition at line 169 of file METAnalyzer.py.

◆ metNoPU

objects.METAnalyzer.metNoPU

Definition at line 179 of file METAnalyzer.py.

◆ noPUMetCollection

objects.METAnalyzer.noPUMetCollection

Definition at line 277 of file METAnalyzer.py.

◆ old74XMiniAODs

objects.METAnalyzer.old74XMiniAODs

Definition at line 282 of file METAnalyzer.py.

◆ pvflag

objects.METAnalyzer.pvflag

===> require the Track Candidate charge and with a minimum dz

Definition at line 75 of file METAnalyzer.py.

◆ pxy

objects.METAnalyzer.pxy

Definition at line 76 of file METAnalyzer.py.

◆ recalibrate

objects.METAnalyzer.recalibrate

Definition at line 279 of file METAnalyzer.py.

◆ recalibrateMET

objects.METAnalyzer.recalibrateMET

Definition at line 184 of file METAnalyzer.py.

◆ sumEt

objects.METAnalyzer.sumEt
counter
Definition: counter.py:1
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
objects.METAnalyzer.sumEt
sumEt
Definition: METAnalyzer.py:97
objects.METAnalyzer.makeMETs
def makeMETs(self, event)
Definition: METAnalyzer.py:175
objects.METAnalyzer.makeMETNoEle
def makeMETNoEle(self, event)
Definition: METAnalyzer.py:134
objects.METAnalyzer.makeGenTkMet
def makeGenTkMet(self, event)
Definition: METAnalyzer.py:109
objects.METAnalyzer.process
def process(self, event)
Definition: METAnalyzer.py:259
objects.METAnalyzer.makeMETNoPhoton
def makeMETNoPhoton(self, event)
Definition: METAnalyzer.py:154
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
objects.METAnalyzer.makeMETNoMu
def makeMETNoMu(self, event)
Definition: METAnalyzer.py:114
format
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
objects.METAnalyzer.sumXY
def sumXY(pxys)
Definition: METAnalyzer.py:90
JetReCalibrator.setFakeRawMETOnOldMiniAODs
def setFakeRawMETOnOldMiniAODs(met, rawpx, rawpy, rawsumet)
Definition: JetReCalibrator.py:186
met_cff.significance
significance
Definition: met_cff.py:18