CMS 3D CMS Logo

Classes | Functions | Variables
jetTools Namespace Reference

Classes

class  AddJetCollection
 
class  AddJetID
 
class  SetTagInfos
 
class  SwitchJetCollection
 
class  UpdateJetCollection
 

Functions

def checkJetCorrectionsFormat (jetCorrections)
 
def deprecatedOptionOutputModule (obj)
 
def jetAlgo (algo)
 
def rerunningIVF ()
 
def rerunningIVFMiniAOD ()
 
def setupBTagging (process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, tightBTagNTkHits, loadStdRecoBTag, svClustering, fatJets, groomedFatJets, algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix)
 
def setupJetCorrections (process, knownModules, jetCorrections, jetSource, pvSource, patJets, labelName, postfix)
 
def setupSVClustering (btagInfo, svClustering, algo, rParam, fatJets=cms.InputTag(''), groomedFatJets=cms.InputTag(''))
 
def undefinedLabelName (obj)
 
def unsupportedJetAlgorithm (obj)
 

Variables

 supportedJetAlgos
 dictionary with supported jet clustering algorithms More...
 

Function Documentation

◆ checkJetCorrectionsFormat()

def jetTools.checkJetCorrectionsFormat (   jetCorrections)

Definition at line 18 of file jetTools.py.

18 def checkJetCorrectionsFormat(jetCorrections):
19 
20  if not isinstance(jetCorrections, type(('PAYLOAD-LABEL',['CORRECTION-LEVEL-A','CORRECTION-LEVEL-B'], 'MET-LABEL'))):
21  raise ValueError("In addJetCollection: 'jetCorrections' must be 'None' (as a python value w/o quotation marks), or of type ('PAYLOAD-LABEL', ['CORRECTION-LEVEL-A', \
22  'CORRECTION-LEVEL-B', ...], 'MET-LABEL'). Note that 'MET-LABEL' can be set to 'None' (as a string in quotation marks) in case you do not want to apply MET(Type1) \
23  corrections.")
24 
25 

Referenced by jetTools.AddJetCollection.toolCode(), and jetTools.UpdateJetCollection.toolCode().

◆ deprecatedOptionOutputModule()

def jetTools.deprecatedOptionOutputModule (   obj)

Definition at line 1917 of file jetTools.py.

1918  sys.stderr.write("-------------------------------------------------------\n")
1919  sys.stderr.write(" Error: the option 'outputModule' is not supported\n")
1920  sys.stderr.write(" anymore by:\n")
1921  sys.stderr.write(" " + obj._label + "\n")
1922  sys.stderr.write(" please use 'outputModules' now and specify the\n")
1923  sys.stderr.write(" names of all needed OutModules in there\n")
1924  sys.stderr.write(" (default: ['out'])\n")
1925  sys.stderr.write("-------------------------------------------------------\n")
1926  raise KeyError("Unsupported option 'outputModule' used in '"+obj._label+"'")
1927 

◆ jetAlgo()

def jetTools.jetAlgo (   algo)

Definition at line 3 of file jetTools.py.

3 def jetAlgo( algo ):
4 
5  # print 'PF2PAT: selecting jet algorithm ', algo
6 
7  if algo == 'IC5':
8  import RecoJets.JetProducers.ic5PFJets_cfi as jetConfig
9  jetAlgo = jetConfig.iterativeCone5PFJets.clone()
10  elif algo == 'AK4':
11  import RecoJets.JetProducers.ak4PFJets_cfi as jetConfig
12  jetAlgo = jetConfig.ak4PFJets.clone()
13  elif algo == 'AK7':
14  import RecoJets.JetProducers.ak4PFJets_cfi as jetConfig
15  jetAlgo = jetConfig.ak4PFJets.clone()
16  jetAlgo.rParam = cms.double(0.7)
17  jetAlgo.doAreaFastjet = cms.bool(False)
18 
19  jetAlgo.src = 'pfNoElectronJME'
20  jetAlgo.doPVCorrection = True
21  jetAlgo.srcPVs = cms.InputTag("goodOfflinePrimaryVertices")
22  return jetAlgo

◆ rerunningIVF()

def jetTools.rerunningIVF ( )

Definition at line 1944 of file jetTools.py.

1944 def rerunningIVF():
1945  sys.stderr.write("-------------------------------------------------------------------\n")
1946  sys.stderr.write(" Warning: You are attempting to remake the IVF secondary vertices\n")
1947  sys.stderr.write(" already produced by the standard reconstruction. This\n")
1948  sys.stderr.write(" option is not enabled by default so please use it only if\n")
1949  sys.stderr.write(" you know what you are doing.\n")
1950  sys.stderr.write("-------------------------------------------------------------------\n")
1951 

Referenced by setupBTagging().

◆ rerunningIVFMiniAOD()

def jetTools.rerunningIVFMiniAOD ( )

Definition at line 1952 of file jetTools.py.

1952 def rerunningIVFMiniAOD():
1953  sys.stderr.write("-------------------------------------------------------------------\n")
1954  sys.stderr.write(" Warning: You are attempting to remake IVF secondary vertices from\n")
1955  sys.stderr.write(" MiniAOD. If that was your intention, note that secondary\n")
1956  sys.stderr.write(" vertices remade from MiniAOD will have somewhat degraded\n")
1957  sys.stderr.write(" performance compared to those remade from RECO/AOD.\n")
1958  sys.stderr.write("-------------------------------------------------------------------\n")

Referenced by setupBTagging().

◆ setupBTagging()

def jetTools.setupBTagging (   process,
  jetSource,
  pfCandidates,
  explicitJTA,
  pvSource,
  svSource,
  elSource,
  muSource,
  runIVF,
  tightBTagNTkHits,
  loadStdRecoBTag,
  svClustering,
  fatJets,
  groomedFatJets,
  algo,
  rParam,
  btagDiscriminators,
  btagInfos,
  patJets,
  labelName,
  btagPrefix,
  postfix 
)

