Skip to content

Commit

Permalink
Merge pull request #46523 from colizz/dev-142X-add-GloParT-final
Browse files Browse the repository at this point in the history
Add GloParT inference facility
  • Loading branch information
cmsbuild authored Nov 4, 2024
2 parents 1a3f98b + 243edc6 commit bf7e479
Show file tree
Hide file tree
Showing 12 changed files with 921 additions and 6 deletions.
2 changes: 2 additions & 0 deletions PhysicsTools/NanoAOD/python/custom_jme_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,9 +1298,11 @@ def RecomputePuppiWeightsMETAK8(proc):
from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetMassRegressionOutputs as pfParticleNetMassRegressionOutputs
from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetMassCorrelatedJetTagsAll as pfParticleNetMassCorrelatedJetTagsAll
from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK8_cff import _pfParticleNetFromMiniAODAK8JetTagsAll as pfParticleNetFromMiniAODAK8JetTagsAll
from RecoBTag.ONNXRuntime.pfGlobalParticleTransformerAK8_cff import _pfGlobalParticleTransformerAK8JetTagsAll as pfGlobalParticleTransformerAK8JetTagsAll

btagDiscriminatorsAK8 = cms.PSet(names = cms.vstring(
pfParticleNetMassCorrelatedJetTagsAll+
pfGlobalParticleTransformerAK8JetTagsAll+
pfParticleNetFromMiniAODAK8JetTagsAll+
pfParticleNetJetTagsAll+
pfParticleNetMassRegressionOutputs
Expand Down
32 changes: 30 additions & 2 deletions PhysicsTools/NanoAOD/python/jetsAK8_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@
n2b1 = Var("?hasUserFloat('nb1AK8PuppiSoftDrop:ecfN2')?userFloat('nb1AK8PuppiSoftDrop:ecfN2'):-99999.", float, doc="N2 with beta=1 (for jets with raw pT>250 GeV)", precision=10),
n3b1 = Var("?hasUserFloat('nb1AK8PuppiSoftDrop:ecfN3')?userFloat('nb1AK8PuppiSoftDrop:ecfN3'):-99999.", float, doc="N3 with beta=1 (for jets with raw pT>250 GeV)", precision=10),
msoftdrop = Var("groomedMass('SoftDropPuppi')",float, doc="Corrected soft drop mass with PUPPI",precision=10),
globalParT3_Xbb = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXbb')",float,doc="Mass-decorrelated GlobalParT-3 X->bb score. Note: For sig vs bkg (e.g. bkg=QCD) tagging, use sig/(sig+bkg) to construct the discriminator",precision=10),
globalParT3_Xcc = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXcc')",float,doc="Mass-decorrelated GlobalParT-3 X->cc score",precision=10),
globalParT3_Xcs = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXcs')",float,doc="Mass-decorrelated GlobalParT-3 X->cs score",precision=10),
globalParT3_Xqq = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXqq')",float,doc="Mass-decorrelated GlobalParT-3 X->qq (ss/dd/uu) score",precision=10),
globalParT3_Xtauhtaue = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXtauhtaue')",float,doc="Mass-decorrelated GlobalParT-3 X->tauhtaue score",precision=10),
globalParT3_Xtauhtaum = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXtauhtaum')",float,doc="Mass-decorrelated GlobalParT-3 X->tauhtaum score",precision=10),
globalParT3_Xtauhtauh = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXtauhtauh')",float,doc="Mass-decorrelated GlobalParT-3 X->tauhtauh score",precision=10),
globalParT3_XWW4q = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXWW4q')",float,doc="Mass-decorrelated GlobalParT-3 X->WW4q score",precision=10),
globalParT3_XWW3q = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXWW3q')",float,doc="Mass-decorrelated GlobalParT-3 X->WW3q score",precision=10),
globalParT3_XWWqqev = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXWWqqev')",float,doc="Mass-decorrelated GlobalParT-3 X->WWqqev score",precision=10),
globalParT3_XWWqqmv = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probXWWqqmv')",float,doc="Mass-decorrelated GlobalParT-3 X->WWqqmv score",precision=10),
globalParT3_TopbWqq = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probTopbWqq')",float,doc="Mass-decorrelated GlobalParT-3 Top->bWqq score",precision=10),
globalParT3_TopbWq = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probTopbWq')",float,doc="Mass-decorrelated GlobalParT-3 Top->bWq score",precision=10),
globalParT3_TopbWev = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probTopbWev')",float,doc="Mass-decorrelated GlobalParT-3 Top->bWev score",precision=10),
globalParT3_TopbWmv = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probTopbWmv')",float,doc="Mass-decorrelated GlobalParT-3 Top->bWmv score",precision=10),
globalParT3_TopbWtauhv = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probTopbWtauhv')",float,doc="Mass-decorrelated GlobalParT-3 Top->bWtauhv score",precision=10),
globalParT3_QCD = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probQCD')",float,doc="Mass-decorrelated GlobalParT-3 QCD score.",precision=10),
globalParT3_massCorrX2p = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:massCorrX2p')",float,doc="GlobalParT-3 mass regression corrector with respect to the original jet mass, optimised for resonance 2-prong (bb/cc/cs/ss/qq) jets. Use (massCorrX2p * mass * (1 - rawFactor)) to get the regressed mass",precision=10),
globalParT3_massCorrGeneric = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:massCorrGeneric')",float,doc="GlobalParT-3 mass regression corrector with respect to the original jet mass, optimised for generic jet cases. Use (massCorrGeneric * mass * (1 - rawFactor)) to get the regressed mass",precision=10),
globalParT3_withMassTopvsQCD = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probWithMassTopvsQCD')",float,doc="GlobalParT-3 tagger (w/mass) Top vs QCD discriminator",precision=10),
globalParT3_withMassWvsQCD = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probWithMassWvsQCD')",float,doc="GlobalParT-3 tagger (w/mass) W vs QCD discriminator",precision=10),
globalParT3_withMassZvsQCD = Var("bDiscriminator('pfGlobalParticleTransformerAK8JetTags:probWithMassZvsQCD')",float,doc="GlobalParT-3 tagger (w/mass) Z vs QCD discriminator",precision=10),
particleNetWithMass_QCD = Var("bDiscriminator('pfParticleNetJetTags:probQCDbb')+bDiscriminator('pfParticleNetJetTags:probQCDcc')+bDiscriminator('pfParticleNetJetTags:probQCDb')+bDiscriminator('pfParticleNetJetTags:probQCDc')+bDiscriminator('pfParticleNetJetTags:probQCDothers')",float,doc="ParticleNet tagger (w/ mass) QCD(bb,cc,b,c,others) sum",precision=10),
particleNetWithMass_TvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:TvsQCD')",float,doc="ParticleNet tagger (w/ mass) top vs QCD discriminator",precision=10),
particleNetWithMass_WvsQCD = Var("bDiscriminator('pfParticleNetDiscriminatorsJetTags:WvsQCD')",float,doc="ParticleNet tagger (w/ mass) W vs QCD discriminator",precision=10),
Expand Down Expand Up @@ -147,7 +169,7 @@
## - To be used in nanoAOD_customizeCommon() in nano_cff.py
###############################################################
from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNetMassLegacy, addParticleNet, jecPayload):
def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubleX, addDeepDoubleXV2, addParticleNetMassLegacy, addParticleNet, addGlobalParT, jecPayload):
_btagDiscriminators=[]
if addDeepBTag:
print("Updating process to run DeepCSV btag to AK8 jets")
Expand All @@ -156,6 +178,10 @@ def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubl
print("Updating process to run DeepBoostedJet on datasets before 103X")
from RecoBTag.ONNXRuntime.pfDeepBoostedJet_cff import _pfDeepBoostedJetTagsAll as pfDeepBoostedJetTagsAll
_btagDiscriminators += pfDeepBoostedJetTagsAll
if addGlobalParT:
print("Updating process to run GlobalParT")
from RecoBTag.ONNXRuntime.pfGlobalParticleTransformerAK8_cff import _pfGlobalParticleTransformerAK8JetTagsAll as pfGlobalParticleTransformerAK8JetTagsAll
_btagDiscriminators += pfGlobalParticleTransformerAK8JetTagsAll
if addParticleNet:
print("Updating process to run ParticleNet joint classification and mass regression")
from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK8_cff import _pfParticleNetFromMiniAODAK8JetTagsAll as pfParticleNetFromMiniAODAK8JetTagsAll
Expand Down Expand Up @@ -200,16 +226,18 @@ def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubl
nanoAOD_addDeepDoubleXV2_switch = cms.untracked.bool(False),
nanoAOD_addParticleNetMassLegacy_switch = cms.untracked.bool(False),
nanoAOD_addParticleNet_switch = cms.untracked.bool(False),
nanoAOD_addGlobalParT_switch = cms.untracked.bool(False),
jecPayload = cms.untracked.string('AK8PFPuppi')
)


