CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
propagateMEtUncertainties Namespace Reference

Functions

def applyUnclEnergyCalibrationOnPfT1T2Met
 
def createPatMETModules
 
def propagateERShiftedJets
 
def propagateMEtUncertainties
 
def propagateShiftedSingleParticles
 

Function Documentation

def propagateMEtUncertainties.applyUnclEnergyCalibrationOnPfT1T2Met (   process,
  postfix 
)

Definition at line 232 of file propagateMEtUncertainties.py.

References python.rootplot.root2matplotlib.replace().

Referenced by createPatMETModules().

233 def applyUnclEnergyCalibrationOnPfT1T2Met(process, postfix):
234 
235  patPFJetMETtype1p2Corr = getattr(process, "patPFJetMETtype1p2Corr" + postfix)
236  patPFJetMETtype1p2Corr.type2ResidualCorrLabel = cms.string("")
237  patPFJetMETtype1p2Corr.type2ResidualCorrEtaMax = cms.double(9.9)
238  patPFJetMETtype1p2Corr.type2ResidualCorrOffset = cms.double(1.)
239  patPFJetMETtype1p2Corr.type2ExtraCorrFactor = cms.double(1.)
240  patPFJetMETtype1p2Corr.isMC = cms.bool(True)
241  patPFJetMETtype1p2Corr.srcGenPileUpSummary = cms.InputTag('addPileupInfo')
242  patPFJetMETtype1p2Corr.type2ResidualCorrVsNumPileUp = cms.PSet(
243  data = cms.PSet(
244  offset = cms.FileInPath('JetMETCorrections/Type1MET/data/unclEnResidualCorr_Data_runs190456to208686_pfCands_offset.txt'),
245  slope = cms.FileInPath('JetMETCorrections/Type1MET/data/unclEnResidualCorr_Data_runs190456to208686_pfCands_slope.txt')
246  ),
247  mc = cms.PSet(
248  offset = cms.FileInPath('JetMETCorrections/Type1MET/data/unclEnResidualCorr_ZplusJets_madgraph_pfCands_offset.txt'),
249  slope = cms.FileInPath('JetMETCorrections/Type1MET/data/unclEnResidualCorr_ZplusJets_madgraph_pfCands_slope.txt')
250  )
251  )
252  patPFJetMETtype1p2Corr.verbosity = cms.int32(0)
253  pfCandMETcorr = getattr(process, "pfCandMETcorr" + postfix)
254  pfCandMETresidualCorr = pfCandMETcorr.clone(
255  residualCorrLabel = cms.string(""),
256  residualCorrEtaMax = cms.double(9.9),
257  residualCorrOffset = cms.double(1.),
258  extraCorrFactor = cms.double(1.),
259  isMC = cms.bool(True),
260  srcGenPileUpSummary = cms.InputTag('addPileupInfo'),
261  residualCorrVsNumPileUp = cms.PSet(
262  data = cms.PSet(
263  offset = cms.FileInPath('JetMETCorrections/Type1MET/data/unclEnResidualCorr_Data_runs190456to208686_pfCands_offset.txt'),
264  slope = cms.FileInPath('JetMETCorrections/Type1MET/data/unclEnResidualCorr_Data_runs190456to208686_pfCands_slope.txt')
265  ),
266  mc = cms.PSet(
267  offset = cms.FileInPath('JetMETCorrections/Type1MET/data/unclEnResidualCorr_ZplusJets_madgraph_pfCands_offset.txt'),
268  slope = cms.FileInPath('JetMETCorrections/Type1MET/data/unclEnResidualCorr_ZplusJets_madgraph_pfCands_slope.txt')
269  )
270  ),
271  verbosity = cms.int32(0)
272  )
273  setattr(process, "pfCandMETresidualCorr" + postfix, pfCandMETresidualCorr)
274  getattr(process, "producePatPFMETCorrectionsUnc" + postfix).replace(pfCandMETcorr, pfCandMETcorr + pfCandMETresidualCorr)
275 
def propagateMEtUncertainties.createPatMETModules (   process,
  metType,
  metPatSequence,
  applyT1Cor = False,
  applyT2Cor = False,
  applyT0pcCor = False,
  applyXYShiftCor = False,
  applyUncEnCalib = False,
  sysShiftCorrParameter = cms.VPSet(),
  postfix = "" 
)

