1 import FWCore.ParameterSet.Config
as cms
9 from copy
import deepcopy
12 print "WARNING: particle based isolation must be studied" 14 def adaptPFMuons(process,module,postfix="", muonMatchModule=None ):
15 print "Adapting PF Muons " 16 print "***************** " 19 module.useParticleFlow =
True 20 module.pfMuonSource = cms.InputTag(
"pfIsolatedMuonsPFBRECO" + postfix)
21 module.userIsolation = cms.PSet()
37 if muonMatchModule ==
None :
38 applyPostfix(process,
"muonMatch",postfix).src = module.pfMuonSource
40 muonMatchModule.src = module.pfMuonSource
42 print " muon source:", module.pfMuonSource
52 print "Adapting PF Electrons " 53 print "********************* " 56 module.useParticleFlow =
True 57 module.pfElectronSource = cms.InputTag(
"pfIsolatedElectronsPFBRECO" + postfix)
58 module.userIsolation = cms.PSet()
80 print " PF electron source:", module.pfElectronSource
91 raise RuntimeError(
"Photons are not supported yet")
96 tauType=
'shrinkingConePFTau',
97 pf2patSelection=[
"DiscriminationByIsolation",
"DiscriminationByLeadingPionPtCut"],
98 selectionDependsOn=[
"DiscriminationByLeadingTrackFinding"],
99 producerFromType=
lambda producer: producer+
"Producer",
101 print "patTaus will be produced from taus of type: %s that pass %s" \
102 % (tauType, pf2patSelection)
107 producerName = producerFromType(tauType)
109 applyPostfix(process,
"pfTaus", postfix).src = producerName+postfix
111 oldTauSansRefs = getattr(process,
'pfTausProducerSansRefs'+postfix)
112 oldTau = getattr(process,
'pfTausProducer'+postfix)
114 newTauSansRefs =
None 115 newTau = getattr(process,producerName+postfix).
clone()
118 if tauType==
'shrinkingConePFTau':
119 newTauSansRefs = getattr(process,producerName+
"SansRefs").
clone()
120 newTauSansRefs.modifiers[1] = cms.PSet(
121 pfTauTagInfoSrc = cms.InputTag(
"pfTauTagInfoProducer"+postfix),
122 name = cms.string(
'pfTauTTIworkaround'+postfix),
123 plugin = cms.string(
'RecoTauTagInfoWorkaroundModifer')
125 newTau.modifiers[1] = newTauSansRefs.modifiers[1]
126 newTauSansRefs.piZeroSrc =
"pfJetsLegacyTaNCPiZeros"+postfix
127 newTau.piZeroSrc = newTauSansRefs.piZeroSrc
128 newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
129 newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
130 newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
131 elif tauType==
'fixedConePFTau':
132 newTau.piZeroSrc =
"pfJetsLegacyTaNCPiZeros"+postfix
133 elif tauType==
'hpsPFTau':
134 newTau = getattr(process,
'combinatoricRecoTaus'+postfix).
clone()
135 newTau.piZeroSrc=
"pfJetsLegacyHPSPiZeros"+postfix
136 newTau.modifiers[3] = cms.PSet(
137 pfTauTagInfoSrc = cms.InputTag(
"pfTauTagInfoProducer"+postfix),
138 name = cms.string(
'pfTauTTIworkaround'+postfix),
139 plugin = cms.string(
'RecoTauTagInfoWorkaroundModifer')
143 setattr(process,
'produceHPSPFTaus'+postfix,cms.Sequence(
applyPostfix(process,
'hpsSelectionDiscriminator',postfix)+
applyPostfix(process,
'hpsPFTauProducerSansRefs',postfix)+
applyPostfix(process,
'hpsPFTauProducer',postfix)))
146 cms.InputTag(
"combinatoricRecoTaus"+postfix),
147 cms.InputTag(
"pfTausBase"+postfix) )
150 cms.InputTag(
"combinatoricRecoTaus"+postfix),
151 cms.InputTag(
"pfTausBase"+postfix) )
162 if tauType==
'shrinkingConePFTau':
164 getattr(process,
"pfTausBase"+postfix).src =
"pfTausBaseSansRefs"+postfix
165 baseSequence += getattr(process,
"pfTausBaseSansRefs"+postfix)
168 def producerIsTauTypeMapperWithPostfix(tauProducer):
171 def recoTauTypeMapperWithGroup(tauProducer):
175 for predisc
in selectionDependsOn:
177 originalName = tauType+predisc
178 clonedName =
"pfTausBase"+predisc+postfix
179 clonedDisc = getattr(process, originalName).
clone()
182 tauCollectionToSelect =
None 183 if tauType !=
'hpsPFTau' :
184 tauCollectionToSelect =
"pfTausBase"+postfix
187 tauCollectionToSelect =
"hpsPFTauProducer"+postfix
190 oldTauTypeMapper=recoTauTypeMapperWithGroup,
191 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
192 preservePFTauProducer=
True)
193 clonedDisc.PFTauProducer = tauCollectionToSelect
196 getattr(process,
"pfTaus" + postfix).discriminators = cms.VPSet()
197 for selection
in pf2patSelection:
199 originalName = tauType+selection
200 clonedName =
"pfTausBase"+selection+postfix
201 clonedDisc = getattr(process, originalName).
clone()
204 tauCollectionToSelect =
None 206 if tauType !=
'hpsPFTau' :
207 tauCollectionToSelect = cms.InputTag(
"pfTausBase"+postfix)
210 tauCollectionToSelect = cms.InputTag(
"hpsPFTauProducer"+postfix)
213 oldTauTypeMapper=recoTauTypeMapperWithGroup,
214 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
215 preservePFTauProducer=
True)
216 clonedDisc.PFTauProducer = tauCollectionToSelect
219 getattr(process,
"pfTaus" + postfix).discriminators.append(cms.PSet(
220 discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
222 if tauType !=
'hpsPFTau':
223 getattr(process,
"pfTaus" + postfix).src =
"pfTausBase"+postfix
227 getattr(process,
"pfTaus" + postfix).src =
"hpsPFTauProducer"+postfix
231 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
233 if tauType !=
'hpsPFTau' :
237 [
"DiscriminationByDecayModeFinding"],
238 [
"DiscriminationByDecayModeFinding"],
241 if tauType !=
'hpsPFTau' :
242 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
244 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
255 if tauType !=
'hpsPFTau' :
257 patTauLabel=
"pfTausBase"+postfix,
258 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
260 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
264 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
266 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
272 process.load(
"CommonTools.ParticleFlow.pfTaus_cff")
273 applyPostfix(process,
"pfTaus",postfix).src = cms.InputTag(tauType+
'Producer'+postfix)
277 from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi
import patPFParticles
279 producer = patPFParticles.clone(pfCandidateSource = src)
280 filter = cms.EDFilter(
"PATPFParticleSelector",
281 src = cms.InputTag(
"pat" + patLabel),
282 cut = cms.string(cut))
283 counter = cms.EDFilter(
"PATCandViewCountFilter",
284 minNumber = cms.uint32(0),
285 maxNumber = cms.uint32(999999),
286 src = cms.InputTag(
"pat" + patLabel))
294 applyPostfix(process,
"patCandidateSummary", postfix).candidates.append(cms.InputTag(
'pat' + patLabel))
295 applyPostfix(process,
"selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag(
'selectedPat' + patLabel))
298 def switchToPFMET(process,input=cms.InputTag(
'pfMETPFBRECO'), type1=
False, postfix=
""):
299 print 'MET: using ', input
301 oldMETSource =
applyPostfix(process,
"patMETs",postfix).metSource
302 applyPostfix(process,
"patMETs",postfix).metSource = input
303 applyPostfix(process,
"patMETs",postfix).addMuonCorrections =
False 307 print 'Apply TypeI corrections for MET' 309 jecLabel = getattr(process,
'patJetCorrFactors'+postfix).payload.pythonValue().
replace(
"'",
"")
310 getattr(process,jecLabel+
'Type1CorMet'+postfix).src = input.getModuleLabel()
314 def switchToPFJets(process, input=cms.InputTag(
'pfNoTauClones'), algo=
'AK4', postfix =
"", jetCorrections=(
'AK4PFchs', [
'L1FastJet',
'L2Relative',
'L3Absolute']), type1=
False, outputModules=[
'out']):
316 print "Switching to PFJets, ", algo
317 print "************************ " 318 print "input collection: ", input
321 genJetCollection = cms.InputTag(
'ak4GenJetsNoNu'+postfix)
324 genJetCollection = cms.InputTag(
'ak7GenJetsNoNu'+postfix)
327 print 'bad jet algorithm:', algo,
'! for now, only AK4 and AK7 are allowed. If you need other algorithms, please contact Colin' 331 from CommonTools.ParticleFlow.Tools.jetTools
import jetAlgo
332 inputCollection = getattr(process,
"pfJetsPFBRECO"+postfix).src
333 setattr(process,
"pfJetsPFBRECO"+postfix,
jetAlgo(algo))
334 getattr(process,
"pfJetsPFBRECO"+postfix).src = inputCollection
335 inputJetCorrLabel=jetCorrections
337 switchJetCollection(process,
341 genJetCollection=genJetCollection,
343 jetTrackAssociation=
True,
344 jetCorrections=inputJetCorrLabel,
345 outputModules = outputModules,
349 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
False 351 for corr
in inputJetCorrLabel[1]:
352 if corr ==
'L1FastJet':
353 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
True 354 applyPostfix(process,
"pfJetsPFBRECO", postfix).doAreaFastjet =
True 358 for mod
in process.producerNames().
split(
' '):
360 if mod.startswith(
"kt6")
and mod.endswith(
"Jets"+postfix)
and not 'GenJets' in mod:
361 prefix = mod.replace(postfix,
'')
362 prefix = prefix.replace(
'kt6PFJets',
'')
363 prefix = prefix.replace(
'kt6CaloJets',
'')
364 prefix = getattr(process,
'patJetCorrFactors'+prefix+postfix).payload.pythonValue().
replace(
"'",
"")
365 for essource
in process.es_sources_().
keys():
366 if essource == prefix+
'L1FastJet':
367 setattr(process,essource+postfix,getattr(process,essource).
clone(srcRho=cms.InputTag(mod,
'rho')))
369 getattr(process,prefix+
'CombinedCorrector').
clone(), process, task)
370 getattr(process,prefix+
'CorMet'+postfix).corrector = prefix+
'CombinedCorrector'+postfix
371 for cor
in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
373 idx = getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.index(essource);
374 getattr(process,prefix+
'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
376 if hasattr( getattr( process,
"patJets" + postfix),
'embedCaloTowers' ):
377 applyPostfix(process,
"patJets", postfix).embedCaloTowers =
False 378 applyPostfix(process,
"patJets", postfix).embedPFCandidates =
True 385 removeMCMatching(process, names=[
'All'], postfix=postfix, outputModules=outputModules)
388 def adaptPVs(process, pvCollection=cms.InputTag(
'offlinePrimaryVertices'), postfix=
''):
389 print "Switching PV collection for PF2PAT:", pvCollection
390 print "***********************************" 393 pvExchange = [
'Vertices',
'vertices',
'pvSrc',
'primaryVertices',
'srcPVs',
'primaryVertex']
398 for m
in (process.producerNames().
split(
' ') + process.filterNames().
split(
' ')):
400 for namePvSrc
in pvExchange:
401 if hasattr(getattr(process,m),namePvSrc):
403 setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
406 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']):
410 if typeIMetCorrections:
411 jetCorrections = (jetCorrections[0],jetCorrections[1],
'Type-1')
412 """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence""" 417 taskLabel = patAlgosToolsTask.label()
419 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix, loadedProducersAndFilters=taskLabel)
420 loadWithPostfix(process,
"CommonTools.ParticleFlow.PFBRECO_cff",postfix, loadedProducersAndFilters=taskLabel)
422 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix, loadedProducersAndFilters=taskLabel)
447 switchToPFJets( process, cms.InputTag(
'pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
448 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
451 if not 'L2L3Residual' in jetCorrections[1]:
453 print '#################################################' 454 print 'WARNING! Not using L2L3Residual but this is data.' 455 print 'If this is okay with you, disregard this message.' 456 print '#################################################' 457 switchToPFJets( process, cms.InputTag(
'pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
458 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
462 adaptPFTaus( process, tauType=
'hpsPFTau', postfix=postfix )
464 switchToPFMET(process, cms.InputTag(
'pfMETPFBRECO'+postfix), type1=typeIMetCorrections, postfix=postfix)
467 addPFCandidates(process,cms.InputTag(
'pfNoJetClones'+postfix),patLabel=
'PFParticles'+postfix,cut=
"",postfix=postfix)
470 adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
473 runOnData(process,postfix=postfix,outputModules=outputModules)
476 getattr(process,
"pfNoPileUpJME"+postfix).enable =
True 477 getattr(process,
"pfNoMuonJMEPFBRECO"+postfix).enable =
True 478 getattr(process,
"pfNoElectronJMEPFBRECO"+postfix).enable =
True 479 getattr(process,
"pfNoTauPFBRECO"+postfix).enable =
False 480 getattr(process,
"pfNoJetPFBRECO"+postfix).enable =
True 482 for object
in excludeFromTopProjection:
484 if object
in [
'Muon',
'Electron']:
486 getattr(process,
"pfNo"+object+jme+
'PFBRECO'+postfix).enable =
False 487 exclusionList=exclusionList+object+
',' 488 exclusionList=exclusionList.rstrip(
',')
489 print "Done: PFBRECO interfaced to PAT, postfix=", postfix,
", Excluded from Top Projection:",exclusionList
def addToProcessAndTask(label, module, process, task)
def replace(string, replacements)
def massSearchReplaceParam(sequence, paramName, paramOldValue, paramValue, verbose=False)
def applyPostfix(process, label, postfix)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
def getPatAlgosToolsTask(process)
def loadWithPostfix(process, moduleName, postfix='', loadedProducersAndFilters=None)