Exemplo n.º 1
0
def setupAK15(process, runOnMC=False, path=None):
    # recluster Puppi jets
    bTagDiscriminators = [
        'pfJetProbabilityBJetTags',
        'pfCombinedInclusiveSecondaryVertexV2BJetTags',
    ]
    subjetBTagDiscriminators = [
        'pfJetProbabilityBJetTags',
        'pfCombinedInclusiveSecondaryVertexV2BJetTags',
    ]
    JETCorrLevels = ['L2Relative', 'L3Absolute', 'L2L3Residual']

    from PhysicsTools.NanoTuples.jetToolbox_cff import jetToolbox
    jetToolbox(process,
               'ak15',
               'dummySeqAK15',
               'out',
               associateTask=False,
               PUMethod='Puppi',
               JETCorrPayload='AK8PFPuppi',
               JETCorrLevels=JETCorrLevels,
               Cut='pt > 160.0 && abs(rapidity()) < 2.4',
               miniAOD=True,
               runOnMC=runOnMC,
               addNsub=True,
               maxTau=3,
               addSoftDrop=True,
               addSoftDropSubjets=True,
               subJETCorrPayload='AK4PFPuppi',
               subJETCorrLevels=JETCorrLevels,
               bTagDiscriminators=bTagDiscriminators,
               subjetBTagDiscriminators=subjetBTagDiscriminators)

    if runOnMC:
        process.ak15GenJetsNoNu.jetPtMin = 100
        process.ak15GenJetsNoNuSoftDrop.jetPtMin = 100

    from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
    from RecoBTag.MXNet.pfDeepBoostedJet_cff import _pfMassDecorrelatedDeepBoostedJetTagsProbs as pfMassDecorrelatedDeepBoostedJetTagsProbs

    updateJetCollection(
        process,
        jetSource=cms.InputTag('packedPatJetsAK15PFPuppiSoftDrop'),
        rParam=1.5,
        jetCorrections=('AK8PFPuppi', cms.vstring(['L2Relative',
                                                   'L3Absolute']), 'None'),
        btagDiscriminators=bTagDiscriminators +
        pfMassDecorrelatedDeepBoostedJetTagsProbs,
        postfix='AK15WithPuppiDaughters',
    )

    # configure DeepAK15
    from PhysicsTools.NanoTuples.pfDeepBoostedJetPreprocessParamsAK15_cfi import pfDeepBoostedJetPreprocessParams as params
    process.pfDeepBoostedJetTagInfosAK15WithPuppiDaughters.jet_radius = 1.5
    process.pfMassDecorrelatedDeepBoostedJetTagsAK15WithPuppiDaughters.preprocessParams = params
    process.pfMassDecorrelatedDeepBoostedJetTagsAK15WithPuppiDaughters.model_path = 'PhysicsTools/NanoTuples/data/DeepBoostedJet/ak15/decorrelated/resnet-symbol.json'
    process.pfMassDecorrelatedDeepBoostedJetTagsAK15WithPuppiDaughters.param_path = 'PhysicsTools/NanoTuples/data/DeepBoostedJet/ak15/decorrelated/resnet.params'

    # src
    srcJets = cms.InputTag('selectedUpdatedPatJetsAK15WithPuppiDaughters')

    # jetID
    process.looseJetIdAK15Puppi = cms.EDProducer(
        "PatJetIDValueMapProducer",
        filterParams=cms.PSet(
            version=cms.string('WINTER16'),
            quality=cms.string('LOOSE'),
        ),
        src=srcJets)

    process.tightJetIdAK15Puppi = cms.EDProducer(
        "PatJetIDValueMapProducer",
        filterParams=cms.PSet(
            version=cms.string('WINTER17'),
            quality=cms.string('TIGHT'),
        ),
        src=srcJets)
    run2_miniAOD_80XLegacy.toModify(process.tightJetIdAK15Puppi.filterParams,
                                    version="WINTER16")

    process.tightJetIdLepVetoAK15Puppi = cms.EDProducer(
        "PatJetIDValueMapProducer",
        filterParams=cms.PSet(
            version=cms.string('WINTER17'),
            quality=cms.string('TIGHTLEPVETO'),
        ),
        src=srcJets)

    process.ak15WithUserData = cms.EDProducer(
        "PATJetUserDataEmbedder",
        src=srcJets,
        userFloats=cms.PSet(),
        userInts=cms.PSet(
            tightId=cms.InputTag("tightJetIdAK15Puppi"),
            tightIdLepVeto=cms.InputTag("tightJetIdLepVetoAK15Puppi"),
        ),
    )
    run2_miniAOD_80XLegacy.toModify(
        process.ak15WithUserData.userInts,
        looseId=cms.InputTag("looseJetIdAK15Puppi"),
        tightIdLepVeto=None,
    )

    process.ak15Table = cms.EDProducer(
        "SimpleCandidateFlatTableProducer",
        src=cms.InputTag("ak15WithUserData"),
        name=cms.string("AK15Puppi"),
        cut=cms.string(""),
        doc=cms.string("ak15 puppi jets"),
        singleton=cms.bool(False),  # the number of entries is variable
        extension=cms.bool(False),  # this is the main table for the jets
        variables=cms.PSet(
            P4Vars,
            jetId=Var(
                "userInt('tightId')*2+4*userInt('tightIdLepVeto')",
                int,
                doc=
                "Jet ID flags bit1 is loose (always false in 2017 since it does not exist), bit2 is tight, bit3 is tightLepVeto"
            ),
            area=Var("jetArea()",
                     float,
                     doc="jet catchment area, for JECs",
                     precision=10),
            rawFactor=Var("1.-jecFactor('Uncorrected')",
                          float,
                          doc="1 - Factor to get back to raw pT",
                          precision=6),
            tau1=Var("userFloat('NjettinessAK15Puppi:tau1')",
                     float,
                     doc="Nsubjettiness (1 axis)",
                     precision=10),
            tau2=Var("userFloat('NjettinessAK15Puppi:tau2')",
                     float,
                     doc="Nsubjettiness (2 axis)",
                     precision=10),
            tau3=Var("userFloat('NjettinessAK15Puppi:tau3')",
                     float,
                     doc="Nsubjettiness (3 axis)",
                     precision=10),
            msoftdrop=Var("groomedMass()",
                          float,
                          doc="Corrected soft drop mass with PUPPI",
                          precision=10),
            btagCSVV2=Var(
                "bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",
                float,
                doc=
                "pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",
                precision=10),
            btagJP=Var(
                "bDiscriminator('pfJetProbabilityBJetTags')",
                float,
                doc="pfJetProbabilityBJetTags b-tag discriminator (aka JP)",
                precision=10),
            nBHadrons=Var("jetFlavourInfo().getbHadrons().size()",
                          int,
                          doc="number of b-hadrons"),
            nCHadrons=Var("jetFlavourInfo().getcHadrons().size()",
                          int,
                          doc="number of c-hadrons"),
            subJetIdx1=Var(
                "?nSubjetCollections()>0 && subjets().size()>0?subjets()[0].key():-1",
                int,
                doc="index of first subjet"),
            subJetIdx2=Var(
                "?nSubjetCollections()>0 && subjets().size()>1?subjets()[1].key():-1",
                int,
                doc="index of second subjet"),
        ))
    run2_miniAOD_80XLegacy.toModify(
        process.ak15Table.variables,
        jetId=Var("userInt('tightId')*2+userInt('looseId')",
                  int,
                  doc="Jet ID flags bit1 is loose, bit2 is tight"))
    process.ak15Table.variables.pt.precision = 10

    # add Mass Decorrelated taggers
    for prob in pfMassDecorrelatedDeepBoostedJetTagsProbs:
        name = prob.split(':')[1]
        setattr(
            process.ak15Table.variables, name,
            Var("bDiscriminator('%s')" % prob, float, doc=prob, precision=-1))

    process.ak15SubJetTable = cms.EDProducer(
        "SimpleCandidateFlatTableProducer",
        src=cms.InputTag("selectedPatJetsAK15PFPuppiSoftDropPacked",
                         "SubJets"),
        cut=cms.string(""),
        name=cms.string("AK15PuppiSubJet"),
        doc=cms.string("ak15 puppi subjets"),
        singleton=cms.bool(False),  # the number of entries is variable
        extension=cms.bool(False),  # this is the main table for the jets
        variables=cms.PSet(
            P4Vars,
            area=Var("jetArea()",
                     float,
                     doc="jet catchment area, for JECs",
                     precision=10),
            rawFactor=Var("1.-jecFactor('Uncorrected')",
                          float,
                          doc="1 - Factor to get back to raw pT",
                          precision=6),
            btagCSVV2=Var(
                "bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",
                float,
                doc=
                " pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",
                precision=10),
            btagJP=Var(
                "bDiscriminator('pfJetProbabilityBJetTags')",
                float,
                doc="pfJetProbabilityBJetTags b-tag discriminator (aka JP)",
                precision=10),
            nBHadrons=Var("jetFlavourInfo().getbHadrons().size()",
                          int,
                          doc="number of b-hadrons"),
            nCHadrons=Var("jetFlavourInfo().getcHadrons().size()",
                          int,
                          doc="number of c-hadrons"),
        ))
    process.ak15SubJetTable.variables.pt.precision = 10

    process.ak15Task = cms.Task(
        process.tightJetIdAK15Puppi,
        process.tightJetIdLepVetoAK15Puppi,
        process.ak15WithUserData,
        process.ak15Table,
        process.ak15SubJetTable,
    )

    if runOnMC:
        process.genJetAK15Table = cms.EDProducer(
            "SimpleCandidateFlatTableProducer",
            src=cms.InputTag("ak15GenJetsNoNu"),
            cut=cms.string("pt > 100."),
            name=cms.string("GenJetAK15"),
            doc=cms.string("AK15 GenJets made with visible genparticles"),
            singleton=cms.bool(False),  # the number of entries is variable
            extension=cms.bool(
                False),  # this is the main table for the genjets
            variables=cms.PSet(P4Vars, ))
        process.genJetAK15Table.variables.pt.precision = 10

        process.genSubJetAK15Table = cms.EDProducer(
            "SimpleCandidateFlatTableProducer",
            src=cms.InputTag("ak15GenJetsNoNuSoftDrop", "SubJets"),
            cut=cms.string(""),
            name=cms.string("GenSubJetAK15"),
            doc=cms.string("AK15 Gen-SubJets made with visible genparticles"),
            singleton=cms.bool(False),  # the number of entries is variable
            extension=cms.bool(
                False),  # this is the main table for the genjets
            variables=cms.PSet(P4Vars, ))
        process.genSubJetAK15Table.variables.pt.precision = 10

        process.ak15Task.add(process.genJetAK15Table)
        process.ak15Task.add(process.genSubJetAK15Table)

    _ak15Task_80X = process.ak15Task.copy()
    _ak15Task_80X.replace(process.tightJetIdLepVetoAK15Puppi,
                          process.looseJetIdAK15Puppi)
    run2_miniAOD_80XLegacy.toReplaceWith(process.ak15Task, _ak15Task_80X)

    if path is None:
        process.schedule.associate(process.ak15Task)
    else:
        getattr(process, path).associate(process.ak15Task)
