CMS 3D CMS Logo

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

Functions

def addModuleToSequence
 
def addShiftedJetCollections
 Now, jet variation for corrected METs, the default collection to use. More...
 
def addShiftedSingleParticleCollection
 Up variation. More...
 
def addSmearedJets
 
def createShiftedSingleParticleUpModule
 
def isValidInputTag
 

Function Documentation

def objectsUncertaintyTools.addModuleToSequence (   process,
  module,
  moduleName_parts,
  sequence,
  postfix 
)

Definition at line 13 of file objectsUncertaintyTools.py.

References addShiftedSingleParticleCollection().

Referenced by jmeUncertaintyTools.JetMEtUncertaintyTools._addCleanedJets(), addShiftedJetCollections(), addShiftedSingleParticleCollection(), addSmearedJets(), and createShiftedSingleParticleUpModule().

13 
14 def addModuleToSequence(process, module, moduleName_parts, sequence, postfix):
15 
16  if not len(moduleName_parts) > 0:
17  raise ValueError("Empty list !!")
18 
19  moduleName = ""
20 
21  lastPart = None
22  for part in moduleName_parts:
23  if part is None or part == "":
24  continue
25 
26  part = part.replace("selected", "")
27  part = part.replace("clean", "")
28 
29  if lastPart is None:
30  moduleName += part[0].lower() + part[1:]
31  lastPart = part
32  else:
33  if lastPart[-1].islower() or lastPart[-1].isdigit():
34  moduleName += part[0].capitalize() + part[1:]
35  else:
36  moduleName += part[0].lower() + part[1:]
37  lastPart = part
38 
39  moduleName += postfix
40  setattr(process, moduleName, module)
41 
42  sequence += module
43 
44  return moduleName
45 
46 
def objectsUncertaintyTools.addShiftedJetCollections (   process,
  jetCollection,
  lastJetCollection,
  jetCorrLabelUpToL3,
  jetCorrLabelUpToL3Res,
  jecUncertaintyFile,
  jecUncertaintyTag,
  varyByNsigmas,
  sequence,
  postfix = "" 
)

Now, jet variation for corrected METs, the default collection to use.

Definition at line 166 of file objectsUncertaintyTools.py.

References addModuleToSequence(), and addSmearedJets().

Referenced by jmeUncertaintyTools.JetMEtUncertaintyTools._addShiftedParticleCollections(), and createShiftedSingleParticleUpModule().

167  postfix = ""):
168 
169  shiftedParticleCollections = {}
170  collectionsToKeep = []
171 
172  shiftedParticleCollections['jetCollection'] = jetCollection
173  shiftedParticleCollections['lastJetCollection'] = lastJetCollection
174 
175  #
176  # Creating two sets for shifted jets corrections, depending of the use needed :
177  #
178 
179  variations=["Up","Down"]
180 
181  for var in variations:
182  # in case of "raw" (uncorrected) MET,
183  # add residual jet energy corrections in quadrature to jet energy uncertainties:
184  # cf. https://twiki.cern.ch/twiki/bin/view/CMS/MissingETUncertaintyPrescription
185  jetsEnShiftForRawMEt = cms.EDProducer("ShiftedPATJetProducer",
186  src = cms.InputTag(lastJetCollection),
187  #jetCorrPayloadName = cms.string(jetCorrPayloadName),
188  #jetCorrUncertaintyTag = cms.string('Uncertainty'),
189  jetCorrInputFileName = cms.FileInPath(jecUncertaintyFile),
190  jetCorrUncertaintyTag = cms.string(jecUncertaintyTag),
191  addResidualJES = cms.bool(True),
192  jetCorrLabelUpToL3 = cms.InputTag(jetCorrLabelUpToL3.value()),
193  jetCorrLabelUpToL3Res = cms.InputTag(jetCorrLabelUpToL3Res.value()),
194  shiftBy = cms.double(+1.*varyByNsigmas)
195  )
196 
197  jetCollectionEnShiftForRawMEt = \
198  addModuleToSequence(process, jetsEnShiftForRawMEt,
199  [ "shifted", jetCollection, "En%sForRawMEt"%var ],
200  sequence, postfix)
201  shiftedParticleCollections[ 'jetCollectionEn%sForRawMEt'%var ] = jetCollectionEnShiftForRawMEt
202  collectionsToKeep.append(jetCollectionEnShiftForRawMEt)
203 
204  ##
205  ## Now, jet variation for corrected METs, the default collection to use
206  ##
207 
208  jetsEnShift = jetsEnShiftForRawMEt.clone(
209  addResidualJES = cms.bool(False)
210  )
211 
212  ## Up Variation
213  jetCollectionEnShift =addModuleToSequence(process, jetsEnShift,
214  [ "shifted", jetCollection, "En"+ var ],
215  sequence, postfix)
216  shiftedParticleCollections['jetCollectionEn' + var ] = jetCollectionEnShift
217  collectionsToKeep.append(jetCollectionEnShift)
218 
219 
220  return (shiftedParticleCollections, collectionsToKeep)
221 
222 
def objectsUncertaintyTools.addShiftedSingleParticleCollection (   process,
  identifier,
  objectCollection,
  varyByNsigmas,
  sequence,
  postfix = "" 
)

