Example #1
0
    def toolCode(self, process):
        """
        Tool code implementation
        """
        ## initialize parameters
        labelName = "patJets" + self._parameters["labelName"].value
        postfix = self._parameters["postfix"].value
        jetSource = self._parameters["jetSource"].value
        algo = self._parameters["algo"].value
        jetCorrections = self._parameters["jetCorrections"].value
        btagDiscriminators = list(self._parameters["btagDiscriminators"].value)
        btagInfos = list(self._parameters["btagInfos"].value)
        jetTrackAssociation = self._parameters["jetTrackAssociation"].value
        outputModules = list(self._parameters["outputModules"].value)

        ## a list of all producer modules, which are already known to process
        knownModules = process.producerNames().split()
        ## determine whether btagging information is required or not
        if btagDiscriminators.count("None") > 0:
            btagDiscriminators.remove("None")
        if btagInfos.count("None") > 0:
            btagInfos.remove("None")
        bTagging = len(btagDiscriminators) > 0 or len(btagInfos) > 0
        ## construct postfix label for auxiliary modules; this postfix
        ## label will start with a capitalized first letter following
        ## the CMS nameing conventions and for improved readablility
        _labelName = labelName[:1].upper() + labelName[1:]
        # _labelName=labelName
        ## determine jet algorithm from jetSource; supported algo types
        ## are ak, kt, sc, ic. This loop expects that the algo type is
        ## followed by a single integer corresponding to the opening
        ## angle parameter dR times 10 (examples ak5, kt4, kt6, ...)
        _algo = algo
        # jetSource=cms.InputTag("ak5PFJets")
        for x in ["ak", "kt", "sc", "ic"]:
            if jetSource.getModuleLabel().lower().find(x) > -1:
                _algo = jetSource.getModuleLabel()[
                    jetSource.getModuleLabel().lower().find(x) : jetSource.getModuleLabel().lower().find(x) + 3
                ]
        # print _algo
        ## add new patJets to process (keep instance for later further modifications)
        from PhysicsTools.PatAlgos.producersLayer1.jetProducer_cfi import patJets

        if labelName in knownModules:
            _newPatJets = getattr(process, labelName + postfix)
            _newPatJets.jetSource = jetSource
        else:
            # setattr(process, labelName, patJets.clone(jetSource=jetSource))
            setattr(process, labelName + postfix, patJets.clone(jetSource=jetSource))
            _newPatJets = getattr(process, labelName + postfix)
            knownModules.append(labelName + postfix)
        ## add new selectedPatJets to process
        from PhysicsTools.PatAlgos.selectionLayer1.jetSelector_cfi import selectedPatJets

        if "selected" + _labelName + postfix in knownModules:
            _newSelectedPatJets = getattr(process, "selected" + _labelName + postfix)
            _newSelectedPatJets.src = labelName + postfix
        else:
            setattr(process, "selected" + _labelName + postfix, selectedPatJets.clone(src=labelName + postfix))
            knownModules.append("selected" + _labelName + postfix)

        ## set postfix label to '' if there is no labelName given. In this case all
        ## modules should keep there names w/o postfixes. This will cover the case
        ## of switchJectCollection
        if self._parameters["labelName"].value == "":
            _labelName = ""

        ## add new patJetPartonMatch to process
        from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetPartonMatch

        if "patJetPartonMatch" + _labelName + postfix in knownModules:
            _newPatJetPartonMatch = getattr(process, "patJetPartonMatch" + _labelName + postfix)
            _newPatJetPartonMatch.src = jetSource
        else:
            setattr(process, "patJetPartonMatch" + _labelName + postfix, patJetPartonMatch.clone(src=jetSource))
            knownModules.append("patJetPartonMatch" + _labelName + postfix)
        ## add new patJetGenJetMatch to process
        from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch

        if "patJetGenJetMatch" + _labelName + postfix in knownModules:
            _newPatJetGenJetMatch = getattr(process, "patJetGenJetMatch" + _labelName + postfix)
            _newPatJetGenJetMatch.src = jetSource
            _newPatJetGenJetMatch.matched = _algo.lower() + "GenJets" + postfix
        else:
            setattr(
                process,
                "patJetGenJetMatch" + _labelName + postfix,
                patJetGenJetMatch.clone(src=jetSource, matched=_algo + "GenJets"),
            )
            knownModules.append("patJetGenJetMatch" + _labelName + postfix)
        ## add new patJetPartonAssociation to process
        from PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff import patJetPartonAssociation

        if "patJetPartonAssociation" + _labelName + postfix in knownModules:
            _newPatJetPartonAssociation = getattr(
                process, "patJetPartonAssociation" + _labelName + postfix, patJetPartonAssociation.clone(jets=jetSource)
            )
            _newPatJetPartonAssociation.jets = jetSource
        else:
            setattr(
                process, "patJetPartonAssociation" + _labelName + postfix, patJetPartonAssociation.clone(jets=jetSource)
            )
            knownModules.append("patJetPartonAssociation" + _labelName + postfix)
        ## add new patJetPartonAssociation to process
        from PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff import patJetFlavourAssociation

        if "patJetFlavourAssociation" + _labelName + postfix in knownModules:
            _newPatJetFlavourAssociation = getattr(
                process,
                "patJetFlavourAssociation" + _labelName + postfix,
                patJetFlavourAssociation.clone(srcByReference="patJetPartonAssociation" + _labelName + postfix),
            )
            _newPatJetFlavourAssociation.srcByReference = "patJetPartonAssociation" + _labelName + postfix
        else:
            setattr(
                process,
                "patJetFlavourAssociation" + _labelName + postfix,
                patJetFlavourAssociation.clone(srcByReference="patJetPartonAssociation" + _labelName + postfix),
            )
            knownModules.append("patJetFlavourAssociation" + _labelName + postfix)
        ## modify new patJets collection accordingly
        _newPatJets.genJetMatch.setModuleLabel("patJetGenJetMatch" + _labelName + postfix)
        _newPatJets.genPartonMatch.setModuleLabel("patJetPartonMatch" + _labelName + postfix)
        _newPatJets.JetPartonMapSource.setModuleLabel("patJetFlavourAssociation" + _labelName + postfix)

        ## add jetTrackAssociation for btagging (or jetTracksAssociation only) if required by user
        if jetTrackAssociation or bTagging:
            ## add new jetTracksAssociationAtVertex to process
            from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex

            if "jetTracksAssociationAtVertex" + _labelName + postfix in knownModules:
                _newJetTracksAssociationAtVertex = getattr(
                    process, "jetTracksAssociatorAtVertex" + _labelName + postfix
                )
                _newJetTracksAssociationAtVertex.jets = jetSource
            else:
                setattr(
                    process,
                    "jetTracksAssociatorAtVertex" + _labelName + postfix,
                    ak5JetTracksAssociatorAtVertex.clone(jets=jetSource),
                )
                knownModules.append("jetTracksAssociationAtVertex" + _labelName + postfix)
            ## add new patJetCharge to process
            from PhysicsTools.PatAlgos.recoLayer0.jetTracksCharge_cff import patJetCharge

            if "patJetCharge" + _labelName + postfix in knownModules:
                _newPatJetCharge = getattr(process, "patJetCharge" + _labelName + postfix)
                _newPatJetCharge.src = "jetTracksAssociatorAtVertex" + _labelName + postfix
            else:
                setattr(
                    process,
                    "patJetCharge" + _labelName + postfix,
                    patJetCharge.clone(src="jetTracksAssociatorAtVertex" + _labelName + postfix),
                )
                knownModules.append("patJetCharge" + _labelName + postfix)
            ## modify new patJets collection accordingly
            _newPatJets.addAssociatedTracks = True
            _newPatJets.trackAssociationSource = cms.InputTag("jetTracksAssociatorAtVertex" + _labelName + postfix)
            _newPatJets.addJetCharge = True
            _newPatJets.jetChargeSource = cms.InputTag("patJetCharge" + _labelName + postfix)
        else:
            ## modify new patJets collection accordingly
            _newPatJets.addAssociatedTracks = False
            _newPatJets.trackAssociationSource = ""
            _newPatJets.addJetCharge = False
            _newPatJets.jetChargeSource = ""
        ## run btagging if required by user
        if bTagging:
            ## expand tagInfos to what is explicitely required by user + implicit
            ## requirements that come in from one or the other discriminator
            requiredTagInfos = list(btagInfos)
            for btagDiscr in btagDiscriminators:
                for requiredTagInfo in supportedBtagDiscr[btagDiscr]:
                    tagInfoCovered = False
                    for tagInfo in requiredTagInfos:
                        if requiredTagInfo == tagInfo:
                            tagInfoCovered = True
                            break
                    if not tagInfoCovered:
                        requiredTagInfos.append(requiredTagInfo)
            ## load sequences and setups needed fro btagging
            ## This loads all available btagger, but the ones we need are added to the process by hand lader. Only needed to get the ESProducer. Needs improvement
            # loadWithPostFix(process,"RecoBTag.Configuration.RecoBTag_cff",postfix)
            process.load("RecoBTag.Configuration.RecoBTag_cff")
            # addESProducers(process,'RecoBTag.Configuration.RecoBTag_cff')
            import RecoBTag.Configuration.RecoBTag_cff as btag

            ## prepare setups for simple secondary vertex infos
            setattr(process, "simpleSecondaryVertex2Trk", simpleSecondaryVertex2Trk)
            ## prepare setups for transient tracks
            setattr(process, "TransientTrackBuilderESProducer", TransientTrackBuilderESProducer)
            ## setup all required btagInfos : we give a dedicated treatment for all five different
            ## types of tagINfos here. A common treatment is possible but might require a more
            ## general approach anyway in coordination with the btaggin POG.
            for btagInfo in requiredTagInfos:
                if "impactParameterTagInfos" in btagInfo:
                    setattr(
                        process,
                        btagInfo + _labelName + postfix,
                        btag.impactParameterTagInfos.clone(
                            jetTracks=cms.InputTag("jetTracksAssociatorAtVertex" + _labelName + postfix)
                        ),
                    )
                if "secondaryVertexTagInfos" in btagInfo:
                    setattr(
                        process,
                        btagInfo + _labelName + postfix,
                        btag.secondaryVertexTagInfos.clone(
                            trackIPTagInfos=cms.InputTag("impactParameterTagInfos" + _labelName + postfix)
                        ),
                    )
                if "secondaryVertexNegativeTagInfos" in btagInfo:
                    setattr(
                        process,
                        btagInfo + _labelName + postfix,
                        btag.secondaryVertexNegativeTagInfos.clone(
                            trackIPTagInfos=cms.InputTag("impactParameterTagInfos" + _labelName + postfix)
                        ),
                    )
                if "softElectronTagInfos" in btagInfo:
                    setattr(
                        process,
                        btagInfo + _labelName + postfix,
                        btag.softElectronTagInfos.clone(jets=cms.InputTag(_newJetCollection)),
                    )
                if "softMuonTagInfos" in btagInfo:
                    setattr(
                        process,
                        btagInfo + _labelName + postfix,
                        btag.softMuonTagInfos.clone(jets=cms.InputTag(_newJetCollection)),
                    )
            ## setup all required btagDiscriminators
            for btagDiscr in btagDiscriminators:
                setattr(
                    process,
                    btagDiscr + _labelName + postfix,
                    getattr(btag, btagDiscr).clone(
                        tagInfos=cms.VInputTag(
                            *[cms.InputTag(x + _labelName + postfix) for x in supportedBtagDiscr[btagDiscr]]
                        )
                    ),
                )
            ## replace corresponding tags for pat jet production
            _newPatJets.tagInfoSources = cms.VInputTag(*[cms.InputTag(x + _labelName + postfix) for x in btagInfos])
            _newPatJets.discriminatorSources = cms.VInputTag(
                *[cms.InputTag(x + _labelName + postfix) for x in btagDiscriminators]
            )
        else:
            _newPatJets.addBTagInfo = False
            ## adjust output module; these collections will be empty anyhow, but we do it to stay clean
            for outputModule in outputModules:
                if hasattr(process, outputModule):
                    getattr(process, outputModule).outputCommands.append(
                        "drop *_" + "selected" + _labelName + postfix + "_tagInfos_*"
                    )

        ## add jet correction factors if required by user
        if jetCorrections != None:
            ## check for the correct format
            if type(jetCorrections) != type(
                ("PAYLOAD-LABEL", ["CORRECTION-LEVEL-A", "CORRECTION-LEVEL-B"], "MET-LABEL")
            ):
                raise ValueError, "In addJetCollection: 'jetCorrections' must be 'None' (as a python value w/o quotation marks), or of type ('PAYLOAD-LABEL', ['CORRECTION-LEVEL-A', \
                'CORRECTION-LEVEL-B', ...], 'MET-LABEL'). Note that 'MET-LABEL' can be set to 'None' (as a string in quotation marks) in case you do not want to apply MET(Type1) \
                corrections."
            ## determine type of jet constituents from jetSource; supported
            ## jet constituent types are calo, pf, jpt, for pf also particleflow
            ## is aloowed as part of the jetSource label, which might be used
            ## in CommonTools.ParticleFlow
            _type = "NONE"
            if jetCorrections[0].count("PF") > 0:
                _type = "PF"
            elif jetCorrections[0].count("Calo") > 0:
                _type = "Calo"
            elif jetCorrections[0].count("JPT") > 0:
                _type = "JPT"
            else:
                raise TypeError, "In addJetCollection: Jet energy corrections are only supported for PF, JPT and Calo jets."
            from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors

            if "patJetCorrFactors" + _labelName + postfix in knownModules:
                _newPatJetCorrFactors = getattr(process, "patJetCorrFactors" + _labelName + postfix)
                _newPatJetCorrFactors.src = jetSource
            else:

                setattr(process, "patJetCorrFactors" + _labelName + postfix, patJetCorrFactors.clone(src=jetSource))
                _newPatJetCorrFactors = getattr(process, "patJetCorrFactors" + _labelName + postfix)
            _newPatJetCorrFactors.payload = jetCorrections[0]
            _newPatJetCorrFactors.levels = jetCorrections[1]
            ## check whether L1Offset or L1FastJet is part of levels
            error = False
            for x in jetCorrections[1]:
                if x == "L1Offset":
                    if not error:
                        _newPatJetCorrFactors.useNPV = True
                        _newPatJetCorrFactors.primaryVertices = "offlinePrimaryVertices"
                        ## we set this to True now as a L1 correction type should appear only once
                        ## otherwise levels is miss configured
                        error = True
                    else:
                        raise ValueError, "In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
                        once. Check the list of correction levels you requested to be applied: ", jetCorrections[
                            1
                        ]
                if x == "L1FastJet":
                    if not error:
                        if _type == "JPT":
                            raise TypeError, "In addJetCollection: L1FastJet corrections are only supported for PF and Calo jets."
                        ## configure module
                        _newPatJetCorrFactors.useRho = True
                        _newPatJetCorrFactors.rho = cms.InputTag("kt6" + _type + "Jets", "rho")
                        ## we set this to True now as a L1 correction type should appear only once
                        ## otherwise levels is miss configured
                        error = True
                    else:
                        raise ValueError, "In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
                        once. Check the list of correction levels you requested to be applied: ", jetCorrections[
                            1
                        ]
            _newPatJets.jetCorrFactorsSource = cms.VInputTag(cms.InputTag("patJetCorrFactors" + _labelName + postfix))
            ## configure MET(Type1) corrections
            if jetCorrections[2].lower() != "none" and jetCorrections[2] != "":
                if not jetCorrections[2].lower() == "type-1" and not jetCorrections[2].lower() == "type-2":
                    raise valueError, "In addJetCollection: Wrong choice of MET corrections for new jet collection. Possible choices are None (or empty string), Type-1, Type-2 (i.e.\
                    Type-1 and Type-2 corrections applied). This choice is not case sensitive. Your choice was: ", jetCorrections[
                        2
                    ]
                if _type == "JPT":
                    raise ValueError, 'In addJecCollection: MET(type1) corrections are not supported for JPTJets. Please set the MET-LABEL to "None" (as string in quatiation \
                    marks) and use raw tcMET together with JPTJets.'
                ## set up jet correctors for MET corrections
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Fastjet
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Offset
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL2Relative
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL3Absolute
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFResidual

                setattr(
                    process,
                    jetCorrections[0] + "L1FastJet",
                    ak5PFL1Fastjet.clone(
                        algorithm=jetCorrections[0], srcRho=cms.InputTag("kt6" + _type + "Jets", "rho")
                    ),
                )
                setattr(process, jetCorrections[0] + "L1Offset", ak5PFL1Offset.clone(algorithm=jetCorrections[0]))
                setattr(process, jetCorrections[0] + "L2Relative", ak5PFL2Relative.clone(algorithm=jetCorrections[0]))
                setattr(process, jetCorrections[0] + "L3Absolute", ak5PFL3Absolute.clone(algorithm=jetCorrections[0]))
                setattr(process, jetCorrections[0] + "L2L3Residual", ak5PFResidual.clone(algorithm=jetCorrections[0]))
                setattr(
                    process,
                    jetCorrections[0] + "CombinedCorrector",
                    cms.ESProducer("JetCorrectionESChain", correctors=cms.vstring()),
                )
                for x in jetCorrections[1]:
                    if (
                        x != "L1FastJet"
                        and x != "L1Offset"
                        and x != "L2Relative"
                        and x != "L3Absolute"
                        and x != "L2L3Residual"
                    ):
                        raise ValueError, "In addJetCollection: Unsupported JEC for MET(Type1). Currently supported jet correction levels are L1FastJet, L1Offset, L2Relative, \
                        L3Asolute, L2L3Residual. Requested was:", x
                    else:
                        getattr(process, jetCorrections[0] + "CombinedCorrector").correctors.append(
                            jetCorrections[0] + x
                        )

                ## set up MET(Type1) correction modules
                if _type == "Calo":
                    from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloJetMETcorr
                    from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloType1CorrectedMet
                    from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloType1p2CorrectedMet

                    setattr(
                        process,
                        jetCorrections[0] + "JetMETcorr" + postfix,
                        caloJetMETcorr.clone(
                            src=jetSource,
                            srcMET="corMetGlobalMuons",
                            jetCorrections=cms.string(jetCorrections[0] + "CombinedCorrector" + postfix),
                        ),
                    )
                    setattr(
                        process,
                        jetCorrections[0] + "Type1CorMet" + postfix,
                        caloType1CorrectedMet.clone(
                            src="corMetGlobalMuons" + postfix,
                            srcType1Corrections=cms.VInputTag(
                                cms.InputTag(jetCorrections[0] + "JetMETcorr" + postfix, "type1")
                            ),
                        ),
                    )
                    setattr(
                        process,
                        jetCorrections[0] + "Type1p2CorMet" + postfix,
                        caloType1p2CorrectedMet.clone(
                            src="corMetGlobalMuons" + postfix,
                            srcType1Corrections=cms.VInputTag(
                                cms.InputTag(jetCorrections[0] + "JetMETcorr" + postfix, "type1")
                            ),
                            srcUnclEnergySums=cms.VInputTag(
                                cms.InputTag(jetCorrections[0] + "JetMETcorr" + postfix, "type2"),
                                cms.InputTag(jetCorrections[0] + "JetMETcorr" + postfix, "offset"),
                                cms.InputTag("muonCaloMETcorr" + postfix),
                            ),
                        ),
                    )

                elif _type == "PF":
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfCandsNotInJet
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfJetMETcorr
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfCandMETcorr
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfType1CorrectedMet
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfType1p2CorrectedMet

                    setattr(
                        process,
                        jetCorrections[0] + "CandsNotInJet" + postfix,
                        pfCandsNotInJet.clone(topCollection=jetSource),
                    )
                    setattr(
                        process,
                        jetCorrections[0] + "CandMETcorr" + postfix,
                        pfCandMETcorr.clone(src=cms.InputTag(jetCorrections[0] + "CandsNotInJet" + postfix)),
                    )
                    setattr(process, jetCorrections[0] + "JetMETcorr" + postfix, pfJetMETcorr.clone(src=jetSource))
                    setattr(
                        process,
                        jetCorrections[0] + "Type1CorMet" + postfix,
                        pfType1CorrectedMet.clone(
                            srcType1Corrections=cms.VInputTag(
                                cms.InputTag(jetCorrections[0] + "JetMETcorr" + postfix, "type1")
                            )
                        ),
                    )
                    setattr(
                        process,
                        jetCorrections[0] + "Type1p2CorMet" + postfix,
                        pfType1p2CorrectedMet.clone(
                            srcType1Corrections=cms.VInputTag(
                                cms.InputTag(jetCorrections[0] + "JetMETcorr" + postfix, "type1")
                            ),
                            srcUnclEnergySums=cms.VInputTag(
                                cms.InputTag(jetCorrections[0] + "JetMETcorr" + postfix, "type2"),
                                cms.InputTag(jetCorrections[0] + "JetMETcorr" + postfix, "offset"),
                                cms.InputTag(jetCorrections[0] + "CandMETcorr" + postfix),
                            ),
                        ),
                    )

                ## common configuration for Calo and PF
                if "L1FastJet" in jetCorrections[1] or "L1Fastjet" in jetCorrections[1]:
                    getattr(process, jetCorrections[0] + "JetMETcorr" + postfix).offsetCorrLabel = cms.string(
                        jetCorrections[0] + "L1FastJet"
                    )
                elif "L1Offset" in jetCorrections[1]:
                    getattr(process, jetCorrections[0] + "JetMETcorr" + postfix).offsetCorrLabel = cms.string(
                        jetCorrections[0] + "L1Offset"
                    )
                else:
                    getattr(process, jetCorrections[0] + "JetMETcorr" + postfix).offsetCorrLabel = cms.string("")

                from PhysicsTools.PatAlgos.producersLayer1.metProducer_cfi import patMETs

                if jetCorrections[2].lower() == "type-1":
                    setattr(
                        process,
                        "patMETs" + _labelName + postfix,
                        patMETs.clone(
                            metSource=cms.InputTag(jetCorrections[0] + "Type1CorMet" + postfix),
                            addMuonCorrections=False,
                        ),
                    )
                elif jetCorrections[2].lower() == "type-1":
                    setattr(
                        process,
                        "patMETs" + _labelName + postfix,
                        patMETs.clone(
                            metSource=cms.InputTag(jetCorrections[0] + "Type1p2CorMet" + postfix),
                            addMuonCorrections=False,
                        ),
                    )
        else:
            ## switch jetCorrFactors off
            _newPatJets.addJetCorrFactors = False
