CMS 3D CMS Logo

Classes | Functions | Variables
jetTools Namespace Reference

Classes

class  AddJetCollection
 
class  AddJetID
 
class  SetTagInfos
 
class  SwitchJetCollection
 
class  UpdateJetCollection
 

Functions

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

Variables

 supportedJetAlgos
 dictionary with supported jet clustering algorithms More...
 

Function Documentation

◆ checkJetCorrectionsFormat()

def jetTools.checkJetCorrectionsFormat (   jetCorrections)

Definition at line 18 of file jetTools.py.

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

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

◆ deprecatedOptionOutputModule()

def jetTools.deprecatedOptionOutputModule (   obj)

Definition at line 1918 of file jetTools.py.

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

◆ jetAlgo()

def jetTools.jetAlgo (   algo)

Definition at line 3 of file jetTools.py.

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

◆ rerunningIVF()

def jetTools.rerunningIVF ( )

Definition at line 1945 of file jetTools.py.

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

Referenced by setupBTagging().

◆ rerunningIVFMiniAOD()

def jetTools.rerunningIVFMiniAOD ( )

Definition at line 1953 of file jetTools.py.

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

Referenced by setupBTagging().

◆ setupBTagging()

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

Definition at line 238 of file jetTools.py.

238 def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, tightBTagNTkHits, loadStdRecoBTag, svClustering, fatJets, groomedFatJets,
239  algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix):
240 
241  task = getPatAlgosToolsTask(process)
242 
243 
244  discriminators = set(btagDiscriminators)
245  present_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  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
650  btag.pfDeepDoubleXTagInfos.clone(
651  jets = jetSource,
652  vertices=pvSource,
653  secondary_vertices=svSource,
654  shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix),
655  ),
656  process, task)
657 
658  if btagInfo == 'pfHiggsInteractionNetTagInfos':
659  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
660  btag.pfHiggsInteractionNetTagInfos.clone(
661  jets = jetSource,
662  vertices = pvSource,
663  secondary_vertices = svSource,
664  pf_candidates = pfCandidates,
665  ),
666  process, task)
667 
668  if btagInfo == 'pfDeepBoostedJetTagInfos':
669  if pfCandidates.value() == 'packedPFCandidates':
670  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
671  if 'updated' not in jetSource.value().lower():
672  raise ValueError("Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value())
673  puppi_value_map = ""
674  vertex_associator = ""
675  elif pfCandidates.value() == 'particleFlow':
676  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
677  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
678  # daughters are the particles used in jet clustering, so already scaled by their puppi weights
679  # Uncomment the lines below after running pfDeepBoostedJetTagInfos with reco::PFCandidates becomes supported
680 # puppi_value_map = "puppi"
681 # vertex_associator = "primaryVertexAssociation:original"
682  else:
683  raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
684  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
685  btag.pfDeepBoostedJetTagInfos.clone(
686  jets = jetSource,
687  vertices = pvSource,
688  secondary_vertices = svSource,
689  pf_candidates = pfCandidates,
690  puppi_value_map = puppi_value_map,
691  vertex_associator = vertex_associator,
692  ),
693  process, task)
694 
695  if btagInfo == 'pfParticleNetTagInfos':
696  if pfCandidates.value() == 'packedPFCandidates':
697  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
698  puppi_value_map = ""
699  vertex_associator = ""
700  elif pfCandidates.value() == 'particleFlow':
701  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
702  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
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.pfParticleNetTagInfos.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 'ParticleNetAK4TagInfos' in btagInfo:
719  if btagInfo == 'pfNegativeParticleNetAK4TagInfos':
720  secondary_vertices = btagPrefix + \
721  'inclusiveCandidateNegativeSecondaryVertices' + labelName + postfix
722  flip_ip_sign = True
723  sip3dSigMax = 10
724  else:
725  secondary_vertices = svSource
726  flip_ip_sign = False
727  sip3dSigMax = -1
728  if pfCandidates.value() == 'packedPFCandidates':
729  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
730  puppi_value_map = ""
731  vertex_associator = ""
732  elif pfCandidates.value() == 'particleFlow':
733  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
734  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
735  puppi_value_map = "puppi"
736  vertex_associator = "primaryVertexAssociation:original"
737  else:
738  raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
739  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
740  btag.pfParticleNetAK4TagInfos.clone(
741  jets = jetSource,
742  vertices = pvSource,
743  secondary_vertices = secondary_vertices,
744  pf_candidates = pfCandidates,
745  puppi_value_map = puppi_value_map,
746  vertex_associator = vertex_associator,
747  flip_ip_sign = flip_ip_sign,
748  sip3dSigMax = sip3dSigMax,
749  ),
750  process, task)
751 
752  acceptedTagInfos.append(btagInfo)
753  elif hasattr(toptag, btagInfo) :
754  acceptedTagInfos.append(btagInfo)
755  else:
756  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo))
757 
758  acceptedBtagDiscriminators = list()
759  for discriminator_name in btagDiscriminators :
760  btagDiscr = discriminator_name.split(':')[0] #split input tag to get the producer label
761  #print discriminator_name, '-->', btagDiscr
762  if hasattr(btag,btagDiscr):
763  newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name
764  if hasattr(process, newDiscr):
765  pass
766  elif hasattr(getattr(btag, btagDiscr), 'tagInfos'):
768  newDiscr,
769  getattr(btag, btagDiscr).clone(
770  tagInfos = cms.VInputTag(
771  *[ cms.InputTag(btagPrefix+x+labelName+postfix) \
772  for x in supportedBtagDiscr[discriminator_name][0] ]
773  )
774  ),
775  process,
776  task
777  )
778  elif hasattr(getattr(btag, btagDiscr), 'src'):
780  newDiscr,
781  getattr(btag, btagDiscr).clone(
782  src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
783  ),
784  process,
785  task
786  )
787  else:
788  raise ValueError('I do not know how to update %s it does not have neither "tagInfos" nor "src" attributes' % btagDiscr)
789  acceptedBtagDiscriminators.append(discriminator_name)
790  else:
791  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
792  #update meta-taggers, if any
793  for meta_tagger in present_meta:
794  btagDiscr = meta_tagger.split(':')[0] #split input tag to get the producer label
795  #print discriminator_name, '-->', btagDiscr
796  if hasattr(btag,btagDiscr):
797  newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name
798  if hasattr(process, newDiscr):
799  pass
800  else:
802  newDiscr,
803  getattr(btag, btagDiscr).clone(),
804  process,
805  task
806  )
807  for dependency in supportedMetaDiscr[meta_tagger]:
808  if ':' in dependency:
809  new_dep = btagPrefix+dependency.split(':')[0]+labelName+postfix+':'+dependency.split(':')[1]
810  else:
811  new_dep = btagPrefix+dependency+labelName+postfix
812  replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
813  replace.doIt(getattr(process, newDiscr), newDiscr)
814  acceptedBtagDiscriminators.append(meta_tagger)
815  else:
816  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
817 
818 
819  patJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix) for x in acceptedTagInfos ] )
820  patJets.discriminatorSources = cms.VInputTag(*[
821  cms.InputTag(btagPrefix+x+labelName+postfix) \
822  if ':' not in x else \
823  cms.InputTag(btagPrefix+x.split(':')[0]+labelName+postfix+':'+x.split(':')[1]) \
824  for x in acceptedBtagDiscriminators
825  ])
826  if len(acceptedBtagDiscriminators) > 0 :
827  patJets.addBTagInfo = True
828 
829  if runIVF:
830  if not tightBTagNTkHits:
831  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
832  if not runIVFforCTagOnly: rerunningIVFMiniAOD()
833  else:
834  rerunningIVF()
835  from PhysicsTools.PatAlgos.tools.helpers import loadWithPrefix
836  ivfbTagInfos = ['pfInclusiveSecondaryVertexFinderTagInfos', 'pfInclusiveSecondaryVertexFinderAK8TagInfos', 'pfInclusiveSecondaryVertexFinderCA15TagInfos']
837  if any(i in acceptedTagInfos for i in ivfbTagInfos) and not runIVFforCTagOnly:
838  if not hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
839  loadWithPrefix(process, 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
840  if tightBTagNTkHits:
841  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
842  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinder')
843  _temp.minHits = cms.uint32(8)
844 
845  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
846  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
847  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinder')
848  _temp.primaryVertices = pvSource
849  _temp.tracks = pfCandidates
850  if hasattr( process, btagPrefix+'candidateVertexArbitrator' ):
851  _temp = getattr(process, btagPrefix+'candidateVertexArbitrator')
852  _temp.primaryVertices = pvSource
853  _temp.tracks = pfCandidates
854  if hasattr( process, btagPrefix+'inclusiveCandidateSecondaryVertices' ) and not hasattr( process, svSource.getModuleLabel() ):
855  addToProcessAndTask(svSource.getModuleLabel(),
856  getattr(process, btagPrefix+'inclusiveCandidateSecondaryVertices').clone(),
857  process, task)
858  if any(i in acceptedTagInfos for i in ivfcTagInfos):
859  if not hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
860  loadWithPrefix(process, 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
861  if tightBTagNTkHits:
862  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
863  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinderCvsL')
864  _temp.minHits = cms.uint32(8)
865 
866  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
867  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
868  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinderCvsL')
869  _temp.primaryVertices = pvSource
870  _temp.tracks = pfCandidates
871  if hasattr( process, btagPrefix+'candidateVertexArbitratorCvsL' ):
872  _temp = getattr(process, btagPrefix+'candidateVertexArbitratorCvsL')
873  _temp.primaryVertices = pvSource
874  _temp.tracks = pfCandidates
875  if hasattr( process, btagPrefix+'inclusiveCandidateSecondaryVerticesCvsL' ) and not hasattr( process, svSourceCvsL.getModuleLabel() ):
876  addToProcessAndTask(svSourceCvsL.getModuleLabel(),
877  getattr(process, btagPrefix+'inclusiveCandidateSecondaryVerticesCvsL').clone(),
878  process, task)
879  if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos:
880  if not hasattr( process, 'inclusiveVertexing' ):
881  process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
882  task.add(process.inclusiveVertexingTask)
883  task.add(process.inclusiveCandidateVertexingTask)
884  task.add(process.inclusiveCandidateVertexingCvsLTask)
885  if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
886  if not hasattr( process, 'inclusiveVertexing' ):
887  process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
888  task.add(process.inclusiveVertexingTask)
889  task.add(process.inclusiveCandidateVertexingTask)
890  task.add(process.inclusiveCandidateVertexingCvsLTask)
891  if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
892  if not hasattr( process, 'inclusiveSecondaryVerticesFiltered' ):
893  process.load( 'RecoBTag.SecondaryVertex.inclusiveSecondaryVerticesFiltered_cfi' )
894  task.add(process.inclusiveSecondaryVerticesFiltered)
895  task.add(process.bVertexFilter)
896  if not hasattr( process, 'bToCharmDecayVertexMerged' ):
897  process.load( 'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' )
898  task.add(process.bToCharmDecayVertexMerged)
899  if 'caTopTagInfos' in acceptedTagInfos :
900  patJets.addTagInfos = True
901  if not hasattr( process, 'caTopTagInfos' ) and not hasattr( process, 'caTopTagInfosAK8' ):
902  process.load( 'RecoJets.JetProducers.caTopTaggers_cff' )
903  task.add(process.caTopTaggersTask)
904 

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

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

◆ setupJetCorrections()

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

Definition at line 26 of file jetTools.py.

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

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

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

◆ setupSVClustering()

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

Definition at line 227 of file jetTools.py.

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

Referenced by setupBTagging().

◆ undefinedLabelName()

def jetTools.undefinedLabelName (   obj)

Definition at line 1929 of file jetTools.py.

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

Referenced by jetTools.AddJetCollection.toolCode().

◆ unsupportedJetAlgorithm()

def jetTools.unsupportedJetAlgorithm (   obj)

Definition at line 1936 of file jetTools.py.

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

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

Variable Documentation

◆ supportedJetAlgos

jetTools.supportedJetAlgos

dictionary with supported jet clustering algorithms

Definition at line 12 of file jetTools.py.

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