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.

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

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

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

Referenced by setupBTagging().

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

◆ rerunningIVFMiniAOD()

def jetTools.rerunningIVFMiniAOD ( )

Definition at line 1956 of file jetTools.py.

Referenced by setupBTagging().

1956 def rerunningIVFMiniAOD():
1957  sys.stderr.write("-------------------------------------------------------------------\n")
1958  sys.stderr.write(" Warning: You are attempting to remake IVF secondary vertices from\n")
1959  sys.stderr.write(" MiniAOD. If that was your intention, note that secondary\n")
1960  sys.stderr.write(" vertices remade from MiniAOD will have somewhat degraded\n")
1961  sys.stderr.write(" performance compared to those remade from RECO/AOD.\n")
1962  sys.stderr.write("-------------------------------------------------------------------\n")
1963 
def rerunningIVFMiniAOD()
Definition: jetTools.py:1956

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

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

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

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

◆ setupSVClustering()

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

Definition at line 227 of file jetTools.py.

References setupBTagging().

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

◆ undefinedLabelName()

def jetTools.undefinedLabelName (   obj)

Definition at line 1932 of file jetTools.py.

Referenced by jetTools.AddJetCollection.toolCode().

1932 def undefinedLabelName(obj):
1933  sys.stderr.write("-------------------------------------------------------\n")
1934  sys.stderr.write(" Error: the jet 'labelName' is not defined.\n")
1935  sys.stderr.write(" All added jets must have 'labelName' defined.\n")
1936  sys.stderr.write("-------------------------------------------------------\n")
1937  raise KeyError("Undefined jet 'labelName' used in '"+obj._label+"'")
1938 
def undefinedLabelName(obj)
Definition: jetTools.py:1932

◆ unsupportedJetAlgorithm()

def jetTools.unsupportedJetAlgorithm (   obj)

Definition at line 1939 of file jetTools.py.

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

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

Variable Documentation

◆ supportedJetAlgos

jetTools.supportedJetAlgos

dictionary with supported jet clustering algorithms

Definition at line 12 of file jetTools.py.