# ParticleNet legacy jet tagger is already in 106Xv2 MINIAOD,
# add ParticleNet legacy mass regression and new combined tagger + mass regression
# add ParticleNet legacy mass regression, new combined tagger + mass regression, and GlobalParT
run2_nanoAOD_106Xv2.toModify(
nanoAOD_addDeepInfoAK8_switch,
nanoAOD_addParticleNetMassLegacy_switch = True,
nanoAOD_addParticleNet_switch = True,
nanoAOD_addGlobalParT_switch = True,
)

################################################
Expand Down
22 changes: 22 additions & 0 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@
plots = cms.VPSet(
Count1D('_size', 6, -0.5, 5.5, 'slimmedJetsAK8, i.e. ak8 fat jets for boosted analysis'),
Plot1D('area', 'area', 20, 2, 4, 'jet catchment area, for JECs'),
Plot1D('globalParT3_Xbb', 'globalParT3_Xbb', 20, -1, 1, 'GlobalParT-3 X->bb score'),
Plot1D('globalParT3_Xcc', 'globalParT3_Xcc', 20, -1, 1, 'GlobalParT-3 X->cc score'),
Plot1D('globalParT3_Xcs', 'globalParT3_Xcs', 20, -1, 1, 'GlobalParT-3 X->cs score'),
Plot1D('globalParT3_Xqq', 'globalParT3_Xqq', 20, -1, 1, 'GlobalParT-3 X->qq (ss/dd/uu) score'),
Plot1D('globalParT3_Xtauhtaue', 'globalParT3_Xtauhtaue', 20, -1, 1, 'GlobalParT-3 X->tauhtaue score'),
Plot1D('globalParT3_Xtauhtaum', 'globalParT3_Xtauhtaum', 20, -1, 1, 'GlobalParT-3 X->tauhtaum score'),
Plot1D('globalParT3_Xtauhtauh', 'globalParT3_Xtauhtauh', 20, -1, 1, 'GlobalParT-3 X->tauhtauh score'),
Plot1D('globalParT3_XWW4q', 'globalParT3_XWW4q', 20, -1, 1, 'GlobalParT-3 X->WW4q score'),
Plot1D('globalParT3_XWW3q', 'globalParT3_XWW3q', 20, -1, 1, 'GlobalParT-3 X->WW3q score'),
Plot1D('globalParT3_XWWqqev', 'globalParT3_XWWqqev', 20, -1, 1, 'GlobalParT-3 X->WWqqev score'),
Plot1D('globalParT3_XWWqqmv', 'globalParT3_XWWqqmv', 20, -1, 1, 'GlobalParT-3 X->WWqqmv score'),
Plot1D('globalParT3_TopbWqq', 'globalParT3_TopbWqq', 20, -1, 1, 'GlobalParT-3 Top->bWqq score'),
Plot1D('globalParT3_TopbWq', 'globalParT3_TopbWq', 20, -1, 1, 'GlobalParT-3 Top->bWq score'),
Plot1D('globalParT3_TopbWev', 'globalParT3_TopbWev', 20, -1, 1, 'GlobalParT-3 Top->bWev score'),
Plot1D('globalParT3_TopbWmv', 'globalParT3_TopbWmv', 20, -1, 1, 'GlobalParT-3 Top->bWmv score'),
Plot1D('globalParT3_TopbWtauhv', 'globalParT3_TopbWtauhv', 20, -1, 1, 'GlobalParT-3 Top->bWtauhv score'),
Plot1D('globalParT3_QCD', 'globalParT3_QCD', 20, -1, 1, 'GlobalParT-3 QCD score'),
Plot1D('globalParT3_massCorrX2p', 'globalParT3_massCorrX2p', 20, -1, 2, 'GlobalParT-3 mass regression corrector (for X->2-prong jets)'),
Plot1D('globalParT3_massCorrGeneric', 'globalParT3_massCorrGeneric', 20, -1, 2, 'GlobalParT-3 mass regression corrector (for generic cases)'),
Plot1D('globalParT3_withMassTopvsQCD', 'globalParT3_withMassTopvsQCD', 20, -1, 1, 'GlobalParT-3 tagger (mass-correlated) Top vs QCD discriminator'),
Plot1D('globalParT3_withMassWvsQCD', 'globalParT3_withMassWvsQCD', 20, -1, 1, 'GlobalParT-3 tagger (mass-correlated) W vs QCD discriminator'),
Plot1D('globalParT3_withMassZvsQCD', 'globalParT3_withMassZvsQCD', 20, -1, 1, 'GlobalParT-3 tagger (mass-correlated) Z vs QCD discriminator'),
Plot1D('particleNetWithMass_QCD', 'particleNetWithMass_QCD', 20, -1, 1, 'ParticleNet (mass-correlated) QCD score'),
Plot1D('particleNetWithMass_TvsQCD', 'particleNetWithMass_TvsQCD', 20, 0, 1, 'ParticleNet (mass-correlated) top vs. QCD score'),
Plot1D('particleNetWithMass_WvsQCD', 'particleNetWithMass_WvsQCD', 20, 0, 1, 'ParticleNet (mass-correlated) W vs. QCD score'),
Expand Down
1 change: 1 addition & 0 deletions PhysicsTools/NanoAOD/python/nano_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def nanoAOD_customizeCommon(process):
addDeepDoubleXV2=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addDeepDoubleXV2_switch,
addParticleNetMassLegacy=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNetMassLegacy_switch,
addParticleNet=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addParticleNet_switch,
addGlobalParT=nanoAOD_addDeepInfoAK8_switch.nanoAOD_addGlobalParT_switch,
jecPayload=nanoAOD_addDeepInfoAK8_switch.jecPayload
)

