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