CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
pfTools Namespace Reference

Functions

def adaptPFElectrons
 
def adaptPFIsoElectrons
 
def adaptPFIsoMuons
 
def adaptPFMuons
 
def adaptPFPhotons
 
def adaptPFTaus
 
def adaptPVs
 
def addPFCandidates
 
def reconfigurePF2PATTaus
 
def removeMCMatchingPF2PAT
 
def switchToPFJets
 
def switchToPFMET
 
def tauTypeInPF2PAT
 
def useGsfElectrons
 
def usePF2PAT
 
def usePFIso
 
def warningIsolation
 

Function Documentation

def pfTools.adaptPFElectrons (   process,
  module,
  postfix 
)

Definition at line 135 of file pfTools.py.

References helpers.removeIfInSequence(), and warningIsolation().

Referenced by usePF2PAT().

136 def adaptPFElectrons(process,module, postfix):
137  # module.useParticleFlow = True
138  print "Adapting PF Electrons "
139  print "********************* "
141  print
142  module.useParticleFlow = True
143  module.pfElectronSource = cms.InputTag("pfIsolatedElectrons" + postfix)
144  module.userIsolation = cms.PSet()
145  module.isoDeposits = cms.PSet(
146  pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
147  pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
148  pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
149  pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
150  pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
151  )
152  module.isolationValues = cms.PSet(
153  pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
154  pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
155  pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
156  pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
157  pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
158  )
159 
160  # COLIN: since we take the egamma momentum for pat Electrons, we must
161  # match the egamma electron to the gen electrons, and not the PFElectron.
162  # -> do not uncomment the line below.
163  # process.electronMatch.src = module.pfElectronSource
164  # COLIN: how do we depend on this matching choice?
165 
166  print " PF electron source:", module.pfElectronSource
167  print " isolation :"
168  print module.isolationValues
169  print " isodeposits: "
170  print module.isoDeposits
171  print
172 
173  print "removing traditional isolation"
174 
175  removeIfInSequence(process, "patElectronIsolation", "patDefaultSequence", postfix)
def adaptPFElectrons
Definition: pfTools.py:135
def warningIsolation
Definition: pfTools.py:29
def removeIfInSequence
Definition: helpers.py:20
def pfTools.adaptPFIsoElectrons (   process,
  module,
  postfix = "PFIso",
  dR = "04" 
)

Definition at line 48 of file pfTools.py.

Referenced by useGsfElectrons(), and usePFIso().

48 
49 def adaptPFIsoElectrons(process,module, postfix = "PFIso", dR = "04"):
50  #FIXME: adaptPFElectrons can use this function.
51  module.isoDeposits = cms.PSet(
52  pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
53  pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
54  pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
55  pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
56  pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
57  )
58  module.isolationValues = cms.PSet(
59  pfChargedHadrons = cms.InputTag("elPFIsoValueCharged"+dR+"PFId"+ postfix),
60  pfChargedAll = cms.InputTag("elPFIsoValueChargedAll"+dR+"PFId"+ postfix),
61  pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU"+dR+"PFId" + postfix),
62  pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral"+dR+"PFId" + postfix),
63  pfPhotons = cms.InputTag("elPFIsoValueGamma"+dR+"PFId" + postfix)
64  )
65  module.isolationValuesNoPFId = cms.PSet(
66  pfChargedHadrons = cms.InputTag("elPFIsoValueCharged"+dR+"NoPFId"+ postfix),
67  pfChargedAll = cms.InputTag("elPFIsoValueChargedAll"+dR+"NoPFId"+ postfix),
68  pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU"+dR+"NoPFId" + postfix),
69  pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral"+dR+"NoPFId" + postfix),
70  pfPhotons = cms.InputTag("elPFIsoValueGamma"+dR+"NoPFId" + postfix)
71  )
def adaptPFIsoElectrons
Definition: pfTools.py:48
def pfTools.adaptPFIsoMuons (   process,
  module,
  postfix = "PFIso",
  dR = "04" 
)

Definition at line 72 of file pfTools.py.

Referenced by usePFIso().

