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 setupPackedPuppi (process)
 
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.

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

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 
def checkJetCorrectionsFormat(jetCorrections)
Definition: jetTools.py:18

◆ deprecatedOptionOutputModule()

def jetTools.deprecatedOptionOutputModule (   obj)

Definition at line 1946 of file jetTools.py.

1947  sys.stderr.write("-------------------------------------------------------\n")
1948  sys.stderr.write(" Error: the option 'outputModule' is not supported\n")
1949  sys.stderr.write(" anymore by:\n")
1950  sys.stderr.write(" " + obj._label + "\n")
1951  sys.stderr.write(" please use 'outputModules' now and specify the\n")
1952  sys.stderr.write(" names of all needed OutModules in there\n")
1953  sys.stderr.write(" (default: ['out'])\n")
1954  sys.stderr.write("-------------------------------------------------------\n")
1955  raise KeyError("Unsupported option 'outputModule' used in '"+obj._label+"'")
1956 
def deprecatedOptionOutputModule(obj)
Definition: jetTools.py:1946

◆ 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
23 
def jetAlgo(algo)
Definition: jetTools.py:3

◆ rerunningIVF()

def jetTools.rerunningIVF ( )

Definition at line 1973 of file jetTools.py.

Referenced by setupBTagging().

1973 def rerunningIVF():
1974  sys.stderr.write("-------------------------------------------------------------------\n")
1975  sys.stderr.write(" Warning: You are attempting to remake the IVF secondary vertices\n")
1976  sys.stderr.write(" already produced by the standard reconstruction. This\n")
1977  sys.stderr.write(" option is not enabled by default so please use it only if\n")
1978  sys.stderr.write(" you know what you are doing.\n")
1979  sys.stderr.write("-------------------------------------------------------------------\n")
1980 
def rerunningIVF()
Definition: jetTools.py:1973

◆ rerunningIVFMiniAOD()

def jetTools.rerunningIVFMiniAOD ( )

Definition at line 1981 of file jetTools.py.

Referenced by setupBTagging().

1981 def rerunningIVFMiniAOD():
1982  sys.stderr.write("-------------------------------------------------------------------\n")
1983  sys.stderr.write(" Warning: You are attempting to remake IVF secondary vertices from\n")
1984  sys.stderr.write(" MiniAOD. If that was your intention, note that secondary\n")
1985  sys.stderr.write(" vertices remade from MiniAOD will have somewhat degraded\n")
1986  sys.stderr.write(" performance compared to those remade from RECO/AOD.\n")
1987  sys.stderr.write("-------------------------------------------------------------------\n")
1988 
def rerunningIVFMiniAOD()
Definition: jetTools.py:1981

◆ 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 249 of file jetTools.py.

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

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

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

◆ setupJetCorrections()

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

Definition at line 26 of file jetTools.py.

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

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

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 
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, patJets, labelName, postfix)
Definition: jetTools.py:26
User floats producers, selectors ##########################.
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def getPatAlgosToolsTask(process)
Definition: helpers.py:13

◆ setupPackedPuppi()

def jetTools.setupPackedPuppi (   process)

Definition at line 237 of file jetTools.py.

References helpers.addToProcessAndTask(), helpers.getPatAlgosToolsTask(), and setupBTagging().

Referenced by setupBTagging().

237 def setupPackedPuppi(process):
238  task = getPatAlgosToolsTask(process)
239  packedPuppiName = "packedpuppi"
240  if not hasattr(process,packedPuppiName):
241  from CommonTools.PileupAlgos.Puppi_cff import puppi
242  addToProcessAndTask(packedPuppiName, puppi.clone(
243  useExistingWeights = True,
244  candName = 'packedPFCandidates',
245  vertexName = 'offlineSlimmedPrimaryVertices') , process, task)
246  return packedPuppiName
247 
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def setupPackedPuppi(process)
Definition: jetTools.py:237
def getPatAlgosToolsTask(process)
Definition: helpers.py:13

◆ setupSVClustering()

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

Definition at line 227 of file jetTools.py.

Referenced by setupBTagging().

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 
def setupSVClustering(btagInfo, svClustering, algo, rParam, fatJets=cms.InputTag(''), groomedFatJets=cms.InputTag(''))
Definition: jetTools.py:227

◆ undefinedLabelName()

def jetTools.undefinedLabelName (   obj)

Definition at line 1957 of file jetTools.py.

Referenced by jetTools.AddJetCollection.toolCode().

1957 def undefinedLabelName(obj):
1958  sys.stderr.write("-------------------------------------------------------\n")
1959  sys.stderr.write(" Error: the jet 'labelName' is not defined.\n")
1960  sys.stderr.write(" All added jets must have 'labelName' defined.\n")
1961  sys.stderr.write("-------------------------------------------------------\n")
1962  raise KeyError("Undefined jet 'labelName' used in '"+obj._label+"'")
1963 
def undefinedLabelName(obj)
Definition: jetTools.py:1957

◆ unsupportedJetAlgorithm()

def jetTools.unsupportedJetAlgorithm (   obj)

Definition at line 1964 of file jetTools.py.

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

1964 def unsupportedJetAlgorithm(obj):
1965  sys.stderr.write("-------------------------------------------------------\n")
1966  sys.stderr.write(" Error: Unsupported jet algorithm detected.\n")
1967  sys.stderr.write(" The supported algorithms are:\n")
1968  for key in supportedJetAlgos.keys():
1969  sys.stderr.write(" " + key.upper() + ", " + key.lower() + ": " + supportedJetAlgos[key] + "\n")
1970  sys.stderr.write("-------------------------------------------------------\n")
1971  raise KeyError("Unsupported jet algorithm used in '"+obj._label+"'")
1972 
def unsupportedJetAlgorithm(obj)
Definition: jetTools.py:1964

Variable Documentation

◆ supportedJetAlgos

jetTools.supportedJetAlgos

dictionary with supported jet clustering algorithms

Definition at line 12 of file jetTools.py.