1 from __future__
import print_function
2 from builtins
import range
9 """ Remove monte carlo matching from a given collection or all PAT 10 candidate collections and adapt the JEC's: 13 _defaultParameters=dicttypes.SortedKeysDict()
15 ConfigToolBase.__init__(self)
16 self.addParameter(self.
_defaultParameters,
'names',[
'All'],
"collection name; supported are 'Photons', 'Electrons', 'LowPtElectrons', 'Muons', 'Taus', 'TausBoosted', 'Jets', 'METs', 'All', 'PFAll', 'PFElectrons','PFTaus','PFMuons'", allowedValues=[
'Photons',
'Electrons',
'LowPtElectrons',
'Muons',
'Taus',
'TausBoosted',
'Jets',
'METs',
'All',
'PFAll',
'PFElectrons',
'PFTaus',
'PFMuons'])
18 self.addParameter(self.
_defaultParameters,
'outputModules',[
'out'],
"names of all output modules specified to be adapted (default is ['out'])")
28 outputModules =
None) :
33 if outputModules
is None:
35 self.setParameter(
'names',names)
36 self.setParameter(
'postfix',postfix)
37 self.setParameter(
'outputModules',outputModules)
43 outputModules=self.
_parameters[
'outputModules'].value
45 print(
'******************* RunOnData *******************')
46 removeMCMatching(process, names=names, postfix=postfix, outputModules=outputModules)
47 for mod
in process.producerNames().
split():
48 if mod.startswith(
'patJetCorrFactors'):
49 prefix = getattr(process, mod).payload.pythonValue().
replace(
"'",
"")
50 if 'L3Absolute' in getattr(process,mod).levels:
51 if not 'L2L3Residual' in getattr(process,mod).levels:
52 getattr(process,mod).levels.insert(getattr(process,mod).levels.index(
'L3Absolute')+1,
'L2L3Residual')
53 print(
'adding L2L3Residual JEC for:', getattr(process,mod).label_())
54 if hasattr(process, prefix+
'CombinedCorrector'+postfix):
55 if prefix+
'L3Absolute' in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
56 if not prefix+
'L2L3Residual' in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
57 idx = getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.index(prefix+
'L3Absolute')+1
58 getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.insert(idx, prefix+
'L2L3Residual')
59 print(
'adding L2L3Residual for TypeI MET correction:', getattr(process,prefix+
'CombinedCorrector'+postfix).label_())
66 """ Remove monte carlo matching from a given collection or all PAT 67 candidate collections: 69 _label=
'removeMCMatching' 70 _defaultParameters=dicttypes.SortedKeysDict()
72 ConfigToolBase.__init__(self)
74 "collection name; supported are 'Photons', 'OOTPhotons', 'Electrons', 'LowPtElectrons', 'Muons', 'Taus', 'TausBoosted', 'Jets', 'METs', 'All', 'PFAll', 'PFElectrons','PFTaus','PFMuons'",
75 allowedValues=[
'Photons',
'OOTPhotons' ,
'Electrons',
'LowPtElectrons',
'Muons',
'Taus',
'TausBoosted',
'Jets',
'METs',
'All',
'PFAll',
'PFElectrons',
'PFTaus',
'PFMuons'])
77 self.addParameter(self.
_defaultParameters,
'outputModules',[
'out'],
"names of all output modules specified to be adapted (default is ['out'])")
87 outputModules =
None) :
92 if outputModules
is None:
94 self.setParameter(
'names',names)
95 self.setParameter(
'postfix',postfix)
96 self.setParameter(
'outputModules',outputModules)
102 outputModules=self.
_parameters[
'outputModules'].value
104 print(
"************** MC dependence removal ************")
106 for obj
in range(len(names)):
107 if( names[obj] ==
'Photons' or names[obj] ==
'All' ):
108 print(
"removing MC dependencies for photons")
110 if( names[obj] ==
'OOTPhotons' or names[obj] ==
'All' ):
111 print(
"removing MC dependencies for out of time photons")
113 if( names[obj] ==
'Electrons' or names[obj] ==
'All' ):
114 print(
"removing MC dependencies for electrons")
116 if( names[obj] ==
'LowPtElectrons' or names[obj] ==
'All' ):
117 print(
"removing MC dependencies for LowPtElectrons")
119 if( names[obj] ==
'Muons' or names[obj] ==
'All' ):
120 print(
"removing MC dependencies for muons")
122 if( names[obj] ==
'Taus' or names[obj] ==
'All' ):
123 print(
"removing MC dependencies for taus")
126 tauProducer = getattr(process,
'patTaus'+postfix)
127 tauProducer.addGenJetMatch =
False 128 tauProducer.embedGenJetMatch =
False 129 attrsToDelete += [tauProducer.genJetMatch.getModuleLabel()]
130 tauProducer.genJetMatch =
'' 131 attrsToDelete += [
'tauGenJets'+postfix]
132 attrsToDelete += [
'tauGenJetsSelectorAllHadrons'+postfix]
134 if( names[obj] ==
'TausBoosted' or names[obj] ==
'All' ):
135 print(
"removing MC dependencies for taus boosted %s" %postfix)
136 if hasattr(process,
'tauMatchBoosted'+postfix)
and hasattr(process,
'patTausBoosted'+postfix) :
139 tauProducer = getattr(process,
'patTausBoosted'+postfix)
140 tauProducer.addGenJetMatch =
False 141 tauProducer.embedGenJetMatch =
False 142 attrsToDelete += [tauProducer.genJetMatch.getModuleLabel()]
143 tauProducer.genJetMatch =
'' 144 attrsToDelete += [
'tauGenJetsBoosted'+postfix]
145 attrsToDelete += [
'tauGenJetsSelectorAllHadronsBoosted'+postfix]
147 print(
"...skipped since taus boosted %s" %postfix,
"are not part of process.")
148 if( names[obj] ==
'Jets' or names[obj] ==
'All' ):
149 print(
"removing MC dependencies for jets")
151 for mod
in process.producerNames().
split():
152 if mod.startswith(
'patJets')
and getattr(process,mod).type_() ==
"PATJetProducer":
153 jetPostfixes.append(getattr(process, mod).label_().
replace(
"patJets",
""))
154 for pfix
in jetPostfixes:
157 jetProducer.addGenPartonMatch =
False 158 jetProducer.embedGenPartonMatch =
False 160 jetProducer.genPartonMatch =
'' 161 jetProducer.addGenJetMatch =
False 163 jetProducer.genJetMatch =
'' 164 jetProducer.getJetMCFlavour =
False 165 jetProducer.useLegacyJetMCFlavour =
False 166 jetProducer.addJetFlavourInfo =
False 168 jetProducer.JetPartonMapSource =
'' 170 jetProducer.JetFlavourInfoSource =
'' 171 attrsToDelete += [
'slimmedGenJets'+pfix]
173 for outMod
in outputModules:
174 if hasattr(process,outMod):
175 getattr(process,outMod).outputCommands.append(
"drop *_selectedPatJets*_genJets_*")
176 getattr(process,outMod).outputCommands.append(
"drop recoGenJets_*_*_*")
178 raise KeyError(
"process has no OutModule named " + outMod)
180 if( names[obj] ==
'METs' or names[obj] ==
'All' ):
181 for mod
in process.producerNames().
split():
182 if mod.startswith(
'pat')
and getattr(process,mod).type_() ==
"PATMETProducer":
184 metProducer = getattr(process, mod)
185 metProducer.addGenMET =
False 186 attrsToDelete += [metProducer.genMETSource.getModuleLabel()]
187 metProducer.genMETSource =
'' 189 'prunedGenParticles',
190 'prunedGenParticlesWithStatusOne',
191 'packedGenParticles',
192 'packedPFCandidateToGenAssociation',
193 'lostTracksToGenAssociation',
195 for attr
in attrsToDelete:
196 if hasattr(process,attr): delattr(process,attr)
201 if hasattr(process, matcherName+postfix):
202 objectMatcher = getattr(process, matcherName+postfix)
203 if hasattr(process, producerName+postfix):
204 objectProducer = getattr(process, producerName+postfix)
205 objectProducer.addGenMatch =
False 206 objectProducer.embedGenMatch =
False 207 attr = objectProducer.genParticleMatch.getModuleLabel()
208 objectProducer.genParticleMatch =
'' 209 if hasattr(process,attr): delattr(process,attr)
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
def jetCollectionString(prefix='', algo='', type='')