コード例 #1
0
    def toolCode(self, process):
        electronCollection = self._parameters['electronCollection'].value
        photonCollection = self._parameters['photonCollection'].value
        muonCollection = self._parameters['muonCollection'].value
        tauCollection = self._parameters['tauCollection'].value
        jetCollection = self._parameters['jetCollection'].value
        jetCollectionUnskimmed = self._parameters['jetCollectionUnskimmed'].value
        jetCorrLabel = self._parameters['jetCorrLabel'].value
        dRjetCleaning =  self._parameters['dRjetCleaning'].value
        doSmearJets = self._parameters['doSmearJets'].value
        makeType1corrPFMEt = self._parameters['makeType1corrPFMEt'].value
        makeType1p2corrPFMEt = self._parameters['makeType1p2corrPFMEt'].value
        doApplyType0corr = self._parameters['doApplyType0corr'].value
        sysShiftCorrParameter = self._parameters['sysShiftCorrParameter'].value
        doApplySysShiftCorr = self._parameters['doApplySysShiftCorr'].value
        jetSmearFileName = self._parameters['jetSmearFileName'].value
        jetSmearHistogram = self._parameters['jetSmearHistogram'].value
        pfCandCollection = self._parameters['pfCandCollection'].value
        doApplyUnclEnergyCalibration = self._parameters['doApplyUnclEnergyCalibration'].value
        jetCorrPayloadName = self._parameters['jetCorrPayloadName'].value
        jetCorrLabelUpToL3 = self._parameters['jetCorrLabelUpToL3'].value
        jetCorrLabelUpToL3Res = self._parameters['jetCorrLabelUpToL3Res'].value
        jecUncertaintyFile = self._parameters['jecUncertaintyFile'].value
        jecUncertaintyTag = self._parameters['jecUncertaintyTag'].value
        varyByNsigmas = self._parameters['varyByNsigmas'].value
        addToPatDefaultSequence = self._parameters['addToPatDefaultSequence'].value
        outputModule = self._parameters['outputModule'].value
        postfix = self._parameters['postfix'].value

        if not hasattr(process, "pfType1MEtUncertaintySequence" + postfix):
            metUncertaintySequence = cms.Sequence()
            setattr(process, "pfType1MEtUncertaintySequence" + postfix, metUncertaintySequence)
        metUncertaintySequence = getattr(process, "pfType1MEtUncertaintySequence" + postfix)

        collectionsToKeep = []


        if isValidInputTag(jetCollection):
            # produce collection of jets not overlapping with reconstructed
            # electrons/photons, muons and tau-jet candidates
            lastJetCollection, cleanedJetCollection = \
                self._addCleanedJets(process, jetCollection,
                                     electronCollection, photonCollection, muonCollection, tauCollection,
                                     metUncertaintySequence, postfix)

            # smear jet energies to account for difference in jet resolutions between MC and Data
            # (cf. JME-10-014 PAS)
            if doSmearJets:
                lastJetCollection = \
                    addSmearedJets(process, cleanedJetCollection,
                                   [ "smeared", jetCollection.value() ],
                                   jetSmearFileName, jetSmearHistogram, jetResolutions,
                                   varyByNsigmas, None, metUncertaintySequence, postfix)
                collectionsToKeep.append( lastJetCollection )

            #for default w/o smearing
            collectionsToKeep.append( lastJetCollection )

        #--------------------------------------------------------------------------------------------
        # produce collection of electrons/photons, muons, tau-jet candidates and jets
        # shifted up/down in energy by their respective energy uncertainties
        #--------------------------------------------------------------------------------------------
        shiftedParticleSequence, shiftedParticleCollections, addCollectionsToKeep = \
          self._addShiftedParticleCollections(process,
                                              electronCollection.value() if isValidInputTag(electronCollection) else "",
                                              photonCollection.value() if isValidInputTag(photonCollection) else "",
                                              muonCollection.value() if isValidInputTag(muonCollection) else "",
                                              tauCollection.value() if isValidInputTag(tauCollection) else "",
                                              jetCollection.value() if isValidInputTag(jetCollection) else "",
                                              cleanedJetCollection,
                                              lastJetCollection, doSmearJets,
                                              jetCorrLabelUpToL3, jetCorrLabelUpToL3Res,
                                              jecUncertaintyFile, jecUncertaintyTag,
                                              jetSmearFileName, jetSmearHistogram,
                                              varyByNsigmas, postfix)
        setattr(process, "shiftedParticlesForType1PFMEtUncertainties" + postfix, shiftedParticleSequence)
        metUncertaintySequence += getattr(process, "shiftedParticlesForType1PFMEtUncertainties" + postfix)
        collectionsToKeep.extend(addCollectionsToKeep)



        #--------------------------------------------------------------------------------------------
        # propagate shifted particle energies to Type 1 and Type 1 + 2 corrected PFMET
        #--------------------------------------------------------------------------------------------

        self._addCorrPFMEt(process, metUncertaintySequence,
                           shiftedParticleCollections, pfCandCollection, jetCollectionUnskimmed,
                           doApplyUnclEnergyCalibration,
                           collectionsToKeep,
                           doSmearJets,
                           makeType1corrPFMEt,
                           makeType1p2corrPFMEt,
                           doApplyType0corr,
                           sysShiftCorrParameter,
                           doApplySysShiftCorr,
                           jetCorrLabel,
                           varyByNsigmas,
                           postfix)

        # insert metUncertaintySequence into patDefaultSequence
        if addToPatDefaultSequence:
            if not hasattr(process, "patDefaultSequence"):
                raise ValueError("PAT default sequence is not defined !!")
            process.patDefaultSequence += metUncertaintySequence


        # add shifted + unshifted collections pf pat::Electrons/Photons,
        # Muons, Taus, Jets and MET to PAT-tuple event content
        if outputModule is not None and hasattr(process, outputModule):
            getattr(process, outputModule).outputCommands = _addEventContent(
                getattr(process, outputModule).outputCommands,
                [ 'keep *_%s_*_%s' % (collectionToKeep, process.name_()) for collectionToKeep in collectionsToKeep ])
