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="", 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 185 of file jetCollectionTools.py.

Constructor & Destructor Documentation

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

Definition at line 189 of file jetCollectionTools.py.

189  def __init__(self,runOnMC=True):
190  self.prerequisites = []
191  self.main = []
192  self.pfLabel = "packedPFCandidates"
193  self.pvLabel = "offlineSlimmedPrimaryVertices"
194  self.svLabel = "slimmedSecondaryVertices"
195  self.muLabel = "slimmedMuons"
196  self.elLabel = "slimmedElectrons"
197  self.gpLabel = "prunedGenParticles"
198  self.runOnMC = runOnMC
199  self.patJetsInMiniAOD = ["slimmedJets", "slimmedJetsAK8", "slimmedJetsPuppi", "slimmedCaloJets"]
200 
def __init__(self, runOnMC=True)

Member Function Documentation

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

Definition at line 201 of file jetCollectionTools.py.

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

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

201  def addProcessAndTask(self, proc, label, module):
202  task = getPatAlgosToolsTask(proc)
203  addToProcessAndTask(label, module, proc, task)
204 
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 = "",
  genJetsCollection = "",
  bTagDiscriminators = ["None"],
  JETCorrLevels = ["L1FastJet",
  L2Relative,
  L3Absolute,
  L2L3Residual 
)

Definition at line 212 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().

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

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