1 from __future__
import print_function
8 """ Remove pat object production steps which rely on RECO event 11 _label=
'restrictInputToAOD' 12 _defaultParameters=dicttypes.SortedKeysDict()
14 ConfigToolBase.__init__(self)
15 self.addParameter(self.
_defaultParameters,
'names',[
'All'],
"list of collection names; supported are 'Photons', 'Electrons',, 'Muons', 'Taus', 'Jets', 'METs', 'All'", allowedValues=[
'Photons',
'Electrons',
'Muons',
'Taus',
'Jets',
'METs',
'All'])
26 self.setParameter(
'names',names)
31 for obj
in range(len(names)):
32 print(
"---------------------------------------------------------------------")
33 print(
"WARNING: the following additional information can only be used on ")
34 print(
" RECO format:")
35 if( names[obj] ==
'Photons' or names[obj] ==
'All' ):
36 print(
" * nothing needs to be done for Photons")
37 if( names[obj] ==
'Electrons' or names[obj] ==
'All' ):
38 print(
" * nothing needs to be done for Electrons")
39 if( names[obj] ==
'Muons' or names[obj] ==
'All' ):
40 print(
" * nothing needs to be done for Muons")
41 if( names[obj] ==
'Taus' or names[obj] ==
'All' ):
42 print(
" * nothing needs to be done for Taus")
43 if( names[obj] ==
'Jets' or names[obj] ==
'All' ):
44 print(
" * nothing needs to be done for Jets")
45 if( names[obj] ==
'METs' or names[obj] ==
'All' ):
46 print(
" * nothing needs to be done for METs")
47 print(
"---------------------------------------------------------------------")
54 """ Remove monte carlo matching from a given collection or all PAT 55 candidate collections: 57 _label=
'removeMCMatching' 58 _defaultParameters=dicttypes.SortedKeysDict()
60 ConfigToolBase.__init__(self)
61 self.addParameter(self.
_defaultParameters,
'names',[
'All'],
"collection name; supported are 'Photons','Muons', 'Taus', 'Jets', 'METs', 'All', 'PFAll','PFTaus','PFMuons'", allowedValues=[
'Photons',
'Muons',
'Taus',
'Jets',
'METs',
'All',
'PFAll',
'PFTaus',
'PFMuons'])
76 self.setParameter(
'names',names)
77 self.setParameter(
'postfix',postfix)
84 print(
"************** MC dependence removal ************")
85 for obj
in range(len(names)):
86 if( names[obj] ==
'Photons' or names[obj] ==
'All' ):
87 print(
"removing MC dependencies for photons")
89 if( names[obj] ==
'Muons' or names[obj] ==
'All' ):
90 print(
"removing MC dependencies for muons")
92 if( names[obj] ==
'Taus' or names[obj] ==
'All' ):
93 print(
"removing MC dependencies for taus")
96 getattr(process,
"patHeavyIonDefaultSequence"+postfix).
remove(
98 getattr(process,
"patHeavyIonDefaultSequence"+postfix).
remove(
99 applyPostfix(process,
"tauGenJetsSelectorAllHadrons", postfix))
100 getattr(process,
"patHeavyIonDefaultSequence"+postfix).
remove(
103 tauProducer = getattr(process,
'patTaus'+postfix)
104 tauProducer.addGenJetMatch =
False 105 tauProducer.embedGenJetMatch =
False 106 tauProducer.genJetMatch =
'' 107 if( names[obj] ==
'Jets' ):
108 print(
"removing MC dependencies for jets")
110 getattr(process,
"patHeavyIonDefaultSequence"+postfix).
remove(
112 getattr(process,
"patHeavyIonDefaultSequence"+postfix).
remove(
118 jetProducer.addGenPartonMatch =
False 119 jetProducer.embedGenPartonMatch =
False 120 jetProducer.genPartonMatch =
'' 121 jetProducer.addGenJetMatch =
False 122 jetProducer.genJetMatch =
'' 123 jetProducer.getJetMCFlavour =
False 124 jetProducer.JetPartonMapSource =
'' 128 if( names[obj] ==
'METs' or names[obj] ==
'All' ):
130 metProducer = getattr(process,
'patMETs'+postfix)
131 metProducer.addGenMET =
False 132 metProducer.genMETSource =
'' 138 objectMatcher = getattr(process, matcherName+postfix)
139 if (producerName==
'pfPatMuons'or producerName==
'pfPatTaus'):
141 getattr(process,
"PFPATafterPAT"+postfix).
remove(objectMatcher)
142 if (producerName==
'patMuons'or producerName==
'patTaus'or 143 producerName==
'patPhotons' or producerName==
'patElectrons'):
144 getattr(process,
"patHeavyIonDefaultSequence"+postfix).
remove(objectMatcher)
146 objectProducer = getattr(process, producerName+postfix)
147 objectProducer.addGenMatch =
False 148 objectProducer.embedGenMatch =
False 149 objectProducer.genParticleMatch =
'' 154 """ Remove all PAT objects from the default sequence but a specific one 156 _label=
'removeAllPATObjectsBut' 157 _defaultParameters=dicttypes.SortedKeysDict()
159 ConfigToolBase.__init__(self)
160 self.addParameter(self.
_defaultParameters,
'names',self._defaultValue,
"list of collection names; supported are 'Photons', 'Electrons', 'Muons', 'Taus', 'Jets', 'METs'", Type=list, allowedValues=[
'Photons',
'Electrons',
'Muons',
'Taus',
'Jets',
'METs'])
161 self.addParameter(self.
_defaultParameters,
'outputInProcess',
True,
"indicate whether there is an output module specified for the process (default is True) ")
170 outputInProcess =
None) :
173 if outputInProcess
is None:
175 self.setParameter(
'names',names)
176 self.setParameter(
'outputInProcess',outputInProcess)
181 outputInProcess=self.
_parameters[
'outputInProcess'].value
183 removeTheseObjectCollections = [
'Photons',
'Electrons',
'Muons',
'Taus',
'Jets',
'METs']
184 for obj
in range(len(names)):
185 removeTheseObjectCollections.remove(names[obj])
186 removeSpecificPATObjects(process, removeTheseObjectCollections, outputInProcess)
193 """ Remove a specific PAT object from the default sequence 195 _label=
'removeSpecificPATObjects' 196 _defaultParameters=dicttypes.SortedKeysDict()
198 ConfigToolBase.__init__(self)
199 self.addParameter(self.
_defaultParameters,
'names',self._defaultValue,
"list of collection names; supported are 'Photons', 'Electrons', 'Muons', 'Taus', 'Jets', 'METs'", Type=list, allowedValues=[
'Photons',
'Electrons',
'Muons',
'Taus',
'Jets',
'METs'])
200 self.addParameter(self.
_defaultParameters,
'outputInProcess',
True,
"indicate whether there is an output module specified for the process (default is True)" )
201 self.addParameter(self.
_defaultParameters,
'postfix',
"",
"postfix of default sequence")
210 outputInProcess =
None,
214 if outputInProcess
is None:
218 self.setParameter(
'names',names)
219 self.setParameter(
'outputInProcess',outputInProcess)
220 self.setParameter(
'postfix',postfix)
225 outputInProcess=self.
_parameters[
'outputInProcess'].value
229 for obj
in range(len(names)):
230 if( names[obj] ==
'Photons' ):
231 removeIfInSequence(process,
'patPhotonIsolation',
"patHeavyIonDefaultSequence", postfix)
233 if( names[obj] ==
'Muons' ):
235 if( names[obj] ==
'Taus' ):
236 removeIfInSequence(process,
'patPFCandidateIsoDepositSelection',
"patHeavyIonDefaultSequence", postfix)
237 removeIfInSequence(process,
'patPFTauIsolation',
"patHeavyIonDefaultSequence", postfix)
240 removeIfInSequence(process,
'tauGenJetsSelectorAllHadrons',
"patHeavyIonDefaultSequence", postfix)
242 if( names[obj] ==
'Jets' ):
244 removeIfInSequence(process,
'patJetCorrections',
"patHeavyIonDefaultSequence", postfix)
245 removeIfInSequence(process,
'patJetPartonMatch',
"patHeavyIonDefaultSequence", postfix)
246 removeIfInSequence(process,
'patJetGenJetMatch',
"patHeavyIonDefaultSequence", postfix)
248 if( names[obj] ==
'METs' ):
249 removeIfInSequence(process,
'patMETCorrections',
"patHeavyIonDefaultSequence", postfix)
252 if( names[obj] ==
'METs' ):
253 process.patCandidates.remove( getattr(process,
'pat'+names[obj]) )
255 if( names[obj] ==
'Jets' ):
264 getattr(process,
'pat'+names[obj]+postfix) )
266 getattr(process,
'selectedPat'+names[obj]+postfix) )
268 getattr(process,
'countPat'+names[obj]+postfix) )
270 if( names[obj] ==
'Electrons' ):
271 print(
'removed from lepton counter: electrons')
272 applyPostfix(process,
"countPatLeptons",postfix).countElectrons =
False 273 elif( names[obj] ==
'Muons' ):
274 print(
'removed from lepton counter: muons')
275 applyPostfix(process,
"countPatLeptons",postfix).countMuons =
False 276 elif( names[obj] ==
'Taus' ):
277 print(
'removed from lepton counter: taus')
278 applyPostfix(process,
"countPatLeptons",postfix).countTaus =
False 280 if( names[obj] ==
'METs' ):
281 applyPostfix(process,
"patCandidateSummary",postfix).candidates.remove(
282 cms.InputTag(
'pat'+names[obj]+postfix) )
284 if( names[obj] ==
'Jets' ):
285 applyPostfix(process,
"patCandidateSummary",postfix).candidates.remove(
287 applyPostfix(process,
"selectedPatCandidateSummary",postfix).candidates.remove(
289 applyPostfix(process,
"cleanPatCandidateSummary",postfix).candidates.remove(
292 applyPostfix(process,
"patCandidateSummary",postfix).candidates.remove(
293 cms.InputTag(
'pat'+names[obj]+postfix) )
294 applyPostfix(process,
"selectedPatCandidateSummary",postfix).candidates.remove(
295 cms.InputTag(
'selectedPat'+names[obj]+postfix) )
296 getattr(process,
"cleanPatCandidateSummary"+postfix).candidates.remove(
297 cms.InputTag(
'cleanPat'+names[obj]+postfix) )
300 if ( outputInProcess ):
301 print(
"---------------------------------------------------------------------")
302 print(
"INFO : some objects have been removed from the sequence. Switching ")
303 print(
" off PAT cross collection cleaning, as it might be of limited")
304 print(
" sense now. If you still want to keep object collection cross")
305 print(
" cleaning within PAT you need to run and configure it by hand")
306 removeCleaning(process)
314 """ remove PAT cleaning from the default sequence: 316 _label=
'removeCleaning' 317 _defaultParameters=dicttypes.SortedKeysDict()
319 ConfigToolBase.__init__(self)
320 self.addParameter(self.
_defaultParameters,
'outputInProcess',
True,
"indicate whether there is an output module specified for the process (default is True)" )
321 self.addParameter(self.
_defaultParameters,
'postfix',
"",
"postfix of default sequence")
329 outputInProcess =
None,
331 if outputInProcess
is None:
336 self.setParameter(
'outputInProcess',outputInProcess)
337 self.setParameter(
'postfix',postfix)
342 outputInProcess=self.
_parameters[
'outputInProcess'].value
347 if hasattr(m,
'src'): m.src = m.src.value().
replace(
'cleanPat',
'selectedPat')
350 countLept =
applyPostfix(process,
"countPatLeptons",postfix)
351 countLept.electronSource = countLept.electronSource.value().
replace(
'cleanPat',
'selectedPat')
352 countLept.muonSource = countLept.muonSource.value().
replace(
'cleanPat',
'selectedPat')
353 countLept.tauSource = countLept.tauSource.value().
replace(
'cleanPat',
'selectedPat')
354 getattr(process,
"patHeavyIonDefaultSequence"+postfix).
remove(
357 if ( outputInProcess ):
358 print(
"---------------------------------------------------------------------")
359 print(
"INFO : cleaning has been removed. Switch output from clean PAT ")
360 print(
" candidates to selected PAT candidates.")
362 from PhysicsTools.PatAlgos.patEventContent_cff
import patEventContentNoCleaning
363 process.out.outputCommands = patEventContentNoCleaning
371 """ Add PAT cleaning from the default sequence 374 _defaultParameters=dicttypes.SortedKeysDict()
376 ConfigToolBase.__init__(self)
385 outputInProcess =
None):
386 if outputInProcess
is None:
389 self.setParameter(
'outputInProcess',outputInProcess)
393 outputInProcess=self.
_parameters[
'outputInProcess'].value
396 process.patHeavyIonDefaultSequence.replace(process.countPatCandidates, process.cleanPatCandidates * process.countPatCandidates)
398 if hasattr(m,
'src'): m.src = m.src.value().
replace(
'selectedPat',
'cleanPat')
400 countLept = process.countPatLeptons
401 countLept.electronSource = countLept.electronSource.value().
replace(
'selectedPat',
'cleanPat')
402 countLept.muonSource = countLept.muonSource.value().
replace(
'selectedPat',
'cleanPat')
403 countLept.tauSource = countLept.tauSource.value().
replace(
'selectedPat',
'cleanPat')
404 if ( outputInProcess ):
405 print(
"---------------------------------------------------------------------")
406 print(
"INFO : cleaning has been added. Switch output from selected PAT ")
407 print(
" candidates to clean PAT candidates.")
409 from PhysicsTools.PatAlgos.patEventContent_cff
import patEventContent
410 process.out.outputCommands = patEventContent
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
def removeIfInSequence(process, target, sequenceLabel, postfix="")
def applyPostfix(process, label, postfix)
def listModules(sequence)
def jetCollectionString(prefix='', algo='', type='')
def remove(d, key, TELL=False)