コード例 #2
0
    def toolCode(self, process):
        electronCollection = self._parameters['electronCollection'].value
        photonCollection = self._parameters['photonCollection'].value
        muonCollection = self._parameters['muonCollection'].value
        tauCollection = self._parameters['tauCollection'].value
        jetCollection = self._parameters['jetCollection'].value
        jetCorrLabel = self._parameters['jetCorrLabel'].value
        dRjetCleaning =  self._parameters['dRjetCleaning'].value
        doSmearJets = self._parameters['doSmearJets'].value
        makeType1corrPFMEt = self._parameters['makeType1corrPFMEt'].value
        makeType1p2corrPFMEt = self._parameters['makeType1p2corrPFMEt'].value
        doApplyType0corr = self._parameters['doApplyType0corr'].value
        sysShiftCorrParameter = self._parameters['sysShiftCorrParameter'].value
        doApplySysShiftCorr = self._parameters['doApplySysShiftCorr'].value
        jetSmearFileName = self._parameters['jetSmearFileName'].value
        jetSmearHistogram = self._parameters['jetSmearHistogram'].value
        pfCandCollection = self._parameters['pfCandCollection'].value
        doApplyUnclEnergyCalibration = self._parameters['doApplyUnclEnergyCalibration'].value
        jetCorrPayloadName = self._parameters['jetCorrPayloadName'].value
        jetCorrLabelUpToL3 = self._parameters['jetCorrLabelUpToL3'].value
        jetCorrLabelUpToL3Res = self._parameters['jetCorrLabelUpToL3Res'].value
        jecUncertaintyFile = self._parameters['jecUncertaintyFile'].value
        jecUncertaintyTag = self._parameters['jecUncertaintyTag'].value
        varyByNsigmas = self._parameters['varyByNsigmas'].value
        addToPatDefaultSequence = self._parameters['addToPatDefaultSequence'].value
        outputModule = self._parameters['outputModule'].value
        postfix = self._parameters['postfix'].value

        if not hasattr(process, "pfType1MEtUncertaintySequence" + postfix):
            metUncertaintySequence = cms.Sequence()
            setattr(process, "pfType1MEtUncertaintySequence" + postfix, metUncertaintySequence)
        metUncertaintySequence = getattr(process, "pfType1MEtUncertaintySequence" + postfix)

        collectionsToKeep = []


        if isValidInputTag(jetCollection):
            # produce collection of jets not overlapping with reconstructed
            # electrons/photons, muons and tau-jet candidates
            lastJetCollection, cleanedJetCollection = \
                self._addCleanedJets(process, jetCollection,
                                     electronCollection, photonCollection, muonCollection, tauCollection,
                                     metUncertaintySequence, postfix)

            # smear jet energies to account for difference in jet resolutions between MC and Data
            # (cf. JME-10-014 PAS)
            if doSmearJets:
                lastJetCollection = \
                    addSmearedJets(process, cleanedJetCollection,
                                   [ "smeared", jetCollection.value() ],
                                   jetSmearFileName, jetSmearHistogram, jetResolutions,
                                   varyByNsigmas, None, metUncertaintySequence, postfix)
                collectionsToKeep.append( lastJetCollection )

            #for default w/o smearing
            collectionsToKeep.append( lastJetCollection )

        #--------------------------------------------------------------------------------------------
        # produce collection of electrons/photons, muons, tau-jet candidates and jets
        # shifted up/down in energy by their respective energy uncertainties
        #--------------------------------------------------------------------------------------------
        shiftedParticleSequence, shiftedParticleCollections, addCollectionsToKeep = \
          self._addShiftedParticleCollections(process,
                                              electronCollection.value() if isValidInputTag(electronCollection) else "",
                                              photonCollection.value() if isValidInputTag(photonCollection) else "",
                                              muonCollection.value() if isValidInputTag(muonCollection) else "",
                                              tauCollection.value() if isValidInputTag(tauCollection) else "",
                                              jetCollection.value() if isValidInputTag(jetCollection) else "",
                                              cleanedJetCollection,
                                              lastJetCollection, doSmearJets,
                                              jetCorrLabelUpToL3, jetCorrLabelUpToL3Res,
                                              jecUncertaintyFile, jecUncertaintyTag,
                                              jetSmearFileName, jetSmearHistogram,
                                              varyByNsigmas, postfix)
        setattr(process, "shiftedParticlesForType1PFMEtUncertainties" + postfix, shiftedParticleSequence)
        metUncertaintySequence += getattr(process, "shiftedParticlesForType1PFMEtUncertainties" + postfix)
        collectionsToKeep.extend(addCollectionsToKeep)



        #--------------------------------------------------------------------------------------------
        # propagate shifted particle energies to Type 1 and Type 1 + 2 corrected PFMET
        #--------------------------------------------------------------------------------------------

        self._addCorrPFMEt(process, metUncertaintySequence,
                           shiftedParticleCollections, pfCandCollection, doApplyUnclEnergyCalibration,
                           collectionsToKeep,
                           doSmearJets,
                           makeType1corrPFMEt,
                           makeType1p2corrPFMEt,
                           doApplyType0corr,
                           sysShiftCorrParameter,
                           doApplySysShiftCorr,
                           jetCorrLabel,
                           varyByNsigmas,
                           postfix)

        # insert metUncertaintySequence into patDefaultSequence
        if addToPatDefaultSequence:
            if not hasattr(process, "patDefaultSequence"):
                raise ValueError("PAT default sequence is not defined !!")
            process.patDefaultSequence += metUncertaintySequence


        # add shifted + unshifted collections pf pat::Electrons/Photons,
        # Muons, Taus, Jets and MET to PAT-tuple event content
        if outputModule is not None and hasattr(process, outputModule):
            getattr(process, outputModule).outputCommands = _addEventContent(
                getattr(process, outputModule).outputCommands,
                [ 'keep *_%s_*_%s' % (collectionToKeep, process.name_()) for collectionToKeep in collectionsToKeep ])
