CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
egammaGainSwitchFixToolsForPAT_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 def replace_input_tag_module_label(tag,names_to_replace,suffix):
4  if type(tag)==str: #having some problems with things appearing as strings....
5  if tag in names_to_replace:
6  tag = tag+suffix
7  else:
8  if tag.getModuleLabel() in names_to_replace:
9  tag.setModuleLabel(tag.getModuleLabel()+suffix)
10 
11 #replaces all input tags in the module which match modules to replace with that module name + suffix
12 def replace_input_tags(process,modname,pset,modules_to_replace,suffix):
13  for paraname in pset.parameterNames_():
14  para = pset.getParameter(paraname)
15  if para.pythonTypeName()=="cms.PSet":
16  replace_input_tags(process,modname,para,modules_to_replace,suffix)
17  elif para.pythonTypeName()=="cms.VPSet":
18  for newpset in para:
19  replace_input_tags(process,modname,newpset,modules_to_replace,suffix)
20  elif para.pythonTypeName()=="cms.InputTag":
21  replace_input_tag_module_label(para,modules_to_replace,suffix)
22  elif para.pythonTypeName()=="cms.VInputTag":
23  for tag in para:
24  replace_input_tag_module_label(tag,modules_to_replace,suffix)
25 
26 
27 #clones all these egamma pat modules and then updates the tags of these modules
28 #to point to the other cloned modules
29 def miniAOD_addOrginalEGamma(process,suffix):
30  modules_to_clone=["slimmedElectrons",
31  "selectedPatElectrons",
32  "patElectrons",
33  "slimmedPhotons",
34  "selectedPatPhotons",
35  "patPhotons",
36  "reducedEgamma",
37  "egmGsfElectronIDs",
38  "electronMVAValueMapProducer",
39  "electronRegressionValueMapProducer",
40  "egmPhotonIDs",
41  "photonIDValueMapProducer",
42  "photonRegressionValueMapProducer",
43  "photonMVAValueMapProducer",
44  "phPFIsoDepositChargedPAT",
45  "phPFIsoDepositChargedAllPAT",
46  "phPFIsoDepositPUPAT",
47  "phPFIsoDepositNeutralPAT",
48  "phPFIsoDepositGammaPAT",
49  "phPFIsoValueCharged04PFIdPAT",
50  "phPFIsoValueChargedAll04PFIdPAT",
51  "phPFIsoValuePU04PFIdPAT",
52  "phPFIsoValueNeutral04PFIdPAT",
53  "phPFIsoValueGamma04PFIdPAT",
54  "elPFIsoDepositChargedPAT",
55  "elPFIsoDepositChargedAllPAT",
56  "elPFIsoDepositPUPAT",
57  "elPFIsoDepositNeutralPAT",
58  "elPFIsoDepositGammaPAT",
59  "elPFIsoValueCharged04PFIdPAT",
60  "elPFIsoValueChargedAll04PFIdPAT",
61  "elPFIsoValuePU04PFIdPAT",
62  "elPFIsoValueNeutral04PFIdPAT",
63  "elPFIsoValueGamma04PFIdPAT",
64  "elPFIsoValueCharged04NoPFIdPAT",
65  "elPFIsoValueChargedAll04NoPFIdPAT",
66  "elPFIsoValuePU04NoPFIdPAT",
67  "elPFIsoValueNeutral04NoPFIdPAT",
68  "elPFIsoValueGamma04NoPFIdPAT"]
69 
70 
71  for name in modules_to_clone:
72  new_name = name+suffix
73  setattr(process,new_name,getattr(process,name).clone())
74  replace_input_tags(process,new_name,getattr(process,new_name),modules_to_clone,suffix)
75 
76  process.reducedEgammaBeforeGSFix.gsfElectronIDSources = cms.VInputTag(
77  cms.InputTag("eidLoose", processName=cms.InputTag.skipCurrentProcess()),
78  cms.InputTag("eidRobustHighEnergy", processName=cms.InputTag.skipCurrentProcess()),
79  cms.InputTag("eidRobustLoose", processName=cms.InputTag.skipCurrentProcess()),
80  cms.InputTag("eidRobustTight", processName=cms.InputTag.skipCurrentProcess()),
81  cms.InputTag("eidTight", processName=cms.InputTag.skipCurrentProcess()),
82  )
83 
84 
85 
86 
87 def customizeGSFixForPAT(process):
88  process.load("RecoEgamma.EgammaTools.egammaGainSwitchFixForPAT_cff")
89  process.load("RecoParticleFlow.PFProducer.pfGSFixLinkerForPAT_cff")
90  process.load("RecoEgamma.EgammaIsolationAlgos.pfClusterIsolationRemapForPAT_cff")
91  process.load("RecoEgamma.ElectronIdentification.idExternalRemapForPAT_cff")
92  process.load("RecoEgamma.EgammaTools.egammaGainSwitchFlag_cff")
93 
94  #this clones all the modules before they were modified to run on the orginal collections
95  miniAOD_addOrginalEGamma(process,"BeforeGSFix")
96  from PhysicsTools.PatAlgos.tools.helpers import addKeepStatement
97  addKeepStatement(process,'keep *_slimmedElectrons_*_*',
98  ['keep *_reducedEgammaBeforeGSFix_*_*',
99  'keep *_slimmedElectronsBeforeGSFix_*_*',
100  'keep *_slimmedPhotonsBeforeGSFix_*_*',
101  'keep EBDigiCollection_selectDigi_*_*',
102  'keep EEDigiCollection_selectDigi_*_*',
103  'drop *_reducedEgammaBeforeGSFix_reducedGedGsfElectrons_*',
104  'drop *_reducedEgammaBeforeGSFix_reducedGedPhotons_*',
105  'keep *_ecalMultiAndGSGlobalRecHitEB_hitsNotReplaced_*',
106  'keep *_particleFlowEGammaGSFixed_dupECALClusters_*',
107  'keep *_particleFlowEGammaGSFixed_dupESClusters_*',
108  ])
109  process.reducedEgamma.gsfElectrons = cms.InputTag("gedGsfElectronsGSFixed")
110  process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag("particleBasedIsolationGSFixed","gedGsfElectrons")
111  process.reducedEgamma.gsfElectronPFClusterIsoSources = cms.VInputTag(
112  cms.InputTag("electronEcalPFClusterIsolationProducerGSFixed"),
113  cms.InputTag("electronHcalPFClusterIsolationProducerGSFixed"),
114  )
115  process.reducedEgamma.gsfElectronIDSources = cms.VInputTag(
116  cms.InputTag("eidLooseGSFixed"),
117  cms.InputTag("eidRobustHighEnergyGSFixed"),
118  cms.InputTag("eidRobustLooseGSFixed"),
119  cms.InputTag("eidRobustTightGSFixed"),
120  cms.InputTag("eidTightGSFixed"),
121  )
122  process.reducedEgamma.photons = cms.InputTag("gedPhotonsGSFixed")
123  process.reducedEgamma.conversions = cms.InputTag("allConversions", processName=cms.InputTag.skipCurrentProcess())
124  process.reducedEgamma.singleConversions = cms.InputTag("particleFlowEGamma", processName=cms.InputTag.skipCurrentProcess())
125  process.reducedEgamma.photonsPFValMap = cms.InputTag("particleBasedIsolationGSFixed","gedPhotons")
126  process.reducedEgamma.photonPFClusterIsoSources = cms.VInputTag(
127  cms.InputTag("photonEcalPFClusterIsolationProducerGSFixed"),
128  cms.InputTag("photonHcalPFClusterIsolationProducerGSFixed"),
129  )
130  process.reducedEgamma.photonIDSources = cms.VInputTag(
131  cms.InputTag("PhotonCutBasedIDLooseGSFixed"),
132  cms.InputTag("PhotonCutBasedIDLooseEMGSFixed"),
133  cms.InputTag("PhotonCutBasedIDTightGSFixed")
134  )
135  process.reducedEgamma.barrelEcalHits = cms.InputTag("ecalMultiAndGSGlobalRecHitEB")
136  process.reducedEgamma.endcapEcalHits = cms.InputTag("reducedEcalRecHitsEE")
137  process.reducedEgamma.preshowerEcalHits = cms.InputTag("reducedEcalRecHitsES")
138 
139  for modification in process.slimmedPhotons.modifierConfig.modifications:
140  if modification.modifierName != 'EGExtraInfoModifierFromIntValueMaps': continue
141  modification.photon_config.hasGainSwitchFlag = cms.InputTag('PhotonGainSwitchFlagProducer:hasGainSwitchFlag')
142  for modification in process.slimmedElectrons.modifierConfig.modifications:
143  if modification.modifierName != 'EGExtraInfoModifierFromIntValueMaps': continue
144  modification.electron_config.hasGainSwitchFlag = cms.InputTag('ElectronGainSwitchFlagProducer:hasGainSwitchFlag')
145 
146 
147  return process
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def addKeepStatement
Definition: helpers.py:427