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 usePF2PAT
 
def warningIsolation
 

Function Documentation

def pfTools.adaptPFElectrons (   process,
  module,
  postfix 
)

Definition at line 88 of file pfTools.py.

Referenced by usePF2PAT().

88 
89 def adaptPFElectrons(process,module, postfix):
90  # module.useParticleFlow = True
91  print "Adapting PF Electrons "
92  print "********************* "
93  #warningIsolation()
94  print
95  module.useParticleFlow = True
96  module.pfElectronSource = cms.InputTag("pfIsolatedElectrons" + postfix)
97  module.userIsolation = cms.PSet()
98  ## module.isoDeposits = cms.PSet(
99  ## pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
100  ## pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
101  ## pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
102  ## pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
103  ## pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
104  ## )
105  ## module.isolationValues = cms.PSet(
106  ## pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
107  ## pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
108  ## pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
109  ## pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
110  ## pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
111  ## )
112 
113  # COLIN: since we take the egamma momentum for pat Electrons, we must
114  # match the egamma electron to the gen electrons, and not the PFElectron.
115  # -> do not uncomment the line below.
116  # process.electronMatch.src = module.pfElectronSource
117  # COLIN: how do we depend on this matching choice?
118 
119  print " PF electron source:", module.pfElectronSource
120  ## print " isolation :"
121  ## print module.isolationValues
122  ## print " isodeposits: "
123  ## print module.isoDeposits
124  print
125 
126 
127 
def adaptPFElectrons
Definition: pfTools.py:88
def pfTools.adaptPFIsoElectrons (   process,
  module,
  postfix = "PFIso",
  dR = "04" 
)

Definition at line 14 of file pfTools.py.

14 
15 def adaptPFIsoElectrons(process,module, postfix = "PFIso", dR = "04"):
16  #FIXME: adaptPFElectrons can use this function.
17  module.isoDeposits = cms.PSet(
18  pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
19  pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
20  pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
21  pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
22  pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
23  )
24  module.isolationValues = cms.PSet(
25  pfChargedHadrons = cms.InputTag("elPFIsoValueCharged"+dR+"PFId"+ postfix),
26  pfChargedAll = cms.InputTag("elPFIsoValueChargedAll"+dR+"PFId"+ postfix),
27  pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU"+dR+"PFId" + postfix),
28  pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral"+dR+"PFId" + postfix),
29  pfPhotons = cms.InputTag("elPFIsoValueGamma"+dR+"PFId" + postfix)
30  )
31  module.isolationValuesNoPFId = cms.PSet(
32  pfChargedHadrons = cms.InputTag("elPFIsoValueCharged"+dR+"NoPFId"+ postfix),
33  pfChargedAll = cms.InputTag("elPFIsoValueChargedAll"+dR+"NoPFId"+ postfix),
34  pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU"+dR+"NoPFId" + postfix),
35  pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral"+dR+"NoPFId" + postfix),
36  pfPhotons = cms.InputTag("elPFIsoValueGamma"+dR+"NoPFId" + postfix)
37  )
def adaptPFIsoElectrons
Definition: pfTools.py:14
def pfTools.adaptPFIsoMuons (   process,
  module,
  postfix = "PFIso",
  dR = "04" 
)

Definition at line 38 of file pfTools.py.

38 
39 def adaptPFIsoMuons(process,module, postfix = "PFIso", dR = "04"):
40  #FIXME: adaptPFMuons can use this function.
41  module.isoDeposits = cms.PSet(
42  pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
43  pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
44  pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
45  pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
46  pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
47  )
48  module.isolationValues = cms.PSet(
49  pfChargedHadrons = cms.InputTag("muPFIsoValueCharged" + dR + postfix),
50  pfChargedAll = cms.InputTag("muPFIsoValueChargedAll" + dR + postfix),
51  pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU" + dR + postfix),
52  pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral" + dR + postfix),
53  pfPhotons = cms.InputTag("muPFIsoValueGamma" + dR + postfix)
54  )
def adaptPFIsoMuons
Definition: pfTools.py:38
def pfTools.adaptPFMuons (   process,
  module,
  postfix = "" 
)

Definition at line 55 of file pfTools.py.

References helpers.applyPostfix().

Referenced by usePF2PAT().