72 
73 def adaptPFIsoMuons(process,module, postfix = "PFIso", dR = "04"):
74  #FIXME: adaptPFMuons can use this function.
75  module.isoDeposits = cms.PSet(
76  pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
77  pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
78  pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
79  pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
80  pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
81  )
82  module.isolationValues = cms.PSet(
83  pfChargedHadrons = cms.InputTag("muPFIsoValueCharged" + dR + postfix),
84  pfChargedAll = cms.InputTag("muPFIsoValueChargedAll" + dR + postfix),
85  pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU" + dR + postfix),
86  pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral" + dR + postfix),
87  pfPhotons = cms.InputTag("muPFIsoValueGamma" + dR + postfix)
88  )
def adaptPFIsoMuons
Definition: pfTools.py:72
def pfTools.adaptPFMuons (   process,
  module,
  postfix = "" 
)

Definition at line 102 of file pfTools.py.

References helpers.applyPostfix(), and warningIsolation().

Referenced by usePF2PAT().

103 def adaptPFMuons(process,module,postfix="" ):
104  print "Adapting PF Muons "
105  print "***************** "
107  print
108  module.useParticleFlow = True
109  module.pfMuonSource = cms.InputTag("pfIsolatedMuons" + postfix)
110  module.userIsolation = cms.PSet()
111  module.isoDeposits = cms.PSet(
112  pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
113  pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
114  pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
115  pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
116  pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
117  )
118  module.isolationValues = cms.PSet(
119  pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
120  pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
121  pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
122  pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
123  pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
124  )
125  # matching the pfMuons, not the standard muons.
126  applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
127 
128  print " muon source:", module.pfMuonSource
129  print " isolation :",
130  print module.isolationValues
131  print " isodeposits: "
132  print module.isoDeposits
133  print
134 
def adaptPFMuons
Definition: pfTools.py:102
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def warningIsolation
Definition: pfTools.py:29
def pfTools.adaptPFPhotons (   process,
  module 
)

Definition at line 176 of file pfTools.py.

References reconfigurePF2PATTaus().

177 def adaptPFPhotons(process,module):
178  raise RuntimeError, "Photons are not supported yet"
def adaptPFPhotons
Definition: pfTools.py:176
def pfTools.adaptPFTaus (   process,
  tauType = 'shrinkingConePFTau',
  postfix = "" 
)

Definition at line 322 of file pfTools.py.

References helpers.applyPostfix(), reconfigurePF2PATTaus(), tauTools.redoPFTauDiscriminators(), python.multivaluedict.remove(), and tauTools.switchToPFTauByType().

Referenced by usePF2PAT().

323 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
324  # Set up the collection used as a preselection to use this tau type
325  if tauType != 'hpsPFTau' :
326  reconfigurePF2PATTaus(process, tauType, postfix=postfix)
327  else:
328  reconfigurePF2PATTaus(process, tauType,
329  ["DiscriminationByLooseCombinedIsolationDBSumPtCorr"],
330  ["DiscriminationByDecayModeFinding"],
331  postfix=postfix)
332  # new default use unselected taus (selected only for jet cleaning)
333  if tauType != 'hpsPFTau' :
334  applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
335  else:
336  applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
337  # to use preselected collection (old default) uncomment line below
338  #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
339 
340 
341  redoPFTauDiscriminators(process,
342  cms.InputTag(tauType+'Producer'),
343  applyPostfix(process,"patTaus", postfix).tauSource,
344  tauType, postfix=postfix)
345 
346  switchToPFTauByType(process, pfTauType=tauType,
347  pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource,
348  pfTauLabelOld=cms.InputTag(tauType+'Producer'),
349  postfix=postfix)
350 
351  applyPostfix(process,"makePatTaus", postfix).remove(
352  applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix)
353  )
354 
#helper function for PAT on PF2PAT sample
def adaptPFTaus
Definition: pfTools.py:322
def redoPFTauDiscriminators
Definition: tauTools.py:12
def reconfigurePF2PATTaus
Definition: pfTools.py:186
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def switchToPFTauByType
Definition: tauTools.py:404
def pfTools.adaptPVs (   process,
  pvCollection = cms.InputTag('offlinePrimaryVertices'),
  postfix = '' 
)

Definition at line 515 of file pfTools.py.

Referenced by usePF2PAT().