Example #2
0
    def addGenJetCollection(
        self,
        proc,
        jet,
        inputCollection="",
        genName="",
        minPt=5.,
    ):
        print(
            "jetCollectionTools::GenJetAdder::addGenJetCollection: Adding Gen Jet Collection: {}"
            .format(jet))
        currentTasks = []

        #
        # Decide which jet collection we're dealing with
        #
        jetLower = jet.lower()
        jetUpper = jet.upper()
        tagName = jetUpper
        genJetInfo = GenJetInfo(jet, inputCollection)

        #=======================================================
        #
        # If gen jet collection in MiniAOD is not
        # specified, build the genjet collection.
        #
        #========================================================
        if not inputCollection:
            print(
                "jetCollectionTools::GenJetAdder::addGenJetCollection: inputCollection not specified. Building genjet collection now"
            )
            #
            # Setup GenParticles
            #
            packedGenPartNoNu = "packedGenParticlesForJetsNoNu"
            if packedGenPartNoNu not in self.prerequisites:
                setattr(
                    proc, packedGenPartNoNu,
                    cms.EDFilter(
                        "CandPtrSelector",
                        src=cms.InputTag("packedGenParticles"),
                        cut=cms.string(
                            "abs(pdgId) != 12 && abs(pdgId) != 14 && abs(pdgId) != 16"
                        ),
                    ))
                self.prerequisites.append(packedGenPartNoNu)
            #
            # Create the GenJet collection
            #
            genJetsCollection = "{}{}{}".format(genJetInfo.jetAlgo.upper(),
                                                genJetInfo.jetSize,
                                                'GenJetsNoNu')
            setattr(
                proc, genJetsCollection,
                ak4GenJets.clone(
                    src=packedGenPartNoNu,
                    jetAlgorithm=cms.string(
                        supportedJetAlgos[genJetInfo.jetAlgo]),
                    rParam=cms.double(genJetInfo.jetSizeNr),
                ))
            self.prerequisites.append(genJetsCollection)
        #
        # GenJet Flavour Labelling
        #
        genFlavour = "{}Flavour".format(genJetInfo.jetTagName)
        setattr(
            proc, genFlavour,
            patJetFlavourAssociation.clone(
                jets=cms.InputTag(genJetsCollection),
                jetAlgorithm=cms.string(supportedJetAlgos[genJetInfo.jetAlgo]),
                rParam=cms.double(genJetInfo.jetSizeNr),
            ))

        currentTasks.append(genFlavour)
        self.main.extend(currentTasks)

        return genJetInfo
    def toolCode(self, process):
        """
        Tool code implementation
        """
        ## initialize parameters
        labelName='patJets'+self._parameters['labelName'].value
        postfix=self._parameters['postfix'].value
        jetSource=self._parameters['jetSource'].value
        algo=self._parameters['algo'].value
        jetCorrections=self._parameters['jetCorrections'].value
        btagDiscriminators=list(self._parameters['btagDiscriminators'].value)
        btagInfos=list(self._parameters['btagInfos'].value)
        jetTrackAssociation=self._parameters['jetTrackAssociation'].value
        outputModules=list(self._parameters['outputModules'].value)

        ## a list of all producer modules, which are already known to process
        knownModules = process.producerNames().split()
        ## determine whether btagging information is required or not
        if btagDiscriminators.count('None')>0:
            btagDiscriminators.remove('None')
        if btagInfos.count('None')>0:
            btagInfos.remove('None')
        bTagging=(len(btagDiscriminators)>0 or len(btagInfos)>0)
        ## construct postfix label for auxiliary modules; this postfix
        ## label will start with a capitalized first letter following
        ## the CMS nameing conventions and for improved readablility
        _labelName=labelName[:1].upper()+labelName[1:]
	#_labelName=labelName
        ## determine jet algorithm from jetSource; supported algo types
        ## are ak, kt, sc, ic. This loop expects that the algo type is
        ## followed by a single integer corresponding to the opening
        ## angle parameter dR times 10 (examples ak5, kt4, kt6, ...)
        _algo=algo
	#jetSource=cms.InputTag("ak5PFJets")
        for x in ["ak", "kt", "sc", "ic"]:
            if jetSource.getModuleLabel().lower().find(x)>-1:
                _algo=jetSource.getModuleLabel()[jetSource.getModuleLabel().lower().find(x):jetSource.getModuleLabel().lower().find(x)+3]
	#print _algo
        ## add new patJets to process (keep instance for later further modifications)
        from PhysicsTools.PatAlgos.producersLayer1.jetProducer_cfi import patJets
        if labelName in knownModules :
            _newPatJets=getattr(process, labelName+postfix)
            _newPatJets.jetSource=jetSource
        else :
            #setattr(process, labelName, patJets.clone(jetSource=jetSource))
            setattr(process, labelName+postfix, patJets.clone(jetSource=jetSource))
            _newPatJets=getattr(process, labelName+postfix)
            knownModules.append(labelName+postfix)
        ## add new selectedPatJets to process
        from PhysicsTools.PatAlgos.selectionLayer1.jetSelector_cfi import selectedPatJets
        if 'selected'+_labelName+postfix in knownModules :
            _newSelectedPatJets=getattr(process, 'selected'+_labelName+postfix)
            _newSelectedPatJets.src=labelName+postfix
        else :
            setattr(process, 'selected'+_labelName+postfix, selectedPatJets.clone(src=labelName+postfix))
            knownModules.append('selected'+_labelName+postfix)

        ## set postfix label to '' if there is no labelName given. In this case all
        ## modules should keep there names w/o postfixes. This will cover the case
        ## of switchJectCollection
        if self._parameters['labelName'].value == '' :
            _labelName = ''

	## add new patJetPartonMatch to process
        from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetPartonMatch
        if 'patJetPartonMatch'+_labelName+postfix in knownModules :
            _newPatJetPartonMatch=getattr(process, 'patJetPartonMatch'+_labelName+postfix)
            _newPatJetPartonMatch.src=jetSource
        else :
            setattr(process, 'patJetPartonMatch'+_labelName+postfix, patJetPartonMatch.clone(src=jetSource))
            knownModules.append('patJetPartonMatch'+_labelName+postfix)
        ## add new patJetGenJetMatch to process
        from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
        if 'patJetGenJetMatch'+_labelName+postfix in knownModules :
            _newPatJetGenJetMatch=getattr(process, 'patJetGenJetMatch'+_labelName+postfix)
            _newPatJetGenJetMatch.src=jetSource
            _newPatJetGenJetMatch.matched=_algo.lower()+'GenJets'+postfix
        else :
            setattr(process, 'patJetGenJetMatch'+_labelName+postfix, patJetGenJetMatch.clone(src=jetSource, matched=_algo+'GenJets'))
            knownModules.append('patJetGenJetMatch'+_labelName+postfix)
        ## add new patJetPartonAssociation to process
        from PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff import patJetPartonAssociation
        if 'patJetPartonAssociation'+_labelName+postfix in knownModules :
            _newPatJetPartonAssociation=getattr(process, 'patJetPartonAssociation'+_labelName+postfix, patJetPartonAssociation.clone(jets=jetSource))
            _newPatJetPartonAssociation.jets=jetSource
        else :
            setattr(process, 'patJetPartonAssociation'+_labelName+postfix, patJetPartonAssociation.clone(jets=jetSource))
            knownModules.append('patJetPartonAssociation'+_labelName+postfix)
        ## add new patJetPartonAssociation to process
        from PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff import patJetFlavourAssociation
        if 'patJetFlavourAssociation'+_labelName+postfix in knownModules :
            _newPatJetFlavourAssociation=getattr(process, 'patJetFlavourAssociation'+_labelName+postfix, patJetFlavourAssociation.clone(srcByReference='patJetPartonAssociation'+_labelName+postfix))
            _newPatJetFlavourAssociation.srcByReference='patJetPartonAssociation'+_labelName+postfix
        else:
            setattr(process, 'patJetFlavourAssociation'+_labelName+postfix, patJetFlavourAssociation.clone(srcByReference='patJetPartonAssociation'+_labelName+postfix))
            knownModules.append('patJetFlavourAssociation'+_labelName+postfix)
        ## modify new patJets collection accordingly
        _newPatJets.genJetMatch.setModuleLabel('patJetGenJetMatch'+_labelName+postfix)
        _newPatJets.genPartonMatch.setModuleLabel('patJetPartonMatch'+_labelName+postfix)
        _newPatJets.JetPartonMapSource.setModuleLabel('patJetFlavourAssociation'+_labelName+postfix)

        ## add jetTrackAssociation for btagging (or jetTracksAssociation only) if required by user
        if (jetTrackAssociation or bTagging):
            ## add new jetTracksAssociationAtVertex to process
            from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex
            if 'jetTracksAssociationAtVertex'+_labelName+postfix in knownModules :
                _newJetTracksAssociationAtVertex=getattr(process, 'jetTracksAssociatorAtVertex'+_labelName+postfix)
                _newJetTracksAssociationAtVertex.jets=jetSource
            else:
                setattr(process, 'jetTracksAssociatorAtVertex'+_labelName+postfix, ak5JetTracksAssociatorAtVertex.clone(jets=jetSource))
                knownModules.append('jetTracksAssociationAtVertex'+_labelName+postfix)
            ## add new patJetCharge to process
            from PhysicsTools.PatAlgos.recoLayer0.jetTracksCharge_cff import patJetCharge
            if 'patJetCharge'+_labelName+postfix in knownModules :
                _newPatJetCharge=getattr(process, 'patJetCharge'+_labelName+postfix)
                _newPatJetCharge.src='jetTracksAssociatorAtVertex'+_labelName+postfix
            else:
                setattr(process, 'patJetCharge'+_labelName+postfix, patJetCharge.clone(src = 'jetTracksAssociatorAtVertex'+_labelName+postfix))
                knownModules.append('patJetCharge'+_labelName+postfix)
            ## modify new patJets collection accordingly
            _newPatJets.addAssociatedTracks=True
            _newPatJets.trackAssociationSource=cms.InputTag('jetTracksAssociatorAtVertex'+_labelName+postfix)
            _newPatJets.addJetCharge=True
            _newPatJets.jetChargeSource=cms.InputTag('patJetCharge'+_labelName+postfix)
        else:
            ## modify new patJets collection accordingly
            _newPatJets.addAssociatedTracks=False
            _newPatJets.trackAssociationSource=''
            _newPatJets.addJetCharge=False
            _newPatJets.jetChargeSource=''
        ## run btagging if required by user
        if (bTagging):
            ## expand tagInfos to what is explicitely required by user + implicit
            ## requirements that come in from one or the other discriminator
            requiredTagInfos = list(btagInfos)
            for btagDiscr in btagDiscriminators :
                for requiredTagInfo in supportedBtagDiscr[btagDiscr] :
                    tagInfoCovered = False
                    for tagInfo in requiredTagInfos :
                        if requiredTagInfo == tagInfo :
                            tagInfoCovered = True
                            break
                    if not tagInfoCovered :
                        requiredTagInfos.append(requiredTagInfo)
            ## load sequences and setups needed fro btagging
	    ## This loads all available btagger, but the ones we need are added to the process by hand lader. Only needed to get the ESProducer. Needs improvement
            #loadWithPostFix(process,"RecoBTag.Configuration.RecoBTag_cff",postfix)
            process.load("RecoBTag.Configuration.RecoBTag_cff")
	    #addESProducers(process,'RecoBTag.Configuration.RecoBTag_cff')
            import RecoBTag.Configuration.RecoBTag_cff as btag

            ## prepare setups for simple secondary vertex infos
            setattr(process, "simpleSecondaryVertex2Trk", simpleSecondaryVertex2Trk)
            ## prepare setups for transient tracks
            setattr(process, "TransientTrackBuilderESProducer", TransientTrackBuilderESProducer)
            ## setup all required btagInfos : we give a dedicated treatment for all five different
            ## types of tagINfos here. A common treatment is possible but might require a more
            ## general approach anyway in coordination with the btaggin POG.
            for btagInfo in requiredTagInfos :
                if 'impactParameterTagInfos' in btagInfo :
                    setattr(process, btagInfo+_labelName+postfix, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag('jetTracksAssociatorAtVertex'+_labelName+postfix)))
                if 'secondaryVertexTagInfos' in btagInfo :
                    setattr(process, btagInfo+_labelName+postfix, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+_labelName+postfix)))
                if 'secondaryVertexNegativeTagInfos' in btagInfo :
                    setattr(process, btagInfo+_labelName+postfix, btag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag('impactParameterTagInfos'+_labelName+postfix)))
                if 'softElectronTagInfos' in btagInfo :
                    setattr(process, btagInfo+_labelName+postfix, btag.softElectronTagInfos.clone(jets = cms.InputTag(_newJetCollection)))
                if 'softMuonTagInfos' in btagInfo :
                    setattr(process, btagInfo+_labelName+postfix, btag.softMuonTagInfos.clone(jets = cms.InputTag(_newJetCollection)))
            ## setup all required btagDiscriminators
            for btagDiscr in btagDiscriminators :
                setattr(process, btagDiscr+_labelName+postfix, getattr(btag, btagDiscr).clone(tagInfos = cms.VInputTag( *[ cms.InputTag(x+_labelName+postfix) for x in supportedBtagDiscr[btagDiscr] ] )))
            ## replace corresponding tags for pat jet production
            _newPatJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x+_labelName+postfix) for x in btagInfos ] )
            _newPatJets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x+_labelName+postfix) for x in btagDiscriminators ] )
        else:
            _newPatJets.addBTagInfo = False
            ## adjust output module; these collections will be empty anyhow, but we do it to stay clean
            for outputModule in outputModules:
                    if hasattr(process,outputModule):
                        getattr(process,outputModule).outputCommands.append("drop *_"+'selected'+_labelName+postfix+"_tagInfos_*")

        ## add jet correction factors if required by user
        if (jetCorrections != None):
            ## check for the correct format
            if type(jetCorrections) != type(('PAYLOAD-LABEL',['CORRECTION-LEVEL-A','CORRECTION-LEVEL-B'], 'MET-LABEL')):
                raise ValueError, "In addJetCollection: 'jetCorrections' must be 'None' (as a python value w/o quotation marks), or of type ('PAYLOAD-LABEL', ['CORRECTION-LEVEL-A', \
                'CORRECTION-LEVEL-B', ...], 'MET-LABEL'). Note that 'MET-LABEL' can be set to 'None' (as a string in quotation marks) in case you do not want to apply MET(Type1) \
                corrections."
            ## determine type of jet constituents from jetSource; supported
            ## jet constituent types are calo, pf, jpt, for pf also particleflow
            ## is aloowed as part of the jetSource label, which might be used
            ## in CommonTools.ParticleFlow
            _type="NONE"
            if jetCorrections[0].count('PF')>0:
                _type='PF'
            elif jetCorrections[0].count('Calo')>0:
                _type='Calo'
            elif jetCorrections[0].count('JPT')>0:
                _type='JPT'
            else:
                raise TypeError, "In addJetCollection: Jet energy corrections are only supported for PF, JPT and Calo jets."
            from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors
            if 'patJetCorrFactors'+_labelName+postfix in knownModules :
                _newPatJetCorrFactors=getattr(process, 'patJetCorrFactors'+_labelName+postfix)
                _newPatJetCorrFactors.src=jetSource
            else :

                setattr(process, 'patJetCorrFactors'+_labelName+postfix, patJetCorrFactors.clone(src=jetSource))
                _newPatJetCorrFactors=getattr(process, "patJetCorrFactors"+_labelName+postfix)
            _newPatJetCorrFactors.payload=jetCorrections[0]
            _newPatJetCorrFactors.levels=jetCorrections[1]
            ## check whether L1Offset or L1FastJet is part of levels
            error=False
            for x in jetCorrections[1]:
                if x == 'L1Offset' :
                    if not error :
                        _newPatJetCorrFactors.useNPV=True
                        _newPatJetCorrFactors.primaryVertices='offlinePrimaryVertices'
                        ## we set this to True now as a L1 correction type should appear only once
                        ## otherwise levels is miss configured
                        error=True
                    else:
                        raise ValueError, "In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
                        once. Check the list of correction levels you requested to be applied: ", jetCorrections[1]
                if x == 'L1FastJet' :
                    if not error :
                        if _type == "JPT" :
                            raise TypeError, "In addJetCollection: L1FastJet corrections are only supported for PF and Calo jets."
                        ## configure module
                        _newPatJetCorrFactors.useRho=True
                        _newPatJetCorrFactors.rho=cms.InputTag('kt6'+_type+'Jets', 'rho')
                        ## we set this to True now as a L1 correction type should appear only once
                        ## otherwise levels is miss configured
                        error=True
                    else:
                        raise ValueError, "In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
                        once. Check the list of correction levels you requested to be applied: ", jetCorrections[1]
            _newPatJets.jetCorrFactorsSource=cms.VInputTag(cms.InputTag('patJetCorrFactors'+_labelName+postfix))
            ## configure MET(Type1) corrections
            if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '':
                if not jetCorrections[2].lower() == 'type-1' and not jetCorrections[2].lower() == 'type-2':
                    raise valueError, "In addJetCollection: Wrong choice of MET corrections for new jet collection. Possible choices are None (or empty string), Type-1, Type-2 (i.e.\
                    Type-1 and Type-2 corrections applied). This choice is not case sensitive. Your choice was: ", jetCorrections[2]
                if _type == "JPT":
                    raise ValueError, "In addJecCollection: MET(type1) corrections are not supported for JPTJets. Please set the MET-LABEL to \"None\" (as string in quatiation \
                    marks) and use raw tcMET together with JPTJets."
                ## set up jet correctors for MET corrections
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Fastjet
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Offset
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL2Relative
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL3Absolute
                from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFResidual

                setattr(process, jetCorrections[0]+'L1FastJet', ak5PFL1Fastjet.clone(algorithm=jetCorrections[0], srcRho=cms.InputTag('kt6'+_type+'Jets','rho')))
                setattr(process, jetCorrections[0]+'L1Offset', ak5PFL1Offset.clone(algorithm=jetCorrections[0]))
                setattr(process, jetCorrections[0]+'L2Relative', ak5PFL2Relative.clone(algorithm=jetCorrections[0]))
                setattr(process, jetCorrections[0]+'L3Absolute', ak5PFL3Absolute.clone(algorithm=jetCorrections[0]))
                setattr(process, jetCorrections[0]+'L2L3Residual', ak5PFResidual.clone(algorithm=jetCorrections[0]))
                setattr(process, jetCorrections[0]+'CombinedCorrector', cms.ESProducer( 'JetCorrectionESChain', correctors = cms.vstring()))
                for x in jetCorrections[1]:
                    if x != 'L1FastJet' and x != 'L1Offset' and x != 'L2Relative' and x != 'L3Absolute' and x != 'L2L3Residual':
                        raise ValueError, 'In addJetCollection: Unsupported JEC for MET(Type1). Currently supported jet correction levels are L1FastJet, L1Offset, L2Relative, \
                        L3Asolute, L2L3Residual. Requested was:', x
                    else:
                        getattr(process, jetCorrections[0]+'CombinedCorrector').correctors.append(jetCorrections[0]+x)

                ## set up MET(Type1) correction modules
                if _type == 'Calo':
                    from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloJetMETcorr
                    from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloType1CorrectedMet
                    from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloType1p2CorrectedMet
                    setattr(process,jetCorrections[0]+'JetMETcorr'+postfix, caloJetMETcorr.clone(src=jetSource,srcMET = "corMetGlobalMuons",jetCorrections = cms.string(jetCorrections[0]+'CombinedCorrector'+postfix)))
                    setattr(process,jetCorrections[0]+'Type1CorMet'+postfix, caloType1CorrectedMet.clone(src = "corMetGlobalMuons"+postfix,srcType1Corrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+'JetMETcorr'+postfix, 'type1'))))
                    setattr(process,jetCorrections[0]+'Type1p2CorMet'+postfix,caloType1p2CorrectedMet.clone(src = "corMetGlobalMuons"+postfix,srcType1Corrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+'JetMETcorr'+postfix, 'type1')),srcUnclEnergySums = cms.VInputTag(cms.InputTag(jetCorrections[0]+'JetMETcorr'+postfix, 'type2'),cms.InputTag(jetCorrections[0]+'JetMETcorr'+postfix, 'offset'),cms.InputTag('muonCaloMETcorr'+postfix))))

                elif _type == 'PF':
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfCandsNotInJet
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfJetMETcorr
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfCandMETcorr
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfType1CorrectedMet
                    from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfType1p2CorrectedMet
                    setattr(process,jetCorrections[0]+'CandsNotInJet'+postfix,pfCandsNotInJet.clone(topCollection = jetSource))
                    setattr(process,jetCorrections[0]+'CandMETcorr'+postfix, pfCandMETcorr.clone(src = cms.InputTag(jetCorrections[0]+'CandsNotInJet'+postfix)))
                    setattr(process,jetCorrections[0]+'JetMETcorr'+postfix, pfJetMETcorr.clone(src = jetSource))
                    setattr(process,jetCorrections[0]+'Type1CorMet'+postfix, pfType1CorrectedMet.clone(srcType1Corrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+'JetMETcorr'+postfix, 'type1'))))
                    setattr(process,jetCorrections[0]+'Type1p2CorMet'+postfix, pfType1p2CorrectedMet.clone(srcType1Corrections = cms.VInputTag(cms.InputTag(jetCorrections[0]+'JetMETcorr'+postfix, 'type1')),srcUnclEnergySums = cms.VInputTag(cms.InputTag(jetCorrections[0]+'JetMETcorr'+postfix, 'type2'),cms.InputTag(jetCorrections[0]+'JetMETcorr'+postfix, 'offset'),cms.InputTag(jetCorrections[0]+'CandMETcorr'+postfix))))

                ## common configuration for Calo and PF
                if ('L1FastJet' in jetCorrections[1] or 'L1Fastjet' in jetCorrections[1]):
                    getattr(process,jetCorrections[0]+'JetMETcorr'+postfix).offsetCorrLabel = cms.string(jetCorrections[0]+'L1FastJet')
                elif ('L1Offset' in jetCorrections[1]):
                    getattr(process,jetCorrections[0]+'JetMETcorr'+postfix).offsetCorrLabel = cms.string(jetCorrections[0]+'L1Offset')
                else:
                    getattr(process,jetCorrections[0]+'JetMETcorr'+postfix).offsetCorrLabel = cms.string('')

                from PhysicsTools.PatAlgos.producersLayer1.metProducer_cfi import patMETs
                if jetCorrections[2].lower() == 'type-1':
                    setattr(process, 'patMETs'+_labelName+postfix, patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+'Type1CorMet'+postfix), addMuonCorrections = False))
                elif jetCorrections[2].lower() == 'type-1':
                    setattr(process, 'patMETs'+_labelName+postfix, patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+'Type1p2CorMet'+postfix), addMuonCorrections = False))
        else:
            ## switch jetCorrFactors off
            _newPatJets.addJetCorrFactors=False