Definition at line 137 of file propagateMEtUncertainties.py.

References applyUnclEnergyCalibrationOnPfT1T2Met(), and clone().

Referenced by runType1CaloMEtUncertainties.RunType1CaloMEtUncertainties._addCorrCaloMEt(), runType1PFMEtUncertainties.RunType1PFMEtUncertainties._addCorrPFMEt(), and propagateERShiftedJets().

138  applyUncEnCalib=False,sysShiftCorrParameter=cms.VPSet(), postfix=""):
139 
140  ##FIXME: postfix is set to null as the whoelsequence receive it later
141  postfix=""
142 
143  if applyUncEnCalib :
144  applyT2Cor = True
145 
146  ## standard naming convention
147  metModName = "pat"+metType+"Met"
148  metModNameT1=metModName
149  metModNameT1T2=metModName
150  if applyT0pcCor :
151  metModNameT1 += "T0pc"
152  metModNameT1T2 += "T0pc"
153  metModNameT1 += "T1"
154  metModNameT1T2 += "T1T2"
155  if applyXYShiftCor :
156  metModNameT1 += "Txy"
157  metModNameT1T2 += "Txy"
158  # disabled spec. name for the moment as it just modifies the type2 MET
159  # if applyUncEnCalib :
160  # metModNameT1 += "UEC"
161  # metModNameT1T2 += "UEC"
162 
163 
164  #plug the MET modules in to the sequence
165  setattr(process, metModName, getattr(process, metModName ) )
166  if applyT1Cor :
167  setattr(process, metModNameT1+postfix, getattr(process, metModNameT1 ).clone(
168  src = cms.InputTag(metModName + postfix)
169  ))
170  metPatSequence += getattr(process, metModNameT1+postfix)
171  if applyT2Cor :
172  setattr(process, metModNameT1T2+postfix, getattr(process, metModNameT1T2 ).clone(
173  src = cms.InputTag(metModName + postfix)
174  ) )
175  metPatSequence += getattr(process, metModNameT1T2+postfix)
176 
177  patMetCorrectionsCentralValue = []
178 
179 
180  #Type0 for pfT1 and pfT1T2 MET
181  if metType == "PF":
182  patMetCorrectionsCentralValue = [ cms.InputTag('patPFJetMETtype1p2Corr' + postfix, 'type1') ]
183  if applyT0pcCor :
184  patMetCorrectionsCentralValue.extend([ cms.InputTag('patPFMETtype0Corr' + postfix) ])
185 
186 
187  # compute XY shift correction if asked, and configure the tool accordingly
188  if applyXYShiftCor :
189  if not hasattr(process, 'pfMEtSysShiftCorrSequence'):
190  process.load("JetMETCorrections.Type1MET.pfMETsysShiftCorrections_cfi")
191  if postfix != "":
192  configtools.cloneProcessingSnippet(process, process.pfMEtSysShiftCorrSequence, postfix)
193 
194  getattr(process, "pfMEtSysShiftCorr" + postfix).parameter = sysShiftCorrParameter
195  metPatSequence += getattr(process, "pfMEtSysShiftCorrSequence" + postfix)
196 
197  patMetCorrectionsCentralValue.extend([ cms.InputTag('pfMEtSysShiftCorr' + postfix) ])
198 
199 
200  #finalize T1/T2 correction process
201  if applyT1Cor :
202  getattr(process, metModNameT1 + postfix).srcType1Corrections = cms.VInputTag(patMetCorrectionsCentralValue)
203  if applyT2Cor :
204  getattr(process, metModNameT1T2 + postfix).srcType1Corrections = cms.VInputTag(patMetCorrectionsCentralValue)
205 
206 
207  # Apply unclustered energy calibration on pfMET T1T2 if asked -> discard type2 and replace it with
208  # calibration computed with the jet residual correction
209  if metType == "PF":
210  if applyUncEnCalib:
211  applyUnclEnergyCalibrationOnPfT1T2Met(process, postfix)
212  patPFMetT1T2 = getattr(process, metModNameT1T2)
213  patPFMetT1T2.applyType2Corrections = cms.bool(True)
214  patPFMetT1T2.srcUnclEnergySums = cms.VInputTag(
215  cms.InputTag('pfCandMETresidualCorr' + postfix),
216  cms.InputTag("patPFJetMETtype1p2Corr" + postfix, "type2")
217  )
218  patPFMetT1T2.type2CorrFormula = cms.string("A")
219  patPFMetT1T2.type2CorrParameter = cms.PSet(A = cms.double(2.))
220 
221 
222  collectionsToKeep = [ 'patPFMet' + postfix ]
223  if applyT1Cor:
224  collectionsToKeep.append( metModNameT1 + postfix )
225  if applyT2Cor:
226  collectionsToKeep.append( metModNameT1T2 + postfix )
227 
228  return (metModName, metModNameT1, metModNameT1T2, collectionsToKeep)
229 
230 
231 
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def propagateMEtUncertainties.propagateERShiftedJets (   process,
  shiftedParticleCollections,
  metProducers,
  metType,
  sequence,
  postfix 
)