Up variation.

Down variation

Definition at line 48 of file objectsUncertaintyTools.py.

References addModuleToSequence(), createShiftedSingleParticleUpModule(), and isValidInputTag().

Referenced by jmeUncertaintyTools.JetMEtUncertaintyTools._addShiftedParticleCollections(), and addModuleToSequence().

48 
49  varyByNsigmas,sequence, postfix = ""):
50 
51  shiftedParticleCollections = {}
52  collectionsToKeep = []
53 
54  shiftedCollectionName = identifier+"Collection"
55  shiftedParticleCollections[ shiftedCollectionName ] = objectCollection
56 
57 
58 
59  objectCollectionUp = None
60  objectCollectionDown = None
61 
62  if isValidInputTag(objectCollection):
63 
64  ##
65  ## Up variation
66  ##
67  objectCollectionUp = createShiftedSingleParticleUpModule(process,identifier,
68  objectCollection,
69  varyByNsigmas, sequence,postfix)
70  # collectionName = objectCollection.value()
71  # collectionName = collectionName.replace("selected", "")
72  # collectionName = collectionName.replace("clean", "")
73  objectModuleUp = getattr(process, objectCollectionUp)
74  shiftedParticleCollections[ shiftedCollectionName+'EnUp'] = objectCollectionUp
75  collectionsToKeep.append(objectCollectionUp)
76 
77  ##
78  ## Down variation
79  ##
80  objectModuleDown = objectModuleUp.clone(
81  shiftBy = cms.double(-1.*varyByNsigmas)
82  )
83  objectCollectionDown = addModuleToSequence(process, objectModuleDown,
84  [ "shifted", objectCollection, "EnDown" ],
85  sequence, postfix)
86  shiftedParticleCollections[ shiftedCollectionName+'EnDown'] = objectCollectionDown
87  collectionsToKeep.append(objectCollectionDown)
88 
89 
90  return (shiftedParticleCollections, collectionsToKeep)
91 
92 
def objectsUncertaintyTools.addSmearedJets (   process,
  jetCollection,
  smearedJetCollectionName_parts,
  jetSmearFileName,
  jetSmearHistogram,
  jetResolutions,
  varyByNsigmas,
  shiftBy = None,
  sequence = None,
  postfix = "" 
)

Definition at line 225 of file objectsUncertaintyTools.py.

References addModuleToSequence().

Referenced by jmeUncertaintyTools.JetMEtUncertaintyTools._addShiftedParticleCollections(), addShiftedJetCollections(), runMVAMEtUncertainties.RunMVAMEtUncertainties.toolCode(), runType1PFMEtUncertainties.RunType1PFMEtUncertainties.toolCode(), and runNoPileUpMEtUncertainties.RunNoPileUpMEtUncertainties.toolCode().

226  varyByNsigmas, shiftBy = None, sequence = None, postfix = ""):
227 
228  smearedJets = cms.EDProducer("SmearedPATJetProducer",
229  src = cms.InputTag(jetCollection),
230  dRmaxGenJetMatch = cms.string('min(0.5, 0.1 + 0.3*exp(-0.05*(genJetPt - 10.)))'),
231  sigmaMaxGenJetMatch = cms.double(3.),
232  inputFileName = cms.FileInPath(jetSmearFileName),
233  lutName = cms.string(jetSmearHistogram),
234  jetResolutions = jetResolutions.METSignificance_params,
235  # CV: skip jet smearing for pat::Jets for which the jet-energy correction (JEC) factors are either very large or negative
236  # since both cases produce unphysically large tails in the Type 1 corrected MET distribution after the smearing,
237  #
238  # e.g. raw jet: energy = 50 GeV, eta = 2.86, pt = 1 GeV
239  # corr. jet: energy = -3 GeV , pt = -0.1 GeV (JEC factor L1fastjet*L2*L3 = -17)
240  # energy = 10 GeV for corrected jet after smearing
241  # --> smeared raw jet energy = -170 GeV !!
242  #
243  # --> (corr. - raw) jet contribution to MET = -1 (-10) GeV before (after) smearing,
244  # even though jet energy got smeared by merely 1 GeV
245  #
246  skipJetSelection = cms.string(
247  'jecSetsAvailable & abs(energy - correctedP4("Uncorrected").energy) > (5.*min(energy, correctedP4("Uncorrected").energy))'
248  ),
249  skipRawJetPtThreshold = cms.double(10.), # GeV
250  skipCorrJetPtThreshold = cms.double(1.e-2),
251  verbosity = cms.int32(0)
252  )
253  if shiftBy is not None:
254  setattr(smearedJets, "shiftBy", cms.double(shiftBy*varyByNsigmas))
255  smearedJetCollection = addModuleToSequence(process, smearedJets,
256  smearedJetCollectionName_parts,
257  sequence, postfix)
258 
259  return smearedJetCollection
260 
def objectsUncertaintyTools.createShiftedSingleParticleUpModule (   process,
  identifier,
  objectCollection,
  varyByNsigmas,
  sequence,
  postfix = "" 
)

