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 addRecoJetCollection (self, proc, jet, inputCollection="", genJetsCollection="", minPt=5., bTagDiscriminators=None, JETCorrLevels=None)
 
def getSequence (self, proc)
 

Public Attributes

 bTagDiscriminators
 
 elLabel
 
 gpLabel
 
 JETCorrLevels
 
 main
 
 muLabel
 
 pfLabel
 
 prerequisites
 
 pvLabel
 
 runOnMC
 
 svLabel
 

Detailed Description

Tool to schedule modules for building a recojet collection with input MiniAODs

Definition at line 204 of file jetCollectionTools.py.

Constructor & Destructor Documentation

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

Definition at line 208 of file jetCollectionTools.py.

208  def __init__(self,runOnMC=True):
209  self.prerequisites = []
210  self.main = []
211  self.bTagDiscriminators = ["None"] # No b-tagging by default
212  self.JETCorrLevels = [ "L1FastJet", "L2Relative", "L3Absolute" ]
213  self.pfLabel = "packedPFCandidates"
214  self.pvLabel = "offlineSlimmedPrimaryVertices"
215  self.svLabel = "slimmedSecondaryVertices"
216  self.muLabel = "slimmedMuons"
217  self.elLabel = "slimmedElectrons"
218  self.gpLabel = "prunedGenParticles"
219  self.runOnMC = runOnMC
220 
def __init__(self, runOnMC=True)

Member Function Documentation

def jetCollectionTools.RecoJetAdder.addRecoJetCollection (   self,
  proc,
  jet,
  inputCollection = "",
  genJetsCollection = "",
  minPt = 5.,
  bTagDiscriminators = None,
  JETCorrLevels = None 
)

Definition at line 240 of file jetCollectionTools.py.

References jetCollectionTools.RecoJetAdder.bTagDiscriminators, jetCollectionTools.RecoJetAdder.elLabel, jetCollectionTools.GenJetAdder.gpLabel, jetCollectionTools.RecoJetAdder.gpLabel, jetCollectionTools.RecoJetAdder.JETCorrLevels, jetCollectionTools.GenJetAdder.main, custom_jme_cff.TableGenJetAdder.main, jetCollectionTools.RecoJetAdder.main, custom_jme_cff.TableRecoJetAdder.main, jetCollectionTools.RecoJetAdder.muLabel, 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.getSequence().

