Skip to content

Commit

Permalink
Provide packedpuppi. Simplify setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
nurfikri89 committed Mar 28, 2023
1 parent e038693 commit dfd4b21
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ def setupSVClustering(btagInfo, svClustering, algo, rParam, fatJets=cms.InputTag
if groomedFatJets != cms.InputTag(''):
btagInfo.groomedFatJets = groomedFatJets

def setupPackedPuppi(process):
task = getPatAlgosToolsTask(process)
packedPuppiName = "packedpuppi"
if not hasattr(process,packedPuppiName):
from CommonTools.PileupAlgos.Puppi_cff import puppi
addToProcessAndTask(packedPuppiName, puppi.clone(
useExistingWeights = True,
candName = 'packedPFCandidates',
vertexName = 'offlineSlimmedPrimaryVertices') , process, task)
return packedPuppiName

def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, tightBTagNTkHits, loadStdRecoBTag, svClustering, fatJets, groomedFatJets,
algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix):
Expand Down Expand Up @@ -605,19 +615,12 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
process, task)


def setupPuppiForBTagging(process):
if not hasattr(process,"packedpuppi"):
from CommonTools.PileupAlgos.Puppi_cff import puppi
addToProcessAndTask('packedpuppi', puppi.clone(
useExistingWeights = True,
candName = 'packedPFCandidates',
vertexName = 'offlineSlimmedPrimaryVertices') , process, task)

if 'pfBoostedDouble' in btagInfo or 'SecondaryVertex' in btagInfo:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
if pfCandidates.value() == 'packedPFCandidates':
_btagInfo.weights = cms.InputTag("packedpuppi")
setupPuppiForBTagging(process)
packedPuppiName = setupPackedPuppi(process)
_btagInfo.weights = cms.InputTag(packedPuppiName)
else:
_btagInfo.weights = cms.InputTag("puppi")

Expand All @@ -630,17 +633,17 @@ def setupPuppiForBTagging(process):
else:
deep_csv_tag_infos = 'pfDeepCSVTagInfos'
flip = False

# use right input tags when running with RECO PF candidates, which actually
# depens of wether jets were slimmed or not (check for s/S-limmed in name)
if not ('limmed' in jetSource.value()):
puppi_value_map = cms.InputTag("puppi")
vertex_associator = cms.InputTag("primaryVertexAssociation","original")
# depens of wether jets use "particleFlow"
if pfCandidates.value() == 'packedPFCandidates':
puppi_value_map = setupPackedPuppi(process)
vertex_associator = cms.InputTag("")
else:
puppi_value_map = cms.InputTag("packedpuppi")
setupPuppiForBTagging(process)
vertex_associator = cms.InputTag("")
puppi_value_map = cms.InputTag("puppi")
vertex_associator = cms.InputTag("primaryVertexAssociation","original")

# If this jet is a puppi jet, then set is_weighted_jet to true.
#
is_weighted_jet = False
if ('puppi' in jetSource.value().lower()):
is_weighted_jet = True
Expand All @@ -660,29 +663,28 @@ def setupPuppiForBTagging(process):
# can only run on PAT jets, so the updater needs to be used
if 'updated' not in jetSource.value().lower():
raise ValueError("Invalid jet collection: %s. pfDeepDoubleXTagInfos only supports running via updateJetCollection." % jetSource.value())
is_weighted_jet = False
if ('puppi' in jetSource.value().lower()):
is_weighted_jet = True
puppi_value_map = cms.InputTag("packedpuppi")
setupPuppiForBTagging(process)
packedPuppiName = setupPackedPuppi(process)
puppi_value_map = cms.InputTag(packedPuppiName)
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepDoubleXTagInfos.clone(
jets = jetSource,
vertices=pvSource,
secondary_vertices=svSource,
shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix),
puppi_value_map = puppi_value_map,
is_weighted_jet = is_weighted_jet
),
process, task)

if btagInfo == 'pfHiggsInteractionNetTagInfos':
packedPuppiName = setupPackedPuppi(process)
puppi_value_map = cms.InputTag(packedPuppiName)
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfHiggsInteractionNetTagInfos.clone(
jets = jetSource,
vertices = pvSource,
secondary_vertices = svSource,
pf_candidates = pfCandidates,
puppi_value_map = puppi_value_map
),
process, task)

Expand All @@ -691,7 +693,7 @@ def setupPuppiForBTagging(process):
# case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
if 'updated' not in jetSource.value().lower():
raise ValueError("Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value())
puppi_value_map = ""
puppi_value_map = setupPackedPuppi(process)
vertex_associator = ""
elif pfCandidates.value() == 'particleFlow':
raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
Expand All @@ -716,7 +718,7 @@ def setupPuppiForBTagging(process):
if btagInfo == 'pfParticleNetTagInfos':
if pfCandidates.value() == 'packedPFCandidates':
# case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
puppi_value_map = ""
puppi_value_map = setupPackedPuppi(process)
vertex_associator = ""
elif pfCandidates.value() == 'particleFlow':
raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
Expand Down Expand Up @@ -748,7 +750,7 @@ def setupPuppiForBTagging(process):
sip3dSigMax = -1
if pfCandidates.value() == 'packedPFCandidates':
# case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
puppi_value_map = ""
puppi_value_map = setupPackedPuppi(process)
vertex_associator = ""
elif pfCandidates.value() == 'particleFlow':
raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
Expand All @@ -757,6 +759,10 @@ def setupPuppiForBTagging(process):
vertex_associator = "primaryVertexAssociation:original"
else:
raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
# If this jet is a Puppi jet, use puppi-weighted p4.
use_puppiP4 = False
if "puppi" in jetSource.value().lower():
use_puppiP4 = True
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfParticleNetAK4TagInfos.clone(
jets = jetSource,
Expand All @@ -767,6 +773,7 @@ def setupPuppiForBTagging(process):
vertex_associator = vertex_associator,
flip_ip_sign = flip_ip_sign,
sip3dSigMax = sip3dSigMax,
use_puppiP4 = use_puppiP4
),
process, task)

Expand Down

0 comments on commit dfd4b21

Please sign in to comment.