CMS 3D CMS Logo

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

Classes

class  RunMETCorrectionsAndUncertainties
 

Functions

def __call__
 
def addIntermediateMETs
 
def ak4JetReclustering
 
def createEnergyScaleShiftedUpModule
 
def createMVAMETModule
 
def createShiftedJetResModule
 
def createShiftedMETModule
 
def createShiftedModules
 
def createShiftedObjectModuleForMVAMET
 
def createSmearedJetModule
 
def extractMET
 
def getCorrectedMET
 
def getDefaultParameters
 self.addParameter(self._defaultParameters, 'jecUncertaintyFile', 'CondFormats/JetMETObjects/data/Summer15_50nsV5_DATA_UncertaintySources_AK4PFchs.txt', More...
 
def getMETUncertainties
 
def getUnclusteredVariations
 
def getUnclusteredVariationsForMVAMET
 
def getVariations
 
def initializeInputTag
 Utilities ====================================================================. More...
 
def isValidInputTag
 
def jetCleaning
 
def jetConfiguration
 
def miniAODConfiguration
 
def produceMET
 
def recomputeRawMetFromPfcs
 
def removePostfix
 
def runMetCorAndUncForMiniAODProduction
 
def runMetCorAndUncFromMiniAOD
 
def toolCode
 
def tuneTxyParameters
 
def updateJECs
 

Variables

tuple runMETCorrectionsAndUncertainties = RunMETCorrectionsAndUncertainties()
 

Function Documentation

def runMETCorrectionsAndUncertainties.__call__ (   self,
  process,
  metType = None,
  correctionLevel = None,
  computeUncertainties = None,
  produceIntermediateCorrections = None,
  electronCollection = None,
  photonCollection = None,
  muonCollection = None,
  tauCollection = None,
  jetCollection = None,
  jetCollectionUnskimmed = None,
  pfCandCollection = None,
  autoJetCleaning = None,
  jetFlavor = None,
  jetCorr = None,
  jetCorLabelUpToL3 = None,
  jetCorLabelL3Res = None,
  jecUncertaintyFile = None,
  jecUncertaintyTag = None,
  mvaMetLeptons = None,
  addToPatDefaultSequence = None,
  manualJetConfig = None,
  recoMetFromPFCs = None,
  reclusterJets = None,
  CHS = None,
  runOnData = None,
  onMiniAOD = None,
  postfix = None 
)

Definition at line 120 of file runMETCorrectionsAndUncertainties.py.

Referenced by getDefaultParameters().

121  postfix =None):
122  electronCollection = self.initializeInputTag(electronCollection, 'electronCollection')
123  photonCollection = self.initializeInputTag(photonCollection, 'photonCollection')
124  muonCollection = self.initializeInputTag(muonCollection, 'muonCollection')
125  tauCollection = self.initializeInputTag(tauCollection, 'tauCollection')
126  jetCollection = self.initializeInputTag(jetCollection, 'jetCollection')
127  jetCollectionUnskimmed = self.initializeInputTag(jetCollectionUnskimmed, 'jetCollectionUnskimmed')
128  pfCandCollection = self.initializeInputTag(pfCandCollection, 'pfCandCollection')
129  if metType is None :
130  metType = self._defaultParameters['metType'].value
131  if correctionLevel is None :
132  correctionLevel = self._defaultParameters['correctionLevel'].value
133  if computeUncertainties is None :
134  computeUncertainties = self._defaultParameters['computeUncertainties'].value
135  if produceIntermediateCorrections is None :
136  produceIntermediateCorrections = self._defaultParameters['produceIntermediateCorrections'].value
137  if electronCollection is None :
138  electronCollection = self._defaultParameters['electronCollection'].value
139  if photonCollection is None :
140  photonCollection = self._defaultParameters['photonCollection'].value
141  if muonCollection is None :
142  muonCollection = self._defaultParameters['muonCollection'].value
143  if tauCollection is None :
144  tauCollection = self._defaultParameters['tauCollection'].value
145  if jetCollection is None :
146  jetCollection = self._defaultParameters['jetCollection'].value
147  if jetCollectionUnskimmed is None :
148  jetCollectionUnskimmed = self._defaultParameters['jetCollectionUnskimmed'].value
149  if pfCandCollection is None :
150  pfCandCollection = self._defaultParameters['pfCandCollection'].value
151  if autoJetCleaning is None :
152  autoJetCleaning = self._defaultParameters['autoJetCleaning'].value
153  if jetFlavor is None :
154  jetFlavor = self._defaultParameters['jetFlavor'].value
155  if jetCorr is None :
156  jetCorr = self._defaultParameters['jetCorrectionType'].value
157  if jetCorLabelUpToL3 is None:
158  jetCorLabelUpToL3 = self._defaultParameters['jetCorLabelUpToL3'].value
159  if jetCorLabelL3Res is None:
160  jetCorLabelL3Res = self._defaultParameters['jetCorLabelL3Res'].value
161  if jecUncertaintyFile is None:
162  jecUncertaintyFile = self._defaultParameters['jecUncertaintyFile'].value
163  if jecUncertaintyTag is None:
164  jecUncertaintyTag = self._defaultParameters['jecUncertaintyTag'].value
165 
166  if mvaMetLeptons is None:
167  mvaMetLeptons = self._defaultParameters['mvaMetLeptons'].value
168 
169  if addToPatDefaultSequence is None :
170  addToPatDefaultSequence = self._defaultParameters['addToPatDefaultSequence'].value
171  if manualJetConfig is None :
172  manualJetConfig = self._defaultParameters['manualJetConfig'].value
173  if recoMetFromPFCs is None :
174  recoMetFromPFCs = self._defaultParameters['recoMetFromPFCs'].value
175  if reclusterJets is None :
176  reclusterJets = self._defaultParameters['reclusterJets'].value
177  if CHS is None :
178  CHS = self._defaultParameters['CHS'].value
179  if runOnData is None :
180  runOnData = self._defaultParameters['runOnData'].value
181  if onMiniAOD is None :
182  onMiniAOD = self._defaultParameters['onMiniAOD'].value
183  if postfix is None :
184  postfix = self._defaultParameters['postfix'].value
185 
186  self.setParameter('metType',metType),
187  self.setParameter('correctionLevel',correctionLevel),
188  self.setParameter('computeUncertainties',computeUncertainties),
189  self.setParameter('produceIntermediateCorrections',produceIntermediateCorrections),
190  self.setParameter('electronCollection',electronCollection),
191  self.setParameter('photonCollection',photonCollection),
192  self.setParameter('muonCollection',muonCollection),
193  self.setParameter('tauCollection',tauCollection),
194  self.setParameter('jetCollection',jetCollection),
195  self.setParameter('jetCollectionUnskimmed',jetCollectionUnskimmed),
196  self.setParameter('pfCandCollection',pfCandCollection),
197 
198  self.setParameter('autoJetCleaning',autoJetCleaning),
199  self.setParameter('jetFlavor',jetFlavor),
200 
201  #optional
202  self.setParameter('jecUncertaintyFile',jecUncertaintyFile),
203  self.setParameter('jecUncertaintyTag',jecUncertaintyTag),
204 
205  self.setParameter('mvaMetLeptons',mvaMetLeptons),
206 
207  self.setParameter('addToPatDefaultSequence',addToPatDefaultSequence),
208  self.setParameter('recoMetFromPFCs',recoMetFromPFCs),
209  self.setParameter('runOnData',runOnData),
210  self.setParameter('onMiniAOD',onMiniAOD),
211  self.setParameter('postfix',postfix),
212 
213  #if mva MET, autoswitch to std jets
214  if metType == "MVA":
215  self.setParameter('CHS',False),
216 
217  #jet energy scale uncertainty needs
218  if manualJetConfig:
219  self.setParameter('CHS',CHS)
220  self.setParameter('jetCorLabelUpToL3',jetCorLabelUpToL3)
221  self.setParameter('jetCorLabelL3Res',jetCorLabelL3Res)
222  self.setParameter('reclusterJets',reclusterJets)
223  else:
224  #internal jet configuration
225  self.jetConfiguration()
226 
227  #met reprocessing and jet reclustering
228  if recoMetFromPFCs:
229  self.setParameter('reclusterJets',True)
230 
231  #jet collection overloading for automatic jet reclustering
232  if reclusterJets:
233  self.setParameter('jetCollection',cms.InputTag('selectedPatJets'))
234  self.setParameter('jetCollectionUnSkimmed',cms.InputTag('patJets'))
235 
236  self.apply(process)
237 
def runMETCorrectionsAndUncertainties.addIntermediateMETs (   self,
  process,
  metType,
  correctionLevel,
  corScheme,
  corTags,
  corNames,
  postfix 
)

Definition at line 538 of file runMETCorrectionsAndUncertainties.py.

References getMETUncertainties().

539  def addIntermediateMETs(self, process, metType, correctionLevel, corScheme, corTags, corNames, postfix):
540  interMets = {}
541 
542  # we don't want to duplicate an exisiting module if we ask for a simple 1-corr scheme
543  if len(correctionLevel) == 1:
544  return interMets
545 
546  #ugly, but it works
547  nCor=len(correctionLevel)+1
548  ids = [0]*nCor
549  for i in range(nCor**nCor):
550  tmp=i
551  exists=False
552  corName=""
553  corrections = []
554  for j in range(nCor):
555  ids[j] = tmp%nCor
556  tmp = tmp//nCor
557 
558  if j != 0 and ids[j-1] < ids[j]:
559  exists=True
560  for k in range(0,j):
561  if ids[k] == ids[j] and ids[k]!=0:
562  exists=True
563 
564  if exists or sum(ids[j] for j in range(nCor))==0:
565  continue
566 
567  for cor in range(nCor):
568  cid = ids[nCor-cor-1]
569  cKey = correctionLevel[cid-1]
570  if cid ==0:#empty correction
571  continue
572  else :
573  corName += corNames[cKey]
574  corrections.append( corTags[ cKey ] )
575 
576  if corName == corScheme:
577  continue
578 
579  corName='pat'+metType+'Met' + corName + postfix
580  interMets[corName] = cms.EDProducer("CorrectedPATMETProducer",
581  src = cms.InputTag('pat'+metType+'Met' + postfix),
582  srcCorrections = cms.VInputTag(corrections)
583  )
584 
585 
586  return interMets
587 
588 
#====================================================================================================
def runMETCorrectionsAndUncertainties.ak4JetReclustering (   self,
  process,
  pfCandCollection,
  patMetModuleSequence,
  postfix 
)