Definition at line 238 of file jetTools.py.

238 def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, tightBTagNTkHits, loadStdRecoBTag, svClustering, fatJets, groomedFatJets,
239  algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix):
240 
241  task = getPatAlgosToolsTask(process)
242 
243 
244  discriminators = set(btagDiscriminators)
245  present_meta = discriminators.intersection(set(supportedMetaDiscr.keys()))
246  discriminators -= present_meta
247  for meta_tagger in present_meta:
248  for src in supportedMetaDiscr[meta_tagger]:
249  discriminators.add(src)
250  btagDiscriminators = list(discriminators)
251 
252 
254  requiredTagInfos = list(btagInfos)
255  for btagDiscr in btagDiscriminators :
256  for tagInfoList in supportedBtagDiscr[btagDiscr] :
257  for requiredTagInfo in tagInfoList :
258  tagInfoCovered = False
259  for tagInfo in requiredTagInfos :
260  if requiredTagInfo == tagInfo :
261  tagInfoCovered = True
262  break
263  if not tagInfoCovered :
264  requiredTagInfos.append(requiredTagInfo)
265 
266  if hasattr( process, 'candidateJetProbabilityComputer' ) == False :
267  if loadStdRecoBTag: # also loading modules already run in the standard reconstruction
268  process.load("RecoBTag.ImpactParameter.impactParameter_cff")
269  task.add(process.impactParameterTask)
270  process.load("RecoBTag.SecondaryVertex.secondaryVertex_cff")
271  task.add(process.secondaryVertexTask)
272  process.load("RecoBTag.SoftLepton.softLepton_cff")
273  task.add(process.softLeptonTask)
274  process.load("RecoBTag.Combined.combinedMVA_cff")
275  task.add(process.combinedMVATask)
276  process.load("RecoBTag.CTagging.cTagging_cff")
277  task.add(process.cTaggingTask)
278  else: # to prevent loading of modules already run in the standard reconstruction
279  process.load("RecoBTag.ImpactParameter.impactParameter_EventSetup_cff")
280  process.load("RecoBTag.SecondaryVertex.secondaryVertex_EventSetup_cff")
281  process.load("RecoBTag.SoftLepton.softLepton_EventSetup_cff")
282  process.load("RecoBTag.Combined.combinedMVA_EventSetup_cff")
283  process.load("RecoBTag.CTagging.cTagging_EventSetup_cff")
285  import RecoJets.JetProducers.caTopTaggers_cff as toptag
286 
287  if tightBTagNTkHits:
288  if not runIVF:
289  sys.stderr.write("-------------------------------------------------------------------\n")
290  sys.stderr.write(" Warning: For a complete switch to the legacy tight b-tag track\n")
291  sys.stderr.write(" selection, please also enable the \'runIVF\' switch.\n")
292  sys.stderr.write("-------------------------------------------------------------------\n")
293  if btagPrefix == '':
294  sys.stderr.write("-------------------------------------------------------------------\n")
295  sys.stderr.write(" Warning: With the tight b-tag track selection enabled, it is\n")
296  sys.stderr.write(" advisable to set \'btagPrefix\' to a non-empty string to\n")
297  sys.stderr.write(" avoid unintentional modifications to the default\n")
298  sys.stderr.write(" b tagging setup that might be loaded in the same job.\n")
299  sys.stderr.write("-------------------------------------------------------------------\n")
300 
301 
303  svSourceCvsL = copy.deepcopy(svSource)
304  svSourceCvsL.setModuleLabel(svSource.getModuleLabel()+'CvsL')
305 
306 
307  runIVFforCTagOnly = False
308  ivfcTagInfos = ['pfInclusiveSecondaryVertexFinderCvsLTagInfos', 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos']
309 
310  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices' and any(i in requiredTagInfos for i in ivfcTagInfos) and not runIVF:
311  runIVFforCTagOnly = True
312  runIVF = True
313  sys.stderr.write("-------------------------------------------------------------------\n")
314  sys.stderr.write(" Info: To run c tagging on MiniAOD, c-tag-specific IVF secondary\n")
315  sys.stderr.write(" vertices will be remade.\n")
316  sys.stderr.write("-------------------------------------------------------------------\n")
317 
318  if runIVF and btagPrefix != '':
319  if runIVFforCTagOnly:
320  svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
321  else:
322  svSource.setModuleLabel(btagPrefix+svSource.getModuleLabel())
323  svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
324 
325 
328 
329  runNegativeVertexing = False
330  runNegativeCvsLVertexing = False
331  for btagInfo in requiredTagInfos:
332  if btagInfo in (
333  'pfInclusiveSecondaryVertexFinderNegativeTagInfos',
334  'pfNegativeDeepFlavourTagInfos',
335  'pfNegativeParticleNetAK4TagInfos',
336  ):
337  runNegativeVertexing = True
338  if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
339  runNegativeCvsLVertexing = True
340 
341  if runNegativeVertexing or runNegativeCvsLVertexing:
342  import RecoVertex.AdaptiveVertexFinder.inclusiveNegativeVertexing_cff as NegVertex
343 
344  if runNegativeVertexing:
345  addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeVertexFinder'+labelName+postfix,
346  NegVertex.inclusiveCandidateNegativeVertexFinder.clone(primaryVertices = pvSource,tracks=pfCandidates),
347  process, task)
348  addToProcessAndTask(btagPrefix+'candidateNegativeVertexMerger'+labelName+postfix,
349  NegVertex.candidateNegativeVertexMerger.clone(secondaryVertices = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeVertexFinder'+labelName+postfix)),
350  process, task)
351  addToProcessAndTask(btagPrefix+'candidateNegativeVertexArbitrator'+labelName+postfix,
352  NegVertex.candidateNegativeVertexArbitrator.clone( secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexMerger'+labelName+postfix)
353  ,primaryVertices = pvSource
354  ,tracks=pfCandidates),
355  process, task)
356  addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix,
357  NegVertex.inclusiveCandidateNegativeSecondaryVertices.clone(secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexArbitrator'+labelName+postfix)),
358  process, task)
359 
360  if runNegativeCvsLVertexing:
361  addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix,
362  NegVertex.inclusiveCandidateNegativeVertexFinderCvsL.clone(primaryVertices = pvSource,tracks=pfCandidates),
363  process, task)
364  addToProcessAndTask(btagPrefix+'candidateNegativeVertexMergerCvsL'+labelName+postfix,
365  NegVertex.candidateNegativeVertexMergerCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix)),
366  process, task)
367  addToProcessAndTask(btagPrefix+'candidateNegativeVertexArbitratorCvsL'+labelName+postfix,
368  NegVertex.candidateNegativeVertexArbitratorCvsL.clone( secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexMergerCvsL'+labelName+postfix)
369  ,primaryVertices = pvSource
370  ,tracks=pfCandidates),
371  process, task)
372  addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix,
373  NegVertex.inclusiveCandidateNegativeSecondaryVerticesCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexArbitratorCvsL'+labelName+postfix)),
374  process, task)
375 
376 
377  acceptedTagInfos = list()
378  for btagInfo in requiredTagInfos:
379  if hasattr(btag,btagInfo):
380  if btagInfo == 'pfImpactParameterTagInfos':
381  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
382  btag.pfImpactParameterTagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
383  process, task)
384  if explicitJTA:
385  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
386  _btagInfo.explicitJTA = cms.bool(explicitJTA)
387  if tightBTagNTkHits:
388  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
389  _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
390  _btagInfo.minimumNumberOfHits = cms.int32(8)
391  if btagInfo == 'pfImpactParameterAK8TagInfos':
392  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
393  btag.pfImpactParameterAK8TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
394  process, task)
395  if explicitJTA:
396  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
397  _btagInfo.explicitJTA = cms.bool(explicitJTA)
398  if tightBTagNTkHits:
399  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
400  _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
401  _btagInfo.minimumNumberOfHits = cms.int32(8)
402  if btagInfo == 'pfImpactParameterCA15TagInfos':
403  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
404  btag.pfImpactParameterCA15TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
405  process, task)
406  if explicitJTA:
407  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
408  _btagInfo.explicitJTA = cms.bool(explicitJTA)
409  if tightBTagNTkHits:
410  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
411  _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
412  _btagInfo.minimumNumberOfHits = cms.int32(8)
413  if btagInfo == 'pfSecondaryVertexTagInfos':
414  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
415  btag.pfSecondaryVertexTagInfos.clone(
416  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
417  process, task)
418  if tightBTagNTkHits:
419  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
420  _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
421  _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
422  if btagInfo == 'pfDeepCSVTagInfos':
423  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
424  btag.pfDeepCSVTagInfos.clone(
425  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
426  process, task)
427  if svClustering or fatJets != cms.InputTag(''):
428  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
429  if btagInfo == 'pfDeepCSVNegativeTagInfos':
430  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
431  btag.pfDeepCSVNegativeTagInfos.clone(
432  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderNegativeTagInfos'+labelName+postfix)),
433  process, task)
434  if svClustering or fatJets != cms.InputTag(''):
435  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
436  if btagInfo == 'pfDeepCSVPositiveTagInfos':
437  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
438  btag.pfDeepCSVPositiveTagInfos.clone(
439  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
440  process, task)
441  if svClustering or fatJets != cms.InputTag(''):
442  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
443  if btagInfo == 'pfDeepCMVATagInfos':
444  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
445  btag.pfDeepCMVATagInfos.clone(
446  deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
447  ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
448  muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
449  elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
450  process, task)
451  if svClustering or fatJets != cms.InputTag(''):
452  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
453  if btagInfo == 'pfDeepCMVANegativeTagInfos':
454  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
455  btag.pfDeepCMVATagInfos.clone(
456  deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
457  ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
458  muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
459  elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
460  process, task)
461  if svClustering or fatJets != cms.InputTag(''):
462  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
463  if btagInfo == 'pfDeepCMVAPositiveTagInfos':
464  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
465  btag.pfDeepCMVATagInfos.clone(
466  deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
467  ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
468  muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
469  elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
470  process, task)
471  if svClustering or fatJets != cms.InputTag(''):
472  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
473  if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfos':
474  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
475  btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(
476  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
477  extSVCollection=svSource),
478  process, task)
479  if svClustering or fatJets != cms.InputTag(''):
480  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
481  if btagInfo == 'pfInclusiveSecondaryVertexFinderAK8TagInfos':
482  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
483  btag.pfInclusiveSecondaryVertexFinderAK8TagInfos.clone(
484  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterAK8TagInfos'+labelName+postfix),
485  extSVCollection=svSource),
486  process, task)
487  if svClustering or fatJets != cms.InputTag(''):
488  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
489  if btagInfo == 'pfBoostedDoubleSVAK8TagInfos':
490  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
491  btag.pfBoostedDoubleSVAK8TagInfos.clone(
492  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderAK8TagInfos'+labelName+postfix)),
493  process, task)
494  if btagInfo == 'pfInclusiveSecondaryVertexFinderCA15TagInfos':
495  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
496  btag.pfInclusiveSecondaryVertexFinderCA15TagInfos.clone(
497  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterCA15TagInfos'+labelName+postfix),
498  extSVCollection=svSource),
499  process, task)
500  if svClustering or fatJets != cms.InputTag(''):
501  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
502  if btagInfo == 'pfBoostedDoubleSVCA15TagInfos':
503  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
504  btag.pfBoostedDoubleSVCA15TagInfos.clone(
505  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderCA15TagInfos'+labelName+postfix)),
506  process, task)
507  if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsLTagInfos':
508  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
509  btag.pfInclusiveSecondaryVertexFinderCvsLTagInfos.clone(
510  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
511  extSVCollection=svSourceCvsL),
512  process, task)
513  if svClustering or fatJets != cms.InputTag(''):
514  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
515  if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
516  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
517  btag.pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos.clone(
518  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
519  extSVCollection = btagPrefix+'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix),
520  process, task)
521  if svClustering or fatJets != cms.InputTag(''):
522  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
523  if btagInfo == 'pfGhostTrackVertexTagInfos':
524  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
525  btag.pfGhostTrackVertexTagInfos.clone(
526  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
527  process, task)
528  if btagInfo == 'pfSecondaryVertexNegativeTagInfos':
529  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
530  btag.pfSecondaryVertexNegativeTagInfos.clone(
531  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
532  process, task)
533  if tightBTagNTkHits:
534  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
535  _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
536  _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
537  if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeTagInfos':
538  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
539  btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(
540  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
541  extSVCollection=cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)),
542  process, task)
543  if svClustering or fatJets != cms.InputTag(''):
544  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
545  if btagInfo == 'impactParameterTagInfos':
546  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
547  btag.impactParameterTagInfos.clone(
548  jetTracks = cms.InputTag('jetTracksAssociatorAtVertex'+labelName+postfix),
549  primaryVertex=pvSource),
550  process, task)
551  if btagInfo == 'secondaryVertexTagInfos':
552  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
553  btag.secondaryVertexTagInfos.clone(
554  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
555  process, task)
556  if btagInfo == 'inclusiveSecondaryVertexFinderTagInfos':
557  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
558  btag.inclusiveSecondaryVertexFinderTagInfos.clone(
559  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
560  process, task)
561  if svClustering or fatJets != cms.InputTag(''):
562  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
563  if btagInfo == 'inclusiveSecondaryVertexFinderFilteredTagInfos':
564  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
565  btag.inclusiveSecondaryVertexFinderFilteredTagInfos.clone(
566  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
567  process, task)
568  if svClustering or fatJets != cms.InputTag(''):
569  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
570  if btagInfo == 'secondaryVertexNegativeTagInfos':
571  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
572  btag.secondaryVertexNegativeTagInfos.clone(
573  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
574  process, task)
575  if btagInfo == 'inclusiveSecondaryVertexFinderNegativeTagInfos':
576  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
577  btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(
578  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
579  process, task)
580  if svClustering or fatJets != cms.InputTag(''):
581  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
582  if btagInfo == 'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos':
583  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
584  btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(
585  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
586  process, task)
587  if svClustering or fatJets != cms.InputTag(''):
588  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
589  if btagInfo == 'softMuonTagInfos':
590  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
591  btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource),
592  process, task)
593  if btagInfo == 'softPFMuonsTagInfos':
594  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
595  btag.softPFMuonsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, muons=muSource),
596  process, task)
597  if btagInfo == 'softPFElectronsTagInfos':
598  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
599  btag.softPFElectronsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, electrons=elSource),
600  process, task)
601  if btagInfo == 'pixelClusterTagInfos':
602  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
603  btag.pixelClusterTagInfos.clone(jets = jetSource, vertices=pvSource),
604  process, task)
605 
606  if 'pfBoostedDouble' in btagInfo or 'SecondaryVertex' in btagInfo:
607  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
608  if pfCandidates.value() == 'packedPFCandidates':
609  _btagInfo.weights = cms.InputTag("packedpuppi")
610  if not hasattr(process,"packedpuppi"):
611  from CommonTools.PileupAlgos.Puppi_cff import puppi
612  addToProcessAndTask('packedpuppi', puppi.clone(
613  useExistingWeights = True,
614  candName = 'packedPFCandidates',
615  vertexName = 'offlineSlimmedPrimaryVertices') , process, task)
616  else:
617  _btagInfo.weights = cms.InputTag("puppi")
618 
619  if 'DeepFlavourTagInfos' in btagInfo:
620  svUsed = svSource
621  if btagInfo == 'pfNegativeDeepFlavourTagInfos':
622  deep_csv_tag_infos = 'pfDeepCSVNegativeTagInfos'
623  svUsed = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)
624  flip = True
625  else:
626  deep_csv_tag_infos = 'pfDeepCSVTagInfos'
627  flip = False
628  # use right input tags when running with RECO PF candidates, which actually
629  # depens of wether jets were slimmed or not (check for s/S-limmed in name)
630  if not ('limmed' in jetSource.value()):
631  puppi_value_map = cms.InputTag("puppi")
632  vertex_associator = cms.InputTag("primaryVertexAssociation","original")
633  else:
634  puppi_value_map = cms.InputTag("")
635  vertex_associator = cms.InputTag("")
636  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
637  btag.pfDeepFlavourTagInfos.clone(
638  jets = jetSource,
639  vertices=pvSource,
640  secondary_vertices=svUsed,
641  shallow_tag_infos = cms.InputTag(btagPrefix+deep_csv_tag_infos+labelName+postfix),
642  puppi_value_map = puppi_value_map,
643  vertex_associator = vertex_associator,
644  flip = flip),
645  process, task)
646 
647  if btagInfo == 'pfDeepDoubleXTagInfos':
648  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
649  btag.pfDeepDoubleXTagInfos.clone(
650  jets = jetSource,
651  vertices=pvSource,
652  secondary_vertices=svSource,
653  shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix),
654  ),
655  process, task)
656 
657  if btagInfo == 'pfHiggsInteractionNetTagInfos':
658  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
659  btag.pfHiggsInteractionNetTagInfos.clone(
660  jets = jetSource,
661  vertices = pvSource,
662  secondary_vertices = svSource,
663  pf_candidates = pfCandidates,
664  ),
665  process, task)
666 
667  if btagInfo == 'pfDeepBoostedJetTagInfos':
668  if pfCandidates.value() == 'packedPFCandidates':
669  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
670  if 'updated' not in jetSource.value().lower():
671  raise ValueError("Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value())
672  puppi_value_map = ""
673  vertex_associator = ""
674  elif pfCandidates.value() == 'particleFlow':
675  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
676  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
677  # daughters are the particles used in jet clustering, so already scaled by their puppi weights
678  # Uncomment the lines below after running pfDeepBoostedJetTagInfos with reco::PFCandidates becomes supported
679 # puppi_value_map = "puppi"
680 # vertex_associator = "primaryVertexAssociation:original"
681  else:
682  raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
683  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
684  btag.pfDeepBoostedJetTagInfos.clone(
685  jets = jetSource,
686  vertices = pvSource,
687  secondary_vertices = svSource,
688  pf_candidates = pfCandidates,
689  puppi_value_map = puppi_value_map,
690  vertex_associator = vertex_associator,
691  ),
692  process, task)
693 
694  if btagInfo == 'pfParticleNetTagInfos':
695  if pfCandidates.value() == 'packedPFCandidates':
696  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
697  puppi_value_map = ""
698  vertex_associator = ""
699  elif pfCandidates.value() == 'particleFlow':
700  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
701  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
702  puppi_value_map = "puppi"
703  vertex_associator = "primaryVertexAssociation:original"
704  else:
705  raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
706  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
707  btag.pfParticleNetTagInfos.clone(
708  jets = jetSource,
709  vertices = pvSource,
710  secondary_vertices = svSource,
711  pf_candidates = pfCandidates,
712  puppi_value_map = puppi_value_map,
713  vertex_associator = vertex_associator,
714  ),
715  process, task)
716 
717  if 'ParticleNetAK4TagInfos' in btagInfo:
718  if btagInfo == 'pfNegativeParticleNetAK4TagInfos':
719  secondary_vertices = btagPrefix + \
720  'inclusiveCandidateNegativeSecondaryVertices' + labelName + postfix
721  flip_ip_sign = True
722  sip3dSigMax = 10
723  else:
724  secondary_vertices = svSource
725  flip_ip_sign = False
726  sip3dSigMax = -1
727  if pfCandidates.value() == 'packedPFCandidates':
728  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
729  puppi_value_map = ""
730  vertex_associator = ""
731  elif pfCandidates.value() == 'particleFlow':
732  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
733  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
734  puppi_value_map = "puppi"
735  vertex_associator = "primaryVertexAssociation:original"
736  else:
737  raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
738  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
739  btag.pfParticleNetAK4TagInfos.clone(
740  jets = jetSource,
741  vertices = pvSource,
742  secondary_vertices = secondary_vertices,
743  pf_candidates = pfCandidates,
744  puppi_value_map = puppi_value_map,
745  vertex_associator = vertex_associator,
746  flip_ip_sign = flip_ip_sign,
747  sip3dSigMax = sip3dSigMax,
748  ),
749  process, task)
750 
751  acceptedTagInfos.append(btagInfo)
752  elif hasattr(toptag, btagInfo) :
753  acceptedTagInfos.append(btagInfo)
754  else:
755  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo))
756 
757  acceptedBtagDiscriminators = list()
758  for discriminator_name in btagDiscriminators :
759  btagDiscr = discriminator_name.split(':')[0] #split input tag to get the producer label
760  #print discriminator_name, '-->', btagDiscr
761  if hasattr(btag,btagDiscr):
762  newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name
763  if hasattr(process, newDiscr):
764  pass
765  elif hasattr(getattr(btag, btagDiscr), 'tagInfos'):
767  newDiscr,
768  getattr(btag, btagDiscr).clone(
769  tagInfos = cms.VInputTag(
770  *[ cms.InputTag(btagPrefix+x+labelName+postfix) \
771  for x in supportedBtagDiscr[discriminator_name][0] ]
772  )
773  ),
774  process,
775  task
776  )
777  elif hasattr(getattr(btag, btagDiscr), 'src'):
779  newDiscr,
780  getattr(btag, btagDiscr).clone(
781  src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
782  ),
783  process,
784  task
785  )
786  else:
787  raise ValueError('I do not know how to update %s it does not have neither "tagInfos" nor "src" attributes' % btagDiscr)
788  acceptedBtagDiscriminators.append(discriminator_name)
789  else:
790  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
791  #update meta-taggers, if any
792  for meta_tagger in present_meta:
793  btagDiscr = meta_tagger.split(':')[0] #split input tag to get the producer label
794  #print discriminator_name, '-->', btagDiscr
795  if hasattr(btag,btagDiscr):
796  newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name
797  if hasattr(process, newDiscr):
798  pass
799  else:
801  newDiscr,
802  getattr(btag, btagDiscr).clone(),
803  process,
804  task
805  )
806  for dependency in supportedMetaDiscr[meta_tagger]:
807  if ':' in dependency:
808  new_dep = btagPrefix+dependency.split(':')[0]+labelName+postfix+':'+dependency.split(':')[1]
809  else:
810  new_dep = btagPrefix+dependency+labelName+postfix
811  replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
812  replace.doIt(getattr(process, newDiscr), newDiscr)
813  acceptedBtagDiscriminators.append(meta_tagger)
814  else:
815  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
816 
817 
818  patJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix) for x in acceptedTagInfos ] )
819  patJets.discriminatorSources = cms.VInputTag(*[
820  cms.InputTag(btagPrefix+x+labelName+postfix) \
821  if ':' not in x else \
822  cms.InputTag(btagPrefix+x.split(':')[0]+labelName+postfix+':'+x.split(':')[1]) \
823  for x in acceptedBtagDiscriminators
824  ])
825  if len(acceptedBtagDiscriminators) > 0 :
826  patJets.addBTagInfo = True
827 
828  if runIVF:
829  if not tightBTagNTkHits:
830  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
831  if not runIVFforCTagOnly: rerunningIVFMiniAOD()
832  else:
833  rerunningIVF()
834  from PhysicsTools.PatAlgos.tools.helpers import loadWithPrefix
835  ivfbTagInfos = ['pfInclusiveSecondaryVertexFinderTagInfos', 'pfInclusiveSecondaryVertexFinderAK8TagInfos', 'pfInclusiveSecondaryVertexFinderCA15TagInfos']
836  if any(i in acceptedTagInfos for i in ivfbTagInfos) and not runIVFforCTagOnly:
837  if not hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
838  loadWithPrefix(process, 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
839  if tightBTagNTkHits:
840  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
841  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinder')
842  _temp.minHits = cms.uint32(8)
843 
844  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
845  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
846  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinder')
847  _temp.primaryVertices = pvSource
848  _temp.tracks = pfCandidates
849  if hasattr( process, btagPrefix+'candidateVertexArbitrator' ):
850  _temp = getattr(process, btagPrefix+'candidateVertexArbitrator')
851  _temp.primaryVertices = pvSource
852  _temp.tracks = pfCandidates
853  if hasattr( process, btagPrefix+'inclusiveCandidateSecondaryVertices' ) and not hasattr( process, svSource.getModuleLabel() ):
854  addToProcessAndTask(svSource.getModuleLabel(),
855  getattr(process, btagPrefix+'inclusiveCandidateSecondaryVertices').clone(),
856  process, task)
857  if any(i in acceptedTagInfos for i in ivfcTagInfos):
858  if not hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
859  loadWithPrefix(process, 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
860  if tightBTagNTkHits:
861  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
862  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinderCvsL')
863  _temp.minHits = cms.uint32(8)
864 
865  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
866  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
867  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinderCvsL')
868  _temp.primaryVertices = pvSource
869  _temp.tracks = pfCandidates
870  if hasattr( process, btagPrefix+'candidateVertexArbitratorCvsL' ):
871  _temp = getattr(process, btagPrefix+'candidateVertexArbitratorCvsL')
872  _temp.primaryVertices = pvSource
873  _temp.tracks = pfCandidates
874  if hasattr( process, btagPrefix+'inclusiveCandidateSecondaryVerticesCvsL' ) and not hasattr( process, svSourceCvsL.getModuleLabel() ):
875  addToProcessAndTask(svSourceCvsL.getModuleLabel(),
876  getattr(process, btagPrefix+'inclusiveCandidateSecondaryVerticesCvsL').clone(),
877  process, task)
878  if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos:
879  if not hasattr( process, 'inclusiveVertexing' ):
880  process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
881  task.add(process.inclusiveVertexingTask)
882  task.add(process.inclusiveCandidateVertexingTask)
883  task.add(process.inclusiveCandidateVertexingCvsLTask)
884  if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
885  if not hasattr( process, 'inclusiveVertexing' ):
886  process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
887  task.add(process.inclusiveVertexingTask)
888  task.add(process.inclusiveCandidateVertexingTask)
889  task.add(process.inclusiveCandidateVertexingCvsLTask)
890  if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
891  if not hasattr( process, 'inclusiveSecondaryVerticesFiltered' ):
892  process.load( 'RecoBTag.SecondaryVertex.inclusiveSecondaryVerticesFiltered_cfi' )
893  task.add(process.inclusiveSecondaryVerticesFiltered)
894  task.add(process.bVertexFilter)
895  if not hasattr( process, 'bToCharmDecayVertexMerged' ):
896  process.load( 'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' )
897  task.add(process.bToCharmDecayVertexMerged)
898  if 'caTopTagInfos' in acceptedTagInfos :
899  patJets.addTagInfos = True
900  if not hasattr( process, 'caTopTagInfos' ) and not hasattr( process, 'caTopTagInfosAK8' ):
901  process.load( 'RecoJets.JetProducers.caTopTaggers_cff' )
902  task.add(process.caTopTaggersTask)
903 

References helpers.addToProcessAndTask(), any(), clone(), helpers.getPatAlgosToolsTask(), helpers.loadWithPrefix(), print(), rerunningIVF(), rerunningIVFMiniAOD(), and setupSVClustering().

Referenced by jetTools.AddJetCollection.toolCode(), and jetTools.UpdateJetCollection.toolCode().

◆ setupJetCorrections()

def jetTools.setupJetCorrections (   process,
  knownModules,
  jetCorrections,
  jetSource,
  pvSource,
  patJets,
  labelName,
  postfix 
)

Definition at line 26 of file jetTools.py.

26 def setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, patJets, labelName, postfix):
27 
28  task = getPatAlgosToolsTask(process)
29 
30 
34  _type="NONE"
35  if jetCorrections[0].count('PF')>0:
36  _type='PF'
37  elif jetCorrections[0].count('Calo')>0:
38  _type='Calo'
39  elif jetCorrections[0].count('JPT')>0:
40  _type='JPT'
41  else:
42  raise TypeError("In addJetCollection: Jet energy corrections are only supported for PF, JPT and Calo jets.")
43  from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors
44  if 'patJetCorrFactors'+labelName+postfix in knownModules :
45  _newPatJetCorrFactors=getattr(process, 'patJetCorrFactors'+labelName+postfix)
46  _newPatJetCorrFactors.src=jetSource
47  _newPatJetCorrFactors.primaryVertices=pvSource
48  else:
49  addToProcessAndTask('patJetCorrFactors'+labelName+postfix,
50  patJetCorrFactors.clone(src=jetSource, primaryVertices=pvSource),
51  process, task)
52  _newPatJetCorrFactors=getattr(process, "patJetCorrFactors"+labelName+postfix)
53  _newPatJetCorrFactors.payload=jetCorrections[0]
54  _newPatJetCorrFactors.levels=jetCorrections[1]
55 
56  error=False
57  for x in jetCorrections[1]:
58  if x == 'L1Offset' :
59  if not error :
60  _newPatJetCorrFactors.useNPV=True
61  _newPatJetCorrFactors.primaryVertices='offlinePrimaryVertices'
62  _newPatJetCorrFactors.useRho=False
63 
65  error=True
66  else:
67  raise ValueError("In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
68  once. Check the list of correction levels you requested to be applied: "+ jetCorrections[1])
69  if x == 'L1FastJet' :
70  if not error :
71  if _type == "JPT" :
72  raise TypeError("In addJetCollection: L1FastJet corrections are only supported for PF and Calo jets.")
73 
74  _newPatJetCorrFactors.useRho=True
75  if "PF" in _type :
76  _newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAll')
77  else :
78  _newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAllCalo')
79 
81  error=True
82  else:
83  raise ValueError("In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
84  once. Check the list of correction levels you requested to be applied: "+ jetCorrections[1])
85  patJets.jetCorrFactorsSource=cms.VInputTag(cms.InputTag('patJetCorrFactors'+labelName+postfix))
86 
87  if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '':
88  if not jetCorrections[2].lower() == 'type-1' and not jetCorrections[2].lower() == 'type-2':
89  raise ValueError("In addJetCollection: Wrong choice of MET corrections for new jet collection. Possible choices are None (or empty string), Type-1, Type-2 (i.e.\
90  Type-1 and Type-2 corrections applied). This choice is not case sensitive. Your choice was: "+ jetCorrections[2])
91  if _type == "JPT":
92  raise ValueError("In addJecCollection: MET(type1) corrections are not supported for JPTJets. Please set the MET-LABEL to \"None\" (as string in quatiation \
93  marks) and use raw tcMET together with JPTJets.")
94 
95  process.load( "JetMETCorrections.Configuration.JetCorrectorsAllAlgos_cff") # FIXME: This adds a lot of garbage
96  # I second the FIXME comment on the last line. When I counted it, this brought in 344 EDProducers
97  # to be available to run unscheduled. All jet correctors, probably some small fraction of which
98  # are actually used.
99  task.add(process.jetCorrectorsAllAlgosTask)
100  _payloadType = jetCorrections[0].split(_type)[0].lower()+_type
101  if "PF" in _type :
102  addToProcessAndTask(jetCorrections[0]+'L1FastJet',
103  getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAll')),
104  process, task)
105  else :
106  addToProcessAndTask(jetCorrections[0]+'L1FastJet',
107  getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAllCalo')),
108  process, task)
109  addToProcessAndTask(jetCorrections[0]+'L1Offset', getattr(process, _payloadType+'L1OffsetCorrector').clone(), process, task)
110  addToProcessAndTask(jetCorrections[0]+'L2Relative', getattr(process, _payloadType+'L2RelativeCorrector').clone(), process, task)
111  addToProcessAndTask(jetCorrections[0]+'L3Absolute', getattr(process, _payloadType+'L3AbsoluteCorrector').clone(), process, task)
112  addToProcessAndTask(jetCorrections[0]+'L2L3Residual', getattr(process, _payloadType+'ResidualCorrector').clone(), process, task)
113  addToProcessAndTask(jetCorrections[0]+'CombinedCorrector',
114  cms.EDProducer( 'ChainedJetCorrectorProducer', correctors = cms.VInputTag()),
115  process, task)
116  for x in jetCorrections[1]:
117  if x != 'L1FastJet' and x != 'L1Offset' and x != 'L2Relative' and x != 'L3Absolute' and x != 'L2L3Residual':
118  raise ValueError('In addJetCollection: Unsupported JEC for MET(Type1). Currently supported jet correction levels are L1FastJet, L1Offset, L2Relative, L3Asolute, L2L3Residual. Requested was: %s'%(x))
119  else:
120  _corrector = _payloadType
121  if x == 'L1FastJet':
122  _corrector += 'L1Fastjet'
123  elif x == 'L2L3Residual':
124  _corrector += 'Residual'
125  else:
126  _corrector += x
127  _corrector += 'Corrector'
128  getattr(process, jetCorrections[0]+'CombinedCorrector').correctors.append(cms.InputTag(_corrector))
129 
130 
131  _labelCorrName = labelName
132  if labelName != '':
133  _labelCorrName = 'For' + labelName
134  if _type == 'Calo':
135  from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType1
136  from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType2
137  from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1
138  from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1T2
140  jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix,
141  corrCaloMetType1.clone(src=jetSource,srcMET = "caloMetM",jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector')),
142  process, task)
144  jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix,
145  corrCaloMetType2.clone(srcUnclEnergySums = cms.VInputTag(
146  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),
147  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),
148  cms.InputTag('muCaloMetCorr'))),
149  process, task)
151  jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix,
152  caloMetT1.clone(src = "caloMetM", srcCorrections = cms.VInputTag(
153  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'))),
154  process, task)
155  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix,
156  caloMetT1T2.clone(src = "caloMetM", srcCorrections = cms.VInputTag(
157  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'),
158  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix))),
159  process, task)
160  elif _type == 'PF':
162  from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsPtrForMetCorr
163  from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsForMetCorr
167  from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1
168  from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1T2
169  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix,
170  pfJetsPtrForMetCorr.clone(src = jetSource), process, task)
172  jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix,
173  pfCandsNotInJetsPtrForMetCorr.clone(topCollection = jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix),
174  process, task)
176  jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix,
177  pfCandsNotInJetsForMetCorr.clone(src = jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix),
178  process, task)
180  jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix,
181  pfCandMETcorr.clone(src = cms.InputTag(jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix)),
182  process, task)
184  jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix,
185  corrPfMetType1.clone(src = jetSource, jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector')),
186  process, task) # FIXME: Originally w/o jet corrections?
187  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix,
188  corrPfMetType2.clone(srcUnclEnergySums = cms.VInputTag(
189  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),
190  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),
191  cms.InputTag(jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix))),
192  process, task)
193  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix,
194  pfMetT1.clone(srcCorrections = cms.VInputTag(
195  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'))),
196  process, task)
197  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix,
198  pfMetT1T2.clone(srcCorrections = cms.VInputTag(
199  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'),
200  jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix)),
201  process, task)
202  if 'Puppi' in jetSource.value() and pfCandidates.value() == 'particleFlow':
203  getattr(process,jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix).srcWeights = "puppiNoLep"
204 
205 
206  if ('L1FastJet' in jetCorrections[1] or 'L1Fastjet' in jetCorrections[1]):
207  getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1FastJet')
208  #FIXME: What is wrong here?
209  #elif ('L1Offset' in jetCorrections[1]):
210  #getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1Offset')
211  else:
212  getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag('')
213 
215  if jetCorrections[2].lower() == 'type-1':
216  addToProcessAndTask('patMETs'+labelName+postfix,
217  patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix),
218  addMuonCorrections = False),
219  process, task)
220  elif jetCorrections[2].lower() == 'type-2':
221  addToProcessAndTask('patMETs'+labelName+postfix,
222  patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix),
223  addMuonCorrections = False),
224  process, task)
225 
226 