Expand Down
14 changes: 13 additions & 1 deletion PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
, 'pfParticleTransformerAK4TagInfos'
# UnifiedParticleTransformerAK4 tag infos
, 'pfUnifiedParticleTransformerAK4TagInfos'
# GlobalParticleTransformerAK8 tag infos
, 'pfGlobalParticleTransformerAK8TagInfos'
# DeepDoubleB/C tag infos
, 'pfDeepDoubleXTagInfos'
# DeepBoostedJet tag infos
Expand Down Expand Up @@ -379,5 +381,15 @@
# update supportedBtagDiscr
for disc in _pfNegativeUnifiedParticleTransformerAK4JetTagsProbs:
supportedBtagDiscr[disc] = [["pfNegativeUnifiedParticleTransformerAK4TagInfos"]]
# -----------------------------------


# -----------------------------------
# setup GlobalParticleTransformer AK8
from RecoBTag.ONNXRuntime.pfGlobalParticleTransformerAK8_cff import _pfGlobalParticleTransformerAK8JetTagsProbs, _pfGlobalParticleTransformerAK8JetTagsMetaDiscrs
# update supportedBtagDiscr
for disc in _pfGlobalParticleTransformerAK8JetTagsProbs:
supportedBtagDiscr[disc] = [["pfGlobalParticleTransformerAK8TagInfos"]]
# update supportedMetaDiscr
for disc in _pfGlobalParticleTransformerAK8JetTagsMetaDiscrs:
supportedMetaDiscr[disc] = _pfGlobalParticleTransformerAK8JetTagsProbs
# -----------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ def applyDeepBtagging(process, postfix=""):
from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetMassRegressionOutputs as pfParticleNetMassRegressionOutputs
from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetMassCorrelatedJetTagsAll as pfParticleNetMassCorrelatedJetTagsAll
from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK8_cff import _pfParticleNetFromMiniAODAK8JetTagsAll as pfParticleNetFromMiniAODAK8JetTagsAll
from RecoBTag.ONNXRuntime.pfGlobalParticleTransformerAK8_cff import _pfGlobalParticleTransformerAK8JetTagsAll as pfGlobalParticleTransformerAK8JetTagsAll

