Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-04 01:26:10

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 from PhysicsTools.NanoAOD.nano_eras_cff import *
0004 from PhysicsTools.NanoAOD.common_cff import *
0005 
0006 from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import *
0007 # Note: Safe to always add 'L2L3Residual' as MC contains dummy L2L3Residual corrections (always set to 1)
0008 #      (cf. https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CMSSW_7_6_4_and_above )
0009 jetCorrFactorsAK8 = patJetCorrFactors.clone(src='slimmedJetsAK8',
0010     levels = cms.vstring('L1FastJet',
0011         'L2Relative',
0012         'L3Absolute',
0013         'L2L3Residual'),
0014     payload = cms.string('AK8PFPuppi'),
0015     primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
0016 )
0017 run2_miniAOD_80XLegacy.toModify(jetCorrFactorsAK8, payload = cms.string('AK8PFchs')) # ak8PFJetsCHS in 2016 80X miniAOD
0018 
0019 from  PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import *
0020 updatedJetsAK8 = updatedPatJets.clone(
0021     addBTagInfo=False,
0022     jetSource='slimmedJetsAK8',
0023     jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactorsAK8") ),
0024 )
0025 
0026 #
0027 # JetID
0028 #
0029 looseJetIdAK8 = cms.EDProducer("PatJetIDValueMapProducer",
0030   filterParams=cms.PSet(
0031     version = cms.string('WINTER16'),
0032     quality = cms.string('LOOSE'),
0033   ),
0034   src = cms.InputTag("updatedJetsAK8")
0035 )
0036 tightJetIdAK8 = cms.EDProducer("PatJetIDValueMapProducer",
0037     filterParams=cms.PSet(
0038         version = cms.string('RUN2ULPUPPI'),
0039         quality = cms.string('TIGHT'),
0040     ),
0041     src = cms.InputTag("updatedJetsAK8")
0042 )
0043 tightJetIdLepVetoAK8 = cms.EDProducer("PatJetIDValueMapProducer",
0044     filterParams=cms.PSet(
0045         version = cms.string('RUN2ULPUPPI'),
0046         quality = cms.string('TIGHTLEPVETO'),
0047     ),
0048     src = cms.InputTag("updatedJetsAK8")
0049 )
0050 
0051 run2_jme_2016.toModify( tightJetIdAK8.filterParams, version = "RUN2UL16PUPPI" )
0052 run2_jme_2016.toModify( tightJetIdLepVetoAK8.filterParams, version = "RUN2UL16PUPPI" )
0053 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0054     modifier.toModify( tightJetIdAK8.filterParams, version = "WINTER16" )
0055     modifier.toModify( tightJetIdLepVetoAK8.filterParams, version = "WINTER16" )
0056 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
0057     modifier.toModify( tightJetIdAK8.filterParams, version = "WINTER17PUPPI" )
0058     modifier.toModify( tightJetIdLepVetoAK8.filterParams, version = "WINTER17PUPPI" )
0059 run2_nanoAOD_102Xv1.toModify( tightJetIdAK8.filterParams, version = "SUMMER18PUPPI" )
0060 run2_nanoAOD_102Xv1.toModify( tightJetIdLepVetoAK8.filterParams, version = "SUMMER18PUPPI" )
0061 
0062 updatedJetsAK8WithUserData = cms.EDProducer("PATJetUserDataEmbedder",
0063     src = cms.InputTag("updatedJetsAK8"),
0064     userFloats = cms.PSet(),
0065     userInts = cms.PSet(
0066         tightId = cms.InputTag("tightJetIdAK8"),
0067         tightIdLepVeto = cms.InputTag("tightJetIdLepVetoAK8"),
0068     ),
0069 )
0070 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0071     modifier.toModify(updatedJetsAK8WithUserData.userInts,
0072         looseId = cms.InputTag("looseJetIdAK8"),
0073     )
0074 
0075 
0076 finalJetsAK8 = cms.EDFilter("PATJetRefSelector",
0077     src = cms.InputTag("updatedJetsAK8WithUserData"),
0078     cut = cms.string("pt > 170")
0079 )
0080 
0081 
0082 lepInAK8JetVars = cms.EDProducer("LepInJetProducer",
0083     src = cms.InputTag("updatedJetsAK8WithUserData"),
0084     srcEle = cms.InputTag("finalElectrons"),
0085     srcMu = cms.InputTag("finalMuons")
0086 )
0087 
0088 fatJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
0089     src = cms.InputTag("finalJetsAK8"),
0090     cut = cms.string(" pt > 170"), #probably already applied in miniaod
0091     name = cms.string("FatJet"),
0092     doc  = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"),
0093     singleton = cms.bool(False), # the number of entries is variable
0094     extension = cms.bool(False), # this is the main table for the jets
0095     variables = cms.PSet(P4Vars,
0096         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"),
0097         area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
0098         rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
0099         tau1 = Var("userFloat('NjettinessAK8Puppi:tau1')",float, doc="Nsubjettiness (1 axis)",precision=10),
0100         tau2 = Var("userFloat('NjettinessAK8Puppi:tau2')",float, doc="Nsubjettiness (2 axis)",precision=10),
0101         tau3 = Var("userFloat('NjettinessAK8Puppi:tau3')",float, doc="Nsubjettiness (3 axis)",precision=10),
0102         tau4 = Var("userFloat('NjettinessAK8Puppi:tau4')",float, doc="Nsubjettiness (4 axis)",precision=10),
0103         n2b1 = Var("?hasUserFloat('nb1AK8PuppiSoftDrop:ecfN2')?userFloat('nb1AK8PuppiSoftDrop:ecfN2'):-99999.", float, doc="N2 with beta=1 (for jets with raw pT>250 GeV)", precision=10),
0104         n3b1 = Var("?hasUserFloat('nb1AK8PuppiSoftDrop:ecfN3')?userFloat('nb1AK8PuppiSoftDrop:ecfN3'):-99999.", float, doc="N3 with beta=1 (for jets with raw pT>250 GeV)", precision=10),
0105         msoftdrop = Var("groomedMass('SoftDropPuppi')",float, doc="Corrected soft drop mass with PUPPI",precision=10),
0106         btagDeepB = Var("?(bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'))>=0?bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb'):-1",float,doc="DeepCSV b+bb tag discriminator",precision=10),
0107         btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
0108         btagHbb = Var("bDiscriminator('pfBoostedDoubleSecondaryVertexAK8BJetTags')",float,doc="Higgs to BB tagger discriminator",precision=10),
0109         btagDDBvLV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleBvLV2JetTags:probHbb')",float,doc="DeepDoubleX V2(mass-decorrelated) discriminator for H(Z)->bb vs QCD",precision=10),
0110         btagDDCvLV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleCvLV2JetTags:probHcc')",float,doc="DeepDoubleX V2 (mass-decorrelated) discriminator for H(Z)->cc vs QCD",precision=10),
0111         btagDDCvBV2 = Var("bDiscriminator('pfMassIndependentDeepDoubleCvBV2JetTags:probHcc')",float,doc="DeepDoubleX V2 (mass-decorrelated) discriminator for H(Z)->cc vs H(Z)->bb",precision=10),
0112         deepTag_TvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:TvsQCD')",float,doc="DeepBoostedJet tagger top vs QCD discriminator",precision=10),
0113         deepTag_WvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:WvsQCD')",float,doc="DeepBoostedJet tagger W vs QCD discriminator",precision=10),
0114         deepTag_ZvsQCD = Var("bDiscriminator('pfDeepBoostedDiscriminatorsJetTags:ZvsQCD')",float,doc="DeepBoostedJet tagger Z vs QCD discriminator",precision=10),
0115         deepTag_H = Var("bDiscriminator('pfDeepBoostedJetTags:probHbb')+bDiscriminator('pfDeepBoostedJetTags:probHcc')+bDiscriminator('pfDeepBoostedJetTags:probHqqqq')",float,doc="DeepBoostedJet tagger H(bb,cc,4q) sum",precision=10),
0116         deepTag_QCD = Var("bDiscriminator('pfDeepBoostedJetTags:probQCDbb')+bDiscriminator('pfDeepBoostedJetTags:probQCDcc')+bDiscriminator('pfDeepBoostedJetTags:probQCDb')+bDiscriminator('pfDeepBoostedJetTags:probQCDc')+bDiscriminator('pfDeepBoostedJetTags:probQCDothers')",float,doc="DeepBoostedJet tagger QCD(bb,cc,b,c,others) sum",precision=10),
0117         deepTag_QCDothers = Var("bDiscriminator('pfDeepBoostedJetTags:probQCDothers')",float,doc="DeepBoostedJet tagger QCDothers value",precision=10),
0118         deepTagMD_TvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:TvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger top vs QCD discriminator",precision=10),
0119         deepTagMD_WvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:WvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger W vs QCD discriminator",precision=10),
0120         deepTagMD_ZvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z vs QCD discriminator",precision=10),
0121         deepTagMD_ZHbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H->bb vs QCD discriminator",precision=10),
0122         deepTagMD_ZbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z->bb vs QCD discriminator",precision=10),
0123         deepTagMD_HbbvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:HbbvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger H->bb vs QCD discriminator",precision=10),
0124         deepTagMD_ZHccvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ZHccvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H->cc vs QCD discriminator",precision=10),
0125         deepTagMD_H4qvsQCD = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:H4qvsQCD')",float,doc="Mass-decorrelated DeepBoostedJet tagger H->4q vs QCD discriminator",precision=10),
0126         deepTagMD_bbvsLight = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:bbvsLight')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H/gluon->bb vs light flavour discriminator",precision=10),
0127         deepTagMD_ccvsLight = Var("bDiscriminator('pfMassDecorrelatedDeepBoostedDiscriminatorsJetTags:ccvsLight')",float,doc="Mass-decorrelated DeepBoostedJet tagger Z/H/gluon->cc vs light flavour discriminator",precision=10),
0128         particleNet_TvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:TvsQCD')",float,doc="ParticleNet tagger top vs QCD discriminator",precision=10),
0129         particleNet_WvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:WvsQCD')",float,doc="ParticleNet tagger W vs QCD discriminator",precision=10),
0130         particleNet_ZvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:ZvsQCD')",float,doc="ParticleNet tagger Z vs QCD discriminator",precision=10),
0131         particleNet_HbbvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:HbbvsQCD')",float,doc="ParticleNet tagger H(->bb) vs QCD discriminator",precision=10),
0132         particleNet_HccvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:HccvsQCD')",float,doc="ParticleNet tagger H(->cc) vs QCD discriminator",precision=10),
0133         particleNet_H4qvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:H4qvsQCD')",float,doc="ParticleNet tagger H(->VV->qqqq) vs QCD discriminator",precision=10),
0134         particleNet_QCD = Var("bDiscriminator('pfParticleNetJetTags:probQCDbb')+bDiscriminator('pfParticleNetJetTags:probQCDcc')+bDiscriminator('pfParticleNetJetTags:probQCDb')+bDiscriminator('pfParticleNetJetTags:probQCDc')+bDiscriminator('pfParticleNetJetTags:probQCDothers')",float,doc="ParticleNet tagger QCD(bb,cc,b,c,others) sum",precision=10),
0135         particleNet_mass = Var("bDiscriminator('pfParticleNetMassRegressionJetTags:mass')",float,doc="ParticleNet mass regression",precision=10),
0136         particleNetMD_Xbb = Var("bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probXbb')",float,doc="Mass-decorrelated ParticleNet tagger raw X->bb score. For X->bb vs QCD tagging, use Xbb/(Xbb+QCD)",precision=10),
0137         particleNetMD_Xcc = Var("bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probXcc')",float,doc="Mass-decorrelated ParticleNet tagger raw X->cc score. For X->cc vs QCD tagging, use Xcc/(Xcc+QCD)",precision=10),
0138         particleNetMD_Xqq = Var("bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probXqq')",float,doc="Mass-decorrelated ParticleNet tagger raw X->qq (uds) score. For X->qq vs QCD tagging, use Xqq/(Xqq+QCD). For W vs QCD tagging, use (Xcc+Xqq)/(Xcc+Xqq+QCD)",precision=10),
0139         particleNetMD_QCD = Var("bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDbb')+bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDcc')+bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDb')+bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDc')+bDiscriminator('pfMassDecorrelatedParticleNetJetTags:probQCDothers')",float,doc="Mass-decorrelated ParticleNet tagger raw QCD score",precision=10),
0140         subJetIdx1 = Var("?nSubjetCollections()>0 && subjets('SoftDropPuppi').size()>0?subjets('SoftDropPuppi')[0].key():-1", int,
0141             doc="index of first subjet"),
0142         subJetIdx2 = Var("?nSubjetCollections()>0 && subjets('SoftDropPuppi').size()>1?subjets('SoftDropPuppi')[1].key():-1", int,
0143             doc="index of second subjet"),
0144         nConstituents = Var("numberOfDaughters()","uint8",doc="Number of particles in the jet"),
0145     ),
0146     externalVariables = cms.PSet(
0147         lsf3 = ExtVar(cms.InputTag("lepInAK8JetVars:lsf3"),float, doc="Lepton Subjet Fraction (3 subjets)",precision=10),
0148         muonIdx3SJ = ExtVar(cms.InputTag("lepInAK8JetVars:muIdx3SJ"),int, doc="index of muon matched to jet"),
0149         electronIdx3SJ = ExtVar(cms.InputTag("lepInAK8JetVars:eleIdx3SJ"),int,doc="index of electron matched to jet"),
0150     )
0151 )
0152 
0153 ### Era dependent customization
0154 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
0155     modifier.toModify( fatJetTable.variables.n2b1, expr = cms.string("userFloat('ak8PFJetsPuppiSoftDropValueMap:nb1AK8PuppiSoftDropN2')"),)
0156     modifier.toModify( fatJetTable.variables.n3b1, expr = cms.string("userFloat('ak8PFJetsPuppiSoftDropValueMap:nb1AK8PuppiSoftDropN3')"),)
0157     # Deprecated after 106X
0158     modifier.toModify( fatJetTable.variables,
0159         btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
0160         btagDDBvL_noMD = Var("bDiscriminator('pfDeepDoubleBvLJetTags:probHbb')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->bb vs QCD",precision=10),
0161         btagDDCvL_noMD = Var("bDiscriminator('pfDeepDoubleCvLJetTags:probHcc')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->cc vs QCD",precision=10),
0162         btagDDCvB_noMD = Var("bDiscriminator('pfDeepDoubleCvBJetTags:probHcc')",float,doc="DeepDoubleX discriminator (no mass-decorrelation) for H(Z)->cc vs H(Z)->bb",precision=10),
0163         btagDDBvL = Var("bDiscriminator('pfMassIndependentDeepDoubleBvLJetTags:probHbb')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->bb vs QCD",precision=10),
0164         btagDDCvL = Var("bDiscriminator('pfMassIndependentDeepDoubleCvLJetTags:probHcc')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->cc vs QCD",precision=10),
0165         btagDDCvB = Var("bDiscriminator('pfMassIndependentDeepDoubleCvBJetTags:probHcc')",float,doc="DeepDoubleX (mass-decorrelated) discriminator for H(Z)->cc vs H(Z)->bb",precision=10),
0166     )
0167 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, msoftdrop_chs = Var("userFloat('ak8PFJetsCHSSoftDropMass')",float, doc="Legacy uncorrected soft drop mass with CHS",precision=10))
0168 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau1, expr = cms.string("userFloat(\'ak8PFJetsPuppiValueMap:NjettinessAK8PuppiTau1\')"),)
0169 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau2, expr = cms.string("userFloat(\'ak8PFJetsPuppiValueMap:NjettinessAK8PuppiTau2\')"),)
0170 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables.tau3, expr = cms.string("userFloat(\'ak8PFJetsPuppiValueMap:NjettinessAK8PuppiTau3\')"),)
0171 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, tau4 = None)
0172 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, n2b1 = None)
0173 run2_miniAOD_80XLegacy.toModify( fatJetTable.variables, n3b1 = None)
0174 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0175     modifier.toModify( fatJetTable.variables, jetId = Var("userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight"))
0176 
0177 ##############################################################
0178 ## DeepInfoAK8:Start
0179 ## - To be used in nanoAOD_customizeCommon() in nano_cff.py
0180 ###############################################################
0181 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
0182 def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNet, addParticleNetMass, jecPayload):
0183     _btagDiscriminators=[]
0184     if addDeepBTag:
0185         print("Updating process to run DeepCSV btag to AK8 jets")
0186         _btagDiscriminators += ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb']
0187     if addDeepBoostedJet:
0188         print("Updating process to run DeepBoostedJet on datasets before 103X")
0189         from RecoBTag.ONNXRuntime.pfDeepBoostedJet_cff import _pfDeepBoostedJetTagsAll as pfDeepBoostedJetTagsAll
0190         _btagDiscriminators += pfDeepBoostedJetTagsAll
0191     if addParticleNet:
0192         print("Updating process to run ParticleNet before it's included in MiniAOD")
0193         from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetJetTagsAll as pfParticleNetJetTagsAll
0194         _btagDiscriminators += pfParticleNetJetTagsAll
0195     if addParticleNetMass:
0196         from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetMassRegressionOutputs
0197         _btagDiscriminators += _pfParticleNetMassRegressionOutputs
0198     if addDeepDoubleX:
0199         print("Updating process to run DeepDoubleX on datasets before 104X")
0200         _btagDiscriminators += ['pfDeepDoubleBvLJetTags:probHbb', \
0201             'pfDeepDoubleCvLJetTags:probHcc', \
0202             'pfDeepDoubleCvBJetTags:probHcc', \
0203             'pfMassIndependentDeepDoubleBvLJetTags:probHbb', 'pfMassIndependentDeepDoubleCvLJetTags:probHcc', 'pfMassIndependentDeepDoubleCvBJetTags:probHcc']
0204     if addDeepDoubleXV2:
0205         print("Updating process to run DeepDoubleXv2 on datasets before 11X")
0206         _btagDiscriminators += [
0207             'pfMassIndependentDeepDoubleBvLV2JetTags:probHbb',
0208             'pfMassIndependentDeepDoubleCvLV2JetTags:probHcc',
0209             'pfMassIndependentDeepDoubleCvBV2JetTags:probHcc'
0210             ]
0211     if len(_btagDiscriminators)==0: return process
0212     print("Will recalculate the following discriminators on AK8 jets: "+", ".join(_btagDiscriminators))
0213     updateJetCollection(
0214        process,
0215        jetSource = cms.InputTag('slimmedJetsAK8'),
0216        pvSource = cms.InputTag('offlineSlimmedPrimaryVertices'),
0217        svSource = cms.InputTag('slimmedSecondaryVertices'),
0218        rParam = 0.8,
0219        jetCorrections = (jecPayload.value(), cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute', 'L2L3Residual']), 'None'),
0220        btagDiscriminators = _btagDiscriminators,
0221        postfix='AK8WithDeepInfo',
0222        printWarning = False
0223     )
0224     process.jetCorrFactorsAK8.src="selectedUpdatedPatJetsAK8WithDeepInfo"
0225     process.updatedJetsAK8.jetSource="selectedUpdatedPatJetsAK8WithDeepInfo"
0226     return process
0227 
0228 nanoAOD_addDeepInfoAK8_switch = cms.PSet(
0229     nanoAOD_addDeepBTag_switch = cms.untracked.bool(False),
0230     nanoAOD_addDeepBoostedJet_switch = cms.untracked.bool(False),
0231     nanoAOD_addDeepDoubleX_switch = cms.untracked.bool(False),
0232     nanoAOD_addDeepDoubleXV2_switch = cms.untracked.bool(False),
0233     nanoAOD_addParticleNet_switch = cms.untracked.bool(False),
0234     nanoAOD_addParticleNetMass_switch = cms.untracked.bool(False),
0235     jecPayload = cms.untracked.string('AK8PFPuppi')
0236 )
0237 # deepAK8 should not run on 80X, that contains ak8PFJetsCHS jets
0238 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfoAK8_switch,
0239     nanoAOD_addDeepBTag_switch = True,
0240     jecPayload = 'AK8PFchs'
0241 )
0242 # for 94X and 102X samples: needs to run DeepAK8, DeepDoubleX and ParticleNet
0243 (run2_nanoAOD_94X2016 | run2_nanoAOD_94XMiniAODv1 | run2_nanoAOD_94XMiniAODv2 | run2_nanoAOD_102Xv1).toModify(
0244     nanoAOD_addDeepInfoAK8_switch,
0245     nanoAOD_addDeepBoostedJet_switch = True,
0246     nanoAOD_addDeepDoubleX_switch = True,
0247     nanoAOD_addDeepDoubleXV2_switch = True,
0248     nanoAOD_addParticleNet_switch = True,
0249     nanoAOD_addParticleNetMass_switch = True,
0250 )
0251 # for 106Xv1: only needs to run ParticleNet and DDXV2; DeepAK8, DeepDoubleX are already in MiniAOD
0252 run2_nanoAOD_106Xv1.toModify(
0253     nanoAOD_addDeepInfoAK8_switch,
0254     nanoAOD_addDeepDoubleXV2_switch = True,
0255     nanoAOD_addParticleNet_switch = True,
0256     nanoAOD_addParticleNetMass_switch = True,
0257 )
0258 # for 106Xv2: only needs to run ParticleNet Mass regression; The rest are already in MiniAOD
0259 run2_nanoAOD_106Xv2.toModify(
0260     nanoAOD_addDeepInfoAK8_switch,
0261     nanoAOD_addParticleNetMass_switch = True,
0262 )
0263 ################################################
0264 ## DeepInfoAK8:End
0265 #################################################
0266 
0267 subJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
0268     src = cms.InputTag("slimmedJetsAK8PFPuppiSoftDropPacked","SubJets"),
0269     cut = cms.string(""), #probably already applied in miniaod
0270     name = cms.string("SubJet"),
0271     doc  = cms.string("slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis"),
0272     singleton = cms.bool(False), # the number of entries is variable
0273     extension = cms.bool(False), # this is the main table for the jets
0274     variables = cms.PSet(P4Vars,
0275         btagDeepB = Var("bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')",float,doc="DeepCSV b+bb tag discriminator",precision=10),
0276         btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
0277         rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
0278         tau1 = Var("userFloat('NjettinessAK8Subjets:tau1')",float, doc="Nsubjettiness (1 axis)",precision=10),
0279         tau2 = Var("userFloat('NjettinessAK8Subjets:tau2')",float, doc="Nsubjettiness (2 axis)",precision=10),
0280         tau3 = Var("userFloat('NjettinessAK8Subjets:tau3')",float, doc="Nsubjettiness (3 axis)",precision=10),
0281         tau4 = Var("userFloat('NjettinessAK8Subjets:tau4')",float, doc="Nsubjettiness (4 axis)",precision=10),
0282         n2b1 = Var("userFloat('nb1AK8PuppiSoftDropSubjets:ecfN2')", float, doc="N2 with beta=1", precision=10),
0283         n3b1 = Var("userFloat('nb1AK8PuppiSoftDropSubjets:ecfN3')", float, doc="N3 with beta=1", precision=10),
0284     )
0285 )
0286 
0287 # Deprecation/backcomp
0288 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
0289     # post 106X
0290     modifier.toModify(subJetTable.variables,
0291         btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
0292     )
0293 
0294 #jets are not as precise as muons
0295 fatJetTable.variables.pt.precision=10
0296 subJetTable.variables.pt.precision=10
0297 
0298 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, tau1 = None)
0299 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, tau2 = None)
0300 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, tau3 = None)
0301 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, tau4 = None)
0302 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, n2b1 = None)
0303 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, n3b1 = None)
0304 run2_miniAOD_80XLegacy.toModify( subJetTable.variables, btagCMVA = None, btagDeepB = None)
0305 
0306 jetAK8UserDataTask = cms.Task(tightJetIdAK8,tightJetIdLepVetoAK8)
0307 _jetAK8UserDataTask2016 = jetAK8UserDataTask.copy()
0308 _jetAK8UserDataTask2016.add(looseJetIdAK8)
0309 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0310     modifier.toReplaceWith(jetAK8UserDataTask,_jetAK8UserDataTask2016)
0311 
0312 jetAK8Task = cms.Task(jetCorrFactorsAK8,updatedJetsAK8,jetAK8UserDataTask,updatedJetsAK8WithUserData,finalJetsAK8)
0313 
0314 #after lepton collections have been run
0315 jetAK8LepTask = cms.Task(lepInAK8JetVars)
0316 
0317 jetAK8TablesTask = cms.Task(fatJetTable,subJetTable)