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 515 of file pfTools.py.

Referenced by usePF2PAT().

516 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix='', sequence='patPF2PATSequence'):
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','primaryVertex']
523  # PV sources NOT to be exchanged:
524  #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc']
525 
526  # exchange the primary vertex source of all relevant modules
527  for m in getattr(process,sequence+postfix).moduleNames():
528  modName = m.replace(postfix,'')
529  # only if the module has a source with a relevant name
530  for namePvSrc in pvExchange:
531  if hasattr(getattr(process,m),namePvSrc):
532  #print m
533  setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
534 
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 535 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().

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