516 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix=''):
517 
518  print "Switching PV collection for PF2PAT:", pvCollection
519  print "***********************************"
520 
521  # PV sources to be exchanged:
522  pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs']
523  # PV sources NOT to be exchanged:
524  #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc','primaryVertex']
525 
526  # find out all added jet collections (they don't belong to PF2PAT)
527  interPostfixes = []
528  for m in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
529  if m.startswith('patJets') and m.endswith(postfix) and not len(m)==len('patJets')+len(postfix):
530  interPostfix = m.replace('patJets','')
531  interPostfix = interPostfix.replace(postfix,'')
532  interPostfixes.append(interPostfix)
533 
534  # exchange the primary vertex source of all relevant modules
535  for m in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
536  modName = m.replace(postfix,'')
537  # only if the module has a source with a relevant name
538  for namePvSrc in pvExchange:
539  if hasattr(getattr(process,m),namePvSrc):
540  # only if the module is not coming from an added jet collection
541  interPostFixFlag = False
542  for pfix in interPostfixes:
543  if modName.endswith(pfix):
544  interPostFixFlag = True
545  break
546  if not interPostFixFlag:
547  setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
548 
def adaptPVs
Definition: pfTools.py:515
def pfTools.addPFCandidates (   process,
  src,
  patLabel = 'PFParticles',
  cut = "",
  postfix = "" 
)

Definition at line 360 of file pfTools.py.

References helpers.applyPostfix(), edm::eventsetup::heterocontainer.insert(), and linker.replace().

Referenced by usePF2PAT().