References helpers.addToProcessAndTask(), clone(), submitPVResolutionJobs.count, helpers.getPatAlgosToolsTask(), and submitPVValidationJobs.split().

Referenced by jetTools.AddJetCollection.toolCode(), and jetTools.UpdateJetCollection.toolCode().

◆ setupSVClustering()

def jetTools.setupSVClustering (   btagInfo,
  svClustering,
  algo,
  rParam,
  fatJets = cms.InputTag(''),
  groomedFatJets = cms.InputTag('') 
)

Definition at line 227 of file jetTools.py.

227 def setupSVClustering(btagInfo, svClustering, algo, rParam, fatJets=cms.InputTag(''), groomedFatJets=cms.InputTag('')):
228  btagInfo.useSVClustering = cms.bool(svClustering)
229  btagInfo.jetAlgorithm = cms.string(algo)
230  btagInfo.rParam = cms.double(rParam)
231 
232  if fatJets != cms.InputTag(''):
233  btagInfo.fatJets = fatJets
234  if groomedFatJets != cms.InputTag(''):
235  btagInfo.groomedFatJets = groomedFatJets
236 
237 

Referenced by setupBTagging().

◆ undefinedLabelName()

def jetTools.undefinedLabelName (   obj)

Definition at line 1928 of file jetTools.py.

