9 from copy
import deepcopy
12 print "WARNING: particle based isolation must be studied"
16 module.isoDeposits = cms.PSet(
17 pfChargedHadrons = cms.InputTag(
"elPFIsoDepositCharged" + postfix),
18 pfChargedAll = cms.InputTag(
"elPFIsoDepositChargedAll" + postfix),
19 pfPUChargedHadrons = cms.InputTag(
"elPFIsoDepositPU" + postfix),
20 pfNeutralHadrons = cms.InputTag(
"elPFIsoDepositNeutral" + postfix),
21 pfPhotons = cms.InputTag(
"elPFIsoDepositGamma" + postfix)
23 module.isolationValues = cms.PSet(
24 pfChargedHadrons = cms.InputTag(
"elPFIsoValueCharged"+dR+
"PFId"+ postfix),
25 pfChargedAll = cms.InputTag(
"elPFIsoValueChargedAll"+dR+
"PFId"+ postfix),
26 pfPUChargedHadrons = cms.InputTag(
"elPFIsoValuePU"+dR+
"PFId" + postfix),
27 pfNeutralHadrons = cms.InputTag(
"elPFIsoValueNeutral"+dR+
"PFId" + postfix),
28 pfPhotons = cms.InputTag(
"elPFIsoValueGamma"+dR+
"PFId" + postfix)
30 module.isolationValuesNoPFId = cms.PSet(
31 pfChargedHadrons = cms.InputTag(
"elPFIsoValueCharged"+dR+
"NoPFId"+ postfix),
32 pfChargedAll = cms.InputTag(
"elPFIsoValueChargedAll"+dR+
"NoPFId"+ postfix),
33 pfPUChargedHadrons = cms.InputTag(
"elPFIsoValuePU"+dR+
"NoPFId" + postfix),
34 pfNeutralHadrons = cms.InputTag(
"elPFIsoValueNeutral"+dR+
"NoPFId" + postfix),
35 pfPhotons = cms.InputTag(
"elPFIsoValueGamma"+dR+
"NoPFId" + postfix)
40 module.isoDeposits = cms.PSet(
41 pfChargedHadrons = cms.InputTag(
"muPFIsoDepositCharged" + postfix),
42 pfChargedAll = cms.InputTag(
"muPFIsoDepositChargedAll" + postfix),
43 pfPUChargedHadrons = cms.InputTag(
"muPFIsoDepositPU" + postfix),
44 pfNeutralHadrons = cms.InputTag(
"muPFIsoDepositNeutral" + postfix),
45 pfPhotons = cms.InputTag(
"muPFIsoDepositGamma" + postfix)
47 module.isolationValues = cms.PSet(
48 pfChargedHadrons = cms.InputTag(
"muPFIsoValueCharged" + dR + postfix),
49 pfChargedAll = cms.InputTag(
"muPFIsoValueChargedAll" + dR + postfix),
50 pfPUChargedHadrons = cms.InputTag(
"muPFIsoValuePU" + dR + postfix),
51 pfNeutralHadrons = cms.InputTag(
"muPFIsoValueNeutral" + dR + postfix),
52 pfPhotons = cms.InputTag(
"muPFIsoValueGamma" + dR + postfix)
56 print "Adapting PF Muons "
57 print "***************** "
60 module.useParticleFlow =
True
61 module.pfMuonSource = cms.InputTag(
"pfIsolatedMuons" + postfix)
62 module.userIsolation = cms.PSet()
78 applyPostfix(process,
"muonMatch",postfix).src = module.pfMuonSource
80 print " muon source:", module.pfMuonSource
90 print "Adapting PF Electrons "
91 print "********************* "
94 module.useParticleFlow =
True
95 module.pfElectronSource = cms.InputTag(
"pfIsolatedElectrons" + postfix)
96 module.userIsolation = cms.PSet()
118 print " PF electron source:", module.pfElectronSource
129 raise RuntimeError,
"Photons are not supported yet"
134 tauType=
'shrinkingConePFTau',
135 pf2patSelection=[
"DiscriminationByIsolation",
"DiscriminationByLeadingPionPtCut"],
136 selectionDependsOn=[
"DiscriminationByLeadingTrackFinding"],
137 producerFromType=
lambda producer: producer+
"Producer",
139 print "patTaus will be produced from taus of type: %s that pass %s" \
140 % (tauType, pf2patSelection)
145 producerName = producerFromType(tauType)
147 applyPostfix(process,
"pfTaus", postfix).src = producerName+postfix
149 oldTauSansRefs = getattr(process,
'pfTausProducerSansRefs'+postfix)
150 oldTau = getattr(process,
'pfTausProducer'+postfix)
152 newTauSansRefs =
None
153 newTau = getattr(process,producerName+postfix).
clone()
156 if tauType==
'shrinkingConePFTau':
157 newTauSansRefs = getattr(process,producerName+
"SansRefs").
clone()
158 newTauSansRefs.modifiers[1] = cms.PSet(
159 pfTauTagInfoSrc = cms.InputTag(
"pfTauTagInfoProducer"+postfix),
160 name = cms.string(
'pfTauTTIworkaround'+postfix),
161 plugin = cms.string(
'RecoTauTagInfoWorkaroundModifer')
163 newTau.modifiers[1] = newTauSansRefs.modifiers[1]
164 newTauSansRefs.piZeroSrc =
"pfJetsLegacyTaNCPiZeros"+postfix
165 newTau.piZeroSrc = newTauSansRefs.piZeroSrc
166 newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
167 newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
168 newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
169 elif tauType==
'fixedConePFTau':
170 newTau.piZeroSrc =
"pfJetsLegacyTaNCPiZeros"+postfix
171 elif tauType==
'hpsPFTau':
172 newTau = getattr(process,
'combinatoricRecoTaus'+postfix).
clone()
173 newTau.piZeroSrc=
"pfJetsLegacyHPSPiZeros"+postfix
174 newTau.modifiers[3] = cms.PSet(
175 pfTauTagInfoSrc = cms.InputTag(
"pfTauTagInfoProducer"+postfix),
176 name = cms.string(
'pfTauTTIworkaround'+postfix),
177 plugin = cms.string(
'RecoTauTagInfoWorkaroundModifer')
181 setattr(process,
'produceHPSPFTaus'+postfix,cms.Sequence(
applyPostfix(process,
'hpsSelectionDiscriminator',postfix)+
applyPostfix(process,
'hpsPFTauProducerSansRefs',postfix)+
applyPostfix(process,
'hpsPFTauProducer',postfix)))
184 cms.InputTag(
"combinatoricRecoTaus"+postfix),
185 cms.InputTag(
"pfTausBase"+postfix) )
188 cms.InputTag(
"combinatoricRecoTaus"+postfix),
189 cms.InputTag(
"pfTausBase"+postfix) )
198 setattr(process,
"pfTausBase"+postfix,newTau)
199 if tauType==
'shrinkingConePFTau':
200 setattr(process,
"pfTausBaseSansRefs"+postfix,newTauSansRefs)
201 getattr(process,
"pfTausBase"+postfix).src =
"pfTausBaseSansRefs"+postfix
202 baseSequence += getattr(process,
"pfTausBaseSansRefs"+postfix)
205 def producerIsTauTypeMapperWithPostfix(tauProducer):
208 def recoTauTypeMapperWithGroup(tauProducer):
212 for predisc
in selectionDependsOn:
214 originalName = tauType+predisc
215 clonedName =
"pfTausBase"+predisc+postfix
216 clonedDisc = getattr(process, originalName).
clone()
217 setattr(process, clonedName, clonedDisc)
219 tauCollectionToSelect =
None
220 if tauType !=
'hpsPFTau' :
221 tauCollectionToSelect =
"pfTausBase"+postfix
224 tauCollectionToSelect =
"hpsPFTauProducer"+postfix
227 oldTauTypeMapper=recoTauTypeMapperWithGroup,
228 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
229 preservePFTauProducer=
True)
230 clonedDisc.PFTauProducer = tauCollectionToSelect
233 getattr(process,
"pfTaus" + postfix).discriminators = cms.VPSet()
234 for selection
in pf2patSelection:
236 originalName = tauType+selection
237 clonedName =
"pfTausBase"+selection+postfix
238 clonedDisc = getattr(process, originalName).
clone()
239 setattr(process, clonedName, clonedDisc)
241 tauCollectionToSelect =
None
243 if tauType !=
'hpsPFTau' :
244 tauCollectionToSelect = cms.InputTag(
"pfTausBase"+postfix)
247 tauCollectionToSelect = cms.InputTag(
"hpsPFTauProducer"+postfix)
250 oldTauTypeMapper=recoTauTypeMapperWithGroup,
251 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
252 preservePFTauProducer=
True)
253 clonedDisc.PFTauProducer = tauCollectionToSelect
256 getattr(process,
"pfTaus" + postfix).discriminators.append(cms.PSet(
257 discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
259 if tauType !=
'hpsPFTau':
260 getattr(process,
"pfTaus" + postfix).src =
"pfTausBase"+postfix
264 getattr(process,
"pfTaus" + postfix).src =
"hpsPFTauProducer"+postfix
268 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
270 if tauType !=
'hpsPFTau' :
274 [
"DiscriminationByDecayModeFinding"],
275 [
"DiscriminationByDecayModeFinding"],
278 if tauType !=
'hpsPFTau' :
279 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
281 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
292 if tauType !=
'hpsPFTau' :
294 patTauLabel=
"pfTausBase"+postfix,
295 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
297 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
301 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
303 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
309 process.load(
"CommonTools.ParticleFlow.pfTaus_cff")
310 applyPostfix(process,
"pfTaus",postfix).src = cms.InputTag(tauType+
'Producer'+postfix)
314 from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi
import patPFParticles
316 producer = patPFParticles.clone(pfCandidateSource = src)
317 filter = cms.EDFilter(
"PATPFParticleSelector",
318 src = cms.InputTag(
"pat" + patLabel),
319 cut = cms.string(cut))
320 counter = cms.EDFilter(
"PATCandViewCountFilter",
321 minNumber = cms.uint32(0),
322 maxNumber = cms.uint32(999999),
323 src = cms.InputTag(
"pat" + patLabel))
325 setattr(process,
"pat" + patLabel, producer)
326 setattr(process,
"selectedPat" + patLabel, filter)
327 setattr(process,
"countPat" + patLabel, counter)
330 applyPostfix(process,
"patCandidateSummary", postfix).candidates.append(cms.InputTag(
'pat' + patLabel))
331 applyPostfix(process,
"selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag(
'selectedPat' + patLabel))
334 def switchToPFMET(process,input=cms.InputTag(
'pfMET'), type1=
False, postfix=
""):
335 print 'MET: using ', input
337 oldMETSource =
applyPostfix(process,
"patMETs",postfix).metSource
338 applyPostfix(process,
"patMETs",postfix).metSource = input
339 applyPostfix(process,
"patMETs",postfix).addMuonCorrections =
False
343 print 'Apply TypeI corrections for MET'
345 jecLabel = getattr(process,
'patJetCorrFactors'+postfix).payload.pythonValue().
replace(
"'",
"")
346 getattr(process,jecLabel+
'Type1CorMet'+postfix).src = input.getModuleLabel()
350 def switchToPFJets(process, input=cms.InputTag(
'pfNoTauClones'), algo=
'AK5', postfix =
"", jetCorrections=(
'AK5PFchs', [
'L1FastJet',
'L2Relative',
'L3Absolute']), type1=
False, outputModules=[
'out']):
352 print "Switching to PFJets, ", algo
353 print "************************ "
354 print "input collection: ", input
357 genJetCollection = cms.InputTag(
'iterativeCone5GenJetsNoNu')
359 genJetCollection = cms.InputTag(
'ak5GenJetsNoNu')
361 genJetCollection = cms.InputTag(
'ak7GenJetsNoNu')
363 print 'bad jet algorithm:', algo,
'! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
367 from CommonTools.ParticleFlow.Tools.jetTools
import jetAlgo
368 inputCollection = getattr(process,
"pfJets"+postfix).src
369 setattr(process,
"pfJets"+postfix,
jetAlgo(algo))
370 getattr(process,
"pfJets"+postfix).src = inputCollection
371 inputJetCorrLabel=jetCorrections
373 switchJetCollection(process,
377 jetTrackAssociation=
True,
378 jetCorrections=inputJetCorrLabel,
379 outputModules = outputModules,
384 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
False
385 for corr
in inputJetCorrLabel[1]:
386 if corr ==
'L1FastJet':
387 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
True
388 applyPostfix(process,
"pfJets", postfix).doAreaFastjet =
True
392 for mod
in process.producerNames().
split(
' '):
394 if mod.startswith(
"kt6")
and mod.endswith(
"Jets"+postfix)
and not 'GenJets' in mod:
395 prefix = mod.replace(postfix,
'')
396 prefix = prefix.replace(
'kt6PFJets',
'')
397 prefix = prefix.replace(
'kt6CaloJets',
'')
398 prefix = getattr(process,
'patJetCorrFactors'+prefix+postfix).payload.pythonValue().
replace(
"'",
"")
399 for essource
in process.es_sources_().
keys():
400 if essource == prefix+
'L1FastJet':
401 setattr(process,essource+postfix,getattr(process,essource).
clone(srcRho=cms.InputTag(mod,
'rho')))
402 setattr(process,prefix+
'CombinedCorrector'+postfix,getattr(process,prefix+
'CombinedCorrector').
clone())
403 getattr(process,prefix+
'CorMet'+postfix).corrector = prefix+
'CombinedCorrector'+postfix
404 for cor
in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
406 idx = getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.index(essource);
407 getattr(process,prefix+
'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
409 if hasattr( getattr( process,
"patJets" + postfix),
'embedCaloTowers' ):
410 applyPostfix(process,
"patJets", postfix).embedCaloTowers =
False
411 applyPostfix(process,
"patJets", postfix).embedPFCandidates =
True
418 removeMCMatching(process, names=[
'All'], postfix=postfix, outputModules=outputModules)
421 def adaptPVs(process, pvCollection=cms.InputTag(
'offlinePrimaryVertices'), postfix=
''):
422 print "Switching PV collection for PF2PAT:", pvCollection
423 print "***********************************"
426 pvExchange = [
'Vertices',
'vertices',
'pvSrc',
'primaryVertices',
'srcPVs']
432 for m
in process.producerNames().
split(
' '):
433 if m.startswith(
'patJets')
and m.endswith(postfix)
and not len(m)==len(
'patJets')+len(postfix):
434 interPostfix = m.replace(
'patJets',
'')
435 interPostfix = interPostfix.replace(postfix,
'')
436 interPostfixes.append(interPostfix)
439 for m
in process.producerNames().
split(
' '):
440 modName = m.replace(postfix,
'')
442 for namePvSrc
in pvExchange:
443 if hasattr(getattr(process,m),namePvSrc):
445 interPostFixFlag =
False
446 for pfix
in interPostfixes:
447 if modName.endswith(pfix):
448 interPostFixFlag =
True
450 if not interPostFixFlag:
451 setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
454 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']):
458 if typeIMetCorrections:
459 jetCorrections = (jetCorrections[0],jetCorrections[1],
'Type-1')
460 """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
465 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
468 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
493 switchToPFJets( process, cms.InputTag(
'pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
494 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
497 if not 'L2L3Residual' in jetCorrections[1]:
499 print '#################################################'
500 print 'WARNING! Not using L2L3Residual but this is data.'
501 print 'If this is okay with you, disregard this message.'
502 print '#################################################'
503 switchToPFJets( process, cms.InputTag(
'pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
504 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
508 adaptPFTaus( process, tauType=
'hpsPFTau', postfix=postfix )
510 switchToPFMET(process, cms.InputTag(
'pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
513 addPFCandidates(process,cms.InputTag(
'pfNoJetClones'+postfix),patLabel=
'PFParticles'+postfix,cut=
"",postfix=postfix)
516 adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
520 loadWithPostfix(process,
"CommonTools.ParticleFlow.genForPF2PAT_cff",postfix)
523 runOnData(process,postfix=postfix,outputModules=outputModules)
526 getattr(process,
"pfNoPileUp"+postfix).enable =
True
527 getattr(process,
"pfNoMuon"+postfix).enable =
True
528 getattr(process,
"pfNoElectron"+postfix).enable =
True
529 getattr(process,
"pfNoTau"+postfix).enable =
False
530 getattr(process,
"pfNoJet"+postfix).enable =
True
532 for object
in excludeFromTopProjection:
533 getattr(process,
"pfNo"+object+postfix).enable =
False
534 exclusionList=exclusionList+object+
','
535 exclusionList=exclusionList.rstrip(
',')
536 print "Done: PF2PAT interfaced to PAT, postfix=", postfix,
", Exluded from Top Projection:",exclusionList
string jetAlgo
Jet configuration.
def massSearchReplaceParam