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

◆ __init__()

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 

Member Function Documentation

◆ addProcessAndTask()

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

Definition at line 207 of file jetCollectionTools.py.

207  def addProcessAndTask(self, proc, label, module):
208  task = getPatAlgosToolsTask(proc)
209  addToProcessAndTask(label, module, proc, task)
210 

References helpers.addToProcessAndTask(), and helpers.getPatAlgosToolsTask().

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

◆ addRecoJetCollection()

def jetCollectionTools.RecoJetAdder.addRecoJetCollection (   self,
  proc,
  jet,
  inputCollection = "",
  minPtFastjet = None,
  genJetsCollection = "",
  bTagDiscriminators = ["None"],
  JETCorrLevels = ["L1FastJet", "L2Relative", "L3Absolute", "L2L3Residual"] 
)

Definition at line 211 of file jetCollectionTools.py.

211  def addRecoJetCollection(self,
212  proc,
213  jet,
214  inputCollection = "",
215  minPtFastjet = None,
216  genJetsCollection = "",
217  bTagDiscriminators = ["None"],
218  JETCorrLevels = ["L1FastJet", "L2Relative", "L3Absolute", "L2L3Residual"],
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  )
299  )
300  self.prerequisites.append(pfCand)
301  #
302  # Softkiller
303  #
304  elif recoJetInfo.jetPUMethod == "sk":
305  self.addProcessAndTask(proc, pfCand, softKiller.clone(
306  PFCandidates = self.pfLabel,
307  rParam = recoJetInfo.jetSizeNr,
308  )
309  )
310  self.prerequisites.append(pfCand)
311  else:
312  raise RuntimeError("Currently unsupported PU method: '%s'" % recoJetInfo.jetPUMethod)
313 
314  #============================================
315  #
316  # Create the recojet collection
317  #
318  #============================================
319  if not recoJetInfo.doCalo:
320  jetCollection = '{}Collection'.format(jetUpper)
321 
322  if jetCollection in self.main:
323  raise ValueError("Step '%s' already implemented" % jetCollection)
324  #
325  # Cluster new jet
326  #
327  if recoJetInfo.jetPUMethod == "chs":
328  self.addProcessAndTask(proc, jetCollection, ak4PFJetsCHS.clone(
329  src = pfCand,
330  )
331  )
332  elif recoJetInfo.jetPUMethod == "puppi":
333  self.addProcessAndTask(proc, jetCollection, ak4PFJetsPuppi.clone(
334  src = self.pfLabel,
335  srcWeights = pfCand
336  )
337  )
338  elif recoJetInfo.jetPUMethod == "sk":
339  self.addProcessAndTask(proc, pfCand, ak4PFJetsSK.clone(
340  src = pfCand,
341  )
342  )
343  elif recoJetInfo.jetPUMethod == "cs":
344  self.addProcessAndTask(proc, jetCollection, ak4PFJetsCS.clone(
345  src = pfCand,
346  )
347  )
348  else:
349  self.addProcessAndTask(proc, jetCollection, ak4PFJets.clone(
350  src = pfCand,
351  )
352  )
353  getattr(proc, jetCollection).jetAlgorithm = supportedJetAlgos[recoJetInfo.jetAlgo]
354  getattr(proc, jetCollection).rParam = recoJetInfo.jetSizeNr
355  #
356  # Set minimum pt threshold of reco jets to be saved after fastjet clustering
357  #
358  if minPtFastjet != None:
359  getattr(proc, jetCollection).jetPtMin = minPtFastjet
360  currentTasks.append(jetCollection)
361  else:
362  jetCollection = inputCollection
363 
364 
365  #=============================================
366  #
367  # Make patJet collection
368  #
369  #=============================================
370  #
371  # Jet correction
372  #
373  if recoJetInfo.jetPUMethod == "puppi":
374  jetCorrLabel = "Puppi"
375  elif recoJetInfo.jetPUMethod in [ "cs", "sk" ]:
376  jetCorrLabel = "chs"
377  else:
378  jetCorrLabel = recoJetInfo.jetPUMethod
379 
380  jetCorrections = (
381  "{}{}{}{}".format(
382  recoJetInfo.jetAlgo.upper(),
383  recoJetInfo.jetSize,
384  "Calo" if recoJetInfo.doCalo else recoJetInfo.jetReco.upper(),
385  jetCorrLabel
386  ),
387  JETCorrLevels,
388  "None",
389  )
390 
391  postfix = "Recluster" if inputCollection == "" else ""
392  addJetCollection(
393  proc,
394  labelName = jetUpper,
395  postfix = postfix,
396  jetSource = cms.InputTag(jetCollection),
397  algo = recoJetInfo.jetAlgo,
398  rParam = recoJetInfo.jetSizeNr,
399  pvSource = cms.InputTag(self.pvLabel),
400  pfCandidates = cms.InputTag(self.pfLabel),
401  svSource = cms.InputTag(self.svLabel),
402  muSource = cms.InputTag(self.muLabel),
403  elSource = cms.InputTag(self.elLabel),
404  genJetCollection = cms.InputTag(genJetsCollection),
405  genParticles = cms.InputTag(self.gpLabel),
406  jetCorrections = jetCorrections,
407  )
408 
409  #
410  # Need to set this explicitly for PUPPI jets
411  #
412  if recoJetInfo.jetPUMethod == "puppi":
413  getattr(proc, "patJetFlavourAssociation{}{}".format(jetUpper,postfix)).weights = cms.InputTag(pfCand)
414 
415  getJetMCFlavour = not recoJetInfo.doCalo and recoJetInfo.jetPUMethod != "cs"
416  if not self.runOnMC: #Remove modules for Gen-level object matching
417  delattr(proc, 'patJetGenJetMatch{}{}'.format(jetUpper,postfix))
418  delattr(proc, 'patJetPartonMatch{}{}'.format(jetUpper,postfix))
419  getJetMCFlavour = False
420  setattr(getattr(proc, "patJets{}{}".format(jetUpper,postfix)), "getJetMCFlavour", cms.bool(getJetMCFlavour))
421 
422  selectedPatJets = "selectedPatJets{}{}".format(jetUpper,postfix)
423  #=============================================
424  #
425  # Update the patJet collection.
426  # This is where we setup
427  # - JEC
428  # - b-tagging discriminators
429  #
430  #=============================================
431  updateJetCollection(
432  proc,
433  labelName = jetUpper,
434  postfix = "Final",
435  jetSource = cms.InputTag(selectedPatJets),
436  jetCorrections = jetCorrections,
437  btagDiscriminators = bTagDiscriminators,
438  )
439 
440  recoJetInfo.patJetFinalCollection = "selectedUpdatedPatJets{}{}".format(jetUpper,"Final")
441  else:
442  recoJetInfo.patJetFinalCollection = inputCollection
443 
444  self.main.extend(currentTasks)
445 
446  return recoJetInfo

