Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QGL, JMENanoAOD] Backport of #40667 (PUPPI-compatible QGTagger producer) to 12_6_X #40740

Merged
13 changes: 9 additions & 4 deletions PhysicsTools/NanoAOD/python/custom_jme_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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),
)

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
92 changes: 45 additions & 47 deletions PhysicsTools/NanoAOD/python/nanojmeDQM_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
])

#============================================
Expand Down Expand Up @@ -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'),
])

#============================================
Expand All @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ]

Expand Down
9 changes: 8 additions & 1 deletion RecoJets/JetProducers/interface/QGTagger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <tuple>

#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"
Expand All @@ -23,7 +24,10 @@ class QGTagger : public edm::global::EDProducer<> {

private:
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
std::tuple<int, float, float> calcVariables(const reco::Jet*, edm::Handle<reco::VertexCollection>&, bool) const;
std::tuple<int, float, float> calcVariables(const reco::Jet*,
edm::Handle<reco::VertexCollection>&,
edm::ValueMap<float>&,
bool) const;
template <typename T>
void putInEvent(const std::string&,
const edm::Handle<edm::View<reco::Jet>>&,
Expand All @@ -35,9 +39,12 @@ class QGTagger : public edm::global::EDProducer<> {
edm::EDGetTokenT<reco::JetCorrector> jetCorrectorToken;
edm::EDGetTokenT<reco::VertexCollection> vertexToken;
edm::EDGetTokenT<double> rhoToken;
const bool computeLikelihood;
edm::ESGetToken<QGLikelihoodObject, QGLikelihoodRcd> paramsToken;
edm::ESGetToken<QGLikelihoodSystematicsObject, QGLikelihoodSystematicsRcd> systToken;
const bool useQC, useJetCorr, produceSyst;
bool applyConstituentWeight;
edm::EDGetTokenT<edm::ValueMap<float>> constituentWeightsToken;
QGLikelihoodCalculator qgLikelihood;
};

Expand Down
Loading