def _addCorrPFMEt(self, process, metUncertaintySequence, shiftedParticleCollections, pfCandCollection, doApplyUnclEnergyCalibration, collectionsToKeep, doSmearJets, makeType1corrPFMEt, makeType1p2corrPFMEt, doApplyType0corr, sysShiftCorrParameter, doApplySysShiftCorr, jetCorrLabel, varyByNsigmas, postfix): # loading default files if not hasattr(process, 'producePatPFMETCorrectionsUnc'): process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff") # #protections against inconsistent met correction scheme : # if makeType1p2corrPFMEt and not makeType1corrPFMEt : print "WARNING: Type2 correction called without Type1 => Type1 enabled automatically for consistency" makeType1corrPFMEt = True if doApplyType0corr and not makeType1corrPFMEt : print "WARNING: Type0 correction called without Type1 => Type0 disabled automatically for consistency" doApplyType0corr = False # # Assign MET names, and create the modules and the sequence used # metModName, metModNameT1, metModNameT1T2, collectionsToKeep = \ createPatMETModules(process, "PF", getattr(process, "producePatPFMETCorrectionsUnc"), makeType1corrPFMEt, makeType1p2corrPFMEt, doApplyType0corr, doApplySysShiftCorr, doApplyUnclEnergyCalibration, sysShiftCorrParameter, "") # If with empty postfix, make a backup of # the met sequence used, because the original # sequence will be modified later in this function if postfix == "": configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrectionsUnc , "OriginalReserved") else: if postfix == "OriginalReserved": raise ValueError("Postfix label '%s' is reserved for internal usage !!" % postfix) if hasattr(process, "producePatPFMETCorrectionsUncOriginalReserved"): configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrectionsUnc, postfix, removePostfix="OriginalReserved") else: configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrectionsUnc, postfix) metUncertaintySequence += getattr(process, "producePatPFMETCorrectionsUnc" + postfix) # # prepare smeared jets variations if needed # if doSmearJets: self._prepareJetVariationsForMET(process, "type1p2","Res",shiftedParticleCollections,metUncertaintySequence, postfix) if makeType1p2corrPFMEt: self._prepareJetVariationsForMET(process, "type2","Res",shiftedParticleCollections,metUncertaintySequence, postfix) # # prepare energy variations # self._prepareJetVariationsForMET(process, "type1p2","En",shiftedParticleCollections,metUncertaintySequence, postfix) if makeType1p2corrPFMEt: self._prepareJetVariationsForMET(process, "type2","En",shiftedParticleCollections,metUncertaintySequence, postfix) # # apply MET smearing to "raw" (uncorrected) MET # if doSmearJets: smearedPatPFMetSequence = cms.Sequence() setattr(process, "smearedPatPFMetSequence" + postfix, smearedPatPFMetSequence) if not hasattr(process, "patPFMetORIGINAL"): setattr(process, "patPFMetORIGINAL" + postfix, getattr(process, "patPFMet").clone()) setattr(process, "patPFMetForMEtUncertainty" + postfix, getattr(process, "patPFMetORIGINAL" + postfix).clone()) smearedPatPFMetSequence += getattr(process, "patPFMetForMEtUncertainty" + postfix) setattr(process, "patPFMETcorrJetSmearing" + postfix, cms.EDProducer("ShiftedParticleMETcorrInputProducer", srcOriginal = cms.InputTag(shiftedParticleCollections['cleanedJetCollection']), srcShifted = cms.InputTag(shiftedParticleCollections['lastJetCollection']) )) smearedPatPFMetSequence += getattr(process, "patPFMETcorrJetSmearing" + postfix) getattr(process, "producePatPFMETCorrectionsUnc" + postfix).replace(getattr(process, "patPFMet" + postfix), smearedPatPFMetSequence) setattr(process, "patPFMet" + postfix, getattr(process, metModNameT1 + postfix).clone( src = cms.InputTag('patPFMetForMEtUncertainty' + postfix), srcType1Corrections = cms.VInputTag( cms.InputTag('patPFMETcorrJetSmearing' + postfix) ), applyType2Corrections = cms.bool(False), srcUnclEnergySums = cms.VInputTag() )) smearedPatPFMetSequence += getattr(process, "patPFMet" + postfix) metUncertaintySequence += smearedPatPFMetSequence #-------------------------------------------------------------------------------------------- # propagate shifts in jet energy scale #-------------------------------------------------------------------------------------------- # to "raw" (uncorrected) and Type corrected MET metTypes = {} #jet identifiers metTypes[ metModName ]='ForRawMEt' if makeType1corrPFMEt: metTypes[ metModNameT1 ]='' for met in metTypes.keys(): metCollectionsUp_Down = \ propagateMEtUncertainties( process, shiftedParticleCollections['lastJetCollection'], "Jet", "En", shiftedParticleCollections['jetCollectionEnUp' + metTypes[met] ], shiftedParticleCollections['jetCollectionEnDown' + metTypes[met] ], getattr(process, met + postfix), "PF", metUncertaintySequence, postfix) collectionsToKeep.extend(metCollectionsUp_Down) # to Type 1 + 2 corrected MET if makeType1p2corrPFMEt: self._propagateJetVariationsToT1T2Met(process, "En", metUncertaintySequence, jetCorrLabel, metModNameT1T2, doApplyType0corr, doApplySysShiftCorr, postfix) #-------------------------------------------------------------------------------------------- # propagate shifts in jet energy resolution #-------------------------------------------------------------------------------------------- if doSmearJets: # to "raw" (uncorrected) MET and to Type 1 corrected MET if asked metProducers = [ getattr(process, metModName + postfix) ] if makeType1corrPFMEt: metProducers.append( getattr(process, metModNameT1 + postfix) ) jetERShiftedMETs = propagateERShiftedJets(process, shiftedParticleCollections, metProducers, "PF", metUncertaintySequence, postfix) collectionsToKeep.extend( jetERShiftedMETs ); # to Type 1 + 2 corrected MET if makeType1p2corrPFMEt: self._propagateJetVariationsToT1T2Met(process, "Res", metUncertaintySequence,jetCorrLabel, metModNameT1T2, doApplyType0corr, doApplySysShiftCorr, postfix) #-------------------------------------------------------------------------------------------- # shift "unclustered energy" (PFJets of Pt < 10 GeV plus PFCandidates not within jets) #-------------------------------------------------------------------------------------------- #unclEnMETcorrections = {} unclEnMETcorrections = \ self._prepareShiftedUnclusteredEnergy(process, metUncertaintySequence, varyByNsigmas, postfix) #-------------------------------------------------------------------------------------------- # and propagate effect of shift to (Type 1 as well as Type 1 + 2 corrected) MET #-------------------------------------------------------------------------------------------- variations=["Up","Down"] for var in variations: # propagate shifts in jet energy/resolution to "raw" (uncorrected) MET setattr(process, "patPFMetUnclusteredEn" + var + postfix, getattr(process, metModNameT1 + postfix).clone( src = cms.InputTag('patPFMet' + postfix), srcType1Corrections = cms.VInputTag(unclEnMETcorrections[ var ]) )) metUncertaintySequence += getattr(process, "patPFMetUnclusteredEn" + var + postfix) collectionsToKeep.append('patPFMetUnclusteredEn' + var + postfix) # propagate shifts in jet energy/resolution to Type 1 corrected MET if makeType1corrPFMEt: setattr(process, metModNameT1+"UnclusteredEn" + var + postfix, getattr(process, metModNameT1 + postfix).clone( src = cms.InputTag(metModNameT1 + postfix), srcType1Corrections = cms.VInputTag(unclEnMETcorrections[ var ]), srcUnclEnergySums = cms.VInputTag(), applyType2Corrections = cms.bool(False), type2CorrParameter = cms.PSet( A = cms.double(1.0) ) )) metUncertaintySequence += getattr(process, metModNameT1+"UnclusteredEn" + var + postfix) collectionsToKeep.append(metModNameT1+'UnclusteredEn' + var + postfix) # propagate shifts in jet energy/resolution to Type 1 + 2 corrected MET if makeType1p2corrPFMEt: setattr(process, metModNameT1T2+"UnclusteredEn" + var + postfix, getattr(process, metModNameT1T2 + postfix).clone( srcUnclEnergySums = cms.VInputTag( cms.InputTag('patPFJetMETtype1p2Corr' + postfix, 'type2' ), cms.InputTag('patPFJetMETtype1p2CorrUnclusteredEn' + var + postfix, 'type2' ), cms.InputTag('patPFJetMETtype2Corr' + postfix, 'type2' ), cms.InputTag('patPFJetMETtype2CorrUnclusteredEn' + var + postfix, 'type2' ), cms.InputTag('patPFJetMETtype1p2Corr' + postfix, 'offset'), cms.InputTag('patPFJetMETtype1p2CorrUnclusteredEn' + var + postfix, 'offset'), cms.InputTag('pfCandMETcorr' + postfix), cms.InputTag('pfCandMETcorrUnclusteredEn' + var + postfix) ) )) metUncertaintySequence += getattr(process, metModNameT1T2+"UnclusteredEn" + var + postfix) collectionsToKeep.append(metModNameT1T2+'UnclusteredEn' + var + postfix) #-------------------------------------------------------------------------------------------- # propagate shifted electron/photon, muon and tau-jet energies to MET #-------------------------------------------------------------------------------------------- metProducers = [ getattr(process, "patPFMet" + postfix) ] if makeType1corrPFMEt: metProducers.append( getattr(process, metModNameT1 + postfix) ) if makeType1p2corrPFMEt: metProducers.append( getattr(process, metModNameT1T2 + postfix) ) singleParticleShiftedMETs = propagateShiftedSingleParticles(process, shiftedParticleCollections, metProducers, "PF", metUncertaintySequence, postfix) collectionsToKeep.extend( singleParticleShiftedMETs );
def _addCorrPFMEt(self, process, metUncertaintySequence, shiftedParticleCollections, pfCandCollection,jetCollectionUnskimmed, doApplyUnclEnergyCalibration, collectionsToKeep, doSmearJets, makeType1corrPFMEt, makeType1p2corrPFMEt, doApplyType0corr, sysShiftCorrParameter, doApplySysShiftCorr, jetCorrLabel, varyByNsigmas, postfix): # loading default files if not hasattr(process, 'producePatPFMETCorrectionsUnc'): process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff") # #protections against inconsistent met correction scheme : # if makeType1p2corrPFMEt and not makeType1corrPFMEt : print "WARNING: Type2 correction called without Type1 => Type1 enabled automatically for consistency" makeType1corrPFMEt = True if doApplyType0corr and not makeType1corrPFMEt : print "WARNING: Type0 correction called without Type1 => Type0 disabled automatically for consistency" doApplyType0corr = False # # Assign MET names, and create the modules and the sequence used # metModName, metModNameT1, metModNameT1T2, collectionsToKeep = \ createPatMETModules(process, "PF", getattr(process, "producePatPFMETCorrectionsUnc"), makeType1corrPFMEt, makeType1p2corrPFMEt, doApplyType0corr, doApplySysShiftCorr, doApplyUnclEnergyCalibration, sysShiftCorrParameter, "") # If with empty postfix, make a backup of # the met sequence used, because the original # sequence will be modified later in this function if postfix == "": configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrectionsUnc , "OriginalReserved") else: if postfix == "OriginalReserved": raise ValueError("Postfix label '%s' is reserved for internal usage !!" % postfix) if hasattr(process, "producePatPFMETCorrectionsUncOriginalReserved"): configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrectionsUnc, postfix, removePostfix="OriginalReserved") else: configtools.cloneProcessingSnippet(process, process.producePatPFMETCorrectionsUnc, postfix) metUncertaintySequence += getattr(process, "producePatPFMETCorrectionsUnc" + postfix) # # prepare smeared jets variations if needed # if doSmearJets: self._prepareJetVariationsForMET(process, "type1p2","Res",shiftedParticleCollections,metUncertaintySequence, postfix) if makeType1p2corrPFMEt: self._prepareJetVariationsForMET(process, "type2","Res",shiftedParticleCollections,metUncertaintySequence, postfix) # # prepare energy variations # self._prepareJetVariationsForMET(process, "type1p2","En",shiftedParticleCollections,metUncertaintySequence, postfix) if makeType1p2corrPFMEt: self._prepareJetVariationsForMET(process, "type2","En",shiftedParticleCollections,metUncertaintySequence, postfix) # # apply MET smearing to "raw" (uncorrected) MET # if doSmearJets: smearedPatPFMetSequence = cms.Sequence() setattr(process, "smearedPatPFMetSequence" + postfix, smearedPatPFMetSequence) if not hasattr(process, "patPFMetORIGINAL"): setattr(process, "patPFMetORIGINAL" + postfix, getattr(process, "patPFMet").clone()) setattr(process, "patPFMetForMEtUncertainty" + postfix, getattr(process, "patPFMetORIGINAL" + postfix).clone()) smearedPatPFMetSequence += getattr(process, "patPFMetForMEtUncertainty" + postfix) setattr(process, "patPFMETcorrJetSmearing" + postfix, cms.EDProducer("ShiftedParticleMETcorrInputProducer", srcOriginal = cms.InputTag(shiftedParticleCollections['cleanedJetCollection']), srcShifted = cms.InputTag(shiftedParticleCollections['lastJetCollection']) )) smearedPatPFMetSequence += getattr(process, "patPFMETcorrJetSmearing" + postfix) getattr(process, "producePatPFMETCorrectionsUnc" + postfix).replace(getattr(process, "patPFMet" + postfix), smearedPatPFMetSequence) setattr(process, "patPFMet" + postfix, getattr(process, metModNameT1 + postfix).clone( src = cms.InputTag('patPFMetForMEtUncertainty' + postfix), srcType1Corrections = cms.VInputTag( cms.InputTag('patPFMETcorrJetSmearing' + postfix) ), applyType2Corrections = cms.bool(False), srcUnclEnergySums = cms.VInputTag() )) smearedPatPFMetSequence += getattr(process, "patPFMet" + postfix) metUncertaintySequence += smearedPatPFMetSequence #-------------------------------------------------------------------------------------------- # propagate shifts in jet energy scale #-------------------------------------------------------------------------------------------- # to "raw" (uncorrected) and Type corrected MET metTypes = {} #jet identifiers metTypes[ metModName ]='ForRawMEt' if makeType1corrPFMEt: metTypes[ metModNameT1 ]='' for met in metTypes.keys(): metCollectionsUp_Down = \ propagateMEtUncertainties( process, shiftedParticleCollections['lastJetCollection'], "Jet", "En", shiftedParticleCollections['jetCollectionEnUp' + metTypes[met] ], shiftedParticleCollections['jetCollectionEnDown' + metTypes[met] ], getattr(process, met + postfix), "PF", metUncertaintySequence, postfix) collectionsToKeep.extend(metCollectionsUp_Down) # to Type 1 + 2 corrected MET if makeType1p2corrPFMEt: self._propagateJetVariationsToT1T2Met(process, "En", metUncertaintySequence, jetCorrLabel, metModNameT1T2, doApplyType0corr, doApplySysShiftCorr, postfix) #-------------------------------------------------------------------------------------------- # propagate shifts in jet energy resolution #-------------------------------------------------------------------------------------------- if doSmearJets: # to "raw" (uncorrected) MET and to Type 1 corrected MET if asked metProducers = [ getattr(process, metModName + postfix) ] if makeType1corrPFMEt: metProducers.append( getattr(process, metModNameT1 + postfix) ) jetERShiftedMETs = propagateERShiftedJets(process, shiftedParticleCollections, metProducers, "PF", metUncertaintySequence, postfix) collectionsToKeep.extend( jetERShiftedMETs ); # to Type 1 + 2 corrected MET if makeType1p2corrPFMEt: self._propagateJetVariationsToT1T2Met(process, "Res", metUncertaintySequence,jetCorrLabel, metModNameT1T2, doApplyType0corr, doApplySysShiftCorr, postfix) #-------------------------------------------------------------------------------------------- # shift "unclustered energy" (PFJets of Pt < 10 GeV plus PFCandidates not within jets) #-------------------------------------------------------------------------------------------- #unclEnMETcorrections = {} unclEnMETcorrections = \ self._prepareShiftedUnclusteredEnergy(process, metUncertaintySequence, varyByNsigmas, postfix) #-------------------------------------------------------------------------------------------- # and propagate effect of shift to (Type 1 as well as Type 1 + 2 corrected) MET #-------------------------------------------------------------------------------------------- variations=["Up","Down"] for var in variations: # propagate shifts in jet energy/resolution to "raw" (uncorrected) MET setattr(process, "patPFMetUnclusteredEn" + var + postfix, getattr(process, metModNameT1 + postfix).clone( src = cms.InputTag('patPFMet' + postfix), srcType1Corrections = cms.VInputTag(unclEnMETcorrections[ var ]) )) metUncertaintySequence += getattr(process, "patPFMetUnclusteredEn" + var + postfix) collectionsToKeep.append('patPFMetUnclusteredEn' + var + postfix) # propagate shifts in jet energy/resolution to Type 1 corrected MET if makeType1corrPFMEt: setattr(process, metModNameT1+"UnclusteredEn" + var + postfix, getattr(process, metModNameT1 + postfix).clone( src = cms.InputTag(metModNameT1 + postfix), srcType1Corrections = cms.VInputTag(unclEnMETcorrections[ var ]), srcUnclEnergySums = cms.VInputTag(), applyType2Corrections = cms.bool(False), type2CorrParameter = cms.PSet( A = cms.double(1.0) ) )) metUncertaintySequence += getattr(process, metModNameT1+"UnclusteredEn" + var + postfix) collectionsToKeep.append(metModNameT1+'UnclusteredEn' + var + postfix) # propagate shifts in jet energy/resolution to Type 1 + 2 corrected MET if makeType1p2corrPFMEt: setattr(process, metModNameT1T2+"UnclusteredEn" + var + postfix, getattr(process, metModNameT1T2 + postfix).clone( srcUnclEnergySums = cms.VInputTag( cms.InputTag('patPFJetMETtype1p2Corr' + postfix, 'type2' ), cms.InputTag('patPFJetMETtype1p2CorrUnclusteredEn' + var + postfix, 'type2' ), cms.InputTag('patPFJetMETtype2Corr' + postfix, 'type2' ), cms.InputTag('patPFJetMETtype2CorrUnclusteredEn' + var + postfix, 'type2' ), cms.InputTag('patPFJetMETtype1p2Corr' + postfix, 'offset'), cms.InputTag('patPFJetMETtype1p2CorrUnclusteredEn' + var + postfix, 'offset'), cms.InputTag('pfCandMETcorr' + postfix), cms.InputTag('pfCandMETcorrUnclusteredEn' + var + postfix) ) )) metUncertaintySequence += getattr(process, metModNameT1T2+"UnclusteredEn" + var + postfix) collectionsToKeep.append(metModNameT1T2+'UnclusteredEn' + var + postfix) #-------------------------------------------------------------------------------------------- # propagate shifted electron/photon, muon and tau-jet energies to MET #-------------------------------------------------------------------------------------------- metProducers = [ getattr(process, "patPFMet" + postfix) ] if makeType1corrPFMEt: metProducers.append( getattr(process, metModNameT1 + postfix) ) if makeType1p2corrPFMEt: metProducers.append( getattr(process, metModNameT1T2 + postfix) ) singleParticleShiftedMETs = propagateShiftedSingleParticles(process, shiftedParticleCollections, metProducers, "PF", metUncertaintySequence, postfix) collectionsToKeep.extend( singleParticleShiftedMETs ); #fix the default jets for the type1 computation to those used to compute the uncertainties #in order to be consistent with what is done in the correction and uncertainty step #particularly true for miniAODs if isValidInputTag(jetCollectionUnskimmed): getattr(process,"patPFJetMETtype1p2Corr").src = jetCollectionUnskimmed getattr(process,"patPFJetMETtype2Corr").src = jetCollectionUnskimmed
def _addCorrCaloMEt(self, process, metUncertaintySequence, shiftedParticleCollections, caloTowerCollection, collectionsToKeep, jetCorrLabelUpToL3, jetCorrLabelUpToL3Res, jecUncertaintyFile, jecUncertaintyTag, varyByNsigmas, type1JetPtThreshold, postfix): # loading default files if not hasattr(process, 'producePatCaloMETCorrectionsUnc'): process.load("PhysicsTools.PatUtils.patCaloMETCorrections_cff") #and setting the default pt threshold for type1 correction process.corrCaloMetType1.type1JetPtThreshold = cms.double(type1JetPtThreshold) # # Assign MET names, and create the modules and the sequence used=> calo met can be only type1 or raw # metModName, metModNameT1, metModNameT1T2, collectionsToKeep = \ createPatMETModules(process, "Calo", getattr(process, "producePatCaloMETCorrectionsUnc" + postfix), True, True, False, False, False, None, postfix) # If with empty postfix, make a backup of # process.producePatPFMETCorrections, because the original # sequence will be modified later in this function if postfix == "": configtools.cloneProcessingSnippet(process, process.producePatCaloMETCorrectionsUnc, "OriginalReserved") else: if postfix == "OriginalReserved": raise ValueError("Postfix label '%s' is reserved for internal usage !!" % postfix) if hasattr(process, "OriginalReserved"): configtools.cloneProcessingSnippet(process, process.producePatCaloMETCorrectionsUncOriginalReserved, postfix, removePostfix="OriginalReserved") else: configtools.cloneProcessingSnippet(process, process.producePatCaloMETCorrectionsUnc, postfix) metUncertaintySequence += getattr(process, "producePatCaloMETCorrectionsUnc" + postfix) # # propagate jet variations # metCollectionsUp_Down = \ propagateMEtUncertainties( process, shiftedParticleCollections['lastJetCollection'], "Jet", "En", shiftedParticleCollections['jetCollectionEnUp'], shiftedParticleCollections['jetCollectionEnDown'], getattr(process, metModNameT1), "Calo", metUncertaintySequence, postfix) # self._addPATMEtProducer(process, metUncertaintySequence, # metCollectionsUp_Down[0], 'patCaloMetT1JetEnUp', collectionsToKeep, postfix) # self._addPATMEtProducer(process, metUncertaintySequence, # metCollectionsUp_Down[1], 'patCaloMetT1JetEnDown', collectionsToKeep, postfix) # # propagate unclustered energy variation # self._propagateUncEnVariations(process, metModNameT1, caloTowerCollection.value(), metUncertaintySequence, varyByNsigmas, collectionsToKeep, postfix)