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

remove unnecessary cloning of particleFlowDisplacedVertex and pfCandidateToVertexAssociation in met corrections #14744

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions PhysicsTools/PatAlgos/python/tools/helpers.py
Expand Up @@ -190,10 +190,11 @@ def modules(self):
class CloneSequenceVisitor(object):
"""Visitor that travels within a cms.Sequence, and returns a cloned version of the Sequence.
All modules and sequences are cloned and a postfix is added"""
def __init__(self, process, label, postfix, removePostfix=""):
def __init__(self, process, label, postfix, removePostfix="", noClones = []):
self._process = process
self._postfix = postfix
self._removePostfix = removePostfix
self._noClones = noClones
self._moduleLabels = []
self._clonedSequence = cms.Sequence()
setattr(process, self._newLabel(label), self._clonedSequence)
Expand All @@ -202,7 +203,9 @@ def enter(self, visitee):
if isinstance(visitee, cms._Module):
label = visitee.label()
newModule = None
if label in self._moduleLabels: # has the module already been cloned ?
if label in self._noClones: #keep unchanged
newModule = getattr(self._process, label)
elif label in self._moduleLabels: # has the module already been cloned ?
newModule = getattr(self._process, self._newLabel(label))
else:
self._moduleLabels.append(label)
Expand Down Expand Up @@ -303,7 +306,7 @@ def contains(sequence, moduleName):



def cloneProcessingSnippet(process, sequence, postfix, removePostfix=""):
def cloneProcessingSnippet(process, sequence, postfix, removePostfix="", noClones = []):
"""
------------------------------------------------------------------
copy a sequence plus the modules and sequences therein
Expand All @@ -313,7 +316,7 @@ def cloneProcessingSnippet(process, sequence, postfix, removePostfix=""):
"""
result = sequence
if not postfix == "":
visitor = CloneSequenceVisitor(process, sequence.label(), postfix, removePostfix)
visitor = CloneSequenceVisitor(process, sequence.label(), postfix, removePostfix, noClones)
sequence.visit(visitor)
result = visitor.clonedSequence()
return result
Expand Down
Expand Up @@ -413,7 +413,8 @@ def produceMET(self, process, metType, metModuleSequence, postfix):
process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff")

if postfix != "" and metType == "PF" and not hasattr(process, 'pat'+metType+'Met'+postfix):
configtools.cloneProcessingSnippet(process, getattr(process,"producePatPFMETCorrections"), postfix)
noClonesTmp = [ "particleFlowDisplacedVertex", "pfCandidateToVertexAssociation" ]
configtools.cloneProcessingSnippet(process, getattr(process,"producePatPFMETCorrections"), postfix, noClones = noClonesTmp)
setattr(process, 'pat'+metType+'Met'+postfix, getattr(process,'patPFMet' ).clone() )
getattr(process, "patPFMet"+postfix).metSource = cms.InputTag("pfMet"+postfix)
getattr(process, "patPFMet"+postfix).srcPFCands = self._parameters["pfCandCollection"].value
Expand Down Expand Up @@ -471,8 +472,9 @@ def getCorrectedMET(self, process, metType, correctionLevel,produceIntermediateC
}

if postfix != "":
noClonesTmp = [ "particleFlowDisplacedVertex", "pfCandidateToVertexAssociation" ]
if not hasattr(process, "patPFMetT0CorrSequence"+postfix):
configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetT0CorrSequence"), postfix)
configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetT0CorrSequence"), postfix, noClones = noClonesTmp)
if not hasattr(process, "patPFMetT1T2CorrSequence"+postfix):
configtools.cloneProcessingSnippet(process, getattr(process,"patPFMetT1T2CorrSequence"), postfix)
if not hasattr(process, "patPFMetT2CorrSequence"+postfix):
Expand Down