55 
56 def adaptPFMuons(process,module,postfix="" ):
57  print "Adapting PF Muons "
58  print "***************** "
59  #warningIsolation()
60  print
61  module.useParticleFlow = True
62  module.pfMuonSource = cms.InputTag("pfIsolatedMuons" + postfix)
63  module.userIsolation = cms.PSet()
64  ## module.isoDeposits = cms.PSet(
65  ## pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
66  ## pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
67  ## pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
68  ## pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
69  ## pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
70  ## )
71  ## module.isolationValues = cms.PSet(
72  ## pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
73  ## pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
74  ## pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
75  ## pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
76  ## pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
77  ## )
78  # matching the pfMuons, not the standard muons.
79  applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
80 
81  print " muon source:", module.pfMuonSource
82  ## print " isolation :",
83  ## print module.isolationValues
84  ## print " isodeposits: "
85  ## print module.isoDeposits
86  print
87 
def adaptPFMuons
Definition: pfTools.py:55
def applyPostfix
Definition: helpers.py:70
def pfTools.adaptPFPhotons (   process,
  module 
)

Definition at line 128 of file pfTools.py.

References reconfigurePF2PATTaus().

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

Definition at line 268 of file pfTools.py.

References reconfigurePF2PATTaus(), and tauTools.switchToPFTauByType().

Referenced by usePF2PAT().

269 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
270  # Set up the collection used as a preselection to use this tau type
271  if tauType != 'hpsPFTau' :
272  reconfigurePF2PATTaus(process, tauType, postfix=postfix)
273  else:
274  reconfigurePF2PATTaus(process, tauType,
275  ["DiscriminationByDecayModeFinding"],
276  ["DiscriminationByDecayModeFinding"],
277  postfix=postfix)
278  # new default use unselected taus (selected only for jet cleaning)
279  if tauType != 'hpsPFTau' :
280  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
281  else:
282  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
283  # to use preselected collection (old default) uncomment line below
284  #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
285 
286  ### apparently not needed anymore, function gone from tauTools.py###
287  #redoPFTauDiscriminators(process,
288  #cms.InputTag(tauType+'Producer'),
289  #applyPostfix(process,"patTaus", postfix).tauSource,
290  #tauType, postfix=postfix)
291 
292 
293  if tauType != 'hpsPFTau' :
294  switchToPFTauByType(process, pfTauType=tauType,
295  patTauLabel="pfTausBase"+postfix,
296  tauSource=cms.InputTag(tauType+'Producer'+postfix),
297  postfix=postfix)
298  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
299  else:
300  switchToPFTauByType(process, pfTauType=tauType,
301  patTauLabel="",
302  tauSource=cms.InputTag(tauType+'Producer'+postfix),
303  postfix=postfix)
304  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
305 
306 
307 
#helper function for PAT on PF2PAT sample
def adaptPFTaus
Definition: pfTools.py:268
def reconfigurePF2PATTaus
Definition: pfTools.py:138
def switchToPFTauByType
Definition: tauTools.py:219
def pfTools.adaptPVs (   process,
  pvCollection = cms.InputTag('offlinePrimaryVertices'),
  postfix = '' 
)

Definition at line 421 of file pfTools.py.

References split.

Referenced by usePF2PAT().

422 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix=''):
423  print "Switching PV collection for PF2PAT:", pvCollection
424  print "***********************************"
425 
426  # PV sources to be exchanged:
427  pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs']
428  # PV sources NOT to be exchanged:
429  #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc','primaryVertex']
430 
431  # find out all added jet collections (they don't belong to PF2PAT)
432  interPostfixes = []
433  for m in process.producerNames().split(' '):
434  if m.startswith('patJets') and m.endswith(postfix) and not len(m)==len('patJets')+len(postfix):
435  interPostfix = m.replace('patJets','')
436  interPostfix = interPostfix.replace(postfix,'')
437  interPostfixes.append(interPostfix)
438 
439  # exchange the primary vertex source of all relevant modules
440  for m in process.producerNames().split(' '):
441  modName = m.replace(postfix,'')
442  # only if the module has a source with a relevant name
443  for namePvSrc in pvExchange:
444  if hasattr(getattr(process,m),namePvSrc):
445  # only if the module is not coming from an added jet collection
446  interPostFixFlag = False
447  for pfix in interPostfixes:
448  if modName.endswith(pfix):
449  interPostFixFlag = True
450  break
451  if not interPostFixFlag:
452  setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
453 
def adaptPVs
Definition: pfTools.py:421
double split
Definition: MVATrainer.cc:139
def pfTools.addPFCandidates (   process,
  src,
  patLabel = 'PFParticles',
  cut = "",
  postfix = "" 
)

