CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
jetTools Namespace Reference

Classes

class  AddJetCollection
 
class  AddJetID
 
class  SetTagInfos
 
class  SwitchJetCollection
 
class  UpdateJetCollection
 

Functions

def checkJetCorrectionsFormat
 
def deprecatedOptionOutputModule
 
def jetAlgo
 
def rerunningIVF
 
def rerunningIVFMiniAOD
 
def setupBTagging
 
def setupJetCorrections
 
def setupSVClustering
 
def undefinedLabelName
 
def unsupportedJetAlgorithm
 

Variables

dictionary supportedJetAlgos
 dictionary with supported jet clustering algorithms More...
 

Function Documentation

def jetTools.checkJetCorrectionsFormat (   jetCorrections)

Definition at line 18 of file jetTools.py.

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

18 
19 def checkJetCorrectionsFormat(jetCorrections):
20  ## check for the correct format
21  if not isinstance(jetCorrections, type(('PAYLOAD-LABEL',['CORRECTION-LEVEL-A','CORRECTION-LEVEL-B'], 'MET-LABEL'))):
22  raise ValueError("In addJetCollection: 'jetCorrections' must be 'None' (as a python value w/o quotation marks), or of type ('PAYLOAD-LABEL', ['CORRECTION-LEVEL-A', \
23  '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) \
24  corrections.")
25 
def checkJetCorrectionsFormat
Definition: jetTools.py:18
def jetTools.deprecatedOptionOutputModule (   obj)

Definition at line 1918 of file jetTools.py.

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

Definition at line 3 of file jetTools.py.

Referenced by pfTools.switchToPFJets().

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

Definition at line 1945 of file jetTools.py.

Referenced by setupBTagging().

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

Definition at line 1953 of file jetTools.py.

Referenced by setupBTagging().

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