361 def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""):
362  from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
363  # make modules
364  producer = patPFParticles.clone(pfCandidateSource = src)
365  filter = cms.EDFilter("PATPFParticleSelector",
366  src = cms.InputTag("pat" + patLabel),
367  cut = cms.string(cut))
368  counter = cms.EDFilter("PATCandViewCountFilter",
369  minNumber = cms.uint32(0),
370  maxNumber = cms.uint32(999999),
371  src = cms.InputTag("pat" + patLabel))
372  # add modules to process
373  setattr(process, "pat" + patLabel, producer)
374  setattr(process, "selectedPat" + patLabel, filter)
375  setattr(process, "countPat" + patLabel, counter)
376  # insert into sequence
377  getattr(process, "patDefaultSequence"+postfix).replace(
378  applyPostfix(process, "patCandidateSummary", postfix),
379  producer+applyPostfix(process, "patCandidateSummary", postfix)
380  )
381  getattr(process, "patDefaultSequence"+postfix).replace(
382  applyPostfix(process, "selectedPatCandidateSummary", postfix),
383  filter+applyPostfix(process, "selectedPatCandidateSummary", postfix)
384  )
385  index = len( applyPostfix( process, "patDefaultSequence", postfix ).moduleNames() )
386  applyPostfix( process, "patDefaultSequence", postfix ).insert( index, counter )
387  # summary tables
388  applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
389  applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
390 
def replace
Definition: linker.py:10
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def addPFCandidates
Definition: pfTools.py:360
bool insert(Storage &, ItemType *, const IdTag &)
def pfTools.reconfigurePF2PATTaus (   process,
  tauType = 'shrinkingConePFTau',
  pf2patSelection = ["DiscriminationByIsolation",
  DiscriminationByLeadingPionPtCut,
  selectionDependsOn = ["DiscriminationByLeadingTrackFinding"],
  producerFromType = lambda producer: producer+"Producer",
  postfix = "" 
)

Definition at line 186 of file pfTools.py.

References TauDiscriminatorTools.adaptTauDiscriminator(), helpers.applyPostfix(), clone(), helpers.cloneProcessingSnippet(), helpers.massSearchReplaceParam(), TauDiscriminatorTools.producerIsTauTypeMapper, and TauDiscriminatorTools.recoTauTypeMapper().

Referenced by adaptPFPhotons(), and adaptPFTaus().

187  postfix = ""):
188  print "patTaus will be produced from taus of type: %s that pass %s" \
189  % (tauType, pf2patSelection)
190 
191  #get baseSequence
192  baseSequence = getattr(process,"pfTausBaseSequence"+postfix)
193  #clean baseSequence from old modules
194  for oldBaseModuleName in baseSequence.moduleNames():
195  oldBaseModule = getattr(process,oldBaseModuleName)
196  baseSequence.remove(oldBaseModule)
197 
198  # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer
199  producerName = producerFromType(tauType)
200  # Set as the source for the pf2pat taus (pfTaus) selector
201  applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
202  # Start our pf2pat taus base sequence
203  oldTauSansRefs = getattr(process,'pfTausProducerSansRefs'+postfix)
204  oldTau = getattr(process,'pfTausProducer'+postfix)
205  ## copy tau and setup it properly
206  newTauSansRefs = None
207  newTau = getattr(process,producerName).clone()
208  ## adapted to new structure in RecoTauProducers PLEASE CHECK!!!
209  if tauType=='shrinkingConePFTau':
210  newTauSansRefs = getattr(process,producerName+"SansRefs").clone()
211  newTauSansRefs.modifiers[1] = cms.PSet(
212  pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
213  name = cms.string('pfTauTTIworkaround'+postfix),
214  plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
215  )
216  newTau.modifiers[1] = newTauSansRefs.modifiers[1]
217  newTauSansRefs.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
218  newTau.piZeroSrc = newTauSansRefs.piZeroSrc
219  newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
220  newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
221  newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
222  elif tauType=='fixedConePFTau':
223  newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
224  elif tauType=='hpsPFTau':
225  newTau = process.combinatoricRecoTaus.clone()
226  newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
227  newTau.modifiers[3] = cms.PSet(
228  pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
229  name = cms.string('pfTauTTIworkaround'+postfix),
230  plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
231  )
232  from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
233  cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix)
234  massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
235  "PFTauProducer",
236  cms.InputTag("combinatoricRecoTaus"),
237  cms.InputTag("pfTausBase"+postfix) )
238  massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
239  "src",
240  cms.InputTag("combinatoricRecoTaus"),
241  cms.InputTag("pfTausBase"+postfix) )
242 
243  newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
244  newTau.jetRegionSrc = oldTau.jetRegionSrc
245  newTau.jetSrc = oldTau.jetSrc
246 
247  # replace old tau producer by new one put it into baseSequence
248  setattr(process,"pfTausBase"+postfix,newTau)
249  if tauType=='shrinkingConePFTau':
250  setattr(process,"pfTausBaseSansRefs"+postfix,newTauSansRefs)
251  getattr(process,"pfTausBase"+postfix).src = "pfTausBaseSansRefs"+postfix
252  baseSequence += getattr(process,"pfTausBaseSansRefs"+postfix)
253  baseSequence += getattr(process,"pfTausBase"+postfix)
254  if tauType=='hpsPFTau':
255  baseSequence += getattr(process,"produceHPSPFTaus"+postfix)
256  #make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
257  def producerIsTauTypeMapperWithPostfix(tauProducer):
258  return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
259 
260  def recoTauTypeMapperWithGroup(tauProducer):
261  return "%s(.*)"%recoTauTypeMapper(tauProducer)
262 
263  # Get our prediscriminants
264  for predisc in selectionDependsOn:
265  # Get the prototype
266  originalName = tauType+predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding
267  clonedName = "pfTausBase"+predisc+postfix
268  clonedDisc = getattr(process, originalName).clone()
269  # Register in our process
270  setattr(process, clonedName, clonedDisc)
271  baseSequence += getattr(process, clonedName)
272 
273  tauCollectionToSelect = None
274  if tauType != 'hpsPFTau' :
275  tauCollectionToSelect = "pfTausBase"+postfix
276  #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
277  else:
278  tauCollectionToSelect = "hpsPFTauProducer"+postfix
279  # Adapt this discriminator for the cloned prediscriminators
280  adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
281  oldTauTypeMapper=recoTauTypeMapperWithGroup,
282  newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
283  preservePFTauProducer=True)
284  clonedDisc.PFTauProducer = tauCollectionToSelect
285 
286  # Reconfigure the pf2pat PFTau selector discrimination sources
287  applyPostfix(process,"pfTaus", postfix).discriminators = cms.VPSet()
288  for selection in pf2patSelection:
289  # Get our discriminator that will be used to select pfTaus
290  originalName = tauType+selection
291  clonedName = "pfTausBase"+selection+postfix
292  clonedDisc = getattr(process, originalName).clone()
293  # Register in our process
294  setattr(process, clonedName, clonedDisc)
295 
296  tauCollectionToSelect = None
297 
298  if tauType != 'hpsPFTau' :
299  tauCollectionToSelect = cms.InputTag("pfTausBase"+postfix)
300  #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
301  else:
302  tauCollectionToSelect = cms.InputTag("hpsPFTauProducer"+postfix)
303  #Adapt our cloned discriminator to the new prediscriminants
304  adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
305  oldTauTypeMapper=recoTauTypeMapperWithGroup,
306  newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
307  preservePFTauProducer=True)
308  clonedDisc.PFTauProducer = tauCollectionToSelect
309  baseSequence += clonedDisc
310  # Add this selection to our pfTau selectors
311  applyPostfix(process,"pfTaus", postfix).discriminators.append(cms.PSet(
312  discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
313  # Set the input of the final selector.
314  if tauType != 'hpsPFTau':
315  applyPostfix(process,"pfTaus", postfix).src = "pfTausBase"+postfix
316  else:
317  # If we are using HPS taus, we need to take the output of the clenaed
318  # collection
319  applyPostfix(process,"pfTaus", postfix).src = "hpsPFTauProducer"+postfix
320 
321 
def cloneProcessingSnippet
Definition: helpers.py:262
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def massSearchReplaceParam
Definition: helpers.py:205
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def pfTools.removeMCMatchingPF2PAT (   process,
  postfix = "",
  outputModules = ['out'] 
)

Definition at line 509 of file pfTools.py.

References helpers.removeIfInSequence().

Referenced by usePF2PAT().

510 def removeMCMatchingPF2PAT( process, postfix="", outputModules=['out'] ):
511  from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
512  removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
513  removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
514 
def removeMCMatchingPF2PAT
Definition: pfTools.py:509
def removeIfInSequence
Definition: helpers.py:20
def pfTools.switchToPFJets (   process,
  input = cms.InputTag('pfNoTau'),
  algo = 'AK5',
  postfix = "",
  jetCorrections = ('AK5PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute,
  type1 = False,
  outputModules = ['out'] 
)

Definition at line 447 of file pfTools.py.

References helpers.applyPostfix(), clone(), if(), patRefSel_refAllJets.jetAlgo, relativeConstraints.keys, and linker.replace().

Referenced by usePF2PAT().

448 def switchToPFJets(process, input=cms.InputTag('pfNoTau'), algo='AK5', postfix = "", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out']):
449 
450  print "Switching to PFJets, ", algo
451  print "************************ "
452  print "input collection: ", input
453 
454  if( algo == 'IC5' ):
455  genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu')
456  elif algo == 'AK5':
457  genJetCollection = cms.InputTag('ak5GenJetsNoNu')
458  elif algo == 'AK7':
459  genJetCollection = cms.InputTag('ak7GenJetsNoNu')
460  else:
461  print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
462  sys.exit(1)
463 
464  # changing the jet collection in PF2PAT:
465  from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
466  inputCollection = getattr(process,"pfJets"+postfix).src
467  setattr(process,"pfJets"+postfix,jetAlgo(algo)) # problem for cfgBrowser
468  getattr(process,"pfJets"+postfix).src = inputCollection
469  inputJetCorrLabel=jetCorrections
470  switchJetCollection(process,
471  input,
472  jetIdLabel = algo,
473  doJTA=True,
474  doBTagging=True,
475  jetCorrLabel=inputJetCorrLabel,
476  doType1MET=type1,
477  genJetCollection = genJetCollection,
478  doJetID = True,
479  postfix = postfix,
480  outputModules = outputModules
481  )
482  # check whether L1FastJet is in the list of correction levels or not
483  applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
484  for corr in inputJetCorrLabel[1]:
485  if corr == 'L1FastJet':
486  applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
487  applyPostfix(process, "pfJets", postfix).doAreaFastjet = True
488  # do correct treatment for TypeI MET corrections
489  if type1:
490  for mod in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
491  if mod.startswith("kt6") and mod.endswith("Jets"+postfix):
492  prefix = mod.replace(postfix,'')
493  prefix = prefix.replace('kt6PFJets','')
494  prefix = prefix.replace('kt6CaloJets','')
495  prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
496  for essource in process.es_sources_().keys():
497  if essource == prefix+'L1FastJet':
498  setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
499  setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone())
500  getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
501  for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
502  if cor == essource:
503  idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
504  getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
505 
506  applyPostfix(process, "patJets", postfix).embedCaloTowers = False
507  applyPostfix(process, "patJets", postfix).embedPFCandidates = True
508 
#-- Remove MC dependence ------------------------------------------------------
string jetAlgo
Jet configuration.
def replace
Definition: linker.py:10
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def switchToPFJets
Definition: pfTools.py:447
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
def pfTools.switchToPFMET (   process,
  input = cms.InputTag('pfMET'),
  type1 = False,
  postfix = "" 
)

Definition at line 391 of file pfTools.py.

References helpers.applyPostfix(), helpers.cloneProcessingSnippet(), if(), python.multivaluedict.remove(), and linker.replace().

Referenced by usePF2PAT().

392 def switchToPFMET(process,input=cms.InputTag('pfMET'), type1=False, postfix=""):
393  print 'MET: using ', input
394  if( not type1 ):
395  oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
396  applyPostfix(process, "patMETs",postfix).metSource = input
397  applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
398  getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
399  else:
400  # type1 corrected MET
401  # name of corrected MET hardcoded in PAT and meaningless
402  print 'Apply TypeI corrections for MET'
403  getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "makePatMETs",postfix))
404  jecLabel = getattr(process,'patJetCorrFactors'+postfix).levels
405 
406  if not hasattr(process,'producePatPFMETCorrections'):
407  process.load("PhysicsTools.PatUtils.patPFMETCorrections_cff")
408  #here add to the current path and give proper postfix
409  if not hasattr(process,'producePatPFMETCorrections'+postfix):
410  cloneProcessingSnippet(process,process.producePatPFMETCorrections,postfix)
411 
412  getattr(process,'patPFMet'+postfix).metSource = cms.InputTag('pfMET'+postfix)
413 
414  getattr(process,'selectedPatJetsForMETtype1p2Corr'+postfix).src = cms.InputTag('selectedPatJets'+postfix)
415  getattr(process,'selectedPatJetsForMETtype2Corr'+postfix).src = cms.InputTag('selectedPatJets'+postfix)
416 
417  getattr(process,'pfCandMETcorr'+postfix).src = cms.InputTag('pfNoJet'+postfix)
418 
419  getattr(process,'patPFJetMETtype1p2Corr'+postfix).offsetCorrLabel = cms.string(jecLabel[0])
420  getattr(process,'patPFJetMETtype1p2Corr'+postfix).jetCorrLabel = cms.string(jecLabel[-1])
421  getattr(process,'patPFJetMETtype1p2Corr'+postfix).type1JetPtThreshold = cms.double(10.0)
422  getattr(process,'patPFJetMETtype1p2Corr'+postfix).skipEM = cms.bool(False)
423  getattr(process,'patPFJetMETtype1p2Corr'+postfix).skipMuons = cms.bool(False)
424 
425  getattr(process,'patPFJetMETtype2Corr'+postfix).offsetCorrLabel = cms.string(jecLabel[0])
426  getattr(process,'patPFJetMETtype2Corr'+postfix).jetCorrLabel = cms.string(jecLabel[-1])
427  getattr(process,'patPFJetMETtype2Corr'+postfix).type1JetPtThreshold = cms.double(10.0)
428  getattr(process,'patPFJetMETtype2Corr'+postfix).skipEM = cms.bool(False)
429  getattr(process,'patPFJetMETtype2Corr'+postfix).skipMuons = cms.bool(False)
430 
431  getattr(process,'patType1CorrectedPFMet'+postfix).srcType1Corrections = cms.VInputTag(
432  cms.InputTag("patPFJetMETtype1p2Corr"+postfix,"type1"),
433  #cms.InputTag("patPFMETtype0Corr"+postfix),
434  )
435  getattr(process,'patType1p2CorrectedPFMet'+postfix).srcType1Corrections = cms.VInputTag(
436  cms.InputTag("patPFJetMETtype1p2Corr"+postfix,"type1"),
437  #cms.InputTag("patPFMETtype0Corr"+postfix),
438  )
439 
440  getattr(process,'patMETs'+postfix).metSource = 'patType1CorrectedPFMet'+postfix
441 
442  getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'selectedPatJets'+postfix),
443  getattr(process,'selectedPatJets'+postfix)
444  *getattr(process,'producePatPFMETCorrections'+postfix)
445  *getattr(process,'patMETs'+postfix)
446  )
def switchToPFMET
Definition: pfTools.py:391
def replace
Definition: linker.py:10
def cloneProcessingSnippet
Definition: helpers.py:262
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
def pfTools.tauTypeInPF2PAT (   process,
  tauType = 'shrinkingConePFTau',
  postfix = "" 
)