Definition at line 115 of file propagateMEtUncertainties.py.

References createPatMETModules().

Referenced by runType1PFMEtUncertainties.RunType1PFMEtUncertainties._addCorrPFMEt(), and propagateShiftedSingleParticles().

116  metType, sequence, postfix):
117 
118  metCollectionsUpDown = []
119 
120  for metProducer in metProducers:
121 
122  tmpMetCollections = propagateMEtUncertainties(process,
123  shiftedParticleCollections['lastJetCollection'], "Jet", "Res",
124  shiftedParticleCollections['jetCollectionResUp'],
125  shiftedParticleCollections['jetCollectionResDown'],
126  metProducer, metType, sequence, postfix)
127 
128  metCollectionsUpDown.extend( tmpMetCollections )
129 
130  return metCollectionsUpDown
131 
132 
133 
134 
def propagateMEtUncertainties.propagateMEtUncertainties (   process,
  particleCollection,
  particleType,
  shiftType,
  particleCollectionShiftUp,
  particleCollectionShiftDown,
  metProducer,
  metType,
  sequence,
  postfix 
)

Definition at line 7 of file propagateMEtUncertainties.py.

References propagateShiftedSingleParticles().

7 
8  metType, sequence, postfix):
9 
10  # produce MET correction objects
11  # (sum of differences in four-momentum between original and up/down shifted particle collection)
12 
13  moduleMETcorrShiftUp = cms.EDProducer("ShiftedParticleMETcorrInputProducer",
14  srcOriginal = cms.InputTag(particleCollection),
15  srcShifted = cms.InputTag(particleCollectionShiftUp)
16  )
17  moduleMETcorrShiftUpName = "pat%sMETcorr%s%sUp" % (metType,particleType, shiftType)
18  moduleMETcorrShiftUpName += postfix
19  setattr(process, moduleMETcorrShiftUpName, moduleMETcorrShiftUp)
20  sequence += moduleMETcorrShiftUp
21  moduleMETcorrShiftDown = moduleMETcorrShiftUp.clone(
22  srcShifted = cms.InputTag(particleCollectionShiftDown)
23  )
24  moduleMETcorrShiftDownName = "pat%sMETcorr%s%sDown" % (metType,particleType, shiftType)
25  moduleMETcorrShiftDownName += postfix
26  setattr(process, moduleMETcorrShiftDownName, moduleMETcorrShiftDown)
27  sequence += moduleMETcorrShiftDown
28 
29  # propagate effects of up/down shifts to MET
30  moduleMETshiftUp = cms.EDProducer("CorrectedPATMETProducer",
31  applyType1Corrections = cms.bool(True),
32  applyType2Corrections = cms.bool(False),
33  src = cms.InputTag(metProducer.label()),
34  srcType1Corrections = cms.VInputTag(cms.InputTag(moduleMETcorrShiftUpName))
35  )
36  metProducerLabel = metProducer.label()
37  if postfix != "":
38  if metProducerLabel[-len(postfix):] == postfix:
39  metProducerLabel = metProducerLabel[0:-len(postfix)]
40  else:
41  raise StandardError("Tried to remove postfix %s from label %s, but it wasn't there" % (postfix, metProducerLabel))
42  moduleMETshiftUpName = "%s%s%sUp" % (metProducerLabel, particleType, shiftType)
43  moduleMETshiftUpName += postfix
44  setattr(process, moduleMETshiftUpName, moduleMETshiftUp)
45  sequence += moduleMETshiftUp
46  moduleMETshiftDown = moduleMETshiftUp.clone(
47  srcType1Corrections = cms.VInputTag(
48  cms.InputTag(moduleMETcorrShiftDownName)
49  )
50  )
51  moduleMETshiftDownName = "%s%s%sDown" % (metProducerLabel, particleType, shiftType)
52  moduleMETshiftDownName += postfix
53  setattr(process, moduleMETshiftDownName, moduleMETshiftDown)
54  sequence += moduleMETshiftDown
55 
56  metCollectionsUp_Down = [
57  moduleMETshiftUpName,
58  moduleMETshiftDownName
59  ]
60 
61  return metCollectionsUp_Down
62 
63 
64 
def propagateMEtUncertainties.propagateShiftedSingleParticles (   process,
  shiftedParticleCollections,
  metProducers,
  metType,
  sequence,
  postfix 
)

