7 """ Remove pat object production steps which rely on RECO event
10 _label=
'restrictInputToAOD'
11 _defaultParameters=dicttypes.SortedKeysDict()
13 ConfigToolBase.__init__(self)
14 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'])
25 self.setParameter(
'names',names)
30 for obj
in range(len(names)):
31 print "---------------------------------------------------------------------"
32 print "WARNING: the following additional information can only be used on "
34 if( names[obj] ==
'Photons' or names[obj] ==
'All' ):
35 print " * nothing needs to be done for Photons"
36 if( names[obj] ==
'Electrons' or names[obj] ==
'All' ):
37 print " * nothing needs to be done for Electrons"
38 if( names[obj] ==
'Muons' or names[obj] ==
'All' ):
39 print " * nothing needs to be done for Muons"
40 if( names[obj] ==
'Taus' or names[obj] ==
'All' ):
41 print " * nothing needs to be done for Taus"
42 if( names[obj] ==
'Jets' or names[obj] ==
'All' ):
43 print " * nothing needs to be done for Jets"
44 if( names[obj] ==
'METs' or names[obj] ==
'All' ):
45 print " * nothing needs to be done for METs"
46 print "---------------------------------------------------------------------"
53 """ Remove monte carlo matching from a given collection or all PAT
54 candidate collections and adapt the JEC's:
57 _defaultParameters=dicttypes.SortedKeysDict()
59 ConfigToolBase.__init__(self)
60 self.addParameter(self.
_defaultParameters,
'names',[
'All'],
"collection name; supported are 'Photons', 'Electrons','Muons', 'Taus', 'Jets', 'METs', 'All', 'PFAll', 'PFElectrons','PFTaus','PFMuons'", allowedValues=[
'Photons',
'Electrons',
'Muons',
'Taus',
'Jets',
'METs',
'All',
'PFAll',
'PFElectrons',
'PFTaus',
'PFMuons'])
62 self.addParameter(self.
_defaultParameters,
'outputModules',[
'out'],
"names of all output modules specified to be adapted (default is ['out'])")
72 outputInProcess =
None,
73 outputModules =
None) :
75 if not outputInProcess
is None:
81 if outputModules
is None:
83 self.setParameter(
'names',names)
84 self.setParameter(
'postfix',postfix)
85 self.setParameter(
'outputModules',outputModules)
91 outputModules=self.
_parameters[
'outputModules'].value
93 print '******************* RunOnData *******************'
94 removeMCMatching(process, names=names, postfix=postfix, outputModules=outputModules)
95 for mod
in getattr(process,
'patDefaultSequence'+postfix).moduleNames():
96 if mod.startswith(
'patJetCorrFactors'):
97 prefix = getattr(process, mod).payload.pythonValue().
replace(
"'",
"")
98 if 'L3Absolute' in getattr(process,mod).levels:
99 if not 'L2L3Residual' in getattr(process,mod).levels:
100 getattr(process,mod).levels.insert(getattr(process,mod).levels.index(
'L3Absolute')+1,
'L2L3Residual')
101 print 'adding L2L3Residual JEC for:', getattr(process,mod).label_()
102 if hasattr(process, prefix+
'CombinedCorrector'+postfix):
103 if prefix+
'L3Absolute' in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
104 if not prefix+
'L2L3Residual' in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
105 idx = getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.index(prefix+
'L3Absolute')+1
106 getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.insert(idx, prefix+
'L2L3Residual')
107 print 'adding L2L3Residual for TypeI MET correction:', getattr(process,prefix+
'CombinedCorrector'+postfix).label_()
114 """ Remove monte carlo matching from a given collection or all PAT
115 candidate collections:
117 _label=
'removeMCMatching'
118 _defaultParameters=dicttypes.SortedKeysDict()
120 ConfigToolBase.__init__(self)
121 self.addParameter(self.
_defaultParameters,
'names',[
'All'],
"collection name; supported are 'Photons', 'Electrons','Muons', 'Taus', 'Jets', 'METs', 'All', 'PFAll', 'PFElectrons','PFTaus','PFMuons'", allowedValues=[
'Photons',
'Electrons',
'Muons',
'Taus',
'Jets',
'METs',
'All',
'PFAll',
'PFElectrons',
'PFTaus',
'PFMuons'])
122 self.addParameter(self.
_defaultParameters,
'postfix',
"",
"postfix of default sequence")
123 self.addParameter(self.
_defaultParameters,
'outputInProcess',
True,
"indicates whether the output of the pat tuple should be made persistent or not (legacy)")
124 self.addParameter(self.
_defaultParameters,
'outputModules',[
'out'],
"names of all output modules specified to be adapted (default is ['out'])")
134 outputInProcess =
None,
135 outputModules =
None) :
137 if not outputInProcess
is None:
140 outputInProcess=self.
_parameters[
'outputInProcess'].value
145 if outputModules
is None:
147 self.setParameter(
'names',names)
148 self.setParameter(
'postfix',postfix)
149 self.setParameter(
'outputInProcess', outputInProcess)
150 self.setParameter(
'outputModules',outputModules)
156 outputInProcess=self.
_parameters[
'outputInProcess'].value
157 outputModules=self.
_parameters[
'outputModules'].value
159 if not outputInProcess:
162 print "************** MC dependence removal ************"
163 for obj
in range(len(names)):
164 if( names[obj] ==
'Photons' or names[obj] ==
'All' ):
165 print "removing MC dependencies for photons"
167 if( names[obj] ==
'Electrons' or names[obj] ==
'All' ):
168 print "removing MC dependencies for electrons"
170 if( names[obj] ==
'Muons' or names[obj] ==
'All' ):
171 print "removing MC dependencies for muons"
173 if( names[obj] ==
'Taus' or names[obj] ==
'All' ):
174 print "removing MC dependencies for taus"
177 for mod
in [
'tauGenJets',
'tauGenJetsSelectorAllHadrons',
'tauGenJetMatch']:
178 if hasattr(process,mod+postfix):
179 getattr(process,
'patDefaultSequence'+postfix).
remove(getattr(process,mod+postfix))
181 tauProducer = getattr(process,
'patTaus'+postfix)
182 tauProducer.addGenJetMatch =
False
183 tauProducer.embedGenJetMatch =
False
184 tauProducer.genJetMatch =
''
185 if( names[obj] ==
'Jets' or names[obj] ==
'All' ):
186 print "removing MC dependencies for jets"
190 for mod
in getattr(process,
'patDefaultSequence'+postfix).moduleNames():
191 if mod.startswith(
'patJets'):
192 jetPostfixes.append(getattr(process, mod).label_().
replace(
"patJets",
""))
193 for pfix
in jetPostfixes:
195 for mod
in [
'patJetPartonMatch',
'patJetGenJetMatch',
'patJetFlavourIdLegacy',
'patJetPartonsLegacy',
'patJetPartonAssociationLegacy',
'patJetFlavourAssociationLegacy',
'patJetFlavourId',
'patJetPartons',
'patJetFlavourAssociation']:
196 if hasattr(process,mod+pfix):
197 getattr(process,
'patDefaultSequence'+postfix).
remove(getattr(process,mod+pfix))
200 jetProducer.addGenPartonMatch =
False
201 jetProducer.embedGenPartonMatch =
False
202 jetProducer.genPartonMatch =
''
203 jetProducer.addGenJetMatch =
False
204 jetProducer.genJetMatch =
''
205 jetProducer.getJetMCFlavour =
False
206 jetProducer.useLegacyJetMCFlavour =
False
207 jetProducer.addJetFlavourInfo =
False
208 jetProducer.JetPartonMapSource =
''
209 jetProducer.JetFlavourInfoSource =
''
211 for outMod
in outputModules:
212 if hasattr(process,outMod):
213 getattr(process,outMod).outputCommands.append(
"drop *_selectedPatJets*_genJets_*")
215 raise KeyError,
"process has no OutModule named", outMod
217 if( names[obj] ==
'METs' or names[obj] ==
'All' ):
219 metProducer = getattr(process,
'patMETs'+postfix)
220 metProducer.addGenMET =
False
221 metProducer.genMETSource =
''
227 objectMatcher = getattr(process, matcherName+postfix)
228 if (producerName==
'pfPatMuons'or producerName==
'pfPatTaus'):
230 getattr(process,
"PFPATafterPAT"+postfix).
remove(objectMatcher)
231 if (producerName==
'patMuons'or producerName==
'patTaus'or
232 producerName==
'patPhotons' or producerName==
'patElectrons'):
233 getattr(process,
"patDefaultSequence"+postfix).
remove(objectMatcher)
235 objectProducer = getattr(process, producerName+postfix)
236 objectProducer.addGenMatch =
False
237 objectProducer.embedGenMatch =
False
238 objectProducer.genParticleMatch =
''
243 """ Remove all PAT objects from the default sequence but a specific one
245 _label=
'removeAllPATObjectsBut'
246 _defaultParameters=dicttypes.SortedKeysDict()
248 ConfigToolBase.__init__(self)
249 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'])
250 self.addParameter(self.
_defaultParameters,
'outputModules',[
'out'],
"names of all output modules specified to be adapted (default is ['out'])")
259 outputInProcess =
None,
260 outputModules =
None) :
262 if not outputInProcess
is None:
266 if outputModules
is None:
268 self.setParameter(
'names',names)
269 self.setParameter(
'outputModules',outputModules)
274 outputModules=self.
_parameters[
'outputModules'].value
276 removeTheseObjectCollections = [
'Photons',
'Electrons',
'Muons',
'Taus',
'Jets',
'METs']
277 for obj
in range(len(names)):
278 removeTheseObjectCollections.remove(names[obj])
279 removeSpecificPATObjects(process, removeTheseObjectCollections, outputModules = outputModules)
286 """ Remove a specific PAT object from the default sequence
288 _label=
'removeSpecificPATObjects'
289 _defaultParameters=dicttypes.SortedKeysDict()
291 ConfigToolBase.__init__(self)
292 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'])
293 self.addParameter(self.
_defaultParameters,
'outputModules',[
'out'],
"names of all output modules specified to be adapted (default is ['out'])")
294 self.addParameter(self.
_defaultParameters,
'postfix',
"",
"postfix of default sequence")
303 outputInProcess =
None,
305 outputModules =
None) :
307 if not outputInProcess
is None:
311 if outputModules
is None:
315 self.setParameter(
'names',names)
316 self.setParameter(
'outputModules',outputModules)
317 self.setParameter(
'postfix',postfix)
322 outputModules=self.
_parameters[
'outputModules'].value
326 for obj
in range(len(names)):
327 if( names[obj] ==
'Photons' ):
331 if( names[obj] ==
'Electrons' ):
336 if( names[obj] ==
'Muons' ):
339 if( names[obj] ==
'Taus' ):
340 removeIfInSequence(process,
'patPFCandidateIsoDepositSelection',
"patDefaultSequence", postfix)
344 removeIfInSequence(process,
'tauGenJetsSelectorAllHadrons',
"patDefaultSequence", postfix)
347 if( names[obj] ==
'Jets' ):
354 if( names[obj] ==
'METs' ):
358 if( names[obj] ==
'METs' ):
359 process.patDefaultSequence.remove( getattr(process,
'pat'+names[obj]) )
361 if( names[obj] ==
'Jets' ):
370 getattr(process,
'pat'+names[obj]+postfix) )
372 getattr(process,
'selectedPat'+names[obj]+postfix) )
374 getattr(process,
'countPat'+names[obj]+postfix) )
376 if( names[obj] ==
'Electrons' ):
377 print 'removed from lepton counter: electrons'
378 applyPostfix(process,
"countPatLeptons",postfix).countElectrons =
False
379 elif( names[obj] ==
'Muons' ):
380 print 'removed from lepton counter: muons'
381 applyPostfix(process,
"countPatLeptons",postfix).countMuons =
False
382 elif( names[obj] ==
'Taus' ):
383 print 'removed from lepton counter: taus'
384 applyPostfix(process,
"countPatLeptons",postfix).countTaus =
False
386 if( names[obj] ==
'METs' ):
387 applyPostfix(process,
"patCandidateSummary",postfix).candidates.remove(
388 cms.InputTag(
'pat'+names[obj]+postfix) )
390 if( names[obj] ==
'Jets' ):
391 applyPostfix(process,
"patCandidateSummary",postfix).candidates.remove(
393 applyPostfix(process,
"selectedPatCandidateSummary",postfix).candidates.remove(
395 applyPostfix(process,
"cleanPatCandidateSummary",postfix).candidates.remove(
399 result = [ m.label()[:-len(postfix)]
for m
in listModules( getattr(process,
"patDefaultSequence"+postfix))]
400 result.extend([ m.label()[:-len(postfix)]
for m
in listSequences( getattr(process,
"patDefaultSequence"+postfix))] )
401 if applyPostfix(process,
"patCandidateSummary",postfix)
in result :
402 applyPostfix(process,
"patCandidateSummary",postfix).candidates.remove(
403 cms.InputTag(
'pat'+names[obj]+postfix) )
404 if applyPostfix(process,
"selectedPatCandidateSummary",postfix)
in result :
405 applyPostfix(process,
"selectedPatCandidateSummary",postfix).candidates.remove(
406 cms.InputTag(
'selectedPat'+names[obj]+postfix) )
407 if applyPostfix(process,
"cleanPatCandidateSummary",postfix)
in result :
408 applyPostfix(process,
"cleanPatCandidateSummary",postfix).candidates.remove(
409 cms.InputTag(
'cleanPat'+names[obj]+postfix) )
412 if len(outputModules) > 0:
413 print "---------------------------------------------------------------------"
414 print "INFO : some objects have been removed from the sequence. Switching "
415 print " off PAT cross collection cleaning, as it might be of limited"
416 print " sense now. If you still want to keep object collection cross"
417 print " cleaning within PAT you need to run and configure it by hand"
418 removeCleaning(process,outputModules=outputModules,postfix=postfix)
425 """ remove PAT cleaning from the default sequence:
427 _label=
'removeCleaning'
428 _defaultParameters=dicttypes.SortedKeysDict()
430 ConfigToolBase.__init__(self)
431 self.addParameter(self.
_defaultParameters,
'outputModules',[
'out'],
"names of all output modules specified to be adapted (default is ['out'])")
432 self.addParameter(self.
_defaultParameters,
'postfix',
"",
"postfix of default sequence")
440 outputInProcess =
None,
442 outputModules =
None) :
444 if not outputInProcess
is None:
446 if outputModules
is None:
451 self.setParameter(
'outputModules',outputModules)
452 self.setParameter(
'postfix',postfix)
457 outputModules=self.
_parameters[
'outputModules'].value
462 if hasattr(m,
'src'): m.src = m.src.value().
replace(
'cleanPat',
'selectedPat')
465 countLept =
applyPostfix(process,
"countPatLeptons",postfix)
466 countLept.electronSource = countLept.electronSource.value().
replace(
'cleanPat',
'selectedPat')
467 countLept.muonSource = countLept.muonSource.value().
replace(
'cleanPat',
'selectedPat')
468 countLept.tauSource = countLept.tauSource.value().
replace(
'cleanPat',
'selectedPat')
469 for m
in getattr(process,
"cleanPatCandidates").moduleNames():
470 getattr(process,
"patDefaultSequence"+postfix).
remove(
473 if len(outputModules) > 0:
474 print "------------------------------------------------------------"
475 print "INFO : cleaning has been removed. Switching output from"
476 print " clean PAT candidates to selected PAT candidates."
478 from PhysicsTools.PatAlgos.patEventContent_cff
import patEventContentNoCleaning
479 for outMod
in outputModules:
480 if hasattr(process,outMod):
481 getattr(process,outMod).outputCommands = patEventContentNoCleaning
483 raise KeyError,
"process has no OutModule named", outMod
490 """ Add PAT cleaning from the default sequence
493 _defaultParameters=dicttypes.SortedKeysDict()
495 ConfigToolBase.__init__(self)
496 self.addParameter(self.
_defaultParameters,
'outputModules',[
'out'],
"names of all output modules specified to be adapted (default is ['out'])")
504 outputInProcess =
None,
505 outputModules =
None):
507 if not outputInProcess
is None:
509 if outputModules
is None:
512 self.setParameter(
'outputModules',outputModules)
516 outputModules=self.
_parameters[
'outputModules'].value
519 process.patDefaultSequence.replace(process.countPatCandidates, process.cleanPatCandidates * process.countPatCandidates)
521 if hasattr(m,
'src'): m.src = m.src.value().
replace(
'selectedPat',
'cleanPat')
523 countLept = process.countPatLeptons
524 countLept.electronSource = countLept.electronSource.value().
replace(
'selectedPat',
'cleanPat')
525 countLept.muonSource = countLept.muonSource.value().
replace(
'selectedPat',
'cleanPat')
526 countLept.tauSource = countLept.tauSource.value().
replace(
'selectedPat',
'cleanPat')
527 if len(outputModules) > 0:
528 print "------------------------------------------------------------"
529 print "INFO : cleaning has been added. Switching output from "
530 print " selected PAT candidates to clean PAT candidates."
532 from PhysicsTools.PatAlgos.patEventContent_cff
import patEventContent
533 for outMod
in outputModules:
534 if hasattr(process,outMod):
535 getattr(process,outMod).outputCommands = patEventContent
537 raise KeyError,
"process has no OutModule named", outMod
542 print "-------------------------------------------------------"
543 print " INFO: the option 'outputInProcess' will be deprecated "
544 print " soon:", obj._label
545 print " please use the option 'outputModules' now and "
546 print " specify the names of all needed OutModules in "
547 print " there (default: ['out'])"
548 print "-------------------------------------------------------"
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
perl if(1 lt scalar(@::datatypes))