コード例 #3
0
    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
コード例 #4
0
    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, "T1T2", "Res",
                                             shiftedParticleCollections,
                                             metUncertaintySequence, postfix)
            if makeType1p2corrPFMEt:
                self._prepareJetVariationsForMET(process, "T2", "Res",
                                                 shiftedParticleCollections,
                                                 metUncertaintySequence,
                                                 postfix)

        #
        # prepare energy variations
        #
        self._prepareJetVariationsForMET(process, "T1T2", "En",
                                         shiftedParticleCollections,
                                         metUncertaintySequence, postfix)
        if makeType1p2corrPFMEt:
            self._prepareJetVariationsForMET(process, "T2", "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),
                    srcCorrections=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),
                    srcCorrections=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),
                        srcCorrections=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('patPFMetT1T2Corr' +
                                         postfix, 'type2'),
                            cms.InputTag(
                                'patPFMetT1T2CorrUnclusteredEn' + var +
                                postfix, 'type2'),
                            cms.InputTag('patPFMetT2Corr' + postfix, 'type2'),
                            cms.InputTag(
                                'patPFMetT2CorrUnclusteredEn' + var +
                                postfix, 'type2'),
                            cms.InputTag('patPFMetT1T2Corr' +
                                         postfix, 'offset'),
                            cms.InputTag(
                                'patPFMetT1T2CorrUnclusteredEn' + 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, "patPFMetT1T2Corr").src = jetCollectionUnskimmed
            getattr(process, "patPFMetT2Corr").src = jetCollectionUnskimmed