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 [
'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 "INFO : jet collection %s does not exists, no energy resolution shifting will be performed in MET uncertainty tools" % 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 "INFO : jet collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % jetCollection
165 process,jetCollection,lastJetCollection,
166 jetCorrLabelUpToL3, jetCorrLabelUpToL3Res,
167 jecUncertaintyFile, jecUncertaintyTag,
168 varyByNsigmas, shiftedParticleSequence,
170 shiftedParticleCollections.update( shiftedJetsCollections )
171 collectionsToKeep.extend( jetsCollectionsToKeep )
177 print "INFO : electron collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % electronCollection
180 process,
"electron", electronCollection,
181 varyByNsigmas,shiftedParticleSequence,
184 shiftedParticleCollections.update( shiftedElectronsCollections )
185 collectionsToKeep.extend( electronsCollectionsToKeep )
191 print "INFO : photon collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % photonCollection
194 process,
"photon", photonCollection,
195 varyByNsigmas,shiftedParticleSequence,
197 shiftedParticleCollections.update( shiftedPhotonsCollections )
198 collectionsToKeep.extend( photonsCollectionsToKeep )
204 print "INFO : muon collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % muonCollection
207 varyByNsigmas,shiftedParticleSequence,
209 shiftedParticleCollections.update( shiftedMuonsCollections )
210 collectionsToKeep.extend( muonsCollectionsToKeep )
216 print "INFO : tau collection %s does not exists, no energy shifting will be performed in MET uncertainty tools" % 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 moduleNameShifts = {
'Up':moduleNameShiftUp ,
'Down':moduleNameShiftDown }
257 return moduleNameShifts
260 def _getLeptonsForPFMEtInput(self, shiftedParticleCollections, substituteKeyUnshifted = None, substituteKeyShifted = None, postfix=""):
262 for particleCol
in shiftedParticleCollections.keys():
263 if not (particleCol.find(
"Jet")
or particleCol.find(
"jet") )
and isValidInputTag(shiftedParticleCollections[collectionName]):
264 print collectionName,
"==>:"+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 metCollection, patMEtCollection,
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)
289 electronCollection =
None,
290 photonCollection =
None,
291 muonCollection =
None,
292 tauCollection =
None,
293 jetCollection =
None,
296 jetSmearFileName =
None,
297 jetSmearHistogram =
None,
298 jetCorrPayloadName =
None,
299 jetCorrLabelUpToL3 =
None,
300 jetCorrLabelUpToL3Res =
None,
301 jecUncertaintyFile =
None,
302 jecUncertaintyTag =
None,
303 varyByNsigmas =
None,
304 addToPatDefaultSequence =
None,
312 if jetCorrLabel
is None:
314 if doSmearJets
is None:
316 if jetSmearFileName
is None:
318 if jetSmearHistogram
is None:
320 if jetCorrPayloadName
is None:
322 if jetCorrLabelUpToL3
is None:
324 if jetCorrLabelUpToL3Res
is None:
326 if jecUncertaintyFile
is None:
328 if jecUncertaintyTag
is None:
330 if varyByNsigmas
is None:
332 if addToPatDefaultSequence
is None:
334 if outputModule
is None:
339 self.setParameter(
'electronCollection', electronCollection)
340 self.setParameter(
'photonCollection', photonCollection)
341 self.setParameter(
'muonCollection', muonCollection)
342 self.setParameter(
'tauCollection', tauCollection)
343 self.setParameter(
'jetCollection', jetCollection)
344 self.setParameter(
'jetCorrLabel', jetCorrLabel)
345 self.setParameter(
'doSmearJets', doSmearJets)
346 self.setParameter(
'jetSmearFileName', jetSmearFileName)
347 self.setParameter(
'jetSmearHistogram', jetSmearHistogram)
348 self.setParameter(
'jetCorrPayloadName', jetCorrPayloadName)
349 self.setParameter(
'jetCorrLabelUpToL3', jetCorrLabelUpToL3)
350 self.setParameter(
'jetCorrLabelUpToL3Res', jetCorrLabelUpToL3Res)
351 self.setParameter(
'jecUncertaintyFile', jecUncertaintyFile)
352 self.setParameter(
'jecUncertaintyTag', jecUncertaintyTag)
353 self.setParameter(
'varyByNsigmas', varyByNsigmas)
354 self.setParameter(
'addToPatDefaultSequence', addToPatDefaultSequence)
355 self.setParameter(
'outputModule', outputModule)
356 self.setParameter(
'postfix', postfix)