# update slimmed jets to include particle-based deep taggers (keep same name)
# make clone for DeepTags-less slimmed AK8 jets, so output name is preserved
addToProcessAndTask('slimmedJetsAK8NoDeepTags', slimmedJetsAK8.clone(), process, task)
_btagDiscriminatorsAK8 = cms.PSet(names = cms.vstring(pfParticleNetMassCorrelatedJetTagsAll+pfParticleNetFromMiniAODAK8JetTagsAll+pfParticleNetJetTagsAll+pfParticleNetMassRegressionOutputs))
_btagDiscriminatorsAK8 = cms.PSet(names = cms.vstring(pfParticleNetMassCorrelatedJetTagsAll+pfGlobalParticleTransformerAK8JetTagsAll+pfParticleNetFromMiniAODAK8JetTagsAll+pfParticleNetJetTagsAll+pfParticleNetMassRegressionOutputs))
updateJetCollection(
process,
jetSource = cms.InputTag('slimmedJetsAK8NoDeepTags'),
Expand Down
4 changes: 2 additions & 2 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
),
process, task)

if btagInfo == 'pfParticleNetTagInfos':
if btagInfo == 'pfParticleNetTagInfos' or btagInfo == 'pfGlobalParticleTransformerAK8TagInfos':
if pfCandidates.value() == 'packedPFCandidates':
# case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
vertex_associator = ""
Expand All @@ -797,7 +797,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
else:
raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfParticleNetTagInfos.clone(
getattr(btag, btagInfo).clone(
jets = jetSource,
vertices = pvSource,
secondary_vertices = svSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def puppiJetMETReclusterFromMiniAOD(process, runOnMC, useExistingWeights=False,
from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetMassRegressionOutputs as pfParticleNetMassRegressionOutputs
from RecoBTag.ONNXRuntime.pfParticleNet_cff import _pfParticleNetMassCorrelatedJetTagsAll as pfParticleNetMassCorrelatedJetTagsAll
from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK8_cff import _pfParticleNetFromMiniAODAK8JetTagsAll as pfParticleNetFromMiniAODAK8JetTagsAll
from RecoBTag.ONNXRuntime.pfGlobalParticleTransformerAK8_cff import _pfGlobalParticleTransformerAK8JetTagsAll as pfGlobalParticleTransformerAK8JetTagsAll
btagDiscriminatorsAK8 = cms.PSet(names = cms.vstring(
pfParticleNetMassCorrelatedJetTagsAll+
pfGlobalParticleTransformerAK8JetTagsAll+
pfParticleNetFromMiniAODAK8JetTagsAll+
pfParticleNetJetTagsAll+
pfParticleNetMassRegressionOutputs
Expand Down
1 change: 1 addition & 0 deletions RecoBTag/Configuration/python/RecoBTag_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from RecoBTag.ONNXRuntime.pfParticleNetAK4_cff import *
from RecoBTag.ONNXRuntime.pfParticleTransformerAK4_cff import *
from RecoBTag.ONNXRuntime.pfUnifiedParticleTransformerAK4_cff import *
from RecoBTag.ONNXRuntime.pfGlobalParticleTransformerAK8_cff import *
from RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff import *
from RecoBTag.PixelCluster.pixelClusterTagInfos_cfi import *

Expand Down
Loading

0 comments on commit bf7e479

Please sign in to comment.