Definition at line 1215 of file runMETCorrectionsAndUncertainties.py.

References clone().

1216  def ak4JetReclustering(self,process, pfCandCollection, patMetModuleSequence, postfix):
1217 
1218  chs = self._parameters["CHS"].value
1219  jetColName="ak4PFJets"
1220  CHSname=""
1221  pfCandColl=pfCandCollection
1222  if chs:
1223  CHSname="chs"
1224  jetColName="ak4PFJetsCHS"
1225 
1226  pfCHS=None
1227  if self._parameters["onMiniAOD"].value:
1228  pfCHS = cms.EDFilter("CandPtrSelector", src = pfCandCollection, cut = cms.string("fromPV"))
1229  else:
1230  setattr( process, "tmpPFCandCollPtr", cms.EDProducer("PFCandidateFwdPtrProducer",
1231  src = pfCandCollection ) )
1232  process.load("CommonTools.ParticleFlow.pfNoPileUpJME_cff")
1233  configtools.cloneProcessingSnippet(process, getattr(process,"pfNoPileUpJMESequence"), postfix )
1234  getattr(process, "pfPileUpJME"+postfix).PFCandidates = cms.InputTag("tmpPFCandCollPtr")
1235  pfCHS = getattr(process, "pfNoPileUpJME").clone( bottomCollection = cms.InputTag("tmpPFCandCollPtr") )
1236 
1237  if not hasattr(process, "pfCHS"+postfix):
1238  setattr(process,"pfCHS"+postfix,pfCHS)
1239  pfCandColl = cms.InputTag("pfCHS"+postfix)
1240 
1241 
1242  jetColName+=postfix
1243 
1244  if not hasattr(process, jetColName):
1245  process.load("RecoJets.JetProducers.ak4PFJets_cfi")
1246 
1247  #if chs:
1248  setattr(process, jetColName, getattr(process,"ak4PFJets").clone() )
1249 
1250  getattr(process, jetColName).src = pfCandColl
1251  getattr(process, jetColName).doAreaFastjet = True
1252 
1253  patMetModuleSequence += getattr(process, jetColName)
1254 
1255  corLevels=['L1FastJet', 'L2Relative', 'L3Absolute']
1256  if self._parameters["runOnData"].value:
1257  corLevels.append("L2L3Residual")
1258 
1259  switchJetCollection(process,
1260  jetSource = cms.InputTag(jetColName),
1261  jetCorrections = ('AK4PF'+CHSname, corLevels , ''),
1262  postfix=postfix
1263  )
1264 
1265  getattr(process,"patJets"+postfix).addGenJetMatch = False
1266  getattr(process,"patJets"+postfix).addGenPartonMatch = False
1267  getattr(process,"patJets"+postfix).addPartonJetMatch = False
1268  if self._parameters['onMiniAOD'].value:
1269  del getattr(process,"patJets"+postfix).JetFlavourInfoSource
1270  del getattr(process,"patJets"+postfix).JetPartonMapSource
1271  getattr(process,"patJets"+postfix).getJetMCFlavour = False
1272 
1273  getattr(process,"patJetCorrFactors"+postfix).src=cms.InputTag(jetColName)
1274  getattr(process,"patJetCorrFactors"+postfix).primaryVertices= cms.InputTag("offlineSlimmedPrimaryVertices")
1275 
1276 
1277  return cms.InputTag("selectedPatJets"+postfix)
1278 
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.createEnergyScaleShiftedUpModule (   self,
  process,
  identifier,
  objectCollection,
  varyByNsigmas,
  jetUncInfos = None,
  postfix = "" 
)

Definition at line 646 of file runMETCorrectionsAndUncertainties.py.

Referenced by getMETUncertainties().

647  varyByNsigmas, jetUncInfos=None, postfix=""):
648 
649  shiftedModuleUp = None
650 
651  if identifier == "Electron":
652  shiftedModuleUp = cms.EDProducer("ShiftedPATElectronProducer",
653  src = objectCollection,
654  binning = cms.VPSet(
655  cms.PSet(
656  binSelection = cms.string('isEB'),
657  binUncertainty = cms.double(0.006)
658  ),
659  cms.PSet(
660  binSelection = cms.string('!isEB'),
661  binUncertainty = cms.double(0.015)
662  ),
663  ),
664  shiftBy = cms.double(+1.*varyByNsigmas)
665  )
666 
667  if identifier == "Photon":
668  shiftedModuleUp = cms.EDProducer("ShiftedPATPhotonProducer",
669  src = objectCollection,
670  binning = cms.VPSet(
671  cms.PSet(
672  binSelection = cms.string('isEB'),
673  binUncertainty = cms.double(0.01)
674  ),
675  cms.PSet(
676  binSelection = cms.string('!isEB'),
677  binUncertainty = cms.double(0.025)
678  ),
679  ),
680  shiftBy = cms.double(+1.*varyByNsigmas)
681  )
682 
683  if identifier == "Muon":
684  shiftedModuleUp = cms.EDProducer("ShiftedPATMuonProducer",
685  src = objectCollection,
686  binning = cms.VPSet(
687  cms.PSet(
688  binSelection = cms.string('pt < 100'),
689  binUncertainty = cms.double(0.002)
690  ),
691  cms.PSet(
692  binSelection = cms.string('pt >= 100'),
693  binUncertainty = cms.double(0.05)
694  ),
695  ),
696  shiftBy = cms.double(+1.*varyByNsigmas)
697  )
698 
699  if identifier == "Tau":
700  shiftedModuleUp = cms.EDProducer("ShiftedPATTauProducer",
701  src = objectCollection,
702  uncertainty = cms.double(0.03),
703  shiftBy = cms.double(+1.*varyByNsigmas)
704  )
705 
706  if identifier == "Jet":
707  moduleType="ShiftedPATJetProducer"
708  #MM: FIXME MVA
709  #if self._parameters["metType"].value == "MVA":
710  # moduleType="ShiftedPFJetProducer"
711 
712  if jetUncInfos["jecUncFile"] == "":
713 
714  shiftedModuleUp = cms.EDProducer(moduleType,
715  src = objectCollection,
716  jetCorrUncertaintyTag = cms.string(jetUncInfos["jecUncTag"] ), #jecUncertaintyTag),
717  addResidualJES = cms.bool(True),
718  jetCorrLabelUpToL3 = cms.InputTag(jetUncInfos["jCorLabelUpToL3"].value() ), #jetCorrLabelUpToL3.value()),
719  jetCorrLabelUpToL3Res = cms.InputTag(jetUncInfos["jCorLabelL3Res"].value() ), #jetCorrLabelUpToL3Res.value()),
720  jetCorrPayloadName = cms.string(jetUncInfos["jCorrPayload"] ),
721  shiftBy = cms.double(+1.*varyByNsigmas),
722  )
723  else:
724 
725 
726  shiftedModuleUp = cms.EDProducer(moduleType,
727  src = objectCollection,
728  jetCorrInputFileName = cms.FileInPath(jetUncInfos["jecUncFile"] ), #jecUncertaintyFile),
729  jetCorrUncertaintyTag = cms.string(jetUncInfos["jecUncTag"] ), #jecUncertaintyTag),
730  addResidualJES = cms.bool(True),
731  jetCorrLabelUpToL3 = cms.InputTag(jetUncInfos["jCorLabelUpToL3"].value() ), #jetCorrLabelUpToL3.value()),
732  jetCorrLabelUpToL3Res = cms.InputTag(jetUncInfos["jCorLabelL3Res"].value() ), #jetCorrLabelUpToL3Res.value()),
733  jetCorrPayloadName = cms.string(jetUncInfos["jCorrPayload"] ),
734  shiftBy = cms.double(+1.*varyByNsigmas),
735  )
736 
737 
738  return shiftedModuleUp
739 
740 
741 #====================================================================================================
742 
743 
#====================================================================================================
Definition: value.py:1
def runMETCorrectionsAndUncertainties.createMVAMETModule (   self,
  process,
  identifier = "",
  shiftedCollection = "",
  isShifted = False,
  postfix = "" 
)

Definition at line 924 of file runMETCorrectionsAndUncertainties.py.

References clone(), and isValidInputTag().

925  def createMVAMETModule(self, process, identifier="", shiftedCollection="", isShifted=False, postfix="" ):
926 
927  if not hasattr(process, "pfMVAMEt"):
928  process.load("RecoMET.METPUSubtraction.mvaPFMET_cff")
929 
930  #retrieve collections
931  electronCollection = self._parameters["electronCollection"].value
932  muonCollection = self._parameters["electronCollection"].value
933  photonCollection = self._parameters["photonCollection"].value
934  tauCollection = self._parameters["tauCollection"].value
935  pfCandCollection = self._parameters["pfCandCollection"].value
936  corJetCollection = cms.InputTag("calibratedAK4PFJetsForPFMVAMEt"+postfix)
937  uncorJetCollection = cms.InputTag("ak4PFJets")
938 
939  #shift if needed===
940  if isShifted:
941  if identifier == "Electron":
942  electronCollection = cms.InputTag(shiftedCollection)
943  if identifier == "Muon":
944  muonCollection = cms.InputTag(shiftedCollection)
945  if identifier == "Tau":
946  tauCollection = cms.InputTag(shiftedCollection)
947  if identifier == "Photon":
948  photonCollection = cms.InputTag(shiftedCollection)
949  if identifier == "Unclustered":
950  pfCandCollection = cms.InputTag(shiftedCollection)
951  if identifier == "Jet":
952  corJetCollection = cms.InputTag(shiftedCollection)
953  uncorJetCollection = cms.InputTag("uncorrected"+shiftedCollection)
954 
955 
956  #leptons
957  mvaMetLeptons = self._parameters["mvaMetLeptons"].value
958  leptons = cms.VInputTag([])
959  if "Electrons" in mvaMetLeptons and isValidInputTag(electronCollection):
960  leptons.append = electronCollection
961  if "Muons" in mvaMetLeptons and isValidInputTag(muonCollection):
962  leptons.append = muonCollection
963  if "Photons" in mvaMetLeptons and isValidInputTag(photonCollection):
964  leptons.append = photonCollection
965  if "Taus" in mvaMetLeptons and isValidInputTag(tauCollection):
966  leptons.append = tauCollection
967 
968 
969  mvaMetProducer=getattr(process, "pfMVAMEt").clone(
970  srcCorrJets = corJetCollection, #cms.InputTag("calibratedAK4PFJetsForPFMVAMEt"+postfix),
971  srcUncorrJets = uncorJetCollection,
972  srcPFCandidates = pfCandCollection,
973  srcLeptons = leptons,
974  )
975 
976  return mvaMetProducer
977 
#========================================================================================
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.createShiftedJetResModule (   self,
  process,
  smear,
  objectCollection,
  varyByNsigmas,
  varDir,
  metUncSequence,
  postfix 
)

