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=str)
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)
45 "Use ak4PFL1FastL2L3 (ak4PFchsL1FastL2L3) for PFJets with (without) charged hadron subtraction, ak4CaloL1FastL2L3 for CaloJets", Type=str)
46 self.addParameter(self.
_defaultParameters,
'jetCorrLabelUpToL3Res',
'ak4PFL1FastL2L3Residual',
47 "Use ak4PFL1FastL2L3Residual (ak4PFchsL1FastL2L3Residual) for PFJets with (without) charged hadron subtraction, ak4CaloL1FastL2L3Residual for CaloJets", Type=str)
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 [
'electrons', electronCollection ],
94 [
'photons', photonCollection ],
95 [
'muons', muonCollection ],
96 [
'taus', tauCollection ] ]:
98 setattr(jetsNotOverlappingWithLeptons.checkOverlaps, collection[0], cms.PSet(
100 algorithm = cms.string(
"byDeltaR"),
101 preselection = cms.string(
""),
102 deltaR = cms.double(0.5),
103 checkRecoComponents = cms.bool(
False),
104 pairCut = cms.string(
""),
105 requireNoOverlaps = cms.bool(
True),
107 numOverlapCollections = numOverlapCollections + 1
108 lastJetCollection = jetCollection.value()
109 if numOverlapCollections >= 1:
110 lastJetCollection = \
112 [ jetCollection.value(),
"NotOverlappingWithLeptonsForJetMEtUncertainty" ],
113 uncertaintySequence, postfix)
114 cleanedJetCollection = lastJetCollection
116 return ( lastJetCollection, cleanedJetCollection )
120 electronCollection =
None,
121 photonCollection =
None,
122 muonCollection =
None,
123 tauCollection =
None,
124 jetCollection =
None, cleanedJetCollection =
None,
125 lastJetCollection =
None, addShiftedResJetCollections =
False,
126 jetCorrLabelUpToL3 =
None, jetCorrLabelUpToL3Res =
None,
127 jecUncertaintyFile =
None, jecUncertaintyTag =
None,
128 jetSmearFileName=
None, jetSmearHistogram=
None,
129 varyByNsigmas =
None,
132 shiftedParticleSequence = cms.Sequence()
133 shiftedParticleCollections = {}
134 collectionsToKeep = []
137 shiftedParticleCollections[
'cleanedJetCollection' ] = cleanedJetCollection
143 print "Warning, jet collection %s does not exists, no energy resolution shifting performed in PAT" % jetCollection
145 if addShiftedResJetCollections:
146 variations = {
"ResUp":-1.,
"ResDown":1. }
147 for var
in variations.keys():
148 jetCollectionToKeep = \
150 [
"smeared", jetCollection, var ],
151 jetSmearFileName,jetSmearHistogram,jetResolutions,
152 varyByNsigmas, variations[ var ],
153 shiftedParticleSequence, postfix)
154 jetCol={
'jetCollection%s'%var:jetCollectionToKeep}
155 shiftedParticleCollections.update( jetCol )
156 collectionsToKeep.append( jetCollectionToKeep )
162 print "Warning, jet collection %s does not exists, no energy shifting performed in PAT" % jetCollection
165 process,jetCollection,lastJetCollection,
166 jetCorrLabelUpToL3, jetCorrLabelUpToL3Res,
167 jecUncertaintyFile, jecUncertaintyTag,
168 varyByNsigmas, shiftedParticleSequence,
170 shiftedParticleCollections.update( shiftedJetsCollections )
171 collectionsToKeep.extend( jetsCollectionsToKeep )
177 print "Warning, electron collection %s does not exists, no energy shifting performed in PAT" % electronCollection
180 process,
"electron", electronCollection,
181 varyByNsigmas,shiftedParticleSequence,
184 shiftedParticleCollections.update( shiftedElectronsCollections )
185 collectionsToKeep.extend( electronsCollectionsToKeep )
191 print "Warning, photon collection %s does not exists, no energy shifting performed in PAT" % photonCollection
194 process,
"photon", photonCollection,
195 varyByNsigmas,shiftedParticleSequence,
197 shiftedParticleCollections.update( shiftedPhotonsCollections )
198 collectionsToKeep.extend( photonsCollectionsToKeep )
204 print "Warning, muon collection %s does not exists, no energy shifting performed in PAT" % muonCollection
207 varyByNsigmas,shiftedParticleSequence,
209 shiftedParticleCollections.update( shiftedMuonsCollections )
210 collectionsToKeep.extend( muonsCollectionsToKeep )
216 print "Warning, tau collection %s does not exists, no energy shifting performed in PAT" % tauCollection
219 varyByNsigmas,shiftedParticleSequence,
221 shiftedParticleCollections.update( shiftedTausCollections )
222 collectionsToKeep.extend( tausCollectionsToKeep )
225 return ( shiftedParticleSequence, shiftedParticleCollections, collectionsToKeep )
232 particleCollection, particleType, shiftType, particleCollectionShiftUp, particleCollectionShiftDown,
234 pfCandCollection, postfix):
236 srcUnshiftedObjects = particleCollection
237 if isinstance(srcUnshiftedObjects, cms.InputTag):
238 srcUnshiftedObjects = srcUnshiftedObjects.value()
239 moduleShiftUp = cms.EDProducer(
"ShiftedPFCandidateProducerByMatchedObject",
240 srcPFCandidates = pfCandCollection,
241 srcUnshiftedObjects = cms.InputTag(srcUnshiftedObjects),
242 srcShiftedObjects = cms.InputTag(particleCollectionShiftUp),
243 dRmatch_PFCandidate = cms.double(dRmatch)
245 moduleNameShiftUp =
"pfCandidates%s%sUp%s" % (particleType, shiftType, postfix)
246 setattr(process, moduleNameShiftUp, moduleShiftUp)
247 metUncertaintySequence += moduleShiftUp
249 moduleShiftDown = moduleShiftUp.clone(
250 srcShiftedObjects = cms.InputTag(particleCollectionShiftDown)
252 moduleNameShiftDown =
"pfCandidates%s%sDown%s" % (particleType, shiftType, postfix)
253 setattr(process, moduleNameShiftDown, moduleShiftDown)
254 metUncertaintySequence += moduleShiftDown
256 return ( moduleNameShiftUp, moduleNameShiftDown )
258 def _getLeptonsForPFMEtInput(self, shiftedParticleCollections, substituteKeyUnshifted = None, substituteKeyShifted = None, postfix=""):
260 for collectionName
in [
'electronCollection',
264 if self._isValidInputTag(shiftedParticleCollections[collectionName]):
265 if substituteKeyUnshifted
is not None and substituteKeyUnshifted
in shiftedParticleCollections.keys()
and \
266 substituteKeyShifted
is not None and substituteKeyShifted
in shiftedParticleCollections.keys()
and \
267 shiftedParticleCollections[collectionName] == shiftedParticleCollections[substituteKeyUnshifted]:
268 retVal.append(cms.InputTag(shiftedParticleCollections[substituteKeyShifted]))
270 retVal.append(shiftedParticleCollections[collectionName])
274 patMEtCollection, metCollection,
275 collectionsToKeep, postfix):
277 module = patMETs.clone(
278 metSource = cms.InputTag(metCollection),
279 addMuonCorrections = cms.bool(
False),
280 genMETSource = cms.InputTag(
'genMetTrue')
282 patMEtCollectionName = patMEtCollection+postfix
283 setattr(process, patMEtCollectionName, module)
284 metUncertaintySequence += module
285 collectionsToKeep.append(patMEtCollectionName)
288 electronCollection =
None,
289 photonCollection =
None,
290 muonCollection =
None,
291 tauCollection =
None,
292 jetCollection =
None,
295 jetSmearFileName =
None,
296 jetSmearHistogram =
None,
297 jetCorrPayloadName =
None,
298 jetCorrLabelUpToL3 =
None,
299 jetCorrLabelUpToL3Res =
None,
300 jecUncertaintyFile =
None,
301 jecUncertaintyTag =
None,
302 varyByNsigmas =
None,
303 addToPatDefaultSequence =
None,
311 if jetCorrLabel
is None:
313 if doSmearJets
is None:
315 if jetSmearFileName
is None:
317 if jetSmearHistogram
is None:
319 if jetCorrPayloadName
is None:
321 if jetCorrLabelUpToL3
is None:
323 if jetCorrLabelUpToL3Res
is None:
325 if jecUncertaintyFile
is None:
327 if jecUncertaintyTag
is None:
329 if varyByNsigmas
is None:
331 if addToPatDefaultSequence
is None:
333 if outputModule
is None:
338 self.setParameter(
'electronCollection', electronCollection)
339 self.setParameter(
'photonCollection', photonCollection)
340 self.setParameter(
'muonCollection', muonCollection)
341 self.setParameter(
'tauCollection', tauCollection)
342 self.setParameter(
'jetCollection', jetCollection)
343 self.setParameter(
'jetCorrLabel', jetCorrLabel)
344 self.setParameter(
'doSmearJets', doSmearJets)
345 self.setParameter(
'jetSmearFileName', jetSmearFileName)
346 self.setParameter(
'jetSmearHistogram', jetSmearHistogram)
347 self.setParameter(
'jetCorrPayloadName', jetCorrPayloadName)
348 self.setParameter(
'jetCorrLabelUpToL3', jetCorrLabelUpToL3)
349 self.setParameter(
'jetCorrLabelUpToL3Res', jetCorrLabelUpToL3Res)
350 self.setParameter(
'jecUncertaintyFile', jecUncertaintyFile)
351 self.setParameter(
'jecUncertaintyTag', jecUncertaintyTag)
352 self.setParameter(
'varyByNsigmas', varyByNsigmas)
353 self.setParameter(
'addToPatDefaultSequence', addToPatDefaultSequence)
354 self.setParameter(
'outputModule', outputModule)
355 self.setParameter(
'postfix', postfix)