test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
rerunParticleFlow.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 
3 import FWCore.ParameterSet.Config as cms
4 
5 import PhysicsTools.PatAlgos.tools.helpers as configtools
6 from Configuration.EventContent.EventContent_cff import RECOEventContent
7 
8 import re
9 
10 def loadIfNecessary(process, configFile, module_or_sequenceName):
11  if not hasattr(process, module_or_sequenceName):
12  process.load(configFile)
13 
14 from FWCore.ParameterSet.Modules import _Module
16  def __init__(self):
17  self.modulesNames = []
18 
19  def giveNext(self):
20  return self.nextInChain
21  def givePrev(self):
22  return self.prevInChain
23 
24  def enter(self, visitee):
25  if isinstance(visitee, _Module):
26  self.modulesNames.append(visitee.label())
27 
28  def leave(self, visitee):
29  pass
30 
31  def getModuleNames(self):
32  return self.modulesNames
33 
34 def updateInputTags(process, object, inputProcess):
35  if isinstance(object, cms.InputTag):
36  #print "InputTag: %s" % object
37  keepStatement_regex = r"keep [a-zA-Z0-9*]+_(?P<label>[a-zA-Z0-9*]+)_[a-zA-Z0-9*]+_[a-zA-Z0-9*]+"
38  keepStatement_matcher = re.compile(keepStatement_regex)
39  isStoredInRECO = False
40  for keepStatement in RECOEventContent.outputCommands:
41  keepStatement_match = keepStatement_matcher.match(keepStatement)
42  if keepStatement_match:
43  label = keepStatement_match.group('label')
44  if label == object.getModuleLabel():
45  isStoredInRECO = True
46  isInRerunParticleFlowSequence = False
47  if hasattr(process, "rerunParticleFlowSequenceForPFMuonCleaning"):
48  sequenceVisitor = seqVisitorGetModuleNames()
49  getattr(process, "rerunParticleFlowSequenceForPFMuonCleaning").visit(sequenceVisitor)
50  moduleNames = sequenceVisitor.getModuleNames()
51  for moduleName in moduleNames:
52  if moduleName == object.getModuleLabel():
53  isInRerunParticleFlowSequence = True
54  if isStoredInRECO and not isInRerunParticleFlowSequence:
55  if object.getProcessName() != inputProcess:
56  #print "InputTag: %s --> updating processName = %s" % (object, inputProcess)
57  object.setProcessName(inputProcess)
58  elif isinstance(object, cms.PSet):
59  for attrName in dir(object):
60  attr = getattr(object, attrName)
61  updateInputTags(process, attr, inputProcess)
62  elif isinstance(object, cms.VPSet):
63  for pset in object:
64  for attrName in dir(pset):
65  attr = getattr(pset, attrName)
66  updateInputTags(process, attr, inputProcess)
67 
68 def rerunParticleFlow(process, inputProcess):
69 
70  # load event-setup definitions necessary to rerun particle-flow sequence
71  loadIfNecessary(process, "TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAny_cfi", "SteppingHelixPropagatorAny")
72  loadIfNecessary(process, "CalibTracker.SiPixelESProducers.SiPixelTemplateDBObjectESProducer_cfi", "siPixelTemplateDBObjectESProducer")
73  loadIfNecessary(process, "RecoTracker.MeasurementDet.MeasurementTrackerESProducer_cfi", "MeasurementTracker")
74  loadIfNecessary(process, "RecoLocalCalo.EcalRecAlgos.EcalSeverityLevelESProducer_cfi", "ecalSeverityLevel")
75  loadIfNecessary(process, "RecoEcal.EgammaCoreTools.EcalNextToDeadChannelESProducer_cff", "ecalNextToDeadChannelESProducer")
76  loadIfNecessary(process, "RecoLocalCalo.HcalRecAlgos.hcalRecAlgoESProd_cfi", "hcalRecAlgos")
77 
78  if not hasattr(process, "UpdaterService"):
79  process.UpdaterService = cms.Service("UpdaterService")
80 
81  # load module definitions necessary to rerun particle-flow sequence
82  loadIfNecessary(process, "RecoParticleFlow.PFClusterProducer.particleFlowCluster_cff", "particleFlowCluster")
83  loadIfNecessary(process, "RecoEgamma.EgammaElectronProducers.gsfElectronSequence_cff", "gsfEcalDrivenElectronSequence")
84  loadIfNecessary(process, "RecoParticleFlow.Configuration.RecoParticleFlow_cff", "particleFlowReco")
85  loadIfNecessary(process, "RecoMuon.MuonIsolation.muonPFIsolationValues_cff", "muonPFIsolationSequence")
86 
87  # define complete sequence of all modules necessary to rerun particle-flow algorithm
88  process.rerunParticleFlowSequence = cms.Sequence(
89  process.particleFlowCluster
90  + process.particleFlowTrackWithDisplacedVertex
91  + process.gsfEcalDrivenElectronSequence
92  + process.particleFlowReco
93  + process.particleFlowLinks
94  )
95 
96  # CV: clone sequence and give it a different name so that particle-flow algorithm
97  # can be run using "official" module labels on embedded event later
98  configtools.cloneProcessingSnippet(process, process.rerunParticleFlowSequence, "ForPFMuonCleaning")
99 
100  # CV: run particle-flow algorithm on final RECO muon collection
101  # (rather than running muon reconstruction sequence in steps)
102  process.pfTrackForPFMuonCleaning.MuColl = cms.InputTag('muons')
103  process.particleFlowBlockForPFMuonCleaning.RecMuons = cms.InputTag('muons')
104  process.particleFlowTmpForPFMuonCleaning.muons = cms.InputTag('muons')
105  process.particleFlowForPFMuonCleaning.FillMuonRefs = False
106 
107  # CV: make sure that all particle-flow based isolation is computed wrt. 'particleFlowTmp' collection
108  # (PAT may overwrite configuration parameters to refer to 'particleFlow' instead)
109  configtools.massSearchReplaceAnyInputTag(process.rerunParticleFlowSequenceForPFMuonCleaning, cms.InputTag('particleFlow'), cms.InputTag('particleFlowTmp'))
110 
111  return process.rerunParticleFlowSequenceForPFMuonCleaning
def visit
Retrieve data from a perf suite output (sub) directory, only examines TimeSize at the moment...
dbl *** dir
Definition: mlp_gen.cc:35