Definition at line 835 of file runMETCorrectionsAndUncertainties.py.

836  def createShiftedJetResModule(self, process, smear, objectCollection, varyByNsigmas, varDir, metUncSequence, postfix ):
837 
838  smearedJetModule = self.createSmearedJetModule(process, objectCollection, smear, varyByNsigmas, varDir, metUncSequence, postfix)
839 
840  return smearedJetModule
841 
842 
#========================================================================================
def runMETCorrectionsAndUncertainties.createShiftedMETModule (   self,
  process,
  originCollection,
  shiftedCollection 
)

Definition at line 914 of file runMETCorrectionsAndUncertainties.py.

915  def createShiftedMETModule(self, process, originCollection, shiftedCollection):
916 
917  shiftedModule = cms.EDProducer("ShiftedParticleMETcorrInputProducer",
918  srcOriginal = originCollection,
919  srcShifted = cms.InputTag(shiftedCollection),
920  )
921 
922  return shiftedModule
923 
#========================================================================================
def runMETCorrectionsAndUncertainties.createShiftedModules (   self,
  process,
  shiftedCollModules,
  identifier,
  preId,
  objectCollection,
  metModName,
  varType,
  metUncSequence,
  postfix 
)

Definition at line 843 of file runMETCorrectionsAndUncertainties.py.

References clone().

844  def createShiftedModules(self, process, shiftedCollModules, identifier, preId, objectCollection, metModName, varType, metUncSequence, postfix):
845 
846  shiftedMetProducers = {}
847 
848  # remove the postfix to put it at the end
849  baseName = self.removePostfix(metModName, postfix)
850 
851  #adding the shifted collection producers to the sequence, create the shifted MET correction Modules and add them as well
852  for mod in shiftedCollModules.keys():
853  modName = "shiftedPat"+preId+identifier+varType+mod+postfix
854  #MM: FIXME MVA
855  #if "MVA" in metModName and identifier == "Jet": #dummy fix
856  # modName = "uncorrectedshiftedPat"+preId+identifier+varType+mod+postfix
857  setattr(process, modName, shiftedCollModules[mod])
858  metUncSequence += getattr(process, modName)
859 
860  #removing the uncorrected
861  modName = "shiftedPat"+preId+identifier+varType+mod+postfix
862 
863  #PF MET =================================================================================
864  if "PF" in metModName:
865  #create the MET shifts and add them to the sequence
866  shiftedMETCorrModule = self.createShiftedMETModule(process, objectCollection, modName)
867  modMETShiftName = "shiftedPatMETCorr"+preId+identifier+varType+mod+postfix
868  setattr(process, modMETShiftName, shiftedMETCorrModule)
869  metUncSequence += getattr(process, modMETShiftName)
870 
871  #and finally prepare the shifted MET producers
872  modName = baseName+identifier+varType+mod+postfix
873  shiftedMETModule = getattr(process, metModName).clone(
874  src = cms.InputTag( metModName ),
875  srcCorrections = cms.VInputTag( cms.InputTag(modMETShiftName) )
876  )
877  shiftedMetProducers[ modName ] = shiftedMETModule
878 
879  #MM: FIXME MVA
880  #MVA MET, duplication of the MVA MET producer ============================================
881  #if "MVA" in metModName:
882  # print "name: ",metModName, modName
883  # shiftedMETModule = self.createMVAMETModule(process, identifier, modName, True)
884  # modName = baseName+identifier+varType+mod+postfix
885  # setattr(process, modName, shiftedMETModule)
886  # shiftedMetProducers[ modName ] = shiftedMETModule
887  #
888  # #pileupjetId and =====
889  # if identifier == "Jet":
890  # #special collection replacement for the MVAMET for the jet case ======
891  # origCollection = cms.InputTag("calibratedAK4PFJetsForPFMVAMEt"+postfix) #self._parameters["jetCollection"].value
892  # newCollection = cms.InputTag("uncorrectedshiftedPat"+preId+identifier+varType+mod+postfix)
893  # moduleName = "shiftedPat"+preId+identifier+varType+mod+postfix
894  # corrShiftedModule = getattr(process,"calibratedAK4PFJetsForPFMVAMEt").clone(
895  # src=newCollection
896  # )
897 
898  # setattr(process, moduleName, corrShiftedModule)
899  # metUncSequence += getattr(process, moduleName)
900 
901  # puJetIdProducer = getattr(process, "puJetIdForPFMVAMEt").clone(
902  # jets = moduleName
903  # )
904  # puJetIdName = "puJetIdForPFMVAMEt"+preId+identifier+varType+mod+postfix
905  # setattr(process, puJetIdName, puJetIdProducer)
906  # metUncSequence += getattr(process, puJetIdName)
907  # shiftedMETModule.srcMVAPileupJetId = cms.InputTag(puJetIdName,"fullDiscriminant")
908 
909  #==========================================================================================
910 
911  return shiftedMetProducers
912 
913 
#========================================================================================
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.createShiftedObjectModuleForMVAMET (   self,
  origCollection,
  shiftedCollection,
  dr = 0.5 
)

Definition at line 1075 of file runMETCorrectionsAndUncertainties.py.

1076  def createShiftedObjectModuleForMVAMET(self, origCollection, shiftedCollection, dr=0.5):
1077  fullShiftedModule = cms.EDProducer("ShiftedPFCandidateProducerByMatchedObject",
1078  srcPFCandidates = origCollection,
1079  srcUnshiftedObjects = origCollection,
1080  dRmatch_PFCandidate = cms.double(dr),
1081  srcShiftedObjects = shiftedCollection
1082  )
1083  return fullShiftedModule
1084 
#========================================================================================
def runMETCorrectionsAndUncertainties.createSmearedJetModule (   self,
  process,
  jetCollection,
  smear,
  varyByNsigmas,
  varDir,
  metUncSequence,
  postfix 
)

Definition at line 1085 of file runMETCorrectionsAndUncertainties.py.

References clone().

1086  def createSmearedJetModule(self, process, jetCollection, smear, varyByNsigmas, varDir, metUncSequence, postfix):
1087 
1088  smearedJetModule = None
1089 
1090  modName = "pat"
1091  selJetModName= "selectedPatJetsForMetT1T2"
1092  if smear:
1093  modName += "SmearedJets"
1094  selJetModName += "SmearCorr"
1095  else:
1096  modName += "Jets"
1097 
1098 
1099  if varDir != "":
1100  modName += "Res"+varDir
1101  selJetModName += "Res"+varDir
1102 
1103  modName += postfix
1104  selJetModName += postfix
1105 
1106  if "PF" == self._parameters["metType"].value:
1107  setattr(process, modName, getattr(process, "patSmearedJets"+postfix).clone(
1108  src = jetCollection,
1109  areSrcJetsSmeared = cms.bool(smear),
1110  shiftBy = cms.double(varyByNsigmas),
1111  ) )
1112  metUncSequence += getattr(process, modName)
1113 
1114  smearedJetModule = getattr(process, "selectedPatJetsForMetT1T2SmearCorr").clone(
1115  src = cms.InputTag(modName)
1116  )
1117 
1118  #MM: FIXME MVA
1119  #if "MVA" == self._parameters["metType"].value:
1120  # from RecoMET.METProducers.METSigParams_cfi import *
1121 
1122  # genJetsCollection=cms.InputTag('ak4GenJetsNoNu')
1123  # if self._parameters["onMiniAOD"].value:
1124  # genJetsCollection=cms.InputTag("slimmedGenJets")
1125 
1126  # smearedJetModule = cms.EDProducer("SmearedPFJetProducer",
1127  # src = cms.InputTag('ak4PFJets'),
1128  # jetCorrLabel = cms.InputTag("ak4PFL1FastL2L3Corrector"),
1129  # dRmaxGenJetMatch = cms.string('min(0.5, 0.1 + 0.3*exp(-0.05*(genJetPt - 10.)))'),
1130  # sigmaMaxGenJetMatch = cms.double(3.),
1131  # inputFileName = cms.FileInPath('PhysicsTools/PatUtils/data/pfJetResolutionMCtoDataCorrLUT.root'),
1132  # lutName = cms.string('pfJetResolutionMCtoDataCorrLUT'),
1133  # jetResolutions = METSignificance_params,
1134  # skipRawJetPtThreshold = cms.double(10.), # GeV
1135  # skipCorrJetPtThreshold = cms.double(1.e-2),
1136  # srcGenJets = genJetsCollection,
1137  # shiftBy = cms.double(varyByNsigmas),
1138  # #verbosity = cms.int32(1)
1139  # )
1140 
1141  return smearedJetModule
1142 
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.extractMET (   self,
  process,
  correctionLevel,
  patMetModuleSequence,
  postfix 
)

Definition at line 1181 of file runMETCorrectionsAndUncertainties.py.

References reco.if().

1182  def extractMET(self, process, correctionLevel, patMetModuleSequence, postfix):
1183  pfMet = cms.EDProducer("RecoMETExtractor",
1184  metSource= cms.InputTag("slimmedMETs",processName=cms.InputTag.skipCurrentProcess()),
1185  correctionLevel = cms.string(correctionLevel)
1186  )
1187  if(correctionLevel=="raw"):#dummy fix
1188  setattr(process,"pfMet"+postfix ,pfMet)
1189  patMetModuleSequence += getattr(process, "pfMet"+postfix)
1190  else:
1191  setattr(process,"met"+correctionLevel+postfix ,pfMet)
1192  patMetModuleSequence += getattr(process, "met"+correctionLevel+postfix)
1193 
if(dp >Float(M_PI)) dp-
def runMETCorrectionsAndUncertainties.getCorrectedMET (   self,
  process,
  metType,
  correctionLevel,
  produceIntermediateCorrections,
  metModuleSequence,
  postfix 
)