240  algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix):
241 
242  task = getPatAlgosToolsTask(process)
243 
244  ## expand the btagDiscriminators to remove the meta taggers and substitute the equivalent sources
245  discriminators = set(btagDiscriminators)
246  present_metaSet = discriminators.intersection(set(supportedMetaDiscr.keys()))
247  discriminators -= present_metaSet
248  for meta_tagger in present_metaSet:
249  for src in supportedMetaDiscr[meta_tagger]:
250  discriminators.add(src)
251  present_meta = sorted(present_metaSet)
252  btagDiscriminators = sorted(discriminators)
253 
254  ## expand tagInfos to what is explicitly required by user + implicit
255  ## requirements that come in from one or the other discriminator
256  requiredTagInfos = list(btagInfos)
257  for btagDiscr in btagDiscriminators :
258  for tagInfoList in supportedBtagDiscr[btagDiscr] :
259  for requiredTagInfo in tagInfoList :
260  tagInfoCovered = False
261  for tagInfo in requiredTagInfos :
262  if requiredTagInfo == tagInfo :
263  tagInfoCovered = True
264  break
265  if not tagInfoCovered :
266  requiredTagInfos.append(requiredTagInfo)
267  ## load sequences and setups needed for btagging
268  if hasattr( process, 'candidateJetProbabilityComputer' ) == False :
269  if loadStdRecoBTag: # also loading modules already run in the standard reconstruction
270  process.load("RecoBTag.ImpactParameter.impactParameter_cff")
271  task.add(process.impactParameterTask)
272  process.load("RecoBTag.SecondaryVertex.secondaryVertex_cff")
273  task.add(process.secondaryVertexTask)
274  process.load("RecoBTag.SoftLepton.softLepton_cff")
275  task.add(process.softLeptonTask)
276  process.load("RecoBTag.Combined.combinedMVA_cff")
277  task.add(process.combinedMVATask)
278  process.load("RecoBTag.CTagging.cTagging_cff")
279  task.add(process.cTaggingTask)
280  else: # to prevent loading of modules already run in the standard reconstruction
281  process.load("RecoBTag.ImpactParameter.impactParameter_EventSetup_cff")
282  process.load("RecoBTag.SecondaryVertex.secondaryVertex_EventSetup_cff")
283  process.load("RecoBTag.SoftLepton.softLepton_EventSetup_cff")
284  process.load("RecoBTag.Combined.combinedMVA_EventSetup_cff")
285  process.load("RecoBTag.CTagging.cTagging_EventSetup_cff")
287  import RecoJets.JetProducers.caTopTaggers_cff as toptag
288 
289  if tightBTagNTkHits:
290  if not runIVF:
291  sys.stderr.write("-------------------------------------------------------------------\n")
292  sys.stderr.write(" Warning: For a complete switch to the legacy tight b-tag track\n")
293  sys.stderr.write(" selection, please also enable the \'runIVF\' switch.\n")
294  sys.stderr.write("-------------------------------------------------------------------\n")
295  if btagPrefix == '':
296  sys.stderr.write("-------------------------------------------------------------------\n")
297  sys.stderr.write(" Warning: With the tight b-tag track selection enabled, it is\n")
298  sys.stderr.write(" advisable to set \'btagPrefix\' to a non-empty string to\n")
299  sys.stderr.write(" avoid unintentional modifications to the default\n")
300  sys.stderr.write(" b tagging setup that might be loaded in the same job.\n")
301  sys.stderr.write("-------------------------------------------------------------------\n")
302 
303  ## define c tagging CvsL SV source (for now tied to the default SV source
304  ## in the first part of the module label, product instance label and process name)
305  svSourceCvsL = copy.deepcopy(svSource)
306  svSourceCvsL.setModuleLabel(svSource.getModuleLabel()+'CvsL')
307 
308  ## check if and under what conditions to re-run IVF
309  runIVFforCTagOnly = False
310  ivfcTagInfos = ['pfInclusiveSecondaryVertexFinderCvsLTagInfos', 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos']
311  ## if MiniAOD and running c tagging
312  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices' and any(i in requiredTagInfos for i in ivfcTagInfos) and not runIVF:
313  runIVFforCTagOnly = True
314  runIVF = True
315  sys.stderr.write("-------------------------------------------------------------------\n")
316  sys.stderr.write(" Info: To run c tagging on MiniAOD, c-tag-specific IVF secondary\n")
317  sys.stderr.write(" vertices will be remade.\n")
318  sys.stderr.write("-------------------------------------------------------------------\n")
319  ## adjust svSources
320  if runIVF and btagPrefix != '':
321  if runIVFforCTagOnly:
322  svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
323  else:
324  svSource.setModuleLabel(btagPrefix+svSource.getModuleLabel())
325  svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
326 
327  ## setup all required btagInfos : we give a dedicated treatment for different
328  ## types of tagInfos here. A common treatment is possible but might require a more
329  ## general approach anyway in coordination with the btagging POG.
330 
331  runNegativeVertexing = False
332  runNegativeCvsLVertexing = False
333  for btagInfo in requiredTagInfos:
334  if btagInfo in (
335  'pfInclusiveSecondaryVertexFinderNegativeTagInfos',
336  'pfNegativeDeepFlavourTagInfos',
337  'pfNegativeParticleNetAK4TagInfos',
338  ):
339  runNegativeVertexing = True
340  if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
341  runNegativeCvsLVertexing = True
342 
343  if runNegativeVertexing or runNegativeCvsLVertexing:
344  import RecoVertex.AdaptiveVertexFinder.inclusiveNegativeVertexing_cff as NegVertex
345 
346  if runNegativeVertexing:
347  addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeVertexFinder'+labelName+postfix,
348  NegVertex.inclusiveCandidateNegativeVertexFinder.clone(primaryVertices = pvSource,tracks=pfCandidates),
349  process, task)
350  addToProcessAndTask(btagPrefix+'candidateNegativeVertexMerger'+labelName+postfix,
351  NegVertex.candidateNegativeVertexMerger.clone(secondaryVertices = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeVertexFinder'+labelName+postfix)),
352  process, task)
353  addToProcessAndTask(btagPrefix+'candidateNegativeVertexArbitrator'+labelName+postfix,
354  NegVertex.candidateNegativeVertexArbitrator.clone( secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexMerger'+labelName+postfix)
355  ,primaryVertices = pvSource
356  ,tracks=pfCandidates),
357  process, task)
358  addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix,
359  NegVertex.inclusiveCandidateNegativeSecondaryVertices.clone(secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexArbitrator'+labelName+postfix)),
360  process, task)
361 
362  if runNegativeCvsLVertexing:
363  addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix,
364  NegVertex.inclusiveCandidateNegativeVertexFinderCvsL.clone(primaryVertices = pvSource,tracks=pfCandidates),
365  process, task)
366  addToProcessAndTask(btagPrefix+'candidateNegativeVertexMergerCvsL'+labelName+postfix,
367  NegVertex.candidateNegativeVertexMergerCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix)),
368  process, task)
369  addToProcessAndTask(btagPrefix+'candidateNegativeVertexArbitratorCvsL'+labelName+postfix,
370  NegVertex.candidateNegativeVertexArbitratorCvsL.clone( secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexMergerCvsL'+labelName+postfix)
371  ,primaryVertices = pvSource
372  ,tracks=pfCandidates),
373  process, task)
374  addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix,
375  NegVertex.inclusiveCandidateNegativeSecondaryVerticesCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexArbitratorCvsL'+labelName+postfix)),
376  process, task)
377 
378 
379  acceptedTagInfos = list()
380  for btagInfo in requiredTagInfos:
381  if hasattr(btag,btagInfo):
382  if btagInfo == 'pfImpactParameterTagInfos':
383  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
384  btag.pfImpactParameterTagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
385  process, task)
386  if explicitJTA:
387  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
388  _btagInfo.explicitJTA = cms.bool(explicitJTA)
389  if tightBTagNTkHits:
390  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
391  _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
392  _btagInfo.minimumNumberOfHits = cms.int32(8)
393  if btagInfo == 'pfImpactParameterAK8TagInfos':
394  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
395  btag.pfImpactParameterAK8TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
396  process, task)
397  if explicitJTA:
398  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
399  _btagInfo.explicitJTA = cms.bool(explicitJTA)
400  if tightBTagNTkHits:
401  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
402  _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
403  _btagInfo.minimumNumberOfHits = cms.int32(8)
404  if btagInfo == 'pfImpactParameterCA15TagInfos':
405  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
406  btag.pfImpactParameterCA15TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
407  process, task)
408  if explicitJTA:
409  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
410  _btagInfo.explicitJTA = cms.bool(explicitJTA)
411  if tightBTagNTkHits:
412  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
413  _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
414  _btagInfo.minimumNumberOfHits = cms.int32(8)
415  if btagInfo == 'pfSecondaryVertexTagInfos':
416  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
417  btag.pfSecondaryVertexTagInfos.clone(
418  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
419  process, task)
420  if tightBTagNTkHits:
421  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
422  _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
423  _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
424  if btagInfo == 'pfDeepCSVTagInfos':
425  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
426  btag.pfDeepCSVTagInfos.clone(
427  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
428  process, task)
429  if svClustering or fatJets != cms.InputTag(''):
430  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
431  if btagInfo == 'pfDeepCSVNegativeTagInfos':
432  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
433  btag.pfDeepCSVNegativeTagInfos.clone(
434  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderNegativeTagInfos'+labelName+postfix)),
435  process, task)
436  if svClustering or fatJets != cms.InputTag(''):
437  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
438  if btagInfo == 'pfDeepCSVPositiveTagInfos':
439  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
440  btag.pfDeepCSVPositiveTagInfos.clone(
441  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
442  process, task)
443  if svClustering or fatJets != cms.InputTag(''):
444  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
445  if btagInfo == 'pfDeepCMVATagInfos':
446  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
447  btag.pfDeepCMVATagInfos.clone(
448  deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
449  ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
450  muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
451  elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
452  process, task)
453  if svClustering or fatJets != cms.InputTag(''):
454  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
455  if btagInfo == 'pfDeepCMVANegativeTagInfos':
456  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
457  btag.pfDeepCMVATagInfos.clone(
458  deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
459  ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
460  muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
461  elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
462  process, task)
463  if svClustering or fatJets != cms.InputTag(''):
464  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
465  if btagInfo == 'pfDeepCMVAPositiveTagInfos':
466  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
467  btag.pfDeepCMVATagInfos.clone(
468  deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
469  ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
470  muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
471  elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
472  process, task)
473  if svClustering or fatJets != cms.InputTag(''):
474  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
475  if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfos':
476  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
477  btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(
478  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
479  extSVCollection=svSource),
480  process, task)
481  if svClustering or fatJets != cms.InputTag(''):
482  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
483  if btagInfo == 'pfInclusiveSecondaryVertexFinderAK8TagInfos':
484  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
485  btag.pfInclusiveSecondaryVertexFinderAK8TagInfos.clone(
486  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterAK8TagInfos'+labelName+postfix),
487  extSVCollection=svSource),
488  process, task)
489  if svClustering or fatJets != cms.InputTag(''):
490  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
491  if btagInfo == 'pfBoostedDoubleSVAK8TagInfos':
492  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
493  btag.pfBoostedDoubleSVAK8TagInfos.clone(
494  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderAK8TagInfos'+labelName+postfix)),
495  process, task)
496  if btagInfo == 'pfInclusiveSecondaryVertexFinderCA15TagInfos':
497  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
498  btag.pfInclusiveSecondaryVertexFinderCA15TagInfos.clone(
499  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterCA15TagInfos'+labelName+postfix),
500  extSVCollection=svSource),
501  process, task)
502  if svClustering or fatJets != cms.InputTag(''):
503  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
504  if btagInfo == 'pfBoostedDoubleSVCA15TagInfos':
505  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
506  btag.pfBoostedDoubleSVCA15TagInfos.clone(
507  svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderCA15TagInfos'+labelName+postfix)),
508  process, task)
509  if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsLTagInfos':
510  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
511  btag.pfInclusiveSecondaryVertexFinderCvsLTagInfos.clone(
512  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
513  extSVCollection=svSourceCvsL),
514  process, task)
515  if svClustering or fatJets != cms.InputTag(''):
516  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
517  if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
518  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
519  btag.pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos.clone(
520  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
521  extSVCollection = btagPrefix+'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix),
522  process, task)
523  if svClustering or fatJets != cms.InputTag(''):
524  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
525  if btagInfo == 'pfGhostTrackVertexTagInfos':
526  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
527  btag.pfGhostTrackVertexTagInfos.clone(
528  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
529  process, task)
530  if btagInfo == 'pfSecondaryVertexNegativeTagInfos':
531  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
532  btag.pfSecondaryVertexNegativeTagInfos.clone(
533  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
534  process, task)
535  if tightBTagNTkHits:
536  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
537  _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
538  _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
539  if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeTagInfos':
540  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
541  btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(
542  trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
543  extSVCollection=cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)),
544  process, task)
545  if svClustering or fatJets != cms.InputTag(''):
546  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
547  if btagInfo == 'impactParameterTagInfos':
548  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
549  btag.impactParameterTagInfos.clone(
550  jetTracks = cms.InputTag('jetTracksAssociatorAtVertex'+labelName+postfix),
551  primaryVertex=pvSource),
552  process, task)
553  if btagInfo == 'secondaryVertexTagInfos':
554  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
555  btag.secondaryVertexTagInfos.clone(
556  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
557  process, task)
558  if btagInfo == 'inclusiveSecondaryVertexFinderTagInfos':
559  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
560  btag.inclusiveSecondaryVertexFinderTagInfos.clone(
561  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
562  process, task)
563  if svClustering or fatJets != cms.InputTag(''):
564  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
565  if btagInfo == 'inclusiveSecondaryVertexFinderFilteredTagInfos':
566  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
567  btag.inclusiveSecondaryVertexFinderFilteredTagInfos.clone(
568  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
569  process, task)
570  if svClustering or fatJets != cms.InputTag(''):
571  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
572  if btagInfo == 'secondaryVertexNegativeTagInfos':
573  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
574  btag.secondaryVertexNegativeTagInfos.clone(
575  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
576  process, task)
577  if btagInfo == 'inclusiveSecondaryVertexFinderNegativeTagInfos':
578  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
579  btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(
580  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
581  process, task)
582  if svClustering or fatJets != cms.InputTag(''):
583  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
584  if btagInfo == 'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos':
585  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
586  btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(
587  trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
588  process, task)
589  if svClustering or fatJets != cms.InputTag(''):
590  setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
591  if btagInfo == 'softMuonTagInfos':
592  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
593  btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource),
594  process, task)
595  if btagInfo == 'softPFMuonsTagInfos':
596  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
597  btag.softPFMuonsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, muons=muSource),
598  process, task)
599  if btagInfo == 'softPFElectronsTagInfos':
600  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
601  btag.softPFElectronsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, electrons=elSource),
602  process, task)
603  if btagInfo == 'pixelClusterTagInfos':
604  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
605  btag.pixelClusterTagInfos.clone(jets = jetSource, vertices=pvSource),
606  process, task)
607 
608  if 'pfBoostedDouble' in btagInfo or 'SecondaryVertex' in btagInfo:
609  _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
610  if pfCandidates.value() == 'packedPFCandidates':
611  _btagInfo.weights = cms.InputTag("packedpuppi")
612  if not hasattr(process,"packedpuppi"):
613  from CommonTools.PileupAlgos.Puppi_cff import puppi
614  addToProcessAndTask('packedpuppi', puppi.clone(
615  useExistingWeights = True,
616  candName = 'packedPFCandidates',
617  vertexName = 'offlineSlimmedPrimaryVertices') , process, task)
618  else:
619  _btagInfo.weights = cms.InputTag("puppi")
620 
621  if 'DeepFlavourTagInfos' in btagInfo:
622  svUsed = svSource
623  if btagInfo == 'pfNegativeDeepFlavourTagInfos':
624  deep_csv_tag_infos = 'pfDeepCSVNegativeTagInfos'
625  svUsed = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)
626  flip = True
627  else:
628  deep_csv_tag_infos = 'pfDeepCSVTagInfos'
629  flip = False
630  # use right input tags when running with RECO PF candidates, which actually
631  # depens of wether jets were slimmed or not (check for s/S-limmed in name)
632  if not ('limmed' in jetSource.value()):
633  puppi_value_map = cms.InputTag("puppi")
634  vertex_associator = cms.InputTag("primaryVertexAssociation","original")
635  else:
636  puppi_value_map = cms.InputTag("")
637  vertex_associator = cms.InputTag("")
638  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
639  btag.pfDeepFlavourTagInfos.clone(
640  jets = jetSource,
641  vertices=pvSource,
642  secondary_vertices=svUsed,
643  shallow_tag_infos = cms.InputTag(btagPrefix+deep_csv_tag_infos+labelName+postfix),
644  puppi_value_map = puppi_value_map,
645  vertex_associator = vertex_associator,
646  flip = flip),
647  process, task)
648 
649  if btagInfo == 'pfDeepDoubleXTagInfos':
650  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
651  btag.pfDeepDoubleXTagInfos.clone(
652  jets = jetSource,
653  vertices=pvSource,
654  secondary_vertices=svSource,
655  shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix),
656  ),
657  process, task)
658 
659  if btagInfo == 'pfHiggsInteractionNetTagInfos':
660  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
661  btag.pfHiggsInteractionNetTagInfos.clone(
662  jets = jetSource,
663  vertices = pvSource,
664  secondary_vertices = svSource,
665  pf_candidates = pfCandidates,
666  ),
667  process, task)
668 
669  if btagInfo == 'pfDeepBoostedJetTagInfos':
670  if pfCandidates.value() == 'packedPFCandidates':
671  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
672  if 'updated' not in jetSource.value().lower():
673  raise ValueError("Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value())
674  puppi_value_map = ""
675  vertex_associator = ""
676  elif pfCandidates.value() == 'particleFlow':
677  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
678  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
679  # daughters are the particles used in jet clustering, so already scaled by their puppi weights
680  # Uncomment the lines below after running pfDeepBoostedJetTagInfos with reco::PFCandidates becomes supported
681 # puppi_value_map = "puppi"
682 # vertex_associator = "primaryVertexAssociation:original"
683  else:
684  raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
685  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
686  btag.pfDeepBoostedJetTagInfos.clone(
687  jets = jetSource,
688  vertices = pvSource,
689  secondary_vertices = svSource,
690  pf_candidates = pfCandidates,
691  puppi_value_map = puppi_value_map,
692  vertex_associator = vertex_associator,
693  ),
694  process, task)
695 
696  if btagInfo == 'pfParticleNetTagInfos':
697  if pfCandidates.value() == 'packedPFCandidates':
698  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
699  puppi_value_map = ""
700  vertex_associator = ""
701  elif pfCandidates.value() == 'particleFlow':
702  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
703  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
704  puppi_value_map = "puppi"
705  vertex_associator = "primaryVertexAssociation:original"
706  else:
707  raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
708  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
709  btag.pfParticleNetTagInfos.clone(
710  jets = jetSource,
711  vertices = pvSource,
712  secondary_vertices = svSource,
713  pf_candidates = pfCandidates,
714  puppi_value_map = puppi_value_map,
715  vertex_associator = vertex_associator,
716  ),
717  process, task)
718 
719  if 'ParticleNetAK4TagInfos' in btagInfo:
720  if btagInfo == 'pfNegativeParticleNetAK4TagInfos':
721  secondary_vertices = btagPrefix + \
722  'inclusiveCandidateNegativeSecondaryVertices' + labelName + postfix
723  flip_ip_sign = True
724  sip3dSigMax = 10
725  else:
726  secondary_vertices = svSource
727  flip_ip_sign = False
728  sip3dSigMax = -1
729  if pfCandidates.value() == 'packedPFCandidates':
730  # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
731  puppi_value_map = ""
732  vertex_associator = ""
733  elif pfCandidates.value() == 'particleFlow':
734  raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
735  # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
736  puppi_value_map = "puppi"
737  vertex_associator = "primaryVertexAssociation:original"
738  else:
739  raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
740  addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
741  btag.pfParticleNetAK4TagInfos.clone(
742  jets = jetSource,
743  vertices = pvSource,
744  secondary_vertices = secondary_vertices,
745  pf_candidates = pfCandidates,
746  puppi_value_map = puppi_value_map,
747  vertex_associator = vertex_associator,
748  flip_ip_sign = flip_ip_sign,
749  sip3dSigMax = sip3dSigMax,
750  ),
751  process, task)
752 
753  acceptedTagInfos.append(btagInfo)
754  elif hasattr(toptag, btagInfo) :
755  acceptedTagInfos.append(btagInfo)
756  else:
757  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo))
758  ## setup all required btagDiscriminators
759  acceptedBtagDiscriminators = list()
760  for discriminator_name in btagDiscriminators :
761  btagDiscr = discriminator_name.split(':')[0] #split input tag to get the producer label
762  #print discriminator_name, '-->', btagDiscr
763  if hasattr(btag,btagDiscr):
764  newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name
765  if hasattr(process, newDiscr):
766  pass
767  elif hasattr(getattr(btag, btagDiscr), 'tagInfos'):
769  newDiscr,
770  getattr(btag, btagDiscr).clone(
771  tagInfos = cms.VInputTag(
772  *[ cms.InputTag(btagPrefix+x+labelName+postfix) \
773  for x in supportedBtagDiscr[discriminator_name][0] ]
774  )
775  ),
776  process,
777  task
778  )
779  elif hasattr(getattr(btag, btagDiscr), 'src'):
781  newDiscr,
782  getattr(btag, btagDiscr).clone(
783  src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
784  ),
785  process,
786  task
787  )
788  else:
789  raise ValueError('I do not know how to update %s it does not have neither "tagInfos" nor "src" attributes' % btagDiscr)
790  acceptedBtagDiscriminators.append(discriminator_name)
791  else:
792  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
793  #update meta-taggers, if any
794  for meta_tagger in present_meta:
795  btagDiscr = meta_tagger.split(':')[0] #split input tag to get the producer label
796  #print discriminator_name, '-->', btagDiscr
797  if hasattr(btag,btagDiscr):
798  newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name
799  if hasattr(process, newDiscr):
800  pass
801  else:
803  newDiscr,
804  getattr(btag, btagDiscr).clone(),
805  process,
806  task
807  )
808  for dependency in supportedMetaDiscr[meta_tagger]:
809  if ':' in dependency:
810  new_dep = btagPrefix+dependency.split(':')[0]+labelName+postfix+':'+dependency.split(':')[1]
811  else:
812  new_dep = btagPrefix+dependency+labelName+postfix
813  replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
814  replace.doIt(getattr(process, newDiscr), newDiscr)
815  acceptedBtagDiscriminators.append(meta_tagger)
816  else:
817  print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
818 
819  ## replace corresponding tags for pat jet production
820  patJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix) for x in acceptedTagInfos ] )
821  patJets.discriminatorSources = cms.VInputTag(*[
822  cms.InputTag(btagPrefix+x+labelName+postfix) \
823  if ':' not in x else \
824  cms.InputTag(btagPrefix+x.split(':')[0]+labelName+postfix+':'+x.split(':')[1]) \
825  for x in acceptedBtagDiscriminators
826  ])
827  if len(acceptedBtagDiscriminators) > 0 :
828  patJets.addBTagInfo = True
829  ## if re-running IVF
830  if runIVF:
831  if not tightBTagNTkHits:
832  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices': ## MiniAOD case
833  if not runIVFforCTagOnly: rerunningIVFMiniAOD()
834  else:
835  rerunningIVF()
836  from PhysicsTools.PatAlgos.tools.helpers import loadWithPrefix
837  ivfbTagInfos = ['pfInclusiveSecondaryVertexFinderTagInfos', 'pfInclusiveSecondaryVertexFinderAK8TagInfos', 'pfInclusiveSecondaryVertexFinderCA15TagInfos']
838  if any(i in acceptedTagInfos for i in ivfbTagInfos) and not runIVFforCTagOnly:
839  if not hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
840  loadWithPrefix(process, 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
841  if tightBTagNTkHits:
842  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
843  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinder')
844  _temp.minHits = cms.uint32(8)
845  ## MiniAOD case
846  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
847  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
848  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinder')
849  _temp.primaryVertices = pvSource
850  _temp.tracks = pfCandidates
851  if hasattr( process, btagPrefix+'candidateVertexArbitrator' ):
852  _temp = getattr(process, btagPrefix+'candidateVertexArbitrator')
853  _temp.primaryVertices = pvSource
854  _temp.tracks = pfCandidates
855  if hasattr( process, btagPrefix+'inclusiveCandidateSecondaryVertices' ) and not hasattr( process, svSource.getModuleLabel() ):
856  addToProcessAndTask(svSource.getModuleLabel(),
857  getattr(process, btagPrefix+'inclusiveCandidateSecondaryVertices').clone(),
858  process, task)
859  if any(i in acceptedTagInfos for i in ivfcTagInfos):
860  if not hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
861  loadWithPrefix(process, 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
862  if tightBTagNTkHits:
863  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
864  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinderCvsL')
865  _temp.minHits = cms.uint32(8)
866  ## MiniAOD case
867  if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
868  if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
869  _temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinderCvsL')
870  _temp.primaryVertices = pvSource
871  _temp.tracks = pfCandidates
872  if hasattr( process, btagPrefix+'candidateVertexArbitratorCvsL' ):
873  _temp = getattr(process, btagPrefix+'candidateVertexArbitratorCvsL')
874  _temp.primaryVertices = pvSource
875  _temp.tracks = pfCandidates
876  if hasattr( process, btagPrefix+'inclusiveCandidateSecondaryVerticesCvsL' ) and not hasattr( process, svSourceCvsL.getModuleLabel() ):
877  addToProcessAndTask(svSourceCvsL.getModuleLabel(),
878  getattr(process, btagPrefix+'inclusiveCandidateSecondaryVerticesCvsL').clone(),
879  process, task)
880  if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos:
881  if not hasattr( process, 'inclusiveVertexing' ):
882  process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
883  task.add(process.inclusiveVertexingTask)
884  task.add(process.inclusiveCandidateVertexingTask)
885  task.add(process.inclusiveCandidateVertexingCvsLTask)
886  if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
887  if not hasattr( process, 'inclusiveVertexing' ):
888  process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
889  task.add(process.inclusiveVertexingTask)
890  task.add(process.inclusiveCandidateVertexingTask)
891  task.add(process.inclusiveCandidateVertexingCvsLTask)
892  if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
893  if not hasattr( process, 'inclusiveSecondaryVerticesFiltered' ):
894  process.load( 'RecoBTag.SecondaryVertex.inclusiveSecondaryVerticesFiltered_cfi' )
895  task.add(process.inclusiveSecondaryVerticesFiltered)
896  task.add(process.bVertexFilter)
897  if not hasattr( process, 'bToCharmDecayVertexMerged' ):
898  process.load( 'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' )
899  task.add(process.bToCharmDecayVertexMerged)
900  if 'caTopTagInfos' in acceptedTagInfos :
901  patJets.addTagInfos = True
902  if not hasattr( process, 'caTopTagInfos' ) and not hasattr( process, 'caTopTagInfosAK8' ):
903  process.load( 'RecoJets.JetProducers.caTopTaggers_cff' )
904  task.add(process.caTopTaggersTask)
def rerunningIVFMiniAOD
Definition: jetTools.py:1953
def setupSVClustering
Definition: jetTools.py:227
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:37
def getPatAlgosToolsTask
Definition: helpers.py:13
def rerunningIVF
Definition: jetTools.py:1945
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def loadWithPrefix
Definition: helpers.py:43
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def addToProcessAndTask
Definition: helpers.py:28
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 
27 def setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, patJets, labelName, postfix):
28 
29  task = getPatAlgosToolsTask(process)
30 
31  ## determine type of jet constituents from jetSource; supported
32  ## jet constituent types are calo, pf, jpt, for pf also particleflow
33  ## is aloowed as part of the jetSource label, which might be used
34  ## in CommonTools.ParticleFlow
35  _type="NONE"
36  if jetCorrections[0].count('PF')>0:
37  _type='PF'
38  elif jetCorrections[0].count('Calo')>0:
39  _type='Calo'
40  elif jetCorrections[0].count('JPT')>0:
41  _type='JPT'
42  else:
43  raise TypeError("In addJetCollection: Jet energy corrections are only supported for PF, JPT and Calo jets.")
44  from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors
45  if 'patJetCorrFactors'+labelName+postfix in knownModules :
46  _newPatJetCorrFactors=getattr(process, 'patJetCorrFactors'+labelName+postfix)
47  _newPatJetCorrFactors.src=jetSource
48  _newPatJetCorrFactors.primaryVertices=pvSource
49  else:
50  addToProcessAndTask('patJetCorrFactors'+labelName+postfix,
51  patJetCorrFactors.clone(src=jetSource, primaryVertices=pvSource),
52  process, task)
53  _newPatJetCorrFactors=getattr(process, "patJetCorrFactors"+labelName+postfix)
54  _newPatJetCorrFactors.payload=jetCorrections[0]
55  _newPatJetCorrFactors.levels=jetCorrections[1]
56  ## check whether L1Offset or L1FastJet is part of levels
57  error=False
58  for x in jetCorrections[1]:
59  if x == 'L1Offset' :
60  if not error :
61  _newPatJetCorrFactors.useNPV=True
62  _newPatJetCorrFactors.primaryVertices='offlinePrimaryVertices'
63  _newPatJetCorrFactors.useRho=False
64  ## we set this to True now as a L1 correction type should appear only once
65  ## otherwise levels is miss configured
66  error=True
67  else:
68  raise ValueError("In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
69  once. Check the list of correction levels you requested to be applied: "+ jetCorrections[1])
70  if x == 'L1FastJet' :
71  if not error :
72  if _type == "JPT" :
73  raise TypeError("In addJetCollection: L1FastJet corrections are only supported for PF and Calo jets.")
74  ## configure module
75  _newPatJetCorrFactors.useRho=True
76  if "PF" in _type :
77  _newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAll')
78  else :
79  _newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAllCalo')
80  ## we set this to True now as a L1 correction type should appear only once
81  ## otherwise levels is miss configured
82  error=True
83  else:
84  raise ValueError("In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
85  once. Check the list of correction levels you requested to be applied: "+ jetCorrections[1])
86  patJets.jetCorrFactorsSource=cms.VInputTag(cms.InputTag('patJetCorrFactors'+labelName+postfix))
87  ## configure MET(Type1) corrections
88  if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '':
89  if not jetCorrections[2].lower() == 'type-1' and not jetCorrections[2].lower() == 'type-2':
90  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.\
91  Type-1 and Type-2 corrections applied). This choice is not case sensitive. Your choice was: "+ jetCorrections[2])
92  if _type == "JPT":
93  raise ValueError("In addJecCollection: MET(type1) corrections are not supported for JPTJets. Please set the MET-LABEL to \"None\" (as string in quatiation \
94  marks) and use raw tcMET together with JPTJets.")
95  ## set up jet correctors for MET corrections
96  process.load( "JetMETCorrections.Configuration.JetCorrectorsAllAlgos_cff") # FIXME: This adds a lot of garbage
97  # I second the FIXME comment on the last line. When I counted it, this brought in 344 EDProducers
98  # to be available to run unscheduled. All jet correctors, probably some small fraction of which
99  # are actually used.
100  task.add(process.jetCorrectorsAllAlgosTask)
101  _payloadType = jetCorrections[0].split(_type)[0].lower()+_type
102  if "PF" in _type :
103  addToProcessAndTask(jetCorrections[0]+'L1FastJet',
104  getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAll')),
105  process, task)
106  else :
107  addToProcessAndTask(jetCorrections[0]+'L1FastJet',
108  getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAllCalo')),
109  process, task)
110  addToProcessAndTask(jetCorrections[0]+'L1Offset', getattr(process, _payloadType+'L1OffsetCorrector').clone(), process, task)
111  addToProcessAndTask(jetCorrections[0]+'L2Relative', getattr(process, _payloadType+'L2RelativeCorrector').clone(), process, task)
112  addToProcessAndTask(jetCorrections[0]+'L3Absolute', getattr(process, _payloadType+'L3AbsoluteCorrector').clone(), process, task)
113  addToProcessAndTask(jetCorrections[0]+'L2L3Residual', getattr(process, _payloadType+'ResidualCorrector').clone(), process, task)
114  addToProcessAndTask(jetCorrections[0]+'CombinedCorrector',
115  cms.EDProducer( 'ChainedJetCorrectorProducer', correctors = cms.VInputTag()),
116  process, task)
117  for x in jetCorrections[1]:
118  if x != 'L1FastJet' and x != 'L1Offset' and x != 'L2Relative' and x != 'L3Absolute' and x != 'L2L3Residual':
119  raise ValueError('In addJetCollection: Unsupported JEC for MET(Type1). Currently supported jet correction levels are L1FastJet, L1Offset, L2Relative, L3Asolute, L2L3Residual. Requested was: %s'%(x))
120  else:
121  _corrector = _payloadType
122  if x == 'L1FastJet':
123  _corrector += 'L1Fastjet'
124  elif x == 'L2L3Residual':
125  _corrector += 'Residual'
126  else:
127  _corrector += x
128  _corrector += 'Corrector'
129  getattr(process, jetCorrections[0]+'CombinedCorrector').correctors.append(cms.InputTag(_corrector))
130 
131  ## set up MET(Type1) correction modules
132  _labelCorrName = labelName
133  if labelName != '':
134  _labelCorrName = 'For' + labelName
135  if _type == 'Calo':
136  from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType1
137  from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType2
138  from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1
139  from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1T2
141  jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix,
142  corrCaloMetType1.clone(src=jetSource,srcMET = "caloMetM",jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector')),
143  process, task)
145  jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix,
146  corrCaloMetType2.clone(srcUnclEnergySums = cms.VInputTag(
147  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),
148  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),
149  cms.InputTag('muCaloMetCorr'))),
150  process, task)
152  jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix,
153  caloMetT1.clone(src = "caloMetM", srcCorrections = cms.VInputTag(
154  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'))),
155  process, task)
156  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix,
157  caloMetT1T2.clone(src = "caloMetM", srcCorrections = cms.VInputTag(
158  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'),
159  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix))),
160  process, task)
161  elif _type == 'PF':
163  from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsPtrForMetCorr
164  from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsForMetCorr
168  from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1
169  from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1T2
170  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix,
171  pfJetsPtrForMetCorr.clone(src = jetSource), process, task)
173  jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix,
174  pfCandsNotInJetsPtrForMetCorr.clone(topCollection = jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix),
175  process, task)
177  jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix,
178  pfCandsNotInJetsForMetCorr.clone(src = jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix),
179  process, task)
181  jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix,
182  pfCandMETcorr.clone(src = cms.InputTag(jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix)),
183  process, task)
185  jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix,
186  corrPfMetType1.clone(src = jetSource, jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector')),
187  process, task) # FIXME: Originally w/o jet corrections?
188  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix,
189  corrPfMetType2.clone(srcUnclEnergySums = cms.VInputTag(
190  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),
191  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),
192  cms.InputTag(jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix))),
193  process, task)
194  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix,
195  pfMetT1.clone(srcCorrections = cms.VInputTag(
196  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'))),
197  process, task)
198  addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix,
199  pfMetT1T2.clone(srcCorrections = cms.VInputTag(
200  cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'),
201  jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix)),
202  process, task)
203  if 'Puppi' in jetSource.value() and pfCandidates.value() == 'particleFlow':
204  getattr(process,jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix).srcWeights = "puppiNoLep"
205 
206  ## common configuration for Calo and PF
207  if ('L1FastJet' in jetCorrections[1] or 'L1Fastjet' in jetCorrections[1]):
208  getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1FastJet')
209  #FIXME: What is wrong here?
210  #elif ('L1Offset' in jetCorrections[1]):
211  #getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1Offset')
212  else:
213  getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag('')
214 
216  if jetCorrections[2].lower() == 'type-1':
217  addToProcessAndTask('patMETs'+labelName+postfix,
218  patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix),
219  addMuonCorrections = False),
220  process, task)
221  elif jetCorrections[2].lower() == 'type-2':
222  addToProcessAndTask('patMETs'+labelName+postfix,
223  patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix),
224  addMuonCorrections = False),
225  process, task)
226 
def setupJetCorrections
Definition: jetTools.py:26
def getPatAlgosToolsTask
Definition: helpers.py:13
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def addToProcessAndTask
Definition: helpers.py:28
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().

228 def setupSVClustering(btagInfo, svClustering, algo, rParam, fatJets=cms.InputTag(''), groomedFatJets=cms.InputTag('')):
229  btagInfo.useSVClustering = cms.bool(svClustering)
230  btagInfo.jetAlgorithm = cms.string(algo)
231  btagInfo.rParam = cms.double(rParam)
232  ## if the jet is actually a subjet
233  if fatJets != cms.InputTag(''):
234  btagInfo.fatJets = fatJets
235  if groomedFatJets != cms.InputTag(''):
236  btagInfo.groomedFatJets = groomedFatJets
237 
def setupSVClustering
Definition: jetTools.py:227
def jetTools.undefinedLabelName (   obj)

Definition at line 1929 of file jetTools.py.

Referenced by jetTools.AddJetCollection.toolCode().

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

Definition at line 1936 of file jetTools.py.

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

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

Variable Documentation

dictionary jetTools.supportedJetAlgos
Initial value:
1 = {
2  'ak' : 'AntiKt'
3  , 'ca' : 'CambridgeAachen'
4  , 'kt' : 'Kt'
5 }

dictionary with supported jet clustering algorithms

Definition at line 12 of file jetTools.py.