Example #4
0
def customizePFPatLikeJetsROI(process, type="AK4PFCHS"):

    # set some default collection variables
    pfjets = "hltAK4PFJetsForBTag"
    PFDeepCSVTags = "hltDeepCombinedSecondaryVertexBPFPatROIJetTags"  #original pfDeepCSVJetTags
    PFDeepFlavourTags = "hltPFDeepFlavourROIJetTags"  #original pfDeepFlavourJetTagsSlimmedDeepFlavour
    payload = "AK4PFHLT"  #original AK4PFchs
    hltVertices = "hltVerticesPFFilterForBTag"  #original offlinePrimaryVertices
    rho = "hltFixedGridRhoFastjetAllForBTag"  #original fixedGridRhoFastjetAll

    siPixelClusters = "hltSiPixelClusters"  #original siPixelClusters
    ecalRecHit = "hltEcalRecHit"  #original ecalRecHit
    hbhereco = "hltHbhereco"  #original hbhereco
    hfreco = "hltHfreco"  #original hfreco
    horeco = "hltHoreco"  #original horeco
    rpcRecHits = "hltRpcRecHits"  #original rpcRecHits
    tracks = "hltMergedTracksForBTag"  #original generalTracks

    puppi = "hltPFPuppiROI"  #original puppi
    puppijets = "hltAK4PFPuppiJetsROI"  #original ak4PFJetsCHS
    payloadPuppi = "AK4PFPuppiHLT"  #original AK4PFchs
    PFPuppiDeepFlavourTags = "hltPFPuppiDeepFlavourROIJetTags"  #original pfDeepFlavourJetTagsSlimmedDeepFlavour
    PFPuppiDeepCSVTags = "hltDeepCombinedSecondaryVertexBPFPuppiPatROIJetTags"  #original pfDeepCSVJetTags

    particleFlow = "hltParticleFlowForBTag"  #original particleFlow
    beamSpot = "hltOnlineBeamSpot"  #original offlineBeamSpot

    # clone and modify the HLT BTV sequence/producers to remove the jet pt and eta selections from "jetsForBtag" and replace with pfjets
    process.hltDeepBLifetimePFPatROITagInfos = process.hltDeepBLifetimeTagInfosPFROI.clone(
        jets=cms.InputTag(pfjets))

    process.hltDeepSecondaryVertexPFPatROITagInfos = process.hltDeepSecondaryVertexTagInfosPFROI.clone(
        trackIPTagInfos=cms.InputTag("hltDeepBLifetimePFPatROITagInfos"))

    process.hltDeepCombinedSecondaryVertexBJetPatROITagInfos = process.hltDeepCombinedSecondaryVertexBJetTagsInfosROI.clone(
        svTagInfos=cms.InputTag("hltDeepSecondaryVertexPFPatROITagInfos"))

    process.hltDeepCombinedSecondaryVertexBPFPatROIJetTags = process.hltDeepCombinedSecondaryVertexBJetTagsPFROI.clone(
        src=cms.InputTag("hltDeepCombinedSecondaryVertexBJetPatROITagInfos"))

    process.HLTBtagDeepCSVSequencePFPatROI = cms.Sequence(
        process.hltVerticesPFForBTag + process.hltVerticesPFSelectorForBTag +
        process.hltVerticesPFFilterForBTag +
        process.hltDeepBLifetimePFPatROITagInfos +
        process.hltDeepInclusiveVertexFinderPFROI +
        process.hltDeepInclusiveSecondaryVerticesPFROI +
        process.hltDeepTrackVertexArbitratorPFROI +
        process.hltDeepInclusiveMergedVerticesPFROI +
        process.hltDeepSecondaryVertexPFPatROITagInfos +
        process.hltDeepCombinedSecondaryVertexBJetPatROITagInfos +
        process.hltDeepCombinedSecondaryVertexBPFPatROIJetTags)

    #
    #  same for puppi jets
    #
    process.hltDeepBLifetimePFPuppiPatROITagInfos = process.hltDeepBLifetimeTagInfosPFROI.clone(
        jets=cms.InputTag(puppijets))

    process.hltDeepSecondaryVertexPFPuppiPatROITagInfos = process.hltDeepSecondaryVertexTagInfosPFROI.clone(
        trackIPTagInfos=cms.InputTag("hltDeepBLifetimePFPuppiPatROITagInfos"),
        weights=cms.InputTag(puppi))

    process.hltDeepCombinedSecondaryVertexBPuppiJetPatROITagInfos = process.hltDeepCombinedSecondaryVertexBJetTagsInfosROI.clone(
        svTagInfos=cms.InputTag("hltDeepSecondaryVertexPFPuppiPatROITagInfos"))

    process.hltDeepCombinedSecondaryVertexBPFPuppiPatROIJetTags = process.hltDeepCombinedSecondaryVertexBJetTagsPFROI.clone(
        src=cms.InputTag(
            "hltDeepCombinedSecondaryVertexBPuppiJetPatROITagInfos"))

    process.HLTBtagDeepCSVSequencePFPuppiPatROI = cms.Sequence(
        process.hltVerticesPFForBTag + process.hltVerticesPFSelectorForBTag +
        process.hltVerticesPFFilterForBTag +
        process.hltDeepBLifetimePFPuppiPatROITagInfos +
        process.hltDeepInclusiveVertexFinderPFROI +
        process.hltDeepInclusiveSecondaryVerticesPFROI +
        process.hltDeepTrackVertexArbitratorPFROI +
        process.hltDeepInclusiveMergedVerticesPFROI +
        process.hltDeepSecondaryVertexPFPuppiPatROITagInfos +
        process.hltDeepCombinedSecondaryVertexBPuppiJetPatROITagInfos +
        process.hltDeepCombinedSecondaryVertexBPFPuppiPatROIJetTags)

    # create patJets  for ak4pfchs and all necessary missing inputs
    from PhysicsTools.PatAlgos.producersLayer1.jetProducer_cfi import patJets
    process.hltPatJetsROI = patJets.clone(
        JetFlavourInfoSource=cms.InputTag("hltPatJetFlavourAssociationROI"),
        JetPartonMapSource=cms.InputTag(
            "hltPatJetFlavourAssociationLegacyROI"),
        addJetID=cms.bool(False),
        addTagInfos=cms.bool(True),
        discriminatorSources=cms.VInputTag(
            cms.InputTag(PFDeepCSVTags, "probb"),
            cms.InputTag(PFDeepCSVTags, "probc"),
            cms.InputTag(PFDeepCSVTags, "probudsg"),
            # cms.InputTag(PFDeepCSVTags,"probbb"), # hltDeepCSV: probb = probb +probbb
            cms.InputTag(PFDeepFlavourTags, "probb"),
            cms.InputTag(PFDeepFlavourTags, "probc"),
            cms.InputTag(PFDeepFlavourTags, "probg"),
            cms.InputTag(PFDeepFlavourTags, "problepb"),
            cms.InputTag(PFDeepFlavourTags, "probbb"),
            cms.InputTag(PFDeepFlavourTags, "probuds"),
        ),
        embedGenPartonMatch=cms.bool(False),
        genJetMatch=cms.InputTag("hltPatJetGenJetMatchROI"),
        genPartonMatch=cms.InputTag("hltPatJetPartonMatchROI"),
        jetChargeSource=cms.InputTag("hltPatJetChargeROI"),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag("hltPatJetCorrFactorsROI")),
        jetIDMap=cms.InputTag("hltAk4JetIDROI"),
        jetSource=cms.InputTag(pfjets),
        tagInfoSources=cms.VInputTag(
            cms.InputTag("hltDeepBLifetimePFPatROITagInfos"),
            cms.InputTag("hltDeepCombinedSecondaryVertexBJetPatROITagInfos"),
            cms.InputTag("hltDeepSecondaryVertexPFPatROITagInfos"),
            cms.InputTag("hltPFDeepFlavourROITagInfos"),
        ),
        trackAssociationSource=cms.InputTag(
            "hltAk4JetTracksAssociatorAtVertexPFROI"),
    )

    process.hltPatJetsPuppiROI = patJets.clone(
        JetFlavourInfoSource=cms.InputTag(
            "hltPatJetFlavourAssociationPuppiROI"),
        JetPartonMapSource=cms.InputTag(
            "hltPatJetFlavourAssociationLegacyPuppiROI"),
        addJetID=cms.bool(False),
        addTagInfos=cms.bool(True),
        discriminatorSources=cms.VInputTag(
            cms.InputTag(PFPuppiDeepCSVTags, "probb"),
            cms.InputTag(PFPuppiDeepCSVTags, "probc"),
            cms.InputTag(PFPuppiDeepCSVTags, "probudsg"),
            # cms.InputTag(PFPuppiDeepCSVTags,"probbb"), # hltDeepCSV: probb = probb +probbb
            cms.InputTag(PFPuppiDeepFlavourTags, "probb"),
            cms.InputTag(PFPuppiDeepFlavourTags, "probc"),
            cms.InputTag(PFPuppiDeepFlavourTags, "probg"),
            cms.InputTag(PFPuppiDeepFlavourTags, "problepb"),
            cms.InputTag(PFPuppiDeepFlavourTags, "probbb"),
            cms.InputTag(PFPuppiDeepFlavourTags, "probuds"),
        ),
        embedGenPartonMatch=cms.bool(False),
        genJetMatch=cms.InputTag("hltPatJetGenJetMatchPuppiROI"),
        genPartonMatch=cms.InputTag("hltPatJetPartonMatchPuppiROI"),
        jetChargeSource=cms.InputTag("patJetPuppiChargeROI"),
        jetCorrFactorsSource=cms.VInputTag(
            cms.InputTag("hltPatJetCorrFactorsPuppiROI")),
        jetIDMap=cms.InputTag("hltAk4JetID"),
        jetSource=cms.InputTag(puppijets),
        tagInfoSources=cms.VInputTag(
            cms.InputTag("hltDeepBLifetimePFPuppiPatROITagInfos"),
            cms.InputTag(
                "hltDeepCombinedSecondaryVertexBPuppiJetPatROITagInfos"),
            cms.InputTag("hltDeepSecondaryVertexPFPuppiPatROITagInfos"),
            cms.InputTag("hltPFPuppiDeepFlavourROITagInfos"),
        ),
        trackAssociationSource=cms.InputTag(
            "hltAk4JetTracksAssociatorAtVertexPFPuppiROI"),
    )

    # for patJets
    from PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff import patJetFlavourAssociation, patJetPartons, patJetFlavourAssociationLegacy, patJetPartonAssociationLegacy, patJetPartonsLegacy
    process.hltPatJetFlavourAssociationROI = patJetFlavourAssociation.clone(
        bHadrons=cms.InputTag("hltPatJetPartons", "bHadrons"),
        cHadrons=cms.InputTag("hltPatJetPartons", "cHadrons"),
        jets=cms.InputTag(pfjets),
        leptons=cms.InputTag("hltPatJetPartons", "leptons"),
        partons=cms.InputTag("hltPatJetPartons", "physicsPartons"),
    )

    process.hltPatJetFlavourAssociationPuppiROI = patJetFlavourAssociation.clone(
        bHadrons=cms.InputTag("hltPatJetPartons", "bHadrons"),
        cHadrons=cms.InputTag("hltPatJetPartons", "cHadrons"),
        jets=cms.InputTag(puppijets),
        leptons=cms.InputTag("hltPatJetPartons", "leptons"),
        partons=cms.InputTag("hltPatJetPartons", "physicsPartons"),
        weights=cms.InputTag(puppi))

    process.hltPatJetPartonsROI = patJetPartons.clone()

    process.hltPatJetFlavourAssociationLegacyROI = patJetFlavourAssociationLegacy.clone(
        srcByReference=cms.InputTag("hltPatJetPartonAssociationLegacyROI"))
    process.hltPatJetFlavourAssociationLegacyPuppiROI = patJetFlavourAssociationLegacy.clone(
        srcByReference=cms.InputTag(
            "hltPatJetPartonAssociationLegacyPuppiROI"))

    process.hltPatJetPartonAssociationLegacyROI = patJetPartonAssociationLegacy.clone(
        jets=cms.InputTag(pfjets),
        partons=cms.InputTag("hltPatJetPartonsLegacyROI"))

    process.hltPatJetPartonAssociationLegacyPuppiROI = patJetPartonAssociationLegacy.clone(
        jets=cms.InputTag(puppijets),
        partons=cms.InputTag("hltPatJetPartonsLegacyROI"))

    process.hltPatJetPartonsLegacyROI = patJetPartonsLegacy.clone(
        src=cms.InputTag("genParticles"), )

    from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
    process.hltPatJetGenJetMatchROI = patJetGenJetMatch.clone(
        matched=cms.InputTag("hltSlimmedGenJets"), src=cms.InputTag(pfjets))

    process.hltPatJetGenJetMatchPuppiROI = patJetGenJetMatch.clone(
        matched=cms.InputTag("hltSlimmedGenJets"), src=cms.InputTag(puppijets))

    from PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi import slimmedGenJets
    process.hltSlimmedGenJets = slimmedGenJets.clone(
        packedGenParticles=cms.InputTag("hltPackedGenParticles"),
        src=cms.InputTag("ak4GenJetsNoNu"))

    from PhysicsTools.PatAlgos.slimming.packedGenParticles_cfi import packedGenParticles
    process.hltPackedGenParticles = packedGenParticles.clone(
        inputCollection=cms.InputTag("hltPrunedGenParticlesWithStatusOne"),
        inputOriginal=cms.InputTag("genParticles"),
        map=cms.InputTag("hltPrunedGenParticles"),
    )

    from PhysicsTools.PatAlgos.slimming.genParticles_cff import prunedGenParticlesWithStatusOne
    from PhysicsTools.PatAlgos.slimming.prunedGenParticles_cfi import prunedGenParticles
    process.hltPrunedGenParticlesWithStatusOne = prunedGenParticlesWithStatusOne.clone(
        src=cms.InputTag("genParticles"))

    process.hltPrunedGenParticles = prunedGenParticles.clone(
        src=cms.InputTag("hltPrunedGenParticlesWithStatusOne"))

    from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetPartonMatch
    process.hltPatJetPartonMatchROI = patJetPartonMatch.clone(
        matched=cms.InputTag("hltPrunedGenParticles"),
        src=cms.InputTag(pfjets))

    process.hltPatJetPartonMatchPuppiROI = patJetPartonMatch.clone(
        matched=cms.InputTag("hltPrunedGenParticles"),
        src=cms.InputTag(puppijets))

    from PhysicsTools.PatAlgos.recoLayer0.jetTracksCharge_cff import patJetCharge
    process.hltPatJetChargeROI = patJetCharge.clone(
        src=cms.InputTag("hltAk4JetTracksAssociatorAtVertexPFROI"), )

    process.patJetPuppiChargeROI = patJetCharge.clone(
        src=cms.InputTag("hltAk4JetTracksAssociatorAtVertexPFPuppiROI"), )

    from RecoJets.JetAssociationProducers.ak4JTA_cff import ak4JetTracksAssociatorAtVertexPF
    process.hltAk4JetTracksAssociatorAtVertexPFROI = ak4JetTracksAssociatorAtVertexPF.clone(
        jets=cms.InputTag(pfjets),
        pvSrc=cms.InputTag(hltVertices),
        tracks=cms.InputTag(tracks),
    )

    process.hltAk4JetTracksAssociatorAtVertexPFPuppiROI = ak4JetTracksAssociatorAtVertexPF.clone(
        jets=cms.InputTag(puppijets),
        pvSrc=cms.InputTag(hltVertices),
        tracks=cms.InputTag(tracks),
    )

    from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors
    process.hltPatJetCorrFactorsROI = patJetCorrFactors.clone(
        payload=cms.string(payload),
        primaryVertices=cms.InputTag(hltVertices),
        rho=cms.InputTag(rho),
        src=cms.InputTag(pfjets),
    )

    process.hltPatJetCorrFactorsPuppiROI = patJetCorrFactors.clone(
        payload=cms.string(payloadPuppi),
        primaryVertices=cms.InputTag(hltVertices),
        rho=cms.InputTag(rho),
        src=cms.InputTag(puppijets),
    )

    from RecoJets.JetProducers.ak4JetID_cfi import ak4JetID
    process.hltAk4JetIDROI = ak4JetID.clone(
        ebRecHitsColl=cms.InputTag(ecalRecHit, "EcalRecHitsEB"),
        eeRecHitsColl=cms.InputTag(ecalRecHit, "EcalRecHitsEE"),
        hbheRecHitsColl=cms.InputTag(hbhereco),
        hfRecHitsColl=cms.InputTag(hfreco),
        hoRecHitsColl=cms.InputTag(horeco),
        rpcRecHits=cms.InputTag(rpcRecHits),
        src=cms.InputTag("hltAK4CaloJets"),
    )

    #### TAGGERS
    # run DeepFlavour for HLT
    from RecoBTag.ONNXRuntime.pfDeepFlavourJetTags_cfi import pfDeepFlavourJetTags

    process.hltPFDeepFlavourROIJetTags = pfDeepFlavourJetTags.clone(
        src=cms.InputTag("hltPFDeepFlavourROITagInfos"))

    process.hltPFPuppiDeepFlavourROIJetTags = pfDeepFlavourJetTags.clone(
        src=cms.InputTag("hltPFPuppiDeepFlavourROITagInfos"))

    from RecoBTag.FeatureTools.pfDeepFlavourTagInfos_cfi import pfDeepFlavourTagInfos
    process.hltPFDeepFlavourROITagInfos = pfDeepFlavourTagInfos.clone(
        candidates=cms.InputTag(particleFlow),
        jets=cms.InputTag(pfjets),
        puppi_value_map=cms.InputTag(puppi),
        secondary_vertices=cms.InputTag(
            "hltDeepInclusiveSecondaryVerticesPFROI"),
        shallow_tag_infos=cms.InputTag(
            "hltDeepCombinedSecondaryVertexBJetPatROITagInfos"),
        vertex_associator=cms.InputTag("hltPrimaryVertexAssociationROI",
                                       "original"),
        vertices=cms.InputTag(hltVertices))

    process.hltPFPuppiDeepFlavourROITagInfos = pfDeepFlavourTagInfos.clone(
        candidates=cms.InputTag(particleFlow),
        jets=cms.InputTag(puppijets),
        puppi_value_map=cms.InputTag(puppi),
        secondary_vertices=cms.InputTag(
            "hltDeepInclusiveSecondaryVerticesPFROI"),
        shallow_tag_infos=cms.InputTag(
            "hltDeepCombinedSecondaryVertexBPuppiJetPatROITagInfos"),
        vertex_associator=cms.InputTag("hltPrimaryVertexAssociationPuppiROI",
                                       "original"),
        vertices=cms.InputTag(hltVertices))

    from RecoBTag.SecondaryVertex.candidateCombinedSecondaryVertexV2Computer_cfi import candidateCombinedSecondaryVertexV2Computer
    process.candidateCombinedSecondaryVertexV2Computer = candidateCombinedSecondaryVertexV2Computer.clone(
    )

    from PhysicsTools.PatAlgos.slimming.primaryVertexAssociation_cfi import primaryVertexAssociation
    process.hltPrimaryVertexAssociationROI = primaryVertexAssociation.clone(
        jets=cms.InputTag(pfjets),
        particles=cms.InputTag(particleFlow),
        vertices=cms.InputTag(hltVertices),
    )

    process.hltPrimaryVertexAssociationPuppiROI = primaryVertexAssociation.clone(
        jets=cms.InputTag(puppijets),
        particles=cms.InputTag(particleFlow),
        vertices=cms.InputTag(hltVertices),
    )

    #from RecoParticleFlow.PFProducer.chargedHadronPFTrackIsolation_cfi import chargedHadronPFTrackIsolation
    #process.hltChargedHadronPFTrackIsolationROI = chargedHadronPFTrackIsolation.clone(
    #    src = cms.InputTag(particleFlow)
    #)

    # create the final path
    process.MC_JetsMatchingPathROI = cms.Path(
        process.HLTAK4PFJetsSequenceForBTag *
        process.HLTBtagDeepCSVSequencePFPatROI *
        process.hltPrunedGenParticlesWithStatusOne *
        process.hltPrunedGenParticles * process.hltPackedGenParticles *
        process.hltPatJetPartonMatchROI * process.hltSlimmedGenJets *
        process.hltAk4JetIDROI * process.hltPatJetGenJetMatchROI *
        process.hltPatJetPartonsLegacyROI *
        process.hltPatJetPartonAssociationLegacyROI *
        process.hltPatJetFlavourAssociationLegacyROI *
        process.hltPatJetPartonsROI * process.hltPatJetFlavourAssociationROI *
        process.hltAk4JetTracksAssociatorAtVertexPFROI *
        process.hltPatJetChargeROI * process.hltPatJetCorrFactorsROI *
        process.hltPrimaryVertexAssociationROI
        # *process.hltChargedHadronPFTrackIsolationROI
        * process.hltPFDeepFlavourROITagInfos *
        process.hltPFDeepFlavourROIJetTags * process.hltPatJetsROI)

    process.MC_PuppiJetsMatchingPathROI = cms.Path(
        process.HLTAK4PFJetsSequenceForBTag *
        process.HLTAK4PFPuppiJetsSequenceROI *
        process.HLTBtagDeepCSVSequencePFPuppiPatROI *
        process.hltPrunedGenParticlesWithStatusOne *
        process.hltPrunedGenParticles * process.hltPackedGenParticles *
        process.hltPatJetPartonMatchPuppiROI * process.hltSlimmedGenJets *
        process.hltAk4JetIDROI * process.hltPatJetGenJetMatchPuppiROI *
        process.hltPatJetPartonsLegacyROI *
        process.hltPatJetPartonAssociationLegacyPuppiROI *
        process.hltPatJetFlavourAssociationLegacyPuppiROI *
        process.hltPatJetPartonsROI *
        process.hltPatJetFlavourAssociationPuppiROI *
        process.hltAk4JetTracksAssociatorAtVertexPFPuppiROI *
        process.patJetPuppiChargeROI * process.hltPatJetCorrFactorsPuppiROI *
        process.hltPrimaryVertexAssociationPuppiROI
        # *process.hltChargedHadronPFTrackIsolation
        * process.hltPFPuppiDeepFlavourROITagInfos *
        process.hltPFPuppiDeepFlavourROIJetTags * process.hltPatJetsPuppiROI)

    if process.schedule_():
        process.schedule.extend([process.MC_JetsMatchingPathROI])
        process.schedule.extend([process.MC_PuppiJetsMatchingPathROI])

    return process