Definition at line 383 of file runMETCorrectionsAndUncertainties.py.

References clone().

384  def getCorrectedMET(self, process, metType, correctionLevel,produceIntermediateCorrections, metModuleSequence, postfix ):
385 
386  # default outputs
387  patMetCorrectionSequence = cms.Sequence()
388  metModName = "pat"+metType+"Met"+postfix
389 
390  # loading correction file if not already here
391  #if not hasattr(process, 'patMetCorrectionSequence'):
392  # process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff")
393  #MM loaded at the production level in principle
394 
395  if metType == "MVA": #corrections are irrelevant for the MVA MET (except jet smearing?)
396  return patMetCorrectionSequence, metModName
397 
398  ## MM: FIXME, smearing procedure needs a lot of work, still 2010 recipes everywhere
399  ## ==> smearing disabled for all cases
400  # if cor == "Smear":
401  # #print "WARNING: smearing procedure still uses 2010 recipe, disabled per default for the moment"
402 
403 
404  corNames = { #not really needed but in case we have changes in the future....
405  "T0":"T0pc",
406  "T1":"T1",
407  "T2":"T2",
408  "Txy":"Txy",
409  "Smear":"Smear",
410  }
411 
412 
413  #if empty correction level, no need to try something
414  for cor in correctionLevel: #MM to be changed!!!!!!
415  if cor not in corNames.keys():
416  if cor != "":
417  print "ERROR : ",cor," is not a proper MET correction name! aborting the MET correction production"
418  return patMetCorrectionSequence, metModName
419 
420  corModNames = {
421  "T0": "patPFMetT0CorrSequence"+postfix,
422  "T1": "patPFMetT1T2CorrSequence"+postfix,
423  "T2": "patPFMetT2CorrSequence"+postfix,
424  "Txy": "patPFMetTxyCorrSequence"+postfix,
425  "Smear": "patPFMetSmearCorrSequence"+postfix,
426  "T2Smear": "patPFMetT2SmearCorrSequence"+postfix
427  }
428 
429  if postfix != "":
430  configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetT0CorrSequence"), postfix)
431  configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetT1T2CorrSequence"), postfix)
432  configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetT2CorrSequence"), postfix)
433  configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetTxyCorrSequence"), postfix)
434  configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetSmearCorrSequence"), postfix)
435  configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetT2SmearCorrSequence"), postfix)
436 
437 
438  corModules = {}
439  for mod in corModNames.keys():
440  corModules[mod] = getattr(process, corModNames[mod] )
441 
442  corTags = {
443  "T0":cms.InputTag('patPFMetT0Corr'+postfix),
444  "T1":cms.InputTag('patPFMetT1T2Corr'+postfix, 'type1'),
445  "T2":cms.InputTag('patPFMetT2Corr'+postfix, 'type2'),
446  "Txy": cms.InputTag('patPFMetTxyCorr'+postfix),
447  "Smear":cms.InputTag('patPFMetSmearCorr'+postfix, 'type1'),
448  "Smear":cms.InputTag('patPFMetT1T2SmearCorr'+postfix, 'type1'),
449  "T2Smear":cms.InputTag('patPFMetT2SmearCorr'+postfix, 'type2')
450  }
451 
452  corScheme=""
453  corrections = []
454  correctionSequence = []
455  for cor in correctionLevel:
456  corScheme += corNames[cor]
457  corrections.append(corTags[cor])
458  correctionSequence.append(corModules[cor])
459 
460  #T2 and smearing corModuleTag switch, specific case
461  if "T2" in correctionLevel and "Smear" in correctionLevel:
462  corrections.append(corTags["T2Smear"])
463  correctionSequence.append(corModules["T2Smear"])
464  # if not produceIntermediateCorrections:
465  # #print "REMOVAL"
466  # correctionSequence.remove( corModules["Smear"] )
467  # corrections.remove(corTags["Smear"])
468 
469 
470  #Txy parameter tuning
471  if "Txy" in correctionLevel:
472  self.tuneTxyParameters(process, corScheme, postfix)
473  getattr(process, "patPFMetTxyCorr"+postfix).srcPFlow = self._parameters["pfCandCollection"].value
474 
475  #Enable MET significance in the type1 MET is computed
476  #if "T1" in correctionLevel:
477  # getattr(process, "pat"+metType+"Met"+postfix).computeMETSignificance = cms.bool(True)
478 
479  #T1 parameter tuning when CHS jets are not used
480  if "T1" in correctionLevel and not self._parameters["CHS"].value:
481  setattr(process, "corrPfMetType1"+postfix, getattr(process, "corrPfMetType1" ).clone() )
482  getattr(process, "corrPfMetType1"+postfix).src = cms.InputTag("ak4PFJets"+postfix)
483  getattr(process, "corrPfMetType1"+postfix).jetCorrLabel = "ak4PFL1FastL2L3Corrector"
484  getattr(process, "corrPfMetType1"+postfix).jetCorrLabelRes = "ak4PFL1FastL2L3ResidualCorrector"
485  getattr(process, "corrPfMetType1"+postfix).offsetCorrLabel = "ak4PFL1FastjetCorrector"
486 
487  if "T1" in correctionLevel and self._parameters["CHS"].value and self._parameters["reclusterJets"].value:
488  getattr(process, "corrPfMetType1"+postfix).src = cms.InputTag("ak4PFJetsCHS"+postfix)
489 
490  #create the main MET producer
491  metModName = "pat"+metType+"Met"+corScheme+postfix
492 
493  sequenceName=""
494  corMetProducer=None
495  if metType == "PF":
496  corMetProducer = cms.EDProducer("CorrectedPATMETProducer",
497  src = cms.InputTag('pat'+metType+'Met' + postfix),
498  srcCorrections = cms.VInputTag(corrections)
499  )
500  sequenceName="patMetCorrectionSequence"
501 
502  #MM: FIXME MVA
503  #if metType == "MVA":
504  # return patMetCorrectionSequence, metModName #FIXME
505  # corMetProducer = self.createMVAMETModule(process)
506  # sequenceName="pfMVAMEtSequence"
507 
508  setattr(process,metModName, corMetProducer)
509 
510  # adding the full sequence only if it does not exist
511  if not hasattr(process, sequenceName+postfix):
512  for corModule in correctionSequence:
513  patMetCorrectionSequence += corModule
514  setattr(process, sequenceName+postfix, patMetCorrectionSequence)
515 
516  else: #if it exists, only add the missing correction modules, no need to redo everything
517  patMetCorrectionSequence = cms.Sequence()
518  setattr(process, sequenceName+postfix,patMetCorrectionSequence)
519  for mod in corModNames.keys():
520  if not hasattr(process, corModNames[mod]):
521  patMetCorrectionSequence += corModule
522 
523 
524  #plug the main patMetproducer
525  metModuleSequence += getattr(process, metModName)
526 
527  #create the intermediate MET steps
528  #and finally add the met producers in the sequence for scheduled mode
529  if produceIntermediateCorrections:
530  interMets = self.addIntermediateMETs(process, metType, correctionLevel, corScheme, corTags,corNames, postfix)
531  for met in interMets.keys():
532  setattr(process,met, interMets[met] )
533  metModuleSequence += getattr(process, met)
534 
535  return patMetCorrectionSequence, metModName
536 
537 
#====================================================================================================
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.getDefaultParameters (   self)

