CMS 3D CMS Logo

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