CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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

◆ __init__()

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 

Member Function Documentation

◆ addRecoJetCollection()

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

Definition at line 232 of file jetCollectionTools.py.

232  def addRecoJetCollection(self,
233  proc,
234  jet,
235  inputCollection = "",
236  genJetsCollection = "",
237  minPt = 5.,
238  bTagDiscriminators = None,
239  JETCorrLevels = None,
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  if recoJetInfo.jetPUMethod == "puppi":
365  _jets = getattr(proc, jetCollection)
366  _jets.src = self.pfLabel
367  _jets.srcWeights = pfCand
368  _jets.applyWeights = True
369  currentTasks.append(jetCollection)
370  else:
371  jetCollection = inputCollection
372 
373  #
374  # PATify
375  #
376  if recoJetInfo.jetPUMethod == "puppi":
377  jetCorrLabel = "Puppi"
378  elif recoJetInfo.jetPUMethod in [ "cs", "sk" ]:
379  jetCorrLabel = "chs"
380  else:
381  jetCorrLabel = recoJetInfo.jetPUMethod
382 
383  #
384  # Jet correction
385  #
386  jetCorrections = (
387  "{}{}{}{}".format(
388  recoJetInfo.jetAlgo.upper(),
389  recoJetInfo.jetSize,
390  "Calo" if recoJetInfo.doCalo else recoJetInfo.jetReco.upper(),
391  jetCorrLabel
392  ),
393  JETCorrLevels,
394  "None",
395  )
396 
397  addJetCollection(
398  proc,
399  labelName = tagName,
400  jetSource = cms.InputTag(jetCollection),
401  algo = recoJetInfo.jetAlgo,
402  rParam = recoJetInfo.jetSizeNr,
403  pvSource = cms.InputTag(self.pvLabel),
404  pfCandidates = cms.InputTag(self.pfLabel),
405  svSource = cms.InputTag(self.svLabel),
406  muSource = cms.InputTag(self.muLabel),
407  elSource = cms.InputTag(self.elLabel),
408  btagDiscriminators = bTagDiscriminators if not recoJetInfo.doCalo else [ "None" ],
409  jetCorrections = jetCorrections,
410  genJetCollection = cms.InputTag(genJetsCollection),
411  genParticles = cms.InputTag(self.gpLabel),
412  )
413 
414  getJetMCFlavour = not recoJetInfo.doCalo and recoJetInfo.jetPUMethod != "cs"
415 
416  if not self.runOnMC: #Remove modules for Gen-level object matching
417  delattr(proc, 'patJetGenJetMatch{}'.format(tagName))
418  delattr(proc, 'patJetPartonMatch{}'.format(tagName))
419  getJetMCFlavour = False
420 
421  setattr(getattr(proc, "patJets{}".format(tagName)), "getJetMCFlavour", cms.bool(getJetMCFlavour))
422  setattr(getattr(proc, "patJetCorrFactors{}".format(tagName)), "payload", cms.string(recoJetInfo.jetCorrPayload))
423  selJet = "selectedPatJets{}".format(tagName)
424  else:
425  selJet = inputCollection
426 
427  if not recoJetInfo.skipUserData:
428  #
429  #
430  #
431  jercVar = "jercVars{}".format(tagName)
432  if jercVar in self.main:
433  raise ValueError("Step '%s' already implemented" % jercVar)
434  setattr(proc, jercVar, proc.jercVars.clone(srcJet = selJet))
435  currentTasks.append(jercVar)
436  #
437  # JetID Loose
438  #
439  looseJetId = "looseJetId{}".format(tagName)
440  if looseJetId in self.main:
441  raise ValueError("Step '%s' already implemented" % looseJetId)
442  setattr(proc, looseJetId, proc.looseJetId.clone(
443  src = selJet,
444  filterParams=proc.looseJetId.filterParams.clone(
445  version ="WINTER16"
446  ),
447  )
448  )
449  currentTasks.append(looseJetId)
450  #
451  # JetID Tight
452  #
453  tightJetId = "tightJetId{}".format(tagName)
454  if tightJetId in self.main:
455  raise ValueError("Step '%s' already implemented" % tightJetId)
456  setattr(proc, tightJetId, proc.tightJetId.clone(
457  src = selJet,
458  filterParams=proc.tightJetId.filterParams.clone(
459  version = "SUMMER18{}".format("PUPPI" if recoJetInfo.jetPUMethod == "puppi" else "")
460  ),
461  )
462  )
463  tightJetIdObj = getattr(proc, tightJetId)
464  run2_jme_2016.toModify(
465  tightJetIdObj.filterParams,
466  version = "WINTER16"
467  )
468  run2_jme_2017.toModify(
469  tightJetIdObj.filterParams,
470  version = 'WINTER17{}'.format("PUPPI" if recoJetInfo.jetPUMethod == "puppi" else "")
471  )
472  currentTasks.append(tightJetId)
473  #
474  # JetID TightLepVeto
475  #
476  tightJetIdLepVeto = "tightJetIdLepVeto{}".format(tagName)
477  if tightJetIdLepVeto in self.main:
478  raise ValueError("Step '%s' already implemented" % tightJetIdLepVeto)
479  setattr(proc, tightJetIdLepVeto, proc.tightJetIdLepVeto.clone(
480  src = selJet,
481  filterParams=proc.tightJetIdLepVeto.filterParams.clone(
482  version = "SUMMER18{}".format("PUPPI" if recoJetInfo.jetPUMethod == "puppi" else "")
483  ),
484  )
485  )
486  tightJetIdLepVetoObj = getattr(proc, tightJetIdLepVeto)
487  run2_jme_2016.toModify(
488  tightJetIdLepVetoObj.filterParams,
489  version = "WINTER16"
490  )
491  run2_jme_2017.toModify(
492  tightJetIdLepVetoObj.filterParams,
493  version = 'WINTER17{}'.format("PUPPI" if recoJetInfo.jetPUMethod == "puppi" else ""),
494  )
495  currentTasks.append(tightJetIdLepVeto)
496  #
497  #
498  #
499  selectedPatJetsWithUserData = "{}WithUserData".format(selJet)
500  if selectedPatJetsWithUserData in self.main:
501  raise ValueError("Step '%s' already implemented" % selectedPatJetsWithUserData)
502  setattr(proc, selectedPatJetsWithUserData,
503  cms.EDProducer("PATJetUserDataEmbedder",
504  src = cms.InputTag(selJet),
505  userFloats = cms.PSet(
506  chFPV0EF = cms.InputTag("{}:chargedFromPV0EnergyFraction".format(jercVar)),
507  chFPV1EF = cms.InputTag("{}:chargedFromPV1EnergyFraction".format(jercVar)),
508  chFPV2EF = cms.InputTag("{}:chargedFromPV2EnergyFraction".format(jercVar)),
509  chFPV3EF = cms.InputTag("{}:chargedFromPV3EnergyFraction".format(jercVar)),
510  ),
511  userInts = cms.PSet(
512  tightId = cms.InputTag(tightJetId),
513  tightIdLepVeto = cms.InputTag(tightJetIdLepVeto),
514  ),
515  )
516  )
517  selectedPatJetsWithUserDataObj = getattr(proc, selectedPatJetsWithUserData)
518  run2_jme_2016.toModify(selectedPatJetsWithUserDataObj.userInts,
519  looseId = cms.InputTag(looseJetId),
520  )
521  currentTasks.append(selectedPatJetsWithUserData)
522  else:
523  selectedPatJetsWithUserData = "selectedPatJets{}".format(tagName)
524 
525  #
526  # Not sure why we can't re-use patJetCorrFactors* created by addJetCollection()
527  # (even cloning doesn't work) Let's just create our own
528  #
529  jetCorrFactors = "jetCorrFactors{}".format(tagName)
530  if jetCorrFactors in self.main:
531  raise ValueError("Step '%s' already implemented" % jetCorrFactors)
532 
533  setattr(proc, jetCorrFactors, patJetCorrFactors.clone(
534  src = selectedPatJetsWithUserData,
535  levels = JETCorrLevels,
536  primaryVertices = self.pvLabel,
537  payload = recoJetInfo.jetCorrPayload,
538  rho = "fixedGridRhoFastjetAll{}".format("Calo" if recoJetInfo.doCalo else ""),
539  )
540  )
541  currentTasks.append(jetCorrFactors)
542 
543  updatedJets = "updatedJets{}".format(tagName)
544  if updatedJets in self.main:
545  raise ValueError("Step '%s' already implemented" % updatedJets)
546 
547  setattr(proc, updatedJets, updatedPatJets.clone(
548  addBTagInfo = False,
549  jetSource = selectedPatJetsWithUserData,
550  jetCorrFactorsSource = [jetCorrFactors],
551  )
552  )
553  currentTasks.append(updatedJets)
554 
555  self.main.extend(currentTasks)
556 
557  return recoJetInfo

References mps_setup.append, cms::cuda.assert(), 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.

◆ getSequence()

def jetCollectionTools.RecoJetAdder.getSequence (   self,
  proc 
)

Definition at line 221 of file jetCollectionTools.py.

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 

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

Member Data Documentation

◆ bTagDiscriminators

jetCollectionTools.RecoJetAdder.bTagDiscriminators

◆ elLabel

jetCollectionTools.RecoJetAdder.elLabel

◆ gpLabel

jetCollectionTools.RecoJetAdder.gpLabel

◆ JETCorrLevels

jetCollectionTools.RecoJetAdder.JETCorrLevels

◆ main

jetCollectionTools.RecoJetAdder.main

◆ muLabel

jetCollectionTools.RecoJetAdder.muLabel

◆ pfLabel

jetCollectionTools.RecoJetAdder.pfLabel

◆ prerequisites

jetCollectionTools.RecoJetAdder.prerequisites

◆ pvLabel

jetCollectionTools.RecoJetAdder.pvLabel

◆ runOnMC

jetCollectionTools.RecoJetAdder.runOnMC

◆ svLabel

jetCollectionTools.RecoJetAdder.svLabel
cms::cuda::assert
assert(be >=bs)
trackselectionRefitting.getSequence
def getSequence(process, collection, saveCPU=False, TTRHBuilder="WithAngleAndTemplate", usePixelQualityFlag=None, openMassWindow=False, cosmicsDecoMode=False, cosmicsZeroTesla=True, momentumConstraint=None, cosmicTrackSplitting=False, isPVValidation=False, use_d0cut=True)
Definition: trackselectionRefitting.py:7
mps_setup.append
append
Definition: mps_setup.py:85
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
format