CMS 3D CMS Logo

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

Functions

def adaptPFElectrons
 
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 51 of file pfTools.py.

References print().

Referenced by usePF2PAT().

51 
52 def adaptPFElectrons(process,module, postfix):
53  # module.useParticleFlow = True
54  print("Adapting PF Electrons ")
55  print("********************* ")
56  #warningIsolation()
57  print()
58  module.useParticleFlow = True
59  module.pfElectronSource = cms.InputTag("pfIsolatedElectronsPFBRECO" + postfix)
60  module.userIsolation = cms.PSet()
61  ## module.isoDeposits = cms.PSet(
62  ## pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
63  ## pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
64  ## pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
65  ## pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
66  ## pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
67  ## )
68  ## module.isolationValues = cms.PSet(
69  ## pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
70  ## pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
71  ## pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
72  ## pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
73  ## pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
74  ## )
75 
76  # COLIN: since we take the egamma momentum for pat Electrons, we must
77  # match the egamma electron to the gen electrons, and not the PFElectron.
78  # -> do not uncomment the line below.
79  # process.electronMatch.src = module.pfElectronSource
80  # COLIN: how do we depend on this matching choice?
81 
82  print(" PF electron source:", module.pfElectronSource)
83  ## print " isolation :"
84  ## print module.isolationValues
85  ## print " isodeposits: "
86  ## print module.isoDeposits
87  print()
88 
89 
90 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def adaptPFElectrons
Definition: pfTools.py:51
def pfTools.adaptPFMuons (   process,
  module,
  postfix = "",
  muonMatchModule = None 
)

Definition at line 15 of file pfTools.py.

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

Referenced by usePF2PAT().

15 
16 def adaptPFMuons(process,module,postfix="", muonMatchModule=None ):
17  print("Adapting PF Muons ")
18  print("***************** ")
19  #warningIsolation()
20  print()
21  module.useParticleFlow = True
22  module.pfMuonSource = cms.InputTag("pfIsolatedMuonsPFBRECO" + postfix)
23  module.userIsolation = cms.PSet()
24  ## module.isoDeposits = cms.PSet(
25  ## pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
26  ## pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
27  ## pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
28  ## pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
29  ## pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
30  ## )
31  ## module.isolationValues = cms.PSet(
32  ## pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
33  ## pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
34  ## pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
35  ## pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
36  ## pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
37  ## )
38  # matching the pfMuons, not the standard muons.
39  if muonMatchModule == None :
40  applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
41  else :
42  muonMatchModule.src = module.pfMuonSource
43 
44  print(" muon source:", module.pfMuonSource)
45  ## print " isolation :",
46  ## print module.isolationValues
47  ## print " isodeposits: "
48  ## print module.isoDeposits
49  print()
50 
def adaptPFMuons
Definition: pfTools.py:15
def applyPostfix
Definition: helpers.py:114
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def pfTools.adaptPFPhotons (   process,
  module 
)

Definition at line 91 of file pfTools.py.

References reconfigurePF2PATTaus().

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

Definition at line 232 of file pfTools.py.

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

Referenced by usePF2PAT().

233 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
234  # Set up the collection used as a preselection to use this tau type
235  if tauType != 'hpsPFTau' :
236  reconfigurePF2PATTaus(process, tauType, postfix=postfix)
237  else:
238  reconfigurePF2PATTaus(process, tauType,
239  ["DiscriminationByDecayModeFinding"],
240  ["DiscriminationByDecayModeFinding"],
241  postfix=postfix)
242  # new default use unselected taus (selected only for jet cleaning)
243  if tauType != 'hpsPFTau' :
244  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
245  else:
246  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
247  # to use preselected collection (old default) uncomment line below
248  #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
249 
250  ### apparently not needed anymore, function gone from tauTools.py###
251  #redoPFTauDiscriminators(process,
252  #cms.InputTag(tauType+'Producer'),
253  #applyPostfix(process,"patTaus", postfix).tauSource,
254  #tauType, postfix=postfix)
255 
256 
257  if tauType != 'hpsPFTau' :
258  switchToPFTauByType(process, pfTauType=tauType,
259  patTauLabel="pfTausBase"+postfix,
260  tauSource=cms.InputTag(tauType+'Producer'+postfix),
261  postfix=postfix)
262  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
263  else:
264  switchToPFTauByType(process, pfTauType=tauType,
265  patTauLabel="",
266  tauSource=cms.InputTag(tauType+'Producer'+postfix),
267  postfix=postfix)
268  getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
269 
270 
271 
#helper function for PAT on PF2PAT sample
def adaptPFTaus
Definition: pfTools.py:232
def reconfigurePF2PATTaus
Definition: pfTools.py:101
def switchToPFTauByType
Definition: tauTools.py:204
def pfTools.adaptPVs (   process,
  pvCollection = cms.InputTag('offlinePrimaryVertices'),
  postfix = '' 
)

