CMS 3D CMS Logo

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