CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
coreTools.py
Go to the documentation of this file.
2 
4 
6 
7  """ Remove pat object production steps which rely on RECO event
8  content
9  """
10  _label='restrictInputToAOD'
11  _defaultParameters=dicttypes.SortedKeysDict()
12  def __init__(self):
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'])
15  self._parameters=copy.deepcopy(self._defaultParameters)
16  self._comment = ""
17 
19  return self._defaultParameters
20 
21  def __call__(self,process,
22  names = None) :
23  if names is None:
24  names=self._defaultParameters['names'].value
25  self.setParameter('names',names)
26  self.apply(process)
27 
28  def toolCode(self, process):
29  names=self._parameters['names'].value
30  for obj in range(len(names)):
31  print "---------------------------------------------------------------------"
32  print "WARNING: the following additional information can only be used on "
33  print " RECO format:"
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 "---------------------------------------------------------------------"
47 
48 restrictInputToAOD=RestrictInputToAOD()
49 
50 
52 
53  """ Remove monte carlo matching from a given collection or all PAT
54  candidate collections and adapt the JEC's:
55  """
56  _label='runOnData'
57  _defaultParameters=dicttypes.SortedKeysDict()
58  def __init__(self):
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'])
61  self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence")
62  self.addParameter(self._defaultParameters,'outputModules',['out'], "names of all output modules specified to be adapted (default is ['out'])")
63  self._parameters=copy.deepcopy(self._defaultParameters)
64  self._comment = ""
65 
67  return self._defaultParameters
68 
69  def __call__(self,process,
70  names = None,
71  postfix = None,
72  outputInProcess = None,
73  outputModules = None) :
74  ## stop processing if 'outputInProcess' exists and show the new alternative
75  if not outputInProcess is None:
77  if names is None:
78  names=self._defaultParameters['names'].value
79  if postfix is None:
80  postfix=self._defaultParameters['postfix'].value
81  if outputModules is None:
82  outputModules=self._defaultParameters['outputModules'].value
83  self.setParameter('names',names)
84  self.setParameter('postfix',postfix)
85  self.setParameter('outputModules',outputModules)
86  self.apply(process)
87 
88  def toolCode(self, process):
89  names=self._parameters['names'].value
90  postfix=self._parameters['postfix'].value
91  outputModules=self._parameters['outputModules'].value
92 
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_()
108 
109 runOnData=RunOnData()
110 
111 
113 
114  """ Remove monte carlo matching from a given collection or all PAT
115  candidate collections:
116  """
117  _label='removeMCMatching'
118  _defaultParameters=dicttypes.SortedKeysDict()
119  def __init__(self):
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'])")
125  self._parameters=copy.deepcopy(self._defaultParameters)
126  self._comment = ""
127 
129  return self._defaultParameters
130 
131  def __call__(self,process,
132  names = None,
133  postfix = None,
134  outputInProcess = None,
135  outputModules = None) :
136  ## stop processing if 'outputInProcess' exists and show the new alternative
137  if not outputInProcess is None:
139  else:
140  outputInProcess=self._parameters['outputInProcess'].value
141  if names is None:
142  names=self._defaultParameters['names'].value
143  if postfix is None:
144  postfix=self._defaultParameters['postfix'].value
145  if outputModules is None:
146  outputModules=self._defaultParameters['outputModules'].value
147  self.setParameter('names',names)
148  self.setParameter('postfix',postfix)
149  self.setParameter('outputInProcess', outputInProcess)
150  self.setParameter('outputModules',outputModules)
151  self.apply(process)
152 
153  def toolCode(self, process):
154  names=self._parameters['names'].value
155  postfix=self._parameters['postfix'].value
156  outputInProcess=self._parameters['outputInProcess'].value
157  outputModules=self._parameters['outputModules'].value
158 
159  if not outputInProcess:
160  outputModules=['']
161 
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"
166  _removeMCMatchingForPATObject(process, 'photonMatch', 'patPhotons', postfix)
167  if( names[obj] == 'Electrons' or names[obj] == 'All' ):
168  print "removing MC dependencies for electrons"
169  _removeMCMatchingForPATObject(process, 'electronMatch', 'patElectrons', postfix)
170  if( names[obj] == 'Muons' or names[obj] == 'All' ):
171  print "removing MC dependencies for muons"
172  _removeMCMatchingForPATObject(process, 'muonMatch', 'patMuons', postfix)
173  if( names[obj] == 'Taus' or names[obj] == 'All' ):
174  print "removing MC dependencies for taus"
175  _removeMCMatchingForPATObject(process, 'tauMatch', 'patTaus', postfix)
176  ## remove mc extra modules 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))
180  ## remove mc extra configs for taus
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"
187  ## there may be multiple jet collection, therefore all jet collections
188  ## in patDefaultSequence+postfix are threated here
189  jetPostfixes = []
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:
194  ## remove mc extra modules for jets
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))
198  ## remove mc extra configs for jets
199  jetProducer = getattr(process, jetCollectionString()+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 = ''
210  ## adjust output
211  for outMod in outputModules:
212  if hasattr(process,outMod):
213  getattr(process,outMod).outputCommands.append("drop *_selectedPatJets*_genJets_*")
214  else:
215  raise KeyError, "process has no OutModule named", outMod
216 
217  if( names[obj] == 'METs' or names[obj] == 'All' ):
218  ## remove mc extra configs for jets
219  metProducer = getattr(process, 'patMETs'+postfix)
220  metProducer.addGenMET = False
221  metProducer.genMETSource = ''
222 
223 removeMCMatching=RemoveMCMatching()
224 
225 def _removeMCMatchingForPATObject(process, matcherName, producerName, postfix=""):
226  ## remove mcMatcher from the default sequence
227  objectMatcher = getattr(process, matcherName+postfix)
228  if (producerName=='pfPatMuons'or producerName=='pfPatTaus'):
229  #no idea what this should do: there is no other occurance of 'PFPATafterPAT' in CMSSW other than here...
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)
234  ## straighten photonProducer
235  objectProducer = getattr(process, producerName+postfix)
236  objectProducer.addGenMatch = False
237  objectProducer.embedGenMatch = False
238  objectProducer.genParticleMatch = ''
239 
240 
242 
243  """ Remove all PAT objects from the default sequence but a specific one
244  """
245  _label='removeAllPATObjectsBut'
246  _defaultParameters=dicttypes.SortedKeysDict()
247  def __init__(self):
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'])")
251  self._parameters=copy.deepcopy(self._defaultParameters)
252  self._comment = ""
253 
255  return self._defaultParameters
256 
257  def __call__(self,process,
258  names = None,
259  outputInProcess = None,
260  outputModules = None) :
261  ## stop processing if 'outputInProcess' exists and show the new alternative
262  if not outputInProcess is None:
264  if names is None:
265  names=self._defaultParameters['names'].value
266  if outputModules is None:
267  outputModules=self._defaultParameters['outputModules'].value
268  self.setParameter('names',names)
269  self.setParameter('outputModules',outputModules)
270  self.apply(process)
271 
272  def toolCode(self, process):
273  names=self._parameters['names'].value
274  outputModules=self._parameters['outputModules'].value
275 
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)
280 
281 removeAllPATObjectsBut=RemoveAllPATObjectsBut()
282 
283 
285 
286  """ Remove a specific PAT object from the default sequence
287  """
288  _label='removeSpecificPATObjects'
289  _defaultParameters=dicttypes.SortedKeysDict()
290  def __init__(self):
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")
295  self._parameters=copy.deepcopy(self._defaultParameters)
296  self._comment = ""
297 
299  return self._defaultParameters
300 
301  def __call__(self,process,
302  names = None,
303  outputInProcess = None,
304  postfix = None,
305  outputModules = None) :
306  ## stop processing if 'outputInProcess' exists and show the new alternative
307  if not outputInProcess is None:
309  if names is None:
310  names=self._defaultParameters['names'].value
311  if outputModules is None:
312  outputModules=self._defaultParameters['outputModules'].value
313  if postfix is None:
314  postfix=self._defaultParameters['postfix'].value
315  self.setParameter('names',names)
316  self.setParameter('outputModules',outputModules)
317  self.setParameter('postfix',postfix)
318  self.apply(process)
319 
320  def toolCode(self, process):
321  names=self._parameters['names'].value
322  outputModules=self._parameters['outputModules'].value
323  postfix=self._parameters['postfix'].value
324 
325  ## remove pre object production steps from the default sequence
326  for obj in range(len(names)):
327  if( names[obj] == 'Photons' ):
328  removeIfInSequence(process, 'patPhotonIsolation', "patDefaultSequence", postfix)
329  removeIfInSequence(process, 'photonMatch', "patDefaultSequence", postfix)
330  removeIfInSequence(process, 'patPhotons', "patDefaultSequence", postfix)
331  if( names[obj] == 'Electrons' ):
332  removeIfInSequence(process, 'patElectronId', "patDefaultSequence", postfix)
333  removeIfInSequence(process, 'patElectronIsolation', "patDefaultSequence", postfix)
334  removeIfInSequence(process, 'electronMatch', "patDefaultSequence", postfix)
335  removeIfInSequence(process, 'patElectrons', "patDefaultSequence", postfix)
336  if( names[obj] == 'Muons' ):
337  removeIfInSequence(process, 'muonMatch', "patDefaultSequence", postfix)
338  removeIfInSequence(process, 'patMuons', "patDefaultSequence", postfix)
339  if( names[obj] == 'Taus' ):
340  removeIfInSequence(process, 'patPFCandidateIsoDepositSelection', "patDefaultSequence", postfix)
341  removeIfInSequence(process, 'patPFTauIsolation', "patDefaultSequence", postfix)
342  removeIfInSequence(process, 'tauMatch', "patDefaultSequence", postfix)
343  removeIfInSequence(process, 'tauGenJets', "patDefaultSequence", postfix)
344  removeIfInSequence(process, 'tauGenJetsSelectorAllHadrons', "patDefaultSequence", postfix)
345  removeIfInSequence(process, 'tauGenJetMatch', "patDefaultSequence", postfix)
346  removeIfInSequence(process, 'patTaus', "patDefaultSequence", postfix)
347  if( names[obj] == 'Jets' ):
348  removeIfInSequence(process, 'patJetCharge', "patDefaultSequence", postfix)
349  removeIfInSequence(process, 'patJetCorrections', "patDefaultSequence", postfix)
350  removeIfInSequence(process, 'patJetPartonMatch', "patDefaultSequence", postfix)
351  removeIfInSequence(process, 'patJetGenJetMatch', "patDefaultSequence", postfix)
352  removeIfInSequence(process, 'patJetFlavourIdLegacy', "patDefaultSequence", postfix)
353  removeIfInSequence(process, 'patJetFlavourId', "patDefaultSequence", postfix)
354  if( names[obj] == 'METs' ):
355  removeIfInSequence(process, 'patMETCorrections', "patDefaultSequence", postfix)
356 
357  ## remove object production steps from the default sequence
358  if( names[obj] == 'METs' ):
359  process.patDefaultSequence.remove( getattr(process, 'pat'+names[obj]) )
360  else:
361  if( names[obj] == 'Jets' ):
362  applyPostfix(process,"patDefaultSequence",postfix).remove(
363  getattr(process, jetCollectionString()+postfix) )
364  applyPostfix(process,"patDefaultSequence",postfix).remove(
365  getattr(process, jetCollectionString('selected')+postfix) )
366  applyPostfix(process,"patDefaultSequence",postfix).remove(
367  getattr(process, jetCollectionString('count')+postfix) )
368  else:
369  applyPostfix(process,"patDefaultSequence",postfix).remove(
370  getattr(process, 'pat'+names[obj]+postfix) )
371  applyPostfix(process,"patDefaultSequence",postfix).remove(
372  getattr(process, 'selectedPat'+names[obj]+postfix) )
373  applyPostfix(process,"patDefaultSequence",postfix).remove(
374  getattr(process, 'countPat'+names[obj]+postfix) )
375  ## in the case of leptons, the lepton counter must be modified as well
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
385  ## remove from summary
386  if( names[obj] == 'METs' ):
387  applyPostfix(process,"patCandidateSummary",postfix).candidates.remove(
388  cms.InputTag('pat'+names[obj]+postfix) )
389  else:
390  if( names[obj] == 'Jets' ):
391  applyPostfix(process,"patCandidateSummary",postfix).candidates.remove(
392  cms.InputTag(jetCollectionString()+postfix) )
393  applyPostfix(process,"selectedPatCandidateSummary",postfix).candidates.remove(
394  cms.InputTag(jetCollectionString('selected')+postfix) )
395  applyPostfix(process,"cleanPatCandidateSummary",postfix).candidates.remove(
396  cms.InputTag(jetCollectionString('clean')+postfix) )
397  else:
398  ## check whether module is in sequence or not
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) )
410  ## remove cleaning for the moment; in principle only the removed object
411  ## could be taken out of the checkOverlaps PSet
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)
419 
420 removeSpecificPATObjects=RemoveSpecificPATObjects()
421 
422 
424 
425  """ remove PAT cleaning from the default sequence:
426  """
427  _label='removeCleaning'
428  _defaultParameters=dicttypes.SortedKeysDict()
429  def __init__(self):
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")
433  self._parameters=copy.deepcopy(self._defaultParameters)
434  self._comment = ""
435 
437  return self._defaultParameters
438 
439  def __call__(self,process,
440  outputInProcess = None,
441  postfix = None,
442  outputModules = None) :
443  ## stop processing if 'outputInProcess' exists and show the new alternative
444  if not outputInProcess is None:
446  if outputModules is None:
447  outputModules=self._defaultParameters['outputModules'].value
448  if postfix is None:
449  postfix=self._defaultParameters['postfix'].value
450 
451  self.setParameter('outputModules',outputModules)
452  self.setParameter('postfix',postfix)
453 
454  self.apply(process)
455 
456  def toolCode(self, process):
457  outputModules=self._parameters['outputModules'].value
458  postfix=self._parameters['postfix'].value
459 
460  ## adapt single object counters
461  for m in listModules(applyPostfix(process,"countPatCandidates",postfix)):
462  if hasattr(m, 'src'): m.src = m.src.value().replace('cleanPat','selectedPat')
463 
464  ## adapt lepton counter
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(
471  applyPostfix(process,m,postfix)
472  )
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."
477  ## add selected pat objects to the pat output
478  from PhysicsTools.PatAlgos.patEventContent_cff import patEventContentNoCleaning
479  for outMod in outputModules:
480  if hasattr(process,outMod):
481  getattr(process,outMod).outputCommands = patEventContentNoCleaning
482  else:
483  raise KeyError, "process has no OutModule named", outMod
484 
485 removeCleaning=RemoveCleaning()
486 
487 
489 
490  """ Add PAT cleaning from the default sequence
491  """
492  _label='addCleaning'
493  _defaultParameters=dicttypes.SortedKeysDict()
494  def __init__(self):
495  ConfigToolBase.__init__(self)
496  self.addParameter(self._defaultParameters,'outputModules',['out'], "names of all output modules specified to be adapted (default is ['out'])")
497  self._parameters=copy.deepcopy(self._defaultParameters)
498  self._comment = ""
499 
501  return self._defaultParameters
502 
503  def __call__(self,process,
504  outputInProcess = None,
505  outputModules = None):
506  ## stop processing if 'outputInProcess' exists and show the new alternative
507  if not outputInProcess is None:
509  if outputModules is None:
510  outputModules=self._defaultParameters['outputModules'].value
511 
512  self.setParameter('outputModules',outputModules)
513  self.apply(process)
514 
515  def toolCode(self, process):
516  outputModules=self._parameters['outputModules'].value
517 
518  ## adapt single object counters
519  process.patDefaultSequence.replace(process.countPatCandidates, process.cleanPatCandidates * process.countPatCandidates)
520  for m in listModules(process.countPatCandidates):
521  if hasattr(m, 'src'): m.src = m.src.value().replace('selectedPat','cleanPat')
522  ## adapt lepton counter
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."
531  ## add clean layer1 objects to the pat output
532  from PhysicsTools.PatAlgos.patEventContent_cff import patEventContent
533  for outMod in outputModules:
534  if hasattr(process,outMod):
535  getattr(process,outMod).outputCommands = patEventContent
536  else:
537  raise KeyError, "process has no OutModule named", outMod
538 
539 addCleaning=AddCleaning()
540 
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 "-------------------------------------------------------"
549  #raise KeyError, "Unsupported option 'outputInProcess' used in '"+obj._label+"'"
def listModules
Definition: helpers.py:208
def listSequences
Definition: helpers.py:213
def deprecatedOptionOutputInProcess
Definition: coreTools.py:541
def _removeMCMatchingForPATObject
Definition: coreTools.py:225
def jetCollectionString
Definition: helpers.py:222
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
tuple _defaultParameters
Definition: coreTools.py:57
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
def removeIfInSequence
Definition: helpers.py:20