test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
metUncertaintyTools.py
Go to the documentation of this file.
2 
4 
5 import PhysicsTools.PatAlgos.tools.helpers as configtools
6 from PhysicsTools.PatAlgos.tools.trigTools import _addEventContent
7 
9 import RecoMET.METProducers.METSigParams_cfi as jetResolutions
11 
13 
14  """ Shift energy of electrons, photons, muons, tau-jets and other jets
15  reconstructed in the event up/down,
16  in order to estimate effect of energy scale uncertainties on MET
17  """
18  _label='runMEtUncertainties'
19  _defaultParameters=dicttypes.SortedKeysDict()
20  def __init__(self):
21  ConfigToolBase.__init__(self)
22  self.addParameter(self._defaultParameters, 'electronCollection', cms.InputTag('selectedPatElectrons'),
23  "Input electron collection", Type=cms.InputTag, acceptNoneValue=True)
24  self.addParameter(self._defaultParameters, 'photonCollection', None, # CV: set to empty InputTag to avoid double-counting wrt. selectedPatElectrons collection
25  "Input photon collection", Type=cms.InputTag, acceptNoneValue=True)
26  self.addParameter(self._defaultParameters, 'muonCollection', cms.InputTag('selectedPatMuons'),
27  "Input muon collection", Type=cms.InputTag, acceptNoneValue=True)
28  self.addParameter(self._defaultParameters, 'tauCollection', cms.InputTag('selectedPatTaus'),
29  "Input tau collection", Type=cms.InputTag, acceptNoneValue=True)
30  self.addParameter(self._defaultParameters, 'jetCollection', cms.InputTag('selectedPatJets'),
31  "Input jet collection", Type=cms.InputTag)
32  self.addParameter(self._defaultParameters, 'dRjetCleaning', 0.5,
33  "Eta-phi distance for extra jet cleaning", Type=float)
34  self.addParameter(self._defaultParameters, 'jetCorrLabel', "L3Absolute",
35  "NOTE: use 'L3Absolute' for MC/'L2L3Residual' for Data", Type=str)
36  self.addParameter(self._defaultParameters, 'doSmearJets', True,
37  "Flag to enable/disable jet smearing to better match MC to Data", Type=bool)
38  self.addParameter(self._defaultParameters, 'makeType1corrPFMEt', True,
39  "Flag to enable/disable sequence for Type 1 corrected PFMEt", Type=bool)
40  self.addParameter(self._defaultParameters, 'makeType1p2corrPFMEt', True,
41  "Flag to enable/disable sequence for Type 1 + 2 corrected PFMEt", Type=bool)
42  self.addParameter(self._defaultParameters, 'makePFMEtByMVA', False,
43  "Flag to enable/disable sequence for MVA-based PFMEt", Type=bool)
44  self.addParameter(self._defaultParameters, 'makeNoPileUpPFMEt', False,
45  "Flag to enable/disable sequence for no-PU PFMEt", Type=bool)
46  self.addParameter(self._defaultParameters, 'doApplyType0corr', False,
47  "Flag to enable/disable usage of Type-0 MET corrections", Type=bool)
48  self.addParameter(self._defaultParameters, 'sysShiftCorrParameter', None,
49  "MET sys. shift correction parameters", Type=cms.PSet)
50  self.addParameter(self._defaultParameters, 'doApplySysShiftCorr', False,
51  "Flag to enable/disable usage of MET sys. shift corrections", Type=bool)
52  self.addParameter(self._defaultParameters, 'jetSmearFileName', 'PhysicsTools/PatUtils/data/pfJetResolutionMCtoDataCorrLUT.root',
53  "Name of ROOT file containing histogram with jet smearing factors", Type=str)
54  self.addParameter(self._defaultParameters, 'jetSmearHistogram', 'pfJetResolutionMCtoDataCorrLUT',
55  "Name of histogram with jet smearing factors", Type=str)
56  self.addParameter(self._defaultParameters, 'pfCandCollection', cms.InputTag('particleFlow'),
57  "Input PFCandidate collection", Type=cms.InputTag)
58  self.addParameter(self._defaultParameters, 'jetCorrPayloadName', 'AK5PF',
59  "Use AK5PF for PFJets, AK5Calo for CaloJets", Type=str)
60  self.addParameter(self._defaultParameters, 'varyByNsigmas', 1.0,
61  "Number of standard deviations by which energies are varied", Type=float)
62  self.addParameter(self._defaultParameters, 'addToPatDefaultSequence', True,
63  "Flag to enable/disable that metUncertaintySequence is inserted into patDefaultSequence", Type=bool)
64  self.addParameter(self._defaultParameters, 'outputModule', 'out',
65  "Module label of PoolOutputModule (empty label indicates no PoolOutputModule is to be configured)", Type=str)
66  self.addParameter(self._defaultParameters, 'postfix', '',
67  "Technical parameter to identify the resulting sequence and its modules (allows multiple calls in a job)", Type=str)
68  self._parameters=copy.deepcopy(self._defaultParameters)
69  self._comment = ""
70 
72  return self._defaultParameters
73 
74  def _addModuleToSequence(self, process, module, moduleName_parts, sequence, postfix):
75 
76  if not len(moduleName_parts) > 0:
77  raise ValueError("Empty list !!")
78 
79  moduleName = ""
80 
81  lastPart = None
82  for part in moduleName_parts:
83  if part is None or part == "":
84  continue
85 
86  part = part.replace("selected", "")
87  part = part.replace("clean", "")
88 
89  if lastPart is None:
90  moduleName += part[0].lower() + part[1:]
91  lastPart = part
92  else:
93  if lastPart[-1].islower() or lastPart[-1].isdigit():
94  moduleName += part[0].capitalize() + part[1:]
95  else:
96  moduleName += part[0].lower() + part[1:]
97  lastPart = part
98 
99  moduleName += postfix
100  setattr(process, moduleName, module)
101 
102  sequence += module
103 
104  return moduleName
105 
106  def _addSmearedJets(self, process, jetCollection, smearedJetCollectionName_parts,
107  jetSmearFileName, jetSmearHistogram, varyByNsigmas,
108  shiftBy = None, postfix = ""):
109 
110  smearedJets = cms.EDProducer("SmearedPATJetProducer",
111  src = cms.InputTag(jetCollection),
112  dRmaxGenJetMatch = cms.string('TMath::Min(0.5, 0.1 + 0.3*TMath::Exp(-0.05*(genJetPt - 10.)))'),
113  sigmaMaxGenJetMatch = cms.double(5.),
114  inputFileName = cms.FileInPath(jetSmearFileName),
115  lutName = cms.string(jetSmearHistogram),
116  jetResolutions = jetResolutions.METSignificance_params,
117  # CV: skip jet smearing for pat::Jets for which the jet-energy correction (JEC) factors are either very large or negative
118  # since both cases produce unphysically large tails in the Type 1 corrected MET distribution after the smearing,
119  #
120  # e.g. raw jet: energy = 50 GeV, eta = 2.86, pt = 1 GeV
121  # corr. jet: energy = -3 GeV , pt = -0.1 GeV (JEC factor L1fastjet*L2*L3 = -17)
122  # energy = 10 GeV for corrected jet after smearing
123  # --> smeared raw jet energy = -170 GeV !!
124  #
125  # --> (corr. - raw) jet contribution to MET = -1 (-10) GeV before (after) smearing,
126  # even though jet energy got smeared by merely 1 GeV
127  #
128  skipJetSelection = cms.string(
129  'jecSetsAvailable & abs(energy - correctedP4("Uncorrected").energy) > (5.*min(energy, correctedP4("Uncorrected").energy))'
130  ),
131  skipRawJetPtThreshold = cms.double(10.), # GeV
132  skipCorrJetPtThreshold = cms.double(1.e-2)
133  )
134  if shiftBy is not None:
135  setattr(smearedJets, "shiftBy", cms.double(shiftBy*varyByNsigmas))
136  smearedJetCollection = \
137  self._addModuleToSequence(process, smearedJets,
138  smearedJetCollectionName_parts,
139  getattr(process, "metUncertaintySequence"+postfix), postfix)
140 
141  return smearedJetCollection
142 
143  def _propagateMEtUncertainties(self, process,
144  particleCollection, particleType, shiftType, particleCollectionShiftUp, particleCollectionShiftDown,
145  metProducer, sequence, postfix):
146 
147  # produce MET correction objects
148  # (sum of differences in four-momentum between original and up/down shifted particle collection)
149  moduleMETcorrShiftUp = cms.EDProducer("ShiftedParticleMETcorrInputProducer",
150  srcOriginal = cms.InputTag(particleCollection),
151  srcShifted = cms.InputTag(particleCollectionShiftUp)
152  )
153  moduleMETcorrShiftUpName = "patPFMETcorr%s%sUp" % (particleType, shiftType)
154  moduleMETcorrShiftUpName += postfix
155  setattr(process, moduleMETcorrShiftUpName, moduleMETcorrShiftUp)
156  sequence += moduleMETcorrShiftUp
157  moduleMETcorrShiftDown = moduleMETcorrShiftUp.clone(
158  srcShifted = cms.InputTag(particleCollectionShiftDown)
159  )
160  moduleMETcorrShiftDownName = "patPFMETcorr%s%sDown" % (particleType, shiftType)
161  moduleMETcorrShiftDownName += postfix
162  setattr(process, moduleMETcorrShiftDownName, moduleMETcorrShiftDown)
163  sequence += moduleMETcorrShiftDown
164 
165  # propagate effects of up/down shifts to MET
166  moduleMETshiftUp = metProducer.clone(
167  src = cms.InputTag(metProducer.label()),
168  srcType1Corrections = cms.VInputTag(
169  cms.InputTag(moduleMETcorrShiftUpName)
170  )
171  )
172  metProducerLabel = metProducer.label()
173  if postfix != "":
174  if metProducerLabel[-len(postfix):] == postfix:
175  metProducerLabel = metProducerLabel[0:-len(postfix)]
176  else:
177  raise StandardError("Tried to remove postfix %s from label %s, but it wasn't there" % (postfix, metProducerLabel))
178  moduleMETshiftUpName = "%s%s%sUp" % (metProducerLabel, particleType, shiftType)
179  moduleMETshiftUpName += postfix
180  setattr(process, moduleMETshiftUpName, moduleMETshiftUp)
181  sequence += moduleMETshiftUp
182  moduleMETshiftDown = moduleMETshiftUp.clone(
183  srcType1Corrections = cms.VInputTag(
184  cms.InputTag(moduleMETcorrShiftDownName)
185  )
186  )
187  moduleMETshiftDownName = "%s%s%sDown" % (metProducerLabel, particleType, shiftType)
188  moduleMETshiftDownName += postfix
189  setattr(process, moduleMETshiftDownName, moduleMETshiftDown)
190  sequence += moduleMETshiftDown
191 
192  metCollectionsUp_Down = [
193  moduleMETshiftUpName,
194  moduleMETshiftDownName
195  ]
196 
197  return metCollectionsUp_Down
198 
199  def _initializeInputTag(self, input, default):
200  retVal = None
201  if input is None:
202  retVal = self._defaultParameters[default].value
203  elif type(input) == str:
204  retVal = cms.InputTag(input)
205  else:
206  retVal = input
207  return retVal
208 
209  @staticmethod
210  def _isValidInputTag(input):
211  input_str = input
212  if isinstance(input, cms.InputTag):
213  input_str = input.value()
214  if input is None or input_str == '""':
215  return False
216  else:
217  return True
218 
219  def _addShiftedParticleCollections(self, process,
220  electronCollection,
221  photonCollection,
222  muonCollection,
223  tauCollection,
224  jetCollection, cleanedJetCollection, lastJetCollection,
225  jetCollectionResUp, jetCollectionResDown,
226  varyByNsigmas,
227  postfix):
228 
229  shiftedParticlesForMEtUncertainties = cms.Sequence()
230  setattr(process, "shiftedParticlesForMEtUncertainties"+postfix, shiftedParticlesForMEtUncertainties)
231 
232  shiftedParticleCollections = {}
233  shiftedParticleCollections['electronCollection'] = electronCollection
234  shiftedParticleCollections['photonCollection'] = photonCollection
235  shiftedParticleCollections['muonCollection'] = muonCollection
236  shiftedParticleCollections['tauCollection'] = tauCollection
237  shiftedParticleCollections['jetCollection'] = jetCollection
238  shiftedParticleCollections['cleanedJetCollection'] = cleanedJetCollection
239  shiftedParticleCollections['lastJetCollection'] = lastJetCollection
240  shiftedParticleCollections['jetCollectionResUp'] = jetCollectionResUp
241  shiftedParticleCollections['jetCollectionResDown'] = jetCollectionResDown
242  collectionsToKeep = []
243 
244  #--------------------------------------------------------------------------------------------
245  # produce collection of jets shifted up/down in energy
246  #--------------------------------------------------------------------------------------------
247 
248  # in case of "raw" (uncorrected) MET,
249  # add residual jet energy corrections in quadrature to jet energy uncertainties:
250  # cf. https://twiki.cern.ch/twiki/bin/view/CMS/MissingETUncertaintyPrescription
251  jetsEnUpForRawMEt = cms.EDProducer("ShiftedPATJetProducer",
252  src = cms.InputTag(lastJetCollection),
253  #jetCorrPayloadName = cms.string(jetCorrPayloadName),
254  #jetCorrUncertaintyTag = cms.string('Uncertainty'),
255  jetCorrInputFileName = cms.FileInPath('PhysicsTools/PatUtils/data/Summer12_V2_DATA_AK5PF_UncertaintySources.txt'),
256  jetCorrUncertaintyTag = cms.string("SubTotalDataMC"),
257  addResidualJES = cms.bool(True),
258  jetCorrLabelUpToL3 = cms.string("ak4PFL1FastL2L3"),
259  jetCorrLabelUpToL3Res = cms.string("ak4PFL1FastL2L3Residual"),
260  shiftBy = cms.double(+1.*varyByNsigmas)
261  )
262  jetCollectionEnUpForRawMEt = \
263  self._addModuleToSequence(process, jetsEnUpForRawMEt,
264  [ "shifted", jetCollection.value(), "EnUpForRawMEt" ],
265  shiftedParticlesForMEtUncertainties, postfix)
266  shiftedParticleCollections['jetCollectionEnUpForRawMEt'] = jetCollectionEnUpForRawMEt
267  collectionsToKeep.append(jetCollectionEnUpForRawMEt)
268  jetsEnDownForRawMEt = jetsEnUpForRawMEt.clone(
269  shiftBy = cms.double(-1.*varyByNsigmas)
270  )
271  jetCollectionEnDownForRawMEt = \
272  self._addModuleToSequence(process, jetsEnDownForRawMEt,
273  [ "shifted", jetCollection.value(), "EnDownForRawMEt" ],
274  shiftedParticlesForMEtUncertainties, postfix)
275  shiftedParticleCollections['jetCollectionEnDownForRawMEt'] = jetCollectionEnDownForRawMEt
276  collectionsToKeep.append(jetCollectionEnDownForRawMEt)
277 
278  jetsEnUpForCorrMEt = jetsEnUpForRawMEt.clone(
279  addResidualJES = cms.bool(False)
280  )
281  jetCollectionEnUpForCorrMEt = \
282  self._addModuleToSequence(process, jetsEnUpForCorrMEt,
283  [ "shifted", jetCollection.value(), "EnUpForCorrMEt" ],
284  shiftedParticlesForMEtUncertainties, postfix)
285  shiftedParticleCollections['jetCollectionEnUpForCorrMEt'] = jetCollectionEnUpForCorrMEt
286  collectionsToKeep.append(jetCollectionEnUpForCorrMEt)
287  jetsEnDownForCorrMEt = jetsEnUpForCorrMEt.clone(
288  shiftBy = cms.double(-1.*varyByNsigmas)
289  )
290  jetCollectionEnDownForCorrMEt = \
291  self._addModuleToSequence(process, jetsEnDownForCorrMEt,
292  [ "shifted", jetCollection.value(), "EnDownForCorrMEt" ],
293  shiftedParticlesForMEtUncertainties, postfix)
294  shiftedParticleCollections['jetCollectionEnDownForCorrMEt'] = jetCollectionEnDownForCorrMEt
295  collectionsToKeep.append(jetCollectionEnDownForCorrMEt)
296 
297  #--------------------------------------------------------------------------------------------
298  # produce collection of electrons shifted up/down in energy
299  #--------------------------------------------------------------------------------------------
300 
301  electronCollectionEnUp = None
302  electronCollectionEnDown = None
303  if self._isValidInputTag(electronCollection):
304  electronsEnUp = cms.EDProducer("ShiftedPATElectronProducer",
305  src = electronCollection,
306  binning = cms.VPSet(
307  cms.PSet(
308  binSelection = cms.string('isEB'),
309  binUncertainty = cms.double(0.006)
310  ),
311  cms.PSet(
312  binSelection = cms.string('!isEB'),
313  binUncertainty = cms.double(0.015)
314  ),
315  ),
316  shiftBy = cms.double(+1.*varyByNsigmas)
317  )
318  electronCollectionEnUp = \
319  self._addModuleToSequence(process, electronsEnUp,
320  [ "shifted", electronCollection.value(), "EnUp" ],
321  shiftedParticlesForMEtUncertainties, postfix)
322  shiftedParticleCollections['electronCollectionEnUp'] = electronCollectionEnUp
323  collectionsToKeep.append(electronCollectionEnUp)
324  electronsEnDown = electronsEnUp.clone(
325  shiftBy = cms.double(-1.*varyByNsigmas)
326  )
327  electronCollectionEnDown = \
328  self._addModuleToSequence(process, electronsEnDown,
329  [ "shifted", electronCollection.value(), "EnDown" ],
330  shiftedParticlesForMEtUncertainties, postfix)
331  shiftedParticleCollections['electronCollectionEnDown'] = electronCollectionEnDown
332  collectionsToKeep.append(electronCollectionEnDown)
333 
334  #--------------------------------------------------------------------------------------------
335  # produce collection of (high Pt) photon candidates shifted up/down in energy
336  #--------------------------------------------------------------------------------------------
337 
338  photonCollectionEnUp = None
339  photonCollectionEnDown = None
340  if self._isValidInputTag(photonCollection):
341  photonsEnUp = cms.EDProducer("ShiftedPATPhotonProducer",
342  src = photonCollection,
343  binning = cms.VPSet(
344  cms.PSet(
345  binSelection = cms.string('isEB = true'),
346  binUncertainty = cms.double(0.01)
347  ),
348  cms.PSet(
349  binSelection = cms.string('isEB = false'),
350  binUncertainty = cms.double(0.025)
351  ),
352  ),
353  shiftBy = cms.double(+1.*varyByNsigmas)
354  )
355  photonCollectionEnUp = \
356  self._addModuleToSequence(process, photonsEnUp,
357  [ "shifted", photonCollection.value(), "EnUp" ],
358  shiftedParticlesForMEtUncertainties, postfix)
359  shiftedParticleCollections['photonCollectionEnUp'] = photonCollectionEnUp
360  collectionsToKeep.append(photonCollectionEnUp)
361  photonsEnDown = photonsEnUp.clone(
362  shiftBy = cms.double(-1.*varyByNsigmas)
363  )
364  photonCollectionEnDown = \
365  self._addModuleToSequence(process, photonsEnDown,
366  [ "shifted", photonCollection.value(), "EnDown" ],
367  shiftedParticlesForMEtUncertainties, postfix)
368  shiftedParticleCollections['photonCollectionEnDown'] = photonCollectionEnDown
369  collectionsToKeep.append(photonCollectionEnDown)
370 
371  #--------------------------------------------------------------------------------------------
372  # produce collection of muons shifted up/down in energy/momentum
373  #--------------------------------------------------------------------------------------------
374 
375  muonCollectionEnUp = None
376  muonCollectionEnDown = None
377  if self._isValidInputTag(muonCollection):
378  muonsEnUp = cms.EDProducer("ShiftedPATMuonProducer",
379  src = muonCollection,
380  uncertainty = cms.double(0.002),
381  shiftBy = cms.double(+1.*varyByNsigmas)
382  )
383  muonCollectionEnUp = \
384  self._addModuleToSequence(process, muonsEnUp,
385  [ "shifted", muonCollection.value(), "EnUp" ],
386  shiftedParticlesForMEtUncertainties, postfix)
387  shiftedParticleCollections['muonCollectionEnUp'] = muonCollectionEnUp
388  collectionsToKeep.append(muonCollectionEnUp)
389  muonsEnDown = muonsEnUp.clone(
390  shiftBy = cms.double(-1.*varyByNsigmas)
391  )
392  muonCollectionEnDown = \
393  self._addModuleToSequence(process, muonsEnDown,
394  [ "shifted", muonCollection.value(), "EnDown" ],
395  shiftedParticlesForMEtUncertainties, postfix)
396  shiftedParticleCollections['muonCollectionEnDown'] = muonCollectionEnDown
397  collectionsToKeep.append(muonCollectionEnDown)
398 
399  #--------------------------------------------------------------------------------------------
400  # produce collection of tau-jets shifted up/down in energy
401  #--------------------------------------------------------------------------------------------
402 
403  tauCollectionEnUp = None
404  tauCollectionEnDown = None
405  if self._isValidInputTag(tauCollection):
406  tausEnUp = cms.EDProducer("ShiftedPATTauProducer",
407  src = tauCollection,
408  uncertainty = cms.double(0.03),
409  shiftBy = cms.double(+1.*varyByNsigmas)
410  )
411  tauCollectionEnUp = \
412  self._addModuleToSequence(process, tausEnUp,
413  [ "shifted", tauCollection.value(), "EnUp" ],
414  shiftedParticlesForMEtUncertainties, postfix)
415  shiftedParticleCollections['tauCollectionEnUp'] = tauCollectionEnUp
416  collectionsToKeep.append(tauCollectionEnUp)
417  tausEnDown = tausEnUp.clone(
418  shiftBy = cms.double(-1.*varyByNsigmas)
419  )
420  tauCollectionEnDown = \
421  self._addModuleToSequence(process, tausEnDown,
422  [ "shifted", tauCollection.value(), "EnDown" ],
423  shiftedParticlesForMEtUncertainties, postfix)
424  shiftedParticleCollections['tauCollectionEnDown'] = tauCollectionEnDown
425  collectionsToKeep.append(tauCollectionEnDown)
426 
427  return ( shiftedParticleCollections, collectionsToKeep )
428 
429  def _addCorrPFMEt(self, process, metUncertaintySequence,
430  shiftedParticleCollections, pfCandCollection,
431  collectionsToKeep,
432  doSmearJets,
433  makeType1corrPFMEt,
434  makeType1p2corrPFMEt,
435  doApplyType0corr,
436  sysShiftCorrParameter,
437  doApplySysShiftCorr,
438  jetCorrLabel,
439  varyByNsigmas,
440  postfix):
441 
442  if not (makeType1corrPFMEt or makeType1p2corrPFMEt):
443  return
444 
445  if not hasattr(process, 'producePatPFMETCorrections'):
446  process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff")
447 
448  # If with empty postfix, make a backup of
449  # process.producePatPFMETCorrections, because the original
450  # sequence will be modified later in this function
451  if postfix == "":
452  configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrections, "OriginalReserved")
453  else:
454  if postfix == "OriginalReserved":
455  raise ValueError("Postfix label '%s' is reserved for internal usage !!" % postfix)
456 
457  if hasattr(process, "producePatPFMETCorrectionsOriginalReserved"):
458  configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrectionsOriginalReserved, postfix, removePostfix="OriginalReserved")
459  else:
460  configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrections, postfix)
461 
462  # add "nominal" (unshifted) pat::MET collections
463  getattr(process, "pfCandsNotInJet"+postfix).bottomCollection = pfCandCollection
464  getattr(process, "selectedPatJetsForMETtype1p2Corr"+postfix).src = shiftedParticleCollections['lastJetCollection']
465  getattr(process, "selectedPatJetsForMETtype2Corr"+postfix).src = shiftedParticleCollections['lastJetCollection']
466 
467 
468  if doApplySysShiftCorr:
469  if not hasattr(process, 'pfMEtSysShiftCorrSequence'):
470  process.load("JetMETCorrections.Type1MET.pfMETsysShiftCorrections_cfi")
471  if postfix != "":
472  configtools.cloneProcessingSnippet(process, process.pfMEtSysShiftCorrSequence, postfix)
473 
474  getattr(process, "pfMEtSysShiftCorr"+postfix).parameter = sysShiftCorrParameter
475  metUncertaintySequence += getattr(process, "pfMEtSysShiftCorrSequence"+postfix)
476 
477  metUncertaintySequence += getattr(process, "producePatPFMETCorrections"+postfix)
478 
479  patType1correctionsCentralValue = [ cms.InputTag('patPFJetMETtype1p2Corr'+postfix, 'type1') ]
480  if doApplyType0corr:
481  patType1correctionsCentralValue.extend([ cms.InputTag('patPFMETtype0Corr'+postfix) ])
482  if doApplySysShiftCorr:
483  patType1correctionsCentralValue.extend([ cms.InputTag('pfMEtSysShiftCorr'+postfix) ])
484  getattr(process, "patType1CorrectedPFMet"+postfix).srcType1Corrections = cms.VInputTag(patType1correctionsCentralValue)
485  getattr(process, "patType1p2CorrectedPFMet"+postfix).srcType1Corrections = cms.VInputTag(patType1correctionsCentralValue)
486 
487  collectionsToKeep.extend([
488  'patPFMet'+postfix,
489  'patType1CorrectedPFMet'+postfix,
490  'patType1p2CorrectedPFMet'+postfix])
491 
492  setattr(process, "selectedPatJetsForMETtype1p2CorrEnUp"+postfix,
493  getattr(process, shiftedParticleCollections['jetCollectionEnUpForCorrMEt']).clone(
494  src = cms.InputTag('selectedPatJetsForMETtype1p2Corr'+postfix)
495  ))
496  metUncertaintySequence += getattr(process, "selectedPatJetsForMETtype1p2CorrEnUp"+postfix)
497  setattr(process, "selectedPatJetsForMETtype1p2CorrEnDown"+postfix,
498  getattr(process, shiftedParticleCollections['jetCollectionEnDownForCorrMEt']).clone(
499  src = cms.InputTag('selectedPatJetsForMETtype1p2Corr'+postfix)
500  ))
501  metUncertaintySequence += getattr(process, "selectedPatJetsForMETtype1p2CorrEnDown"+postfix)
502  if makeType1p2corrPFMEt:
503  setattr(process, "selectedPatJetsForMETtype2CorrEnUp"+postfix,
504  getattr(process, shiftedParticleCollections['jetCollectionEnUpForCorrMEt']).clone(
505  src = cms.InputTag('selectedPatJetsForMETtype2Corr'+postfix)
506  ))
507  metUncertaintySequence += getattr(process, "selectedPatJetsForMETtype2CorrEnUp"+postfix)
508  setattr(process, "selectedPatJetsForMETtype2CorrEnDown"+postfix,
509  getattr(process, shiftedParticleCollections['jetCollectionEnDownForCorrMEt']).clone(
510  src = cms.InputTag('selectedPatJetsForMETtype2Corr'+postfix)
511  ))
512  metUncertaintySequence += getattr(process, "selectedPatJetsForMETtype2CorrEnDown"+postfix)
513 
514  if doSmearJets:
515  setattr(process, "selectedPatJetsForMETtype1p2CorrResUp"+postfix,
516  getattr(process, shiftedParticleCollections['jetCollectionResUp']).clone(
517  src = cms.InputTag('selectedPatJetsForMETtype1p2Corr'+postfix)
518  ))
519  metUncertaintySequence += getattr(process, "selectedPatJetsForMETtype1p2CorrResUp"+postfix)
520  setattr(process, "selectedPatJetsForMETtype1p2CorrResDown"+postfix,
521  getattr(process, shiftedParticleCollections['jetCollectionResDown']).clone(
522  src = cms.InputTag('selectedPatJetsForMETtype1p2Corr'+postfix)
523  ))
524  metUncertaintySequence += getattr(process, "selectedPatJetsForMETtype1p2CorrResDown"+postfix)
525  if makeType1p2corrPFMEt:
526  setattr(process, "selectedPatJetsForMETtype2CorrResUp"+postfix,
527  getattr(process, shiftedParticleCollections['jetCollectionResUp']).clone(
528  src = cms.InputTag('selectedPatJetsForMETtype2Corr'+postfix)
529  ))
530  metUncertaintySequence += getattr(process, "selectedPatJetsForMETtype2CorrResUp"+postfix)
531  setattr(process, "selectedPatJetsForMETtype2CorrResDown"+postfix,
532  getattr(process, shiftedParticleCollections['jetCollectionResDown']).clone(
533  src = cms.InputTag('selectedPatJetsForMETtype2Corr'+postfix)
534  ))
535  metUncertaintySequence += getattr(process, "selectedPatJetsForMETtype2CorrResDown"+postfix)
536 
537  if doSmearJets:
538  # apply MET smearing to "raw" (uncorrected) MET
539  smearedPatPFMetSequence = cms.Sequence()
540  setattr(process, "smearedPatPFMetSequence"+postfix, smearedPatPFMetSequence)
541  setattr(process, "patPFMetForMEtUncertainty"+postfix, getattr(process, "patPFMet"+postfix).clone())
542  smearedPatPFMetSequence += getattr(process, "patPFMetForMEtUncertainty"+postfix)
543  setattr(process, "patPFMETcorrJetSmearing"+postfix, cms.EDProducer("ShiftedParticleMETcorrInputProducer",
544  srcOriginal = cms.InputTag(shiftedParticleCollections['cleanedJetCollection']),
545  srcShifted = cms.InputTag(shiftedParticleCollections['lastJetCollection'])
546  ))
547  smearedPatPFMetSequence += getattr(process, "patPFMETcorrJetSmearing"+postfix)
548  getattr(process, "producePatPFMETCorrections"+postfix).replace(getattr(process, "patPFMet"+postfix), smearedPatPFMetSequence)
549  setattr(process, "patPFMet"+postfix, getattr(process, "patType1CorrectedPFMet"+postfix).clone(
550  src = cms.InputTag('patPFMetForMEtUncertainty'+postfix),
551  srcType1Corrections = cms.VInputTag(
552  cms.InputTag('patPFMETcorrJetSmearing'+postfix)
553  )
554  ))
555  smearedPatPFMetSequence += getattr(process, "patPFMet"+postfix)
556  metUncertaintySequence += smearedPatPFMetSequence
557 
558  # propagate shifts in jet energy to "raw" (uncorrected) and Type 1 corrected MET
559  metCollectionsUp_DownForRawMEt = \
561  process, shiftedParticleCollections['lastJetCollection'], "Jet", "En",
562  shiftedParticleCollections['jetCollectionEnUpForRawMEt'], shiftedParticleCollections['jetCollectionEnDownForRawMEt'],
563  getattr(process, "patPFMet"+postfix), metUncertaintySequence, postfix)
564  collectionsToKeep.extend(metCollectionsUp_DownForRawMEt)
565 
566  metCollectionsUp_DownForCorrMEt = \
568  process, shiftedParticleCollections['lastJetCollection'], "Jet", "En",
569  shiftedParticleCollections['jetCollectionEnUpForCorrMEt'], shiftedParticleCollections['jetCollectionEnDownForCorrMEt'],
570  getattr(process, "patType1CorrectedPFMet"+postfix), metUncertaintySequence, postfix)
571  collectionsToKeep.extend(metCollectionsUp_DownForCorrMEt)
572 
573  # propagate shifts in jet energy to Type 1 + 2 corrected MET
574  if makeType1p2corrPFMEt:
575  setattr(process, "patPFJetMETtype1p2CorrEnUp"+postfix, getattr(process, "patPFJetMETtype1p2Corr"+postfix).clone(
576  src = cms.InputTag(getattr(process, "selectedPatJetsForMETtype1p2CorrEnUp"+postfix).label()),
577  jetCorrLabel = cms.string(jetCorrLabel)
578  ))
579  metUncertaintySequence += getattr(process, "patPFJetMETtype1p2CorrEnUp"+postfix)
580  setattr(process, "patPFJetMETtype1p2CorrEnDown"+postfix, getattr(process, "patPFJetMETtype1p2CorrEnUp"+postfix).clone(
581  src = cms.InputTag(getattr(process, "selectedPatJetsForMETtype1p2CorrEnDown"+postfix).label())
582  ))
583  metUncertaintySequence += getattr(process, "patPFJetMETtype1p2CorrEnDown"+postfix)
584  setattr(process, "patPFJetMETtype2CorrEnUp"+postfix, getattr(process, "patPFJetMETtype2Corr"+postfix).clone(
585  src = cms.InputTag('selectedPatJetsForMETtype2CorrEnUp'+postfix)
586  ))
587  metUncertaintySequence += getattr(process, "patPFJetMETtype2CorrEnUp"+postfix)
588  setattr(process, "patPFJetMETtype2CorrEnDown"+postfix, getattr(process, "patPFJetMETtype2Corr"+postfix).clone(
589  src = cms.InputTag('selectedPatJetsForMETtype2CorrEnDown'+postfix)
590  ))
591  metUncertaintySequence += getattr(process, "patPFJetMETtype2CorrEnDown"+postfix)
592 
593  patType1correctionsJetEnUp = [ cms.InputTag('patPFJetMETtype1p2CorrEnUp'+postfix, 'type1') ]
594  if doApplyType0corr:
595  patType1correctionsJetEnUp.extend([ cms.InputTag('patPFMETtype0Corr'+postfix) ])
596  if doApplySysShiftCorr:
597  patType1correctionsJetEnUp.extend([ cms.InputTag('pfMEtSysShiftCorr'+postfix) ])
598  setattr(process, "patType1p2CorrectedPFMetJetEnUp"+postfix, getattr(process, "patType1p2CorrectedPFMet"+postfix).clone(
599  srcType1Corrections = cms.VInputTag(patType1correctionsJetEnUp),
600  srcUnclEnergySums = cms.VInputTag(
601  cms.InputTag('patPFJetMETtype1p2CorrEnUp'+postfix, 'type2' ),
602  cms.InputTag('patPFJetMETtype2CorrEnUp'+postfix, 'type2' ),
603  cms.InputTag('patPFJetMETtype1p2CorrEnUp'+postfix, 'offset'),
604  cms.InputTag('pfCandMETcorr'+postfix)
605  )
606  ))
607  metUncertaintySequence += getattr(process, "patType1p2CorrectedPFMetJetEnUp"+postfix)
608  collectionsToKeep.append('patType1p2CorrectedPFMetJetEnUp'+postfix)
609  patType1correctionsJetEnDown = [ cms.InputTag('patPFJetMETtype1p2CorrEnDown'+postfix, 'type1') ]
610  if doApplyType0corr:
611  patType1correctionsJetEnDown.extend([ cms.InputTag('patPFMETtype0Corr'+postfix) ])
612  if doApplySysShiftCorr:
613  patType1correctionsJetEnDown.extend([ cms.InputTag('pfMEtSysShiftCorr'+postfix) ])
614  setattr(process, "patType1p2CorrectedPFMetJetEnDown"+postfix, getattr(process, "patType1p2CorrectedPFMetJetEnUp"+postfix).clone(
615  srcType1Corrections = cms.VInputTag(patType1correctionsJetEnDown),
616  srcUnclEnergySums = cms.VInputTag(
617  cms.InputTag('patPFJetMETtype1p2CorrEnDown'+postfix, 'type2' ),
618  cms.InputTag('patPFJetMETtype2CorrEnDown'+postfix, 'type2' ),
619  cms.InputTag('patPFJetMETtype1p2CorrEnDown'+postfix, 'offset'),
620  cms.InputTag('pfCandMETcorr'+postfix)
621  )
622  ))
623  metUncertaintySequence += getattr(process, "patType1p2CorrectedPFMetJetEnDown"+postfix)
624  collectionsToKeep.append('patType1p2CorrectedPFMetJetEnDown'+postfix)
625 
626  if doSmearJets:
627  # propagate shifts in jet resolution to "raw" (uncorrected) MET and Type 1 corrected MET
628  for metProducer in [ getattr(process, "patPFMet"+postfix),
629  getattr(process, "patType1CorrectedPFMet"+postfix) ]:
630 
631  metCollectionsUp_Down = \
633  process, shiftedParticleCollections['lastJetCollection'], "Jet", "Res",
634  shiftedParticleCollections['jetCollectionResUp'], shiftedParticleCollections['jetCollectionResDown'],
635  metProducer, metUncertaintySequence, postfix)
636  collectionsToKeep.extend(metCollectionsUp_Down)
637 
638  # propagate shifts in jet resolution to Type 1 + 2 corrected MET
639  if makeType1p2corrPFMEt:
640  setattr(process, "patPFJetMETtype1p2CorrResUp"+postfix, getattr(process, "patPFJetMETtype1p2Corr"+postfix).clone(
641  src = cms.InputTag(getattr(process, "selectedPatJetsForMETtype1p2CorrResUp"+postfix).label()),
642  jetCorrLabel = cms.string(jetCorrLabel)
643  ))
644  metUncertaintySequence += getattr(process, "patPFJetMETtype1p2CorrResUp"+postfix)
645  setattr(process, "patPFJetMETtype1p2CorrResDown"+postfix, getattr(process, "patPFJetMETtype1p2CorrResUp"+postfix).clone(
646  src = cms.InputTag(getattr(process, "selectedPatJetsForMETtype1p2CorrResDown"+postfix).label())
647  ))
648  metUncertaintySequence += getattr(process, "patPFJetMETtype1p2CorrResDown"+postfix)
649  setattr(process, "patPFJetMETtype2CorrResUp"+postfix, getattr(process, "patPFJetMETtype2Corr"+postfix).clone(
650  src = cms.InputTag('selectedPatJetsForMETtype2CorrResUp'+postfix)
651  ))
652  metUncertaintySequence += getattr(process, "patPFJetMETtype2CorrResUp"+postfix)
653  setattr(process, "patPFJetMETtype2CorrResDown"+postfix, getattr(process, "patPFJetMETtype2Corr"+postfix).clone(
654  src = cms.InputTag('selectedPatJetsForMETtype2CorrResDown'+postfix)
655  ))
656  metUncertaintySequence += getattr(process, "patPFJetMETtype2CorrResDown"+postfix)
657 
658  patType1correctionsJetResUp = [ cms.InputTag('patPFJetMETtype1p2CorrResUp'+postfix, 'type1') ]
659  if doApplyType0corr:
660  patType1correctionsJetResUp.extend([ cms.InputTag('patPFMETtype0Corr'+postfix) ])
661  if doApplySysShiftCorr:
662  patType1correctionsJetResUp.extend([ cms.InputTag('pfMEtSysShiftCorr'+postfix) ])
663  setattr(process, "patType1p2CorrectedPFMetJetResUp"+postfix, getattr(process, "patType1p2CorrectedPFMet"+postfix).clone(
664  srcType1Corrections = cms.VInputTag(patType1correctionsJetResUp),
665  srcUnclEnergySums = cms.VInputTag(
666  cms.InputTag('patPFJetMETtype1p2CorrResUp'+postfix, 'type2' ),
667  cms.InputTag('patPFJetMETtype2CorrResUp'+postfix, 'type2' ),
668  cms.InputTag('patPFJetMETtype1p2CorrResUp'+postfix, 'offset'),
669  cms.InputTag('pfCandMETcorr'+postfix)
670  )
671  ))
672  metUncertaintySequence += getattr(process, "patType1p2CorrectedPFMetJetResUp"+postfix)
673  collectionsToKeep.append('patType1p2CorrectedPFMetJetResUp'+postfix)
674  patType1correctionsJetResDown = [ cms.InputTag('patPFJetMETtype1p2CorrResDown'+postfix, 'type1') ]
675  if doApplyType0corr:
676  patType1correctionsJetResDown.extend([ cms.InputTag('patPFMETtype0Corr'+postfix) ])
677  if doApplySysShiftCorr:
678  patType1correctionsJetResDown.extend([ cms.InputTag('pfMEtSysShiftCorr'+postfix) ])
679  setattr(process, "patType1p2CorrectedPFMetJetResDown"+postfix, getattr(process, "patType1p2CorrectedPFMetJetResUp"+postfix).clone(
680  srcType1Corrections = cms.VInputTag(patType1correctionsJetResDown),
681  srcUnclEnergySums = cms.VInputTag(
682  cms.InputTag('patPFJetMETtype1p2CorrResDown'+postfix, 'type2' ),
683  cms.InputTag('patPFJetMETtype2CorrResDown'+postfix, 'type2' ),
684  cms.InputTag('patPFJetMETtype1p2CorrResDown'+postfix, 'offset'),
685  cms.InputTag('pfCandMETcorr'+postfix)
686  )
687  ))
688  metUncertaintySequence += getattr(process, "patType1p2CorrectedPFMetJetResDown"+postfix)
689  collectionsToKeep.append('patType1p2CorrectedPFMetJetResDown'+postfix)
690 
691  #--------------------------------------------------------------------------------------------
692  # shift "unclustered energy" (PFJets of Pt < 10 GeV plus PFCandidates not within jets)
693  # and propagate effect of shift to (Type 1 as well as Type 1 + 2 corrected) MET
694  #--------------------------------------------------------------------------------------------
695 
696  unclEnMETcorrections = [
697  [ 'pfCandMETcorr'+postfix, [ '' ] ],
698  [ 'patPFJetMETtype1p2Corr'+postfix, [ 'type2', 'offset' ] ],
699  [ 'patPFJetMETtype2Corr'+postfix, [ 'type2' ] ],
700  ]
701  unclEnMETcorrectionsUp = []
702  unclEnMETcorrectionsDown = []
703  for srcUnclEnMETcorr in unclEnMETcorrections:
704  moduleUnclEnMETcorrUp = cms.EDProducer("ShiftedMETcorrInputProducer",
705  src = cms.VInputTag(
706  [ cms.InputTag(srcUnclEnMETcorr[0], instanceLabel) for instanceLabel in srcUnclEnMETcorr[1] ]
707  ),
708  uncertainty = cms.double(0.10),
709  shiftBy = cms.double(+1.*varyByNsigmas)
710  )
711  baseName = srcUnclEnMETcorr[0]
712  if postfix != "":
713  if baseName[-len(postfix):] == postfix:
714  baseName = baseName[0:-len(postfix)]
715  else:
716  raise StandardError("Tried to remove postfix %s from label %s, but it wasn't there" % (postfix, baseName))
717  moduleUnclEnMETcorrUpName = "%sUnclusteredEnUp" % baseName
718  moduleUnclEnMETcorrUpName += postfix
719  setattr(process, moduleUnclEnMETcorrUpName, moduleUnclEnMETcorrUp)
720  metUncertaintySequence += moduleUnclEnMETcorrUp
721  unclEnMETcorrectionsUp.extend([ cms.InputTag(moduleUnclEnMETcorrUpName, instanceLabel)
722  for instanceLabel in srcUnclEnMETcorr[1] ] )
723  moduleUnclEnMETcorrDown = moduleUnclEnMETcorrUp.clone(
724  shiftBy = cms.double(-1.*varyByNsigmas)
725  )
726  moduleUnclEnMETcorrDownName = "%sUnclusteredEnDown" % baseName
727  moduleUnclEnMETcorrDownName += postfix
728  setattr(process, moduleUnclEnMETcorrDownName, moduleUnclEnMETcorrDown)
729  metUncertaintySequence += moduleUnclEnMETcorrDown
730  unclEnMETcorrectionsDown.extend([ cms.InputTag(moduleUnclEnMETcorrDownName, instanceLabel)
731  for instanceLabel in srcUnclEnMETcorr[1] ] )
732 
733  # propagate shifts in jet energy/resolution to "raw" (uncorrected) MET
734  setattr(process, "patPFMetUnclusteredEnUp"+postfix, getattr(process, "patType1CorrectedPFMet"+postfix).clone(
735  src = cms.InputTag('patPFMet'+postfix),
736  srcType1Corrections = cms.VInputTag(unclEnMETcorrectionsUp)
737  ))
738  metUncertaintySequence += getattr(process, "patPFMetUnclusteredEnUp"+postfix)
739  collectionsToKeep.append('patPFMetUnclusteredEnUp'+postfix)
740  setattr(process, "patPFMetUnclusteredEnDown"+postfix, getattr(process, "patPFMetUnclusteredEnUp"+postfix).clone(
741  srcType1Corrections = cms.VInputTag(unclEnMETcorrectionsDown)
742  ))
743  metUncertaintySequence += getattr(process, "patPFMetUnclusteredEnDown"+postfix)
744  collectionsToKeep.append('patPFMetUnclusteredEnDown'+postfix)
745 
746  # propagate shifts in jet energy/resolution to Type 1 corrected MET
747  setattr(process, "patType1CorrectedPFMetUnclusteredEnUp"+postfix, getattr(process, "patType1CorrectedPFMet"+postfix).clone(
748  src = cms.InputTag('patType1CorrectedPFMet'+postfix),
749  srcType1Corrections = cms.VInputTag(unclEnMETcorrectionsUp)
750  ))
751  metUncertaintySequence += getattr(process, "patType1CorrectedPFMetUnclusteredEnUp"+postfix)
752  collectionsToKeep.append('patType1CorrectedPFMetUnclusteredEnUp'+postfix)
753  setattr(process, "patType1CorrectedPFMetUnclusteredEnDown"+postfix, getattr(process, "patType1CorrectedPFMetUnclusteredEnUp"+postfix).clone(
754  srcType1Corrections = cms.VInputTag(unclEnMETcorrectionsDown)
755  ))
756  metUncertaintySequence += getattr(process, "patType1CorrectedPFMetUnclusteredEnDown"+postfix)
757  collectionsToKeep.append('patType1CorrectedPFMetUnclusteredEnDown'+postfix)
758 
759  # propagate shifts in jet energy/resolution to Type 1 + 2 corrected MET
760  if makeType1p2corrPFMEt:
761  setattr(process, "patType1p2CorrectedPFMetUnclusteredEnUp"+postfix, getattr(process, "patType1p2CorrectedPFMet"+postfix).clone(
762  srcUnclEnergySums = cms.VInputTag(
763  cms.InputTag('patPFJetMETtype1p2Corr'+postfix, 'type2' ),
764  cms.InputTag('patPFJetMETtype1p2CorrUnclusteredEnUp'+postfix, 'type2' ),
765  cms.InputTag('patPFJetMETtype2Corr'+postfix, 'type2' ),
766  cms.InputTag('patPFJetMETtype2CorrUnclusteredEnUp'+postfix, 'type2' ),
767  cms.InputTag('patPFJetMETtype1p2Corr'+postfix, 'offset'),
768  cms.InputTag('patPFJetMETtype1p2CorrUnclusteredEnUp'+postfix, 'offset'),
769  cms.InputTag('pfCandMETcorr'+postfix),
770  cms.InputTag('pfCandMETcorrUnclusteredEnUp'+postfix)
771  )
772  ))
773  metUncertaintySequence += getattr(process, "patType1p2CorrectedPFMetUnclusteredEnUp"+postfix)
774  collectionsToKeep.append('patType1p2CorrectedPFMetUnclusteredEnUp'+postfix)
775  setattr(process, "patType1p2CorrectedPFMetUnclusteredEnDown"+postfix, getattr(process, "patType1p2CorrectedPFMetUnclusteredEnUp"+postfix).clone(
776  srcUnclEnergySums = cms.VInputTag(
777  cms.InputTag('patPFJetMETtype1p2Corr'+postfix, 'type2' ),
778  cms.InputTag('patPFJetMETtype1p2CorrUnclusteredEnDown'+postfix, 'type2' ),
779  cms.InputTag('patPFJetMETtype2Corr'+postfix, 'type2' ),
780  cms.InputTag('patPFJetMETtype2CorrUnclusteredEnDown'+postfix, 'type2' ),
781  cms.InputTag('patPFJetMETtype1p2Corr'+postfix, 'offset'),
782  cms.InputTag('patPFJetMETtype1p2CorrUnclusteredEnDown'+postfix, 'offset'),
783  cms.InputTag('pfCandMETcorr'+postfix),
784  cms.InputTag('pfCandMETcorrUnclusteredEnDown'+postfix)
785  )
786  ))
787  metUncertaintySequence += getattr(process, "patType1p2CorrectedPFMetUnclusteredEnDown"+postfix)
788  collectionsToKeep.append('patType1p2CorrectedPFMetUnclusteredEnDown'+postfix)
789 
790  #--------------------------------------------------------------------------------------------
791  # propagate shifted electron/photon, muon and tau-jet energies to MET
792  #--------------------------------------------------------------------------------------------
793 
794  metProducers = [ getattr(process, "patPFMet"+postfix),
795  getattr(process, "patType1CorrectedPFMet"+postfix) ]
796  if makeType1p2corrPFMEt:
797  metProducers.append( getattr(process, "patType1p2CorrectedPFMet"+postfix) )
798  for metProducer in metProducers:
799 
800  if self._isValidInputTag(shiftedParticleCollections['electronCollection']):
801  metCollectionsUp_Down = \
803  process, shiftedParticleCollections['electronCollection'].value(), "Electron", "En",
804  shiftedParticleCollections['electronCollectionEnUp'], shiftedParticleCollections['electronCollectionEnDown'],
805  metProducer, metUncertaintySequence, postfix)
806  collectionsToKeep.extend(metCollectionsUp_Down)
807 
808  if self._isValidInputTag(shiftedParticleCollections['photonCollection']):
809  metCollectionsUp_Down = \
811  process, shiftedParticleCollections['photonCollection'].value(), "Photon", "En",
812  shiftedParticleCollections['photonCollectionEnUp'], shiftedParticleCollections['photonCollectionEnDown'],
813  metProducer, metUncertaintySequence, postfix)
814  collectionsToKeep.extend(metCollectionsUp_Down)
815 
816  if self._isValidInputTag(shiftedParticleCollections['muonCollection']):
817  metCollectionsUp_Down = \
819  process, shiftedParticleCollections['muonCollection'].value(), "Muon", "En",
820  shiftedParticleCollections['muonCollectionEnUp'], shiftedParticleCollections['muonCollectionEnDown'],
821  metProducer, metUncertaintySequence, postfix)
822  collectionsToKeep.extend(metCollectionsUp_Down)
823 
824  if self._isValidInputTag(shiftedParticleCollections['tauCollection']):
825  metCollectionsUp_Down = \
827  process, shiftedParticleCollections['tauCollection'].value(), "Tau", "En",
828  shiftedParticleCollections['tauCollectionEnUp'], shiftedParticleCollections['tauCollectionEnDown'],
829  metProducer, metUncertaintySequence, postfix)
830  collectionsToKeep.extend(metCollectionsUp_Down)
831 
832  def _addPFCandidatesForPFMEtInput(self, process, metUncertaintySequence,
833  particleCollection, particleType, shiftType, particleCollectionShiftUp, particleCollectionShiftDown,
834  dRmatch,
835  pfCandCollection, postfix):
836 
837  srcUnshiftedObjects = particleCollection
838  if isinstance(srcUnshiftedObjects, cms.InputTag):
839  srcUnshiftedObjects = srcUnshiftedObjects.value()
840  moduleShiftUp = cms.EDProducer("ShiftedPFCandidateProducerForPFMEtMVA",
841  srcPFCandidates = pfCandCollection,
842  srcUnshiftedObjects = cms.InputTag(srcUnshiftedObjects),
843  srcShiftedObjects = cms.InputTag(particleCollectionShiftUp),
844  dRmatch_PFCandidate = cms.double(dRmatch)
845  )
846  moduleNameShiftUp = "pfCandidates%s%sUpForMEtUncertainties" % (particleType, shiftType)
847  moduleNameShiftUp += postfix
848  setattr(process, moduleNameShiftUp, moduleShiftUp)
849  metUncertaintySequence += moduleShiftUp
850 
851  moduleShiftDown = moduleShiftUp.clone(
852  srcShiftedObjects = cms.InputTag(particleCollectionShiftDown)
853  )
854  moduleNameShiftDown = "pfCandidates%s%sDownForMEtUncertainties" % (particleType, shiftType)
855  moduleNameShiftDown += postfix
856  setattr(process, moduleNameShiftDown, moduleShiftDown)
857  metUncertaintySequence += moduleShiftDown
858 
859  return ( moduleNameShiftUp, moduleNameShiftDown )
860 
861  def _getLeptonsForPFMEtInput(self, shiftedParticleCollections, substituteKeyUnshifted = None, substituteKeyShifted = None, postfix=""):
862  retVal = []
863  for collectionName in [ 'electronCollection',
864  'photonCollection',
865  'muonCollection',
866  'tauCollection' ]:
867  if self._isValidInputTag(shiftedParticleCollections[collectionName]):
868  if substituteKeyUnshifted is not None and substituteKeyUnshifted in shiftedParticleCollections.keys() and \
869  substituteKeyShifted is not None and substituteKeyShifted in shiftedParticleCollections.keys() and \
870  shiftedParticleCollections[collectionName] == shiftedParticleCollections[substituteKeyUnshifted]:
871  retVal.append(cms.InputTag(shiftedParticleCollections[substituteKeyShifted]))
872  else:
873  retVal.append(shiftedParticleCollections[collectionName])
874  return retVal
875 
876  def _addPATMEtProducer(self, process, metUncertaintySequence,
877  pfMEtCollection, patMEtCollection,
878  collectionsToKeep, postfix):
879 
880  module = patMETs.clone(
881  metSource = cms.InputTag(pfMEtCollection),
882  addMuonCorrections = cms.bool(False),
883  genMETSource = cms.InputTag('genMetTrue')
884  )
885  patMEtCollectionName = patMEtCollection+postfix
886  setattr(process, patMEtCollectionName, module)
887  metUncertaintySequence += module
888  collectionsToKeep.append(patMEtCollectionName)
889 
890  def _addPFMEtByMVA(self, process, metUncertaintySequence,
891  shiftedParticleCollections, pfCandCollection,
892  collectionsToKeep,
893  doSmearJets,
894  makePFMEtByMVA,
895  varyByNsigmas,
896  postfix):
897 
898  if not makePFMEtByMVA:
899  return
900 
901  if not hasattr(process, "pfMEtMVA"):
902  process.load("JetMETCorrections.METPUSubtraction.mvaPFMET_cff")
903 
904  lastUncorrectedJetCollectionForPFMEtByMVA = 'ak4PFJets'
905  lastCorrectedJetCollectionForPFMEtByMVA = 'calibratedAK5PFJetsForPFMEtMVA'
906  if postfix != "":
907  configtools.cloneProcessingSnippet(process, process.pfMEtMVAsequence, postfix)
908  lastCorrectedJetCollectionForPFMEtByMVA += postfix
909 
910  if doSmearJets:
911  process.load("RecoJets.Configuration.GenJetParticles_cff")
912  metUncertaintySequence += process.genParticlesForJetsNoNu
913  process.load("RecoJets.Configuration.RecoGenJets_cff")
914  metUncertaintySequence += process.ak4GenJetsNoNu
915  setattr(process, "smearedUncorrectedJetsForPFMEtByMVA"+postfix, cms.EDProducer("SmearedPFJetProducer",
916  src = cms.InputTag('ak4PFJets'),
917  jetCorrLabel = cms.string("ak4PFL1FastL2L3"),
918  dRmaxGenJetMatch = cms.string('TMath::Min(0.5, 0.1 + 0.3*TMath::Exp(-0.05*(genJetPt - 10.)))'),
919  sigmaMaxGenJetMatch = cms.double(5.),
920  inputFileName = cms.FileInPath('PhysicsTools/PatUtils/data/pfJetResolutionMCtoDataCorrLUT.root'),
921  lutName = cms.string('pfJetResolutionMCtoDataCorrLUT'),
922  jetResolutions = jetResolutions.METSignificance_params,
923  skipRawJetPtThreshold = cms.double(10.), # GeV
924  skipCorrJetPtThreshold = cms.double(1.e-2),
925  srcGenJets = cms.InputTag('ak4GenJetsNoNu')
926  ))
927  metUncertaintySequence += getattr(process, "smearedUncorrectedJetsForPFMEtByMVA"+postfix)
928  getattr(process, "calibratedAK5PFJetsForPFMEtMVA"+postfix).src = cms.InputTag('smearedUncorrectedJetsForPFMEtByMVA'+postfix)
929  getattr(process, "pfMEtMVA"+postfix).srcUncorrJets = cms.InputTag('smearedUncorrectedJetsForPFMEtByMVA'+postfix)
930  metUncertaintySequence += getattr(process, "calibratedAK5PFJetsForPFMEtMVA"+postfix)
931  setattr(process, "smearedCorrectedJetsForPFMEtByMVA"+postfix, getattr(process, "smearedUncorrectedJetsForPFMEtByMVA"+postfix).clone(
932  src = cms.InputTag('calibratedAK5PFJetsForPFMEtMVA'+postfix),
933  jetCorrLabel = cms.string("")
934  ))
935  metUncertaintySequence += getattr(process, "smearedCorrectedJetsForPFMEtByMVA"+postfix)
936  getattr(process, "pfMEtMVA"+postfix).srcCorrJets = cms.InputTag('smearedCorrectedJetsForPFMEtByMVA'+postfix)
937  metUncertaintySequence += getattr(process, "pfMEtMVA"+postfix)
938  else:
939  metUncertaintySequence += getattr(process, "pfMEtMVAsequence"+postfix)
940  self._addPATMEtProducer(process, metUncertaintySequence,
941  'pfMEtMVA'+postfix, 'patPFMetMVA', collectionsToKeep, postfix)
942 
943  for leptonCollection in [ [ 'Electron', 'En', 'electronCollection', 0.3 ],
944  [ 'Photon', 'En', 'photonCollection', 0.3 ],
945  [ 'Muon', 'En', 'muonCollection', 0.3 ],
946  [ 'Tau', 'En', 'tauCollection', 0.3 ] ]:
947  if self._isValidInputTag(shiftedParticleCollections[leptonCollection[2]]):
948  pfCandCollectionLeptonShiftUp, pfCandCollectionLeptonShiftDown = \
950  process, metUncertaintySequence,
951  shiftedParticleCollections['%s' % leptonCollection[2]], leptonCollection[0], leptonCollection[1],
952  shiftedParticleCollections['%s%sUp' % (leptonCollection[2], leptonCollection[1])],
953  shiftedParticleCollections['%s%sDown' % (leptonCollection[2], leptonCollection[1])],
954  leptonCollection[3],
955  pfCandCollection, postfix)
956  modulePFMEtLeptonShiftUp = getattr(process, "pfMEtMVA"+postfix).clone(
957  srcPFCandidates = cms.InputTag(pfCandCollectionLeptonShiftUp),
958  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(
959  shiftedParticleCollections, leptonCollection[2], '%s%sUp' % (leptonCollection[2], leptonCollection[1]), postfix=postfix))
960  )
961  modulePFMEtLeptonShiftUpName = "pfMEtMVA%s%sUp" % (leptonCollection[0], leptonCollection[1])
962  modulePFMEtLeptonShiftUpName += postfix
963  setattr(process, modulePFMEtLeptonShiftUpName, modulePFMEtLeptonShiftUp)
964  metUncertaintySequence += modulePFMEtLeptonShiftUp
965  self._addPATMEtProducer(process, metUncertaintySequence,
966  modulePFMEtLeptonShiftUpName, 'patPFMetMVA%s%sUp' % (leptonCollection[0], leptonCollection[1]), collectionsToKeep, postfix)
967  modulePFMEtLeptonShiftDown = getattr(process, "pfMEtMVA"+postfix).clone(
968  srcPFCandidates = cms.InputTag(pfCandCollectionLeptonShiftDown),
969  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(
970  shiftedParticleCollections, leptonCollection[2], '%s%sDown' % (leptonCollection[2], leptonCollection[1]), postfix=postfix))
971  )
972  modulePFMEtLeptonShiftDownName = "pfMEtMVA%s%sDown" % (leptonCollection[0], leptonCollection[1])
973  modulePFMEtLeptonShiftDownName += postfix
974  setattr(process, modulePFMEtLeptonShiftDownName, modulePFMEtLeptonShiftDown)
975  metUncertaintySequence += modulePFMEtLeptonShiftDown
976  self._addPATMEtProducer(process, metUncertaintySequence,
977  modulePFMEtLeptonShiftDownName, 'patPFMetMVA%s%sDown' % (leptonCollection[0], leptonCollection[1]), collectionsToKeep, postfix)
978 
979  if self._isValidInputTag(shiftedParticleCollections['jetCollection']):
980  setattr(process, "uncorrectedJetsEnUpForPFMEtByMVA"+postfix, cms.EDProducer("ShiftedPFJetProducer",
981  src = cms.InputTag(lastUncorrectedJetCollectionForPFMEtByMVA),
982  jetCorrInputFileName = cms.FileInPath('PhysicsTools/PatUtils/data/Summer12_V2_DATA_AK5PF_UncertaintySources.txt'),
983  jetCorrUncertaintyTag = cms.string("SubTotalDataMC"),
984  addResidualJES = cms.bool(True),
985  jetCorrLabelUpToL3 = cms.string("ak4PFL1FastL2L3"),
986  jetCorrLabelUpToL3Res = cms.string("ak4PFL1FastL2L3Residual"),
987  shiftBy = cms.double(+1.*varyByNsigmas)
988  ))
989  metUncertaintySequence += getattr(process, "uncorrectedJetsEnUpForPFMEtByMVA"+postfix)
990  setattr(process, "uncorrectedJetsEnDownForPFMEtByMVA"+postfix, getattr(process, "uncorrectedJetsEnUpForPFMEtByMVA"+postfix).clone(
991  shiftBy = cms.double(-1.*varyByNsigmas)
992  ))
993  metUncertaintySequence += getattr(process, "uncorrectedJetsEnDownForPFMEtByMVA"+postfix)
994  setattr(process, "correctedJetsEnUpForPFMEtByMVA"+postfix, getattr(process, "uncorrectedJetsEnUpForPFMEtByMVA"+postfix).clone(
995  src = cms.InputTag(lastCorrectedJetCollectionForPFMEtByMVA),
996  addResidualJES = cms.bool(False),
997  shiftBy = cms.double(+1.*varyByNsigmas)
998  ))
999  metUncertaintySequence += getattr(process, "correctedJetsEnUpForPFMEtByMVA"+postfix)
1000  setattr(process, "correctedJetsEnDownForPFMEtByMVA"+postfix, getattr(process, "correctedJetsEnUpForPFMEtByMVA"+postfix).clone(
1001  shiftBy = cms.double(-1.*varyByNsigmas)
1002  ))
1003  metUncertaintySequence += getattr(process, "correctedJetsEnDownForPFMEtByMVA"+postfix)
1004  pfCandCollectionJetEnUp, pfCandCollectionJetEnDown = \
1006  process, metUncertaintySequence,
1007  shiftedParticleCollections['lastJetCollection'], "Jet", "En",
1008  shiftedParticleCollections['jetCollectionEnUpForCorrMEt'], shiftedParticleCollections['jetCollectionEnDownForCorrMEt'],
1009  0.5,
1010  pfCandCollection, postfix)
1011  setattr(process, "pfMEtMVAJetEnUp"+postfix, getattr(process, "pfMEtMVA").clone(
1012  srcCorrJets = cms.InputTag('correctedJetsEnUpForPFMEtByMVA'+postfix),
1013  srcUncorrJets = cms.InputTag('uncorrectedJetsEnUpForPFMEtByMVA'+postfix),
1014  srcPFCandidates = cms.InputTag(pfCandCollectionJetEnUp),
1015  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1016  ))
1017  metUncertaintySequence += getattr(process, "pfMEtMVAJetEnUp"+postfix)
1018  self._addPATMEtProducer(process, metUncertaintySequence,
1019  'pfMEtMVAJetEnUp'+postfix, 'patPFMetMVAJetEnUp', collectionsToKeep, postfix)
1020  setattr(process, "pfMEtMVAJetEnDown"+postfix, getattr(process, "pfMEtMVA"+postfix).clone(
1021  srcCorrJets = cms.InputTag('correctedJetsEnDownForPFMEtByMVA'+postfix),
1022  srcUncorrJets = cms.InputTag('uncorrectedJetsEnDownForPFMEtByMVA'+postfix),
1023  srcPFCandidates = cms.InputTag(pfCandCollectionJetEnDown),
1024  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1025  ))
1026  metUncertaintySequence += getattr(process, "pfMEtMVAJetEnDown"+postfix)
1027  self._addPATMEtProducer(process, metUncertaintySequence,
1028  'pfMEtMVAJetEnDown'+postfix, 'patPFMetMVAJetEnDown', collectionsToKeep, postfix)
1029 
1030  if hasattr(process, "smearedUncorrectedJetsForPFMEtByMVA"+postfix):
1031  setattr(process, "uncorrectedJetsResUpForPFMEtByMVA"+postfix, getattr(process, "smearedUncorrectedJetsForPFMEtByMVA"+postfix).clone(
1032  shiftBy = cms.double(-1.*varyByNsigmas)
1033  ))
1034  metUncertaintySequence += getattr(process, "uncorrectedJetsResUpForPFMEtByMVA"+postfix)
1035  setattr(process, "uncorrectedJetsResDownForPFMEtByMVA"+postfix, getattr(process, "smearedUncorrectedJetsForPFMEtByMVA"+postfix).clone(
1036  shiftBy = cms.double(+1.*varyByNsigmas)
1037  ))
1038  metUncertaintySequence += getattr(process, "uncorrectedJetsResDownForPFMEtByMVA"+postfix)
1039  setattr(process, "correctedJetsResUpForPFMEtByMVA"+postfix, getattr(process, "smearedCorrectedJetsForPFMEtByMVA"+postfix).clone(
1040  shiftBy = cms.double(-1.*varyByNsigmas)
1041  ))
1042  metUncertaintySequence += getattr(process, "correctedJetsResUpForPFMEtByMVA"+postfix)
1043  setattr(process, "correctedJetsResDownForPFMEtByMVA"+postfix, getattr(process, "smearedCorrectedJetsForPFMEtByMVA"+postfix).clone(
1044  shiftBy = cms.double(+1.*varyByNsigmas)
1045  ))
1046  metUncertaintySequence += getattr(process, "correctedJetsResDownForPFMEtByMVA"+postfix)
1047  pfCandCollectionJetResUp, pfCandCollectionJetResDown = \
1049  process, metUncertaintySequence,
1050  shiftedParticleCollections['jetCollection'], "Jet", "Res",
1051  shiftedParticleCollections['jetCollectionResUp'], shiftedParticleCollections['jetCollectionResDown'],
1052  0.5,
1053  pfCandCollection, postfix)
1054  setattr(process, "pfMEtMVAJetResUp"+postfix, getattr(process, "pfMEtMVA"+postfix).clone(
1055  srcCorrJets = cms.InputTag('correctedJetsResUpForPFMEtByMVA'+postfix),
1056  srcUncorrJets = cms.InputTag('uncorrectedJetsResUpForPFMEtByMVA'+postfix),
1057  srcPFCandidates = cms.InputTag(pfCandCollectionJetResUp),
1058  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1059  ))
1060  metUncertaintySequence += getattr(process, "pfMEtMVAJetResUp"+postfix)
1061  self._addPATMEtProducer(process, metUncertaintySequence,
1062  'pfMEtMVAJetResUp'+postfix, 'patPFMetMVAJetResUp', collectionsToKeep, postfix)
1063  setattr(process, "pfMEtMVAJetResDown"+postfix, getattr(process, "pfMEtMVA"+postfix).clone(
1064  srcCorrJets = cms.InputTag('correctedJetsResDownForPFMEtByMVA'+postfix),
1065  srcUncorrJets = cms.InputTag('uncorrectedJetsResDownForPFMEtByMVA'+postfix),
1066  srcPFCandidates = cms.InputTag(pfCandCollectionJetResDown),
1067  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1068  ))
1069  metUncertaintySequence += getattr(process, "pfMEtMVAJetResDown"+postfix)
1070  self._addPATMEtProducer(process, metUncertaintySequence,
1071  'pfMEtMVAJetResDown'+postfix, 'patPFMetMVAJetResDown', collectionsToKeep, postfix)
1072 
1073  setattr(process, "pfCandsNotInJetUnclusteredEnUpForPFMEtByMVA"+postfix, cms.EDProducer("ShiftedPFCandidateProducer",
1074  src = cms.InputTag('pfCandsNotInJet'),
1075  shiftBy = cms.double(+1.*varyByNsigmas),
1076  uncertainty = cms.double(0.10)
1077  ))
1078  metUncertaintySequence += getattr(process, "pfCandsNotInJetUnclusteredEnUpForPFMEtByMVA"+postfix)
1079  setattr(process, "pfCandsNotInJetUnclusteredEnDownForPFMEtByMVA"+postfix, getattr(process, "pfCandsNotInJetUnclusteredEnUpForPFMEtByMVA"+postfix).clone(
1080  shiftBy = cms.double(-1.*varyByNsigmas)
1081  ))
1082  metUncertaintySequence += getattr(process, "pfCandsNotInJetUnclusteredEnDownForPFMEtByMVA"+postfix)
1083  pfCandCollectionUnclusteredEnUp, pfCandCollectionUnclusteredEnDown = \
1085  process, metUncertaintySequence,
1086  pfCandCollection, "Unclustered", "En",
1087  'pfCandsNotInJetUnclusteredEnUpForPFMEtByMVA'+postfix, 'pfCandsNotInJetUnclusteredEnDownForPFMEtByMVA'+postfix, #fixme MM
1088  0.01,
1089  pfCandCollection, postfix)
1090  setattr(process, "pfMEtMVAUnclusteredEnUp"+postfix, getattr(process, "pfMEtMVA"+postfix).clone(
1091  srcPFCandidates = cms.InputTag(pfCandCollectionUnclusteredEnUp),
1092  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1093  ))
1094  metUncertaintySequence += getattr(process, "pfMEtMVAUnclusteredEnUp"+postfix)
1095  self._addPATMEtProducer(process, metUncertaintySequence,
1096  'pfMEtMVAUnclusteredEnUp'+postfix, 'patPFMetMVAUnclusteredEnUp', collectionsToKeep, postfix)
1097  setattr(process, "pfMEtMVAUnclusteredEnDown"+postfix, getattr(process, "pfMEtMVA"+postfix).clone(
1098  srcPFCandidates = cms.InputTag(pfCandCollectionUnclusteredEnDown),
1099  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1100  ))
1101  metUncertaintySequence += getattr(process, "pfMEtMVAUnclusteredEnDown"+postfix)
1102  self._addPATMEtProducer(process, metUncertaintySequence,
1103  'pfMEtMVAUnclusteredEnDown'+postfix, 'patPFMetMVAUnclusteredEnDown', collectionsToKeep, postfix)
1104 
1105 # IN HERE
1106  def _addNoPileUpPFMEt(self, process, metUncertaintySequence,
1107  shiftedParticleCollections, pfCandCollection,
1108  collectionsToKeep,
1109  doSmearJets,
1110  makeNoPileUpPFMEt,
1111  varyByNsigmas,
1112  postfix):
1113 
1114  if not makeNoPileUpPFMEt:
1115  return
1116 
1117  if not hasattr(process, "noPileUpPFMEt"):
1118  process.load("JetMETCorrections.METPUSubtraction.noPileUpPFMET_cff")
1119 
1120  lastUncorrectedJetCollectionForNoPileUpPFMEt = 'ak4PFJets'
1121  lastCorrectedJetCollectionForNoPileUpPFMEt = 'calibratedAK5PFJetsForNoPileUpPFMEt'
1122  if postfix != "":
1123  configtools.cloneProcessingSnippet(process, process.noPileUpPFMEtSequence, postfix)
1124  lastCorrectedJetCollectionForNoPileUpPFMEt+= postfix
1125 
1126 
1127  if doSmearJets:
1128  process.load("RecoJets.Configuration.GenJetParticles_cff")
1129  metUncertaintySequence += process.genParticlesForJetsNoNu
1130  process.load("RecoJets.Configuration.RecoGenJets_cff")
1131  metUncertaintySequence += process.ak4GenJetsNoNu
1132  setattr(process, "smearedUncorrectedJetsForNoPileUpPFMEt"+postfix, cms.EDProducer("SmearedPFJetProducer",
1133  src = cms.InputTag('ak4PFJets'),
1134  jetCorrLabel = cms.string("ak4PFL1FastL2L3"),
1135  dRmaxGenJetMatch = cms.string('TMath::Min(0.5, 0.1 + 0.3*TMath::Exp(-0.05*(genJetPt - 10.)))'),
1136  sigmaMaxGenJetMatch = cms.double(5.),
1137  inputFileName = cms.FileInPath('PhysicsTools/PatUtils/data/pfJetResolutionMCtoDataCorrLUT.root'),
1138  lutName = cms.string('pfJetResolutionMCtoDataCorrLUT'),
1139  jetResolutions = jetResolutions.METSignificance_params,
1140  skipRawJetPtThreshold = cms.double(10.), # GeV
1141  skipCorrJetPtThreshold = cms.double(1.e-2),
1142  srcGenJets = cms.InputTag('ak4GenJetsNoNu'),
1143  ##verbosity = cms.int32(1)
1144  ))
1145  metUncertaintySequence += getattr(process, "smearedUncorrectedJetsForNoPileUpPFMEt"+postfix)
1146  getattr(process, "calibratedAK5PFJetsForNoPileUpPFMEt"+postfix).src = cms.InputTag('smearedUncorrectedJetsForNoPileUpPFMEt'+postfix)
1147  metUncertaintySequence += getattr(process, "noPileUpPFMEtSequence"+postfix)
1148  self._addPATMEtProducer(process, metUncertaintySequence,
1149  'noPileUpPFMEt'+postfix, 'patPFMetNoPileUp', collectionsToKeep, postfix)
1150 
1151  for leptonCollection in [ [ 'Electron', 'En', 'electronCollection', 0.3 ],
1152  [ 'Photon', 'En', 'photonCollection', 0.3 ],
1153  [ 'Muon', 'En', 'muonCollection', 0.3 ],
1154  [ 'Tau', 'En', 'tauCollection', 0.3 ] ]:
1155  if self._isValidInputTag(shiftedParticleCollections[leptonCollection[2]]):
1156  pfCandCollectionLeptonShiftUp, pfCandCollectionLeptonShiftDown = \
1158  process, metUncertaintySequence,
1159  shiftedParticleCollections['%s' % leptonCollection[2]], leptonCollection[0], leptonCollection[1],
1160  shiftedParticleCollections['%s%sUp' % (leptonCollection[2], leptonCollection[1])], shiftedParticleCollections['%s%sDown' % (leptonCollection[2], leptonCollection[1])],
1161  leptonCollection[3],
1162  pfCandCollection, postfix)
1163  modulePFCandidateToVertexAssociationShiftUp = process.pfCandidateToVertexAssociation.clone(
1164  PFCandidateCollection = cms.InputTag(pfCandCollectionLeptonShiftUp)
1165  )
1166  modulePFCandidateToVertexAssociationShiftUpName = "pfCandidateToVertexAssociation%s%sUp" % (leptonCollection[0], leptonCollection[1])
1167  modulePFCandidateToVertexAssociationShiftUpName += postfix
1168  setattr(process, modulePFCandidateToVertexAssociationShiftUpName, modulePFCandidateToVertexAssociationShiftUp)
1169  metUncertaintySequence += modulePFCandidateToVertexAssociationShiftUp
1170  modulePFMEtDataLeptonShiftUp = getattr(process, "noPileUpPFMEtData"+postfix).clone(
1171  srcPFCandidates = cms.InputTag(pfCandCollectionLeptonShiftUp),
1172  srcPFCandToVertexAssociations = cms.InputTag(modulePFCandidateToVertexAssociationShiftUpName)
1173  )
1174  modulePFMEtDataLeptonShiftUpName = "noPileUpPFMEtData%s%sUp" % (leptonCollection[0], leptonCollection[1])
1175  modulePFMEtDataLeptonShiftUpName += postfix
1176  setattr(process, modulePFMEtDataLeptonShiftUpName, modulePFMEtDataLeptonShiftUp)
1177  metUncertaintySequence += modulePFMEtDataLeptonShiftUp
1178  modulePFMEtLeptonShiftUp = getattr(process, "noPileUpPFMEt"+postfix).clone(
1179  srcMVAMEtData = cms.InputTag(modulePFMEtDataLeptonShiftUpName),
1180  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(
1181  shiftedParticleCollections, leptonCollection[2], '%s%sUp' % (leptonCollection[2], leptonCollection[1]), postfix=postfix))
1182  )
1183  modulePFMEtLeptonShiftUpName = "noPileUpPFMEt%s%sUp" % (leptonCollection[0], leptonCollection[1])
1184  modulePFMEtLeptonShiftUpName += postfix
1185  setattr(process, modulePFMEtLeptonShiftUpName, modulePFMEtLeptonShiftUp)
1186  metUncertaintySequence += modulePFMEtLeptonShiftUp
1187  self._addPATMEtProducer(process, metUncertaintySequence,
1188  modulePFMEtLeptonShiftUpName, 'patPFMetNoPileUp%s%sUp' % (leptonCollection[0], leptonCollection[1]), collectionsToKeep, postfix)
1189  modulePFCandidateToVertexAssociationShiftDown = modulePFCandidateToVertexAssociationShiftUp.clone(
1190  PFCandidateCollection = cms.InputTag(pfCandCollectionLeptonShiftDown)
1191  )
1192  modulePFCandidateToVertexAssociationShiftDownName = "pfCandidateToVertexAssociation%s%sDown" % (leptonCollection[0], leptonCollection[1])
1193  modulePFCandidateToVertexAssociationShiftDownName += postfix
1194  setattr(process, modulePFCandidateToVertexAssociationShiftDownName, modulePFCandidateToVertexAssociationShiftDown)
1195  metUncertaintySequence += modulePFCandidateToVertexAssociationShiftDown
1196  modulePFMEtDataLeptonShiftDown = getattr(process, "noPileUpPFMEtData"+postfix).clone(
1197  srcPFCandidates = cms.InputTag(pfCandCollectionLeptonShiftDown),
1198  srcPFCandToVertexAssociations = cms.InputTag(modulePFCandidateToVertexAssociationShiftDownName)
1199  )
1200  modulePFMEtDataLeptonShiftDownName = "noPileUpPFMEtData%s%sDown" % (leptonCollection[0], leptonCollection[1])
1201  modulePFMEtDataLeptonShiftDownName += postfix
1202  setattr(process, modulePFMEtDataLeptonShiftDownName, modulePFMEtDataLeptonShiftDown)
1203  metUncertaintySequence += modulePFMEtDataLeptonShiftDown
1204  modulePFMEtLeptonShiftDown = getattr(process, "noPileUpPFMEt"+postfix).clone(
1205  srcMVAMEtData = cms.InputTag(modulePFMEtDataLeptonShiftDownName),
1206  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(
1207  shiftedParticleCollections, leptonCollection[2], '%s%sDown' % (leptonCollection[2], leptonCollection[1]), postfix=postfix))
1208  )
1209  modulePFMEtLeptonShiftDownName = "noPileUpPFMEt%s%sDown" % (leptonCollection[0], leptonCollection[1])
1210  modulePFMEtLeptonShiftDownName += postfix
1211  setattr(process, modulePFMEtLeptonShiftDownName, modulePFMEtLeptonShiftDown)
1212  metUncertaintySequence += modulePFMEtLeptonShiftDown
1213  self._addPATMEtProducer(process, metUncertaintySequence,
1214  modulePFMEtLeptonShiftDownName, 'patPFMetNoPileUp%s%sDown' % (leptonCollection[0], leptonCollection[1]), collectionsToKeep, postfix)
1215 
1216  if self._isValidInputTag(shiftedParticleCollections['jetCollection']):
1217  setattr(process, "uncorrectedJetsEnUpForNoPileUpPFMEt"+postfix, cms.EDProducer("ShiftedPFJetProducer",
1218  src = cms.InputTag(lastUncorrectedJetCollectionForNoPileUpPFMEt),
1219  jetCorrInputFileName = cms.FileInPath('PhysicsTools/PatUtils/data/Summer12_V2_DATA_AK5PF_UncertaintySources.txt'),
1220  jetCorrUncertaintyTag = cms.string("SubTotalDataMC"),
1221  addResidualJES = cms.bool(False),
1222  jetCorrLabelUpToL3 = cms.string("ak4PFL1FastL2L3"),
1223  jetCorrLabelUpToL3Res = cms.string("ak4PFL1FastL2L3Residual"),
1224  shiftBy = cms.double(+1.*varyByNsigmas),
1225  ##verbosity = cms.int32(1)
1226  ))
1227  metUncertaintySequence += getattr(process, "uncorrectedJetsEnUpForNoPileUpPFMEt"+postfix)
1228  setattr(process, "correctedJetsEnUpForNoPileUpPFMEt"+postfix, getattr(process, "uncorrectedJetsEnUpForNoPileUpPFMEt"+postfix).clone(
1229  src = cms.InputTag(lastCorrectedJetCollectionForNoPileUpPFMEt),
1230  addResidualJES = cms.bool(False),
1231  shiftBy = cms.double(+1.*varyByNsigmas)
1232  ))
1233  metUncertaintySequence += getattr(process, "correctedJetsEnUpForNoPileUpPFMEt"+postfix)
1234  setattr(process, "puJetIdForNoPileUpPFMEtJetEnUp"+postfix, getattr(process, "puJetIdForNoPileUpPFMEt"+postfix).clone(
1235  jets = cms.InputTag('correctedJetsEnUpForNoPileUpPFMEt'+postfix)
1236  ))
1237  metUncertaintySequence += getattr(process, "puJetIdForNoPileUpPFMEtJetEnUp"+postfix)
1238  setattr(process, "noPileUpPFMEtDataJetEnUp"+postfix, getattr(process, "noPileUpPFMEtData"+postfix).clone(
1239  srcJets = cms.InputTag('correctedJetsEnUpForNoPileUpPFMEt'+postfix),
1240  srcJetIds = cms.InputTag('puJetIdForNoPileUpPFMEtJetEnUp'+postfix, 'fullId')
1241  ))
1242  metUncertaintySequence += getattr(process, "noPileUpPFMEtDataJetEnUp"+postfix)
1243  setattr(process, "noPileUpPFMEtJetEnUp"+postfix, getattr(process, "noPileUpPFMEt"+postfix).clone(
1244  srcMVAMEtData = cms.InputTag('noPileUpPFMEtDataJetEnUp'+postfix),
1245  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1246  ))
1247  metUncertaintySequence += getattr(process, "noPileUpPFMEtJetEnUp"+postfix)
1248  self._addPATMEtProducer(process, metUncertaintySequence,
1249  'noPileUpPFMEtJetEnUp'+postfix, 'patPFMetNoPileUpJetEnUp', collectionsToKeep, postfix)
1250  setattr(process, "uncorrectedJetsEnDownForNoPileUpPFMEt"+postfix, getattr(process, "uncorrectedJetsEnUpForNoPileUpPFMEt"+postfix).clone(
1251  shiftBy = cms.double(-1.*varyByNsigmas)
1252  ))
1253  metUncertaintySequence += getattr(process, "uncorrectedJetsEnDownForNoPileUpPFMEt"+postfix)
1254  setattr(process, "correctedJetsEnDownForNoPileUpPFMEt"+postfix, getattr(process, "correctedJetsEnUpForNoPileUpPFMEt"+postfix).clone(
1255  shiftBy = cms.double(-1.*varyByNsigmas)
1256  ))
1257  metUncertaintySequence += getattr(process, "correctedJetsEnDownForNoPileUpPFMEt"+postfix)
1258  setattr(process, "puJetIdForNoPileUpPFMEtJetEnDown"+postfix, getattr(process, "puJetIdForNoPileUpPFMEt"+postfix).clone(
1259  jets = cms.InputTag('correctedJetsEnDownForNoPileUpPFMEt'+postfix)
1260  ))
1261  metUncertaintySequence += getattr(process, "puJetIdForNoPileUpPFMEtJetEnDown"+postfix)
1262  setattr(process, "noPileUpPFMEtDataJetEnDown"+postfix, getattr(process, "noPileUpPFMEtData"+postfix).clone(
1263  srcJets = cms.InputTag('correctedJetsEnDownForNoPileUpPFMEt'+postfix),
1264  srcJetIds = cms.InputTag('puJetIdForNoPileUpPFMEtJetEnDown'+postfix, 'fullId')
1265  ))
1266  metUncertaintySequence += getattr(process, "noPileUpPFMEtDataJetEnDown"+postfix)
1267  setattr(process, "noPileUpPFMEtJetEnDown"+postfix, getattr(process, "noPileUpPFMEt"+postfix).clone(
1268  srcMVAMEtData = cms.InputTag('noPileUpPFMEtDataJetEnDown'+postfix),
1269  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1270  ))
1271  metUncertaintySequence += getattr(process, "noPileUpPFMEtJetEnDown"+postfix)
1272  self._addPATMEtProducer(process, metUncertaintySequence,
1273  'noPileUpPFMEtJetEnDown'+postfix, 'patPFMetNoPileUpJetEnDown', collectionsToKeep, postfix)
1274 
1275  if hasattr(process, "smearedUncorrectedJetsForNoPileUpPFMEt"+postfix):
1276  setattr(process, "smearedCorrectedJetsForNoPileUpPFMEt"+postfix, getattr(process, "smearedUncorrectedJetsForNoPileUpPFMEt"+postfix).clone(
1277  src = cms.InputTag('calibratedAK5PFJetsForNoPileUpPFMEt'+postfix),
1278  jetCorrLabel = cms.string("")
1279  ))
1280  setattr(process, "correctedJetsResUpForNoPileUpPFMEt"+postfix, getattr(process, "smearedCorrectedJetsForNoPileUpPFMEt"+postfix).clone(
1281  shiftBy = cms.double(-1.*varyByNsigmas)
1282  ))
1283  metUncertaintySequence += getattr(process, "correctedJetsResUpForNoPileUpPFMEt"+postfix)
1284  setattr(process, "correctedJetsResDownForNoPileUpPFMEt"+postfix, getattr(process, "smearedCorrectedJetsForNoPileUpPFMEt"+postfix).clone(
1285  shiftBy = cms.double(+1.*varyByNsigmas)
1286  ))
1287  metUncertaintySequence += getattr(process, "correctedJetsResDownForNoPileUpPFMEt"+postfix)
1288  setattr(process, "puJetIdForNoPileUpPFMEtJetResUp"+postfix, getattr(process, "puJetIdForNoPileUpPFMEt"+postfix).clone(
1289  jets = cms.InputTag('correctedJetsResUpForNoPileUpPFMEt'+postfix)
1290  ))
1291  metUncertaintySequence += getattr(process, "puJetIdForNoPileUpPFMEtJetResUp"+postfix)
1292  setattr(process, "noPileUpPFMEtDataJetResUp"+postfix, getattr(process, "noPileUpPFMEtData"+postfix).clone(
1293  srcJets = cms.InputTag('correctedJetsResUpForNoPileUpPFMEt'+postfix),
1294  srcJetIds = cms.InputTag('puJetIdForNoPileUpPFMEtJetResUp'+postfix, 'fullId')
1295  ))
1296  metUncertaintySequence += getattr(process, "noPileUpPFMEtDataJetResUp"+postfix)
1297  setattr(process, "noPileUpPFMEtJetResUp"+postfix, getattr(process, "noPileUpPFMEt"+postfix).clone(
1298  srcMVAMEtData = cms.InputTag('noPileUpPFMEtDataJetResUp'+postfix),
1299  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1300  ))
1301  metUncertaintySequence += getattr(process, "noPileUpPFMEtJetResUp"+postfix)
1302  self._addPATMEtProducer(process, metUncertaintySequence,
1303  'noPileUpPFMEtJetResUp'+postfix, 'patPFMetNoPileUpJetResUp', collectionsToKeep, postfix)
1304  setattr(process, "puJetIdForNoPileUpPFMEtJetResDown"+postfix, getattr(process, "puJetIdForNoPileUpPFMEt"+postfix).clone(
1305  jets = cms.InputTag('correctedJetsResDownForNoPileUpPFMEt'+postfix)
1306  ))
1307  metUncertaintySequence += getattr(process, "puJetIdForNoPileUpPFMEtJetResDown"+postfix)
1308  setattr(process, "noPileUpPFMEtDataJetResDown"+postfix, getattr(process, "noPileUpPFMEtData"+postfix).clone(
1309  srcJets = cms.InputTag('correctedJetsResDownForNoPileUpPFMEt'+postfix),
1310  srcJetIds = cms.InputTag('puJetIdForNoPileUpPFMEtJetResDown'+postfix, 'fullId')
1311  ))
1312  metUncertaintySequence += getattr(process, "noPileUpPFMEtDataJetResDown"+postfix)
1313  setattr(process, "noPileUpPFMEtJetResDown"+postfix, getattr(process, "noPileUpPFMEt"+postfix).clone(
1314  srcMVAMEtData = cms.InputTag('noPileUpPFMEtDataJetResDown'+postfix),
1315  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1316  ))
1317  metUncertaintySequence += getattr(process, "noPileUpPFMEtJetResDown"+postfix)
1318  self._addPATMEtProducer(process, metUncertaintySequence,
1319  'noPileUpPFMEtJetResDown'+postfix, 'patPFMetNoPileUpJetResDown', collectionsToKeep, postfix)
1320 
1321  setattr(process, "pfCandsUnclusteredEnUpForNoPileUpPFMEt"+postfix, cms.EDProducer("ShiftedPFCandidateProducerForNoPileUpPFMEt",
1322  srcPFCandidates = cms.InputTag('particleFlow'),
1323  srcJets = cms.InputTag('calibratedAK5PFJetsForNoPileUpPFMEt'+postfix),
1324  jetCorrInputFileName = cms.FileInPath('PhysicsTools/PatUtils/data/Summer12_V2_DATA_AK5PF_UncertaintySources.txt'),
1325  jetCorrUncertaintyTag = cms.string("SubTotalDataMC"),
1326  minJetPt = cms.double(10.0),
1327  shiftBy = cms.double(+1.*varyByNsigmas),
1328  unclEnUncertainty = cms.double(0.10)
1329  ))
1330  metUncertaintySequence += getattr(process, "pfCandsUnclusteredEnUpForNoPileUpPFMEt"+postfix)
1331  setattr(process, "pfCandidateToVertexAssociationUnclusteredEnUpForNoPileUpPFMEt"+postfix, process.pfCandidateToVertexAssociation.clone(
1332  PFCandidateCollection = cms.InputTag('pfCandsUnclusteredEnUpForNoPileUpPFMEt'+postfix)
1333  ))
1334  metUncertaintySequence += getattr(process, "pfCandidateToVertexAssociationUnclusteredEnUpForNoPileUpPFMEt"+postfix)
1335  setattr(process, "noPileUpPFMEtDataUnclusteredEnUp"+postfix, getattr(process, "noPileUpPFMEtData"+postfix).clone(
1336  srcPFCandidates = cms.InputTag('pfCandsUnclusteredEnUpForNoPileUpPFMEt'+postfix),
1337  srcPFCandToVertexAssociations = cms.InputTag('pfCandidateToVertexAssociationUnclusteredEnUpForNoPileUpPFMEt'+postfix),
1338  ))
1339  metUncertaintySequence += getattr(process, "noPileUpPFMEtDataUnclusteredEnUp"+postfix)
1340  setattr(process, "noPileUpPFMEtUnclusteredEnUp"+postfix, getattr(process, "noPileUpPFMEt"+postfix).clone(
1341  srcMVAMEtData = cms.InputTag('noPileUpPFMEtDataUnclusteredEnUp'+postfix),
1342  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1343  ))
1344  metUncertaintySequence += getattr(process, "noPileUpPFMEtUnclusteredEnUp"+postfix)
1345  self._addPATMEtProducer(process, metUncertaintySequence,
1346  'noPileUpPFMEtUnclusteredEnUp'+postfix, 'patPFMetNoPileUpUnclusteredEnUp', collectionsToKeep, postfix)
1347  setattr(process, "pfCandsUnclusteredEnDownForNoPileUpPFMEt"+postfix, getattr(process, "pfCandsUnclusteredEnUpForNoPileUpPFMEt"+postfix).clone(
1348  shiftBy = cms.double(-1.*varyByNsigmas),
1349  ))
1350  metUncertaintySequence += getattr(process, "pfCandsUnclusteredEnDownForNoPileUpPFMEt"+postfix)
1351  setattr(process, "pfCandidateToVertexAssociationUnclusteredEnDownForNoPileUpPFMEt"+postfix, process.pfCandidateToVertexAssociation.clone(
1352  PFCandidateCollection = cms.InputTag('pfCandsUnclusteredEnDownForNoPileUpPFMEt'+postfix)
1353  ))
1354  metUncertaintySequence += getattr(process, "pfCandidateToVertexAssociationUnclusteredEnDownForNoPileUpPFMEt"+postfix)
1355  setattr(process, "noPileUpPFMEtDataUnclusteredEnDown"+postfix, getattr(process, "noPileUpPFMEtData"+postfix).clone(
1356  srcPFCandidates = cms.InputTag('pfCandsUnclusteredEnDownForNoPileUpPFMEt'+postfix),
1357  srcPFCandToVertexAssociations = cms.InputTag('pfCandidateToVertexAssociationUnclusteredEnDownForNoPileUpPFMEt'+postfix),
1358  ))
1359  metUncertaintySequence += getattr(process, "noPileUpPFMEtDataUnclusteredEnDown"+postfix)
1360  setattr(process, "noPileUpPFMEtUnclusteredEnDown"+postfix, getattr(process, "noPileUpPFMEt"+postfix).clone(
1361  srcMVAMEtData = cms.InputTag('noPileUpPFMEtDataUnclusteredEnDown'+postfix),
1362  srcLeptons = cms.VInputTag(self._getLeptonsForPFMEtInput(shiftedParticleCollections, postfix=postfix))
1363  ))
1364  metUncertaintySequence += getattr(process, "noPileUpPFMEtUnclusteredEnDown"+postfix)
1365  self._addPATMEtProducer(process, metUncertaintySequence,
1366  'noPileUpPFMEtUnclusteredEnDown'+postfix, 'patPFMetNoPileUpUnclusteredEnDown', collectionsToKeep, postfix)
1367 
1368  def __call__(self, process,
1369  electronCollection = None,
1370  photonCollection = None,
1371  muonCollection = None,
1372  tauCollection = None,
1373  jetCollection = None,
1374  dRjetCleaning = None,
1375  jetCorrLabel = None,
1376  doSmearJets = None,
1377  makeType1corrPFMEt = None,
1378  makeType1p2corrPFMEt = None,
1379  makePFMEtByMVA = None,
1380  makeNoPileUpPFMEt = None,
1381  doApplyType0corr = None,
1382  sysShiftCorrParameter = None,
1383  doApplySysShiftCorr = None,
1384  jetSmearFileName = None,
1385  jetSmearHistogram = None,
1386  pfCandCollection = None,
1387  jetCorrPayloadName = None,
1388  varyByNsigmas = None,
1389  addToPatDefaultSequence = None,
1390  outputModule = None,
1391  postfix = None):
1392  electronCollection = self._initializeInputTag(electronCollection, 'electronCollection')
1393  photonCollection = self._initializeInputTag(photonCollection, 'photonCollection')
1394  muonCollection = self._initializeInputTag(muonCollection, 'muonCollection')
1395  tauCollection = self._initializeInputTag(tauCollection, 'tauCollection')
1396  jetCollection = self._initializeInputTag(jetCollection, 'jetCollection')
1397  if jetCorrLabel is None:
1398  jetCorrLabel = self._defaultParameters['jetCorrLabel'].value
1399  if dRjetCleaning is None:
1400  dRjetCleaning = self._defaultParameters['dRjetCleaning'].value
1401  if doSmearJets is None:
1402  doSmearJets = self._defaultParameters['doSmearJets'].value
1403  if makeType1corrPFMEt is None:
1404  makeType1corrPFMEt = self._defaultParameters['makeType1corrPFMEt'].value
1405  if makeType1p2corrPFMEt is None:
1406  makeType1p2corrPFMEt = self._defaultParameters['makeType1p2corrPFMEt'].value
1407  if makePFMEtByMVA is None:
1408  makePFMEtByMVA = self._defaultParameters['makePFMEtByMVA'].value
1409  if makeNoPileUpPFMEt is None:
1410  makeNoPileUpPFMEt = self._defaultParameters['makeNoPileUpPFMEt'].value
1411  if doApplyType0corr is None:
1412  doApplyType0corr = self._defaultParameters['doApplyType0corr'].value
1413  if sysShiftCorrParameter is None:
1414  sysShiftCorrParameter = self._defaultParameters['sysShiftCorrParameter'].value
1415  if doApplySysShiftCorr is None:
1416  doApplySysShiftCorr = self._defaultParameters['doApplySysShiftCorr'].value
1417  if sysShiftCorrParameter is None:
1418  if doApplySysShiftCorr:
1419  raise ValueError("MET sys. shift correction parameters must be specified explicitely !!")
1420  sysShiftCorrParameter = cms.PSet()
1421  if jetSmearFileName is None:
1422  jetSmearFileName = self._defaultParameters['jetSmearFileName'].value
1423  if jetSmearHistogram is None:
1424  jetSmearHistogram = self._defaultParameters['jetSmearHistogram'].value
1425  pfCandCollection = self._initializeInputTag(pfCandCollection, 'pfCandCollection')
1426  if jetCorrPayloadName is None:
1427  jetCorrPayloadName = self._defaultParameters['jetCorrPayloadName'].value
1428  if varyByNsigmas is None:
1429  varyByNsigmas = self._defaultParameters['varyByNsigmas'].value
1430  if addToPatDefaultSequence is None:
1431  addToPatDefaultSequence = self._defaultParameters['addToPatDefaultSequence'].value
1432  if outputModule is None:
1433  outputModule = self._defaultParameters['outputModule'].value
1434  if postfix is None:
1435  postfix = self._defaultParameters['postfix'].value
1436 
1437  self.setParameter('electronCollection', electronCollection)
1438  self.setParameter('photonCollection', photonCollection)
1439  self.setParameter('muonCollection', muonCollection)
1440  self.setParameter('tauCollection', tauCollection)
1441  self.setParameter('jetCollection', jetCollection)
1442  self.setParameter('jetCorrLabel', jetCorrLabel)
1443  self.setParameter('dRjetCleaning', dRjetCleaning)
1444  self.setParameter('doSmearJets', doSmearJets)
1445  self.setParameter('makeType1corrPFMEt', makeType1corrPFMEt)
1446  self.setParameter('makeType1p2corrPFMEt', makeType1p2corrPFMEt)
1447  self.setParameter('makePFMEtByMVA', makePFMEtByMVA)
1448  self.setParameter('makeNoPileUpPFMEt', makeNoPileUpPFMEt)
1449  self.setParameter('doApplyType0corr', doApplyType0corr)
1450  self.setParameter('doApplySysShiftCorr', doApplySysShiftCorr)
1451  self.setParameter('sysShiftCorrParameter', sysShiftCorrParameter)
1452  self.setParameter('jetSmearFileName', jetSmearFileName)
1453  self.setParameter('jetSmearHistogram', jetSmearHistogram)
1454  self.setParameter('pfCandCollection', pfCandCollection)
1455  self.setParameter('jetCorrPayloadName', jetCorrPayloadName)
1456  self.setParameter('varyByNsigmas', varyByNsigmas)
1457  self.setParameter('addToPatDefaultSequence', addToPatDefaultSequence)
1458  self.setParameter('outputModule', outputModule)
1459  self.setParameter('postfix', postfix)
1460 
1461  self.apply(process)
1462 
1463  def toolCode(self, process):
1464  electronCollection = self._parameters['electronCollection'].value
1465  photonCollection = self._parameters['photonCollection'].value
1466  muonCollection = self._parameters['muonCollection'].value
1467  tauCollection = self._parameters['tauCollection'].value
1468  jetCollection = self._parameters['jetCollection'].value
1469  jetCorrLabel = self._parameters['jetCorrLabel'].value
1470  dRjetCleaning = self._parameters['dRjetCleaning'].value
1471  doSmearJets = self._parameters['doSmearJets'].value
1472  makeType1corrPFMEt = self._parameters['makeType1corrPFMEt'].value
1473  makeType1p2corrPFMEt = self._parameters['makeType1p2corrPFMEt'].value
1474  makePFMEtByMVA = self._parameters['makePFMEtByMVA'].value
1475  makeNoPileUpPFMEt = self._parameters['makeNoPileUpPFMEt'].value
1476  doApplyType0corr = self._parameters['doApplyType0corr'].value
1477  sysShiftCorrParameter = self._parameters['sysShiftCorrParameter'].value
1478  doApplySysShiftCorr = self._parameters['doApplySysShiftCorr'].value
1479  jetSmearFileName = self._parameters['jetSmearFileName'].value
1480  jetSmearHistogram = self._parameters['jetSmearHistogram'].value
1481  pfCandCollection = self._parameters['pfCandCollection'].value
1482  jetCorrPayloadName = self._parameters['jetCorrPayloadName'].value
1483  varyByNsigmas = self._parameters['varyByNsigmas'].value
1484  addToPatDefaultSequence = self._parameters['addToPatDefaultSequence'].value
1485  outputModule = self._parameters['outputModule'].value
1486  postfix = self._parameters['postfix'].value
1487 
1488  metUncertaintySequence = cms.Sequence()
1489  setattr(process, "metUncertaintySequence"+postfix, metUncertaintySequence)
1490 
1491  collectionsToKeep = []
1492 
1493  # produce collection of jets not overlapping with reconstructed
1494  # electrons/photons, muons and tau-jet candidates
1495  jetsNotOverlappingWithLeptonsForMEtUncertainty = cms.EDProducer("PATJetCleaner",
1496  src = jetCollection,
1497  preselection = cms.string(''),
1498  checkOverlaps = cms.PSet(),
1499  finalCut = cms.string('')
1500  )
1501  numOverlapCollections = 0
1502  for collection in [
1503  [ 'electrons', electronCollection ],
1504  [ 'photons', photonCollection ],
1505  [ 'muons', muonCollection ],
1506  [ 'taus', tauCollection ] ]:
1507  if self._isValidInputTag(collection[1]):
1508  setattr(jetsNotOverlappingWithLeptonsForMEtUncertainty.checkOverlaps, collection[0], cms.PSet(
1509  src = collection[1],
1510  algorithm = cms.string("byDeltaR"),
1511  preselection = cms.string(""),
1512  deltaR = cms.double(0.5),
1513  checkRecoComponents = cms.bool(False),
1514  pairCut = cms.string(""),
1515  requireNoOverlaps = cms.bool(True),
1516  ))
1517  numOverlapCollections = numOverlapCollections + 1
1518  lastJetCollection = jetCollection.value()
1519  if numOverlapCollections >= 1:
1520  lastJetCollection = \
1521  self._addModuleToSequence(process, jetsNotOverlappingWithLeptonsForMEtUncertainty,
1522  [ jetCollection.value(), "NotOverlappingWithLeptonsForMEtUncertainty" ],
1523  metUncertaintySequence, postfix)
1524  cleanedJetCollection = lastJetCollection
1525 
1526  # smear jet energies to account for difference in jet resolutions between MC and Data
1527  # (cf. JME-10-014 PAS)
1528  jetCollectionResUp = None
1529  jetCollectionResDown = None
1530  if doSmearJets:
1531  lastJetCollection = \
1532  self._addSmearedJets(process, cleanedJetCollection, [ "smeared", jetCollection.value() ],
1533  jetSmearFileName, jetSmearHistogram, varyByNsigmas, postfix=postfix)
1534 
1535  jetCollectionResUp = \
1536  self._addSmearedJets(process, cleanedJetCollection, [ "smeared", jetCollection.value(), "ResUp" ],
1537  jetSmearFileName, jetSmearHistogram, varyByNsigmas,
1538  -1., postfix=postfix)
1539  collectionsToKeep.append(jetCollectionResUp)
1540  jetCollectionResDown = \
1541  self._addSmearedJets(process, cleanedJetCollection, [ "smeared", jetCollection.value(), "ResDown" ],
1542  jetSmearFileName, jetSmearHistogram, varyByNsigmas,
1543  +1., postfix=postfix)
1544  collectionsToKeep.append(jetCollectionResDown)
1545 
1546  collectionsToKeep.append(lastJetCollection)
1547 
1548  #--------------------------------------------------------------------------------------------
1549  # produce collection of electrons/photons, muons, tau-jet candidates and jets
1550  # shifted up/down in energy by their respective energy uncertainties
1551  #--------------------------------------------------------------------------------------------
1552 
1553  shiftedParticleCollections, addCollectionsToKeep = \
1554  self._addShiftedParticleCollections(process,
1555  electronCollection,
1556  photonCollection,
1557  muonCollection,
1558  tauCollection,
1559  jetCollection, cleanedJetCollection, lastJetCollection,
1560  jetCollectionResUp, jetCollectionResDown,
1561  varyByNsigmas,
1562  postfix)
1563  metUncertaintySequence += getattr(process, "shiftedParticlesForMEtUncertainties"+postfix)
1564  collectionsToKeep.extend(addCollectionsToKeep)
1565 
1566  #--------------------------------------------------------------------------------------------
1567  # propagate shifted particle energies to Type 1 and Type 1 + 2 corrected PFMET
1568  #--------------------------------------------------------------------------------------------
1569 
1570  self._addCorrPFMEt(process, metUncertaintySequence,
1571  shiftedParticleCollections, pfCandCollection,
1572  collectionsToKeep,
1573  doSmearJets,
1574  makeType1corrPFMEt,
1575  makeType1p2corrPFMEt,
1576  doApplyType0corr,
1577  sysShiftCorrParameter,
1578  doApplySysShiftCorr,
1579  jetCorrLabel,
1580  varyByNsigmas,
1581  postfix)
1582 
1583  #--------------------------------------------------------------------------------------------
1584  # propagate shifted particle energies to MVA-based PFMET
1585  #--------------------------------------------------------------------------------------------
1586 
1587  self._addPFMEtByMVA(process, metUncertaintySequence,
1588  shiftedParticleCollections, pfCandCollection,
1589  collectionsToKeep,
1590  doSmearJets,
1591  makePFMEtByMVA,
1592  varyByNsigmas,
1593  postfix)
1594 
1595  #--------------------------------------------------------------------------------------------
1596  # propagate shifted particle energies to no-PU PFMET
1597  #--------------------------------------------------------------------------------------------
1598 
1599  self._addNoPileUpPFMEt(process, metUncertaintySequence,
1600  shiftedParticleCollections, pfCandCollection,
1601  collectionsToKeep,
1602  doSmearJets,
1603  makeNoPileUpPFMEt,
1604  varyByNsigmas,
1605  postfix)
1606 
1607  # insert metUncertaintySequence into patDefaultSequence
1608  if hasattr(process,'options') and hasattr(process.options,'allowUnscheduled') and process.options.allowUnscheduled == True:
1609  addToPatDefaultSequence = False
1610  if addToPatDefaultSequence:
1611  if not hasattr(process, "patDefaultSequence"):
1612  raise ValueError("PAT default sequence is not defined !!")
1613  process.patDefaultSequence += metUncertaintySequence
1614 
1615  # add shifted + unshifted collections pf pat::Electrons/Photons,
1616  # Muons, Taus, Jets and MET to PAT-tuple event content
1617  if outputModule is not None and hasattr(process, outputModule):
1618  getattr(process, outputModule).outputCommands = _addEventContent(
1619  getattr(process, outputModule).outputCommands,
1620  [ 'keep *_%s_*_%s' % (collectionToKeep, process.name_()) for collectionToKeep in collectionsToKeep ])
1621 
1622 runMEtUncertainties=RunMEtUncertainties()
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def _addEventContent
Definition: trigTools.py:29