CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
jetCollectionTools.RecoJetAdder Class Reference
Inheritance diagram for jetCollectionTools.RecoJetAdder:

Public Member Functions

def __init__ (self, runOnMC=True)
 
def addProcessAndTask (self, proc, label, module)
 
def addRecoJetCollection (self, proc, jet, inputCollection="", minPtFastjet=None, genJetsCollection="", bTagDiscriminators=["None"], JETCorrLevels=["L1FastJet", L2Relative, L3Absolute, L2L3Residual)
 

Public Attributes

 elLabel
 
 gpLabel
 
 main
 
 muLabel
 
 patJetsInMiniAOD
 
 pfLabel
 
 prerequisites
 
 pvLabel
 
 runOnMC
 
 svLabel
 

Detailed Description

Tool to schedule modules for building a patJet collection from MiniAODs

Definition at line 191 of file jetCollectionTools.py.

Constructor & Destructor Documentation

def jetCollectionTools.RecoJetAdder.__init__ (   self,
  runOnMC = True 
)

Definition at line 195 of file jetCollectionTools.py.

195  def __init__(self,runOnMC=True):
196  self.prerequisites = []
197  self.main = []
198  self.pfLabel = "packedPFCandidates"
199  self.pvLabel = "offlineSlimmedPrimaryVertices"
200  self.svLabel = "slimmedSecondaryVertices"
201  self.muLabel = "slimmedMuons"
202  self.elLabel = "slimmedElectrons"
203  self.gpLabel = "prunedGenParticles"
204  self.runOnMC = runOnMC
205  self.patJetsInMiniAOD = ["slimmedJets", "slimmedJetsAK8", "slimmedJetsPuppi", "slimmedCaloJets"]
206 
def __init__(self, runOnMC=True)

Member Function Documentation

def jetCollectionTools.RecoJetAdder.addProcessAndTask (   self,
  proc,
  label,
  module 
)

Definition at line 207 of file jetCollectionTools.py.

References jetCollectionTools.RecoJetAdder.addRecoJetCollection(), helpers.addToProcessAndTask(), and helpers.getPatAlgosToolsTask().

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

207  def addProcessAndTask(self, proc, label, module):
208  task = getPatAlgosToolsTask(proc)
209  addToProcessAndTask(label, module, proc, task)
210 
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:29
def addProcessAndTask(self, proc, label, module)
def getPatAlgosToolsTask(process)
Definition: helpers.py:14
def jetCollectionTools.RecoJetAdder.addRecoJetCollection (   self,
  proc,
  jet,
  inputCollection = "",
  minPtFastjet = None,
  genJetsCollection = "",
  bTagDiscriminators = ["None"],
  JETCorrLevels = ["L1FastJet",
  L2Relative,
  L3Absolute,
  L2L3Residual 
)

Definition at line 219 of file jetCollectionTools.py.

References jetCollectionTools.GenJetAdder.addProcessAndTask(), jetCollectionTools.RecoJetAdder.addProcessAndTask(), jetCollectionTools.RecoJetAdder.elLabel, jetCollectionTools.GenJetAdder.gpLabel, jetCollectionTools.RecoJetAdder.gpLabel, jetCollectionTools.GenJetAdder.main, jetCollectionTools.RecoJetAdder.main, jetCollectionTools.RecoJetAdder.muLabel, jetCollectionTools.RecoJetAdder.patJetsInMiniAOD, jetCollectionTools.RecoJetAdder.pfLabel, jetCollectionTools.GenJetAdder.prerequisites, jetCollectionTools.RecoJetAdder.prerequisites, edm.print(), jetCollectionTools.RecoJetAdder.pvLabel, jetCollectionTools.RecoJetAdder.runOnMC, and jetCollectionTools.RecoJetAdder.svLabel.

Referenced by jetCollectionTools.RecoJetAdder.addProcessAndTask().

219  ):
220  print("jetCollectionTools::RecoJetAdder::addRecoJetCollection: Adding Reco Jet Collection: {}".format(jet))
221 
222  currentTasks = []
223 
224  if inputCollection and inputCollection not in self.patJetsInMiniAOD:
225  raise RuntimeError("Invalid input collection: %s" % inputCollection)
226 
227  #=======================================================
228  #
229  # Figure out which jet collection we're dealing with
230  #
231  #=======================================================
232  recoJetInfo = RecoJetInfo(jet, inputCollection)
233  jetLower = recoJetInfo.jetLower
234  jetUpper = recoJetInfo.jetUpper
235  tagName = recoJetInfo.jetTagName
236 
237  if inputCollection == "slimmedJets":
238  assert(jetLower == "ak4pfchs")
239  elif inputCollection == "slimmedJetsAK8":
240  assert(jetLower == "ak8pfpuppi")
241  elif inputCollection == "slimmedJetsPuppi":
242  assert(jetLower == "ak4pfpuppi")
243  elif inputCollection == "slimmedCaloJets":
244  assert(jetLower == "ak4calo")
245 
246  #=======================================================
247  #
248  # If the patJet collection in MiniAOD is not specified,
249  # we have to build the patJet collection from scratch.
250  #
251  #========================================================
252  if not inputCollection or recoJetInfo.doCalo:
253  print("jetCollectionTools::RecoJetAdder::addRecoJetCollection: inputCollection not specified. Building recojet collection now")
254 
255  #=======================================================
256  #
257  # Prepare the inputs to jet clustering
258  #
259  #========================================================
260  #
261  # Specify PF candidates
262  #
263  pfCand = self.pfLabel
264  #
265  # Setup PU method for PF candidates
266  #
267  if recoJetInfo.jetPUMethod not in [ "", "cs" ]:
268  pfCand += recoJetInfo.jetPUMethod
269 
270 
271  #
272  # Setup modules to perform PU mitigation for
273  # PF candidates
274  #
275  if pfCand not in self.prerequisites:
276  #
277  # Skip if no PU Method or CS specified
278  #
279  if recoJetInfo.jetPUMethod in [ "", "cs" ]:
280  pass
281  #
282  # CHS
283  #
284  elif recoJetInfo.jetPUMethod == "chs":
285  self.addProcessAndTask(proc, pfCand, cms.EDFilter("CandPtrSelector",
286  src = cms.InputTag(self.pfLabel),
287  cut = cms.string("fromPV"),
288  )
289  )
290  self.prerequisites.append(pfCand)
291  #
292  # PUPPI
293  #
294  elif recoJetInfo.jetPUMethod == "puppi":
295  self.addProcessAndTask(proc, pfCand, puppi.clone(
296  candName = self.pfLabel,
297  vertexName = self.pvLabel,
298  clonePackedCands = True,
299  useExistingWeights = True,
300  )
301  )
302  self.prerequisites.append(pfCand)
303  #
304  # Softkiller
305  #
306  elif recoJetInfo.jetPUMethod == "sk":
307  self.addProcessAndTask(proc, pfCand, softKiller.clone(
308  PFCandidates = self.pfLabel,
309  rParam = recoJetInfo.jetSizeNr,
310  )
311  )
312  self.prerequisites.append(pfCand)
313  else:
314  raise RuntimeError("Currently unsupported PU method: '%s'" % recoJetInfo.jetPUMethod)
315 
316  #============================================
317  #
318  # Create the recojet collection
319  #
320  #============================================
321  if not recoJetInfo.doCalo:
322  jetCollection = '{}Collection'.format(jetUpper)
323 
324  if jetCollection in self.main:
325  raise ValueError("Step '%s' already implemented" % jetCollection)
326  #
327  # Cluster new jet
328  #
329  if recoJetInfo.jetPUMethod == "chs":
330  self.addProcessAndTask(proc, jetCollection, ak4PFJetsCHS.clone(
331  src = pfCand,
332  )
333  )
334  elif recoJetInfo.jetPUMethod == "puppi":
335  self.addProcessAndTask(proc, jetCollection, ak4PFJetsPuppi.clone(
336  src = pfCand,
337  )
338  )
339  elif recoJetInfo.jetPUMethod == "sk":
340  self.addProcessAndTask(proc, pfCand, ak4PFJetsSK.clone(
341  src = pfCand,
342  )
343  )
344  elif recoJetInfo.jetPUMethod == "cs":
345  self.addProcessAndTask(proc, jetCollection, ak4PFJetsCS.clone(
346  src = pfCand,
347  )
348  )
349  else:
350  self.addProcessAndTask(proc, jetCollection, ak4PFJets.clone(
351  src = pfCand,
352  )
353  )
354  getattr(proc, jetCollection).jetAlgorithm = supportedJetAlgos[recoJetInfo.jetAlgo]
355  getattr(proc, jetCollection).rParam = recoJetInfo.jetSizeNr
356  #
357  # Set minimum pt threshold of reco jets to be saved after fastjet clustering
358  #
359  if minPtFastjet != None:
360  getattr(proc, jetCollection).jetPtMin = minPtFastjet
361  currentTasks.append(jetCollection)
362  else:
363  jetCollection = inputCollection
364 
365 
366  #=============================================
367  #
368  # Make patJet collection
369  #
370  #=============================================
371  #
372  # Jet correction
373  #
374  if recoJetInfo.jetPUMethod == "puppi":
375  jetCorrLabel = "Puppi"
376  elif recoJetInfo.jetPUMethod in [ "cs", "sk" ]:
377  jetCorrLabel = "chs"
378  else:
379  jetCorrLabel = recoJetInfo.jetPUMethod
380 
381  jetCorrections = (
382  "{}{}{}{}".format(
383  recoJetInfo.jetAlgo.upper(),
384  recoJetInfo.jetSize,
385  "Calo" if recoJetInfo.doCalo else recoJetInfo.jetReco.upper(),
386  jetCorrLabel
387  ),
388  JETCorrLevels,
389  "None",
390  )
391 
392  postfix = "Recluster" if inputCollection == "" else ""
393  addJetCollection(
394  proc,
395  labelName = jetUpper,
396  postfix = postfix,
397  jetSource = cms.InputTag(jetCollection),
398  algo = recoJetInfo.jetAlgo,
399  rParam = recoJetInfo.jetSizeNr,
400  pvSource = cms.InputTag(self.pvLabel),
401  pfCandidates = cms.InputTag(self.pfLabel),
402  svSource = cms.InputTag(self.svLabel),
403  muSource = cms.InputTag(self.muLabel),
404  elSource = cms.InputTag(self.elLabel),
405  genJetCollection = cms.InputTag(genJetsCollection),
406  genParticles = cms.InputTag(self.gpLabel),
407  jetCorrections = jetCorrections,
408  )
409 
410  #
411  # Need to set this explicitly for PUPPI jets
412  #
413  if recoJetInfo.jetPUMethod == "puppi":
414  getattr(proc, "patJetFlavourAssociation{}{}".format(jetUpper,postfix)).weights = cms.InputTag(pfCand)
415 
416  getJetMCFlavour = not recoJetInfo.doCalo and recoJetInfo.jetPUMethod != "cs"
417  if not self.runOnMC: #Remove modules for Gen-level object matching
418  delattr(proc, 'patJetGenJetMatch{}{}'.format(jetUpper,postfix))
419  delattr(proc, 'patJetPartonMatch{}{}'.format(jetUpper,postfix))
420  getJetMCFlavour = False
421  setattr(getattr(proc, "patJets{}{}".format(jetUpper,postfix)), "getJetMCFlavour", cms.bool(getJetMCFlavour))
422 
423  selectedPatJets = "selectedPatJets{}{}".format(jetUpper,postfix)
424  #=============================================
425  #
426  # Update the patJet collection.
427  # This is where we setup
428  # - JEC
429  # - b-tagging discriminators
430  #
431  #=============================================
432  updateJetCollection(
433  proc,
434  labelName = jetUpper,
435  postfix = "Final",
436  jetSource = cms.InputTag(selectedPatJets),
437  jetCorrections = jetCorrections,
438  btagDiscriminators = bTagDiscriminators,
439  )
440 
441  recoJetInfo.patJetFinalCollection = "selectedUpdatedPatJets{}{}".format(jetUpper,"Final")
442  else:
443  recoJetInfo.patJetFinalCollection = inputCollection
444 
445  self.main.extend(currentTasks)
446 

Member Data Documentation

jetCollectionTools.RecoJetAdder.elLabel
jetCollectionTools.RecoJetAdder.gpLabel
jetCollectionTools.RecoJetAdder.main
jetCollectionTools.RecoJetAdder.muLabel
jetCollectionTools.RecoJetAdder.patJetsInMiniAOD
jetCollectionTools.RecoJetAdder.pfLabel
jetCollectionTools.RecoJetAdder.prerequisites
jetCollectionTools.RecoJetAdder.pvLabel
jetCollectionTools.RecoJetAdder.runOnMC
jetCollectionTools.RecoJetAdder.svLabel