240  ):
241  print("jetCollectionTools::RecoJetAdder::addRecoJetCollection: Adding Reco Jet Collection: {}".format(jet))
242 
243  currentTasks = []
244 
245  if inputCollection and inputCollection not in [
246  "slimmedJets", "slimmedJetsAK8", "slimmedJetsPuppi", "slimmedCaloJets",
247  ]:
248  raise RuntimeError("Invalid input collection: %s" % inputCollection)
249 
250  if bTagDiscriminators is None:
251  bTagDiscriminators = self.bTagDiscriminators
252 
253  if JETCorrLevels is None:
254  JETCorrLevels = self.JETCorrLevels
255 
256  #
257  # Decide which jet collection we're dealing with
258  #
259  recoJetInfo = RecoJetInfo(jet, inputCollection)
260  jetLower = recoJetInfo.jetLower
261  jetUpper = recoJetInfo.jetUpper
262  tagName = recoJetInfo.jetTagName
263 
264  if inputCollection == "slimmedJets":
265  assert(jetLower == "ak4pfchs")
266  elif inputCollection == "slimmedJetsAK8":
267  assert(jetLower == "ak8pfpuppi")
268  elif inputCollection == "slimmedJetsPuppi":
269  assert(jetLower == "ak4pfpuppi")
270  elif inputCollection == "slimmedCaloJets":
271  assert(jetLower == "ak4calo")
272 
273  #=======================================================
274  #
275  # If jet collection in MiniAOD is not
276  # specified, build the jet collection.
277  #
278  #========================================================
279  if not inputCollection or recoJetInfo.doCalo:
280  print("jetCollectionTools::RecoJetAdder::addRecoJetCollection: inputCollection not specified. Building recojet collection now")
281 
282  #=======================================================
283  #
284  # Prepare the inputs to jet clustering
285  #
286  #========================================================
287  #
288  # Set up PF candidates
289  #
290  pfCand = self.pfLabel
291  #
292  # Setup PU method for PF candidates
293  #
294  if recoJetInfo.jetPUMethod not in [ "", "cs" ]:
295  pfCand += recoJetInfo.jetPUMethod
296  #
297  #
298  #
299  if pfCand not in self.prerequisites:
300  #
301  # Skip if no PU Method or CS specified
302  #
303  if recoJetInfo.jetPUMethod in [ "", "cs" ]:
304  pass
305  #
306  # CHS
307  #
308  elif recoJetInfo.jetPUMethod == "chs":
309  setattr(proc, pfCand,
310  cms.EDFilter("CandPtrSelector",
311  src = cms.InputTag(self.pfLabel),
312  cut = cms.string("fromPV"),
313  )
314  )
315  self.prerequisites.append(pfCand)
316  #
317  # PUPPI
318  #
319  elif recoJetInfo.jetPUMethod == "puppi":
320  setattr(proc, pfCand,
321  puppi.clone(
322  candName = self.pfLabel,
323  vertexName = self.pvLabel,
324  )
325  )
326  self.prerequisites.append(pfCand)
327  #
328  # Softkiller
329  #
330  elif recoJetInfo.jetPUMethod == "sk":
331  setattr(proc, pfCand,
332  softKiller.clone(
333  PFCandidates = self.pfLabel,
334  rParam = recoJetInfo.jetSizeNr,
335  )
336  )
337  self.prerequisites.append(pfCand)
338  else:
339  raise RuntimeError("Currently unsupported PU method: '%s'" % recoJetInfo.jetPUMethod)
340 
341  #============================================
342  #
343  # Create the recojet collection
344  #
345  #============================================
346  if not recoJetInfo.doCalo:
347  jetCollection = '{}Collection'.format(tagName)
348 
349  if jetCollection in self.main:
350  raise ValueError("Step '%s' already implemented" % jetCollection)
351 
352  setattr(proc, jetCollection, ak4PFJetsCS.clone(
353  src = pfCand,
354  doAreaFastjet = True,
355  jetPtMin = minPt,
356  jetAlgorithm = supportedJetAlgos[recoJetInfo.jetAlgo],
357  rParam = recoJetInfo.jetSizeNr,
358  useConstituentSubtraction = recoJetInfo.doCS,
359  csRParam = 0.4 if recoJetInfo.doCS else -1.,
360  csRho_EtaMax = PFJetParameters.Rho_EtaMax if recoJetInfo.doCS else -1.,
361  useExplicitGhosts = recoJetInfo.doCS or recoJetInfo.jetPUMethod == "sk",
362  )
363  )
364  currentTasks.append(jetCollection)
365  else:
366  jetCollection = inputCollection
367 
368  #
369  # PATify
370  #
371  if recoJetInfo.jetPUMethod == "puppi":
372  jetCorrLabel = "Puppi"
373  elif recoJetInfo.jetPUMethod in [ "cs", "sk" ]:
374  jetCorrLabel = "chs"
375  else:
376  jetCorrLabel = recoJetInfo.jetPUMethod
377 
378  #
379  # Jet correction
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  addJetCollection(
393  proc,
394  labelName = tagName,
395  jetSource = cms.InputTag(jetCollection),
396  algo = recoJetInfo.jetAlgo,
397  rParam = recoJetInfo.jetSizeNr,
398  pvSource = cms.InputTag(self.pvLabel),
399  pfCandidates = cms.InputTag(self.pfLabel),
400  svSource = cms.InputTag(self.svLabel),
401  muSource = cms.InputTag(self.muLabel),
402  elSource = cms.InputTag(self.elLabel),
403  btagDiscriminators = bTagDiscriminators if not recoJetInfo.doCalo else [ "None" ],
404  jetCorrections = jetCorrections,
405  genJetCollection = cms.InputTag(genJetsCollection),
406  genParticles = cms.InputTag(self.gpLabel),
407  )
408 
409  getJetMCFlavour = not recoJetInfo.doCalo and recoJetInfo.jetPUMethod != "cs"
410 
411  if not self.runOnMC: #Remove modules for Gen-level object matching
412  delattr(proc, 'patJetGenJetMatch{}'.format(tagName))
413  delattr(proc, 'patJetPartonMatch{}'.format(tagName))
414  getJetMCFlavour = False
415 
416  setattr(getattr(proc, "patJets{}".format(tagName)), "getJetMCFlavour", cms.bool(getJetMCFlavour))
417  setattr(getattr(proc, "patJetCorrFactors{}".format(tagName)), "payload", cms.string(recoJetInfo.jetCorrPayload))
418  selJet = "selectedPatJets{}".format(tagName)
419  else:
420  selJet = inputCollection
421 
422  if not recoJetInfo.skipUserData:
423  #
424  #
425  #
426  jercVar = "jercVars{}".format(tagName)
427  if jercVar in self.main:
428  raise ValueError("Step '%s' already implemented" % jercVar)
429  setattr(proc, jercVar, proc.jercVars.clone(srcJet = selJet))
430  currentTasks.append(jercVar)
431  #
432  # JetID Loose
433  #
434  looseJetId = "looseJetId{}".format(tagName)
435  if looseJetId in self.main:
436  raise ValueError("Step '%s' already implemented" % looseJetId)
437  setattr(proc, looseJetId, proc.looseJetId.clone(
438  src = selJet,
439  filterParams=proc.looseJetId.filterParams.clone(
440  version ="WINTER16"
441  ),
442  )
443  )
444  currentTasks.append(looseJetId)
445  #
446  # JetID Tight
447  #
448  tightJetId = "tightJetId{}".format(tagName)
449  if tightJetId in self.main:
450  raise ValueError("Step '%s' already implemented" % tightJetId)
451  setattr(proc, tightJetId, proc.tightJetId.clone(
452  src = selJet,
453  filterParams=proc.tightJetId.filterParams.clone(
454  version = "SUMMER18{}".format("PUPPI" if recoJetInfo.jetPUMethod == "puppi" else "")
455  ),
456  )
457  )
458  tightJetIdObj = getattr(proc, tightJetId)
459  run2_jme_2016.toModify(
460  tightJetIdObj.filterParams,
461  version = "WINTER16"
462  )
463  run2_jme_2017.toModify(
464  tightJetIdObj.filterParams,
465  version = 'WINTER17{}'.format("PUPPI" if recoJetInfo.jetPUMethod == "puppi" else "")
466  )
467  currentTasks.append(tightJetId)
468  #
469  # JetID TightLepVeto
470  #
471  tightJetIdLepVeto = "tightJetIdLepVeto{}".format(tagName)
472  if tightJetIdLepVeto in self.main:
473  raise ValueError("Step '%s' already implemented" % tightJetIdLepVeto)
474  setattr(proc, tightJetIdLepVeto, proc.tightJetIdLepVeto.clone(
475  src = selJet,
476  filterParams=proc.tightJetIdLepVeto.filterParams.clone(
477  version = "SUMMER18{}".format("PUPPI" if recoJetInfo.jetPUMethod == "puppi" else "")
478  ),
479  )
480  )
481  tightJetIdLepVetoObj = getattr(proc, tightJetIdLepVeto)
482  run2_jme_2016.toModify(
483  tightJetIdLepVetoObj.filterParams,
484  version = "WINTER16"
485  )
486  run2_jme_2017.toModify(
487  tightJetIdLepVetoObj.filterParams,
488  version = 'WINTER17{}'.format("PUPPI" if recoJetInfo.jetPUMethod == "puppi" else ""),
489  )
490  currentTasks.append(tightJetIdLepVeto)
491  #
492  #
493  #
494  selectedPatJetsWithUserData = "{}WithUserData".format(selJet)
495  if selectedPatJetsWithUserData in self.main:
496  raise ValueError("Step '%s' already implemented" % selectedPatJetsWithUserData)
497  setattr(proc, selectedPatJetsWithUserData,
498  cms.EDProducer("PATJetUserDataEmbedder",
499  src = cms.InputTag(selJet),
500  userFloats = cms.PSet(
501  jercCHPUF = cms.InputTag("{}:chargedHadronPUEnergyFraction".format(jercVar)),
502  jercCHF = cms.InputTag("{}:chargedHadronCHSEnergyFraction".format(jercVar)),
503  ),
504  userInts = cms.PSet(
505  tightId = cms.InputTag(tightJetId),
506  tightIdLepVeto = cms.InputTag(tightJetIdLepVeto),
507  ),
508  )
509  )
510  selectedPatJetsWithUserDataObj = getattr(proc, selectedPatJetsWithUserData)
511  run2_jme_2016.toModify(selectedPatJetsWithUserDataObj.userInts,
512  looseId = cms.InputTag(looseJetId),
513  )
514  currentTasks.append(selectedPatJetsWithUserData)
515  else:
516  selectedPatJetsWithUserData = "selectedPatJets{}".format(tagName)
517 
518  #
519  # Not sure why we can't re-use patJetCorrFactors* created by addJetCollection()
520  # (even cloning doesn't work) Let's just create our own
521  #
522  jetCorrFactors = "jetCorrFactors{}".format(tagName)
523  if jetCorrFactors in self.main:
524  raise ValueError("Step '%s' already implemented" % jetCorrFactors)
525 
526  setattr(proc, jetCorrFactors, patJetCorrFactors.clone(
527  src = selectedPatJetsWithUserData,
528  levels = JETCorrLevels,
529  primaryVertices = self.pvLabel,
530  payload = recoJetInfo.jetCorrPayload,
531  rho = "fixedGridRhoFastjetAll{}".format("Calo" if recoJetInfo.doCalo else ""),
532  )
533  )
534  currentTasks.append(jetCorrFactors)
535 
536  updatedJets = "updatedJets{}".format(tagName)
537  if updatedJets in self.main:
538  raise ValueError("Step '%s' already implemented" % updatedJets)
539 
540  setattr(proc, updatedJets, updatedPatJets.clone(
541  addBTagInfo = False,
542  jetSource = selectedPatJetsWithUserData,
543  jetCorrFactorsSource = [jetCorrFactors],
544  )
545  )
546  currentTasks.append(updatedJets)
547 
548  self.main.extend(currentTasks)
549 
550  return recoJetInfo
def jetCollectionTools.RecoJetAdder.getSequence (   self,
  proc 
)

Definition at line 221 of file jetCollectionTools.py.

References jetCollectionTools.RecoJetAdder.addRecoJetCollection(), jetCollectionTools.GenJetAdder.main, custom_jme_cff.TableGenJetAdder.main, jetCollectionTools.RecoJetAdder.main, custom_jme_cff.TableRecoJetAdder.main, jetCollectionTools.GenJetAdder.prerequisites, and jetCollectionTools.RecoJetAdder.prerequisites.

221  def getSequence(self, proc):
222  tasks = self.prerequisites + self.main
223 
224  resultSequence = cms.Sequence()
225  for idx, task in enumerate(tasks):
226  if idx == 0:
227  resultSequence = cms.Sequence(getattr(proc, task))
228  else:
229  resultSequence.insert(idx, getattr(proc, task))
230  return resultSequence
231 

Member Data Documentation

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