Definition at line 313 of file pfTools.py.

References helpers.applyPostfix().

Referenced by usePF2PAT().

314 def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""):
315  from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
316  # make modules
317  producer = patPFParticles.clone(pfCandidateSource = src)
318  filter = cms.EDFilter("PATPFParticleSelector",
319  src = cms.InputTag("pat" + patLabel),
320  cut = cms.string(cut))
321  counter = cms.EDFilter("PATCandViewCountFilter",
322  minNumber = cms.uint32(0),
323  maxNumber = cms.uint32(999999),
324  src = cms.InputTag("pat" + patLabel))
325  # add modules to process
326  setattr(process, "pat" + patLabel, producer)
327  setattr(process, "selectedPat" + patLabel, filter)
328  setattr(process, "countPat" + patLabel, counter)
329 
330  # summary tables
331  applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
332  applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
333 
def applyPostfix
Definition: helpers.py:70
def addPFCandidates
Definition: pfTools.py:313
def pfTools.reconfigurePF2PATTaus (   process,
  tauType = 'shrinkingConePFTau',
  pf2patSelection = ["DiscriminationByIsolation",
  DiscriminationByLeadingPionPtCut,
  selectionDependsOn = ["DiscriminationByLeadingTrackFinding"],
  producerFromType = lambda producer: producer+"Producer",
  postfix = "" 
)

Definition at line 138 of file pfTools.py.

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

Referenced by adaptPFPhotons(), and adaptPFTaus().

139  postfix = ""):
140  print "patTaus will be produced from taus of type: %s that pass %s" \
141  % (tauType, pf2patSelection)
142 
143 
144 
145  # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer
146  producerName = producerFromType(tauType)
147  # Set as the source for the pf2pat taus (pfTaus) selector
148  applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
149  # Start our pf2pat taus base sequence
150  oldTauSansRefs = getattr(process,'pfTausProducerSansRefs'+postfix)
151  oldTau = getattr(process,'pfTausProducer'+postfix)
152  ## copy tau and setup it properly
153  newTauSansRefs = None
154  newTau = getattr(process,producerName+postfix).clone()
155 
156  ## adapted to new structure in RecoTauProducers PLEASE CHECK!!!
157  if tauType=='shrinkingConePFTau':
158  newTauSansRefs = getattr(process,producerName+"SansRefs").clone()
159  newTauSansRefs.modifiers[1] = cms.PSet(
160  pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
161  name = cms.string('pfTauTTIworkaround'+postfix),
162  plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
163  )
164  newTau.modifiers[1] = newTauSansRefs.modifiers[1]
165  newTauSansRefs.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
166  newTau.piZeroSrc = newTauSansRefs.piZeroSrc
167  newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
168  newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
169  newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
170  elif tauType=='fixedConePFTau':
171  newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
172  elif tauType=='hpsPFTau':
173  newTau = getattr(process,'combinatoricRecoTaus'+postfix).clone()
174  newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
175  newTau.modifiers[3] = cms.PSet(
176  pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
177  name = cms.string('pfTauTTIworkaround'+postfix),
178  plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
179  )
180  from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
181  #cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix)
182  setattr(process,'produceHPSPFTaus'+postfix,cms.Sequence(applyPostfix(process,'hpsSelectionDiscriminator',postfix)+applyPostfix(process,'hpsPFTauProducerSansRefs',postfix)+applyPostfix(process,'hpsPFTauProducer',postfix)))
183  massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
184  "PFTauProducer",
185  cms.InputTag("combinatoricRecoTaus"+postfix),
186  cms.InputTag("pfTausBase"+postfix) )
187  massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
188  "src",
189  cms.InputTag("combinatoricRecoTaus"+postfix),
190  cms.InputTag("pfTausBase"+postfix) )
191  ### Next three lines crash, oldTau does not have any of these attributes. Why?###
192  #newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
193  #newTau.jetRegionSrc = oldTau.jetRegionSrc
194  #newTau.jetSrc = oldTau.jetSrc
195  #newTau.builders[0].pfCandSrc = cms.InputTag("pfNoElectronJMEPFlow")
196  #newTau.jetRegionSrc = cms.InputTag("pfTauPFJets08RegionPFlow")
197  #newTau.jetSrc = cms.InputTag("pfJetsPFlow")
198  # replace old tau producer by new one put it into baseSequence
199  setattr(process,"pfTausBase"+postfix,newTau)
200  if tauType=='shrinkingConePFTau':
201  setattr(process,"pfTausBaseSansRefs"+postfix,newTauSansRefs)
202  getattr(process,"pfTausBase"+postfix).src = "pfTausBaseSansRefs"+postfix
203  baseSequence += getattr(process,"pfTausBaseSansRefs"+postfix)
204 
205  #make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
206  def producerIsTauTypeMapperWithPostfix(tauProducer):
207  return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
208 
209  def recoTauTypeMapperWithGroup(tauProducer):
210  return "%s(.*)"%recoTauTypeMapper(tauProducer)
211 
212  # Get our prediscriminants
213  for predisc in selectionDependsOn:
214  # Get the prototype
215  originalName = tauType+predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding
216  clonedName = "pfTausBase"+predisc+postfix
217  clonedDisc = getattr(process, originalName).clone()
218  setattr(process, clonedName, clonedDisc)
219 
220  tauCollectionToSelect = None
221  if tauType != 'hpsPFTau' :
222  tauCollectionToSelect = "pfTausBase"+postfix
223  #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
224  else:
225  tauCollectionToSelect = "hpsPFTauProducer"+postfix
226  # Adapt this discriminator for the cloned prediscriminators
227  adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
228  oldTauTypeMapper=recoTauTypeMapperWithGroup,
229  newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
230  preservePFTauProducer=True)
231  clonedDisc.PFTauProducer = tauCollectionToSelect
232 
233  # Reconfigure the pf2pat PFTau selector discrimination sources
234  getattr(process,"pfTaus" + postfix).discriminators = cms.VPSet()
235  for selection in pf2patSelection:
236  # Get our discriminator that will be used to select pfTaus
237  originalName = tauType+selection
238  clonedName = "pfTausBase"+selection+postfix
239  clonedDisc = getattr(process, originalName).clone()
240  setattr(process, clonedName, clonedDisc)
241 
242  tauCollectionToSelect = None
243 
244  if tauType != 'hpsPFTau' :
245  tauCollectionToSelect = cms.InputTag("pfTausBase"+postfix)
246  #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
247  else:
248  tauCollectionToSelect = cms.InputTag("hpsPFTauProducer"+postfix)
249  #Adapt our cloned discriminator to the new prediscriminants
250  adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
251  oldTauTypeMapper=recoTauTypeMapperWithGroup,
252  newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
253  preservePFTauProducer=True)
254  clonedDisc.PFTauProducer = tauCollectionToSelect
255 
256  # Add this selection to our pfTau selectors
257  getattr(process,"pfTaus" + postfix).discriminators.append(cms.PSet(
258  discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
259  # Set the input of the final selector.
260  if tauType != 'hpsPFTau':
261  getattr(process,"pfTaus" + postfix).src = "pfTausBase"+postfix
262  else:
263  # If we are using HPS taus, we need to take the output of the clenaed
264  # collection
265  getattr(process,"pfTaus" + postfix).src = "hpsPFTauProducer"+postfix
266 
267 
def applyPostfix
Definition: helpers.py:70
def massSearchReplaceParam
Definition: helpers.py:249
tuple clone
Definition: statics.py:58
def pfTools.removeMCMatchingPF2PAT (   process,
  postfix = "",
  outputModules = ['out'] 
)

Definition at line 414 of file pfTools.py.

415 def removeMCMatchingPF2PAT( process, postfix="", outputModules=['out'] ):
416  #from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
417  ### no longe needed in unscheduled mode###
418  #removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
419  removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
420 
def removeMCMatchingPF2PAT
Definition: pfTools.py:414
def pfTools.switchToPFJets (   process,
  input = cms.InputTag('pfNoTauClones'),
  algo = 'AK5',
  postfix = "",
  jetCorrections = ('AK5PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute,
  type1 = False,
  outputModules = ['out'] 
)

Definition at line 350 of file pfTools.py.

References helpers.applyPostfix(), statics.clone, reco.if(), patRefSel_refAllJets.jetAlgo, relativeConstraints.keys, python.rootplot.root2matplotlib.replace(), and split.

Referenced by usePF2PAT().

351 def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK5', postfix = "", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out']):
352 
353  print "Switching to PFJets, ", algo
354  print "************************ "
355  print "input collection: ", input
356 
357  if( algo == 'IC5' ):
358  genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu')
359  elif algo == 'AK5':
360  genJetCollection = cms.InputTag('ak5GenJetsNoNu')
361  elif algo == 'AK7':
362  genJetCollection = cms.InputTag('ak7GenJetsNoNu')
363  else:
364  print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
365  sys.exit(1)
366 
367  # changing the jet collection in PF2PAT:
368  from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
369  inputCollection = getattr(process,"pfJets"+postfix).src
370  setattr(process,"pfJets"+postfix,jetAlgo(algo)) # problem for cfgBrowser
371  getattr(process,"pfJets"+postfix).src = inputCollection
372  inputJetCorrLabel=jetCorrections
373 
374  switchJetCollection(process,
375  jetSource = input,
376  algo=algo,
377  postfix=postfix,
378  jetTrackAssociation=True,
379  jetCorrections=inputJetCorrLabel,
380  outputModules = outputModules,
381  #btagDiscriminators = ['combinedSecondaryVertexBJetTags',]
382  )
383 
384  # check whether L1FastJet is in the list of correction levels or not
385  applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
386  for corr in inputJetCorrLabel[1]:
387  if corr == 'L1FastJet':
388  applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
389  applyPostfix(process, "pfJets", postfix).doAreaFastjet = True
390  # do correct treatment for TypeI MET corrections
391  #type1=True
392  if type1:
393  for mod in process.producerNames().split(' '):
394 
395  if mod.startswith("kt6") and mod.endswith("Jets"+postfix) and not 'GenJets' in mod:
396  prefix = mod.replace(postfix,'')
397  prefix = prefix.replace('kt6PFJets','')
398  prefix = prefix.replace('kt6CaloJets','')
399  prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
400  for essource in process.es_sources_().keys():
401  if essource == prefix+'L1FastJet':
402  setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
403  setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone())
404  getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
405  for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
406  if cor == essource:
407  idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
408  getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
409 
410  if hasattr( getattr( process, "patJets" + postfix), 'embedCaloTowers' ): # optional parameter, which defaults to 'False' anyway
411  applyPostfix(process, "patJets", postfix).embedCaloTowers = False
412  applyPostfix(process, "patJets", postfix).embedPFCandidates = True
413 
#-- Remove MC dependence ------------------------------------------------------
string jetAlgo
Jet configuration.
def applyPostfix
Definition: helpers.py:70
def switchToPFJets
Definition: pfTools.py:350
if(dp >Float(M_PI)) dp-
tuple clone
Definition: statics.py:58
double split
Definition: MVATrainer.cc:139
def pfTools.switchToPFMET (   process,
  input = cms.InputTag('pfMET'),
  type1 = False,
  postfix = "" 
)

