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) )
160 setattr(process,
"pfTausBase"+postfix,newTau)
161 if tauType==
'shrinkingConePFTau':
162 setattr(process,
"pfTausBaseSansRefs"+postfix,newTauSansRefs)
163 getattr(process,
"pfTausBase"+postfix).src =
"pfTausBaseSansRefs"+postfix
164 baseSequence += getattr(process,
"pfTausBaseSansRefs"+postfix)
167 def producerIsTauTypeMapperWithPostfix(tauProducer):
170 def recoTauTypeMapperWithGroup(tauProducer):
174 for predisc
in selectionDependsOn:
176 originalName = tauType+predisc
177 clonedName =
"pfTausBase"+predisc+postfix
178 clonedDisc = getattr(process, originalName).
clone()
179 setattr(process, clonedName, clonedDisc)
181 tauCollectionToSelect =
None
182 if tauType !=
'hpsPFTau' :
183 tauCollectionToSelect =
"pfTausBase"+postfix
186 tauCollectionToSelect =
"hpsPFTauProducer"+postfix
189 oldTauTypeMapper=recoTauTypeMapperWithGroup,
190 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
191 preservePFTauProducer=
True)
192 clonedDisc.PFTauProducer = tauCollectionToSelect
195 getattr(process,
"pfTaus" + postfix).discriminators = cms.VPSet()
196 for selection
in pf2patSelection:
198 originalName = tauType+selection
199 clonedName =
"pfTausBase"+selection+postfix
200 clonedDisc = getattr(process, originalName).
clone()
201 setattr(process, clonedName, clonedDisc)
203 tauCollectionToSelect =
None
205 if tauType !=
'hpsPFTau' :
206 tauCollectionToSelect = cms.InputTag(
"pfTausBase"+postfix)
209 tauCollectionToSelect = cms.InputTag(
"hpsPFTauProducer"+postfix)
212 oldTauTypeMapper=recoTauTypeMapperWithGroup,
213 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
214 preservePFTauProducer=
True)
215 clonedDisc.PFTauProducer = tauCollectionToSelect
218 getattr(process,
"pfTaus" + postfix).discriminators.append(cms.PSet(
219 discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
221 if tauType !=
'hpsPFTau':
222 getattr(process,
"pfTaus" + postfix).src =
"pfTausBase"+postfix
226 getattr(process,
"pfTaus" + postfix).src =
"hpsPFTauProducer"+postfix
230 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
232 if tauType !=
'hpsPFTau' :
236 [
"DiscriminationByDecayModeFinding"],
237 [
"DiscriminationByDecayModeFinding"],
240 if tauType !=
'hpsPFTau' :
241 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
243 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
254 if tauType !=
'hpsPFTau' :
256 patTauLabel=
"pfTausBase"+postfix,
257 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
259 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
263 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
265 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
271 process.load(
"CommonTools.ParticleFlow.pfTaus_cff")
272 applyPostfix(process,
"pfTaus",postfix).src = cms.InputTag(tauType+
'Producer'+postfix)
276 from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi
import patPFParticles
278 producer = patPFParticles.clone(pfCandidateSource = src)
279 filter = cms.EDFilter(
"PATPFParticleSelector",
280 src = cms.InputTag(
"pat" + patLabel),
281 cut = cms.string(cut))
282 counter = cms.EDFilter(
"PATCandViewCountFilter",
283 minNumber = cms.uint32(0),
284 maxNumber = cms.uint32(999999),
285 src = cms.InputTag(
"pat" + patLabel))
287 setattr(process,
"pat" + patLabel, producer)
288 setattr(process,
"selectedPat" + patLabel, filter)
289 setattr(process,
"countPat" + patLabel, counter)
292 applyPostfix(process,
"patCandidateSummary", postfix).candidates.append(cms.InputTag(
'pat' + patLabel))
293 applyPostfix(process,
"selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag(
'selectedPat' + patLabel))
296 def switchToPFMET(process,input=cms.InputTag(
'pfMETPFBRECO'), type1=
False, postfix=
""):
297 print 'MET: using ', input
299 oldMETSource =
applyPostfix(process,
"patMETs",postfix).metSource
300 applyPostfix(process,
"patMETs",postfix).metSource = input
301 applyPostfix(process,
"patMETs",postfix).addMuonCorrections =
False
305 print 'Apply TypeI corrections for MET'
307 jecLabel = getattr(process,
'patJetCorrFactors'+postfix).payload.pythonValue().
replace(
"'",
"")
308 getattr(process,jecLabel+
'Type1CorMet'+postfix).src = input.getModuleLabel()
312 def switchToPFJets(process, input=cms.InputTag(
'pfNoTauClones'), algo=
'AK4', postfix =
"", jetCorrections=(
'AK4PFchs', [
'L1FastJet',
'L2Relative',
'L3Absolute']), type1=
False, outputModules=[
'out']):
314 print "Switching to PFJets, ", algo
315 print "************************ "
316 print "input collection: ", input
319 genJetCollection = cms.InputTag(
'ak4GenJetsNoNu'+postfix)
322 genJetCollection = cms.InputTag(
'ak7GenJetsNoNu'+postfix)
325 print 'bad jet algorithm:', algo,
'! for now, only AK4 and AK7 are allowed. If you need other algorithms, please contact Colin'
329 from CommonTools.ParticleFlow.Tools.jetTools
import jetAlgo
330 inputCollection = getattr(process,
"pfJetsPFBRECO"+postfix).src
331 setattr(process,
"pfJetsPFBRECO"+postfix,
jetAlgo(algo))
332 getattr(process,
"pfJetsPFBRECO"+postfix).src = inputCollection
333 inputJetCorrLabel=jetCorrections
335 switchJetCollection(process,
339 genJetCollection=genJetCollection,
341 jetTrackAssociation=
True,
342 jetCorrections=inputJetCorrLabel,
343 outputModules = outputModules,
347 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
False
348 for corr
in inputJetCorrLabel[1]:
349 if corr ==
'L1FastJet':
350 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
True
351 applyPostfix(process,
"pfJetsPFBRECO", postfix).doAreaFastjet =
True
355 for mod
in process.producerNames().
split(
' '):
357 if mod.startswith(
"kt6")
and mod.endswith(
"Jets"+postfix)
and not 'GenJets' in mod:
358 prefix = mod.replace(postfix,
'')
359 prefix = prefix.replace(
'kt6PFJets',
'')
360 prefix = prefix.replace(
'kt6CaloJets',
'')
361 prefix = getattr(process,
'patJetCorrFactors'+prefix+postfix).payload.pythonValue().
replace(
"'",
"")
362 for essource
in process.es_sources_().
keys():
363 if essource == prefix+
'L1FastJet':
364 setattr(process,essource+postfix,getattr(process,essource).
clone(srcRho=cms.InputTag(mod,
'rho')))
365 setattr(process,prefix+
'CombinedCorrector'+postfix,getattr(process,prefix+
'CombinedCorrector').
clone())
366 getattr(process,prefix+
'CorMet'+postfix).corrector = prefix+
'CombinedCorrector'+postfix
367 for cor
in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
369 idx = getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.index(essource);
370 getattr(process,prefix+
'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
372 if hasattr( getattr( process,
"patJets" + postfix),
'embedCaloTowers' ):
373 applyPostfix(process,
"patJets", postfix).embedCaloTowers =
False
374 applyPostfix(process,
"patJets", postfix).embedPFCandidates =
True
381 removeMCMatching(process, names=[
'All'], postfix=postfix, outputModules=outputModules)
384 def adaptPVs(process, pvCollection=cms.InputTag(
'offlinePrimaryVertices'), postfix=
''):
385 print "Switching PV collection for PF2PAT:", pvCollection
386 print "***********************************"
389 pvExchange = [
'Vertices',
'vertices',
'pvSrc',
'primaryVertices',
'srcPVs',
'primaryVertex']
394 for m
in (process.producerNames().
split(
' ') + process.filterNames().
split(
' ')):
396 for namePvSrc
in pvExchange:
397 if hasattr(getattr(process,m),namePvSrc):
399 setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
402 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']):
406 if typeIMetCorrections:
407 jetCorrections = (jetCorrections[0],jetCorrections[1],
'Type-1')
408 """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
413 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
414 loadWithPostfix(process,
"CommonTools.ParticleFlow.PFBRECO_cff",postfix)
416 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
441 switchToPFJets( process, cms.InputTag(
'pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
442 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
445 if not 'L2L3Residual' in jetCorrections[1]:
447 print '#################################################'
448 print 'WARNING! Not using L2L3Residual but this is data.'
449 print 'If this is okay with you, disregard this message.'
450 print '#################################################'
451 switchToPFJets( process, cms.InputTag(
'pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
452 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
456 adaptPFTaus( process, tauType=
'hpsPFTau', postfix=postfix )
458 switchToPFMET(process, cms.InputTag(
'pfMETPFBRECO'+postfix), type1=typeIMetCorrections, postfix=postfix)
461 addPFCandidates(process,cms.InputTag(
'pfNoJetClones'+postfix),patLabel=
'PFParticles'+postfix,cut=
"",postfix=postfix)
464 adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
467 runOnData(process,postfix=postfix,outputModules=outputModules)
470 getattr(process,
"pfNoPileUpJME"+postfix).enable =
True
471 getattr(process,
"pfNoMuonJMEPFBRECO"+postfix).enable =
True
472 getattr(process,
"pfNoElectronJMEPFBRECO"+postfix).enable =
True
473 getattr(process,
"pfNoTauPFBRECO"+postfix).enable =
False
474 getattr(process,
"pfNoJetPFBRECO"+postfix).enable =
True
476 for object
in excludeFromTopProjection:
478 if object
in [
'Muon',
'Electron']:
480 getattr(process,
"pfNo"+object+jme+
'PFBRECO'+postfix).enable =
False
481 exclusionList=exclusionList+object+
','
482 exclusionList=exclusionList.rstrip(
',')
483 print "Done: PFBRECO interfaced to PAT, postfix=", postfix,
", Excluded from Top Projection:",exclusionList
def massSearchReplaceParam
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
if(conf.exists("allCellsPositionCalc"))