Definition at line 66 of file propagateMEtUncertainties.py.

References propagateERShiftedJets().

Referenced by runType1PFMEtUncertainties.RunType1PFMEtUncertainties._addCorrPFMEt(), and propagateMEtUncertainties().

66 
67  metType, sequence, postfix):
68 
69  metCollectionsUpDown = []
70 
71  #looping over existing single particles collections, rejecting jets and Up or Down variations
72 
73  for shiftedCol in shiftedParticleCollections.keys():
74  if shiftedCol.find('jet')!=-1 or shiftedCol.find('Jet')!=-1 or shiftedCol.find('Up')!=-1 or shiftedCol.find('Down')!=-1 :
75  continue
76 
77  particleType=""
78  if shiftedCol.find('electron')!=-1:
79  particleType="Electron"
80  if shiftedCol.find('photon')!=-1:
81  particleType="Photon"
82  if shiftedCol.find('muon')!=-1:
83  particleType="Muon"
84  if shiftedCol.find('tau')!=-1:
85  particleType="Tau"
86 
87  for metProducer in metProducers:
88  tmpMetCollections = propagateMEtUncertainties(process,
89  shiftedParticleCollections[shiftedCol],
90  particleType, "En",
91  shiftedParticleCollections[shiftedCol+'EnUp'],
92  shiftedParticleCollections[shiftedCol+'EnDown'],
93  metProducer, metType, sequence, postfix)
94 
95  metCollectionsUpDown.extend( tmpMetCollections )
96 
97  return metCollectionsUpDown
98 
99 
100 
101 
102 #def propagateESShiftedJets(process, shiftedParticleCollections, metProducers,
103 # metType, sequence, postfix):
104 #
105 # metCollectionsUp_DownForRawMEt = \
106 # propagateMEtUncertainties(
107 # process, shiftedParticleCollections['lastJetCollection'], "Jet", "En",
108 # shiftedParticleCollections['jetCollectionEnUpForRawMEt'], shiftedParticleCollections['jetCollectionEnDownForRawMEt'],
109 # getattr(process, "patPFMet" + postfix), "PF", metUncertaintySequence, postfix)
110 # collectionsToKeep.extend(metCollectionsUp_DownForRawMEt)
111 
112 
113