Definition at line 355 of file pfTools.py.

References helpers.applyPostfix().

356 def tauTypeInPF2PAT(process,tauType='shrinkingConePFTau', postfix = ""):
357  process.load("CommonTools.ParticleFlow.pfTaus_cff")
358  applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
359 
def tauTypeInPF2PAT
Definition: pfTools.py:355
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def pfTools.useGsfElectrons (   process,
  postfix,
  dR = "04" 
)

Definition at line 34 of file pfTools.py.

References adaptPFIsoElectrons(), helpers.applyPostfix(), linker.replace(), and pfIsolation.setupPFElectronIso().

34 
35 def useGsfElectrons(process, postfix, dR = "04"):
36  print "using Gsf Electrons in PF2PAT"
37  print "WARNING: this will destory the feature of top projection which solves the ambiguity between leptons and jets because"
38  print "WARNING: there will be overlap between non-PF electrons and jets even though top projection is ON!"
39  print "********************* "
40  module = applyPostfix(process,"patElectrons",postfix)
41  module.useParticleFlow = False
42  print "Building particle-based isolation for GsfElectrons in PF2PAT(PFBRECO)"
43  print "********************* "
44  adaptPFIsoElectrons( process, module, postfix+"PFIso", dR )
45  getattr(process,'patDefaultSequence'+postfix).replace( getattr(process,"patElectrons"+postfix),
46  setupPFElectronIso(process, 'gsfElectrons', "PFIso", postfix, runPF2PAT=True) +
47  getattr(process,"patElectrons"+postfix) )
def replace
Definition: linker.py:10
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def useGsfElectrons
Definition: pfTools.py:34
def setupPFElectronIso
Definition: pfIsolation.py:121
def adaptPFIsoElectrons
Definition: pfTools.py:48
def pfTools.usePF2PAT (   process,
  runPF2PAT = True,
  jetAlgo = 'AK5',
  runOnMC = True,
  postfix = "",
  jetCorrections = ('AK5PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute,
  pvCollection = cms.InputTag('offlinePrimaryVertices'),
  typeIMetCorrections = False,
  outputModules = ['out'] 
)
Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence

Definition at line 549 of file pfTools.py.

References adaptPFElectrons(), adaptPFMuons(), adaptPFTaus(), adaptPVs(), addPFCandidates(), helpers.applyPostfix(), helpers.cloneProcessingSnippet(), helpers.removeIfInSequence(), removeMCMatchingPF2PAT(), linker.replace(), switchToPFJets(), and switchToPFMET().

Referenced by SUSY_pattuple_cff.loadPF2PAT().

550 def usePF2PAT(process, runPF2PAT=True, jetAlgo='AK5', runOnMC=True, postfix="", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative','L3Absolute']), pvCollection=cms.InputTag('offlinePrimaryVertices'), typeIMetCorrections=False, outputModules=['out']):
551  # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
552  # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
553 
554  """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
555 
556  # -------- CORE ---------------
557  if runPF2PAT:
558  process.load("CommonTools.ParticleFlow.PF2PAT_cff")
559  #add Pf2PAT *before* cloning so that overlapping modules are cloned too
560  #process.patDefaultSequence.replace( process.patCandidates, process.PF2PAT+process.patCandidates)
561  process.patPF2PATSequence = cms.Sequence( process.PF2PAT + process.patDefaultSequence)
562  else:
563  process.patPF2PATSequence = cms.Sequence( process.patDefaultSequence )
564 
565  if not postfix == "":
566  from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
567  cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)
568  #delete everything pat PF2PAT modules! if you want to test the postfixing for completeness
569  #from PhysicsTools.PatAlgos.tools.helpers import listModules,listSequences
570  #for module in listModules(process.patDefaultSequence):
571  # if not module.label() is None: process.__delattr__(module.label())
572  #for sequence in listSequences(process.patDefaultSequence):
573  # if not sequence.label() is None: process.__delattr__(sequence.label())
574  #del process.patDefaultSequence
575 
576  removeCleaning(process, postfix=postfix, outputModules=outputModules)
577 
578  # -------- OBJECTS ------------
579  # Muons
580  adaptPFMuons(process,
581  applyPostfix(process,"patMuons",postfix),
582  postfix)
583 
584  # Electrons
585  adaptPFElectrons(process,
586  applyPostfix(process,"patElectrons",postfix),
587  postfix)
588 
589  # Photons
590  print "Temporarily switching off photons completely"
591 
592  removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
593  removeIfInSequence(process,"patPhotonIsolation","patDefaultSequence",postfix)
594 
595  # Jets
596  if runOnMC :
597  switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
598  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
599  applyPostfix(process,"patDefaultSequence",postfix).replace(
600  applyPostfix(process,"patJetGenJetMatch",postfix),
601  getattr(process,"genForPF2PATSequence") *
602  applyPostfix(process,"patJetGenJetMatch",postfix)
603  )
604  else :
605  if not 'L2L3Residual' in jetCorrections[1]:
606  print '#################################################'
607  print 'WARNING! Not using L2L3Residual but this is data.'
608  print 'If this is okay with you, disregard this message.'
609  print '#################################################'
610  switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
611  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
612 
613  # Taus
614  #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
615  #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
616  adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
617 
618  # MET
619  switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
620  if not runOnMC :
621  if hasattr(process,'patPFMet'+postfix):
622  getattr(process,'patPFMet'+postfix).addGenMET = cms.bool(False)
623 
624  # Unmasked PFCandidates
625  addPFCandidates(process,cms.InputTag('pfNoJet'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
626 
627  # adapt primary vertex collection
628  adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
629 
630  if runOnMC:
631  process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
632  getattr(process, "patDefaultSequence"+postfix).replace(
633  applyPostfix(process,"patCandidates",postfix),
634  process.genForPF2PATSequence+applyPostfix(process,"patCandidates",postfix)
635  )
636  else:
637  removeMCMatchingPF2PAT(process,postfix=postfix,outputModules=outputModules)
638 
639  print "Done: PF2PAT interfaced to PAT, postfix=", postfix
def switchToPFMET
Definition: pfTools.py:391
def adaptPFTaus
Definition: pfTools.py:322
def replace
Definition: linker.py:10
def adaptPFMuons
Definition: pfTools.py:102
def cloneProcessingSnippet
Definition: helpers.py:262
def removeMCMatchingPF2PAT
Definition: pfTools.py:509
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def usePF2PAT
Definition: pfTools.py:549
def addPFCandidates
Definition: pfTools.py:360
def adaptPVs
Definition: pfTools.py:515
def adaptPFElectrons
Definition: pfTools.py:135
def switchToPFJets
Definition: pfTools.py:447
def removeIfInSequence
Definition: helpers.py:20
def pfTools.usePFIso (   process,
  postfix = "PFIso" 
)

Definition at line 89 of file pfTools.py.

References adaptPFIsoElectrons(), adaptPFIsoMuons(), helpers.applyPostfix(), linker.replace(), pfIsolation.setupPFElectronIso(), and pfIsolation.setupPFMuonIso().

Referenced by SUSY_pattuple_cff.loadPAT().

89 
90 def usePFIso(process, postfix = "PFIso"):
91  print "Building particle-based isolation "
92  print "***************** "
93  process.eleIsoSequence = setupPFElectronIso(process, 'gsfElectrons', postfix)
94  process.muIsoSequence = setupPFMuonIso(process, 'muons', postfix)
95  adaptPFIsoMuons( process, applyPostfix(process,"patMuons",""), postfix)
96  adaptPFIsoElectrons( process, applyPostfix(process,"patElectrons",""), postfix)
97  getattr(process,'patDefaultSequence').replace( getattr(process,"patCandidates"),
98  process.pfParticleSelectionSequence +
99  process.eleIsoSequence +
100  process.muIsoSequence +
101  getattr(process,"patCandidates") )
def setupPFMuonIso
Definition: pfIsolation.py:112
def adaptPFIsoMuons
Definition: pfTools.py:72
def replace
Definition: linker.py:10
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def usePFIso
Definition: pfTools.py:89
def setupPFElectronIso
Definition: pfIsolation.py:121
def adaptPFIsoElectrons
Definition: pfTools.py:48
def pfTools.warningIsolation ( )

Definition at line 29 of file pfTools.py.

Referenced by adaptPFElectrons(), and adaptPFMuons().

29 
30 def warningIsolation():
31  print "WARNING: particle based isolation must be studied"
def warningIsolation
Definition: pfTools.py:29