References jetCollectionTools.GenJetAdder.addProcessAndTask(), jetCollectionTools.RecoJetAdder.addProcessAndTask(), mps_setup.append, cms::cuda.assert(), 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, print(), jetCollectionTools.RecoJetAdder.pvLabel, jetCollectionTools.RecoJetAdder.runOnMC, and jetCollectionTools.RecoJetAdder.svLabel.

Member Data Documentation

◆ elLabel

jetCollectionTools.RecoJetAdder.elLabel

◆ gpLabel

jetCollectionTools.RecoJetAdder.gpLabel

◆ main

jetCollectionTools.RecoJetAdder.main

◆ muLabel

jetCollectionTools.RecoJetAdder.muLabel

◆ patJetsInMiniAOD

jetCollectionTools.RecoJetAdder.patJetsInMiniAOD

◆ pfLabel

jetCollectionTools.RecoJetAdder.pfLabel

◆ prerequisites

jetCollectionTools.RecoJetAdder.prerequisites

◆ pvLabel

jetCollectionTools.RecoJetAdder.pvLabel

◆ runOnMC

jetCollectionTools.RecoJetAdder.runOnMC

◆ svLabel

jetCollectionTools.RecoJetAdder.svLabel
helpers.getPatAlgosToolsTask
def getPatAlgosToolsTask(process)
Definition: helpers.py:14
cms::cuda::assert
assert(be >=bs)
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
mps_setup.append
append
Definition: mps_setup.py:85
format
helpers.addToProcessAndTask
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:29