Definition at line 94 of file objectsUncertaintyTools.py.

References addModuleToSequence(), and addShiftedJetCollections().

Referenced by addShiftedSingleParticleCollection().

94 
95  varyByNsigmas,sequence,postfix=""):
96 
97  shiftedCollectionUp = None
98 
99  if identifier == "electron":
100  shiftedModuleUp = cms.EDProducer("ShiftedPATElectronProducer",
101  src = cms.InputTag(objectCollection),
102  binning = cms.VPSet(
103  cms.PSet(
104  binSelection = cms.string('isEB'),
105  binUncertainty = cms.double(0.006)
106  ),
107  cms.PSet(
108  binSelection = cms.string('!isEB'),
109  binUncertainty = cms.double(0.015)
110  ),
111  ),
112  shiftBy = cms.double(+1.*varyByNsigmas)
113  )
114 
115  if identifier == "photon":
116  shiftedModuleUp = cms.EDProducer("ShiftedPATPhotonProducer",
117  src = cms.InputTag(objectCollection),
118  binning = cms.VPSet(
119  cms.PSet(
120  binSelection = cms.string('isEB'),
121  binUncertainty = cms.double(0.01)
122  ),
123  cms.PSet(
124  binSelection = cms.string('!isEB'),
125  binUncertainty = cms.double(0.025)
126  ),
127  ),
128  shiftBy = cms.double(+1.*varyByNsigmas)
129  )
130 
131  if identifier == "muon":
132  shiftedModuleUp = cms.EDProducer("ShiftedPATMuonProducer",
133  src = cms.InputTag(objectCollection),
134  binning = cms.VPSet(
135  cms.PSet(
136  binSelection = cms.string('pt < 100'),
137  binUncertainty = cms.double(0.002)
138  ),
139  cms.PSet(
140  binSelection = cms.string('pt >= 100'),
141  binUncertainty = cms.double(0.05)
142  ),
143  ),
144  shiftBy = cms.double(+1.*varyByNsigmas)
145  )
146 
147  if identifier == "tau":
148  shiftedModuleUp = cms.EDProducer("ShiftedPATTauProducer",
149  src = cms.InputTag(objectCollection),
150  uncertainty = cms.double(0.03),
151  shiftBy = cms.double(+1.*varyByNsigmas)
152  )
153 
154  shiftedCollectionUp = addModuleToSequence(process, shiftedModuleUp,
155  [ "shifted", objectCollection, "EnUp" ],
156  sequence, postfix)
157 
158  return shiftedCollectionUp
159 
160 
161 
def objectsUncertaintyTools.isValidInputTag (   input)

Definition at line 3 of file objectsUncertaintyTools.py.

Referenced by jmeUncertaintyTools.JetMEtUncertaintyTools._addCleanedJets(), runMVAMEtUncertainties.RunMVAMEtUncertainties._addPFMVAMEt(), jmeUncertaintyTools.JetMEtUncertaintyTools._addShiftedParticleCollections(), jmeUncertaintyTools.JetMEtUncertaintyTools._getLeptonsForPFMEtInput(), addShiftedSingleParticleCollection(), runMVAMEtUncertainties.RunMVAMEtUncertainties.toolCode(), runType1PFMEtUncertainties.RunType1PFMEtUncertainties.toolCode(), and runNoPileUpMEtUncertainties.RunNoPileUpMEtUncertainties.toolCode().

3 
4 def isValidInputTag(input):
5  input_str = input
6  if isinstance(input, cms.InputTag):
7  input_str = input.value()
8  if input is None or input_str == '""':
9  return False
10  else:
11  return True
12