CMS 3D CMS Logo

muonRecoMitigation.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
4 
5 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
6 
7 def muonRecoMitigation(process,
8  pfCandCollection,
9  runOnMiniAOD,
10  selection="",
11  muonCollection="",
12  cleanCollName="cleanMuonsPFCandidates",
13  cleaningScheme="all",
14  postfix=""):
15 
16  task = getPatAlgosToolsTask(process)
17 
18  sequence=cms.Sequence()
19 
20  if selection=="":
21  typeFix=""
22 
23  if runOnMiniAOD:
24  from RecoMET.METFilters.badGlobalMuonTaggersMiniAOD_cff import badGlobalMuonTaggerMAOD, cloneGlobalMuonTaggerMAOD
25  typeFix="MAOD"
26  badMuModule=badGlobalMuonTaggerMAOD
27  cloneMuModule=cloneGlobalMuonTaggerMAOD
28  else:
29  from RecoMET.METFilters.badGlobalMuonTaggersAOD_cff import badGlobalMuonTagger, cloneGlobalMuonTagger
30  badMuModule=badGlobalMuonTagger
31  cloneMuModule=cloneGlobalMuonTagger
32 
33  vtags=cms.VInputTag()
34  if cleaningScheme in ["bad","all","computeAllApplyBad","computeAllApplyClone"]:
35  addToProcessAndTask('badGlobalMuonTagger'+typeFix+postfix, badMuModule.clone(), process, task )
36  sequence +=getattr(process,"badGlobalMuonTagger"+typeFix+postfix)
37  if cleaningScheme in ["bad","computeAllApplyBad"]:
38  badMuonCollection = 'badGlobalMuonTagger'+typeFix+postfix+':bad'
39  if cleaningScheme in ["clone","duplicated","all","computeAllApplyBad","computeAllApplyClone"]:
40  addToProcessAndTask('cloneGlobalMuonTagger'+typeFix+postfix, cloneMuModule.clone(), process, task )
41  sequence +=getattr(process,"cloneGlobalMuonTagger"+typeFix+postfix)
42  if cleaningScheme in ["clone","duplicated","computeAllApplyClone"]:
43  badMuonCollection = 'cloneGlobalMuonTagger'+typeFix+postfix+':bad'
44 
45  if cleaningScheme=="all":
46  badMuonCollection="badMuons"+postfix
47  badMuonProducer = cms.EDProducer(
48  "CandViewMerger",
49  src = cms.VInputTag(
50  cms.InputTag('badGlobalMuonTagger'+typeFix+postfix,'bad'),
51  cms.InputTag('cloneGlobalMuonTagger'+typeFix+postfix,'bad'),
52  )
53  )
54  addToProcessAndTask(badMuonCollection, badMuonProducer, process, task)
55  sequence +=getattr(process, badMuonCollection )
56  else:
57  badMuonCollection="badMuons"+postfix
58  badMuonModule = cms.EDFilter("CandViewSelector",
59  src = cms.InputTag(muonCollection),
60  cut = cms.string(selection)
61  )
62 
63  # now cleaning ================================
64  cleanedPFCandCollection=cleanCollName+postfix
65  if runOnMiniAOD:
66  cleanedPFCandProducer = cms.EDProducer("CandPtrProjector",
67  src = cms.InputTag(pfCandCollection),
68  veto = cms.InputTag(badMuonCollection)
69  )
70  else:
71  cleanedPFCandProducer = cms.EDProducer("PFCandPtrProjector",
72  src = cms.InputTag(pfCandCollection),
73  veto = cms.InputTag(badMuonCollection)
74  )
75 
76  addToProcessAndTask(cleanedPFCandCollection, cleanedPFCandProducer, process, task)
77  sequence +=getattr(process, cleanedPFCandCollection )
78 
79  return sequence
def muonRecoMitigation(process, pfCandCollection, runOnMiniAOD, selection="", muonCollection="", cleanCollName="cleanMuonsPFCandidates", cleaningScheme="all", postfix="")
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:29
def getPatAlgosToolsTask(process)
Definition: helpers.py:14