CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
extraSlimmedMETs_MuEGFixMoriond2017.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag,cloneProcessingSnippet,addKeepStatement
3 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
4 
5 def addExtraMETCollections(process, unCleanPFCandidateCollection,
6  cleanElectronCollection,
7  cleanPhotonCollection,
8  unCleanElectronCollection,
9  unCleanPhotonCollection ):
10 
11  task = getPatAlgosToolsTask(process)
12 
13  # Muon/EGamma un/corrected pfMET ============
14  from PhysicsTools.PatUtils.tools.corMETFromMuonAndEG import corMETFromMuonAndEG
15  from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncForMiniAODProduction
16 
17  # uncorrected MET
18  cloneProcessingSnippet(process, getattr(process,"makePatJets"),"BackupAllEvents", addToTask = True )
19  massSearchReplaceAnyInputTag(getattr(process,"makePatJetsBackupAllEvents"), "ak4PFJetsCHS", "ak4PFJetsCHSBackupAllEvents")
20  massSearchReplaceAnyInputTag(getattr(process,"makePatJetsBackupAllEvents"), "pfCandidatesBadMuonsCleaned", "particleFlow")
21  del process.patJetsBackupAllEvents.userData
22  process.patJetsBackupAllEvents.addAssociatedTracks = cms.bool(False)
23  process.patJetsBackupAllEvents.addBTagInfo = cms.bool(False)
24  process.patJetsBackupAllEvents.addDiscriminators = cms.bool(False)
25  process.patJetsBackupAllEvents.addGenJetMatch = cms.bool(False)
26  process.patJetsBackupAllEvents.addGenPartonMatch = cms.bool(False)
27  process.patJetsBackupAllEvents.addJetCharge = cms.bool(False)
28  process.patJetsBackupAllEvents.addJetCorrFactors = cms.bool(True)
29  process.patJetsBackupAllEvents.addJetFlavourInfo = cms.bool(False)
30  process.patJetsBackupAllEvents.addJetID = cms.bool(False)
31  process.patJetsBackupAllEvents.addPartonJetMatch = cms.bool(False)
32  process.patJetsBackupAllEvents.addResolutions = cms.bool(False)
33  process.patJetsBackupAllEvents.addTagInfos = cms.bool(False)
34  process.patJetsBackupAllEvents.discriminatorSources = cms.VInputTag()
35  process.patJetsBackupAllEvents.embedGenJetMatch = cms.bool(False)
36 
38  metType="PF",
39  pfCandColl=cms.InputTag(unCleanPFCandidateCollection),
40  recoMetFromPFCs=True,
41  jetCollUnskimmed="patJetsBackupAllEvents",
42  postfix="Uncorrected"
43  )
44 
45  if not hasattr(process, "slimmedMETs"):
46  process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
47 
48  process.slimmedMETsUncorrected = process.slimmedMETs.clone()
49  task.add(process.slimmedMETs)
50  process.slimmedMETsUncorrected.src = cms.InputTag("patPFMetT1Uncorrected")
51  process.slimmedMETsUncorrected.rawVariation = cms.InputTag("patPFMetUncorrected")
52  process.slimmedMETsUncorrected.t1Uncertainties = cms.InputTag("patPFMetT1%sUncorrected")
53  process.slimmedMETsUncorrected.t01Variation = cms.InputTag("patPFMetT0pcT1Uncorrected")
54  process.slimmedMETsUncorrected.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sUncorrected")
55  process.slimmedMETsUncorrected.tXYUncForRaw = cms.InputTag("patPFMetTxyUncorrected")
56  process.slimmedMETsUncorrected.tXYUncForT1 = cms.InputTag("patPFMetT1TxyUncorrected")
57  process.slimmedMETsUncorrected.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyUncorrected")
58  process.slimmedMETsUncorrected.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyUncorrected")
59  process.slimmedMETsUncorrected.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyUncorrected")
60  del process.slimmedMETsUncorrected.caloMET
61 
62  # EG corrected MET
63  corMETFromMuonAndEG(process,
64  pfCandCollection="", #not needed
65  electronCollection=unCleanElectronCollection,
66  photonCollection=unCleanPhotonCollection,
67  corElectronCollection=cleanElectronCollection,
68  corPhotonCollection=cleanPhotonCollection,
69  allMETEGCorrected=True,
70  muCorrection=False,
71  eGCorrection=True,
72  runOnMiniAOD=False,
73  eGPFix="Uncorrected",
74  postfix="EGOnly"
75  )
76  process.slimmedMETsEGClean = process.slimmedMETs.clone()
77  task.add(process.slimmedMETsEGClean)
78  process.slimmedMETsEGClean.src = cms.InputTag("patPFMetT1UncorrectedEGOnly")
79  process.slimmedMETsEGClean.rawVariation = cms.InputTag("patPFMetRawUncorrectedEGOnly")
80  process.slimmedMETsEGClean.t1Uncertainties = cms.InputTag("patPFMetT1%sUncorrectedEGOnly")
81  process.slimmedMETsEGClean.t01Variation = cms.InputTag("patPFMetT0pcT1UncorrectedEGOnly")
82  process.slimmedMETsEGClean.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sUncorrectedEGOnly")
83  process.slimmedMETsEGClean.tXYUncForRaw = cms.InputTag("patPFMetTxyUncorrectedEGOnly")
84  process.slimmedMETsEGClean.tXYUncForT1 = cms.InputTag("patPFMetT1TxyUncorrectedEGOnly")
85  process.slimmedMETsEGClean.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyUncorrectedEGOnly")
86  process.slimmedMETsEGClean.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyUncorrectedEGOnly")
87  process.slimmedMETsEGClean.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyUncorrectedEGOnly")
88  del process.slimmedMETsEGClean.caloMET
89 
90  # fully corrected MET
91  corMETFromMuonAndEG(process,
92  pfCandCollection="", #not needed
93  electronCollection=unCleanElectronCollection,
94  photonCollection=unCleanPhotonCollection,
95  corElectronCollection=cleanElectronCollection,
96  corPhotonCollection=cleanPhotonCollection,
97  allMETEGCorrected=True,
98  muCorrection=False,
99  eGCorrection=True,
100  runOnMiniAOD=False,
101  postfix="MuEGClean"
102  )
103  process.slimmedMETsMuEGClean = process.slimmedMETs.clone()
104  task.add(process.slimmedMETsMuEGClean)
105  process.slimmedMETsMuEGClean.src = cms.InputTag("patPFMetT1MuEGClean")
106  process.slimmedMETsMuEGClean.rawVariation = cms.InputTag("patPFMetRawMuEGClean")
107  process.slimmedMETsMuEGClean.t1Uncertainties = cms.InputTag("patPFMetT1%sMuEGClean")
108  process.slimmedMETsMuEGClean.t01Variation = cms.InputTag("patPFMetT0pcT1MuEGClean")
109  process.slimmedMETsMuEGClean.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sMuEGClean")
110  process.slimmedMETsMuEGClean.tXYUncForRaw = cms.InputTag("patPFMetTxyMuEGClean")
111  process.slimmedMETsMuEGClean.tXYUncForT1 = cms.InputTag("patPFMetT1TxyMuEGClean")
112  process.slimmedMETsMuEGClean.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyMuEGClean")
113  process.slimmedMETsMuEGClean.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyMuEGClean")
114  process.slimmedMETsMuEGClean.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyMuEGClean")
115  del process.slimmedMETsMuEGClean.caloMET
116 
117  addKeepStatement(process, "keep *_slimmedMETs_*_*",
118  ["keep *_slimmedMETsUncorrected_*_*", "keep *_slimmedMETsEGClean_*_*", "keep *_slimmedMETsMuEGClean_*_*"])
119 
120 
121 
122 def addExtraPuppiMETCorrections(process,
123  cleanPFCandidateCollection,
124  unCleanPFCandidateCollection,
125  cleanElectronCollection,
126  cleanPhotonCollection,
127  unCleanElectronCollection,
128  unCleanPhotonCollection
129  ):
130 
131  task = getPatAlgosToolsTask(process)
132 
133  from PhysicsTools.PatUtils.tools.corMETFromMuonAndEG import corMETFromMuonAndEG
134  #EG correction for puppi, muon correction done right above
135  corMETFromMuonAndEG(process,
136  metType="Puppi",
137  electronCollection=unCleanElectronCollection,
138  photonCollection=unCleanPhotonCollection,
139  corElectronCollection=cleanElectronCollection,
140  corPhotonCollection=cleanPhotonCollection,
141  allMETEGCorrected=True,
142  muCorrection=False,
143  eGCorrection=True,
144  runOnMiniAOD=False,
145  eGPfCandMatching=True,
146  eGPFix="Puppi",
147  postfix="PuppiClean"
148  )
149 
150  if not hasattr(process, "slimmedMETs"):
151  process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
152  task.add(process.slimmedMETs)
153 
154  process.slimmedMETsPuppi.src = cms.InputTag("patPFMetT1PuppiPuppiClean")
155  process.slimmedMETsPuppi.rawVariation = cms.InputTag("patPFMetRawPuppiPuppiClean")
156  process.slimmedMETsPuppi.t1Uncertainties = cms.InputTag("patPFMetT1%sPuppiPuppiClean")
157  process.slimmedMETsPuppi.t01Variation = cms.InputTag("patPFMetT0pcT1PuppiPuppiClean")
158  process.slimmedMETsPuppi.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sPuppiPuppiClean")
159  process.slimmedMETsPuppi.tXYUncForRaw = cms.InputTag("patPFMetTxyPuppiPuppiClean")
160  process.slimmedMETsPuppi.tXYUncForT1 = cms.InputTag("patPFMetT1TxyPuppiPuppiClean")
161  process.slimmedMETsPuppi.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyPuppiPuppiClean")
162  process.slimmedMETsPuppi.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyPuppiPuppiClean")
163  process.slimmedMETsPuppi.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyPuppiPuppiClean")
164  #del process.slimmedMETsPuppi.caloMET
165 
166  #EGamma correction
167  process.puppiMETEGCor = cms.EDProducer("CorrMETDataExtractor",
168  corrections = cms.VInputTag(
169  cms.InputTag("corMETPhotonPuppiClean"),
170  cms.InputTag("corMETElectronPuppiClean") )
171  )
172  task.add(process.puppiMETEGCor)
173 
174  #Muon correction, restarting from PF candidates to take the weights
175  process.puppiMuonCorrection = cms.EDProducer("ShiftedParticleMETcorrInputProducer",
176  srcOriginal = cms.InputTag(unCleanPFCandidateCollection),
177  srcShifted = cms.InputTag(cleanPFCandidateCollection),
178  srcWeights = cms.InputTag("")
179  )
180 
181  task.add(process.puppiMuonCorrection)
182 
183  process.puppiMETMuCor = cms.EDProducer("CorrMETDataExtractor",
184  corrections = cms.VInputTag(
185  cms.InputTag("puppiMuonCorrection") )
186  )
187  task.add(process.puppiMETMuCor)
188  addKeepStatement(process, "keep *_slimmedMETsPuppi_*_*",
189  ["keep *_puppiMETEGCor_*_*", "keep *_puppiMETMuCor_*_*"])
def cloneProcessingSnippet
Definition: helpers.py:257
def getPatAlgosToolsTask
Definition: helpers.py:13
def massSearchReplaceAnyInputTag
Definition: MassReplace.py:79
def addKeepStatement
Definition: helpers.py:354