self.addParameter(self._defaultParameters, 'jecUncertaintyFile', 'CondFormats/JetMETObjects/data/Summer15_50nsV5_DATA_UncertaintySources_AK4PFchs.txt',

self.addParameter(self._defaultParameters, 'jecUncertaintyTag', 'SubTotalMC',

Definition at line 89 of file runMETCorrectionsAndUncertainties.py.

References __call__().

89 
90  def getDefaultParameters(self):
91  return self._defaultParameters
92 
#=========================================================================================
def getDefaultParameters
self.addParameter(self._defaultParameters, &#39;jecUncertaintyFile&#39;, &#39;CondFormats/JetMETObjects/data/Summ...
def runMETCorrectionsAndUncertainties.getMETUncertainties (   self,
  process,
  metType,
  metModName,
  electronCollection,
  photonCollection,
  muonCollection,
  tauCollection,
  jetCollection,
  jetUncInfos,
  patMetModuleSequence,
  postfix 
)

Definition at line 590 of file runMETCorrectionsAndUncertainties.py.

References createEnergyScaleShiftedUpModule(), and isValidInputTag().

Referenced by addIntermediateMETs().

591  muonCollection, tauCollection, jetCollection, jetUncInfos, patMetModuleSequence, postfix):
592 
593 
594  # uncertainty sequence
595  metUncSequence = cms.Sequence()
596 
597  #===================================================================================
598  # jet energy resolution shifts
599  #===================================================================================
600  if not isValidInputTag(jetCollection): #or jetCollection=="":
601  print "INFO : jet collection %s does not exists, no energy resolution shifting will be performed in MET uncertainty tools" % jetCollection
602  else:
603  preId=""
604  if "Smear" in metModName:
605  preId="Smeared"
606 
607  metJERUncModules = self.getVariations(process, metModName, "Jet",preId, jetCollection, "Res", metUncSequence, postfix=postfix )
608 
609  for mod in metJERUncModules.keys():
610  setattr(process, mod, metJERUncModules[mod] )
611  patMetModuleSequence += getattr(process, mod)
612 
613  #===================================================================================
614  # Unclustered energy shifts
615  #===================================================================================
616  metUnclEUncModules = self.getUnclusteredVariations(process, metModName, metUncSequence, postfix )
617  for mod in metUnclEUncModules.keys():
618  setattr(process, mod, metUnclEUncModules[mod] )
619  patMetModuleSequence += getattr(process, mod)
620 
621  #===================================================================================
622  # Other energy shifts
623  #===================================================================================
624  objectCollections = { "Jet":jetCollection,
625  "Electron":electronCollection,
626  "Photon":photonCollection,
627  "Muon":muonCollection,
628  "Tau":tauCollection,
629  }
630 
631  for obj in objectCollections.keys():
632  if not isValidInputTag(objectCollections[obj]): # or objectCollections[obj]=="":
633  print "INFO : %s collection %s does not exists, no energy scale shifting will be performed in MET uncertainty tools" %(obj, objectCollections[obj])
634  else:
635  metObjUncModules = self.getVariations(process, metModName, obj,"", objectCollections[obj], "En", metUncSequence, jetUncInfos, postfix )
636 
637  #adding the shifted MET produced to the proper patMetModuleSequence
638  for mod in metObjUncModules.keys():
639  setattr(process, mod, metObjUncModules[mod] )
640  patMetModuleSequence += getattr(process, mod)
641 
642  #return the sequence containing the shifted collections producers
643  return metUncSequence
644 
#====================================================================================================
def runMETCorrectionsAndUncertainties.getUnclusteredVariations (   self,
  process,
  metModName,
  metUncSequence,
  postfix 
)

Definition at line 978 of file runMETCorrectionsAndUncertainties.py.

References clone().

979  def getUnclusteredVariations(self, process, metModName, metUncSequence, postfix ):
980 
981  varyByNsigmas=1
982 
983  unclEnMETcorrectionsSrcs = [
984  [ 'pfCandMETcorr' + postfix, [ '' ] ],
985  [ 'patPFMetT1T2Corr' + postfix, [ 'type2', 'offset' ] ],
986  [ 'patPFMetT2Corr' + postfix, [ 'type2' ] ],
987  ]
988 
989  #MM missing protection against missing corrections needed to compute the uncertainties
990  #for srcUnclEnMETcorr in unclEnMETcorrectionsSrcs:
991  # if not hasattr(process, srcUnclEnMETcorr[0])
992  # metUncSequence
993 
994  shiftedMetProducers = {}
995 
996  variations={"Up":1.,"Down":-1.}
997  for var in variations.keys():
998 
999  modName = self.removePostfix(metModName, postfix)
1000  modName = modName+"UnclusteredEn"+var+postfix
1001 
1002  #MM: FIXME MVA
1003  ##MVA MET special case
1004  #if "MVA" in metModName:
1005  # shiftedMetProducers[ modName ] = self.getUnclusteredVariationsForMVAMET(process, var, variations[var]*varyByNsigmas, metUncSequence, postfix )
1006  # continue
1007 
1008 
1009  for srcUnclEnMETcorr in unclEnMETcorrectionsSrcs:
1010  moduleUnclEnMETcorr = cms.EDProducer("ShiftedMETcorrInputProducer",
1011  src = cms.VInputTag(
1012  [ cms.InputTag(srcUnclEnMETcorr[0], instanceLabel) for instanceLabel in srcUnclEnMETcorr[1] ]
1013  ),
1014  uncertainty = cms.double(0.10),
1015  shiftBy = cms.double(variations[var]*varyByNsigmas)
1016  )
1017 
1018  baseName = self.removePostfix(srcUnclEnMETcorr[0], postfix)
1019 
1020  moduleUnclEnMETcorrName = baseName+"UnclusteredEn"+var+postfix
1021  setattr(process, moduleUnclEnMETcorrName, moduleUnclEnMETcorr)
1022  metUncSequence += moduleUnclEnMETcorr
1023  unclEnMETcorrections = ([ cms.InputTag(moduleUnclEnMETcorrName, instanceLabel)
1024  for instanceLabel in srcUnclEnMETcorr[1] ] )
1025 
1026 
1027  #and finally prepare the shifted MET producer
1028  if "PF" in metModName:
1029  shiftedMETModule = getattr(process, metModName).clone(
1030  src = cms.InputTag( metModName ),
1031  srcCorrections = cms.VInputTag( unclEnMETcorrections )
1032  )
1033  shiftedMetProducers[ modName ] = shiftedMETModule
1034 
1035  return shiftedMetProducers
1036 
1037 
#========================================================================================
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.getUnclusteredVariationsForMVAMET (   self,
  process,
  var,
  val,
  metUncSequence,
  postfix 
)

Definition at line 1038 of file runMETCorrectionsAndUncertainties.py.

1039  def getUnclusteredVariationsForMVAMET(self, process, var, val, metUncSequence, postfix ):
1040 
1041  if not hasattr(process, "pfCandsNotInJetsForMetCorr"):
1042  process.load("JetMETCorrections.Type1MET.correctionTerms.PfMetType1Type2_cff")
1043 
1044  #MM: it's bloody stupid to make it that way....
1045  # compute the shifted particles ====
1046  unclCandModule = cms.EDProducer("ShiftedPFCandidateProducer",
1047  src = cms.InputTag('pfCandsNotInJetsForMetCorr'),
1048  shiftBy = cms.double(val),
1049  uncertainty = cms.double(0.10)
1050  )
1051  setattr(process, "pfCandsNotInJetsUnclusteredEn"+var+postfix, unclCandModule)
1052  metUncSequence += getattr(process, "pfCandsNotInJetsUnclusteredEn"+var+postfix)
1053 
1054 
1055 
1056  #replace the old unclustered particles by the shifted ones....
1057  pfCandCollection = self._parameters["pfCandCollection"].value
1058 
1059  #top projection on jets
1060  pfCandsNotInJets = cms.EDProducer("CandPtrProjector",
1061  src = pfCandCollection,
1062  veto = cms.InputTag("ak4PFJets")
1063  )
1064  setattr(process, "pfCandsNotInJetsUnclusteredEn"+var+postfix, pfCandsNotInJets)
1065  metUncSequence += getattr(process,"pfCandsNotInJetsUnclusteredEn"+var+postfix)
1066 
1067  fullShiftedModule = self.createShiftedObjectModuleForMVAMET(pfCandCollection, cms.InputTag("pfCandsNotInJetsUnclusteredEn"+var+postfix), 0.01 )
1068  setattr(process, "pfCandidatesEn"+var+postfix, fullShiftedModule)
1069  metUncSequence += getattr(process, "pfCandidatesEn"+var+postfix)
1070 
1071  # duplication of the MVA MET producer ============================================
1072  shiftedMETModule = self.createMVAMETModule(process, "Unclustered", "pfCandidatesEn"+var+postfix, True)
1073  return shiftedMETModule
1074 
#========================================================================================
def runMETCorrectionsAndUncertainties.getVariations (   self,
  process,
  metModName,
  identifier,
  preId,
  objectCollection,
  varType,
  metUncSequence,
  jetUncInfos = None,
  postfix = "" 
)

Definition at line 793 of file runMETCorrectionsAndUncertainties.py.

References clone().

Referenced by tuneTxyParameters().

794  metUncSequence, jetUncInfos=None, postfix="" ):
795 
796  # temporary hardcoded varyByNSigma value
797  varyByNsigmas=1
798 
799  # remove the postfix to put it at the end
800  baseName = self.removePostfix(metModName, postfix)
801 
802  #default shifted MET producers
803  shiftedMetProducers = {preId+identifier+varType+'Up':None, preId+identifier+varType+'Down':None}
804 
805  #create the shifted collection producers=========================================
806  shiftedCollModules = {'Up':None, 'Down':None}
807 
808  if identifier=="Jet" and varType=="Res":
809  smear=False
810  if "Smear" in metModName:
811  smear=True
812 
813  shiftedCollModules['Up'] = self.createShiftedJetResModule(process, smear, objectCollection, +1.*varyByNsigmas,
814  "Up", metUncSequence, postfix)
815  shiftedCollModules['Down'] = self.createShiftedJetResModule(process, smear, objectCollection, -1.*varyByNsigmas,
816  "Down", metUncSequence, postfix)
817 
818  else:
819  shiftedCollModules['Up'] = self.createEnergyScaleShiftedUpModule(process, identifier, objectCollection, varyByNsigmas, jetUncInfos, postfix)
820  shiftedCollModules['Down'] = shiftedCollModules['Up'].clone( shiftBy = cms.double(-1.*varyByNsigmas) )
821 
822  if identifier=="Jet" and varType=="Res":
823  smear=False
824  if "Smear" in metModName:
825  objectCollection=cms.InputTag("selectedPatJetsForMetT1T2SmearCorr"+postfix)
826 
827 
828 
829  #and the MET producers
830  shiftedMetProducers = self.createShiftedModules(process, shiftedCollModules, identifier, preId, objectCollection,
831  metModName, varType, metUncSequence, postfix)
832 
833  return shiftedMetProducers
834 
#========================================================================================
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.initializeInputTag (   self,
  input,
  default 
)

Utilities ====================================================================.

Definition at line 1144 of file runMETCorrectionsAndUncertainties.py.

1145  def initializeInputTag(self, input, default):
1146  retVal = None
1147  if input is None:
1148  retVal = self._defaultParameters[default].value
1149  elif type(input) == str:
1150  retVal = cms.InputTag(input)
1151  else:
1152  retVal = input
1153  return retVal
1154 
def initializeInputTag
Utilities ====================================================================.
def runMETCorrectionsAndUncertainties.isValidInputTag (   input)

Definition at line 8 of file runMETCorrectionsAndUncertainties.py.

Referenced by createMVAMETModule(), getMETUncertainties(), jetCleaning(), and toolCode().

8 
9 def isValidInputTag(input):
10  input_str = input
11  if isinstance(input, cms.InputTag):
12  input_str = input.value()
13  if input is None or input_str == '""':
14  return False
15  else:
16  return True
17 
def runMETCorrectionsAndUncertainties.jetCleaning (   self,
  process,
  autoJetCleaning,
  postfix 
)

Definition at line 1377 of file runMETCorrectionsAndUncertainties.py.

References clone(), and isValidInputTag().

1378  def jetCleaning(self, process, autoJetCleaning, postfix ):
1379 
1380  if autoJetCleaning != "None" or autoJetCleaning == "Manual" :
1381  return self._parameters["jetCollection"].value
1382 
1383  #retrieve collections
1384  electronCollection = self._parameters["electronCollection"].value
1385  muonCollection = self._parameters["muonCollection"].value
1386  photonCollection = self._parameters["photonCollection"].value
1387  tauCollection = self._parameters["tauCollection"].value
1388  jetCollection = self._parameters["jetCollection"].value
1389 
1390 
1391  if autoJetCleaning == "Full" : # auto clean taus, photons and jets
1392  if isValidInputTag(tauCollection):
1393  process.load("PhysicsTools.PatAlgos.cleaningLayer1.tauCleaner_cfi")
1394  cleanPatTauProducer = getattr(process, "cleanPatTaus").clone(
1395  src = tauCollection
1396 
1397  )
1398  cleanPatTauProducer.checkOverlaps.electrons.src = electronCollection
1399  cleanPatTauProducer.checkOverlaps.muons.src = muonCollection
1400  setattr(process, "cleanedPatTaus"+postfix, cleanPatTauProducer)
1401  tauCollection = cms.InputTag("cleanedPatTaus"+postfix)
1402 
1403  if isValidInputTag(photonCollection):
1404  process.load("PhysicsTools.PatAlgos.cleaningLayer1.photonCleaner_cfi")
1405  cleanPatPhotonProducer = getattr(process, "cleanPatPhotons").clone(
1406  src = photonCollection
1407  )
1408  cleanPatPhotonProducer.checkOverlaps.electrons.src = electronCollection
1409  setattr(process, "cleanedPatPhotons"+postfix, cleanPatPhotonProducer)
1410  photonCollection = cms.InputTag("cleanedPatPhotons"+postfix)
1411 
1412  #jet cleaning
1413  process.load("PhysicsTools.PatAlgos.cleaningLayer1.jetCleaner_cfi")
1414  cleanPatJetProducer = getattr(process, "cleanPatJets").clone(
1415  src = jetCollection
1416  )
1417  cleanPatJetProducer.checkOverlaps.muons.src = muonCollection
1418  cleanPatJetProducer.checkOverlaps.electrons.src = electronCollection
1419  if isValidInputTag(photonCollection) and autoJetCleaning != "LepClean":
1420  cleanPatJetProducer.checkOverlaps.photons.src = photonCollection
1421  else:
1422  del cleanPatJetProducer.checkOverlaps.photons
1423 
1424  if isValidInputTag(tauCollection) and autoJetCleaning != "LepClean":
1425  cleanPatJetProducer.checkOverlaps.taus.src = tauCollection
1426  else:
1427  del cleanPatJetProducer.checkOverlaps.taus
1428 
1429  setattr(process, "cleanedPatJets"+postfix, cleanPatJetProducer)
1430 
1431  return cms.InputTag("cleanedPatJets"+postfix)
1432 
1433 
#========================================================================================
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.jetConfiguration (   self)

Definition at line 1348 of file runMETCorrectionsAndUncertainties.py.

1349  def jetConfiguration(self):
1350 
1351  jetFlavor = self._parameters["jetFlavor"].value
1352  jetCorr = self._parameters["jetCorrectionType"].value
1353 
1354  jetCorLabelUpToL3Name="ak4PF"
1355  jetCorLabelL3ResName="ak4PF"
1356 
1357  # normal or CHS jets =============================
1358  if "chs" in jetFlavor:
1359  self.setParameter("CHS",True)
1360  jetCorLabelUpToL3Name += "CHS" #chs
1361  jetCorLabelL3ResName += "CHS"
1362  else:
1363  self.setParameter("CHS",False)
1364 
1365  # change the correction type =====================
1366  if jetCorr == "L1L2L3-L1":
1367  jetCorLabelUpToL3Name += "L1FastL2L3Corrector"
1368  jetCorLabelL3ResName += "L1FastL2L3ResidualCorrector"
1369  elif jetCorr == "L1L2L3-RC": #to be fixed
1370  jetCorLabelUpToL3Name += "L1FastL2L3Corrector"
1371  jetCorLabelL3ResName += "L1FastL2L3ResidualCorrector"
1372 
1373  self.setParameter("jetCorLabelUpToL3",cms.InputTag(jetCorLabelUpToL3Name) )
1374  self.setParameter("jetCorLabelL3Res",cms.InputTag(jetCorLabelL3ResName) )
1375 
def runMETCorrectionsAndUncertainties.miniAODConfiguration (   self,
  process,
  pfCandCollection,
  jetCollection,
  patMetModuleSequence,
  postfix 
)

Definition at line 1279 of file runMETCorrectionsAndUncertainties.py.

1280  def miniAODConfiguration(self, process, pfCandCollection, jetCollection, patMetModuleSequence, postfix ):
1281 
1282  if self._parameters["metType"].value == "PF": # not hasattr(process, "pfMet"+postfix)
1283 
1284  getattr(process, "patPFMet"+postfix).addGenMET = False
1285  if not self._parameters["runOnData"].value:
1286  getattr(process, "patPFMet"+postfix).addGenMET = True
1287  process.genMetExtractor = cms.EDProducer("GenMETExtractor",
1288  metSource= cms.InputTag("slimmedMETs",processName=cms.InputTag.skipCurrentProcess())
1289  )
1290  patMetModuleSequence += getattr(process, "genMetExtractor")
1291  getattr(process, "patPFMet"+postfix).genMETSource = cms.InputTag("genMetExtractor")
1292 
1293  if hasattr(process, "patPFMetTxyCorr"+postfix):
1294  getattr(process, "patPFMetTxyCorr"+postfix).vertexCollection = cms.InputTag("offlineSlimmedPrimaryVertices")
1295 
1296  #handling jets when no reclustering is done
1297  if not self._parameters["reclusterJets"].value:
1298  self.updateJECs(process, jetCollection, patMetModuleSequence, postfix)
1299 
1300 
1301  #MM: FIXME MVA
1302  #if hasattr(process, "pfMVAMet"):
1303  # getattr(process, "pfMVAMet").srcVertices = cms.InputTag("offlineSlimmedPrimaryVertices")
1304  # getattr(process, "pfMVAMEt").srcVertices = cms.InputTag("offlineSlimmedPrimaryVertices")
1305  # getattr(process, "puJetIdForPFMVAMEt").vertexes = cms.InputTag("offlineSlimmedPrimaryVertices")
1306  # getattr(process, "patMVAMet").addGenMET = False
1307 
1308  if not hasattr(process, "slimmedMETs"+postfix) and self._parameters["metType"].value == "PF":
1309 
1310  from PhysicsTools.PatAlgos.selectionLayer1.jetSelector_cfi import selectedPatJets
1311  setattr(process, "selectedPatJets"+postfix, selectedPatJets.clone() )
1312 
1313  getattr(process,"selectedPatJets"+postfix).src = cms.InputTag("patJets"+postfix)
1314  getattr(process,"selectedPatJets"+postfix).cut = cms.string("pt > 10")
1315 
1316  from PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi import slimmedMETs
1317  setattr(process, "slimmedMETs"+postfix, slimmedMETs.clone() )
1318  getattr(process,"slimmedMETs"+postfix).src = cms.InputTag("patPFMetT1"+postfix)
1319  getattr(process,"slimmedMETs"+postfix).rawVariation = cms.InputTag("patPFMet"+postfix)
1320  getattr(process,"slimmedMETs"+postfix).t1Uncertainties = cms.InputTag("patPFMetT1%s"+postfix)
1321  getattr(process,"slimmedMETs"+postfix).t01Variation = cms.InputTag("patPFMetT0pcT1"+postfix)
1322  getattr(process,"slimmedMETs"+postfix).t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%s"+postfix)
1323 
1324  getattr(process,"slimmedMETs"+postfix).tXYUncForRaw = cms.InputTag("patPFMetTxy"+postfix)
1325  getattr(process,"slimmedMETs"+postfix).tXYUncForT1 = cms.InputTag("patPFMetT1Txy"+postfix)
1326  getattr(process,"slimmedMETs"+postfix).tXYUncForT01 = cms.InputTag("patPFMetT0pcT1Txy"+postfix)
1327  getattr(process,"slimmedMETs"+postfix).tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxy"+postfix)
1328  getattr(process,"slimmedMETs"+postfix).tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxy"+postfix)
1329 
1330  getattr(process,"slimmedMETs"+postfix).runningOnMiniAOD = True
1331  getattr(process,"slimmedMETs"+postfix).t01Variation = cms.InputTag("slimmedMETs",processName=cms.InputTag.skipCurrentProcess())
1332 
1333  #extractor for caloMET === temporary for the beginning of the data taking
1334  self.extractMET(process,"calo",patMetModuleSequence,postfix)
1335  from PhysicsTools.PatAlgos.tools.metTools import addMETCollection
1336  addMETCollection(process,
1337  labelName = "patCaloMet",
1338  metSource = "metcalo")
1339  getattr(process,"patCaloMet").addGenMET = False
1340 
1341  #smearing and type0 variations not yet supported in reprocessing
1342  del getattr(process,"slimmedMETs"+postfix).t1SmearedVarsAndUncs
1343  del getattr(process,"slimmedMETs"+postfix).tXYUncForT01
1344  del getattr(process,"slimmedMETs"+postfix).tXYUncForT1Smear
1345  del getattr(process,"slimmedMETs"+postfix).tXYUncForT01Smear
1346  #del getattr(process,"slimmedMETs"+postfix).caloMET
1347 
def runMETCorrectionsAndUncertainties.produceMET (   self,
  process,
  metType,
  metModuleSequence,
  postfix 
)

Definition at line 355 of file runMETCorrectionsAndUncertainties.py.

References clone().

356  def produceMET(self, process, metType, metModuleSequence, postfix):
357  if metType == "PF" and not hasattr(process, 'pat'+metType+'Met'):
358  process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff")
359 
360  if postfix != "" and metType == "PF" and not hasattr(process, 'pat'+metType+'Met'+postfix):
361  configtools.cloneProcessingSnippet(process, getattr(process,"producePatPFMETCorrections"), postfix)
362  setattr(process, 'pat'+metType+'Met'+postfix, getattr(process,'patPFMet' ).clone() )
363  getattr(process, "patPFMet"+postfix).metSource = cms.InputTag("pfMet"+postfix)
364  getattr(process, "patPFMet"+postfix).srcJets = cms.InputTag("selectedPatJets"+postfix)
365  getattr(process, "patPFMet"+postfix).srcPFCands = self._parameters["pfCandCollection"].value
366 
367  if self._parameters["runOnData"].value:
368  getattr(process, "patPFMet"+postfix).addGenMET = False
369 
370 
371  #MM: FIXME MVA
372  if metType == "MVA": # and not hasattr(process, 'pat'+metType+'Met'):
373  # process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff")
374  mvaMetProducer = self.createMVAMETModule(process)
375  setattr(process, 'pfMVAMet'+postfix, mvaMetProducer )
376  setattr(process, 'pat'+metType+'Met'+postfix, getattr(process,'patPFMet' ).clone(
377  metSource = cms.InputTag('pfMVAMet'),
378 
379  ) )
380 
381  metModuleSequence += getattr(process, 'pat'+metType+'Met'+postfix )
382 
#====================================================================================================
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.recomputeRawMetFromPfcs (   self,
  process,
  pfCandCollection,
  onMiniAOD,
  patMetModuleSequence,
  postfix 
)

Definition at line 1155 of file runMETCorrectionsAndUncertainties.py.

References clone().

1156  def recomputeRawMetFromPfcs(self, process, pfCandCollection, onMiniAOD, patMetModuleSequence, postfix):
1157 
1158  #RECO MET
1159  if not hasattr(process, "pfMet"+postfix) and self._parameters["metType"].value == "PF":
1160  #common to AOD/mAOD processing
1161  #raw MET
1162  from RecoMET.METProducers.PFMET_cfi import pfMet
1163  setattr(process, "pfMet"+postfix, pfMet.clone() )
1164  getattr(process, "pfMet"+postfix).src = pfCandCollection
1165  getattr(process, "pfMet"+postfix).calculateSignificance = False
1166  patMetModuleSequence += getattr(process, "pfMet"+postfix)
1167 
1168  #PAT METs
1169  process.load("PhysicsTools.PatAlgos.producersLayer1.metProducer_cff")
1170  configtools.cloneProcessingSnippet(process, getattr(process,"patMETCorrections"), postfix)
1171 
1172  #T1 pfMet for AOD to mAOD only
1173  if not onMiniAOD:
1174  #correction duplication needed
1175  getattr(process, "pfMetT1"+postfix).src = cms.InputTag("pfMet"+postfix)
1176  patMetModuleSequence += getattr(process, "pfMetT1"+postfix)
1177 
1178  setattr(process, 'patMETs'+postfix, getattr(process,'patMETs' ).clone() )
1179  getattr(process, "patMETs"+postfix).metSource = cms.InputTag("pfMetT1"+postfix)
1180 
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def runMETCorrectionsAndUncertainties.removePostfix (   self,
  name,
  postfix 
)

Definition at line 744 of file runMETCorrectionsAndUncertainties.py.

745  def removePostfix(self, name, postfix):
746 
747  if postfix=="":
748  return name
749 
750  baseName = name
751  if baseName[-len(postfix):] == postfix:
752  baseName = baseName[0:-len(postfix)]
753  else:
754  raise Exception("Tried to remove postfix %s from %s, but it wasn't there" % (postfix, baseName))
755 
756  return baseName
757 
#====================================================================================================
def runMETCorrectionsAndUncertainties.runMetCorAndUncForMiniAODProduction (   process,
  metType = "PF",
  jetCollUnskimmed = "patJets",
  jetColl = "selectedPatJetsForMETUnc",
  photonColl = "selectedPatPhotons",
  electronColl = "selectedPatElectrons",
  muonColl = "selectedPatMuons",
  tauColl = "selectedPatTaus",
  pfCandColl = "particleFlow",
  jetCleaning = "LepClean",
  jecUnFile = "",
  recoMetFromPFCs = False,
  postfix = "" 
)

Definition at line 1452 of file runMETCorrectionsAndUncertainties.py.

References runMetCorAndUncFromMiniAOD().

Referenced by miniAOD_tools.miniAOD_customizeCommon().

1453  postfix=""):
1454 
1455  runMETCorrectionsAndUncertainties = RunMETCorrectionsAndUncertainties()
1456 
1457  #MET flavors
1458  runMETCorrectionsAndUncertainties(process, metType="PF",
1459  correctionLevel=["T0","T1","T2","Smear","Txy"],
1460  computeUncertainties=False,
1461  produceIntermediateCorrections=True,
1462  addToPatDefaultSequence=False,
1463  jetCollectionUnskimmed=jetCollUnskimmed,
1464  jetCollection=jetColl,
1465  photonCollection=photonColl,
1466  electronCollection=electronColl,
1467  muonCollection=muonColl,
1468  tauCollection=tauColl,
1469  pfCandCollection =pfCandColl,
1470  autoJetCleaning=jetCleaning,
1471  jecUncertaintyFile=jecUnFile,
1472  recoMetFromPFCs=recoMetFromPFCs,
1473  postfix=postfix
1474  )
1475 
1476  #MET T1 uncertainties
1477  runMETCorrectionsAndUncertainties(process, metType="PF",
1478  correctionLevel=["T1"],
1479  computeUncertainties=True,
1480  produceIntermediateCorrections=False,
1481  addToPatDefaultSequence=False,
1482  jetCollectionUnskimmed=jetCollUnskimmed,
1483  jetCollection=jetColl,
1484  photonCollection=photonColl,
1485  electronCollection=electronColl,
1486  muonCollection=muonColl,
1487  tauCollection=tauColl,
1488  pfCandCollection =pfCandColl,
1489  autoJetCleaning=jetCleaning,
1490  jecUncertaintyFile=jecUnFile,
1491  recoMetFromPFCs=recoMetFromPFCs,
1492  postfix=postfix
1493  )
1494 
1495  #MET T1 Smeared JER uncertainties
1496  runMETCorrectionsAndUncertainties(process, metType="PF",
1497  correctionLevel=["T1","Smear"],
1498  computeUncertainties=True,
1499  produceIntermediateCorrections=False,
1500  addToPatDefaultSequence=False,
1501  jetCollectionUnskimmed=jetCollUnskimmed,
1502  jetCollection=jetColl,
1503  photonCollection=photonColl,
1504  electronCollection=electronColl,
1505  muonCollection=muonColl,
1506  tauCollection=tauColl,
1507  pfCandCollection =pfCandColl,
1508  autoJetCleaning=jetCleaning,
1509  jecUncertaintyFile=jecUnFile,
1510  recoMetFromPFCs=recoMetFromPFCs,
1511  postfix=postfix,
1512  )
1513 
1514 
1515 
1516 
# miniAOD reproduction ===========================
def runMETCorrectionsAndUncertainties.runMetCorAndUncFromMiniAOD (   process,
  metType = "PF",
  jetCollUnskimmed = "slimmedJets",
  jetColl = "selectedPatJets",
  photonColl = "slimmedPhotons",
  electronColl = "slimmedElectrons",
  muonColl = "slimmedMuons",
  tauColl = "slimmedTaus",
  pfCandColl = "packedPFCandidates",
  jetFlav = "AK4PFchs",
  jetCleaning = "LepClean",
  isData = False,
  jetConfig = False,
  reclusterJets = False,
  recoMetFromPFCs = False,
  jetCorLabelL3 = cms.InputTag('ak4PFCHSL1FastL2L3Corrector'),
  jetCorLabelRes = cms.InputTag('ak4PFCHSL1FastL2L3ResidualCorrector'),
  jecUncFile = "",
  postfix = "" 
)