Exemplo n.º 2
0
def setupCustomizedAK8(process, runOnMC=False, path=None):
    # recluster Puppi jets
    bTagDiscriminators = [
        'pfCombinedInclusiveSecondaryVertexV2BJetTags',
        'pfBoostedDoubleSecondaryVertexAK8BJetTags',
    ]
    subjetBTagDiscriminators = [
        'pfCombinedInclusiveSecondaryVertexV2BJetTags',
        'pfDeepCSVJetTags:probb',
        'pfDeepCSVJetTags:probbb',
    ]
    JETCorrLevels = ['L2Relative', 'L3Absolute', 'L2L3Residual']

    from PhysicsTools.NanoTuples.jetToolbox_cff import jetToolbox
    jetToolbox(process,
               'ak8',
               'dummySeqAK8',
               'noOutput',
               PUMethod='Puppi',
               JETCorrPayload='AK8PFPuppi',
               JETCorrLevels=JETCorrLevels,
               Cut='pt > 170.0 && abs(rapidity()) < 2.4',
               runOnMC=runOnMC,
               addNsub=True,
               maxTau=3,
               addSoftDrop=True,
               addSoftDropSubjets=True,
               subJETCorrPayload='AK4PFPuppi',
               subJETCorrLevels=JETCorrLevels,
               bTagDiscriminators=bTagDiscriminators,
               subjetBTagDiscriminators=subjetBTagDiscriminators)

    if runOnMC:
        process.ak8GenJetsNoNu.jetPtMin = 100
        process.ak8GenJetsNoNuSoftDrop.jetPtMin = 100

    from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
    from RecoBTag.ONNXRuntime.pfDeepBoostedJet_cff import _pfDeepBoostedJetTagsProbs, _pfMassDecorrelatedDeepBoostedJetTagsProbs
    from RecoBTag.MXNet.pfParticleNet_cff import _pfParticleNetJetTagsProbs, _pfMassDecorrelatedParticleNetJetTagsProbs
    updateJetCollection(
        process,
        jetSource=cms.InputTag('packedPatJetsAK8PFPuppiSoftDrop'),
        rParam=0.8,
        jetCorrections=('AK8PFPuppi', cms.vstring(JETCorrLevels), 'None'),
        btagDiscriminators=bTagDiscriminators + _pfDeepBoostedJetTagsProbs +
        _pfMassDecorrelatedDeepBoostedJetTagsProbs +
        _pfParticleNetJetTagsProbs +
        _pfMassDecorrelatedParticleNetJetTagsProbs,
        postfix='AK8WithPuppiDaughters',
    )

    # src
    srcJets = cms.InputTag('selectedUpdatedPatJetsAK8WithPuppiDaughters')

    # jetID
    process.looseJetIdCustomAK8 = cms.EDProducer(
        "PatJetIDValueMapProducer",
        filterParams=cms.PSet(
            version=cms.string('WINTER16'),
            quality=cms.string('LOOSE'),
        ),
        src=srcJets)

    process.tightJetIdCustomAK8 = cms.EDProducer(
        "PatJetIDValueMapProducer",
        filterParams=cms.PSet(
            version=cms.string('SUMMER18PUPPI'),
            quality=cms.string('TIGHT'),
        ),
        src=srcJets)

    process.tightJetIdLepVetoCustomAK8 = cms.EDProducer(
        "PatJetIDValueMapProducer",
        filterParams=cms.PSet(
            version=cms.string('SUMMER18PUPPI'),
            quality=cms.string('TIGHTLEPVETO'),
        ),
        src=srcJets)

    run2_jme_2016.toModify(process.tightJetIdCustomAK8.filterParams,
                           version="WINTER16")
    run2_jme_2016.toModify(process.tightJetIdLepVetoCustomAK8.filterParams,
                           version="WINTER16")
    run2_jme_2017.toModify(process.tightJetIdCustomAK8.filterParams,
                           version="WINTER17PUPPI")
    run2_jme_2017.toModify(process.tightJetIdLepVetoCustomAK8.filterParams,
                           version="WINTER17PUPPI")

    process.customAK8WithUserData = cms.EDProducer(
        "PATJetUserDataEmbedder",
        src=srcJets,
        userFloats=cms.PSet(),
        userInts=cms.PSet(
            tightId=cms.InputTag("tightJetIdCustomAK8"),
            tightIdLepVeto=cms.InputTag("tightJetIdLepVetoCustomAK8"),
        ),
    )

    run2_jme_2016.toModify(
        process.customAK8WithUserData.userInts,
        looseId=cms.InputTag("looseJetIdCustomAK8"),
        tightIdLepVeto=None,
    )

    process.customAK8Table = cms.EDProducer(
        "SimpleCandidateFlatTableProducer",
        src=cms.InputTag("customAK8WithUserData"),
        name=cms.string("CustomAK8Puppi"),
        cut=cms.string(""),
        doc=cms.string("reclustered ak8 puppi jets"),
        singleton=cms.bool(False),  # the number of entries is variable
        extension=cms.bool(False),  # this is the main table for the jets
        variables=cms.PSet(
            P4Vars,
            jetId=Var(
                "userInt('tightId')*2+4*userInt('tightIdLepVeto')",
                int,
                doc=
                "Jet ID flags bit1 is loose (always false in 2017 since it does not exist), bit2 is tight, bit3 is tightLepVeto"
            ),
            area=Var("jetArea()",
                     float,
                     doc="jet catchment area, for JECs",
                     precision=10),
            rawFactor=Var("1.-jecFactor('Uncorrected')",
                          float,
                          doc="1 - Factor to get back to raw pT",
                          precision=6),
            nPFConstituents=Var("numberOfDaughters()",
                                int,
                                doc="Number of PF candidate constituents"),
            tau1=Var("userFloat('NjettinessAK8Puppi:tau1')",
                     float,
                     doc="Nsubjettiness (1 axis)",
                     precision=10),
            tau2=Var("userFloat('NjettinessAK8Puppi:tau2')",
                     float,
                     doc="Nsubjettiness (2 axis)",
                     precision=10),
            tau3=Var("userFloat('NjettinessAK8Puppi:tau3')",
                     float,
                     doc="Nsubjettiness (3 axis)",
                     precision=10),
            msoftdrop=Var("groomedMass()",
                          float,
                          doc="Corrected soft drop mass with PUPPI",
                          precision=10),
            btagCSVV2=Var(
                "bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",
                float,
                doc=
                " pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",
                precision=10),
            btagHbb=Var(
                "bDiscriminator('pfBoostedDoubleSecondaryVertexAK8BJetTags')",
                float,
                doc="Higgs to BB tagger discriminator",
                precision=10),
            nBHadrons=Var("jetFlavourInfo().getbHadrons().size()",
                          int,
                          doc="number of b-hadrons"),
            nCHadrons=Var("jetFlavourInfo().getcHadrons().size()",
                          int,
                          doc="number of c-hadrons"),
            subJetIdx1=Var(
                "?nSubjetCollections()>0 && subjets().size()>0?subjets()[0].key():-1",
                int,
                doc="index of first subjet"),
            subJetIdx2=Var(
                "?nSubjetCollections()>0 && subjets().size()>1?subjets()[1].key():-1",
                int,
                doc="index of second subjet"),
        ))
    run2_jme_2016.toModify(
        process.customAK8Table.variables,
        jetId=Var("userInt('tightId')*2+userInt('looseId')",
                  int,
                  doc="Jet ID flags bit1 is loose, bit2 is tight"))
    process.customAK8Table.variables.pt.precision = 10

    # add DeepAK8 scores: nominal
    for prob in _pfDeepBoostedJetTagsProbs:
        name = 'DeepAK8_' + prob.split(':')[1]
        setattr(
            process.customAK8Table.variables, name,
            Var("bDiscriminator('%s')" % prob, float, doc=prob, precision=-1))

    # add DeepAK8 scores: mass decorrelated
    for prob in _pfMassDecorrelatedDeepBoostedJetTagsProbs:
        name = 'DeepAK8MD_' + prob.split(':')[1]
        setattr(
            process.customAK8Table.variables, name,
            Var("bDiscriminator('%s')" % prob, float, doc=prob, precision=-1))

    # add ParticleNet nominal taggers
    for prob in _pfParticleNetJetTagsProbs:
        name = 'ParticleNet_' + prob.split(':')[1]
        setattr(
            process.customAK8Table.variables, name,
            Var("bDiscriminator('%s')" % prob, float, doc=prob, precision=-1))

    # add ParticleNet mass-decorelated taggers
    for prob in _pfMassDecorrelatedParticleNetJetTagsProbs:
        name = 'ParticleNetMD_' + prob.split(':')[1]
        setattr(
            process.customAK8Table.variables, name,
            Var("bDiscriminator('%s')" % prob, float, doc=prob, precision=-1))

    process.customAK8SubJetTable = cms.EDProducer(
        "SimpleCandidateFlatTableProducer",
        src=cms.InputTag("selectedPatJetsAK8PFPuppiSoftDropPacked", "SubJets"),
        cut=cms.string(""),
        name=cms.string("CustomAK8PuppiSubJet"),
        doc=cms.string("reculstered ak8 puppi subjets"),
        singleton=cms.bool(False),  # the number of entries is variable
        extension=cms.bool(False),  # this is the main table for the jets
        variables=cms.PSet(
            P4Vars,
            area=Var("jetArea()",
                     float,
                     doc="jet catchment area, for JECs",
                     precision=10),
            rawFactor=Var("1.-jecFactor('Uncorrected')",
                          float,
                          doc="1 - Factor to get back to raw pT",
                          precision=6),
            btagDeepB=Var(
                "bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')",
                float,
                doc="DeepCSV b+bb tag discriminator",
                precision=10),
            btagCSVV2=Var(
                "bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",
                float,
                doc=
                " pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",
                precision=10),
            nBHadrons=Var("jetFlavourInfo().getbHadrons().size()",
                          int,
                          doc="number of b-hadrons"),
            nCHadrons=Var("jetFlavourInfo().getcHadrons().size()",
                          int,
                          doc="number of c-hadrons"),
        ))
    process.customAK8SubJetTable.variables.pt.precision = 10

    process.customizedAK8Task = cms.Task(process.tightJetIdCustomAK8,
                                         process.tightJetIdLepVetoCustomAK8,
                                         process.customAK8WithUserData,
                                         process.customAK8Table,
                                         process.customAK8SubJetTable)

    if runOnMC:
        process.customGenJetAK8Table = cms.EDProducer(
            "SimpleCandidateFlatTableProducer",
            src=cms.InputTag("ak8GenJetsNoNu"),
            cut=cms.string("pt > 100."),
            name=cms.string("CustomGenJetAK8"),
            doc=cms.string("AK8 GenJets made with visible genparticles"),
            singleton=cms.bool(False),  # the number of entries is variable
            extension=cms.bool(
                False),  # this is the main table for the genjets
            variables=cms.PSet(P4Vars, ))
        process.customGenJetAK8Table.variables.pt.precision = 10

        process.customGenSubJetAK8Table = cms.EDProducer(
            "SimpleCandidateFlatTableProducer",
            src=cms.InputTag("ak8GenJetsNoNuSoftDrop", "SubJets"),
            cut=cms.string(""),
            name=cms.string("CustomGenSubJetAK8"),
            doc=cms.string("AK8 Gen-SubJets made with visible genparticles"),
            singleton=cms.bool(False),  # the number of entries is variable
            extension=cms.bool(
                False),  # this is the main table for the genjets
            variables=cms.PSet(P4Vars, ))
        process.customGenSubJetAK8Table.variables.pt.precision = 10

        process.customizedAK8Task.add(process.customGenJetAK8Table)
        process.customizedAK8Task.add(process.customGenSubJetAK8Table)

    _customizedAK8Task_80X = process.customizedAK8Task.copy()
    _customizedAK8Task_80X.replace(process.tightJetIdLepVetoCustomAK8,
                                   process.looseJetIdCustomAK8)
    run2_jme_2016.toReplaceWith(process.customizedAK8Task,
                                _customizedAK8Task_80X)

    if path is None:
        process.schedule.associate(process.customizedAK8Task)
    else:
        getattr(process, path).associate(process.customizedAK8Task)