1928 def undefinedLabelName(obj):
1929  sys.stderr.write("-------------------------------------------------------\n")
1930  sys.stderr.write(" Error: the jet 'labelName' is not defined.\n")
1931  sys.stderr.write(" All added jets must have 'labelName' defined.\n")
1932  sys.stderr.write("-------------------------------------------------------\n")
1933  raise KeyError("Undefined jet 'labelName' used in '"+obj._label+"'")
1934 

Referenced by jetTools.AddJetCollection.toolCode().

◆ unsupportedJetAlgorithm()

def jetTools.unsupportedJetAlgorithm (   obj)

Definition at line 1935 of file jetTools.py.

1935 def unsupportedJetAlgorithm(obj):
1936  sys.stderr.write("-------------------------------------------------------\n")
1937  sys.stderr.write(" Error: Unsupported jet algorithm detected.\n")
1938  sys.stderr.write(" The supported algorithms are:\n")
1939  for key in supportedJetAlgos.keys():
1940  sys.stderr.write(" " + key.upper() + ", " + key.lower() + ": " + supportedJetAlgos[key] + "\n")
1941  sys.stderr.write("-------------------------------------------------------\n")
1942  raise KeyError("Unsupported jet algorithm used in '"+obj._label+"'")
1943 

Referenced by jetTools.AddJetCollection.toolCode(), and jetTools.UpdateJetCollection.toolCode().

