Skip to content

Commit

Permalink
Merge pull request #14744 from slava77/CMSSW_8_1_X_2016-05-31-1100/si…
Browse files Browse the repository at this point in the history
…gn719/noClonesMETPF

remove unnecessary cloning of  particleFlowDisplacedVertex and pfCandidateToVertexAssociation in met corrections
  • Loading branch information
davidlange6 committed Jun 3, 2016
2 parents b2ab068 + 519bd24 commit 0cee4b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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

0 comments on commit 0cee4b2

Please sign in to comment.