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

References split.

Referenced by usePF2PAT().

423 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix=''):
424  print "Switching PV collection for PF2PAT:", pvCollection
425  print "***********************************"
426 
427  # PV sources to be exchanged:
428  pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs','primaryVertex']
429  # PV sources NOT to be exchanged:
430  #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc']
431 
432  # exchange the primary vertex source of all relevant modules
433  for m in (process.producerNames().split(' ') + process.filterNames().split(' ')):
434  # only if the module has a source with a relevant name
435  for namePvSrc in pvExchange:
436  if hasattr(getattr(process,m),namePvSrc):
437  #print m
438  setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
439 
def adaptPVs
Definition: pfTools.py:422
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(), 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
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def pfTools.removeMCMatchingPF2PAT (   process,
  postfix = "",
  outputModules = ['out'] 
)

Definition at line 415 of file pfTools.py.

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

Definition at line 350 of file pfTools.py.

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

Referenced by usePF2PAT().

351 def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK4', postfix = "", jetCorrections=('AK4PFchs', ['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 == 'AK4':
358  genJetCollection = cms.InputTag('ak4GenJetsNoNu'+postfix)
359  rParam=0.4
360  elif algo == 'AK7':
361  genJetCollection = cms.InputTag('ak7GenJetsNoNu'+postfix)
362  rParam=0.7
363  else:
364  print 'bad jet algorithm:', algo, '! for now, only AK4 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  rParam=rParam,
378  genJetCollection=genJetCollection,
379  postfix=postfix,
380  jetTrackAssociation=True,
381  jetCorrections=inputJetCorrLabel,
382  outputModules = outputModules,
383  )
384 
385  # check whether L1FastJet is in the list of correction levels or not
386  applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
387  for corr in inputJetCorrLabel[1]:
388  if corr == 'L1FastJet':
389  applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
390  applyPostfix(process, "pfJets", postfix).doAreaFastjet = True
391  # do correct treatment for TypeI MET corrections
392  #type1=True
393  if type1:
394  for mod in process.producerNames().split(' '):
395 
396  if mod.startswith("kt6") and mod.endswith("Jets"+postfix) and not 'GenJets' in mod:
397  prefix = mod.replace(postfix,'')
398  prefix = prefix.replace('kt6PFJets','')
399  prefix = prefix.replace('kt6CaloJets','')
400  prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
401  for essource in process.es_sources_().keys():
402  if essource == prefix+'L1FastJet':
403  setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
404  setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone())
405  getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
406  for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
407  if cor == essource:
408  idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
409  getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
410 
411  if hasattr( getattr( process, "patJets" + postfix), 'embedCaloTowers' ): # optional parameter, which defaults to 'False' anyway
412  applyPostfix(process, "patJets", postfix).embedCaloTowers = False
413  applyPostfix(process, "patJets", postfix).embedPFCandidates = True
414 
#-- Remove MC dependence ------------------------------------------------------
string jetAlgo
Jet configuration.
def applyPostfix
Definition: helpers.py:70
def switchToPFJets
Definition: pfTools.py:350
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
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(), 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(conf.exists("allCellsPositionCalc"))
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 = 'AK4',
  runOnMC = True,
  postfix = "",
  jetCorrections = ('AK4PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute,
  None,
  pvCollection = cms.InputTag('goodOfflinePrimaryVerticesPFlow',,
  typeIMetCorrections = False,
  outputModules = ['out'],
  excludeFromTopProjection = ['Tau'] 
)

Definition at line 440 of file pfTools.py.

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

441 def usePF2PAT(process,runPF2PAT=True, jetAlgo='AK4', runOnMC=True, postfix="", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative','L3Absolute'],'None'), pvCollection=cms.InputTag('goodOfflinePrimaryVerticesPFlow',), typeIMetCorrections=False, outputModules=['out'],excludeFromTopProjection=['Tau']):
442  # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
443  # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
444 
445  if typeIMetCorrections:
446  jetCorrections = (jetCorrections[0],jetCorrections[1],'Type-1')
447  """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
448 
449  # -------- CORE ---------------
450  from PhysicsTools.PatAlgos.tools.helpers import loadWithPostfix
451  if runPF2PAT:
452  loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix)
453  loadWithPostfix(process,"CommonTools.ParticleFlow.PF2PAT_cff",postfix)
454  else:
455  loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix)
456 
457 
458 
459 
460  # -------- OBJECTS ------------
461  # Muons
462 
463  adaptPFMuons(process,
464  applyPostfix(process,"patMuons",postfix),
465  postfix)
466 
467  # Electrons
468 
469  adaptPFElectrons(process,
470  applyPostfix(process,"patElectrons",postfix),
471  postfix)
472 
473  # Photons
474  #print "Temporarily switching off photons completely"
475 
476  #removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
477 
478  # Jets
479  if runOnMC :
480  switchToPFJets( process, cms.InputTag('pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
481  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
482 
483  else :
484  if not 'L2L3Residual' in jetCorrections[1]:
485  ### think of a more accurate warning
486  print '#################################################'
487  print 'WARNING! Not using L2L3Residual but this is data.'
488  print 'If this is okay with you, disregard this message.'
489  print '#################################################'
490  switchToPFJets( process, cms.InputTag('pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
491  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
492  # Taus
493  #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
494  #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
495  adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
496  # MET
497  switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
498 
499  # Unmasked PFCandidates
500  addPFCandidates(process,cms.InputTag('pfNoJetClones'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
501 
502  # adapt primary vertex collection
503  adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
504 
505  if not runOnMC:
506  runOnData(process,postfix=postfix,outputModules=outputModules)
507 
508  # Configure Top Projections
509  getattr(process,"pfNoPileUpJME"+postfix).enable = True
510  getattr(process,"pfNoMuonJME"+postfix).enable = True
511  getattr(process,"pfNoElectronJME"+postfix).enable = True
512  getattr(process,"pfNoTau"+postfix).enable = False
513  getattr(process,"pfNoJet"+postfix).enable = True
514  exclusionList = ''
515  for object in excludeFromTopProjection:
516  jme = ''
517  if object in ['Muon','Electron']:
518  jme = 'JME'
519  getattr(process,"pfNo"+object+jme+postfix).enable = False
520  exclusionList=exclusionList+object+','
521  exclusionList=exclusionList.rstrip(',')
522  print "Done: PF2PAT interfaced to PAT, postfix=", postfix,", Excluded 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:440
def addPFCandidates
Definition: pfTools.py:313
def adaptPVs
Definition: pfTools.py:422
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