Definition at line 334 of file pfTools.py.

References helpers.applyPostfix(), reco.if(), and python.rootplot.root2matplotlib.replace().

Referenced by usePF2PAT().

335 def switchToPFMET(process,input=cms.InputTag('pfMET'), type1=False, postfix=""):
336  print 'MET: using ', input
337  if( not type1 ):
338  oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
339  applyPostfix(process, "patMETs",postfix).metSource = input
340  applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
341  else:
342  # type1 corrected MET
343  # name of corrected MET hardcoded in PAT and meaningless
344  print 'Apply TypeI corrections for MET'
345  #getattr(process, "patPF2PATSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
346  jecLabel = getattr(process,'patJetCorrFactors'+postfix).payload.pythonValue().replace("'","")
347  getattr(process,jecLabel+'Type1CorMet'+postfix).src = input.getModuleLabel()
348  #getattr(process,'patMETs'+postfix).metSource = jecLabel+'Type1CorMet'+postfix
349  #getattr(process,'patMETs'+postfix).addMuonCorrections = False
def switchToPFMET
Definition: pfTools.py:334
def applyPostfix
Definition: helpers.py:70
if(dp >Float(M_PI)) dp-
def pfTools.tauTypeInPF2PAT (   process,
  tauType = 'shrinkingConePFTau',
  postfix = "" 
)