Definition at line 1535 of file runMETCorrectionsAndUncertainties.py.

Referenced by runMetCorAndUncForMiniAODProduction().

1536  postfix=""):
1537 
1538  runMETCorrectionsAndUncertainties = RunMETCorrectionsAndUncertainties()
1539 
1540  #MET T1 uncertainties
1541  runMETCorrectionsAndUncertainties(process, metType="PF",
1542  correctionLevel=["T1"],
1543  computeUncertainties=True,
1544  produceIntermediateCorrections=False,
1545  addToPatDefaultSequence=False,
1546  jetCollection=jetColl,
1547  jetCollectionUnskimmed=jetCollUnskimmed,
1548  electronCollection=electronColl,
1549  muonCollection=muonColl,
1550  tauCollection=tauColl,
1551  photonCollection=photonColl,
1552  pfCandCollection =pfCandColl,
1553  runOnData=isData,
1554  onMiniAOD=True,
1555  reclusterJets=reclusterJets,
1556  recoMetFromPFCs=recoMetFromPFCs,
1557  autoJetCleaning=jetCleaning,
1558  manualJetConfig=jetConfig,
1559  jetFlavor=jetFlav,
1560  jetCorLabelUpToL3=jetCorLabelL3,
1561  jetCorLabelL3Res=jetCorLabelRes,
1562  jecUncertaintyFile=jecUncFile,
1563  postfix=postfix,
1564  )
1565 
1566  #MET T1+Txy
1567  runMETCorrectionsAndUncertainties(process, metType="PF",
1568  correctionLevel=["T1","Txy"],
1569  computeUncertainties=False,
1570  produceIntermediateCorrections=True,
1571  addToPatDefaultSequence=False,
1572  jetCollection=jetColl,
1573  jetCollectionUnskimmed=jetCollUnskimmed,
1574  electronCollection=electronColl,
1575  muonCollection=muonColl,
1576  tauCollection=tauColl,
1577  photonCollection=photonColl,
1578  pfCandCollection =pfCandColl,
1579  runOnData=isData,
1580  onMiniAOD=True,
1581  reclusterJets=reclusterJets,
1582  recoMetFromPFCs=recoMetFromPFCs,
1583  autoJetCleaning=jetCleaning,
1584  manualJetConfig=jetConfig,
1585  jetFlavor=jetFlav,
1586  jetCorLabelUpToL3=jetCorLabelL3,
1587  jetCorLabelL3Res=jetCorLabelRes,
1588  jecUncertaintyFile=jecUncFile,
1589  postfix=postfix,
1590  )
def runMETCorrectionsAndUncertainties.toolCode (   self,
  process 
)

