Skip to content

Commit

Permalink
Merge pull request #22345 from cms-met/fixmettool1010_backport94X
Browse files Browse the repository at this point in the history
Fix in MET tool when reclustering jets and MET on the fly [backport]
  • Loading branch information
cmsbuild committed Mar 10, 2018
2 parents a2f8135 + 19f174c commit fb6a408
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 8 additions & 4 deletions PhysicsTools/PatAlgos/python/tools/helpers.py
Expand Up @@ -119,15 +119,19 @@ def applyPostfix(process, label, postfix):
return result

def removeIfInSequence(process, target, sequenceLabel, postfix=""):
labels = __labelsInSequence(process, sequenceLabel, postfix)
labels = __labelsInSequence(process, sequenceLabel, postfix, True)
if target+postfix in labels:
getattr(process, sequenceLabel+postfix).remove(
getattr(process, target+postfix)
)

def __labelsInSequence(process, sequenceLabel, postfix=""):
result = [ m.label()[:-len(postfix)] for m in listModules( getattr(process,sequenceLabel+postfix))]
result.extend([ m.label()[:-len(postfix)] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False):
position = -len(postfix)
if keepPostFix:
position = None

result = [ m.label()[:position] for m in listModules( getattr(process,sequenceLabel+postfix))]
result.extend([ m.label()[:position] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
if postfix == "":
result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))] )
Expand Down
Expand Up @@ -310,6 +310,7 @@ def toolCode(self, process):
self.extractMET(process, "raw", patMetModuleSequence, postfix)

#jet AK4 reclustering if needed for JECs

if reclusterJets:
jetCollectionUnskimmed = self.ak4JetReclustering(process, pfCandCollection,
patMetModuleSequence, postfix)
Expand All @@ -318,7 +319,7 @@ def toolCode(self, process):
if onMiniAOD:
if not reclusterJets and reapplyJEC:
jetCollectionUnskimmed = self.updateJECs(process, jetCollectionUnskimmed, patMetModuleSequence, postfix)


#getting the jet collection that will be used for corrections
#and uncertainty computation
Expand All @@ -328,7 +329,7 @@ def toolCode(self, process):
autoJetCleaning,
patMetModuleSequence,
postfix)

#pre-preparation to run over miniAOD
if onMiniAOD:
self.miniAODConfigurationPre(process, patMetModuleSequence, pfCandCollection, postfix)
Expand Down Expand Up @@ -449,6 +450,7 @@ def produceMET(self, process, metType, metModuleSequence, postfix):
task.add(process.patPFMetT2SmearCorrTask)
task.add(process.patPFMetTxyCorrTask)
task.add(process.jetCorrectorsTask)

if postfix != "" and metType == "PF" and not hasattr(process, 'pat'+metType+'Met'+postfix):
noClonesTmp = [ "particleFlowDisplacedVertex", "pfCandidateToVertexAssociation" ]
configtools.cloneProcessingSnippet(process, getattr(process,"producePatPFMETCorrections"), postfix, noClones = noClonesTmp, addToTask = True)
Expand Down Expand Up @@ -1443,8 +1445,9 @@ def ak4JetReclustering(self,process, pfCandCollection, patMetModuleSequence, pos
pfCHS=None
if self._parameters["onMiniAOD"].value:
pfCHS = cms.EDFilter("CandPtrSelector", src = pfCandCollection, cut = cms.string("fromPV"))
setattr(process,"pfNoPileUpJME"+postfix,pfCHS)
pfCandColl = cms.InputTag("pfNoPileUpJME"+postfix)
addToProcessAndTask("pfNoPileUpJME"+postfix, pfCHS, process, task)
patMetModuleSequence += getattr(process, "pfNoPileUpJME"+postfix)
else:
addToProcessAndTask("tmpPFCandCollPtr"+postfix,
cms.EDProducer("PFCandidateFwdPtrProducer",
Expand All @@ -1459,6 +1462,8 @@ def ak4JetReclustering(self,process, pfCandCollection, patMetModuleSequence, pos
bottomCollection = cms.InputTag("tmpPFCandCollPtr"+postfix) ),
process, task )
pfCandColl = cms.InputTag("pfNoPileUpJME"+postfix)
patMetModuleSequence += getattr(process, "tmpPFCandCollPtr"+postfix)
patMetModuleSequence += getattr(process, "pfNoPileUpJME"+postfix)

jetColName+=postfix
if not hasattr(process, jetColName):
Expand Down Expand Up @@ -1513,10 +1518,11 @@ def miniAODConfigurationPre(self, process, patMetModuleSequence, pfCandCollectio

#extractor for caloMET === temporary for the beginning of the data taking
self.extractMET(process,"rawCalo",patMetModuleSequence,postfix)
caloMetName="metrawCalo" if hasattr(process,"metrawCalo") else "metrawCalo"+postfix
from PhysicsTools.PatAlgos.tools.metTools import addMETCollection
addMETCollection(process,
labelName = "patCaloMet",
metSource = "metrawCalo"
metSource = caloMetName
)
getattr(process,"patCaloMet").addGenMET = False

Expand Down

0 comments on commit fb6a408

Please sign in to comment.