CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
jetCollectionTools.RecoJetAdder Class Reference
Inheritance diagram for jetCollectionTools.RecoJetAdder:

Public Member Functions

def __init__
 
def addProcessAndTask
 
def addRecoJetCollection
 

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

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

Definition at line 195 of file jetCollectionTools.py.

196  def __init__(self,runOnMC=True):
197  self.prerequisites = []
198  self.main = []
199  self.pfLabel = "packedPFCandidates"
200  self.pvLabel = "offlineSlimmedPrimaryVertices"
201  self.svLabel = "slimmedSecondaryVertices"
202  self.muLabel = "slimmedMuons"
203  self.elLabel = "slimmedElectrons"
204  self.gpLabel = "prunedGenParticles"
205  self.runOnMC = runOnMC
206  self.patJetsInMiniAOD = ["slimmedJets", "slimmedJetsAK8", "slimmedJetsPuppi", "slimmedCaloJets"]

Member Function Documentation

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

Definition at line 207 of file jetCollectionTools.py.

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

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

208  def addProcessAndTask(self, proc, label, module):
209  task = getPatAlgosToolsTask(proc)
210  addToProcessAndTask(label, module, proc, task)
def getPatAlgosToolsTask
Definition: helpers.py:13
def addToProcessAndTask
Definition: helpers.py:28
def jetCollectionTools.RecoJetAdder.addRecoJetCollection (   self,
  proc,
  jet,
  inputCollection = "",
  minPtFastjet = None,
  genJetsCollection = "",
  bTagDiscriminators = ["None"],
  JETCorrLevels = ["L1FastJet",
  L2Relative,
  L3Absolute,
  L2L3Residual 
)

Definition at line 219 of file jetCollectionTools.py.

References jetCollectionTools.GenJetAdder.addProcessAndTask(), jetCollectionTools.RecoJetAdder.addProcessAndTask(), 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.

Referenced by jetCollectionTools.RecoJetAdder.addProcessAndTask().

220  ):
221  print("jetCollectionTools::RecoJetAdder::addRecoJetCollection: Adding Reco Jet Collection: {}".format(jet))
222 
223  currentTasks = []
224 
225  if inputCollection and inputCollection not in self.patJetsInMiniAOD:
226  raise RuntimeError("Invalid input collection: %s" % inputCollection)
227 
228  #=======================================================
229  #
230  # Figure out which jet collection we're dealing with
231  #
232  #=======================================================
233  recoJetInfo = RecoJetInfo(jet, inputCollection)
234  jetLower = recoJetInfo.jetLower
235  jetUpper = recoJetInfo.jetUpper
236  tagName = recoJetInfo.jetTagName
237 
238  if inputCollection == "slimmedJets":
239  assert(jetLower == "ak4pfchs")
240  elif inputCollection == "slimmedJetsAK8":
241  assert(jetLower == "ak8pfpuppi")
242  elif inputCollection == "slimmedJetsPuppi":
243  assert(jetLower == "ak4pfpuppi")
244  elif inputCollection == "slimmedCaloJets":
245  assert(jetLower == "ak4calo")
246 
247  #=======================================================
248  #
249  # If the patJet collection in MiniAOD is not specified,
250  # we have to build the patJet collection from scratch.
251  #
252  #========================================================
253  if not inputCollection or recoJetInfo.doCalo:
254  print("jetCollectionTools::RecoJetAdder::addRecoJetCollection: inputCollection not specified. Building recojet collection now")
255 
256  #=======================================================
257  #
258  # Prepare the inputs to jet clustering
259  #
260  #========================================================
261  #
262  # Specify PF candidates
263  #
264  pfCand = self.pfLabel
265  #
266  # Setup PU method for PF candidates
267  #
268  if recoJetInfo.jetPUMethod not in [ "", "cs" ]:
269  pfCand += recoJetInfo.jetPUMethod
270 
271 
272  #
273  # Setup modules to perform PU mitigation for
274  # PF candidates
275  #
276  if pfCand not in self.prerequisites:
277  #
278  # Skip if no PU Method or CS specified
279  #
280  if recoJetInfo.jetPUMethod in [ "", "cs" ]:
281  pass
282  #
283  # CHS
284  #
285  elif recoJetInfo.jetPUMethod == "chs":
286  from CommonTools.ParticleFlow.pfCHS_cff import pfCHS, packedPrimaryVertexAssociationJME
287  self.addProcessAndTask(proc, "packedPrimaryVertexAssociationJME", packedPrimaryVertexAssociationJME.clone())
288  self.prerequisites.append("packedPrimaryVertexAssociationJME")
289  self.addProcessAndTask(proc, pfCand, pfCHS.clone())
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 
return recoJetInfo
assert(be >=bs)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

Member Data Documentation

jetCollectionTools.RecoJetAdder.elLabel

Definition at line 202 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.gpLabel

Definition at line 203 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.main

Definition at line 197 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.muLabel

Definition at line 201 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.patJetsInMiniAOD

Definition at line 205 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.pfLabel

Definition at line 198 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.prerequisites

Definition at line 196 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.pvLabel

Definition at line 199 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.runOnMC

Definition at line 204 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().

jetCollectionTools.RecoJetAdder.svLabel

Definition at line 200 of file jetCollectionTools.py.

Referenced by jetCollectionTools.RecoJetAdder.addRecoJetCollection().