Definition at line 389 of file pfTools.py.

References print(), and submitPVValidationJobs.split().

Referenced by usePF2PAT().

390 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix=''):
391  print("Switching PV collection for PF2PAT:", pvCollection)
392  print("***********************************")
393 
394  # PV sources to be exchanged:
395  pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs','primaryVertex']
396  # PV sources NOT to be exchanged:
397  #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc']
398 
399  # exchange the primary vertex source of all relevant modules
400  for m in (process.producerNames().split(' ') + process.filterNames().split(' ')):
401  # only if the module has a source with a relevant name
402  for namePvSrc in pvExchange:
403  if hasattr(getattr(process,m),namePvSrc):
404  #print m
405  setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
406 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def adaptPVs
Definition: pfTools.py:389
def pfTools.addPFCandidates (   process,
  src,
  patLabel = 'PFParticles',
  cut = "",
  postfix = "" 
)

Definition at line 277 of file pfTools.py.

References helpers.addToProcessAndTask(), helpers.applyPostfix(), and helpers.getPatAlgosToolsTask().

Referenced by usePF2PAT().

278 def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""):
279  from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
280  # make modules
281  producer = patPFParticles.clone(pfCandidateSource = src)
282  filter = cms.EDFilter("PATPFParticleSelector",
283  src = cms.InputTag("pat" + patLabel),
284  cut = cms.string(cut))
285  counter = cms.EDFilter("PATCandViewCountFilter",
286  minNumber = cms.uint32(0),
287  maxNumber = cms.uint32(999999),
288  src = cms.InputTag("pat" + patLabel))
289  # add modules to process
290  task = getPatAlgosToolsTask(process)
291  addToProcessAndTask("pat" + patLabel, producer, process, task)
292  addToProcessAndTask("selectedPat" + patLabel, filter, process, task)
293  addToProcessAndTask("countPat" + patLabel, counter, process, task)
294 
295  # summary tables
296  applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
297  applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
298 
def getPatAlgosToolsTask
Definition: helpers.py:13
def applyPostfix
Definition: helpers.py:114
def addPFCandidates
Definition: pfTools.py:277
def addToProcessAndTask
Definition: helpers.py:28
def pfTools.reconfigurePF2PATTaus (   process,
  tauType = 'shrinkingConePFTau',
  pf2patSelection = ["DiscriminationByIsolation",
  DiscriminationByLeadingPionPtCut,
  selectionDependsOn = ["DiscriminationByLeadingTrackFinding"],
  producerFromType = lambda producer: producer+"Producer",
  postfix = "" 
)

Definition at line 101 of file pfTools.py.

References TauDiscriminatorTools.adaptTauDiscriminator(), helpers.addToProcessAndTask(), helpers.applyPostfix(), clone(), helpers.getPatAlgosToolsTask(), MassReplace.massSearchReplaceParam(), print(), TauDiscriminatorTools.producerIsTauTypeMapper, and TauDiscriminatorTools.recoTauTypeMapper().

Referenced by adaptPFPhotons(), and adaptPFTaus().

102  postfix = ""):
103  print("patTaus will be produced from taus of type: %s that pass %s" \
104  % (tauType, pf2patSelection))
105 
106 
107 
108  # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer
109  producerName = producerFromType(tauType)
110  # Set as the source for the pf2pat taus (pfTaus) selector
111  applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
112  # Start our pf2pat taus base sequence
113  oldTauSansRefs = getattr(process,'pfTausProducerSansRefs'+postfix)
114  oldTau = getattr(process,'pfTausProducer'+postfix)
115  ## copy tau and setup it properly
116  newTauSansRefs = None
117  newTau = getattr(process,producerName+postfix).clone()
118 
119  ## adapted to new structure in RecoTauProducers PLEASE CHECK!!!
120  if tauType=='shrinkingConePFTau':
121  newTauSansRefs = getattr(process,producerName+"SansRefs").clone()
122  newTauSansRefs.modifiers[1] = cms.PSet(
123  pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
124  name = cms.string('pfTauTTIworkaround'+postfix),
125  plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
126  )
127  newTau.modifiers[1] = newTauSansRefs.modifiers[1]
128  newTauSansRefs.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
129  newTau.piZeroSrc = newTauSansRefs.piZeroSrc
130  newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
131  newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
132  newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
133  elif tauType=='fixedConePFTau':
134  newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
135  elif tauType=='hpsPFTau':
136  newTau = getattr(process,'combinatoricRecoTaus'+postfix).clone()
137  newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
138  newTau.modifiers[3] = cms.PSet(
139  pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
140  name = cms.string('pfTauTTIworkaround'+postfix),
141  plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
142  )
143  from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
144  #cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix, addToTask = True)
145  setattr(process,'produceHPSPFTaus'+postfix,cms.Sequence(applyPostfix(process,'hpsSelectionDiscriminator',postfix)+applyPostfix(process,'hpsPFTauProducerSansRefs',postfix)+applyPostfix(process,'hpsPFTauProducer',postfix)))
146  massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
147  "PFTauProducer",
148  cms.InputTag("combinatoricRecoTaus"+postfix),
149  cms.InputTag("pfTausBase"+postfix) )
150  massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
151  "src",
152  cms.InputTag("combinatoricRecoTaus"+postfix),
153  cms.InputTag("pfTausBase"+postfix) )
154  ### Next three lines crash, oldTau does not have any of these attributes. Why?###
155  #newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
156  #newTau.jetRegionSrc = oldTau.jetRegionSrc
157  #newTau.jetSrc = oldTau.jetSrc
158  #newTau.builders[0].pfCandSrc = cms.InputTag("pfNoElectronJME" + postfix)
159  #newTau.jetRegionSrc = cms.InputTag("pfTauPFJets08Region" + postfix)
160  #newTau.jetSrc = cms.InputTag("pfJetsPFBRECO" + postfix)
161  # replace old tau producer by new one put it into baseSequence
162  task = getPatAlgosToolsTask(process)
163  addToProcessAndTask("pfTausBase"+postfix, newTau, process, task)
164  if tauType=='shrinkingConePFTau':
165  addToProcessAndTask("pfTausBaseSansRefs"+postfix, newTauSansRefs, process, task)
166  getattr(process,"pfTausBase"+postfix).src = "pfTausBaseSansRefs"+postfix
167  baseSequence += getattr(process,"pfTausBaseSansRefs"+postfix)
168 
169  #make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
170  def producerIsTauTypeMapperWithPostfix(tauProducer):
171  return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
172 
173  def recoTauTypeMapperWithGroup(tauProducer):
174  return "%s(.*)"%recoTauTypeMapper(tauProducer)
175 
176  # Get our prediscriminants
177  for predisc in selectionDependsOn:
178  # Get the prototype
179  originalName = tauType+predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding
180  clonedName = "pfTausBase"+predisc+postfix
181  clonedDisc = getattr(process, originalName).clone()
182  addToProcessAndTask(clonedName, clonedDisc, process, task)
183 
184  tauCollectionToSelect = None
185  if tauType != 'hpsPFTau' :
186  tauCollectionToSelect = "pfTausBase"+postfix
187  #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
188  else:
189  tauCollectionToSelect = "hpsPFTauProducer"+postfix
190  # Adapt this discriminator for the cloned prediscriminators
191  adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
192  oldTauTypeMapper=recoTauTypeMapperWithGroup,
193  newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
194  preservePFTauProducer=True)
195  clonedDisc.PFTauProducer = tauCollectionToSelect
196 
197  # Reconfigure the pf2pat PFTau selector discrimination sources
198  getattr(process,"pfTaus" + postfix).discriminators = cms.VPSet()
199  for selection in pf2patSelection:
200  # Get our discriminator that will be used to select pfTaus
201  originalName = tauType+selection
202  clonedName = "pfTausBase"+selection+postfix
203  clonedDisc = getattr(process, originalName).clone()
204  addToProcessAndTask(clonedName, clonedDisc, process, task)
205 
206  tauCollectionToSelect = None
207 
208  if tauType != 'hpsPFTau' :
209  tauCollectionToSelect = cms.InputTag("pfTausBase"+postfix)
210  #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
211  else:
212  tauCollectionToSelect = cms.InputTag("hpsPFTauProducer"+postfix)
213  #Adapt our cloned discriminator to the new prediscriminants
214  adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
215  oldTauTypeMapper=recoTauTypeMapperWithGroup,
216  newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
217  preservePFTauProducer=True)
218  clonedDisc.PFTauProducer = tauCollectionToSelect
219 
220  # Add this selection to our pfTau selectors
221  getattr(process,"pfTaus" + postfix).discriminators.append(cms.PSet(
222  discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
223  # Set the input of the final selector.
224  if tauType != 'hpsPFTau':
225  getattr(process,"pfTaus" + postfix).src = "pfTausBase"+postfix
226  else:
227  # If we are using HPS taus, we need to take the output of the clenaed
228  # collection
229  getattr(process,"pfTaus" + postfix).src = "hpsPFTauProducer"+postfix
230 
231 
def massSearchReplaceParam
Definition: MassReplace.py:129
def getPatAlgosToolsTask
Definition: helpers.py:13
def applyPostfix
Definition: helpers.py:114
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def addToProcessAndTask
Definition: helpers.py:28
def pfTools.removeMCMatchingPF2PAT (   process,
  postfix = "",
  outputModules = ['out'] 
)

Definition at line 382 of file pfTools.py.

383 def removeMCMatchingPF2PAT( process, postfix="", outputModules=['out'] ):
384  #from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
385  ### no longe needed in unscheduled mode###
386  #removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
387  removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
388 
def removeMCMatchingPF2PAT
Definition: pfTools.py:382
def pfTools.switchToPFJets (   process,
  input = cms.InputTag('pfNoTauClones'),
  algo = 'AK4',
  postfix = "",
  jetCorrections = ('AK4PFchs', ['L1FastJet',
  L2Relative,
  L3Absolute,
  type1 = False,
  outputModules = ['out'] 
)

Definition at line 315 of file pfTools.py.

References helpers.addToProcessAndTask(), helpers.applyPostfix(), clone(), helpers.getPatAlgosToolsTask(), jetTools.jetAlgo(), relativeConstraints.keys, print(), python.rootplot.root2matplotlib.replace(), and submitPVValidationJobs.split().

Referenced by usePF2PAT().

316 def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK4', postfix = "", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out']):
317 
318  print("Switching to PFJets, ", algo)
319  print("************************ ")
320  print("input collection: ", input)
321 
322  if algo == 'AK4':
323  genJetCollection = cms.InputTag('ak4GenJetsNoNu'+postfix)
324  rParam=0.4
325  elif algo == 'AK7':
326  genJetCollection = cms.InputTag('ak7GenJetsNoNu'+postfix)
327  rParam=0.7
328  else:
329  print('bad jet algorithm:', algo, '! for now, only AK4 and AK7 are allowed. If you need other algorithms, please contact Colin')
330  sys.exit(1)
331 
332  # changing the jet collection in PF2PAT:
333  from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
334  inputCollection = getattr(process,"pfJetsPFBRECO"+postfix).src
335  setattr(process,"pfJetsPFBRECO"+postfix,jetAlgo(algo)) # problem for cfgBrowser
336  getattr(process,"pfJetsPFBRECO"+postfix).src = inputCollection
337  inputJetCorrLabel=jetCorrections
338 
339  switchJetCollection(process,
340  jetSource = input,
341  algo=algo,
342  rParam=rParam,
343  genJetCollection=genJetCollection,
344  postfix=postfix,
345  jetTrackAssociation=True,
346  jetCorrections=inputJetCorrLabel,
347  outputModules = outputModules,
348  )
349 
350  # check whether L1FastJet is in the list of correction levels or not
351  applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
352  task = getPatAlgosToolsTask(process)
353  for corr in inputJetCorrLabel[1]:
354  if corr == 'L1FastJet':
355  applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
356  applyPostfix(process, "pfJetsPFBRECO", postfix).doAreaFastjet = True
357  # do correct treatment for TypeI MET corrections
358  #type1=True
359  if type1:
360  for mod in process.producerNames().split(' '):
361 
362  if mod.startswith("kt6") and mod.endswith("Jets"+postfix) and not 'GenJets' in mod:
363  prefix = mod.replace(postfix,'')
364  prefix = prefix.replace('kt6PFJets','')
365  prefix = prefix.replace('kt6CaloJets','')
366  prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
367  for essource in process.es_sources_().keys():
368  if essource == prefix+'L1FastJet':
369  setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
370  addToProcessAndTask(prefix+'CombinedCorrector'+postfix,
371  getattr(process,prefix+'CombinedCorrector').clone(), process, task)
372  getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
373  for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
374  if cor == essource:
375  idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
376  getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
377 
378  if hasattr( getattr( process, "patJets" + postfix), 'embedCaloTowers' ): # optional parameter, which defaults to 'False' anyway
379  applyPostfix(process, "patJets", postfix).embedCaloTowers = False
380  applyPostfix(process, "patJets", postfix).embedPFCandidates = True
381 
#-- Remove MC dependence ------------------------------------------------------
def jetAlgo
Definition: jetTools.py:3
def getPatAlgosToolsTask
Definition: helpers.py:13
def applyPostfix
Definition: helpers.py:114
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def switchToPFJets
Definition: pfTools.py:315
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def addToProcessAndTask
Definition: helpers.py:28
def pfTools.switchToPFMET (   process,
  input = cms.InputTag('pfMETPFBRECO'),
  type1 = False,
  postfix = "" 
)

Definition at line 299 of file pfTools.py.

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

Referenced by usePF2PAT().

300 def switchToPFMET(process,input=cms.InputTag('pfMETPFBRECO'), type1=False, postfix=""):
301  print('MET: using ', input)
302  if( not type1 ):
303  oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
304  applyPostfix(process, "patMETs",postfix).metSource = input
305  applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
306  else:
307  # type1 corrected MET
308  # name of corrected MET hardcoded in PAT and meaningless
309  print('Apply TypeI corrections for MET')
310  #getattr(process, "patPF2PATSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
311  jecLabel = getattr(process,'patJetCorrFactors'+postfix).payload.pythonValue().replace("'","")
312  getattr(process,jecLabel+'Type1CorMet'+postfix).src = input.getModuleLabel()
313  #getattr(process,'patMETs'+postfix).metSource = jecLabel+'Type1CorMet'+postfix
314  #getattr(process,'patMETs'+postfix).addMuonCorrections = False
def switchToPFMET
Definition: pfTools.py:299
def applyPostfix
Definition: helpers.py:114
if(conf_.getParameter< bool >("UseStripCablingDB"))
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def pfTools.tauTypeInPF2PAT (   process,
  tauType = 'shrinkingConePFTau',
  postfix = "" 
)

Definition at line 272 of file pfTools.py.

References helpers.applyPostfix().

273 def tauTypeInPF2PAT(process,tauType='shrinkingConePFTau', postfix = ""):
274  process.load("CommonTools.ParticleFlow.pfTaus_cff")
275  applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
276 
def tauTypeInPF2PAT
Definition: pfTools.py:272
def applyPostfix
Definition: helpers.py:114
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 407 of file pfTools.py.

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

408 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']):
409  # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
410  # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
411 
412  if typeIMetCorrections:
413  jetCorrections = (jetCorrections[0],jetCorrections[1],'Type-1')
414  """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
415 
416  # -------- CORE ---------------
417  from PhysicsTools.PatAlgos.tools.helpers import loadWithPostfix
418  patAlgosToolsTask = getPatAlgosToolsTask(process)
419  taskLabel = patAlgosToolsTask.label()
420  if runPF2PAT:
421  loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix, loadedProducersAndFilters=taskLabel)
422  loadWithPostfix(process,"CommonTools.ParticleFlow.PFBRECO_cff",postfix, loadedProducersAndFilters=taskLabel)
423  else:
424  loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix, loadedProducersAndFilters=taskLabel)
425 
426 
427 
428 
429  # -------- OBJECTS ------------
430  # Muons
431 
432  adaptPFMuons(process,
433  applyPostfix(process,"patMuons",postfix),
434  postfix)
435 
436  # Electrons
437 
438  adaptPFElectrons(process,
439  applyPostfix(process,"patElectrons",postfix),
440  postfix)
441 
442  # Photons
443  #print "Temporarily switching off photons completely"
444 
445  #removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
446 
447  # Jets
448  if runOnMC :
449  switchToPFJets( process, cms.InputTag('pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
450  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
451 
452  else :
453  if not 'L2L3Residual' in jetCorrections[1]:
454  ### think of a more accurate warning
455  print('#################################################')
456  print('WARNING! Not using L2L3Residual but this is data.')
457  print('If this is okay with you, disregard this message.')
458  print('#################################################')
459  switchToPFJets( process, cms.InputTag('pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
460  jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
461  # Taus
462  #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
463  #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
464  adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
465  # MET
466  switchToPFMET(process, cms.InputTag('pfMETPFBRECO'+postfix), type1=typeIMetCorrections, postfix=postfix)
467 
468  # Unmasked PFCandidates
469  addPFCandidates(process,cms.InputTag('pfNoJetClones'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
470 
471  # adapt primary vertex collection
472  adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
473 
474  if not runOnMC:
475  runOnData(process,postfix=postfix,outputModules=outputModules)
476 
477  # Configure Top Projections
478  getattr(process,"pfNoPileUpJME"+postfix).enable = True
479  getattr(process,"pfNoMuonJMEPFBRECO"+postfix).enable = True
480  getattr(process,"pfNoElectronJMEPFBRECO"+postfix).enable = True
481  getattr(process,"pfNoTauPFBRECO"+postfix).enable = False
482  getattr(process,"pfNoJetPFBRECO"+postfix).enable = True
483  exclusionList = ''
484  for object in excludeFromTopProjection:
485  jme = ''
486  if object in ['Muon','Electron']:
487  jme = 'JME'
488  getattr(process,"pfNo"+object+jme+'PFBRECO'+postfix).enable = False
489  exclusionList=exclusionList+object+','
490  exclusionList=exclusionList.rstrip(',')
491  print("Done: PFBRECO interfaced to PAT, postfix=", postfix,", Excluded from Top Projection:",exclusionList)
def switchToPFMET
Definition: pfTools.py:299
def adaptPFTaus
Definition: pfTools.py:232
def adaptPFMuons
Definition: pfTools.py:15
def getPatAlgosToolsTask
Definition: helpers.py:13
def applyPostfix
Definition: helpers.py:114
def usePF2PAT
Definition: pfTools.py:407
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def addPFCandidates
Definition: pfTools.py:277
def adaptPVs
Definition: pfTools.py:389
def adaptPFElectrons
Definition: pfTools.py:51
def switchToPFJets
Definition: pfTools.py:315
def loadWithPostfix
Definition: helpers.py:46
def pfTools.warningIsolation ( )

Definition at line 12 of file pfTools.py.

References print().

12 
13 def warningIsolation():
14  print("WARNING: particle based isolation must be studied")
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def warningIsolation
Definition: pfTools.py:12