Definition at line 238 of file runMETCorrectionsAndUncertainties.py.

References isValidInputTag().

239  def toolCode(self, process):
240  metType = self._parameters['metType'].value
241  correctionLevel = self._parameters['correctionLevel'].value
242  computeUncertainties = self._parameters['computeUncertainties'].value
243  produceIntermediateCorrections = self._parameters['produceIntermediateCorrections'].value
244  electronCollection = self._parameters['electronCollection'].value
245  photonCollection = self._parameters['photonCollection'].value
246  muonCollection = self._parameters['muonCollection'].value
247  tauCollection = self._parameters['tauCollection'].value
248  jetCollection = self._parameters['jetCollection'].value
249  jetCollectionUnskimmed = self._parameters['jetCollectionUnskimmed'].value
250  pfCandCollection = self._parameters['pfCandCollection'].value
251  autoJetCleaning = self._parameters['autoJetCleaning'].value
252  jetFlavor = self._parameters['jetFlavor'].value
253  jetCorLabelUpToL3 = self._parameters['jetCorLabelUpToL3'].value
254  jetCorLabelL3Res = self._parameters['jetCorLabelL3Res'].value
255  jecUncertaintyFile = self._parameters['jecUncertaintyFile'].value
256  jecUncertaintyTag = self._parameters['jecUncertaintyTag'].value
257 
258  mvaMetLeptons = self._parameters['mvaMetLeptons'].value
259  addToPatDefaultSequence = self._parameters['addToPatDefaultSequence'].value
260  recoMetFromPFCs = self._parameters['recoMetFromPFCs'].value
261  reclusterJets = self._parameters['reclusterJets'].value
262  onMiniAOD = self._parameters['onMiniAOD'].value
263  postfix = self._parameters['postfix'].value
264 
265  #prepare jet configuration
266  jetUncInfos = { "jCorrPayload":jetFlavor, "jCorLabelUpToL3":jetCorLabelUpToL3,
267  "jCorLabelL3Res":jetCorLabelL3Res, "jecUncFile":jecUncertaintyFile,
268  "jecUncTag":jecUncertaintyTag }
269 
270  patMetModuleSequence = cms.Sequence()
271 
272  # recompute the MET (and thus the jets as well for correction) from scratch
273  if recoMetFromPFCs:
274  self.recomputeRawMetFromPfcs(process,
275  pfCandCollection,
276  onMiniAOD,
277  patMetModuleSequence,
278  postfix)
279  reclusterJets = True
280  elif onMiniAOD: #raw MET extraction if running on miniAODs
281  self.extractMET(process, "raw", patMetModuleSequence, postfix)
282 
283 
284  #default MET production
285  self.produceMET(process, metType,patMetModuleSequence, postfix)
286 
287 
288  #jet AK4 reclustering if needed for JECs
289  if reclusterJets:
290  jetCollection = self.ak4JetReclustering(process, pfCandCollection,
291  patMetModuleSequence, postfix)
292 
293  #preparation to run over miniAOD (met reproduction)
294  if onMiniAOD:
295  # reclusterJets = True
296  self.miniAODConfiguration(process,
297  pfCandCollection,
298  jetCollectionUnskimmed,
299  patMetModuleSequence,
300  postfix
301  )
302 
303  #jet ES configuration and jet cleaning
304  self.jetCleaning(process, autoJetCleaning, postfix)
305 
306 
307  # correct the MET
308  patMetCorrectionSequence, metModName = self.getCorrectedMET(process, metType, correctionLevel,
309  produceIntermediateCorrections,
310  patMetModuleSequence, postfix )
311 
312  #fix the default jets for the type1 computation to those used to compute the uncertainties
313  #in order to be consistent with what is done in the correction and uncertainty step
314  #particularly true for miniAODs
315  if isValidInputTag(jetCollectionUnskimmed) and "T1" in metModName:
316  getattr(process,"patPFMetT1T2Corr").src = jetCollectionUnskimmed
317  getattr(process,"patPFMetT2Corr").src = jetCollectionUnskimmed
318 
319  if postfix!="" and reclusterJets:
320  getattr(process,"patPFMetT1T2Corr"+postfix).src = cms.InputTag(jetCollectionUnskimmed.value()+postfix)
321  getattr(process,"patPFMetT2Corr"+postfix).src = cms.InputTag(jetCollectionUnskimmed.value()+postfix)
322 
323  #compute the uncertainty on the MET
324  patMetUncertaintySequence = cms.Sequence()
325  if computeUncertainties:
326  patMetUncertaintySequence = self.getMETUncertainties(process, metType, metModName,
327  electronCollection,
328  photonCollection,
329  muonCollection,
330  tauCollection,
331  jetCollection,
332  jetUncInfos,
333  patMetModuleSequence,
334  postfix)
335 
336 
337  setattr(process, "patMetCorrectionSequence"+postfix, patMetCorrectionSequence)
338  setattr(process, "patMetUncertaintySequence"+postfix, patMetUncertaintySequence)
339  setattr(process, "patMetModuleSequence"+postfix, patMetModuleSequence)
340 
341  #prepare and fill the final sequence containing all the sub-sequence
342  fullPatMetSequence = cms.Sequence()
343  fullPatMetSequence += getattr(process, "patMetCorrectionSequence"+postfix)
344  fullPatMetSequence += getattr(process, "patMetUncertaintySequence"+postfix)
345  fullPatMetSequence += getattr(process, "patMetModuleSequence"+postfix)
346 
347  setattr(process,"fullPatMetSequence"+postfix,fullPatMetSequence)
348 
349  # insert the fullPatMetSequence into patDefaultSequence if needed
350  if addToPatDefaultSequence:
351  if not hasattr(process, "patDefaultSequence"):
352  raise ValueError("PAT default sequence is not defined !!")
353  process.patDefaultSequence += getattr(process, "fullPatMetSequence"+postfix)
354 
#====================================================================================================
def runMETCorrectionsAndUncertainties.tuneTxyParameters (   self,
  process,
  corScheme,
  postfix 
)

