CMS 3D CMS Logo

pfTools.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
6 
7 from PhysicsTools.PatAlgos.tools.helpers import listModules, applyPostfix, getPatAlgosToolsTask, addToProcessAndTask
8 
9 from copy import deepcopy
10 
12  print "WARNING: particle based isolation must be studied"
13 
14 def adaptPFMuons(process,module,postfix="", muonMatchModule=None ):
15  print "Adapting PF Muons "
16  print "***************** "
17  #warningIsolation()
18  print
19  module.useParticleFlow = True
20  module.pfMuonSource = cms.InputTag("pfIsolatedMuonsPFBRECO" + postfix)
21  module.userIsolation = cms.PSet()
22  ## module.isoDeposits = cms.PSet(
23  ## pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
24  ## pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
25  ## pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
26  ## pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
27  ## pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
28  ## )
29  ## module.isolationValues = cms.PSet(
30  ## pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
31  ## pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
32  ## pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
33  ## pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
34  ## pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
35  ## )
36  # matching the pfMuons, not the standard muons.
37  if muonMatchModule == None :
38  applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
39  else :
40  muonMatchModule.src = module.pfMuonSource
41 
42  print " muon source:", module.pfMuonSource
43  ## print " isolation :",
44  ## print module.isolationValues
45  ## print " isodeposits: "
46  ## print module.isoDeposits
47  print
48 
49 
50 def adaptPFElectrons(process,module, postfix):
51  # module.useParticleFlow = True
52  print "Adapting PF Electrons "
53  print "********************* "
54  #warningIsolation()
55  print
56  module.useParticleFlow = True
57  module.pfElectronSource = cms.InputTag("pfIsolatedElectronsPFBRECO" + postfix)
58  module.userIsolation = cms.PSet()
59  ## module.isoDeposits = cms.PSet(
60  ## pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
61  ## pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
62  ## pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
63  ## pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
64  ## pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
65  ## )
66  ## module.isolationValues = cms.PSet(
67  ## pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
68  ## pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
69  ## pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
70  ## pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
71  ## pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
72  ## )
73 
74  # COLIN: since we take the egamma momentum for pat Electrons, we must
75  # match the egamma electron to the gen electrons, and not the PFElectron.
76  # -> do not uncomment the line below.
77  # process.electronMatch.src = module.pfElectronSource
78  # COLIN: how do we depend on this matching choice?
79 
80  print " PF electron source:", module.pfElectronSource
81  ## print " isolation :"
82  ## print module.isolationValues
83  ## print " isodeposits: "
84  ## print module.isoDeposits
85  print
86 
87 
88 
89 
90 def adaptPFPhotons(process,module):
91  raise RuntimeError("Photons are not supported yet")
92 
93 from RecoTauTag.RecoTau.TauDiscriminatorTools import adaptTauDiscriminator, producerIsTauTypeMapper
94 
95 def reconfigurePF2PATTaus(process,
96  tauType='shrinkingConePFTau',
97  pf2patSelection=["DiscriminationByIsolation", "DiscriminationByLeadingPionPtCut"],
98  selectionDependsOn=["DiscriminationByLeadingTrackFinding"],
99  producerFromType=lambda producer: producer+"Producer",
100  postfix = ""):
101  print "patTaus will be produced from taus of type: %s that pass %s" \
102  % (tauType, pf2patSelection)
103 
104 
105 
106  # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer
107  producerName = producerFromType(tauType)
108  # Set as the source for the pf2pat taus (pfTaus) selector
109  applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
110  # Start our pf2pat taus base sequence
111  oldTauSansRefs = getattr(process,'pfTausProducerSansRefs'+postfix)
112  oldTau = getattr(process,'pfTausProducer'+postfix)
113  ## copy tau and setup it properly
114  newTauSansRefs = None
115  newTau = getattr(process,producerName+postfix).clone()
116 
117  ## adapted to new structure in RecoTauProducers PLEASE CHECK!!!
118  if tauType=='shrinkingConePFTau':
119  newTauSansRefs = getattr(process,producerName+"SansRefs").clone()
120  newTauSansRefs.modifiers[1] = cms.PSet(
121  pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
122  name = cms.string('pfTauTTIworkaround'+postfix),
123  plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
124  )
125  newTau.modifiers[1] = newTauSansRefs.modifiers[1]
126  newTauSansRefs.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
127  newTau.piZeroSrc = newTauSansRefs.piZeroSrc
128  newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
129  newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
130  newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
131  elif tauType=='fixedConePFTau':
132  newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
133  elif tauType=='hpsPFTau':
134  newTau = getattr(process,'combinatoricRecoTaus'+postfix).clone()
135  newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
136  newTau.modifiers[3] = cms.PSet(
137  pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
138  name = cms.string('pfTauTTIworkaround'+postfix),
139  plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
140  )
141  from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
142  #cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix, addToTask = True)
143  setattr(process,'produceHPSPFTaus'+postfix,cms.Sequence(applyPostfix(process,'hpsSelectionDiscriminator',postfix)+applyPostfix(process,'hpsPFTauProducerSansRefs',postfix)+applyPostfix(process,'hpsPFTauProducer',postfix)))
144  massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
145  "PFTauProducer",
146  cms.InputTag("combinatoricRecoTaus"+postfix),
147  cms.InputTag("pfTausBase"+postfix) )
148  massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
149  "src",
150  cms.InputTag("combinatoricRecoTaus"+postfix),
151  cms.InputTag("pfTausBase"+postfix) )
152  ### Next three lines crash, oldTau does not have any of these attributes. Why?###
153  #newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
154  #newTau.jetRegionSrc = oldTau.jetRegionSrc
155  #newTau.jetSrc = oldTau.jetSrc
156  #newTau.builders[0].pfCandSrc = cms.InputTag("pfNoElectronJME" + postfix)
157  #newTau.jetRegionSrc = cms.InputTag("pfTauPFJets08Region" + postfix)
158  #newTau.jetSrc = cms.InputTag("pfJetsPFBRECO" + postfix)
159  # replace old tau producer by new one put it into baseSequence
160  task = getPatAlgosToolsTask(process)
161  addToProcessAndTask("pfTausBase"+postfix, newTau, process, task)
162  if tauType=='shrinkingConePFTau':
163  addToProcessAndTask("pfTausBaseSansRefs"+postfix, newTauSansRefs, process, task)
164  getattr(process,"pfTausBase"+postfix).src = "pfTausBaseSansRefs"+postfix
165  baseSequence += getattr(process,"pfTausBaseSansRefs"+postfix)
166 
167  #make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
168  def producerIsTauTypeMapperWithPostfix(tauProducer):
169  return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
170 
171  def recoTauTypeMapperWithGroup(tauProducer):
172  return "%s(.*)"%recoTauTypeMapper(tauProducer)
173 
174  # Get our prediscriminants
175  for predisc in selectionDependsOn:
176  # Get the prototype
177  originalName = tauType+predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding
178  clonedName = "pfTausBase"+predisc+postfix
179  clonedDisc = getattr(process, originalName).clone()
180  addToProcessAndTask(clonedName, clonedDisc, process, task)
181 
182  tauCollectionToSelect = None
183  if tauType != 'hpsPFTau' :
184  tauCollectionToSelect = "pfTausBase"+postfix
185  #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
186  else:
187  tauCollectionToSelect = "hpsPFTauProducer"+postfix
188  # Adapt this discriminator for the cloned prediscriminators
189  adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
190  oldTauTypeMapper=recoTauTypeMapperWithGroup,
191  newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
192  preservePFTauProducer=True)
193  clonedDisc.PFTauProducer = tauCollectionToSelect
194 
195  # Reconfigure the pf2pat PFTau selector discrimination sources
196  getattr(process,"pfTaus" + postfix).discriminators = cms.VPSet()
197  for selection in pf2patSelection:
198  # Get our discriminator that will be used to select pfTaus
199  originalName = tauType+selection
200  clonedName = "pfTausBase"+selection+postfix
201  clonedDisc = getattr(process, originalName).clone()
202  addToProcessAndTask(clonedName, clonedDisc, process, task)
203 
204  tauCollectionToSelect = None
205 
206  if tauType != 'hpsPFTau' :
207  tauCollectionToSelect = cms.InputTag("pfTausBase"+postfix)
208  #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
209  else:
210  tauCollectionToSelect = cms.InputTag("hpsPFTauProducer"+postfix)
211  #Adapt our cloned discriminator to the new prediscriminants
212  adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
213  oldTauTypeMapper=recoTauTypeMapperWithGroup,
214  newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
215  preservePFTauProducer=True)
216  clonedDisc.PFTauProducer = tauCollectionToSelect
217 
218  # Add this selection to our pfTau selectors
219  getattr(process,"pfTaus" + postfix).discriminators.append(cms.PSet(
220  discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
221  # Set the input of the final selector.
222  if tauType != 'hpsPFTau':
223  getattr(process,"pfTaus" + postfix).src = "pfTausBase"+postfix
224  else:
225  # If we are using HPS taus, we need to take the output of the clenaed
226  # collection
227  getattr(process,"pfTaus" + postfix).src = "hpsPFTauProducer"+postfix
228 
229 
230 
231 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
232  # Set up the collection used as a preselection to use this tau type
233  if tauType != 'hpsPFTau' :
234  reconfigurePF2PATTaus(process, tauType, postfix=postfix)
235  else:
236  reconfigurePF2PATTaus(process, tauType,
237  ["DiscriminationByDecayModeFinding"],
238  ["DiscriminationByDecayModeFinding"],
239  postfix=postfix)
240  # new default use unselected taus (selected only for jet cleaning)
241  if tauType != 'hpsPFTau' :
242  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
243  else:
244  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
245  # to use preselected collection (old default) uncomment line below
246  #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
247 
248  ### apparently not needed anymore, function gone from tauTools.py###
249  #redoPFTauDiscriminators(process,
250  #cms.InputTag(tauType+'Producer'),
251  #applyPostfix(process,"patTaus", postfix).tauSource,
252  #tauType, postfix=postfix)
253 
254 
255  if tauType != 'hpsPFTau' :
256  switchToPFTauByType(process, pfTauType=tauType,
257  patTauLabel="pfTausBase"+postfix,
258  tauSource=cms.InputTag(tauType+'Producer'+postfix),
259  postfix=postfix)
260  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
261  else:
262  switchToPFTauByType(process, pfTauType=tauType,
263  patTauLabel="",
264  tauSource=cms.InputTag(tauType+'Producer'+postfix),
265  postfix=postfix)
266  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
267 
268 
269 
270 #helper function for PAT on PF2PAT sample
271 def tauTypeInPF2PAT(process,tauType='shrinkingConePFTau', postfix = ""):
272  process.load("CommonTools.ParticleFlow.pfTaus_cff")
273  applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
274 
275 
276 def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""):
277  from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
278  # make modules
279  producer = patPFParticles.clone(pfCandidateSource = src)
280  filter = cms.EDFilter("PATPFParticleSelector",
281  src = cms.InputTag("pat" + patLabel),
282  cut = cms.string(cut))
283  counter = cms.EDFilter("PATCandViewCountFilter",
284  minNumber = cms.uint32(0),
285  maxNumber = cms.uint32(999999),
286  src = cms.InputTag("pat" + patLabel))
287  # add modules to process
288  task = getPatAlgosToolsTask(process)
289  addToProcessAndTask("pat" + patLabel, producer, process, task)
290  addToProcessAndTask("selectedPat" + patLabel, filter, process, task)
291  addToProcessAndTask("countPat" + patLabel, counter, process, task)
292 
293  # summary tables
294  applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
295  applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
296 
297 
298 def switchToPFMET(process,input=cms.InputTag('pfMETPFBRECO'), type1=False, postfix=""):
299  print 'MET: using ', input
300  if( not type1 ):
301  oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
302  applyPostfix(process, "patMETs",postfix).metSource = input
303  applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
304  else:
305  # type1 corrected MET
306  # name of corrected MET hardcoded in PAT and meaningless
307  print 'Apply TypeI corrections for MET'
308  #getattr(process, "patPF2PATSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
309  jecLabel = getattr(process,'patJetCorrFactors'+postfix).payload.pythonValue().replace("'","")
310  getattr(process,jecLabel+'Type1CorMet'+postfix).src = input.getModuleLabel()
311  #getattr(process,'patMETs'+postfix).metSource = jecLabel+'Type1CorMet'+postfix
312  #getattr(process,'patMETs'+postfix).addMuonCorrections = False
313 
314 def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK4', postfix = "", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out']):
315 
316  print "Switching to PFJets, ", algo
317  print "************************ "
318  print "input collection: ", input
319 
320  if algo == 'AK4':
321  genJetCollection = cms.InputTag('ak4GenJetsNoNu'+postfix)
322  rParam=0.4
323  elif algo == 'AK7':
324  genJetCollection = cms.InputTag('ak7GenJetsNoNu'+postfix)
325  rParam=0.7
326  else:
327  print 'bad jet algorithm:', algo, '! for now, only AK4 and AK7 are allowed. If you need other algorithms, please contact Colin'
328  sys.exit(1)
329 
330  # changing the jet collection in PF2PAT:
331  from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
332  inputCollection = getattr(process,"pfJetsPFBRECO"+postfix).src
333  setattr(process,"pfJetsPFBRECO"+postfix,jetAlgo(algo)) # problem for cfgBrowser
334  getattr(process,"pfJetsPFBRECO"+postfix).src = inputCollection
335  inputJetCorrLabel=jetCorrections
336 
337  switchJetCollection(process,
338  jetSource = input,
339  algo=algo,
340  rParam=rParam,
341  genJetCollection=genJetCollection,
342  postfix=postfix,
343  jetTrackAssociation=True,
344  jetCorrections=inputJetCorrLabel,
345  outputModules = outputModules,
346  )
347 
348  # check whether L1FastJet is in the list of correction levels or not
349  applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
350  task = getPatAlgosToolsTask(process)
351  for corr in inputJetCorrLabel[1]:
352  if corr == 'L1FastJet':
353  applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
354  applyPostfix(process, "pfJetsPFBRECO", postfix).doAreaFastjet = True
355  # do correct treatment for TypeI MET corrections
356  #type1=True
357  if type1:
358  for mod in process.producerNames().split(' '):
359 
360  if mod.startswith("kt6") and mod.endswith("Jets"+postfix) and not 'GenJets' in mod:
361  prefix = mod.replace(postfix,'')
362  prefix = prefix.replace('kt6PFJets','')
363  prefix = prefix.replace('kt6CaloJets','')
364  prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
365  for essource in process.es_sources_().keys():
366  if essource == prefix+'L1FastJet':
367  setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
368  addToProcessAndTask(prefix+'CombinedCorrector'+postfix,
369  getattr(process,prefix+'CombinedCorrector').clone(), process, task)
370  getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
371  for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
372  if cor == essource:
373  idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
374  getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
375 
376  if hasattr( getattr( process, "patJets" + postfix), 'embedCaloTowers' ): # optional parameter, which defaults to 'False' anyway
377  applyPostfix(process, "patJets", postfix).embedCaloTowers = False
378  applyPostfix(process, "patJets", postfix).embedPFCandidates = True
379 
380 #-- Remove MC dependence ------------------------------------------------------
381 def removeMCMatchingPF2PAT( process, postfix="", outputModules=['out'] ):
382  #from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
383  ### no longe needed in unscheduled mode###
384  #removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
385  removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
386 
387 
388 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix=''):
389  print "Switching PV collection for PF2PAT:", pvCollection
390  print "***********************************"
391 
392  # PV sources to be exchanged:
393  pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs','primaryVertex']
394  # PV sources NOT to be exchanged:
395  #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc']
396 
397  # exchange the primary vertex source of all relevant modules
398  for m in (process.producerNames().split(' ') + process.filterNames().split(' ')):
399  # only if the module has a source with a relevant name
400  for namePvSrc in pvExchange:
401  if hasattr(getattr(process,m),namePvSrc):
402  #print m
403  setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
404 
405 
406 def usePF2PAT(process,runPF2PAT=True, jetAlgo='AK4', runOnMC=True, postfix="", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative','L3Absolute'],'None'), pvCollection=cms.InputTag('goodOfflinePrimaryVerticesPFlow',), typeIMetCorrections=False, outputModules=['out'],excludeFromTopProjection=['Tau']):
407  # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
408  # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
409 
410  if typeIMetCorrections:
411  jetCorrections = (jetCorrections[0],jetCorrections[1],'Type-1')
412  """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
413 
414  # -------- CORE ---------------
415  from PhysicsTools.PatAlgos.tools.helpers import loadWithPostfix
416  patAlgosToolsTask = getPatAlgosToolsTask(process)
417  taskLabel = patAlgosToolsTask.label()
418  if runPF2PAT:
419  loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix, loadedProducersAndFilters=taskLabel)
420  loadWithPostfix(process,"CommonTools.ParticleFlow.PFBRECO_cff",postfix, loadedProducersAndFilters=taskLabel)
421  else:
422  loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix, loadedProducersAndFilters=taskLabel)
423 
424 
425 
426 
427  # -------- OBJECTS ------------
428  # Muons
429 
430  adaptPFMuons(process,
431  applyPostfix(process,"patMuons",postfix),
432  postfix)
433 
434  # Electrons
435 
436  adaptPFElectrons(process,
437  applyPostfix(process,"patElectrons",postfix),
438  postfix)
439 
440  # Photons
441  #print "Temporarily switching off photons completely"
442 
443  #removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
444 
445  # Jets
446  if runOnMC :
447  switchToPFJets( process, cms.InputTag('pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
448  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
449 
450  else :
451  if not 'L2L3Residual' in jetCorrections[1]:
452  ### think of a more accurate warning
453  print '#################################################'
454  print 'WARNING! Not using L2L3Residual but this is data.'
455  print 'If this is okay with you, disregard this message.'
456  print '#################################################'
457  switchToPFJets( process, cms.InputTag('pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
458  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
459  # Taus
460  #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
461  #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
462  adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
463  # MET
464  switchToPFMET(process, cms.InputTag('pfMETPFBRECO'+postfix), type1=typeIMetCorrections, postfix=postfix)
465 
466  # Unmasked PFCandidates
467  addPFCandidates(process,cms.InputTag('pfNoJetClones'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
468 
469  # adapt primary vertex collection
470  adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
471 
472  if not runOnMC:
473  runOnData(process,postfix=postfix,outputModules=outputModules)
474 
475  # Configure Top Projections
476  getattr(process,"pfNoPileUpJME"+postfix).enable = True
477  getattr(process,"pfNoMuonJMEPFBRECO"+postfix).enable = True
478  getattr(process,"pfNoElectronJMEPFBRECO"+postfix).enable = True
479  getattr(process,"pfNoTauPFBRECO"+postfix).enable = False
480  getattr(process,"pfNoJetPFBRECO"+postfix).enable = True
481  exclusionList = ''
482  for object in excludeFromTopProjection:
483  jme = ''
484  if object in ['Muon','Electron']:
485  jme = 'JME'
486  getattr(process,"pfNo"+object+jme+'PFBRECO'+postfix).enable = False
487  exclusionList=exclusionList+object+','
488  exclusionList=exclusionList.rstrip(',')
489  print "Done: PFBRECO interfaced to PAT, postfix=", postfix,", Excluded from Top Projection:",exclusionList
def usePF2PAT(process, runPF2PAT=True, jetAlgo='AK4', runOnMC=True, postfix="", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative','L3Absolute'],'None'), pvCollection=cms.InputTag('goodOfflinePrimaryVerticesPFlow',), typeIMetCorrections=False, outputModules=['out'], excludeFromTopProjection=['Tau'])
Definition: pfTools.py:406
def switchToPFMET(process, input=cms.InputTag('pfMETPFBRECO'), type1=False, postfix="")
Definition: pfTools.py:298
def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK4', postfix="", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out'])
Definition: pfTools.py:314
def recoTauTypeMapper(tauProducer)
def warningIsolation()
Definition: pfTools.py:11
def tauTypeInPF2PAT(process, tauType='shrinkingConePFTau', postfix="")
Definition: pfTools.py:271
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def replace(string, replacements)
def massSearchReplaceParam(sequence, paramName, paramOldValue, paramValue, verbose=False)
Definition: MassReplace.py:116
def adaptPFTaus(process, tauType='shrinkingConePFTau', postfix="")
Definition: pfTools.py:231
def applyPostfix(process, label, postfix)
Definition: helpers.py:114
def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix='')
Definition: pfTools.py:388
def adaptTauDiscriminator(discriminator, newTauProducer='shrinkingConePFTauProducer', oldTauTypeMapper=recoTauTypeMapper, newTauTypeMapper=recoTauTypeMapper, preservePFTauProducer=False)
def switchToPFTauByType(process, pfTauType=None, tauSource=cms.InputTag('hpsPFTauProducer'), patTauLabel="", postfix="")
Definition: tauTools.py:222
def addPFCandidates(process, src, patLabel='PFParticles', cut="", postfix="")
Definition: pfTools.py:276
def adaptPFPhotons(process, module)
Definition: pfTools.py:90
def adaptPFElectrons(process, module, postfix)
Definition: pfTools.py:50
def reconfigurePF2PATTaus(process, tauType='shrinkingConePFTau', pf2patSelection=["DiscriminationByIsolation", DiscriminationByLeadingPionPtCut, selectionDependsOn=["DiscriminationByLeadingTrackFinding"], producerFromType=lambda producer:producer+"Producer", postfix="")
Definition: pfTools.py:100
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def getPatAlgosToolsTask(process)
Definition: helpers.py:13
def loadWithPostfix(process, moduleName, postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:46
def adaptPFMuons(process, module, postfix="", muonMatchModule=None)
Definition: pfTools.py:14
double split
Definition: MVATrainer.cc:139
def removeMCMatchingPF2PAT(process, postfix="", outputModules=['out'])
Definition: pfTools.py:381