6 from PhysicsTools.PatAlgos.tools.trigTools
import _addEventContent
19 """ Base class for estimating systematic uncertainties on MET """
20 _label=
'JetMEtUncertaintyTools'
21 _defaultParameters=dicttypes.SortedKeysDict()
23 ConfigToolBase.__init__(self)
24 self.addParameter(self.
_defaultParameters,
'electronCollection', cms.InputTag(
'cleanPatElectrons'),
25 "Input electron collection", Type=cms.InputTag, acceptNoneValue=
True)
27 "Input photon collection", Type=cms.InputTag, acceptNoneValue=
True)
28 self.addParameter(self.
_defaultParameters,
'muonCollection', cms.InputTag(
'cleanPatMuons'),
29 "Input muon collection", Type=cms.InputTag, acceptNoneValue=
True)
30 self.addParameter(self.
_defaultParameters,
'tauCollection', cms.InputTag(
'cleanPatTaus'),
31 "Input tau collection", Type=cms.InputTag, acceptNoneValue=
True)
32 self.addParameter(self.
_defaultParameters,
'jetCollection', cms.InputTag(
'cleanPatJets'),
33 "Input jet collection", Type=cms.InputTag)
35 "NOTE: use 'L3Absolute' for MC/'L2L3Residual' for Data", Type=cms.InputTag)
37 "Flag to enable/disable jet smearing to better match MC to Data", Type=bool)
38 self.addParameter(self.
_defaultParameters,
'jetSmearFileName',
'PhysicsTools/PatUtils/data/pfJetResolutionMCtoDataCorrLUT.root',
39 "Name of ROOT file containing histogram with jet smearing factors", Type=str)
40 self.addParameter(self.
_defaultParameters,
'jetSmearHistogram',
'pfJetResolutionMCtoDataCorrLUT',
41 "Name of histogram with jet smearing factors", Type=str)
43 "Use AK4PF for PFJets, AK4Calo for CaloJets", Type=str)
44 self.addParameter(self.
_defaultParameters,
'jetCorrLabelUpToL3', cms.InputTag(
'ak4PFL1FastL2L3Corrector'),
45 "Use ak4PFL1FastL2L3Corrector (ak4PFchsL1FastL2L3Corrector) for PFJets with (without) charged hadron subtraction, ak4CaloL1FastL2L3Corrector for CaloJets", Type=cms.InputTag)
46 self.addParameter(self.
_defaultParameters,
'jetCorrLabelUpToL3Res', cms.InputTag(
'ak4PFL1FastL2L3ResidualCorrector'),
47 "Use ak4PFL1FastL2L3ResidualCorrector (ak4PFchsL1FastL2L3ResiduaCorrectorl) for PFJets with (without) charged hadron subtraction, ak4CaloL1FastL2L3ResidualCorrector for CaloJets", Type=cms.InputTag)
48 self.addParameter(self.
_defaultParameters,
'jecUncertaintyFile',
"PhysicsTools/PatUtils/data/Summer13_V1_DATA_UncertaintySources_AK5PF.txt",
49 "Name of file containing jet energy uncertainty parameters", Type=str)
51 "Name of tag for Data/MC jet energy uncertainties", Type=str)
53 "Number of standard deviations by which energies are varied", Type=float)
55 "Flag to enable/disable that metUncertaintySequence is inserted into patDefaultSequence", Type=bool)
57 "Module label of PoolOutputModule (empty label indicates no PoolOutputModule is to be configured)", Type=str)
59 "Technical parameter to identify the resulting sequence and its modules (allows multiple calls in a job)", Type=str)
71 elif type(input) == str:
72 retVal = cms.InputTag(input)
79 electronCollection, photonCollection,
80 muonCollection, tauCollection,
81 uncertaintySequence, postfix =
""):
85 jetsNotOverlappingWithLeptons = cms.EDProducer(
"PATJetCleaner",
87 preselection = cms.string(
''),
88 checkOverlaps = cms.PSet(),
89 finalCut = cms.string(
'')
91 numOverlapCollections = 0
93 if "ak4" in jetCollection.moduleLabel.lower(): radius=0.4
95 [
'electrons', electronCollection ],
96 [
'photons', photonCollection ],
97 [
'muons', muonCollection ],
98 [
'taus', tauCollection ] ]:
100 setattr(jetsNotOverlappingWithLeptons.checkOverlaps, collection[0], cms.PSet(
102 algorithm = cms.string(
"byDeltaR"),
103 preselection = cms.string(
""),
104 deltaR = cms.double(radius),
105 checkRecoComponents = cms.bool(
False),
106 pairCut = cms.string(
""),
107 requireNoOverlaps = cms.bool(
True),
109 numOverlapCollections = numOverlapCollections + 1
110 lastJetCollection = jetCollection.value()
111 if numOverlapCollections >= 1:
112 lastJetCollection = \
114 [ jetCollection.value(),
"NotOverlappingWithLeptonsForJetMEtUncertainty" ],
115 uncertaintySequence, postfix)
116 cleanedJetCollection = lastJetCollection
118 return ( lastJetCollection, cleanedJetCollection )
122 electronCollection =
None,
123 photonCollection =
None,
124 muonCollection =
None,
125 tauCollection =
None,
126 jetCollection =
None, cleanedJetCollection =
None,
127 lastJetCollection =
None, addShiftedResJetCollections =
False,
128 jetCorrLabelUpToL3 =
None, jetCorrLabelUpToL3Res =
None,
129 jecUncertaintyFile =
None, jecUncertaintyTag =
None,
130 jetSmearFileName=
None, jetSmearHistogram=
None,
131 varyByNsigmas =
None,
134 shiftedParticleSequence = cms.Sequence()
135 shiftedParticleCollections = {}
136 collectionsToKeep = []
139 shiftedParticleCollections[
'cleanedJetCollection' ] = cleanedJetCollection
145 print "INFO : jet collection %s does not exists, no energy resolution shifting will be performed in MET uncertainty tools" % jetCollection
147 if addShiftedResJetCollections:
148 variations = {
"ResUp":-1.,
"ResDown":1. }
149 for var
in variations.keys():
150 jetCollectionToKeep = \
152 [
"smeared", jetCollection, var ],
153 jetSmearFileName,jetSmearHistogram,jetResolutions,
154 varyByNsigmas, variations[ var ],
155 shiftedParticleSequence, postfix)
156 jetCol={
'jetCollection%s'%var:jetCollectionToKeep}
157 shiftedParticleCollections.update( jetCol )
158 collectionsToKeep.append( jetCollectionToKeep )
164 print "INFO : jet collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % jetCollection
167 process,jetCollection,lastJetCollection,
168 jetCorrLabelUpToL3, jetCorrLabelUpToL3Res,
169 jecUncertaintyFile, jecUncertaintyTag,
170 varyByNsigmas, shiftedParticleSequence,
172 shiftedParticleCollections.update( shiftedJetsCollections )
173 collectionsToKeep.extend( jetsCollectionsToKeep )
179 print "INFO : electron collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % electronCollection
182 process,
"electron", electronCollection,
183 varyByNsigmas,shiftedParticleSequence,
186 shiftedParticleCollections.update( shiftedElectronsCollections )
187 collectionsToKeep.extend( electronsCollectionsToKeep )
193 print "INFO : photon collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % photonCollection
196 process,
"photon", photonCollection,
197 varyByNsigmas,shiftedParticleSequence,
199 shiftedParticleCollections.update( shiftedPhotonsCollections )
200 collectionsToKeep.extend( photonsCollectionsToKeep )
206 print "INFO : muon collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % muonCollection
209 varyByNsigmas,shiftedParticleSequence,
211 shiftedParticleCollections.update( shiftedMuonsCollections )
212 collectionsToKeep.extend( muonsCollectionsToKeep )
218 print "INFO : tau collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % tauCollection
221 varyByNsigmas,shiftedParticleSequence,
223 shiftedParticleCollections.update( shiftedTausCollections )
224 collectionsToKeep.extend( tausCollectionsToKeep )
227 return ( shiftedParticleSequence, shiftedParticleCollections, collectionsToKeep )
234 particleCollection, particleType, shiftType, particleCollectionShiftUp, particleCollectionShiftDown,
236 pfCandCollection, postfix):
238 srcUnshiftedObjects = particleCollection
239 if isinstance(srcUnshiftedObjects, cms.InputTag):
240 srcUnshiftedObjects = srcUnshiftedObjects.value()
241 moduleShiftUp = cms.EDProducer(
"ShiftedPFCandidateProducerByMatchedObject",
242 srcPFCandidates = pfCandCollection,
243 srcUnshiftedObjects = cms.InputTag(srcUnshiftedObjects),
244 srcShiftedObjects = cms.InputTag(particleCollectionShiftUp),
245 dRmatch_PFCandidate = cms.double(dRmatch)
247 moduleNameShiftUp =
"pfCandidates%s%sUp%s" % (particleType, shiftType, postfix)
248 setattr(process, moduleNameShiftUp, moduleShiftUp)
249 metUncertaintySequence += moduleShiftUp
251 moduleShiftDown = moduleShiftUp.clone(
252 srcShiftedObjects = cms.InputTag(particleCollectionShiftDown)
254 moduleNameShiftDown =
"pfCandidates%s%sDown%s" % (particleType, shiftType, postfix)
255 setattr(process, moduleNameShiftDown, moduleShiftDown)
256 metUncertaintySequence += moduleShiftDown
258 moduleNameShifts = {
'Up':moduleNameShiftUp ,
'Down':moduleNameShiftDown }
259 return moduleNameShifts
262 def _getLeptonsForPFMEtInput(self, shiftedParticleCollections, substituteKeyUnshifted = None, substituteKeyShifted = None, postfix=""):
264 for particleCol
in shiftedParticleCollections.keys():
265 if not (particleCol.find(
"Jet")
or particleCol.find(
"jet") )
and isValidInputTag(shiftedParticleCollections[collectionName]):
266 print collectionName,
"==>:"+shiftedParticleCollections[collectionName]
267 if substituteKeyUnshifted
is not None and substituteKeyUnshifted
in shiftedParticleCollections.keys()
and \
268 substituteKeyShifted
is not None and substituteKeyShifted
in shiftedParticleCollections.keys()
and \
269 shiftedParticleCollections[collectionName] == shiftedParticleCollections[substituteKeyUnshifted]:
270 retVal.append(cms.InputTag(shiftedParticleCollections[substituteKeyShifted]))
272 retVal.append(shiftedParticleCollections[collectionName])
276 metCollection, patMEtCollection,
277 collectionsToKeep, postfix):
279 module = patMETs.clone(
280 metSource = cms.InputTag(metCollection),
281 addMuonCorrections = cms.bool(
False),
282 genMETSource = cms.InputTag(
'genMetTrue')
284 patMEtCollectionName = patMEtCollection+postfix
285 setattr(process, patMEtCollectionName, module)
286 metUncertaintySequence += module
287 collectionsToKeep.append(patMEtCollectionName)
291 electronCollection =
None,
292 photonCollection =
None,
293 muonCollection =
None,
294 tauCollection =
None,
295 jetCollection =
None,
298 jetSmearFileName =
None,
299 jetSmearHistogram =
None,
300 jetCorrPayloadName =
None,
301 jetCorrLabelUpToL3 =
None,
302 jetCorrLabelUpToL3Res =
None,
303 jecUncertaintyFile =
None,
304 jecUncertaintyTag =
None,
305 varyByNsigmas =
None,
306 addToPatDefaultSequence =
None,
314 if jetCorrLabel
is None:
316 if doSmearJets
is None:
318 if jetSmearFileName
is None:
320 if jetSmearHistogram
is None:
322 if jetCorrPayloadName
is None:
324 if jetCorrLabelUpToL3
is None:
326 if jetCorrLabelUpToL3Res
is None:
328 if jecUncertaintyFile
is None:
330 if jecUncertaintyTag
is None:
332 if varyByNsigmas
is None:
334 if addToPatDefaultSequence
is None:
336 if outputModule
is None:
341 self.setParameter(
'electronCollection', electronCollection)
342 self.setParameter(
'photonCollection', photonCollection)
343 self.setParameter(
'muonCollection', muonCollection)
344 self.setParameter(
'tauCollection', tauCollection)
345 self.setParameter(
'jetCollection', jetCollection)
346 self.setParameter(
'jetCorrLabel', jetCorrLabel)
347 self.setParameter(
'doSmearJets', doSmearJets)
348 self.setParameter(
'jetSmearFileName', jetSmearFileName)
349 self.setParameter(
'jetSmearHistogram', jetSmearHistogram)
350 self.setParameter(
'jetCorrPayloadName', jetCorrPayloadName)
351 self.setParameter(
'jetCorrLabelUpToL3', jetCorrLabelUpToL3)
352 self.setParameter(
'jetCorrLabelUpToL3Res', jetCorrLabelUpToL3Res)
353 self.setParameter(
'jecUncertaintyFile', jecUncertaintyFile)
354 self.setParameter(
'jecUncertaintyTag', jecUncertaintyTag)
355 self.setParameter(
'varyByNsigmas', varyByNsigmas)
356 self.setParameter(
'addToPatDefaultSequence', addToPatDefaultSequence)
357 self.setParameter(
'outputModule', outputModule)
358 self.setParameter(
'postfix', postfix)