diff --git a/PhysicsTools/NanoAOD/python/electrons_cff.py b/PhysicsTools/NanoAOD/python/electrons_cff.py index 3ba7fc290fc96..2f98dbaee3032 100644 --- a/PhysicsTools/NanoAOD/python/electrons_cff.py +++ b/PhysicsTools/NanoAOD/python/electrons_cff.py @@ -268,22 +268,21 @@ def _get_bitmapVIDForEle_docstring(modules,WorkingPoints): src = cms.InputTag("linkedObjects","electrons"), weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/el_BDTG_2017.weights.xml"), name = cms.string("electronMVATTH"), + backend = cms.string("TMVA"), isClassifier = cms.bool(True), - variablesOrder = cms.vstring(["LepGood_pt","LepGood_eta","LepGood_jetNDauChargedMVASel","LepGood_miniRelIsoCharged","LepGood_miniRelIsoNeutral","LepGood_jetPtRelv2","LepGood_jetDF","LepGood_jetPtRatio","LepGood_dxy","LepGood_sip3d","LepGood_dz","LepGood_mvaFall17V2noIso"]), - variables = cms.PSet( - LepGood_pt = cms.string("pt"), - LepGood_eta = cms.string("eta"), - LepGood_jetNDauChargedMVASel = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"), - # NB: only using Fall17V2 iso here - LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg_Fall17V2')/pt"), - LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll_Fall17V2')-userFloat('miniIsoChg_Fall17V2'))/pt"), - LepGood_jetPtRelv2 = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"), - LepGood_jetDF = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0"), - LepGood_jetPtRatio = cms.string("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+userFloat('PFIsoAll04_Fall17V2')/pt)"), - LepGood_dxy = cms.string("log(abs(dB('PV2D')))"), - LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"), - LepGood_dz = cms.string("log(abs(dB('PVDZ')))"), - LepGood_mvaFall17V2noIso = cms.string("userFloat('mvaNoIso_Fall17V2')"), + variables = cms.VPSet( + cms.PSet( name = cms.string("LepGood_pt"), expr = cms.string("pt")), + cms.PSet( name = cms.string("LepGood_eta"), expr = cms.string("eta")), + cms.PSet( name = cms.string("LepGood_jetNDauChargedMVASel"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0")), + cms.PSet( name = cms.string("LepGood_miniRelIsoCharged"), expr = cms.string("userFloat('miniIsoChg_Fall17V2')/pt")), + cms.PSet( name = cms.string("LepGood_miniRelIsoNeutral"), expr = cms.string("(userFloat('miniIsoAll_Fall17V2')-userFloat('miniIsoChg_Fall17V2'))/pt")), + cms.PSet( name = cms.string("LepGood_jetPtRelv2"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0")), + cms.PSet( name = cms.string("LepGood_jetDF"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0")), + cms.PSet( name = cms.string("LepGood_jetPtRatio"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+userFloat('PFIsoAll04_Fall17V2')/pt)")), + cms.PSet( name = cms.string("LepGood_dxy"), expr = cms.string("log(abs(dB('PV2D')))")), + cms.PSet( name = cms.string("LepGood_sip3d"), expr = cms.string("abs(dB('PV3D')/edB('PV3D'))")), + cms.PSet( name = cms.string("LepGood_dz"), expr = cms.string("log(abs(dB('PVDZ')))")), + cms.PSet( name = cms.string("LepGood_mvaFall17V2noIso"), expr = cms.string("userFloat('mvaNoIso_Fall17V2')")), ) ) run2_egamma_2016.toModify( diff --git a/PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py b/PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py index fffe94aec8493..e8c4bc4b1b7b4 100644 --- a/PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py +++ b/PhysicsTools/NanoAOD/python/jetsAK4_CHS_cff.py @@ -246,44 +246,55 @@ weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/breg_training_2018.onnx"), name = cms.string("JetRegNN"), - isClassifier = cms.bool(False), - variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR","Jet_neHEF", - "Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL", - "Jet_numDaughters_pt03","Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy", - "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy", - "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy", - "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy", - "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy", - "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy", - "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy", - "Jet_chHEF","Jet_chEmEF","Jet_leptonPtRelInv","isEle","isMu","isOther","Jet_mass","Jet_ptd"]), - variables = cms.PSet( - Jet_pt = cms.string("pt*jecFactor('Uncorrected')"), - Jet_mt = cms.string("mt*jecFactor('Uncorrected')"), - Jet_eta = cms.string("eta"), - Jet_mass = cms.string("mass*jecFactor('Uncorrected')"), - Jet_ptd = cms.string("userFloat('ptD')"), - Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"), - Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"), - Jet_vtxMass = cms.string("userFloat('vtxMass')"), - Jet_vtx3dL = cms.string("userFloat('vtx3dL')"), - Jet_vtx3deL = cms.string("userFloat('vtx3deL')"), - Jet_vtxPt = cms.string("userFloat('vtxPt')"), - Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"), - Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"), - Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"), - Jet_neHEF = cms.string("neutralHadronEnergyFraction()"), - Jet_neEmEF = cms.string("neutralEmEnergyFraction()"), - Jet_chHEF = cms.string("chargedHadronEnergyFraction()"), - Jet_chEmEF = cms.string("chargedEmEnergyFraction()"), - isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"), - isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"), - isOther = cms.string("?userInt('leptonPdgId')==0?1:0"), + variables = cms.VPSet( + cms.PSet( name = cms.string("Jet_pt"), expr = cms.string("pt*jecFactor('Uncorrected')")), + cms.PSet( name = cms.string("Jet_eta"), expr = cms.string("eta")), + cms.PSet( name = cms.string("rho")), + cms.PSet( name = cms.string("Jet_mt"), expr = cms.string("mt*jecFactor('Uncorrected')")), + cms.PSet( name = cms.string("Jet_leadTrackPt"), expr = cms.string("userFloat('leadTrackPt')")), + cms.PSet( name = cms.string("Jet_leptonPtRel"), expr = cms.string("userFloat('leptonPtRelv0')")), + cms.PSet( name = cms.string("Jet_leptonDeltaR"), expr = cms.string("userFloat('leptonDeltaR')")), + cms.PSet( name = cms.string("Jet_neHEF"), expr = cms.string("neutralHadronEnergyFraction()")), + cms.PSet( name = cms.string("Jet_neEmEF"), expr = cms.string("neutralEmEnergyFraction()")), + cms.PSet( name = cms.string("Jet_vtxPt"), expr = cms.string("userFloat('vtxPt')")), + cms.PSet( name = cms.string("Jet_vtxMass"), expr = cms.string("userFloat('vtxMass')")), + cms.PSet( name = cms.string("Jet_vtx3dL"), expr = cms.string("userFloat('vtx3dL')")), + cms.PSet( name = cms.string("Jet_vtxNtrk"), expr = cms.string("userInt('vtxNtrk')")), + cms.PSet( name = cms.string("Jet_vtx3deL"), expr = cms.string("userFloat('vtx3deL')")), + cms.PSet( name = cms.string("Jet_numDaughters_pt03")), + cms.PSet( name = cms.string("Jet_energyRing_dR0_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR1_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR2_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR3_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR4_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR0_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR1_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR2_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR3_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR4_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR0_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR1_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR2_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR3_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR4_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR0_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR1_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR2_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR3_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR4_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_chHEF"), expr = cms.string("chargedHadronEnergyFraction()")), + cms.PSet( name = cms.string("Jet_chEmEF"), expr = cms.string("chargedEmEnergyFraction()")), + cms.PSet( name = cms.string("Jet_leptonPtRelInv"), expr = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')")), + cms.PSet( name = cms.string("isEle"), expr = cms.string("?abs(userInt('leptonPdgId'))==11?1:0")), + cms.PSet( name = cms.string("isMu"), expr = cms.string("?abs(userInt('leptonPdgId'))==13?1:0")), + cms.PSet( name = cms.string("isOther"), expr = cms.string("?userInt('leptonPdgId')==0?1:0")), + cms.PSet( name = cms.string("Jet_mass"), expr = cms.string("mass*jecFactor('Uncorrected')")), + cms.PSet( name = cms.string("Jet_ptd"), expr = cms.string("userFloat('ptD')")) ), - inputTensorName = cms.string("ffwd_inp:0"), - outputTensorName = cms.string("ffwd_out/BiasAdd:0"), - outputNames = cms.vstring(["corr","res"]), - outputFormulas = cms.vstring(["at(0)*0.27912887930870056+1.0545977354049683","0.5*(at(2)-at(1))*0.27912887930870056"]), + inputTensorName = cms.string("ffwd_inp:0"), + outputTensorName = cms.string("ffwd_out/BiasAdd:0"), + outputNames = cms.vstring(["corr","res"]), + outputFormulas = cms.vstring(["at(0)*0.27912887930870056+1.0545977354049683","0.5*(at(2)-at(1))*0.27912887930870056"]), ) cjetNN = cms.EDProducer("BJetEnergyRegressionMVA", @@ -297,40 +308,47 @@ weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/creg_training_2018.onnx"), name = cms.string("JetRegNN"), - isClassifier = cms.bool(False), - variablesOrder = cms.vstring(["Jet_pt","Jet_eta","rho","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonDeltaR", - "Jet_neHEF","Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL", - "Jet_numDaughters_pt03","Jet_chEmEF","Jet_chHEF", "Jet_ptd","Jet_mass", - "Jet_energyRing_dR0_em_Jet_rawEnergy","Jet_energyRing_dR1_em_Jet_rawEnergy", - "Jet_energyRing_dR2_em_Jet_rawEnergy","Jet_energyRing_dR3_em_Jet_rawEnergy","Jet_energyRing_dR4_em_Jet_rawEnergy", - "Jet_energyRing_dR0_neut_Jet_rawEnergy","Jet_energyRing_dR1_neut_Jet_rawEnergy","Jet_energyRing_dR2_neut_Jet_rawEnergy", - "Jet_energyRing_dR3_neut_Jet_rawEnergy","Jet_energyRing_dR4_neut_Jet_rawEnergy","Jet_energyRing_dR0_ch_Jet_rawEnergy", - "Jet_energyRing_dR1_ch_Jet_rawEnergy","Jet_energyRing_dR2_ch_Jet_rawEnergy","Jet_energyRing_dR3_ch_Jet_rawEnergy", - "Jet_energyRing_dR4_ch_Jet_rawEnergy","Jet_energyRing_dR0_mu_Jet_rawEnergy","Jet_energyRing_dR1_mu_Jet_rawEnergy", - "Jet_energyRing_dR2_mu_Jet_rawEnergy","Jet_energyRing_dR3_mu_Jet_rawEnergy","Jet_energyRing_dR4_mu_Jet_rawEnergy"]), - variables = cms.PSet( - Jet_pt = cms.string("pt*jecFactor('Uncorrected')"), - Jet_mt = cms.string("mt*jecFactor('Uncorrected')"), - Jet_eta = cms.string("eta"), - Jet_mass = cms.string("mass*jecFactor('Uncorrected')"), - Jet_ptd = cms.string("userFloat('ptD')"), - Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"), - Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"), - Jet_vtxMass = cms.string("userFloat('vtxMass')"), - Jet_vtx3dL = cms.string("userFloat('vtx3dL')"), - Jet_vtx3deL = cms.string("userFloat('vtx3deL')"), - Jet_vtxPt = cms.string("userFloat('vtxPt')"), - Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"), - Jet_leptonPtRelInv = cms.string("userFloat('leptonPtRelInvv0')*jecFactor('Uncorrected')"), - Jet_leptonDeltaR = cms.string("userFloat('leptonDeltaR')"), - Jet_neHEF = cms.string("neutralHadronEnergyFraction()"), - Jet_neEmEF = cms.string("neutralEmEnergyFraction()"), - Jet_chHEF = cms.string("chargedHadronEnergyFraction()"), - Jet_chEmEF = cms.string("chargedEmEnergyFraction()"), - isMu = cms.string("?abs(userInt('leptonPdgId'))==13?1:0"), - isEle = cms.string("?abs(userInt('leptonPdgId'))==11?1:0"), - isOther = cms.string("?userInt('leptonPdgId')==0?1:0"), - ), + variables = cms.VPSet( + cms.PSet( name = cms.string("Jet_pt"), expr = cms.string("pt*jecFactor('Uncorrected')")), + cms.PSet( name = cms.string("Jet_eta"), expr = cms.string("eta")), + cms.PSet( name = cms.string("rho")), + cms.PSet( name = cms.string("Jet_mt"), expr = cms.string("mt*jecFactor('Uncorrected')")), + cms.PSet( name = cms.string("Jet_leadTrackPt"), expr = cms.string("userFloat('leadTrackPt')")), + cms.PSet( name = cms.string("Jet_leptonPtRel"), expr = cms.string("userFloat('leptonPtRelv0')")), + cms.PSet( name = cms.string("Jet_leptonDeltaR"), expr = cms.string("userFloat('leptonDeltaR')")), + cms.PSet( name = cms.string("Jet_neHEF"), expr = cms.string("neutralHadronEnergyFraction()")), + cms.PSet( name = cms.string("Jet_neEmEF"), expr = cms.string("neutralEmEnergyFraction()")), + cms.PSet( name = cms.string("Jet_vtxPt"), expr = cms.string("userFloat('vtxPt')")), + cms.PSet( name = cms.string("Jet_vtxMass"), expr = cms.string("userFloat('vtxMass')")), + cms.PSet( name = cms.string("Jet_vtx3dL"), expr = cms.string("userFloat('vtx3dL')")), + cms.PSet( name = cms.string("Jet_vtxNtrk"), expr = cms.string("userInt('vtxNtrk')")), + cms.PSet( name = cms.string("Jet_vtx3deL"), expr = cms.string("userFloat('vtx3deL')")), + cms.PSet( name = cms.string("Jet_numDaughters_pt03")), + cms.PSet( name = cms.string("Jet_chEmEF"), expr = cms.string("chargedEmEnergyFraction()")), + cms.PSet( name = cms.string("Jet_chHEF"), expr = cms.string("chargedHadronEnergyFraction()")), + cms.PSet( name = cms.string("Jet_ptd"), expr = cms.string("userFloat('ptD')")), + cms.PSet( name = cms.string("Jet_mass"), expr = cms.string("mass*jecFactor('Uncorrected')")), + cms.PSet( name = cms.string("Jet_energyRing_dR0_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR1_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR2_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR3_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR4_em_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR0_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR1_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR2_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR3_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR4_neut_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR0_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR1_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR2_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR3_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR4_ch_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR0_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR1_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR2_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR3_mu_Jet_rawEnergy")), + cms.PSet( name = cms.string("Jet_energyRing_dR4_mu_Jet_rawEnergy")), + ), inputTensorName = cms.string("ffwd_inp:0"), outputTensorName = cms.string("ffwd_out/BiasAdd:0"), outputNames = cms.vstring(["corr","res"]), @@ -466,18 +484,15 @@ def nanoAOD_refineFastSim_bTagDeepFlav(process): weightFile=cms.FileInPath("PhysicsTools/NanoAOD/data/btagDeepFlavRefineNN_CHS.onnx"), name = cms.string("btagDeepFlavRefineNN"), - isClassifier = cms.bool(False), - variablesOrder = cms.vstring(["GenJet_pt","GenJet_eta","Jet_hadronFlavour", - "Jet_btagDeepFlavB","Jet_btagDeepFlavCvB","Jet_btagDeepFlavCvL","Jet_btagDeepFlavQG"]), - variables = cms.PSet( - GenJet_pt = cms.string("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().pt():pt"), - GenJet_eta = cms.string("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().eta():eta"), - Jet_hadronFlavour = cms.string("hadronFlavour()"), - Jet_btagDeepFlavB = cms.string("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')"), - Jet_btagDeepFlavCvB = cms.string("?(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"), - Jet_btagDeepFlavCvL = cms.string("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg')):-1"), - Jet_btagDeepFlavQG = cms.string("?(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds'))>0?bDiscriminator('pfDeepFlavourJetTags:probg')/(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds')):-1"), - ), + variables = cms.VPSet( + cms.PSet( name = cms.string("GenJet_pt"), expr = cms.string("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().pt():pt")), + cms.PSet( name = cms.string("GenJet_eta"), expr = cms.string("?genJetFwdRef().backRef().isNonnull()?genJetFwdRef().backRef().eta():eta")), + cms.PSet( name = cms.string("Jet_hadronFlavour"), expr = cms.string("hadronFlavour()")), + cms.PSet( name = cms.string("Jet_btagDeepFlavB"), expr = cms.string("bDiscriminator('pfDeepFlavourJetTags:probb')+bDiscriminator('pfDeepFlavourJetTags:probbb')+bDiscriminator('pfDeepFlavourJetTags:problepb')")), + cms.PSet( name = cms.string("Jet_btagDeepFlavCvB"), expr = cms.string("?(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")), + cms.PSet( name = cms.string("Jet_btagDeepFlavCvL"), expr = cms.string("?(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg'))>0?bDiscriminator('pfDeepFlavourJetTags:probc')/(bDiscriminator('pfDeepFlavourJetTags:probc')+bDiscriminator('pfDeepFlavourJetTags:probuds')+bDiscriminator('pfDeepFlavourJetTags:probg')):-1")), + cms.PSet( name = cms.string("Jet_btagDeepFlavQG"), expr = cms.string("?(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds'))>0?bDiscriminator('pfDeepFlavourJetTags:probg')/(bDiscriminator('pfDeepFlavourJetTags:probg')+bDiscriminator('pfDeepFlavourJetTags:probuds')):-1")), + ), inputTensorName = cms.string("input"), outputTensorName = cms.string("output"), outputNames = cms.vstring(["btagDeepFlavBrefined","btagDeepFlavCvBrefined","btagDeepFlavCvLrefined","btagDeepFlavQGrefined"]), diff --git a/PhysicsTools/NanoAOD/python/muons_cff.py b/PhysicsTools/NanoAOD/python/muons_cff.py index 094a9dc3ccacc..ccc2f5ae6b891 100644 --- a/PhysicsTools/NanoAOD/python/muons_cff.py +++ b/PhysicsTools/NanoAOD/python/muons_cff.py @@ -33,7 +33,6 @@ muonMVAID = cms.EDProducer("EvaluateMuonMVAID", src = cms.InputTag("slimmedMuonsUpdated"), weightFile = cms.FileInPath("RecoMuon/MuonIdentification/data/mvaID.onnx"), - isClassifier = cms.bool(False), backend = cms.string('ONNX'), name = cms.string("muonMVAID"), outputTensorName= cms.string("probabilities"), @@ -41,21 +40,27 @@ outputNames = cms.vstring(["probGOOD", "wpMedium", "wpTight"]), batch_eval =cms.bool(True), outputFormulas = cms.vstring(["at(1)", "? at(1) > 0.08 ? 1 : 0", "? at(1) > 0.20 ? 1 : 0"]), - variablesOrder = cms.vstring(["LepGood_global_muon","LepGood_validFraction","Muon_norm_chi2_extended","LepGood_local_chi2","LepGood_kink","LepGood_segmentComp","Muon_n_Valid_hits_extended","LepGood_n_MatchedStations","LepGood_Valid_pixel","LepGood_tracker_layers","LepGood_pt","LepGood_eta"]), - variables = cms.PSet( - LepGood_global_muon = cms.string("isGlobalMuon"), - LepGood_validFraction = cms.string("?innerTrack.isNonnull?innerTrack().validFraction:-99"), - LepGood_local_chi2 = cms.string("combinedQuality().chi2LocalPosition"), - LepGood_kink = cms.string("combinedQuality().trkKink"), - LepGood_segmentComp = cms.string("segmentCompatibility"), - LepGood_n_MatchedStations = cms.string("numberOfMatchedStations()"), - LepGood_Valid_pixel = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().numberOfValidPixelHits():-99"), - LepGood_tracker_layers = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().trackerLayersWithMeasurement():-99"), - LepGood_pt = cms.string("pt"), - LepGood_eta = cms.string("eta"), - ) + variables = cms.VPSet( + cms.PSet( name = cms.string("LepGood_global_muon"), expr = cms.string("isGlobalMuon")), + cms.PSet( name = cms.string("LepGood_validFraction"), expr = cms.string("?innerTrack.isNonnull?innerTrack().validFraction:-99")), + cms.PSet( name = cms.string("Muon_norm_chi2_extended")), + cms.PSet( name = cms.string("LepGood_local_chi2"), expr = cms.string("combinedQuality().chi2LocalPosition")), + cms.PSet( name = cms.string("LepGood_kink"), expr = cms.string("combinedQuality().trkKink")), + cms.PSet( name = cms.string("LepGood_segmentComp"), expr = cms.string("segmentCompatibility")), + cms.PSet( name = cms.string("Muon_n_Valid_hits_extended")), + cms.PSet( name = cms.string("LepGood_n_MatchedStations"), expr = cms.string("numberOfMatchedStations()")), + cms.PSet( name = cms.string("LepGood_Valid_pixel"), expr = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().numberOfValidPixelHits():-99")), + cms.PSet( name = cms.string("LepGood_tracker_layers"), expr = cms.string("?innerTrack.isNonnull()?innerTrack().hitPattern().trackerLayersWithMeasurement():-99")), + cms.PSet( name = cms.string("LepGood_pt"), expr = cms.string("pt")), + cms.PSet( name = cms.string("LepGood_eta"), expr = cms.string("eta")), + ) ) + + + + + slimmedMuonsWithUserData = cms.EDProducer("PATMuonUserDataEmbedder", src = cms.InputTag("slimmedMuonsUpdated"), userFloats = cms.PSet( @@ -87,24 +92,23 @@ muonMVATTH= cms.EDProducer("MuonBaseMVAValueMapProducer", src = cms.InputTag("linkedObjects","muons"), weightFile = cms.FileInPath("PhysicsTools/NanoAOD/data/mu_BDTG_2017.weights.xml"), + backend = cms.string("TMVA"), name = cms.string("muonMVATTH"), isClassifier = cms.bool(True), - variablesOrder = cms.vstring(["LepGood_pt","LepGood_eta","LepGood_jetNDauChargedMVASel","LepGood_miniRelIsoCharged","LepGood_miniRelIsoNeutral","LepGood_jetPtRelv2","LepGood_jetDF","LepGood_jetPtRatio","LepGood_dxy","LepGood_sip3d","LepGood_dz","LepGood_segmentComp"]), - variables = cms.PSet( - LepGood_pt = cms.string("pt"), - LepGood_eta = cms.string("eta"), - LepGood_jetNDauChargedMVASel = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0"), - LepGood_miniRelIsoCharged = cms.string("userFloat('miniIsoChg')/pt"), - LepGood_miniRelIsoNeutral = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt"), - LepGood_jetPtRelv2 = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0"), - LepGood_jetDF = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0"), - LepGood_jetPtRatio = cms.string("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt)"), - LepGood_dxy = cms.string("log(abs(dB('PV2D')))"), - LepGood_sip3d = cms.string("abs(dB('PV3D')/edB('PV3D'))"), - LepGood_dz = cms.string("log(abs(dB('PVDZ')))"), - LepGood_segmentComp = cms.string("segmentCompatibility"), - - ) + variables = cms.VPSet( + cms.PSet( name = cms.string("LepGood_pt"), expr = cms.string("pt")), + cms.PSet( name = cms.string("LepGood_eta"), expr = cms.string("eta")), + cms.PSet( name = cms.string("LepGood_jetNDauChargedMVASel"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('jetNDauChargedMVASel'):0")), + cms.PSet( name = cms.string("LepGood_miniRelIsoCharged"), expr = cms.string("userFloat('miniIsoChg')/pt")), + cms.PSet( name = cms.string("LepGood_miniRelIsoNeutral"), expr = cms.string("(userFloat('miniIsoAll')-userFloat('miniIsoChg'))/pt")), + cms.PSet( name = cms.string("LepGood_jetPtRelv2"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?userFloat('ptRel'):0")), + cms.PSet( name = cms.string("LepGood_jetDF"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0")), + cms.PSet( name = cms.string("LepGood_jetPtRatio"), expr = cms.string("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt)")), + cms.PSet( name = cms.string("LepGood_dxy"), expr = cms.string("log(abs(dB('PV2D')))")), + cms.PSet( name = cms.string("LepGood_sip3d"), expr = cms.string("abs(dB('PV3D')/edB('PV3D'))")), + cms.PSet( name = cms.string("LepGood_dz"), expr = cms.string("log(abs(dB('PVDZ')))")), + cms.PSet( name = cms.string("LepGood_segmentComp"), expr = cms.string("segmentCompatibility")), + ) ) muonMVALowPt = muonMVATTH.clone( diff --git a/PhysicsTools/PatAlgos/interface/BaseMVAValueMapProducer.h b/PhysicsTools/PatAlgos/interface/BaseMVAValueMapProducer.h index c501a444736f9..a533dfe5b1bf0 100644 --- a/PhysicsTools/PatAlgos/interface/BaseMVAValueMapProducer.h +++ b/PhysicsTools/PatAlgos/interface/BaseMVAValueMapProducer.h @@ -86,36 +86,32 @@ class BaseMVAValueMapProducer : public edm::stream::EDProducer>(iConfig.getParameter("src"))), - variablesOrder_(iConfig.getParameter>("variablesOrder")), name_(iConfig.getParameter("name")), backend_(iConfig.getParameter("backend")), weightfilename_(iConfig.getParameter("weightFile").fullPath()), - isClassifier_(iConfig.getParameter("isClassifier")), tmva_(backend_ == "TMVA"), tf_(backend_ == "TF"), onnx_(backend_ == "ONNX"), batch_eval_(iConfig.getParameter("batch_eval")) { - if (!(tmva_ || tf_ || onnx_)) { - throw cms::Exception("ConfigError") << "Only 'TF', 'ONNX' and 'TMVA' backends are supported\n"; - } - - if (tmva_) + if (tmva_) { reader_ = new TMVA::Reader(); - edm::ParameterSet const& varsPSet = iConfig.getParameter("variables"); - for (const std::string& vname : varsPSet.getParameterNamesForType()) { - funcs_.emplace_back( - std::pair>(vname, varsPSet.getParameter(vname))); + isClassifier_ = iConfig.getParameter("isClassifier"); } - values_.resize(variablesOrder_.size()); + std::vector const& varsPSet = iConfig.getParameter>("variables"); + values_.resize(varsPSet.size()); size_t i = 0; - for (const auto& v : variablesOrder_) { - positions_[v] = i; + for (const edm::ParameterSet& var_pset : varsPSet) { + const std::string& vname = var_pset.getParameter("name"); + if (var_pset.existsAs("expr")) + funcs_.emplace_back( + std::pair>(vname, var_pset.getParameter("expr"))); + positions_[vname] = i; if (tmva_) - reader_->AddVariable(v, (&values_.front()) + i); + reader_->AddVariable(vname, (&values_.front()) + i); i++; } - // reader_.BookMVA(name_,iConfig.getParameter("weightFile").fullPath() ); + if (tmva_) { reco::details::loadTMVAWeights(reader_, name_, weightfilename_); } @@ -161,7 +157,6 @@ class BaseMVAValueMapProducer : public edm::stream::EDProducer> src_; std::map positions_; std::vector>> funcs_; - std::vector variablesOrder_; std::vector values_; TMVA::Reader* reader_; @@ -276,9 +271,12 @@ void BaseMVAValueMapProducer::produce(edm::Event& iEvent, const edm::EventSet template std::unique_ptr BaseMVAValueMapProducer::initializeGlobalCache(const edm::ParameterSet& cfg) { - return std::make_unique(cfg.getParameter("weightFile").fullPath(), - cfg.getParameter("backend"), - cfg.getParameter("disableONNXGraphOpt")); + std::string backend = cfg.getParameter("backend"); + bool disableONNXGraphOpt = false; + if (backend == "ONNX") + disableONNXGraphOpt = cfg.getParameter("disableONNXGraphOpt"); + return std::make_unique( + cfg.getParameter("weightFile").fullPath(), backend, disableONNXGraphOpt); } template @@ -288,22 +286,40 @@ template edm::ParameterSetDescription BaseMVAValueMapProducer::getDescription() { edm::ParameterSetDescription desc; desc.add("src")->setComment("input physics object collection"); - desc.add>("variablesOrder")->setComment("ordered list of MVA input variable names"); + desc.add("name")->setComment("output score variable name"); - desc.add("isClassifier")->setComment("is a classifier discriminator"); - edm::ParameterSetDescription variables; - variables.setAllowAnything(); - desc.add("variables", variables)->setComment("list of input variable definitions"); - desc.add("weightFile")->setComment("xml weight file"); - desc.add("backend", "TMVA")->setComment("TMVA, TF or ONNX"); - desc.add("inputTensorName", "")->setComment("Name of tensorflow input tensor in the model"); - desc.add("outputTensorName", "")->setComment("Name of tensorflow output tensor in the model"); - desc.add>("outputNames", std::vector()) - ->setComment("Names of the output values to be used in the output valuemap"); - desc.add>("outputFormulas", std::vector()) - ->setComment("Formulas to be used to post process the output"); + desc.add("weightFile")->setComment("xml weight file, or TF/ONNX model file"); desc.add("batch_eval", false)->setComment("Run inference in batch instead of per-object"); - desc.add("disableONNXGraphOpt", false)->setComment("Disable ONNX runtime graph optimization"); + + edm::ParameterSetDescription variable; + variable.add("name")->setComment("name of the variable, either created by expr, or internally by code"); + variable.addOptional("expr")->setComment( + "a function to define the content of the model input, absence of it means the leaf is computed internally"); + variable.setComment("a PSet to define an entry to the ML model"); + desc.addVPSet("variables", variable); + + auto itn = edm::ParameterDescription( + "inputTensorName", "", true, edm::Comment("Name of tensorflow input tensor in the model")); + auto otn = edm::ParameterDescription( + "outputTensorName", "", true, edm::Comment("Name of tensorflow output tensor in the model")); + auto on = edm::ParameterDescription>( + "outputNames", + std::vector(), + true, + edm::Comment("Names of the output values to be used in the output valuemap")); + auto of = edm::ParameterDescription>( + "outputFormulas", + std::vector(), + true, + edm::Comment("Formulas to be used to post process the output")); + auto dog = edm::ParameterDescription( + "disableONNXGraphOpt", false, true, edm::Comment("Disable ONNX runtime graph optimization")); + + desc.ifValue(edm::ParameterDescription( + "backend", "TMVA", true, edm::Comment("the backend to evaluate the model:tmva, tf or onnx")), + "TMVA" >> edm::ParameterDescription( + "isClassifier", true, true, edm::Comment("a classification or regression")) or + "TF" >> (itn and otn and on and of) or "ONNX" >> (itn and otn and on and of and dog)); return desc; }