Definition at line 308 of file pfTools.py.

References helpers.applyPostfix().

309 def tauTypeInPF2PAT(process,tauType='shrinkingConePFTau', postfix = ""):
310  process.load("CommonTools.ParticleFlow.pfTaus_cff")
311  applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
312 
def tauTypeInPF2PAT
Definition: pfTools.py:308
def applyPostfix
Definition: helpers.py:70
def pfTools.usePF2PAT (   process,
  runPF2PAT = True,
  jetAlgo = 'ak5',
  runOnMC = True,
  postfix = "",
  jetCorrections = ('AK5PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute,
  None,
  pvCollection = cms.InputTag('offlinePrimaryVertices',,
  typeIMetCorrections = False,
  outputModules = ['out'],
  excludeFromTopProjection = ['Tau'] 
)

Definition at line 454 of file pfTools.py.

References adaptPFElectrons(), adaptPFMuons(), adaptPFTaus(), adaptPVs(), addPFCandidates(), helpers.applyPostfix(), helpers.loadWithPostfix(), switchToPFJets(), and switchToPFMET().

455 def usePF2PAT(process,runPF2PAT=True, jetAlgo='ak5', runOnMC=True, postfix="", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative','L3Absolute'],'None'), pvCollection=cms.InputTag('offlinePrimaryVertices',), typeIMetCorrections=False, outputModules=['out'],excludeFromTopProjection=['Tau']):
456  # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
457  # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
458 
459  if typeIMetCorrections:
460  jetCorrections = (jetCorrections[0],jetCorrections[1],'Type-1')
461  """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
462 
463  # -------- CORE ---------------
464  from PhysicsTools.PatAlgos.tools.helpers import loadWithPostfix
465  if runPF2PAT:
466  loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix)
467  loadWithPostfix(process,"CommonTools.ParticleFlow.PF2PAT_cff",postfix)
468  else:
469  loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix)
470 
471 
472 
473 
474  # -------- OBJECTS ------------
475  # Muons
476 
477  adaptPFMuons(process,
478  applyPostfix(process,"patMuons",postfix),
479  postfix)
480 
481  # Electrons
482 
483  adaptPFElectrons(process,
484  applyPostfix(process,"patElectrons",postfix),
485  postfix)
486 
487  # Photons
488  #print "Temporarily switching off photons completely"
489 
490  #removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
491 
492  # Jets
493  if runOnMC :
494  switchToPFJets( process, cms.InputTag('pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
495  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
496 
497  else :
498  if not 'L2L3Residual' in jetCorrections[1]:
499  ### think of a more accurate warning
500  print '#################################################'
501  print 'WARNING! Not using L2L3Residual but this is data.'
502  print 'If this is okay with you, disregard this message.'
503  print '#################################################'
504  switchToPFJets( process, cms.InputTag('pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
505  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
506  # Taus
507  #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
508  #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
509  adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
510  # MET
511  switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
512 
513  # Unmasked PFCandidates
514  addPFCandidates(process,cms.InputTag('pfNoJetClones'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
515 
516  # adapt primary vertex collection
517  adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
518 
519  if runOnMC:
520 
521  loadWithPostfix(process,"CommonTools.ParticleFlow.genForPF2PAT_cff",postfix)
522 
523  else:
524  runOnData(process,postfix=postfix,outputModules=outputModules)
525 
526  # Configure Top Projections
527  getattr(process,"pfNoPileUp"+postfix).enable = True
528  getattr(process,"pfNoMuon"+postfix).enable = True
529  getattr(process,"pfNoElectron"+postfix).enable = True
530  getattr(process,"pfNoTau"+postfix).enable = False
531  getattr(process,"pfNoJet"+postfix).enable = True
532  exclusionList = ''
533  for object in excludeFromTopProjection:
534  getattr(process,"pfNo"+object+postfix).enable = False
535  exclusionList=exclusionList+object+','
536  exclusionList=exclusionList.rstrip(',')
537  print "Done: PF2PAT interfaced to PAT, postfix=", postfix,", Exluded from Top Projection:",exclusionList
def switchToPFMET
Definition: pfTools.py:334
def adaptPFTaus
Definition: pfTools.py:268
def adaptPFMuons
Definition: pfTools.py:55
def applyPostfix
Definition: helpers.py:70
def usePF2PAT
Definition: pfTools.py:454
def addPFCandidates
Definition: pfTools.py:313
def adaptPVs
Definition: pfTools.py:421
def adaptPFElectrons
Definition: pfTools.py:88
def switchToPFJets
Definition: pfTools.py:350
def loadWithPostfix
Definition: helpers.py:18
def pfTools.warningIsolation ( )

Definition at line 11 of file pfTools.py.

11 
12 def warningIsolation():
13  print "WARNING: particle based isolation must be studied"
def warningIsolation
Definition: pfTools.py:11