def customizePFPatLikeJets(process, runCalo=True, runPuppi=True, runPF=True, roiReplace=False, roiReplaceCalo=False, isData=False):
    # set some default collection variables
    pfjets =                "hltAK4PFJets" if roiReplace==False else "hltAK4PFJetsROIForBTag"                                #original ak4PFJetsCHS
    puppijets =             "hltAK4PFPuppiJets"                                  #original ak4PFJetsCHS
    pfjetsCorrected =       "hltAK4PFJetsCorrected" if roiReplace==False else "hltAK4PFJetsCorrectedROIForBTag"                         #original ak4PFJetsCHS
    calojets =              "hltAK4CaloJets"                                #original ak4CaloJets
    # calojetsCutted =        "hltSelectorCentralJets30L1FastJeta2p5"
    calojetsCutted =        "hltSelectorCentralJets30L1FastJeta"
    PFDeepCSVTags =         "hltDeepCombinedSecondaryVertexBPFPatJetTags"   #original pfDeepCSVJetTags
    PFPuppiDeepCSVTags =    "hltDeepCombinedSecondaryVertexBPFPuppiPatJetTags"   #original pfDeepCSVJetTags
    CaloDeepCSVTags =       "hltDeepCombinedSecondaryVertexCaloPatBJetTags"
    PFDeepFlavourTags =     "hltPFDeepFlavourPatJetTags"                       #original pfDeepFlavourJetTagsSlimmedDeepFlavour
    PFPuppiDeepFlavourTags ="hltPFPuppiDeepFlavourJetTags"                       #original pfDeepFlavourJetTagsSlimmedDeepFlavour
    rho =                   "hltFixedGridRhoFastjetAll" if roiReplace==False else "hltFixedGridRhoFastjetAllROIForBTag"                     #original fixedGridRhoFastjetAll
    hltVertices =           "hltVerticesPFFilter" if roiReplace==False else "hltVerticesPFFilterROIForBTag"                           #original offlinePrimaryVertices
    siPixelClusters =       "hltSiPixelClusters"                            #original siPixelClusters
    ecalRecHit =            "hltEcalRecHit"                                 #original ecalRecHit
    hbhereco =              "hltHbhereco"                                   #original hbhereco
    hfreco =                "hltHfreco"                                     #original hfreco
    horeco =                "hltHoreco"                                     #original horeco
    rpcRecHits =            "hltRpcRecHits"                                 #original rpcRecHits
    # tracks =                "hltMergedTracks"                               #original generalTracks
    tracks =                "hltPFMuonMerging" if roiReplace==False else "hltPFMuonMergingROIForBTag"                               #original generalTracks
    # tracks =                "hltPixelTracks"                               #original generalTracks
    payload =               "AK4PFHLT"                                      #original AK4PFchs
    payloadPuppi =          "AK4PFPuppiHLT"                                      #original AK4PFchs
    particleFlow =          "hltParticleFlow" if roiReplace==False else "hltParticleFlowROIForBTag"                               #original particleFlow
    puppi =                 "hltPFPuppi"                                    #original puppi
    puppiNoLep =            "hltPFPuppiNoLep"                               #original puppiNoLep
    beamSpot =              "hltOnlineBeamSpot"                             #original offlineBeamSpot
    caloTower =             "hltTowerMakerForAll"

    # clone and modify the HLT BTV sequence/producers to remove the jet pt and eta selections from "jetsForBtag" and replace with pfjets
    if roiReplace==False:
        process.hltDeepCombinedSecondaryVertexBPFPatJetTags = process.hltDeepCombinedSecondaryVertexBJetTagsPF.clone(
            src = cms.InputTag( "hltDeepCombinedSecondaryVertexBJetPatTagInfos" )
        )
        process.hltDeepCombinedSecondaryVertexBJetPatTagInfos = process.hltDeepCombinedSecondaryVertexBJetTagsInfos.clone(
            svTagInfos = cms.InputTag( "hltDeepSecondaryVertexPFPatTagInfos" )
        )
        process.hltDeepSecondaryVertexPFPatTagInfos = process.hltDeepSecondaryVertexTagInfosPF.clone(
            trackIPTagInfos = cms.InputTag( "hltDeepBLifetimePFPatTagInfos" )
        )
        process.hltDeepBLifetimePFPatTagInfos = process.hltDeepBLifetimeTagInfosPF.clone(
            jets = cms.InputTag( pfjets)
        )
    else:
        process.hltDeepCombinedSecondaryVertexBPFPatJetTags = process.hltDeepCombinedSecondaryVertexBJetTagsPFROIForBTag.clone(
            src = cms.InputTag( "hltDeepCombinedSecondaryVertexBJetPatTagInfos" )
        )
        process.hltDeepCombinedSecondaryVertexBJetPatTagInfos = process.hltDeepCombinedSecondaryVertexBJetTagsInfosROIForBTag.clone(
            svTagInfos = cms.InputTag( "hltDeepSecondaryVertexPFPatTagInfos" )
        )
        process.hltDeepSecondaryVertexPFPatTagInfos = process.hltDeepSecondaryVertexTagInfosPFROIForBTag.clone(
            trackIPTagInfos = cms.InputTag( "hltDeepBLifetimePFPatTagInfos" )
        )
        process.hltDeepBLifetimePFPatTagInfos = process.hltDeepBLifetimeTagInfosPFROIForBTag.clone(
            jets = cms.InputTag( pfjets)
        )
    if roiReplace==False:
        process.HLTBtagDeepCSVSequencePFPat = cms.Sequence(
            process.hltVerticesPF
            + process.hltVerticesPFSelector
            + process.hltVerticesPFFilter
            + process.hltDeepBLifetimePFPatTagInfos
            + process.hltDeepInclusiveVertexFinderPF
            + process.hltDeepInclusiveSecondaryVerticesPF
            + process.hltDeepTrackVertexArbitratorPF
            + process.hltDeepInclusiveMergedVerticesPF
            + process.hltDeepSecondaryVertexPFPatTagInfos
            + process.hltDeepCombinedSecondaryVertexBJetPatTagInfos
            + process.hltDeepCombinedSecondaryVertexBPFPatJetTags
        )
    else:
        process.HLTBtagDeepCSVSequencePFPat = cms.Sequence(
            process.hltVerticesPFROIForBTag
            + process.hltVerticesPFSelectorROIForBTag
            + process.hltVerticesPFFilterROIForBTag
            + process.hltDeepBLifetimePFPatTagInfos
            + process.hltDeepInclusiveVertexFinderPFROIForBTag
            + process.hltDeepInclusiveSecondaryVerticesPFROIForBTag
            + process.hltDeepTrackVertexArbitratorPFROIForBTag
            + process.hltDeepInclusiveMergedVerticesPFROIForBTag
            + process.hltDeepSecondaryVertexPFPatTagInfos
            + process.hltDeepCombinedSecondaryVertexBJetPatTagInfos
            + process.hltDeepCombinedSecondaryVertexBPFPatJetTags
        )

    # do the same for PuppiJets

    process.hltDeepCombinedSecondaryVertexBPFPuppiPatJetTags = process.hltDeepCombinedSecondaryVertexBJetTagsPF.clone(
        src = cms.InputTag( "hltDeepCombinedSecondaryVertexBPuppiJetPatTagInfos" )
    )
    process.hltDeepCombinedSecondaryVertexBPuppiJetPatTagInfos = process.hltDeepCombinedSecondaryVertexBJetTagsInfos.clone(
        svTagInfos = cms.InputTag( "hltDeepSecondaryVertexPFPuppiPatTagInfos" )
    )
    process.hltDeepSecondaryVertexPFPuppiPatTagInfos = process.hltDeepSecondaryVertexTagInfosPF.clone(
        trackIPTagInfos = cms.InputTag( "hltDeepBLifetimePFPuppiPatTagInfos" ),
        weights = cms.InputTag(puppi)
    )
    process.hltDeepBLifetimePFPuppiPatTagInfos = process.hltDeepBLifetimeTagInfosPF.clone(
        jets = cms.InputTag( puppijets )
    )
    process.HLTBtagDeepCSVSequencePFPuppiPat = cms.Sequence(
        process.hltVerticesPF
        + process.hltVerticesPFSelector
        + process.hltVerticesPFFilter
        + process.hltDeepBLifetimePFPuppiPatTagInfos
        + process.hltDeepInclusiveVertexFinderPF
        + process.hltDeepInclusiveSecondaryVerticesPF
        + process.hltDeepTrackVertexArbitratorPF
        + process.hltDeepInclusiveMergedVerticesPF
        + process.hltDeepSecondaryVertexPFPuppiPatTagInfos
        + process.hltDeepCombinedSecondaryVertexBPuppiJetPatTagInfos
        + process.hltDeepCombinedSecondaryVertexBPFPuppiPatJetTags
    )

    # do the same for caloJets
    # if roiReplace==False:
    if roiReplaceCalo==False:
        process.hltDeepCombinedSecondaryVertexCaloPatBJetTags = process.hltDeepCombinedSecondaryVertexBJetTagsCalo.clone(
            src = cms.InputTag("hltDeepCombinedSecondaryVertexBJetCaloPatTagInfos"),
        )

        process.hltDeepCombinedSecondaryVertexBJetCaloPatTagInfos = process.hltDeepCombinedSecondaryVertexBJetTagsInfosCalo.clone(
            svTagInfos = cms.InputTag("hltInclusiveSecondaryVertexFinderPatTagInfos")
        )
        process.hltInclusiveSecondaryVertexFinderPatTagInfos = process.hltInclusiveSecondaryVertexFinderTagInfos.clone(
            trackIPTagInfos = cms.InputTag("hltImpactParameterPatTagInfos"),
        )

        process.hltImpactParameterPatTagInfos = process.hltImpactParameterTagInfos.clone(
            jetTracks = cms.InputTag("hltFastPixelBLifetimeL3AssociatorPat"),
        )

        # process.hltSelectorCentralJets20L1FastJeta2p5 = process.hltSelectorCentralJets30L1FastJeta.clone(
        #     etaMax = cms.double(2.5),
        #     etaMin = cms.double(-2.5),
        #     src = cms.InputTag("hltSelectorJets20L1FastJet")
        # )

        # process.hltSelectorJets20L1FastJet = process.hltSelectorJets30L1FastJet.clone(
        #     etMin = cms.double(20.0),
        # )

        # process.hltSelector8CentralJetsL1FastJet202p5 = cms.EDFilter("LargestEtCaloJetSelector",
        #     filter = cms.bool(False),
        #     maxNumber = cms.uint32(8),
        #     src = cms.InputTag("hltSelectorCentralJets20L1FastJeta2p5")
        # )

        process.hltFastPixelBLifetimeL3AssociatorPat = process.hltFastPixelBLifetimeL3Associator.clone(
            jets = cms.InputTag(calojetsCutted),
            tracks = cms.InputTag("hltMergedTracksForBTag" if roiReplaceCalo==False else "hltMergedTracksROIForBTag"),
        )

        process.HLTBtagDeepCSVSequenceCaloPat = cms.Sequence(
            # process.hltSelectorJets20L1FastJet
            process.hltSelectorJets30L1FastJet
            # +process.hltSelectorCentralJets20L1FastJeta2p5
            +process.hltSelectorCentralJets30L1FastJeta
            +process.hltSelector8CentralJetsL1FastJet
            # +process.hltSelector8CentralJetsL1FastJet202p5
            +process.HLTTrackReconstructionForBTag
            +process.hltVerticesL3
            # +process.hltVerticesL3Selector
            # +process.hltVerticesL3Filter
            +process.hltFastPixelBLifetimeL3AssociatorPat
            +process.hltImpactParameterPatTagInfos
            +process.hltInclusiveVertexFinder
            +process.hltInclusiveSecondaryVertices
            +process.hltTrackVertexArbitrator
            +process.hltInclusiveMergedVertices
            +process.hltInclusiveSecondaryVertexFinderPatTagInfos
            +process.hltDeepCombinedSecondaryVertexBJetCaloPatTagInfos
            +process.hltDeepCombinedSecondaryVertexCaloPatBJetTags
        )
    else:
        process.hltDeepCombinedSecondaryVertexCaloPatBJetTags = process.hltDeepCombinedSecondaryVertexBJetTagsCaloROIForBTag.clone(
            src = cms.InputTag("hltDeepCombinedSecondaryVertexBJetCaloPatTagInfos"),
        )

        process.hltDeepCombinedSecondaryVertexBJetCaloPatTagInfos = process.hltDeepCombinedSecondaryVertexBJetTagsInfosCaloROIForBTag.clone(
            svTagInfos = cms.InputTag("hltInclusiveSecondaryVertexFinderPatTagInfos")
        )
        process.hltInclusiveSecondaryVertexFinderPatTagInfos = process.hltInclusiveSecondaryVertexFinderTagInfosROIForBTag.clone(
            trackIPTagInfos = cms.InputTag("hltImpactParameterPatTagInfos"),
        )

        process.hltImpactParameterPatTagInfos = process.hltImpactParameterTagInfosROIForBTag.clone(
            jetTracks = cms.InputTag("hltFastPixelBLifetimeL3AssociatorPat"),
        )

        # process.hltSelector8CentralJetsL1FastJet202p5 = cms.EDFilter("LargestEtCaloJetSelector",
        #     filter = cms.bool(False),
        #     maxNumber = cms.uint32(8),
        #     src = cms.InputTag("hltSelectorCentralJets20L1FastJeta2p5")
        # )

        # process.hltSelectorCentralJets20L1FastJeta2p5 = process.hltSelectorCentralJets30L1FastJeta.clone(
        #     etaMax = cms.double(2.5),
        #     etaMin = cms.double(-2.5),
        #     src = cms.InputTag("hltSelectorJets20L1FastJet")
        # )

        # process.hltSelectorJets20L1FastJet = process.hltSelectorJets30L1FastJet.clone(
        #     etMin = cms.double(20.0),
        #     src = cms.InputTag("hltAK4CaloJetsCorrectedIDPassed")
        # )

        process.hltFastPixelBLifetimeL3AssociatorPat = process.hltFastPixelBLifetimeL3AssociatorROIForBTag.clone(
            jets = cms.InputTag(calojetsCutted),
            tracks = cms.InputTag("hltMergedTracksForBTag" if roiReplaceCalo==False else "hltMergedTracksROIForBTag"),
        )

        process.HLTBtagDeepCSVSequenceCaloPat = cms.Sequence(
            # process.hltSelectorJets20L1FastJet
            process.hltSelectorJets30L1FastJet
            # +process.hltSelectorCentralJets20L1FastJeta2p5
            +process.hltSelectorCentralJets30L1FastJeta
            +process.hltSelector8CentralJetsL1FastJet
            # +process.hltSelector8CentralJetsL1FastJet202p5
            +process.HLTTrackReconstructionForBTag
            +process.hltVerticesL3ROIForBTag
            +process.hltVerticesL3SelectorROIForBTag
            +process.hltVerticesL3FilterROIForBTag
            +process.hltFastPixelBLifetimeL3AssociatorPat
            +process.hltImpactParameterPatTagInfos
            +process.hltInclusiveVertexFinderROIForBTag
            +process.hltInclusiveSecondaryVerticesROIForBTag
            +process.hltTrackVertexArbitratorROIForBTag
            +process.hltInclusiveMergedVerticesROIForBTag
            +process.hltInclusiveSecondaryVertexFinderPatTagInfos
            +process.hltDeepCombinedSecondaryVertexBJetCaloPatTagInfos
            +process.hltDeepCombinedSecondaryVertexCaloPatBJetTags
        )


    # create patJets  for ak4pfchs and all necessary missing inputs
    from PhysicsTools.PatAlgos.producersLayer1.jetProducer_cfi import patJets
    process.hltPatJets = patJets.clone(
        JetFlavourInfoSource = cms.InputTag("hltPatJetFlavourAssociation") if not isData else cms.InputTag(""),
        JetPartonMapSource = cms.InputTag("hltPatJetFlavourAssociationLegacy") if not isData else cms.InputTag(""),
        addJetID = cms.bool(False),
        addTagInfos = cms.bool(True),
        addGenJetMatch = cms.bool(True) if not isData else cms.bool(False),
        addGenPartonMatch = cms.bool(True) if not isData else cms.bool(False),
        addJetFlavourInfo = cms.bool(True) if not isData else cms.bool(False),
        addPartonJetMatch = cms.bool(True) if not isData else cms.bool(False),
        discriminatorSources = cms.VInputTag(
            cms.InputTag(PFDeepCSVTags,"probb"),cms.InputTag(PFDeepCSVTags,"probc"),cms.InputTag(PFDeepCSVTags,"probudsg"),
            # cms.InputTag(PFDeepCSVTags,"probbb"), # hltDeepCSV: probb = probb +probbb
            cms.InputTag(PFDeepFlavourTags,"probb"), cms.InputTag(PFDeepFlavourTags,"probc"), cms.InputTag(PFDeepFlavourTags,"probg"),
            cms.InputTag(PFDeepFlavourTags,"problepb"), cms.InputTag(PFDeepFlavourTags,"probbb"), cms.InputTag(PFDeepFlavourTags,"probuds"),
        ),
        embedGenPartonMatch = cms.bool(False),
        genJetMatch = cms.InputTag("hltPatJetGenJetMatch") if not isData else cms.InputTag(""),
        genPartonMatch = cms.InputTag("hltPatJetPartonMatch") if not isData else cms.InputTag(""),
        jetChargeSource = cms.InputTag("hltPatJetCharge"),
        jetCorrFactorsSource = cms.VInputTag(cms.InputTag("hltPatJetCorrFactors")),
        jetIDMap = cms.InputTag("hltAk4JetID"),
        jetSource = cms.InputTag(pfjets),
        tagInfoSources = cms.VInputTag(
            cms.InputTag("hltDeepBLifetimePFPatTagInfos"),
            cms.InputTag("hltDeepCombinedSecondaryVertexBJetPatTagInfos"),
            cms.InputTag("hltDeepSecondaryVertexPFPatTagInfos"),
            cms.InputTag("hltPFDeepFlavourPatTagInfos"),
        ),
        trackAssociationSource = cms.InputTag("hltAk4JetTracksAssociatorAtVertexPF"),
    )
    process.hltPatJetsPuppi = patJets.clone(
        JetFlavourInfoSource = cms.InputTag("hltPatJetFlavourAssociationPuppi") if not isData else cms.InputTag(""),
        JetPartonMapSource = cms.InputTag("hltPatJetFlavourAssociationLegacyPuppi") if not isData else cms.InputTag(""),
        addJetID = cms.bool(False),
        addTagInfos = cms.bool(True),
        addGenJetMatch = cms.bool(True) if not isData else cms.bool(False),
        addGenPartonMatch = cms.bool(True) if not isData else cms.bool(False),
        addJetFlavourInfo = cms.bool(True) if not isData else cms.bool(False),
        addPartonJetMatch = cms.bool(True) if not isData else cms.bool(False),
        discriminatorSources = cms.VInputTag(
            cms.InputTag(PFPuppiDeepCSVTags,"probb"),cms.InputTag(PFPuppiDeepCSVTags,"probc"),cms.InputTag(PFPuppiDeepCSVTags,"probudsg"),
            # cms.InputTag(PFPuppiDeepCSVTags,"probbb"), # hltDeepCSV: probb = probb +probbb
            cms.InputTag(PFPuppiDeepFlavourTags,"probb"), cms.InputTag(PFPuppiDeepFlavourTags,"probc"), cms.InputTag(PFPuppiDeepFlavourTags,"probg"),
            cms.InputTag(PFPuppiDeepFlavourTags,"problepb"), cms.InputTag(PFPuppiDeepFlavourTags,"probbb"), cms.InputTag(PFPuppiDeepFlavourTags,"probuds"),
        ),
        embedGenPartonMatch = cms.bool(False),
        genJetMatch = cms.InputTag("hltPatJetGenJetMatchPuppi") if not isData else cms.InputTag(""),
        genPartonMatch = cms.InputTag("hltPatJetPartonMatchPuppi") if not isData else cms.InputTag(""),
        jetChargeSource = cms.InputTag("patJetPuppiCharge"),
        jetCorrFactorsSource = cms.VInputTag(cms.InputTag("hltPatJetCorrFactorsPuppi")),
        jetIDMap = cms.InputTag("hltAk4JetID"),
        jetSource = cms.InputTag(puppijets),
        tagInfoSources = cms.VInputTag(
            cms.InputTag("hltDeepBLifetimePFPuppiPatTagInfos"),
            cms.InputTag("hltDeepCombinedSecondaryVertexBPuppiJetPatTagInfos"),
            cms.InputTag("hltDeepSecondaryVertexPFPuppiPatTagInfos"),
            cms.InputTag("hltPFPuppiDeepFlavourTagInfos"),
        ),
        trackAssociationSource = cms.InputTag("hltAk4JetTracksAssociatorAtVertexPFPuppi"),
    )
    process.hltPatJetsCalo = patJets.clone(
        JetFlavourInfoSource = cms.InputTag("hltPatJetFlavourAssociationCalo") if not isData else cms.InputTag(""),
        JetPartonMapSource = cms.InputTag("hltPatJetFlavourAssociationLegacyCalo") if not isData else cms.InputTag(""),
        addAssociatedTracks = cms.bool(True),
        addBTagInfo = cms.bool(True),
        addDiscriminators = cms.bool(True),
        addEfficiencies = cms.bool(False),
        embedCaloTowers = cms.bool(True),
        addGenJetMatch = cms.bool(True) if not isData else cms.bool(False),
        addGenPartonMatch = cms.bool(True) if not isData else cms.bool(False),
        addJetCharge = cms.bool(False),
        addJetCorrFactors = cms.bool(False),
        addJetFlavourInfo = cms.bool(True) if not isData else cms.bool(False),
        addPartonJetMatch = cms.bool(False),
        addJetID = cms.bool(False),
        addTagInfos = cms.bool(True),
        discriminatorSources = cms.VInputTag(
            cms.InputTag(CaloDeepCSVTags,"probb"),cms.InputTag(CaloDeepCSVTags,"probc"),cms.InputTag(CaloDeepCSVTags,"probudsg"),
            # # cms.InputTag(PFDeepCSVTags,"probbb"), # hltDeepCSV: probb = probb +probbb
        ),
        embedGenPartonMatch = cms.bool(False),
        genJetMatch = cms.InputTag("hltPatJetGenJetMatchCalo") if not isData else cms.InputTag(""),
        genPartonMatch = cms.InputTag("hltPatJetPartonMatchCalo") if not isData else cms.InputTag(""),
        # jetChargeSource = cms.InputTag("hltPatJetCharge"),
        # jetCorrFactorsSource = cms.VInputTag(cms.InputTag("hltPatJetCorrFactors")),
        # jetIDMap = cms.InputTag("hltAk4JetID"),
        jetSource = cms.InputTag(calojetsCutted),
        tagInfoSources = cms.VInputTag(
            cms.InputTag("hltImpactParameterPatTagInfos"),
            cms.InputTag("hltDeepCombinedSecondaryVertexBJetCaloPatTagInfos"),
            cms.InputTag("hltInclusiveSecondaryVertexFinderPatTagInfos"),
            # cms.InputTag("hltImpactParameterTagInfos"),
            # cms.InputTag("hltInclusiveSecondaryVertexFinderTagInfos"),
            # cms.InputTag("hltDeepCombinedSecondaryVertexBJetTagsInfoCalo"),
            # cms.InputTag("hltDeepSecondaryVertexPFPuppiPatTagInfos"),
        ),
        trackAssociationSource = cms.InputTag("hltAk4JetTracksAssociatorAtVertexCalo"),
    )

    # for patJets
    from PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff import patJetFlavourAssociation,patJetPartons,patJetFlavourAssociationLegacy,patJetPartonAssociationLegacy,patJetPartonsLegacy
    process.hltPatJetFlavourAssociation = patJetFlavourAssociation.clone(
        bHadrons = cms.InputTag("hltPatJetPartons","bHadrons"),
        cHadrons = cms.InputTag("hltPatJetPartons","cHadrons"),
        jets = cms.InputTag(pfjets),
        leptons = cms.InputTag("hltPatJetPartons","leptons"),
        partons = cms.InputTag("hltPatJetPartons","physicsPartons"),
    )
    process.hltPatJetFlavourAssociationPuppi = patJetFlavourAssociation.clone(
        bHadrons = cms.InputTag("hltPatJetPartons","bHadrons"),
        cHadrons = cms.InputTag("hltPatJetPartons","cHadrons"),
        jets = cms.InputTag(puppijets),
        leptons = cms.InputTag("hltPatJetPartons","leptons"),
        partons = cms.InputTag("hltPatJetPartons","physicsPartons"),
        weights = cms.InputTag(puppi)
    )
    process.hltPatJetFlavourAssociationCalo = patJetFlavourAssociation.clone(
        bHadrons = cms.InputTag("hltPatJetPartons","bHadrons"),
        cHadrons = cms.InputTag("hltPatJetPartons","cHadrons"),
        jets = cms.InputTag(calojetsCutted),
        leptons = cms.InputTag("hltPatJetPartons","leptons"),
        partons = cms.InputTag("hltPatJetPartons","physicsPartons"),
    )
    process.hltPatJetPartons = patJetPartons.clone()

    process.hltPatJetFlavourAssociationLegacy = patJetFlavourAssociationLegacy.clone(
        srcByReference = cms.InputTag("hltPatJetPartonAssociationLegacy")
    )
    process.hltPatJetFlavourAssociationLegacyCalo = patJetFlavourAssociationLegacy.clone(
        srcByReference = cms.InputTag("hltPatJetPartonAssociationLegacyCalo")
    )
    process.hltPatJetFlavourAssociationLegacyPuppi = patJetFlavourAssociationLegacy.clone(
        srcByReference = cms.InputTag("hltPatJetPartonAssociationLegacyPuppi")
    )

    process.hltPatJetPartonAssociationLegacy = patJetPartonAssociationLegacy.clone(
        jets = cms.InputTag(pfjets),
        partons = cms.InputTag("hltPatJetPartonsLegacy")
    )
    process.hltPatJetPartonAssociationLegacyPuppi = patJetPartonAssociationLegacy.clone(
        jets = cms.InputTag(puppijets),
        partons = cms.InputTag("hltPatJetPartonsLegacy")
    )
    process.hltPatJetPartonAssociationLegacyCalo = patJetPartonAssociationLegacy.clone(
        jets = cms.InputTag(calojetsCutted),
        partons = cms.InputTag("hltPatJetPartonsLegacy")
    )

    process.hltPatJetPartonsLegacy = patJetPartonsLegacy.clone(
        src = cms.InputTag("genParticles"),
    )

    from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetGenJetMatch
    process.hltPatJetGenJetMatch = patJetGenJetMatch.clone(
        matched = cms.InputTag("hltSlimmedGenJets"),
        src = cms.InputTag(pfjets)
    )
    process.hltPatJetGenJetMatchPuppi = patJetGenJetMatch.clone(
        matched = cms.InputTag("hltSlimmedGenJets"),
        src = cms.InputTag(puppijets)
    )
    process.hltPatJetGenJetMatchCalo = patJetGenJetMatch.clone(
        matched = cms.InputTag("hltSlimmedGenJets"),
        src = cms.InputTag(calojetsCutted)
    )

    from PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi import slimmedGenJets
    process.hltSlimmedGenJets = slimmedGenJets.clone(
        packedGenParticles = cms.InputTag("hltPackedGenParticles"),
        src = cms.InputTag("ak4GenJetsNoNu")
    )

    from PhysicsTools.PatAlgos.slimming.packedGenParticles_cfi import packedGenParticles
    process.hltPackedGenParticles = packedGenParticles.clone(
        inputCollection = cms.InputTag("hltPrunedGenParticlesWithStatusOne"),
        inputOriginal = cms.InputTag("genParticles"),
        map = cms.InputTag("hltPrunedGenParticles"),
    )

    from PhysicsTools.PatAlgos.slimming.genParticles_cff import prunedGenParticlesWithStatusOne
    from PhysicsTools.PatAlgos.slimming.prunedGenParticles_cfi import prunedGenParticles
    process.hltPrunedGenParticlesWithStatusOne = prunedGenParticlesWithStatusOne.clone(
        src = cms.InputTag("genParticles")
    )

    process.hltPrunedGenParticles = prunedGenParticles.clone(
        src = cms.InputTag("hltPrunedGenParticlesWithStatusOne")
    )

    from PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi import patJetPartonMatch
    process.hltPatJetPartonMatch = patJetPartonMatch.clone(
        matched = cms.InputTag("hltPrunedGenParticles"),
        src = cms.InputTag(pfjets)
    )
    process.hltPatJetPartonMatchPuppi = patJetPartonMatch.clone(
        matched = cms.InputTag("hltPrunedGenParticles"),
        src = cms.InputTag(puppijets)
    )
    process.hltPatJetPartonMatchCalo = patJetPartonMatch.clone(
        matched = cms.InputTag("hltPrunedGenParticles"),
        src = cms.InputTag(calojetsCutted)
    )

    from PhysicsTools.PatAlgos.recoLayer0.jetTracksCharge_cff import patJetCharge
    process.hltPatJetCharge = patJetCharge.clone(
        src = cms.InputTag("hltAk4JetTracksAssociatorAtVertexPF"),
    )
    process.patJetPuppiCharge = patJetCharge.clone(
        src = cms.InputTag("hltAk4JetTracksAssociatorAtVertexPFPuppi"),
    )

    from RecoJets.JetAssociationProducers.ak4JTA_cff import ak4JetTracksAssociatorAtVertexPF
    process.hltAk4JetTracksAssociatorAtVertexPF = ak4JetTracksAssociatorAtVertexPF.clone(
        jets = cms.InputTag(pfjets),
        pvSrc = cms.InputTag(hltVertices),
        tracks = cms.InputTag(tracks),
    )
    process.hltAk4JetTracksAssociatorAtVertexPFPuppi = ak4JetTracksAssociatorAtVertexPF.clone(
        jets = cms.InputTag(puppijets),
        pvSrc = cms.InputTag(hltVertices),
        tracks = cms.InputTag(tracks),
    )
    process.hltAk4JetTracksAssociatorAtVertexCalo = ak4JetTracksAssociatorAtVertexPF.clone(
        jets = cms.InputTag(calojetsCutted),
        # pvSrc = cms.InputTag(hltVertices),
        # pvSrc = cms.InputTag("hltVerticesL3" if roiReplace==False else "hltVerticesL3ROIForBTag"),
        pvSrc = cms.InputTag("hltVerticesL3" if roiReplaceCalo==False else "hltVerticesL3FilterROIForBTag"),
        # pvSrc = cms.InputTag("hltVerticesL3Filter" if roiReplaceCalo==False else "hltVerticesL3FilterROIForBTag"),
        # tracks = cms.InputTag(tracks),
        tracks = cms.InputTag("hltMergedTracksForBTag" if roiReplaceCalo==False else "hltMergedTracksROIForBTag"),
    )

    from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi  import patJetCorrFactors
    process.hltPatJetCorrFactors = patJetCorrFactors.clone(
        payload = cms.string(payload),
        primaryVertices = cms.InputTag(hltVertices),
        rho = cms.InputTag(rho),
        src = cms.InputTag(pfjets),
    )
    process.hltPatJetCorrFactorsPuppi = patJetCorrFactors.clone(
        payload = cms.string(payloadPuppi),
        primaryVertices = cms.InputTag(hltVertices),
        rho = cms.InputTag(rho),
        src = cms.InputTag(puppijets),
    )

    from RecoJets.JetProducers.ak4JetID_cfi import ak4JetID
    process.hltAk4JetID = ak4JetID.clone(
        ebRecHitsColl = cms.InputTag(ecalRecHit,"EcalRecHitsEB"),
        eeRecHitsColl = cms.InputTag(ecalRecHit,"EcalRecHitsEE"),
        hbheRecHitsColl = cms.InputTag(hbhereco),
        hfRecHitsColl = cms.InputTag(hfreco),
        hoRecHitsColl = cms.InputTag(horeco),
        rpcRecHits = cms.InputTag(rpcRecHits),
        src = cms.InputTag(calojets),
    )



    #### TAGGERS
    # run DeepFlavour for HLT
    # from RecoBTag.ONNXRuntime.pfDeepFlavourJetTags_cfi import pfDeepFlavourJetTags
    # process.hltPFDeepFlavourJetTags = pfDeepFlavourJetTags.clone(
    #     src = cms.InputTag("hltPFDeepFlavourTagInfos")
    # )
    # process.hltPFPuppiDeepFlavourJetTags = pfDeepFlavourJetTags.clone(
    #     src = cms.InputTag("hltPFPuppiDeepFlavourTagInfos")
    # )
    # from RecoBTag.FeatureTools.pfDeepFlavourTagInfos_cfi import pfDeepFlavourTagInfos
    # process.hltPFDeepFlavourTagInfos = pfDeepFlavourTagInfos.clone(
    #     candidates = cms.InputTag(particleFlow),
    #     jets = cms.InputTag(pfjets),
    #     fallback_puppi_weight = cms.bool(True),
    #     puppi_value_map = cms.InputTag(""),
    #     secondary_vertices = cms.InputTag("hltDeepInclusiveSecondaryVerticesPF"),
    #     shallow_tag_infos = cms.InputTag("hltDeepCombinedSecondaryVertexBJetPatTagInfos"),
    #     vertex_associator = cms.InputTag("hltPrimaryVertexAssociation","original"),
    #     vertices = cms.InputTag(hltVertices)
    # )
    # process.hltPFPuppiDeepFlavourTagInfos = pfDeepFlavourTagInfos.clone(
    #     candidates = cms.InputTag(particleFlow),
    #     jets = cms.InputTag(puppijets),
    #     puppi_value_map = cms.InputTag(puppi),
    #     secondary_vertices = cms.InputTag("hltDeepInclusiveSecondaryVerticesPF"),
    #     shallow_tag_infos = cms.InputTag("hltDeepCombinedSecondaryVertexBPuppiJetPatTagInfos"),
    #     vertex_associator = cms.InputTag("hltPrimaryVertexAssociationPuppi","original"),
    #     vertices = cms.InputTag(hltVertices)
    # )
    if roiReplace==False:
        process.hltPrimaryVertexAssociationPat = process.hltPrimaryVertexAssociation.clone(
            jets = cms.InputTag(pfjets),
        )

        process.hltPFDeepFlavourPatTagInfos = process.hltPFDeepFlavourTagInfos.clone(
            jets = cms.InputTag(pfjets),
            shallow_tag_infos = cms.InputTag("hltDeepCombinedSecondaryVertexBJetPatTagInfos"),
            vertex_associator = cms.InputTag("hltPrimaryVertexAssociationPat","original"),
        )

        process.hltPFDeepFlavourPatJetTags = process.hltPFDeepFlavourJetTags.clone(
            src = cms.InputTag("hltPFDeepFlavourPatTagInfos")
        )
    else:
        process.hltPrimaryVertexAssociationPat = process.hltPrimaryVertexAssociationROIForBTag.clone(
            jets = cms.InputTag(pfjets),
        )

        process.hltPFDeepFlavourPatTagInfos = process.hltPFDeepFlavourTagInfosROIForBTag.clone(
            jets = cms.InputTag(pfjets),
            shallow_tag_infos = cms.InputTag("hltDeepCombinedSecondaryVertexBJetPatTagInfos"),
            vertex_associator = cms.InputTag("hltPrimaryVertexAssociationPat","original"),
        )

        process.hltPFDeepFlavourPatJetTags = process.hltPFDeepFlavourJetTagsROIForBTag.clone(
            src = cms.InputTag("hltPFDeepFlavourPatTagInfos")
        )

    from RecoBTag.SecondaryVertex.candidateCombinedSecondaryVertexV2Computer_cfi import candidateCombinedSecondaryVertexV2Computer
    process.candidateCombinedSecondaryVertexV2Computer = candidateCombinedSecondaryVertexV2Computer.clone()

    # from PhysicsTools.PatAlgos.slimming.primaryVertexAssociation_cfi import primaryVertexAssociation
    # process.hltPrimaryVertexAssociation = primaryVertexAssociation.clone(
    #     jets = cms.InputTag(pfjets),
    #     particles = cms.InputTag(particleFlow),
    #     vertices = cms.InputTag(hltVertices),
    # )
    # process.hltPrimaryVertexAssociationPuppi = primaryVertexAssociation.clone(
    #     jets = cms.InputTag(puppijets),
    #     particles = cms.InputTag(particleFlow),
    #     vertices = cms.InputTag(hltVertices),
    # )
    if roiReplace==False:
        process.HLTBtagDeepJetSequencePFPat = cms.Sequence(
            process.hltVerticesPF
            + process.hltVerticesPFSelector
            + process.hltVerticesPFFilter
            + process.hltDeepBLifetimePFPatTagInfos
            + process.hltDeepInclusiveVertexFinderPF
            + process.hltDeepInclusiveSecondaryVerticesPF
            + process.hltDeepTrackVertexArbitratorPF
            + process.hltDeepInclusiveMergedVerticesPF
            + process.hltDeepSecondaryVertexPFPatTagInfos
            + process.hltDeepCombinedSecondaryVertexBJetPatTagInfos
            + process.hltPrimaryVertexAssociationPat
            + process.hltPFDeepFlavourPatTagInfos
            + process.hltPFDeepFlavourPatJetTags
        )
    else:
        process.HLTBtagDeepJetSequencePFPat = cms.Sequence(
            process.hltVerticesPFROIForBTag
            + process.hltVerticesPFSelectorROIForBTag
            + process.hltVerticesPFFilterROIForBTag
            + process.hltDeepBLifetimePFPatTagInfos
            + process.hltDeepInclusiveVertexFinderPFROIForBTag
            + process.hltDeepInclusiveSecondaryVerticesPFROIForBTag
            + process.hltDeepTrackVertexArbitratorPFROIForBTag
            + process.hltDeepInclusiveMergedVerticesPFROIForBTag
            + process.hltDeepSecondaryVertexPFPatTagInfos
            + process.hltDeepCombinedSecondaryVertexBJetPatTagInfos
            + process.hltPrimaryVertexAssociationPat
            + process.hltPFDeepFlavourPatTagInfos
            + process.hltPFDeepFlavourPatJetTags
        )





    # create the final path
    if runPF:
        if roiReplace==False:
            process.MC_JetsMatchingPath = cms.Path(
                process.HLTBeginSequence
                +process.HLTAK4PFJetsSequence
                +process.HLTBtagDeepCSVSequencePFPat
                +process.hltPrunedGenParticlesWithStatusOne
                +process.hltPrunedGenParticles
                +process.hltPackedGenParticles
                +process.hltPatJetPartonMatch
                +process.hltSlimmedGenJets
                +process.hltAk4JetID
                +process.hltPatJetGenJetMatch
                +process.hltPatJetPartonsLegacy
                +process.hltPatJetPartonAssociationLegacy
                +process.hltPatJetFlavourAssociationLegacy
                +process.hltPatJetPartons
                +process.hltPatJetFlavourAssociation
                +process.hltAk4JetTracksAssociatorAtVertexPF
                +process.hltPatJetCharge
                +process.hltPatJetCorrFactors

                # +process.hltPrimaryVertexAssociationPat
                # +process.hltPFDeepFlavourPatTagInfos
                # +process.hltPFDeepFlavourPatJetTags
                + process.HLTBtagDeepJetSequencePFPat

                +process.hltPatJets
                +process.HLTEndSequence
            )
            if isData:
                process.MC_JetsMatchingPath = cms.Path(
                    process.HLTBeginSequence
                    +process.HLTAK4PFJetsSequence
                    +process.HLTBtagDeepCSVSequencePFPat
                    # +process.hltPrunedGenParticlesWithStatusOne
                    # +process.hltPrunedGenParticles
                    # +process.hltPackedGenParticles
                    # +process.hltPatJetPartonMatch
                    # +process.hltSlimmedGenJets
                    +process.hltAk4JetID
                    # +process.hltPatJetGenJetMatch
                    # +process.hltPatJetPartonsLegacy
                    # +process.hltPatJetPartonAssociationLegacy
                    # +process.hltPatJetFlavourAssociationLegacy
                    # +process.hltPatJetPartons
                    # +process.hltPatJetFlavourAssociation
                    +process.hltAk4JetTracksAssociatorAtVertexPF
                    +process.hltPatJetCharge
                    +process.hltPatJetCorrFactors

                    # +process.hltPrimaryVertexAssociationPat
                    # +process.hltPFDeepFlavourPatTagInfos
                    # +process.hltPFDeepFlavourPatJetTags
                    + process.HLTBtagDeepJetSequencePFPat

                    +process.hltPatJets
                    +process.HLTEndSequence
                )
        else:
            process.MC_JetsMatchingPath = cms.Path(
                process.HLTBeginSequence
                +process.HLTAK4PFJetsSequenceROIForBTag
                +process.HLTBtagDeepCSVSequencePFPat
                +process.hltPrunedGenParticlesWithStatusOne
                +process.hltPrunedGenParticles
                +process.hltPackedGenParticles
                +process.hltPatJetPartonMatch
                +process.hltSlimmedGenJets
                +process.hltAk4JetID
                +process.hltPatJetGenJetMatch
                +process.hltPatJetPartonsLegacy
                +process.hltPatJetPartonAssociationLegacy
                +process.hltPatJetFlavourAssociationLegacy
                +process.hltPatJetPartons
                +process.hltPatJetFlavourAssociation
                +process.hltAk4JetTracksAssociatorAtVertexPF
                +process.hltPatJetCharge
                +process.hltPatJetCorrFactors

                # +process.hltPrimaryVertexAssociationPat
                # +process.hltPFDeepFlavourPatTagInfos
                # +process.hltPFDeepFlavourPatJetTags
                + process.HLTBtagDeepJetSequencePFPat

                +process.hltPatJets
                +process.HLTEndSequence
            )
            if isData:
                process.MC_JetsMatchingPath = cms.Path(
                    process.HLTBeginSequence
                    +process.HLTAK4PFJetsSequenceROIForBTag
                    +process.HLTBtagDeepCSVSequencePFPat
                    # +process.hltPrunedGenParticlesWithStatusOne
                    # +process.hltPrunedGenParticles
                    # +process.hltPackedGenParticles
                    # +process.hltPatJetPartonMatch
                    # +process.hltSlimmedGenJets
                    +process.hltAk4JetID
                    # +process.hltPatJetGenJetMatch
                    # +process.hltPatJetPartonsLegacy
                    # +process.hltPatJetPartonAssociationLegacy
                    # +process.hltPatJetFlavourAssociationLegacy
                    # +process.hltPatJetPartons
                    # +process.hltPatJetFlavourAssociation
                    +process.hltAk4JetTracksAssociatorAtVertexPF
                    +process.hltPatJetCharge
                    +process.hltPatJetCorrFactors

                    # +process.hltPrimaryVertexAssociationPat
                    # +process.hltPFDeepFlavourPatTagInfos
                    # +process.hltPFDeepFlavourPatJetTags
                    + process.HLTBtagDeepJetSequencePFPat

                    +process.hltPatJets
                    +process.HLTEndSequence
                )

    if runPuppi:
        process.MC_PuppiJetsMatchingPath = cms.Path(
            process.HLTBeginSequence
            +process.HLTAK4PFPuppiJetsSequence
            +process.HLTBtagDeepCSVSequencePFPuppiPat
            +process.hltPrunedGenParticlesWithStatusOne
            +process.hltPrunedGenParticles
            +process.hltPackedGenParticles
            +process.hltPatJetPartonMatchPuppi
            +process.hltSlimmedGenJets
            +process.hltAk4JetID
            +process.hltPatJetGenJetMatchPuppi
            +process.hltPatJetPartonsLegacy
            +process.hltPatJetPartonAssociationLegacyPuppi
            +process.hltPatJetFlavourAssociationLegacyPuppi
            +process.hltPatJetPartons
            +process.hltPatJetFlavourAssociationPuppi
            +process.hltAk4JetTracksAssociatorAtVertexPFPuppi
            +process.patJetPuppiCharge
            +process.hltPatJetCorrFactorsPuppi

            +process.hltPrimaryVertexAssociationPuppi
            +process.hltPFPuppiDeepFlavourTagInfos
            +process.hltPFPuppiDeepFlavourJetTags

            +process.hltPatJetsPuppi
            +process.HLTEndSequence
        )

    if runCalo:
        process.MC_CaloJetsMatchingPath = cms.Path(
            process.HLTBeginSequence
            # +process.HLTAK4CaloJetsCorrectionSequence
            +process.HLTAK4CaloJetsSequence
            +process.HLTBtagDeepCSVSequenceCaloPat
            +process.hltPrunedGenParticlesWithStatusOne
            +process.hltPrunedGenParticles
            +process.hltPackedGenParticles
            +process.hltPatJetPartonMatchCalo
            +process.hltSlimmedGenJets
            +process.hltPatJetGenJetMatchCalo
            +process.hltPatJetPartonsLegacy
            +process.hltPatJetPartons
            +process.hltPatJetPartonAssociationLegacyCalo
            +process.hltPatJetFlavourAssociationLegacyCalo
            +process.hltPatJetFlavourAssociationCalo
            +process.hltAk4JetTracksAssociatorAtVertexCalo

            +process.hltPatJetsCalo
            +process.HLTEndSequence
        )
        if isData:
            process.MC_CaloJetsMatchingPath = cms.Path(
                process.HLTBeginSequence
                # +process.HLTAK4CaloJetsCorrectionSequence
                +process.HLTAK4CaloJetsSequence
                +process.HLTBtagDeepCSVSequenceCaloPat
                # +process.hltPrunedGenParticlesWithStatusOne
                # +process.hltPrunedGenParticles
                # +process.hltPackedGenParticles
                # +process.hltPatJetPartonMatchCalo
                # +process.hltSlimmedGenJets
                # +process.hltPatJetGenJetMatchCalo
                # +process.hltPatJetPartonsLegacy
                # +process.hltPatJetPartons
                # +process.hltPatJetPartonAssociationLegacyCalo
                # +process.hltPatJetFlavourAssociationLegacyCalo
                # +process.hltPatJetFlavourAssociationCalo
                +process.hltAk4JetTracksAssociatorAtVertexCalo

                +process.hltPatJetsCalo
                +process.HLTEndSequence
            )

    if process.schedule_():
        if runPF: process.schedule.extend([process.MC_JetsMatchingPath])
        if runCalo: process.schedule.extend([process.MC_CaloJetsMatchingPath])
        if runPuppi: process.schedule.extend([process.MC_PuppiJetsMatchingPath])

    return process