Variable Documentation

◆ supportedJetAlgos

jetTools.supportedJetAlgos

dictionary with supported jet clustering algorithms

Definition at line 12 of file jetTools.py.

RecoBTag_cff
jetTools.rerunningIVF
def rerunningIVF()
Definition: jetTools.py:1944
helpers.getPatAlgosToolsTask
def getPatAlgosToolsTask(process)
Definition: helpers.py:14
jetTools.checkJetCorrectionsFormat
def checkJetCorrectionsFormat(jetCorrections)
Definition: jetTools.py:18
correctionTermsPfMetType1Type2_cff
Puppi_cff
jetTools.jetAlgo
def jetAlgo(algo)
Definition: jetTools.py:3
any
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:38
jetCorrFactors_cfi
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
metProducer_cfi
jetTools.deprecatedOptionOutputModule
def deprecatedOptionOutputModule(obj)
Definition: jetTools.py:1917
ak4PFJets_cfi
jetTools.undefinedLabelName
def undefinedLabelName(obj)
Definition: jetTools.py:1928
jetTools.setupJetCorrections
def setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, patJets, labelName, postfix)
Definition: jetTools.py:26
jetTools.unsupportedJetAlgorithm
def unsupportedJetAlgorithm(obj)
Definition: jetTools.py:1935
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
helpers
jetTools.setupBTagging
def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, tightBTagNTkHits, loadStdRecoBTag, svClustering, fatJets, groomedFatJets, algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix)
Definition: jetTools.py:238
helpers.loadWithPrefix
def loadWithPrefix(process, moduleName, prefix='', loadedProducersAndFilters=None)
Definition: helpers.py:44
correctionTermsCaloMet_cff
jetTools.setupSVClustering
def setupSVClustering(btagInfo, svClustering, algo, rParam, fatJets=cms.InputTag(''), groomedFatJets=cms.InputTag(''))
Definition: jetTools.py:227
helpers.addToProcessAndTask
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:29
jetTools.rerunningIVFMiniAOD
def rerunningIVFMiniAOD()
Definition: jetTools.py:1952