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 = '',
  sequence = 'patPF2PATSequence' 
)

Definition at line 516 of file pfTools.py.

Referenced by usePF2PAT().

517 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix='', sequence='patPF2PATSequence'):
518 
519  print "Switching PV collection for PF2PAT:", pvCollection
520  print "***********************************"
521 
522  # PV sources to be exchanged:
523  pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs','primaryVertex']
524  # PV sources NOT to be exchanged:
525  #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc']
526 
527  # exchange the primary vertex source of all relevant modules
528  for m in getattr(process,sequence+postfix).moduleNames():
529  modName = m.replace(postfix,'')
530  # only if the module has a source with a relevant name
531  for namePvSrc in pvExchange:
532  if hasattr(getattr(process,m),namePvSrc):
533  #print m
534  setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
535 
def adaptPVs
Definition: pfTools.py:516
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 python.rootplot.root2matplotlib.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 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 510 of file pfTools.py.

References helpers.removeIfInSequence().

Referenced by usePF2PAT().

511 def removeMCMatchingPF2PAT( process, postfix="", outputModules=['out'] ):
512  from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
513  removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
514  removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
515 
def removeMCMatchingPF2PAT
Definition: pfTools.py:510
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(), patRefSel_refAllJets.jetAlgo, relativeConstraints.keys, and python.rootplot.root2matplotlib.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 == 'AK5':
455  genJetCollection = cms.InputTag('ak5GenJetsNoNu')
456  rParam=0.5
457  elif algo == 'AK7':
458  genJetCollection = cms.InputTag('ak7GenJetsNoNu')
459  rParam=0.7
460  else:
461  print 'bad jet algorithm:', algo, '! for now, only 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  rParam=rParam,
474  doJTA=True,
475  doBTagging=True,
476  jetCorrLabel=inputJetCorrLabel,
477  doType1MET=type1,
478  genJetCollection = genJetCollection,
479  doJetID = True,
480  postfix = postfix,
481  outputModules = outputModules
482  )
483  # check whether L1FastJet is in the list of correction levels or not
484  applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
485  for corr in inputJetCorrLabel[1]:
486  if corr == 'L1FastJet':
487  applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
488  applyPostfix(process, "pfJets", postfix).doAreaFastjet = True
489  # do correct treatment for TypeI MET corrections
490  if type1:
491  for mod in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
492  if mod.startswith("kt6") and mod.endswith("Jets"+postfix):
493  prefix = mod.replace(postfix,'')
494  prefix = prefix.replace('kt6PFJets','')
495  prefix = prefix.replace('kt6CaloJets','')
496  prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
497  for essource in process.es_sources_().keys():
498  if essource == prefix+'L1FastJet':
499  setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
500  setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone())
501  getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
502  for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
503  if cor == essource:
504  idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
505  getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
506 
507  applyPostfix(process, "patJets", postfix).embedCaloTowers = False
508  applyPostfix(process, "patJets", postfix).embedPFCandidates = True
509 
#-- Remove MC dependence ------------------------------------------------------
string jetAlgo
Jet configuration.
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
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 python.rootplot.root2matplotlib.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 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(), python.rootplot.root2matplotlib.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 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 536 of file pfTools.py.

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

Referenced by SUSY_pattuple_cff.loadPF2PAT().

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