From 2fc7b8e8b0ca3cb2688c2490a15b2217144f4434 Mon Sep 17 00:00:00 2001 From: Nurfikri Norjoharuddeen Date: Wed, 1 Feb 2023 18:17:23 +0100 Subject: [PATCH 1/8] Modify to use constituent weights from ValueMap. Add option to compute likelihood --- RecoJets/JetProducers/interface/QGTagger.h | 8 +- RecoJets/JetProducers/plugins/QGTagger.cc | 101 +++++++++++++------ RecoJets/JetProducers/python/QGTagger_cfi.py | 9 +- 3 files changed, 80 insertions(+), 38 deletions(-) diff --git a/RecoJets/JetProducers/interface/QGTagger.h b/RecoJets/JetProducers/interface/QGTagger.h index 231e5a35f48da..8cb4fb383c270 100644 --- a/RecoJets/JetProducers/interface/QGTagger.h +++ b/RecoJets/JetProducers/interface/QGTagger.h @@ -23,7 +23,10 @@ class QGTagger : public edm::global::EDProducer<> { private: void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; - std::tuple calcVariables(const reco::Jet*, edm::Handle&, bool) const; + std::tuple calcVariables(const reco::Jet*, + edm::Handle&, + edm::ValueMap&, + bool) const; template void putInEvent(const std::string&, const edm::Handle>&, @@ -35,9 +38,12 @@ class QGTagger : public edm::global::EDProducer<> { edm::EDGetTokenT jetCorrectorToken; edm::EDGetTokenT vertexToken; edm::EDGetTokenT rhoToken; + const bool computeLikelihood; edm::ESGetToken paramsToken; edm::ESGetToken systToken; const bool useQC, useJetCorr, produceSyst; + bool applyConstituentWeight; + edm::EDGetTokenT> constituentWeightsToken; QGLikelihoodCalculator qgLikelihood; }; diff --git a/RecoJets/JetProducers/plugins/QGTagger.cc b/RecoJets/JetProducers/plugins/QGTagger.cc index a0d16bf769da5..a599e973c28d6 100644 --- a/RecoJets/JetProducers/plugins/QGTagger.cc +++ b/RecoJets/JetProducers/plugins/QGTagger.cc @@ -23,19 +23,31 @@ * Authors: andrea.carlo.marini@cern.ch, tom.cornelis@cern.ch, cms-qg-workinggroup@cern.ch */ QGTagger::QGTagger(const edm::ParameterSet& iConfig) - : jetsToken(consumes>(iConfig.getParameter("srcJets"))), - jetCorrectorToken(consumes(iConfig.getParameter("jec"))), - vertexToken(consumes(iConfig.getParameter("srcVertexCollection"))), - rhoToken(consumes(iConfig.getParameter("srcRho"))), - paramsToken(esConsumes(edm::ESInputTag("", iConfig.getParameter("jetsLabel")))), - useQC(iConfig.getParameter("useQualityCuts")), - useJetCorr(!iConfig.getParameter("jec").label().empty()), - produceSyst(!iConfig.getParameter("systematicsLabel").empty()) { - produces>("qgLikelihood"); + : jetsToken(consumes>(iConfig.getParameter("srcJets"))), + jetCorrectorToken(consumes(iConfig.getParameter("jec"))), + vertexToken(consumes(iConfig.getParameter("srcVertexCollection"))), + rhoToken(consumes(iConfig.getParameter("srcRho"))), + computeLikelihood(iConfig.getParameter("computeLikelihood")), + paramsToken(esConsumes(edm::ESInputTag("", iConfig.getParameter("jetsLabel")))), + useQC(iConfig.getParameter("useQualityCuts")), + useJetCorr(!iConfig.getParameter("jec").label().empty()), + produceSyst(!iConfig.getParameter("systematicsLabel").empty()), + applyConstituentWeight(false) +{ produces>("axis2"); produces>("mult"); produces>("ptD"); - if (produceSyst) { + if (computeLikelihood){ + produces>("qgLikelihood"); + } + + edm::InputTag srcConstituentWeights = iConfig.getParameter("srcConstituentWeights"); + if (!srcConstituentWeights.label().empty()){ + constituentWeightsToken = consumes>(srcConstituentWeights); + applyConstituentWeight = true; + } + + if (computeLikelihood && produceSyst) { systToken = esConsumes(edm::ESInputTag("", iConfig.getParameter("systematicsLabel"))); produces>("qgLikelihoodSmearedQuark"); produces>("qgLikelihoodSmearedGluon"); @@ -63,7 +75,15 @@ void QGTagger::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& edm::Handle rho; iEvent.getByToken(rhoToken, rho); - const auto& QGLParamsColl = iSetup.getData(paramsToken); + edm::ValueMap constituentWeights; + if (applyConstituentWeight){ + constituentWeights = iEvent.get(constituentWeightsToken); + } + + const QGLikelihoodObject* QGLParamsColl = nullptr; + if (computeLikelihood){ + QGLParamsColl = &iSetup.getData(paramsToken); + } const QGLikelihoodSystematicsObject* QGLSystColl = nullptr; if (produceSyst) { @@ -81,17 +101,17 @@ void QGTagger::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& float ptD, axis2; int mult; - std::tie(mult, ptD, axis2) = calcVariables(&*jet, vertexCollection, weAreUsingPackedCandidates); + std::tie(mult, ptD, axis2) = calcVariables(&*jet, vertexCollection, constituentWeights, weAreUsingPackedCandidates); float qgValue; - if (mult > 2) + if (mult > 2 && computeLikelihood) qgValue = - qgLikelihood.computeQGLikelihood(QGLParamsColl, pt, jet->eta(), *rho, {(float)mult, ptD, -std::log(axis2)}); + qgLikelihood.computeQGLikelihood(*QGLParamsColl, pt, jet->eta(), *rho, {(float)mult, ptD, -std::log(axis2)}); else qgValue = -1; qgProduct.push_back(qgValue); - if (produceSyst) { + if (computeLikelihood && produceSyst) { smearedQuarkProduct.push_back(qgLikelihood.systematicSmearing(*QGLSystColl, pt, jet->eta(), *rho, qgValue, 0)); smearedGluonProduct.push_back(qgLikelihood.systematicSmearing(*QGLSystColl, pt, jet->eta(), *rho, qgValue, 1)); smearedAllProduct.push_back(qgLikelihood.systematicSmearing(*QGLSystColl, pt, jet->eta(), *rho, qgValue, 2)); @@ -101,14 +121,16 @@ void QGTagger::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& ptDProduct.push_back(ptD); } - putInEvent("qgLikelihood", jets, qgProduct, iEvent); putInEvent("axis2", jets, axis2Product, iEvent); putInEvent("mult", jets, multProduct, iEvent); putInEvent("ptD", jets, ptDProduct, iEvent); - if (produceSyst) { - putInEvent("qgLikelihoodSmearedQuark", jets, smearedQuarkProduct, iEvent); - putInEvent("qgLikelihoodSmearedGluon", jets, smearedGluonProduct, iEvent); - putInEvent("qgLikelihoodSmearedAll", jets, smearedAllProduct, iEvent); + if (computeLikelihood){ + putInEvent("qgLikelihood", jets, qgProduct, iEvent); + if (produceSyst) { + putInEvent("qgLikelihoodSmearedQuark", jets, smearedQuarkProduct, iEvent); + putInEvent("qgLikelihoodSmearedGluon", jets, smearedGluonProduct, iEvent); + putInEvent("qgLikelihoodSmearedAll", jets, smearedAllProduct, iEvent); + } } } @@ -141,14 +163,23 @@ bool QGTagger::isPackedCandidate(const reco::Jet* jet) const { /// Calculation of axis2, mult and ptD std::tuple QGTagger::calcVariables(const reco::Jet* jet, edm::Handle& vC, + edm::ValueMap& constituentWeights, bool weAreUsingPackedCandidates) const { float sum_weight = 0., sum_deta = 0., sum_dphi = 0., sum_deta2 = 0., sum_dphi2 = 0., sum_detadphi = 0., sum_pt = 0.; - int mult = 0; + + float multWeighted = 0; //Loop over the jet constituents - for (auto daughter : jet->getJetConstituentsQuick()) { + for (auto daughter : jet->getJetConstituents()) { + const reco::Candidate* cand = daughter.get(); + + float constWeight = 1.0; + if (applyConstituentWeight){ + constWeight = constituentWeights[daughter]; + } + if (weAreUsingPackedCandidates) { //packed candidate situation - auto part = static_cast(daughter); + auto part = static_cast(cand); if (part->charge()) { if (!(part->fromPV() > 1 && part->trackHighPurity())) @@ -157,16 +188,16 @@ std::tuple QGTagger::calcVariables(const reco::Jet* jet, if ((part->dz() * part->dz()) / (part->dzError() * part->dzError()) > 25.) continue; if ((part->dxy() * part->dxy()) / (part->dxyError() * part->dxyError()) < 25.) - ++mult; + multWeighted += constWeight; } else - ++mult; + multWeighted += constWeight; } else { - if (part->pt() < 1.0) + if ((constWeight * part->pt()) < 1.0) continue; - ++mult; + multWeighted += constWeight; } } else { - auto part = static_cast(daughter); + auto part = static_cast(cand); reco::TrackRef itrk = part->trackRef(); if (itrk.isNonnull()) { //Track exists --> charged particle @@ -187,19 +218,19 @@ std::tuple QGTagger::calcVariables(const reco::Jet* jet, if (dz * dz / dz_sigma_square > 25.) continue; if (d0 * d0 / d0_sigma_square < 25.) - ++mult; + multWeighted += constWeight; } else - ++mult; + multWeighted += constWeight; } else { //No track --> neutral particle - if (part->pt() < 1.0) + if ((constWeight * part->pt()) < 1.0) continue; //Only use neutrals with pt > 1 GeV - ++mult; + multWeighted += constWeight; } } float deta = daughter->eta() - jet->eta(); float dphi = reco::deltaPhi(daughter->phi(), jet->phi()); - float partPt = daughter->pt(); + float partPt = constWeight * daughter->pt(); float weight = partPt * partPt; sum_weight += weight; @@ -223,6 +254,8 @@ std::tuple QGTagger::calcVariables(const reco::Jet* jet, b = ave_dphi2 - ave_dphi * ave_dphi; c = -(sum_detadphi / sum_weight - ave_deta * ave_dphi); } + + int mult = std::round(multWeighted); float delta = sqrt(fabs((a - b) * (a - b) + 4 * c * c)); float axis2 = (a + b - delta > 0 ? sqrt(0.5 * (a + b - delta)) : 0); float ptD = (sum_weight > 0 ? sqrt(sum_weight) / sum_pt : 0); @@ -234,11 +267,13 @@ void QGTagger::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("srcJets"); desc.add("srcRho"); + desc.add("computeLikelihood"); desc.add("jetsLabel"); desc.add("systematicsLabel", ""); desc.add("useQualityCuts"); desc.add("jec", edm::InputTag())->setComment("Jet correction service: only applied when non-empty"); desc.add("srcVertexCollection")->setComment("Ignored for miniAOD, possible to keep empty"); + desc.add("srcConstituentWeights",edm::InputTag())->setComment("Constituent weights ValueMap"); descriptions.add("QGTagger", desc); } diff --git a/RecoJets/JetProducers/python/QGTagger_cfi.py b/RecoJets/JetProducers/python/QGTagger_cfi.py index c76789cd0a5b6..f5cbcad7d5328 100644 --- a/RecoJets/JetProducers/python/QGTagger_cfi.py +++ b/RecoJets/JetProducers/python/QGTagger_cfi.py @@ -1,11 +1,12 @@ import FWCore.ParameterSet.Config as cms QGTagger = cms.EDProducer('QGTagger', - srcJets = cms.InputTag('ak4PFJetsCHS'), - jetsLabel = cms.string('QGL_AK4PFchs'), - srcRho = cms.InputTag('fixedGridRhoFastjetAll'), + srcJets = cms.InputTag('ak4PFJetsCHS'), + computeLikelihood = cms.bool(True), + jetsLabel = cms.string('QGL_AK4PFchs'), + srcRho = cms.InputTag('fixedGridRhoFastjetAll'), srcVertexCollection = cms.InputTag('offlinePrimaryVerticesWithBS'), - useQualityCuts = cms.bool(False) + useQualityCuts = cms.bool(False), ) QGTaggerTask = cms.Task(QGTagger) From ce1407461c71abaa740ff8102755a6ee1dac2543 Mon Sep 17 00:00:00 2001 From: Nurfikri Norjoharuddeen Date: Wed, 1 Feb 2023 18:28:40 +0100 Subject: [PATCH 2/8] Update QGTagger for puppi jets. Add missing pfDeepCSVJetTags:probudsg score for training to fix bug for btagDeepCvL. Fix isPUPPIJet bug for PileUpJetID. Fix name for ParticleNet gluon score. --- PhysicsTools/NanoAOD/python/custom_jme_cff.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/custom_jme_cff.py b/PhysicsTools/NanoAOD/python/custom_jme_cff.py index 0cb22d4e7c321..c6bf82d5dab86 100644 --- a/PhysicsTools/NanoAOD/python/custom_jme_cff.py +++ b/PhysicsTools/NanoAOD/python/custom_jme_cff.py @@ -21,7 +21,7 @@ import copy bTagCSVV2 = ['pfCombinedInclusiveSecondaryVertexV2BJetTags'] -bTagDeepCSV = ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb','pfDeepCSVJetTags:probc'] +bTagDeepCSV = ['pfDeepCSVJetTags:probb','pfDeepCSVJetTags:probbb','pfDeepCSVJetTags:probc','pfDeepCSVJetTags:probudsg'] bTagDeepJet = [ 'pfDeepFlavourJetTags:probb','pfDeepFlavourJetTags:probbb','pfDeepFlavourJetTags:problepb', 'pfDeepFlavourJetTags:probc','pfDeepFlavourJetTags:probuds','pfDeepFlavourJetTags:probg' @@ -183,7 +183,7 @@ particleNetAK4_CvsL = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4DiscriminatorsJetTags:CvsL'):-1",float,doc="ParticleNetAK4 tagger c vs udsg discriminator",precision=10), particleNetAK4_CvsB = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4DiscriminatorsJetTags:CvsB'):-1",float,doc="ParticleNetAK4 tagger c vs b discriminator",precision=10), particleNetAK4_QvsG = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4DiscriminatorsJetTags:QvsG'):-1",float,doc="ParticleNetAK4 tagger uds vs g discriminator",precision=10), - particleNetAK4_G = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4DiscriminatorsJetTags:probg'):-1",float,doc="ParticleNetAK4 tagger g raw score",precision=10), + particleNetAK4_G = Var("?(pt>=15)?bDiscriminator('pfParticleNetAK4JetTags:probg'):-1",float,doc="ParticleNetAK4 tagger g raw score",precision=10), particleNetAK4_puIdDisc = Var("?(pt>=15)?1-bDiscriminator('pfParticleNetAK4JetTags:probpu'):-1",float,doc="ParticleNetAK4 tagger pileup jet discriminator",precision=10), ) @@ -272,7 +272,7 @@ def AddPileUpJetIDVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName vertexes = "offlineSlimmedPrimaryVertices", inputIsCorrected = True, applyJec = False, - usePuppi = True if "Puppi" in jetName else False + usePuppi = True if "PUPPI" in jetName.upper() else False ) ) getattr(proc,jetTaskName).add(getattr(proc, puJetIdVarsCalculator)) @@ -330,14 +330,19 @@ def AddQGLTaggerVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName=" Schedule the QGTagger module to calculate input variables to the QG likelihood """ + isPUPPIJet = True if "PUPPI" in jetName.upper() else False + QGLTagger="qgtagger{}".format(jetName) patJetWithUserData="{}WithUserData".format(jetSrc) if calculateQGLVars: setattr(proc, QGLTagger, qgtagger.clone( - srcJets = jetSrc + srcJets = jetSrc, + computeLikelihood = False, ) ) + if isPUPPIJet: + getattr(proc,QGLTagger).srcConstituentWeights = cms.InputTag("packedPFCandidatespuppi") # # Save variables as userFloats and userInts for each jet From aeb3c041e9ceb109aa22c57b432c1b1e5cd42f88 Mon Sep 17 00:00:00 2001 From: Nurfikri Norjoharuddeen Date: Wed, 1 Feb 2023 18:29:50 +0100 Subject: [PATCH 3/8] Fine-tune nanojmeDQM --- PhysicsTools/NanoAOD/python/nanojmeDQM_cff.py | 92 +++++++++---------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/nanojmeDQM_cff.py b/PhysicsTools/NanoAOD/python/nanojmeDQM_cff.py index 17ebe27b943dd..4a9ce352b3dbf 100644 --- a/PhysicsTools/NanoAOD/python/nanojmeDQM_cff.py +++ b/PhysicsTools/NanoAOD/python/nanojmeDQM_cff.py @@ -20,40 +20,39 @@ _ak4puppiplots.append(plot) _ak4puppiplots.extend([ - Plot1D('nConstChHads', 'nConstChHads', 20, 14.5, 34.5, 'number of charged hadrons in the jet'), - Plot1D('nConstElecs', 'nConstElecs', 3, -0.5, 2.5, 'number of electrons in the jet'), - Plot1D('nConstHFEMs', 'nConstHFEMs', 1, -0.5, 0.5, 'number of HF EMs in the jet'), - Plot1D('nConstHFHads', 'nConstHFHads', 1, -0.5, 0.5, 'number of HF Hadrons in the jet'), - Plot1D('nConstMuons', 'nConstMuons', 2, -0.5, 1.5, 'number of muons in the jet'), - Plot1D('nConstNeuHads', 'nConstNeuHads', 8, 1.5, 9.5, 'number of neutral hadrons in the jet'), - Plot1D('nConstPhotons', 'nConstPhotons', 16, 5.5, 21.5, 'number of photons in the jet'), - Plot1D('puId_dR2Mean','puId_dR2Mean', 120, -1, 0.2, "pT^2-weighted average square distance of jet constituents from the jet axis (PileUp ID BDT input variable)"), - Plot1D('puId_majW','puId_majW', 70, -1, 0.4, "major axis of jet ellipsoid in eta-phi plane (PileUp ID BDT input variable)"), - Plot1D('puId_minW','puId_minW', 70, -1, 0.4, "minor axis of jet ellipsoid in eta-phi plane (PileUp ID BDT input variable)"), - Plot1D('puId_frac01','puId_frac01', 22, -1, 1, "fraction of constituents' pT contained within dR <0.1 (PileUp ID BDT input variable)"), - Plot1D('puId_frac02','puId_frac02', 22, -1, 1, "fraction of constituents' pT contained within 0.1< dR <0.2 (PileUp ID BDT input variable)"), - Plot1D('puId_frac03','puId_frac03', 22, -1, 1, "fraction of constituents' pT contained within 0.2< dR <0.3 (PileUp ID BDT input variable)"), - Plot1D('puId_frac04','puId_frac04', 22, -1, 1, "fraction of constituents' pT contained within 0.3< dR <0.4 (PileUp ID BDT input variable)"), - Plot1D('puId_ptD','puId_ptD', 20, -1, 1, "pT-weighted average pT of constituents (PileUp ID BDT input variable)"), - Plot1D('puId_beta','puId_beta', 50, -1, 1, "fraction of pT of charged constituents associated to PV (PileUp ID BDT input variable)"), - Plot1D('puId_pull','puId_pull', 208, -1, 0.04, "magnitude of pull vector (PileUp ID BDT input variable)"), - Plot1D('puId_jetR','puId_jetR', 50, -1, 1, "fraction of jet pT carried by the leading constituent (PileUp ID BDT input variable)"), - Plot1D('puId_jetRchg','puId_jetRchg', 50, -1, 1, "fraction of jet pT carried by the leading charged constituent (PileUp ID BDT input variable)"), - Plot1D('puId_nCharged','puId_nCharged', 40, -0.5, 39.5, "number of charged constituents (PileUp ID BDT input variable)"), - Plot1D('qgl_axis2','qgl_axis2', 60, -1, 0.5, "ellipse minor jet axis (Quark vs Gluon likelihood input variable)"), - Plot1D('qgl_ptD','qgl_ptD', 40, -1, 1, "pT-weighted average pT of constituents (Quark vs Gluon likelihood input variable)"), - Plot1D('qgl_mult','qgl_mult', 61, -1.5, 59.5, "PF candidates multiplicity (Quark vs Gluon likelihood input variable)"), + Plot1D('nConstChHads','nConstChHads', 10, 0, 40,'number of charged hadrons in the jet'), + Plot1D('nConstNeuHads','nConstNeuHads', 10, 0, 40,'number of neutral hadrons in the jet'), + Plot1D('nConstPhotons','nConstPhotons', 10, 0, 40,'number of photons in the jet'), + Plot1D('nConstElecs','nConstElecs', 5, 0, 10,'number of electrons in the jet'), + Plot1D('nConstMuons','nConstMuons', 5, 0, 10,'number of muons in the jet'), + Plot1D('nConstHFEMs','nConstHFEMs', 5, 0, 10,'number of HF EMs in the jet'), + Plot1D('nConstHFHads','nConstHFHads', 5, 0, 10,'number of HF Hadrons in the jet'), + Plot1D('puId_dR2Mean','puId_dR2Mean',20, 0, 0.2,"pT^2-weighted average square distance of jet constituents from the jet axis (PileUp ID BDT input variable)"), + Plot1D('puId_majW','puId_majW',10, 0, 0.5, "major axis of jet ellipsoid in eta-phi plane (PileUp ID BDT input variable)"), + Plot1D('puId_minW','puId_minW',10, 0, 0.5, "minor axis of jet ellipsoid in eta-phi plane (PileUp ID BDT input variable)"), + Plot1D('puId_frac01','puId_frac01',10, 0, 1, "fraction of constituents' pT contained within dR <0.1 (PileUp ID BDT input variable)"), + Plot1D('puId_frac02','puId_frac02',10, 0, 1, "fraction of constituents' pT contained within 0.1< dR <0.2 (PileUp ID BDT input variable)"), + Plot1D('puId_frac03','puId_frac03',10, 0, 1, "fraction of constituents' pT contained within 0.2< dR <0.3 (PileUp ID BDT input variable)"), + Plot1D('puId_frac04','puId_frac04',10, 0, 1, "fraction of constituents' pT contained within 0.3< dR <0.4 (PileUp ID BDT input variable)"), + Plot1D('puId_ptD','puId_ptD',10, 0, 1, "pT-weighted average pT of constituents (PileUp ID BDT input variable)"), + Plot1D('puId_beta','puId_beta',10, 0, 1, "fraction of pT of charged constituents associated to PV (PileUp ID BDT input variable)"), + Plot1D('puId_pull','puId_pull',10, 0, 0.05, "magnitude of pull vector (PileUp ID BDT input variable)"), + Plot1D('puId_jetR','puId_jetR',10, 0, 1, "fraction of jet pT carried by the leading constituent (PileUp ID BDT input variable)"), + Plot1D('puId_jetRchg','puId_jetRchg',10, 0, 1, "fraction of jet pT carried by the leading charged constituent (PileUp ID BDT input variable)"), + Plot1D('puId_nCharged','puId_nCharged',10, 0, 40, "number of charged constituents (PileUp ID BDT input variable)"), + Plot1D('qgl_axis2','qgl_axis2',10, 0, 0.4, "ellipse minor jet axis (Quark vs Gluon likelihood input variable)"), + Plot1D('qgl_ptD','qgl_ptD',10, 0, 1, "pT-weighted average pT of constituents (Quark vs Gluon likelihood input variable)"), + Plot1D('qgl_mult','qgl_mult', 10, 0, 50, "PF candidates multiplicity (Quark vs Gluon likelihood input variable)"), Plot1D('btagDeepFlavG','btagDeepFlavG',20, -1, 1, "DeepFlavour gluon tag raw score"), Plot1D('btagDeepFlavUDS','btagDeepFlavUDS',20, -1, 1, "DeepFlavour uds tag raw score"), - Plot1D('btagDeepFlavQG','btagDeepFlavQG',20, -1, 1, "DeepJet g vs uds discriminator"), Plot1D('particleNetAK4_B','particleNetAK4_B',20, -1, 1, "ParticleNetAK4 tagger b vs all (udsg, c) discriminator"), - Plot1D('particleNetAK4_CvsL','particleNetAK4_CvsL',20, -1, 1, "ParticleNetAK4 tagger c vs udsg discriminator"), - Plot1D('particleNetAK4_CvsB','particleNetAK4_CvsB',20, -1, 1, "ParticleNetAK4 tagger c vs b discriminator"), - Plot1D('particleNetAK4_QvsG','particleNetAK4_QvsG',20, -1, 1, "ParticleNetAK4 tagger uds vs g discriminator"), + Plot1D('particleNetAK4_CvsL','particleNetAK4_CvsL',20, -1, 1,"ParticleNetAK4 tagger c vs udsg discriminator"), + Plot1D('particleNetAK4_CvsB','particleNetAK4_CvsB',20, -1, 1,"ParticleNetAK4 tagger c vs b discriminator"), + Plot1D('particleNetAK4_QvsG','particleNetAK4_QvsG',20, -1, 1,"ParticleNetAK4 tagger uds vs g discriminator"), Plot1D('particleNetAK4_G','particleNetAK4_G',20, -1, 1, "ParticleNetAK4 tagger g raw score"), - Plot1D('particleNetAK4_puIdDisc','particleNetAK4_puIdDisc',20, -1, 1, "ParticleNetAK4 tagger pileup jet discriminator"), - Plot1D('hfEmEF', 'hfEmEF', 20, 0, 1, 'electromagnetic energy fraction in HF'), - Plot1D('hfHEF', 'hfHEF', 20, 0, 1, 'hadronic energy fraction in HF'), + Plot1D('particleNetAK4_puIdDisc','particleNetAK4_puIdDisc',20, -1, 1,"ParticleNetAK4 tagger pileup jet discriminator"), + Plot1D('hfEmEF','hfEmEF', 20, 0, 1,'electromagnetic energy fraction in HF'), + Plot1D('hfHEF','hfHEF', 20, 0, 1,'hadronic energy fraction in HF'), ]) #============================================ @@ -97,15 +96,15 @@ # #============================================ nanojmeDQM.vplots.FatJet.plots.extend([ - Plot1D('nConstChHads', 'nConstChHads', 20, 14.5, 34.5, 'number of charged hadrons in the jet'), - Plot1D('nConstElecs', 'nConstElecs', 3, -0.5, 2.5, 'number of electrons in the jet'), - Plot1D('nConstHFEMs', 'nConstHFEMs', 1, -0.5, 0.5, 'number of HF EMs in the jet'), - Plot1D('nConstHFHads', 'nConstHFHads', 1, -0.5, 0.5, 'number of HF Hadrons in the jet'), - Plot1D('nConstMuons', 'nConstMuons', 2, -0.5, 1.5, 'number of muons in the jet'), - Plot1D('nConstNeuHads', 'nConstNeuHads', 8, 1.5, 9.5, 'number of neutral hadrons in the jet'), - Plot1D('nConstPhotons', 'nConstPhotons', 16, 5.5, 21.5, 'number of photons in the jet'), - Plot1D('neEmEF', 'neEmEF', 20, 0.3, 0.4, 'neutral Electromagnetic Energy Fraction'), - Plot1D('neHEF', 'neHEF', 20, 0.01, 0.2, 'neutral Hadron Energy Fraction'), + Plot1D('nConstChHads','nConstChHads',10,0,40,'number of charged hadrons in the jet'), + Plot1D('nConstNeuHads','nConstNeuHads',10,0,40,'number of neutral hadrons in the jet'), + Plot1D('nConstPhotons','nConstPhotons',10,0,40,'number of photons in the jet'), + Plot1D('nConstElecs','nConstElecs',5,0,10,'number of electrons in the jet'), + Plot1D('nConstMuons','nConstMuons',5,0,10,'number of muons in the jet'), + Plot1D('nConstHFEMs','nConstHFEMs',5,0,10,'number of HF EMs in the jet'), + Plot1D('nConstHFHads','nConstHFHads',5,0,10,'number of HF Hadrons in the jet'), + Plot1D('neEmEF','neEmEF',20, 0, 1,'neutral Electromagnetic Energy Fraction'), + Plot1D('neHEF','neHEF',20, 0, 1,'neutral Hadron Energy Fraction'), ]) #============================================ @@ -127,14 +126,13 @@ Plot1D('phi', 'phi', 20, -3.14159, 3.14159, 'phi'), Plot1D('pt', 'pt', 20, 0, 400, 'pt'), Plot1D('rawFactor', 'rawFactor', 20, -0.5, 0.5, '1 - Factor to get back to raw pT'), - Plot1D('nConstChHads', 'nConstChHads', 20, 14.5, 34.5, 'number of charged hadrons in the jet'), - Plot1D('nConstElecs', 'nConstElecs', 3, -0.5, 2.5, 'number of electrons in the jet'), - Plot1D('nConstHFEMs', 'nConstHFEMs', 1, -0.5, 0.5, 'number of HF EMs in the jet'), - Plot1D('nConstHFHads', 'nConstHFHads', 1, -0.5, 0.5, 'number of HF Hadrons in the jet'), - Plot1D('nConstMuons', 'nConstMuons', 2, -0.5, 1.5, 'number of muons in the jet'), - Plot1D('nConstNeuHads', 'nConstNeuHads', 8, 1.5, 9.5, 'number of neutral hadrons in the jet'), - Plot1D('nConstPhotons', 'nConstPhotons', 16, 5.5, 21.5, 'number of photons in the jet'), - Plot1D('nConstituents', 'nConstituents', 20, 0, 80, 'Number of particles in the jet'), + Plot1D('nConstChHads','nConstChHads', 10, 0, 40,'number of charged hadrons in the jet'), + Plot1D('nConstNeuHads','nConstNeuHads', 10, 0, 40,'number of neutral hadrons in the jet'), + Plot1D('nConstPhotons','nConstPhotons', 10, 0, 40,'number of photons in the jet'), + Plot1D('nConstElecs','nConstElecs', 5, 0, 10,'number of electrons in the jet'), + Plot1D('nConstMuons','nConstMuons', 5, 0, 10,'number of muons in the jet'), + Plot1D('nConstHFEMs','nConstHFEMs', 5, 0, 10,'number of HF EMs in the jet'), + Plot1D('nConstHFHads','nConstHFHads', 5, 0, 10,'number of HF Hadrons in the jet'), Plot1D('nElectrons', 'nElectrons', 5, -0.5, 4.5, 'number of electrons in the jet'), Plot1D('nMuons', 'nMuons', 4, -0.5, 3.5, 'number of muons in the jet'), Plot1D('hadronFlavour', 'hadronFlavour', 6, -0.5, 5.5, 'flavour from hadron ghost clustering'), From 368720ef8d2d0c82da0a821c431319db0e2fbed9 Mon Sep 17 00:00:00 2001 From: Nurfikri Norjoharuddeen Date: Thu, 2 Feb 2023 10:04:03 +0100 Subject: [PATCH 4/8] Apply patches for code-checks and code-format --- RecoJets/JetProducers/plugins/QGTagger.cc | 39 +++++++++++------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/RecoJets/JetProducers/plugins/QGTagger.cc b/RecoJets/JetProducers/plugins/QGTagger.cc index a599e973c28d6..4509418167ee8 100644 --- a/RecoJets/JetProducers/plugins/QGTagger.cc +++ b/RecoJets/JetProducers/plugins/QGTagger.cc @@ -23,26 +23,25 @@ * Authors: andrea.carlo.marini@cern.ch, tom.cornelis@cern.ch, cms-qg-workinggroup@cern.ch */ QGTagger::QGTagger(const edm::ParameterSet& iConfig) - : jetsToken(consumes>(iConfig.getParameter("srcJets"))), - jetCorrectorToken(consumes(iConfig.getParameter("jec"))), - vertexToken(consumes(iConfig.getParameter("srcVertexCollection"))), - rhoToken(consumes(iConfig.getParameter("srcRho"))), - computeLikelihood(iConfig.getParameter("computeLikelihood")), - paramsToken(esConsumes(edm::ESInputTag("", iConfig.getParameter("jetsLabel")))), - useQC(iConfig.getParameter("useQualityCuts")), - useJetCorr(!iConfig.getParameter("jec").label().empty()), - produceSyst(!iConfig.getParameter("systematicsLabel").empty()), - applyConstituentWeight(false) -{ + : jetsToken(consumes>(iConfig.getParameter("srcJets"))), + jetCorrectorToken(consumes(iConfig.getParameter("jec"))), + vertexToken(consumes(iConfig.getParameter("srcVertexCollection"))), + rhoToken(consumes(iConfig.getParameter("srcRho"))), + computeLikelihood(iConfig.getParameter("computeLikelihood")), + paramsToken(esConsumes(edm::ESInputTag("", iConfig.getParameter("jetsLabel")))), + useQC(iConfig.getParameter("useQualityCuts")), + useJetCorr(!iConfig.getParameter("jec").label().empty()), + produceSyst(!iConfig.getParameter("systematicsLabel").empty()), + applyConstituentWeight(false) { produces>("axis2"); produces>("mult"); produces>("ptD"); - if (computeLikelihood){ + if (computeLikelihood) { produces>("qgLikelihood"); } edm::InputTag srcConstituentWeights = iConfig.getParameter("srcConstituentWeights"); - if (!srcConstituentWeights.label().empty()){ + if (!srcConstituentWeights.label().empty()) { constituentWeightsToken = consumes>(srcConstituentWeights); applyConstituentWeight = true; } @@ -76,12 +75,12 @@ void QGTagger::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iEvent.getByToken(rhoToken, rho); edm::ValueMap constituentWeights; - if (applyConstituentWeight){ + if (applyConstituentWeight) { constituentWeights = iEvent.get(constituentWeightsToken); } const QGLikelihoodObject* QGLParamsColl = nullptr; - if (computeLikelihood){ + if (computeLikelihood) { QGLParamsColl = &iSetup.getData(paramsToken); } @@ -106,7 +105,7 @@ void QGTagger::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& float qgValue; if (mult > 2 && computeLikelihood) qgValue = - qgLikelihood.computeQGLikelihood(*QGLParamsColl, pt, jet->eta(), *rho, {(float)mult, ptD, -std::log(axis2)}); + qgLikelihood.computeQGLikelihood(*QGLParamsColl, pt, jet->eta(), *rho, {(float)mult, ptD, -std::log(axis2)}); else qgValue = -1; @@ -124,7 +123,7 @@ void QGTagger::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& putInEvent("axis2", jets, axis2Product, iEvent); putInEvent("mult", jets, multProduct, iEvent); putInEvent("ptD", jets, ptDProduct, iEvent); - if (computeLikelihood){ + if (computeLikelihood) { putInEvent("qgLikelihood", jets, qgProduct, iEvent); if (produceSyst) { putInEvent("qgLikelihoodSmearedQuark", jets, smearedQuarkProduct, iEvent); @@ -170,11 +169,11 @@ std::tuple QGTagger::calcVariables(const reco::Jet* jet, float multWeighted = 0; //Loop over the jet constituents - for (auto daughter : jet->getJetConstituents()) { + for (const auto& daughter : jet->getJetConstituents()) { const reco::Candidate* cand = daughter.get(); float constWeight = 1.0; - if (applyConstituentWeight){ + if (applyConstituentWeight) { constWeight = constituentWeights[daughter]; } @@ -273,7 +272,7 @@ void QGTagger::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { desc.add("useQualityCuts"); desc.add("jec", edm::InputTag())->setComment("Jet correction service: only applied when non-empty"); desc.add("srcVertexCollection")->setComment("Ignored for miniAOD, possible to keep empty"); - desc.add("srcConstituentWeights",edm::InputTag())->setComment("Constituent weights ValueMap"); + desc.add("srcConstituentWeights", edm::InputTag())->setComment("Constituent weights ValueMap"); descriptions.add("QGTagger", desc); } From e1f88d9d099e03694fc6d278a210f740bcdc8e27 Mon Sep 17 00:00:00 2001 From: Nurfikri Norjoharuddeen Date: Thu, 2 Feb 2023 16:24:20 +0100 Subject: [PATCH 5/8] Add ValueMap header file --- RecoJets/JetProducers/interface/QGTagger.h | 1 + 1 file changed, 1 insertion(+) diff --git a/RecoJets/JetProducers/interface/QGTagger.h b/RecoJets/JetProducers/interface/QGTagger.h index 8cb4fb383c270..c0bf9e58f23f0 100644 --- a/RecoJets/JetProducers/interface/QGTagger.h +++ b/RecoJets/JetProducers/interface/QGTagger.h @@ -3,6 +3,7 @@ #include #include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/Common/interface/ValueMap.h" #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/global/EDProducer.h" From 5919dbc29b94f67e2a69357822cc43cfafbe84ee Mon Sep 17 00:00:00 2001 From: Nurfikri Norjoharuddeen Date: Tue, 7 Feb 2023 16:21:54 +0100 Subject: [PATCH 6/8] Delete QGTagger_cfi.py. Let QGTagger module to generate one with default fillDescription. --- RecoJets/JetProducers/plugins/QGTagger.cc | 12 ++++++------ RecoJets/JetProducers/python/QGTagger_cfi.py | 12 ------------ 2 files changed, 6 insertions(+), 18 deletions(-) delete mode 100644 RecoJets/JetProducers/python/QGTagger_cfi.py diff --git a/RecoJets/JetProducers/plugins/QGTagger.cc b/RecoJets/JetProducers/plugins/QGTagger.cc index 4509418167ee8..6beff8902e8c2 100644 --- a/RecoJets/JetProducers/plugins/QGTagger.cc +++ b/RecoJets/JetProducers/plugins/QGTagger.cc @@ -264,14 +264,14 @@ std::tuple QGTagger::calcVariables(const reco::Jet* jet, /// Descriptions method void QGTagger::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("srcJets"); - desc.add("srcRho"); - desc.add("computeLikelihood"); - desc.add("jetsLabel"); + desc.add("srcJets",edm::InputTag("ak4PFJetsCHS")); + desc.add("srcRho",edm::InputTag("fixedGridRhoFastjetAll")); + desc.add("computeLikelihood",true); + desc.add("jetsLabel","QGL_AK4PFchs"); desc.add("systematicsLabel", ""); - desc.add("useQualityCuts"); + desc.add("useQualityCuts",false); desc.add("jec", edm::InputTag())->setComment("Jet correction service: only applied when non-empty"); - desc.add("srcVertexCollection")->setComment("Ignored for miniAOD, possible to keep empty"); + desc.add("srcVertexCollection",edm::InputTag("offlinePrimaryVerticesWithBS"))->setComment("Ignored for miniAOD, possible to keep empty"); desc.add("srcConstituentWeights", edm::InputTag())->setComment("Constituent weights ValueMap"); descriptions.add("QGTagger", desc); } diff --git a/RecoJets/JetProducers/python/QGTagger_cfi.py b/RecoJets/JetProducers/python/QGTagger_cfi.py deleted file mode 100644 index f5cbcad7d5328..0000000000000 --- a/RecoJets/JetProducers/python/QGTagger_cfi.py +++ /dev/null @@ -1,12 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -QGTagger = cms.EDProducer('QGTagger', - srcJets = cms.InputTag('ak4PFJetsCHS'), - computeLikelihood = cms.bool(True), - jetsLabel = cms.string('QGL_AK4PFchs'), - srcRho = cms.InputTag('fixedGridRhoFastjetAll'), - srcVertexCollection = cms.InputTag('offlinePrimaryVerticesWithBS'), - useQualityCuts = cms.bool(False), -) - -QGTaggerTask = cms.Task(QGTagger) From 46c95349bdcd3a1bbb21b39fd92026a0aacb9e28 Mon Sep 17 00:00:00 2001 From: Nurfikri Norjoharuddeen Date: Tue, 7 Feb 2023 16:23:24 +0100 Subject: [PATCH 7/8] Add QGTagger module directly into task --- PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 6013ac7b7ffec..0b21e79b4bd10 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -241,7 +241,7 @@ def _add_slimmedMETsNoHF(process): ## Quark Gluon Likelihood process.load('RecoJets.JetProducers.QGTagger_cfi') - task.add(process.QGTaggerTask) + task.add(process.QGTagger) process.patJets.userData.userFloats.src += [ 'QGTagger:qgLikelihood', ] From 193817fe31af48abbc9cef833c8e54879e81d990 Mon Sep 17 00:00:00 2001 From: Nurfikri Norjoharuddeen Date: Tue, 7 Feb 2023 17:51:31 +0100 Subject: [PATCH 8/8] Apply code-format patch --- RecoJets/JetProducers/plugins/QGTagger.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/RecoJets/JetProducers/plugins/QGTagger.cc b/RecoJets/JetProducers/plugins/QGTagger.cc index 6beff8902e8c2..1204cecc3b89c 100644 --- a/RecoJets/JetProducers/plugins/QGTagger.cc +++ b/RecoJets/JetProducers/plugins/QGTagger.cc @@ -264,14 +264,15 @@ std::tuple QGTagger::calcVariables(const reco::Jet* jet, /// Descriptions method void QGTagger::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("srcJets",edm::InputTag("ak4PFJetsCHS")); - desc.add("srcRho",edm::InputTag("fixedGridRhoFastjetAll")); - desc.add("computeLikelihood",true); - desc.add("jetsLabel","QGL_AK4PFchs"); + desc.add("srcJets", edm::InputTag("ak4PFJetsCHS")); + desc.add("srcRho", edm::InputTag("fixedGridRhoFastjetAll")); + desc.add("computeLikelihood", true); + desc.add("jetsLabel", "QGL_AK4PFchs"); desc.add("systematicsLabel", ""); - desc.add("useQualityCuts",false); + desc.add("useQualityCuts", false); desc.add("jec", edm::InputTag())->setComment("Jet correction service: only applied when non-empty"); - desc.add("srcVertexCollection",edm::InputTag("offlinePrimaryVerticesWithBS"))->setComment("Ignored for miniAOD, possible to keep empty"); + desc.add("srcVertexCollection", edm::InputTag("offlinePrimaryVerticesWithBS")) + ->setComment("Ignored for miniAOD, possible to keep empty"); desc.add("srcConstituentWeights", edm::InputTag())->setComment("Constituent weights ValueMap"); descriptions.add("QGTagger", desc); }