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 193 of file jetCollectionTools.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 197 of file jetCollectionTools.py.

197  def __init__(self,runOnMC=True):
198  self.prerequisites = []
199  self.main = []
200  self.pfLabel = "packedPFCandidates"
201  self.pvLabel = "offlineSlimmedPrimaryVertices"
202  self.svLabel = "slimmedSecondaryVertices"
203  self.muLabel = "slimmedMuons"
204  self.elLabel = "slimmedElectrons"
205  self.gpLabel = "prunedGenParticles"
206  self.runOnMC = runOnMC
207  self.patJetsInMiniAOD = ["slimmedJets", "slimmedJetsAK8", "slimmedJetsPuppi", "slimmedCaloJets"]
208 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ addProcessAndTask()

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

Definition at line 209 of file jetCollectionTools.py.

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

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

209  def addProcessAndTask(self, proc, label, module):
210  task = getPatAlgosToolsTask(proc)
211  addToProcessAndTask(label, module, proc, task)
212 
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def getPatAlgosToolsTask(process)
Definition: helpers.py:13

◆ addRecoJetCollection()

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

Definition at line 221 of file jetCollectionTools.py.

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, jetTools.setupPuppiForPackedPF(), and jetCollectionTools.RecoJetAdder.svLabel.

Referenced by jetCollectionTools.RecoJetAdder.addProcessAndTask().

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

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