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 ##################### User floats producers, selectors ##########################
0007 
0008 from  PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import *
0009 # Note: Safe to always add 'L2L3Residual' as MC contains dummy L2L3Residual corrections (always set to 1)
0010 #      (cf. https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyCorrections#CMSSW_7_6_4_and_above )
0011 jetCorrFactorsNano = patJetCorrFactors.clone(src='slimmedJets',
0012     levels = cms.vstring('L1FastJet',
0013         'L2Relative',
0014         'L3Absolute',
0015         'L2L3Residual'),
0016     primaryVertices = cms.InputTag("offlineSlimmedPrimaryVertices"),
0017 )
0018 
0019 from  PhysicsTools.PatAlgos.producersLayer1.jetUpdater_cfi import *
0020 updatedJets = updatedPatJets.clone(
0021     addBTagInfo=False,
0022     jetSource='slimmedJets',
0023     jetCorrFactorsSource=cms.VInputTag(cms.InputTag("jetCorrFactorsNano") ),
0024 )
0025 
0026 #
0027 # JetID
0028 #
0029 looseJetId = cms.EDProducer("PatJetIDValueMapProducer",
0030     filterParams=cms.PSet(
0031         version = cms.string('WINTER16'),
0032         quality = cms.string('LOOSE'),
0033     ),
0034     src = cms.InputTag("updatedJets")
0035 )
0036 tightJetId = cms.EDProducer("PatJetIDValueMapProducer",
0037     filterParams=cms.PSet(
0038         version = cms.string('RUN2ULCHS'),
0039         quality = cms.string('TIGHT'),
0040     ),
0041     src = cms.InputTag("updatedJets")
0042 )
0043 tightJetIdLepVeto = cms.EDProducer("PatJetIDValueMapProducer",
0044     filterParams=cms.PSet(
0045         version = cms.string('RUN2ULCHS'),
0046         quality = cms.string('TIGHTLEPVETO'),
0047     ),
0048     src = cms.InputTag("updatedJets")
0049 )
0050 run2_jme_2016.toModify( tightJetId.filterParams, version = "RUN2UL16CHS" )
0051 run2_jme_2016.toModify( tightJetIdLepVeto.filterParams, version = "RUN2UL16CHS" )
0052 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0053     modifier.toModify( tightJetId.filterParams, version = "WINTER16" )
0054     modifier.toModify( tightJetIdLepVeto.filterParams, version = "WINTER16" )
0055 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
0056     modifier.toModify( tightJetId.filterParams, version = "WINTER17" )
0057     modifier.toModify( tightJetIdLepVeto.filterParams, version = "WINTER17" )
0058 run2_nanoAOD_102Xv1.toModify( tightJetId.filterParams, version = "SUMMER18" )
0059 run2_nanoAOD_102Xv1.toModify( tightJetIdLepVeto.filterParams, version = "SUMMER18" )
0060 
0061 bJetVars = cms.EDProducer("JetRegressionVarProducer",
0062     pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
0063     src = cms.InputTag("updatedJets"),
0064     svsrc = cms.InputTag("slimmedSecondaryVertices"),
0065     gpsrc = cms.InputTag("prunedGenParticles"),
0066     #musrc = cms.InputTag("slimmedMuons"),
0067     #elesrc = cms.InputTag("slimmedElectrons")
0068 )
0069 
0070 jercVars = cms.EDProducer("BetaStarPackedCandidateVarProducer",
0071     srcJet = cms.InputTag("updatedJets"),
0072     srcPF = cms.InputTag("packedPFCandidates"),
0073     maxDR = cms.double(0.4)
0074 )
0075 
0076 updatedJetsWithUserData = cms.EDProducer("PATJetUserDataEmbedder",
0077     src = cms.InputTag("updatedJets"),
0078     userFloats = cms.PSet(
0079         leadTrackPt = cms.InputTag("bJetVars:leadTrackPt"),
0080         leptonPtRel = cms.InputTag("bJetVars:leptonPtRel"),
0081         leptonPtRatio = cms.InputTag("bJetVars:leptonPtRatio"),
0082         leptonPtRelInv = cms.InputTag("bJetVars:leptonPtRelInv"),
0083         leptonPtRelv0 = cms.InputTag("bJetVars:leptonPtRelv0"),
0084         leptonPtRatiov0 = cms.InputTag("bJetVars:leptonPtRatiov0"),
0085         leptonPtRelInvv0 = cms.InputTag("bJetVars:leptonPtRelInvv0"),
0086         leptonDeltaR = cms.InputTag("bJetVars:leptonDeltaR"),
0087         leptonPt = cms.InputTag("bJetVars:leptonPt"),
0088         vtxPt = cms.InputTag("bJetVars:vtxPt"),
0089         vtxMass = cms.InputTag("bJetVars:vtxMass"),
0090         vtx3dL = cms.InputTag("bJetVars:vtx3dL"),
0091         vtx3deL = cms.InputTag("bJetVars:vtx3deL"),
0092         ptD = cms.InputTag("bJetVars:ptD"),
0093         genPtwNu = cms.InputTag("bJetVars:genPtwNu"),
0094         qgl = cms.InputTag('qgtagger:qgLikelihood'),
0095         puIdNanoDisc = cms.InputTag('pileupJetIdNano:fullDiscriminant'),
0096         chFPV0EF = cms.InputTag("jercVars:chargedFromPV0EnergyFraction"),
0097     ),
0098     userInts = cms.PSet(
0099         tightId = cms.InputTag("tightJetId"),
0100         tightIdLepVeto = cms.InputTag("tightJetIdLepVeto"),
0101         vtxNtrk = cms.InputTag("bJetVars:vtxNtrk"),
0102         leptonPdgId = cms.InputTag("bJetVars:leptonPdgId"),
0103         puIdNanoId = cms.InputTag('pileupJetIdNano:fullId'),
0104     ),
0105 )
0106 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0107     modifier.toModify(updatedJetsWithUserData.userInts,
0108         looseId = cms.InputTag("looseJetId"),
0109     )
0110 
0111 
0112 finalJets = cms.EDFilter("PATJetRefSelector",
0113     src = cms.InputTag("updatedJetsWithUserData"),
0114     cut = cms.string("pt > 15")
0115 )
0116 
0117 
0118 ##################### Tables for final output and docs ##########################
0119 
0120 
0121 jetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
0122     src = cms.InputTag("linkedObjects","jets"),
0123     cut = cms.string(""), #we should not filter on cross linked collections
0124     name = cms.string("Jet"),
0125     doc  = cms.string("slimmedJets, i.e. ak4 PFJets CHS with JECs applied, after basic selection (" + finalJets.cut.value()+")"),
0126     singleton = cms.bool(False), # the number of entries is variable
0127     extension = cms.bool(False), # this is the main table for the jets
0128     externalVariables = cms.PSet(
0129         bRegCorr = ExtVar(cms.InputTag("bjetNN:corr"),float, doc="pt correction for b-jet energy regression",precision=10),
0130         bRegRes = ExtVar(cms.InputTag("bjetNN:res"),float, doc="res on pt corrected with b-jet regression",precision=6),
0131         cRegCorr = ExtVar(cms.InputTag("cjetNN:corr"),float, doc="pt correction for c-jet energy regression",precision=10),
0132         cRegRes = ExtVar(cms.InputTag("cjetNN:res"),float, doc="res on pt corrected with c-jet regression",precision=6),
0133     ),
0134     variables = cms.PSet(P4Vars,
0135         area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
0136         nMuons = Var("?hasOverlaps('muons')?overlaps('muons').size():0", int, doc="number of muons in the jet"),
0137         muonIdx1 = Var("?overlaps('muons').size()>0?overlaps('muons')[0].key():-1", int, doc="index of first matching muon"),
0138         muonIdx2 = Var("?overlaps('muons').size()>1?overlaps('muons')[1].key():-1", int, doc="index of second matching muon"),
0139         electronIdx1 = Var("?overlaps('electrons').size()>0?overlaps('electrons')[0].key():-1", int, doc="index of first matching electron"),
0140         electronIdx2 = Var("?overlaps('electrons').size()>1?overlaps('electrons')[1].key():-1", int, doc="index of second matching electron"),
0141         nElectrons = Var("?hasOverlaps('electrons')?overlaps('electrons').size():0", int, doc="number of electrons in the jet"),
0142         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),
0143         btagDeepFlavB = Var("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')",float,doc="DeepJet b+bb+lepb tag discriminator",precision=10),
0144         btagCSVV2 = Var("bDiscriminator('pfCombinedInclusiveSecondaryVertexV2BJetTags')",float,doc=" pfCombinedInclusiveSecondaryVertexV2 b-tag discriminator (aka CSVV2)",precision=10),
0145         btagDeepCvL = Var("?bDiscriminator('pfDeepCSVJetTags:probc')>=0?bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probudsg')):-1", float,doc="DeepCSV c vs udsg discriminator",precision=10),
0146         btagDeepCvB = Var("?bDiscriminator('pfDeepCSVJetTags:probc')>=0?bDiscriminator('pfDeepCSVJetTags:probc')/(bDiscriminator('pfDeepCSVJetTags:probc')+bDiscriminator('pfDeepCSVJetTags:probb')+bDiscriminator('pfDeepCSVJetTags:probbb')):-1",float,doc="DeepCSV c vs b+bb discriminator",precision=10),
0147         btagDeepFlavCvL = Var("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg')):-1",float,doc="DeepJet c vs uds+g discriminator",precision=10),
0148         btagDeepFlavCvB = Var("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')):-1",float,doc="DeepJet c vs b+bb+lepb discriminator",precision=10),
0149         btagDeepFlavQG = Var("?(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds'))>0?bDiscriminator('pfDeepFlavourJetTags:probg')/(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds')):-1",float,doc="DeepJet g vs uds discriminator",precision=10),
0150         puIdDisc = Var("userFloat('puIdNanoDisc')", float,doc="Pileup ID discriminant with 106X (2018) training",precision=10),
0151         puId = Var("userInt('puIdNanoId')", int,doc="Pileup ID flags with 106X (2018) training"),
0152         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"),
0153         qgl = Var("?userFloat('qgl')>0?userFloat('qgl'):-1",float,doc="Quark vs Gluon likelihood discriminator",precision=10),
0154         hfsigmaEtaEta = Var("userFloat('hfJetShowerShape:sigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10),
0155         hfsigmaPhiPhi = Var("userFloat('hfJetShowerShape:sigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10),
0156         hfcentralEtaStripSize = Var("userInt('hfJetShowerShape:centralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable) "),
0157         hfadjacentEtaStripsSize = Var("userInt('hfJetShowerShape:adjacentEtaStripsSize')", int, doc="eta size of the strips next to the central tower strip in HF (noise discriminating variable) "),
0158         nConstituents = Var("numberOfDaughters()","uint8",doc="Number of particles in the jet"),
0159         rawFactor = Var("1.-jecFactor('Uncorrected')",float,doc="1 - Factor to get back to raw pT",precision=6),
0160         chHEF = Var("chargedHadronEnergyFraction()", float, doc="charged Hadron Energy Fraction", precision= 6),
0161         neHEF = Var("neutralHadronEnergyFraction()", float, doc="neutral Hadron Energy Fraction", precision= 6),
0162         chEmEF = Var("chargedEmEnergyFraction()", float, doc="charged Electromagnetic Energy Fraction", precision= 6),
0163         neEmEF = Var("neutralEmEnergyFraction()", float, doc="neutral Electromagnetic Energy Fraction", precision= 6),
0164         muEF = Var("muonEnergyFraction()", float, doc="muon Energy Fraction", precision= 6),
0165         chFPV0EF = Var("userFloat('chFPV0EF')", float, doc="charged fromPV==0 Energy Fraction (energy excluded from CHS jets). Previously called betastar.", precision= 6),
0166     )
0167 )
0168 
0169 #jets are not as precise as muons
0170 jetTable.variables.pt.precision=10
0171 
0172 ### Era dependent customization
0173 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
0174     # Deprecated after 106X
0175     modifier.toModify(jetTable.variables,
0176         btagCMVA = Var("bDiscriminator('pfCombinedMVAV2BJetTags')",float,doc="CMVA V2 btag discriminator",precision=10),
0177         btagDeepC = Var("bDiscriminator('pfDeepCSVJetTags:probc')",float,doc="DeepCSV charm btag discriminator",precision=10),
0178         btagDeepFlavC = Var("bDiscriminator('pfDeepFlavourJetTags:probc')",float,doc="DeepFlavour charm tag discriminator",precision=10),
0179     )
0180 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0181     modifier.toModify( jetTable.variables, jetId = Var("userInt('tightIdLepVeto')*4+userInt('tightId')*2+userInt('looseId')",int,doc="Jet ID flags bit1 is loose, bit2 is tight, bit3 is tightLepVeto"))
0182 
0183 run2_nanoAOD_102Xv1.toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 102X (2018) training")
0184 run2_nanoAOD_102Xv1.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for pre-UL trainings"))
0185 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2016) training")
0186 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify( jetTable.variables.puId, doc="Pileup ID flags with 106X (2016) training")
0187 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2016APV) training")
0188 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify( jetTable.variables.puId,  doc="Pileup ID flags with 106X (2016APV) training")
0189 run2_jme_2017.toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 106X (2017) training")
0190 run2_jme_2017.toModify( jetTable.variables.puId, doc="Pileup ID flags with 106X (2017) training")
0191 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0192     modifier.toModify( jetTable.variables, puIdDisc = Var("userFloat('pileupJetId:fullDiscriminant')",float,doc="Pileup ID discriminant with 80X (2016) training",precision=10))
0193     modifier.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for pre-UL trainings"))
0194 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
0195     modifier.toModify( jetTable.variables.puIdDisc, doc="Pileup ID discriminant with 94X (2017) training")
0196     modifier.toModify( jetTable.variables, puId = Var("userInt('pileupJetId:fullId')",int,doc="Pileup ID flags for 2016/2017/2018 EOY trainings"))
0197 
0198 bjetNN = cms.EDProducer("BJetEnergyRegressionMVA",
0199     backend = cms.string("ONNX"),
0200     batch_eval = cms.bool(True),
0201     src = cms.InputTag("linkedObjects","jets"),
0202     pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
0203     svsrc = cms.InputTag("slimmedSecondaryVertices"),
0204     rhosrc = cms.InputTag("fixedGridRhoFastjetAll"),
0205 
0206     weightFile =  cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2018.onnx"),
0207     name = cms.string("JetRegNN"),
0208     isClassifier = cms.bool(False),
0209     variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR","Jet_neHEF",
0210                                   "Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL",
0211                                   "Jet_numDaughters_pt03","Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy",
0212                                   "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy",
0213                                   "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy",
0214                                   "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy",
0215                                   "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy",
0216                                   "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy",
0217                                   "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy",
0218                                   "Jet_chHEF","Jet_chEmEF","Jet_leptonPtRelInv","isEle","isMu","isOther","Jet_mass","Jet_ptd"]),
0219     variables = cms.PSet(
0220     Jet_pt = cms.string("pt*jecFactor('Uncorrected')"),
0221     Jet_mt = cms.string("mt*jecFactor('Uncorrected')"),
0222     Jet_eta = cms.string("eta"),
0223     Jet_mass = cms.string("mass*jecFactor('Uncorrected')"),
0224     Jet_ptd = cms.string("userFloat('ptD')"),
0225     Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
0226     Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
0227     Jet_vtxMass = cms.string("userFloat('vtxMass')"),
0228     Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
0229     Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
0230     Jet_vtxPt = cms.string("userFloat('vtxPt')"),
0231     #Jet_leptonPt = cms.string("userFloat('leptonPt')"),
0232     Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
0233     Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"),
0234     Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"),
0235     #Jet_leptonPdgId = cms.string("userInt('leptonPdgId')"),
0236     Jet_neHEF = cms.string("neutralHadronEnergyFraction()"),
0237     Jet_neEmEF = cms.string("neutralEmEnergyFraction()"),
0238     Jet_chHEF = cms.string("chargedHadronEnergyFraction()"),
0239     Jet_chEmEF = cms.string("chargedEmEnergyFraction()"),
0240     isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"),
0241     isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"),
0242     isOther = cms.string("?userInt('leptonPdgId')==0?1:0"),
0243     ),
0244      inputTensorName = cms.string("ffwd_inp:0"),
0245      outputTensorName = cms.string("ffwd_out/BiasAdd:0"),
0246      outputNames = cms.vstring(["corr","res"]),
0247      outputFormulas = cms.vstring(["at(0)*0.27912887930870056+1.0545977354049683","0.5*(at(2)-at(1))*0.27912887930870056"]),
0248 )
0249 
0250 cjetNN = cms.EDProducer("BJetEnergyRegressionMVA",
0251     backend = cms.string("ONNX"),
0252     batch_eval = cms.bool(True),
0253 
0254     src = cms.InputTag("linkedObjects","jets"),
0255     pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
0256     svsrc = cms.InputTag("slimmedSecondaryVertices"),
0257     rhosrc = cms.InputTag("fixedGridRhoFastjetAll"),
0258 
0259     weightFile =  cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2018.onnx"),
0260     name = cms.string("JetRegNN"),
0261     isClassifier = cms.bool(False),
0262     variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR",
0263                                   "Jet_neHEF","Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL",
0264                                   "Jet_numDaughters_pt03","Jet_chEmEF","Jet_chHEF", "Jet_ptd","Jet_mass",
0265                                   "Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy",
0266                                   "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy",
0267                                   "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy",
0268                                   "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy",
0269                                   "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy",
0270                                   "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy",
0271                                   "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy"]),
0272     variables = cms.PSet(
0273     Jet_pt = cms.string("pt*jecFactor('Uncorrected')"),
0274     Jet_mt = cms.string("mt*jecFactor('Uncorrected')"),
0275     Jet_eta = cms.string("eta"),
0276     Jet_mass = cms.string("mass*jecFactor('Uncorrected')"),
0277     Jet_ptd = cms.string("userFloat('ptD')"),
0278     Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
0279     Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
0280     Jet_vtxMass = cms.string("userFloat('vtxMass')"),
0281     Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
0282     Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
0283     Jet_vtxPt = cms.string("userFloat('vtxPt')"),
0284     #Jet_leptonPt = cms.string("userFloat('leptonPt')"),
0285     Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
0286     Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"),
0287     Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"),
0288     #Jet_leptonPdgId = cms.string("userInt('leptonPdgId')"),
0289     Jet_neHEF = cms.string("neutralHadronEnergyFraction()"),
0290     Jet_neEmEF = cms.string("neutralEmEnergyFraction()"),
0291     Jet_chHEF = cms.string("chargedHadronEnergyFraction()"),
0292     Jet_chEmEF = cms.string("chargedEmEnergyFraction()"),
0293     isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"),
0294     isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"),
0295     isOther = cms.string("?userInt('leptonPdgId')==0?1:0"),
0296     ),
0297     inputTensorName = cms.string("ffwd_inp:0"),
0298     outputTensorName = cms.string("ffwd_out/BiasAdd:0"),
0299     outputNames = cms.vstring(["corr","res"]),
0300     outputFormulas = cms.vstring(["at(0)*0.24325256049633026+0.993854820728302","0.5*(at(2)-at(1))*0.24325256049633026"]),
0301 )
0302 
0303 
0304 run2_jme_2016.toModify( bjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2016.onnx") )
0305 run2_jme_2016.toModify( bjetNN,outputFormulas = cms.vstring(["at(0)*0.31976690888404846+1.047176718711853","0.5*(at(2)-at(1))*0.31976690888404846"]))
0306 
0307 run2_jme_2017.toModify( bjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2017.onnx") )
0308 run2_jme_2017.toModify( bjetNN,outputFormulas = cms.vstring(["at(0)*0.28225210309028625+1.055067777633667","0.5*(at(2)-at(1))*0.28225210309028625"]))
0309 
0310 run2_jme_2016.toModify( cjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2016.onnx") )
0311 run2_jme_2016.toModify( cjetNN,outputFormulas = cms.vstring(["at(0)*0.28862622380256653+0.9908722639083862","0.5*(at(2)-at(1))*0.28862622380256653"]))
0312 
0313 run2_jme_2017.toModify( cjetNN, weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2017.onnx") )
0314 run2_jme_2017.toModify( cjetNN,outputFormulas = cms.vstring(["at(0)*0.24718524515628815+0.9927206635475159","0.5*(at(2)-at(1))*0.24718524515628815"]))
0315 
0316 
0317 #
0318 # Quark-Gluon Likelihood (QGL)
0319 #
0320 from RecoJets.JetProducers.QGTagger_cfi import  QGTagger
0321 qgtagger=QGTagger.clone(srcJets="updatedJets",srcVertexCollection="offlineSlimmedPrimaryVertices")
0322 
0323 #
0324 # PileUp ID
0325 #
0326 from RecoJets.JetProducers.PileupJetID_cfi import pileupJetId, _chsalgos_94x, _chsalgos_102x, _chsalgos_106X_UL16, _chsalgos_106X_UL16APV, _chsalgos_106X_UL17, _chsalgos_106X_UL18
0327 pileupJetIdNano=pileupJetId.clone(jets="updatedJets",algos = cms.VPSet(_chsalgos_106X_UL18),inputIsCorrected=True,applyJec=False,vertexes="offlineSlimmedPrimaryVertices")
0328 run2_jme_2017.toModify(pileupJetIdNano, algos = _chsalgos_106X_UL17)
0329 (run2_jme_2016 & ~tracker_apv_vfp30_2016 ).toModify(pileupJetIdNano, algos = _chsalgos_106X_UL16)
0330 (run2_jme_2016 & tracker_apv_vfp30_2016 ).toModify(pileupJetIdNano, algos = _chsalgos_106X_UL16APV)
0331 run2_nanoAOD_102Xv1.toModify(pileupJetIdNano, algos = _chsalgos_102x)
0332 for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
0333     modifier.toModify(pileupJetIdNano, algos = _chsalgos_94x)
0334 
0335 ##############################################################
0336 ## DeepInfoAK4CHS:Start
0337 ## - To be used in nanoAOD_customizeCommon() in nano_cff.py
0338 ###############################################################
0339 from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
0340 def nanoAOD_addDeepInfoAK4CHS(process,addDeepBTag,addDeepFlavour):
0341     _btagDiscriminators=[]
0342     if addDeepBTag:
0343         print("Updating process to run DeepCSV btag")
0344         _btagDiscriminators += ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb','pfDeepCSVJetTags:probc']
0345     if addDeepFlavour:
0346         print("Updating process to run DeepFlavour btag")
0347         _btagDiscriminators += ['pfDeepFlavourJetTags:probb','pfDeepFlavourJetTags:probbb','pfDeepFlavourJetTags:problepb','pfDeepFlavourJetTags:probc']
0348     if len(_btagDiscriminators)==0: return process
0349     print("Will recalculate the following discriminators: "+", ".join(_btagDiscriminators))
0350     updateJetCollection(
0351         process,
0352         jetSource = cms.InputTag('slimmedJets'),
0353         jetCorrections = ('AK4PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute','L2L3Residual']), 'None'),
0354         btagDiscriminators = _btagDiscriminators,
0355         postfix = 'WithDeepInfo',
0356     )
0357     process.load("Configuration.StandardSequences.MagneticField_cff")
0358     process.jetCorrFactorsNano.src="selectedUpdatedPatJetsWithDeepInfo"
0359     process.updatedJets.jetSource="selectedUpdatedPatJetsWithDeepInfo"
0360     return process
0361 
0362 nanoAOD_addDeepInfoAK4CHS_switch = cms.PSet(
0363     nanoAOD_addDeepBTag_switch = cms.untracked.bool(False),
0364     nanoAOD_addDeepFlavourTag_switch = cms.untracked.bool(False),
0365 )
0366 run2_miniAOD_80XLegacy.toModify(nanoAOD_addDeepInfoAK4CHS_switch, nanoAOD_addDeepBTag_switch = cms.untracked.bool(True))
0367 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2:
0368     modifier.toModify(nanoAOD_addDeepInfoAK4CHS_switch, nanoAOD_addDeepFlavourTag_switch =  cms.untracked.bool(True))
0369 ################################################
0370 ## DeepInfoAK4CHS:End
0371 #################################################
0372 
0373 ################################################################################
0374 # JETS FOR MET type1
0375 ################################################################################
0376 basicJetsForMetForT1METNano = cms.EDProducer("PATJetCleanerForType1MET",
0377     src = updatedJetsWithUserData.src,
0378     jetCorrEtaMax = cms.double(9.9),
0379     jetCorrLabel = cms.InputTag("L3Absolute"),
0380     jetCorrLabelRes = cms.InputTag("L2L3Residual"),
0381     offsetCorrLabel = cms.InputTag("L1FastJet"),
0382     skipEM = cms.bool(False),
0383     skipEMfractionThreshold = cms.double(0.9),
0384     skipMuonSelection = cms.string('isGlobalMuon | isStandAloneMuon'),
0385     skipMuons = cms.bool(True),
0386     type1JetPtThreshold = cms.double(0.0),
0387     calcMuonSubtrRawPtAsValueMap = cms.bool(True)
0388 )
0389 
0390 updatedJetsWithUserData.userFloats.muonSubtrRawPt = cms.InputTag("basicJetsForMetForT1METNano:MuonSubtrRawPt")
0391 
0392 corrT1METJetTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
0393     src = finalJets.src,
0394     cut = cms.string("pt<15 && abs(eta)<9.9"),
0395     name = cms.string("CorrT1METJet"),
0396     doc  = cms.string("Additional low-pt ak4 CHS jets for Type-1 MET re-correction"),
0397     singleton = cms.bool(False), # the number of entries is variable
0398     extension = cms.bool(False), # this is the main table for the jets
0399     variables = cms.PSet(
0400         rawPt = Var("pt()*jecFactor('Uncorrected')",float,precision=10),
0401         eta  = Var("eta",  float,precision=12),
0402         phi = Var("phi", float, precision=12),
0403         area = Var("jetArea()", float, doc="jet catchment area, for JECs",precision=10),
0404     )
0405 )
0406 
0407 corrT1METJetTable.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6)
0408 jetTable.variables.muonSubtrFactor = Var("1-userFloat('muonSubtrRawPt')/(pt()*jecFactor('Uncorrected'))",float,doc="1-(muon-subtracted raw pt)/(raw pt)",precision=6)
0409 
0410 jetForMETTask =  cms.Task(basicJetsForMetForT1METNano,corrT1METJetTable)
0411 
0412 #before cross linking
0413 jetUserDataTask = cms.Task(bJetVars,qgtagger,jercVars,tightJetId,tightJetIdLepVeto,pileupJetIdNano)
0414 
0415 #
0416 # HF shower shape recomputation
0417 # Only run if needed (i.e. if default MINIAOD info is missing or outdated because of new JECs...)
0418 #
0419 from RecoJets.JetProducers.hfJetShowerShape_cfi import hfJetShowerShape
0420 hfJetShowerShapeforNanoAOD = hfJetShowerShape.clone(jets="updatedJets",vertices="offlineSlimmedPrimaryVertices")
0421 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016, run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2, run2_nanoAOD_102Xv1, run2_nanoAOD_106Xv1:
0422     modifier.toModify(updatedJetsWithUserData.userFloats,
0423         hfsigmaEtaEta = cms.InputTag('hfJetShowerShapeforNanoAOD:sigmaEtaEta'),
0424         hfsigmaPhiPhi = cms.InputTag('hfJetShowerShapeforNanoAOD:sigmaPhiPhi'),
0425     )
0426     modifier.toModify(updatedJetsWithUserData.userInts,
0427         hfcentralEtaStripSize = cms.InputTag('hfJetShowerShapeforNanoAOD:centralEtaStripSize'),
0428         hfadjacentEtaStripsSize = cms.InputTag('hfJetShowerShapeforNanoAOD:adjacentEtaStripsSize'),
0429     )
0430     modifier.toModify(jetTable.variables, hfsigmaEtaEta = Var("userFloat('hfsigmaEtaEta')",float,doc="sigmaEtaEta for HF jets (noise discriminating variable)",precision=10))
0431     modifier.toModify(jetTable.variables, hfsigmaPhiPhi = Var("userFloat('hfsigmaPhiPhi')",float,doc="sigmaPhiPhi for HF jets (noise discriminating variable)",precision=10))
0432     modifier.toModify(jetTable.variables, hfcentralEtaStripSize = Var("userInt('hfcentralEtaStripSize')", int, doc="eta size of the central tower strip in HF (noise discriminating variable)"))
0433     modifier.toModify(jetTable.variables, hfadjacentEtaStripsSize = Var("userInt('hfadjacentEtaStripsSize')", int, doc="eta size of the strips next to the central tower strip in HF (noise discriminating variable)"))
0434     modifier.toModify(jetUserDataTask, jetUserDataTask.add(hfJetShowerShapeforNanoAOD))
0435 
0436 _jetUserDataTask2016 = jetUserDataTask.copy()
0437 _jetUserDataTask2016.add(looseJetId)
0438 
0439 for modifier in run2_miniAOD_80XLegacy, run2_nanoAOD_94X2016:
0440   modifier.toReplaceWith(jetUserDataTask,_jetUserDataTask2016)
0441 
0442 #before cross linking
0443 jetTask = cms.Task(jetCorrFactorsNano,updatedJets,jetUserDataTask,updatedJetsWithUserData,finalJets)
0444 
0445 #after cross linkining
0446 jetTablesTask = cms.Task(bjetNN,cjetNN,jetTable)