Definition at line 758 of file runMETCorrectionsAndUncertainties.py.

References getVariations().

759  def tuneTxyParameters(self, process, corScheme, postfix):
761  xyTags = {
762  "Txy_50ns":metCors.patMultPhiCorrParams_Txy_50ns,
763  "T1Txy_50ns":metCors.patMultPhiCorrParams_T1Txy_50ns,
764  "T0pcTxy_50ns":metCors.patMultPhiCorrParams_T0pcTxy_50ns,
765  "T0pcT1Txy_50ns":metCors.patMultPhiCorrParams_T0pcT1Txy_50ns,
766  "T1T2Txy_50ns":metCors.patMultPhiCorrParams_T1T2Txy_50ns,
767  "T0pcT1T2Txy_50ns":metCors.patMultPhiCorrParams_T0pcT1T2Txy_50ns,
768  "T1SmearTxy_50ns":metCors.patMultPhiCorrParams_T1SmearTxy_50ns,
769  "T1T2SmearTxy_50ns":metCors.patMultPhiCorrParams_T1T2SmearTxy_50ns,
770  "T0pcT1SmearTxy_50ns":metCors.patMultPhiCorrParams_T0pcT1SmearTxy_50ns,
771  "T0pcT1T2SmearTxy_50ns":metCors.patMultPhiCorrParams_T0pcT1T2SmearTxy_50ns,
772 
773  "Txy_25ns":metCors.patMultPhiCorrParams_Txy_25ns,
774  "T1Txy_25ns":metCors.patMultPhiCorrParams_T1Txy_25ns,
775  "T0pcTxy_25ns":metCors.patMultPhiCorrParams_T0pcTxy_25ns,
776  "T0pcT1Txy_25ns":metCors.patMultPhiCorrParams_T0pcT1Txy_25ns,
777  "T1T2Txy_25ns":metCors.patMultPhiCorrParams_T1T2Txy_25ns,
778  "T0pcT1T2Txy_25ns":metCors.patMultPhiCorrParams_T0pcT1T2Txy_25ns,
779  "T1SmearTxy_25ns":metCors.patMultPhiCorrParams_T1SmearTxy_25ns,
780  "T1T2SmearTxy_25ns":metCors.patMultPhiCorrParams_T1T2SmearTxy_25ns,
781  "T0pcT1SmearTxy_25ns":metCors.patMultPhiCorrParams_T0pcT1SmearTxy_25ns,
782  "T0pcT1T2SmearTxy_25ns":metCors.patMultPhiCorrParams_T0pcT1T2SmearTxy_25ns
783  }
784 
785  getattr(process, "patPFMetTxyCorr"+postfix).parameters = xyTags[corScheme+"_25ns"]
786  ##for automatic switch to 50ns / 25ns corrections ==> does not work...
787  #from Configuration.StandardSequences.Eras import eras
788  #eras.run2_50ns_specific.toModify( getattr(process, "patPFMetTxyCorr"+postfix) , parameters=xyTags[corScheme+"_50ns"] )
789  #eras.run2_25ns_specific.toModify( getattr(process, "patPFMetTxyCorr"+postfix) , parameters=xyTags[corScheme+"_25ns"] )
790 
791 
#====================================================================================================
def runMETCorrectionsAndUncertainties.updateJECs (   self,
  process,
  jetCollection,
  patMetModuleSequence,
  postfix 
)

Definition at line 1194 of file runMETCorrectionsAndUncertainties.py.

1195  def updateJECs(self,process,jetCollection, patMetModuleSequence, postfix):
1196  from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import patJetCorrFactorsUpdated
1197  patJetCorrFactorsReapplyJEC = patJetCorrFactorsUpdated.clone(
1198  src = jetCollection,
1199  levels = ['L1FastJet',
1200  'L2Relative',
1201  'L3Absolute'],
1202  payload = 'AK4PFchs' ) # always CHS from miniAODs
1203 
1204  from PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cff import patJetsUpdated
1205  patJetsReapplyJEC = patJetsUpdated.clone(
1206  jetSource = cms.InputTag("slimmedJets"),
1207  jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactorsReapplyJEC"))
1208  )
1209 
1210  setattr(process,"patJetCorrFactorsReapplyJEC",patJetCorrFactorsReapplyJEC)
1211  setattr(process,"patJets",patJetsReapplyJEC.clone())
1212  patMetModuleSequence += getattr(process,"patJetCorrFactorsReapplyJEC")
1213  patMetModuleSequence += getattr(process,"patJets")
1214 

Variable Documentation

tuple runMETCorrectionsAndUncertainties.runMETCorrectionsAndUncertainties = RunMETCorrectionsAndUncertainties()

Definition at line 1434 of file runMETCorrectionsAndUncertainties.py.