9 from copy
import deepcopy
12 print "WARNING: particle based isolation must be studied"
14 from CommonTools.ParticleFlow.Tools.pfIsolation
import setupPFElectronIso, setupPFMuonIso
17 print "using Gsf Electrons in PF2PAT"
18 print "WARNING: this will destory the feature of top projection which solves the ambiguity between leptons and jets because"
19 print "WARNING: there will be overlap between non-PF electrons and jets even though top projection is ON!"
20 print "********************* "
22 module.useParticleFlow =
False
23 print "Building particle-based isolation for GsfElectrons in PF2PAT(PFBRECO)"
24 print "********************* "
26 getattr(process,
'patDefaultSequence'+postfix).
replace( getattr(process,
"patElectrons"+postfix),
28 getattr(process,
"patElectrons"+postfix) )
32 module.isoDeposits = cms.PSet(
33 pfChargedHadrons = cms.InputTag(
"elPFIsoDepositCharged" + postfix),
34 pfChargedAll = cms.InputTag(
"elPFIsoDepositChargedAll" + postfix),
35 pfPUChargedHadrons = cms.InputTag(
"elPFIsoDepositPU" + postfix),
36 pfNeutralHadrons = cms.InputTag(
"elPFIsoDepositNeutral" + postfix),
37 pfPhotons = cms.InputTag(
"elPFIsoDepositGamma" + postfix)
39 module.isolationValues = cms.PSet(
40 pfChargedHadrons = cms.InputTag(
"elPFIsoValueCharged"+dR+
"PFId"+ postfix),
41 pfChargedAll = cms.InputTag(
"elPFIsoValueChargedAll"+dR+
"PFId"+ postfix),
42 pfPUChargedHadrons = cms.InputTag(
"elPFIsoValuePU"+dR+
"PFId" + postfix),
43 pfNeutralHadrons = cms.InputTag(
"elPFIsoValueNeutral"+dR+
"PFId" + postfix),
44 pfPhotons = cms.InputTag(
"elPFIsoValueGamma"+dR+
"PFId" + postfix)
46 module.isolationValuesNoPFId = cms.PSet(
47 pfChargedHadrons = cms.InputTag(
"elPFIsoValueCharged"+dR+
"NoPFId"+ postfix),
48 pfChargedAll = cms.InputTag(
"elPFIsoValueChargedAll"+dR+
"NoPFId"+ postfix),
49 pfPUChargedHadrons = cms.InputTag(
"elPFIsoValuePU"+dR+
"NoPFId" + postfix),
50 pfNeutralHadrons = cms.InputTag(
"elPFIsoValueNeutral"+dR+
"NoPFId" + postfix),
51 pfPhotons = cms.InputTag(
"elPFIsoValueGamma"+dR+
"NoPFId" + postfix)
56 module.isoDeposits = cms.PSet(
57 pfChargedHadrons = cms.InputTag(
"muPFIsoDepositCharged" + postfix),
58 pfChargedAll = cms.InputTag(
"muPFIsoDepositChargedAll" + postfix),
59 pfPUChargedHadrons = cms.InputTag(
"muPFIsoDepositPU" + postfix),
60 pfNeutralHadrons = cms.InputTag(
"muPFIsoDepositNeutral" + postfix),
61 pfPhotons = cms.InputTag(
"muPFIsoDepositGamma" + postfix)
63 module.isolationValues = cms.PSet(
64 pfChargedHadrons = cms.InputTag(
"muPFIsoValueCharged" + dR + postfix),
65 pfChargedAll = cms.InputTag(
"muPFIsoValueChargedAll" + dR + postfix),
66 pfPUChargedHadrons = cms.InputTag(
"muPFIsoValuePU" + dR + postfix),
67 pfNeutralHadrons = cms.InputTag(
"muPFIsoValueNeutral" + dR + postfix),
68 pfPhotons = cms.InputTag(
"muPFIsoValueGamma" + dR + postfix)
72 print "Building particle-based isolation "
73 print "***************** "
78 getattr(process,
'patDefaultSequence').
replace( getattr(process,
"patCandidates"),
79 process.pfParticleSelectionSequence +
80 process.eleIsoSequence +
81 process.muIsoSequence +
82 getattr(process,
"patCandidates") )
85 print "Adapting PF Muons "
86 print "***************** "
89 module.useParticleFlow =
True
90 module.pfMuonSource = cms.InputTag(
"pfIsolatedMuons" + postfix)
91 module.userIsolation = cms.PSet()
107 applyPostfix(process,
"muonMatch",postfix).src = module.pfMuonSource
109 print " muon source:", module.pfMuonSource
119 print "Adapting PF Electrons "
120 print "********************* "
123 module.useParticleFlow =
True
124 module.pfElectronSource = cms.InputTag(
"pfIsolatedElectrons" + postfix)
125 module.userIsolation = cms.PSet()
147 print " PF electron source:", module.pfElectronSource
158 raise RuntimeError,
"Photons are not supported yet"
163 tauType=
'shrinkingConePFTau',
164 pf2patSelection=[
"DiscriminationByIsolation",
"DiscriminationByLeadingPionPtCut"],
165 selectionDependsOn=[
"DiscriminationByLeadingTrackFinding"],
166 producerFromType=
lambda producer: producer+
"Producer",
168 print "patTaus will be produced from taus of type: %s that pass %s" \
169 % (tauType, pf2patSelection)
174 producerName = producerFromType(tauType)
176 applyPostfix(process,
"pfTaus", postfix).src = producerName+postfix
178 oldTauSansRefs = getattr(process,
'pfTausProducerSansRefs'+postfix)
179 oldTau = getattr(process,
'pfTausProducer'+postfix)
181 newTauSansRefs =
None
182 newTau = getattr(process,producerName+postfix).
clone()
185 if tauType==
'shrinkingConePFTau':
186 newTauSansRefs = getattr(process,producerName+
"SansRefs").
clone()
187 newTauSansRefs.modifiers[1] = cms.PSet(
188 pfTauTagInfoSrc = cms.InputTag(
"pfTauTagInfoProducer"+postfix),
189 name = cms.string(
'pfTauTTIworkaround'+postfix),
190 plugin = cms.string(
'RecoTauTagInfoWorkaroundModifer')
192 newTau.modifiers[1] = newTauSansRefs.modifiers[1]
193 newTauSansRefs.piZeroSrc =
"pfJetsLegacyTaNCPiZeros"+postfix
194 newTau.piZeroSrc = newTauSansRefs.piZeroSrc
195 newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
196 newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
197 newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
198 elif tauType==
'fixedConePFTau':
199 newTau.piZeroSrc =
"pfJetsLegacyTaNCPiZeros"+postfix
200 elif tauType==
'hpsPFTau':
201 newTau = getattr(process,
'combinatoricRecoTaus'+postfix).
clone()
202 newTau.piZeroSrc=
"pfJetsLegacyHPSPiZeros"+postfix
203 newTau.modifiers[3] = cms.PSet(
204 pfTauTagInfoSrc = cms.InputTag(
"pfTauTagInfoProducer"+postfix),
205 name = cms.string(
'pfTauTTIworkaround'+postfix),
206 plugin = cms.string(
'RecoTauTagInfoWorkaroundModifer')
210 setattr(process,
'produceHPSPFTaus'+postfix,cms.Sequence(
applyPostfix(process,
'hpsSelectionDiscriminator',postfix)+
applyPostfix(process,
'hpsPFTauProducerSansRefs',postfix)+
applyPostfix(process,
'hpsPFTauProducer',postfix)))
213 cms.InputTag(
"combinatoricRecoTaus"+postfix),
214 cms.InputTag(
"pfTausBase"+postfix) )
217 cms.InputTag(
"combinatoricRecoTaus"+postfix),
218 cms.InputTag(
"pfTausBase"+postfix) )
227 setattr(process,
"pfTausBase"+postfix,newTau)
228 if tauType==
'shrinkingConePFTau':
229 setattr(process,
"pfTausBaseSansRefs"+postfix,newTauSansRefs)
230 getattr(process,
"pfTausBase"+postfix).src =
"pfTausBaseSansRefs"+postfix
231 baseSequence += getattr(process,
"pfTausBaseSansRefs"+postfix)
234 def producerIsTauTypeMapperWithPostfix(tauProducer):
237 def recoTauTypeMapperWithGroup(tauProducer):
241 for predisc
in selectionDependsOn:
243 originalName = tauType+predisc
244 clonedName =
"pfTausBase"+predisc+postfix
245 clonedDisc = getattr(process, originalName).
clone()
246 setattr(process, clonedName, clonedDisc)
248 tauCollectionToSelect =
None
249 if tauType !=
'hpsPFTau' :
250 tauCollectionToSelect =
"pfTausBase"+postfix
253 tauCollectionToSelect =
"hpsPFTauProducer"+postfix
256 oldTauTypeMapper=recoTauTypeMapperWithGroup,
257 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
258 preservePFTauProducer=
True)
259 clonedDisc.PFTauProducer = tauCollectionToSelect
262 getattr(process,
"pfTaus" + postfix).discriminators = cms.VPSet()
263 for selection
in pf2patSelection:
265 originalName = tauType+selection
266 clonedName =
"pfTausBase"+selection+postfix
267 clonedDisc = getattr(process, originalName).
clone()
268 setattr(process, clonedName, clonedDisc)
270 tauCollectionToSelect =
None
272 if tauType !=
'hpsPFTau' :
273 tauCollectionToSelect = cms.InputTag(
"pfTausBase"+postfix)
276 tauCollectionToSelect = cms.InputTag(
"hpsPFTauProducer"+postfix)
279 oldTauTypeMapper=recoTauTypeMapperWithGroup,
280 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
281 preservePFTauProducer=
True)
282 clonedDisc.PFTauProducer = tauCollectionToSelect
285 getattr(process,
"pfTaus" + postfix).discriminators.append(cms.PSet(
286 discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
288 if tauType !=
'hpsPFTau':
289 getattr(process,
"pfTaus" + postfix).src =
"pfTausBase"+postfix
293 getattr(process,
"pfTaus" + postfix).src =
"hpsPFTauProducer"+postfix
297 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
299 if tauType !=
'hpsPFTau' :
303 [
"DiscriminationByLooseCombinedIsolationDBSumPtCorr"],
304 [
"DiscriminationByDecayModeFinding"],
307 if tauType !=
'hpsPFTau' :
308 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
310 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
321 if tauType !=
'hpsPFTau' :
323 patTauLabel=
"pfTausBase"+postfix,
324 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
326 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
330 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
332 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
338 process.load(
"CommonTools.ParticleFlow.pfTaus_cff")
339 applyPostfix(process,
"pfTaus",postfix).src = cms.InputTag(tauType+
'Producer'+postfix)
343 from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi
import patPFParticles
345 producer = patPFParticles.clone(pfCandidateSource = src)
346 filter = cms.EDFilter(
"PATPFParticleSelector",
347 src = cms.InputTag(
"pat" + patLabel),
348 cut = cms.string(cut))
349 counter = cms.EDFilter(
"PATCandViewCountFilter",
350 minNumber = cms.uint32(0),
351 maxNumber = cms.uint32(999999),
352 src = cms.InputTag(
"pat" + patLabel))
354 setattr(process,
"pat" + patLabel, producer)
355 setattr(process,
"selectedPat" + patLabel, filter)
356 setattr(process,
"countPat" + patLabel, counter)
359 applyPostfix(process,
"patCandidateSummary", postfix).candidates.append(cms.InputTag(
'pat' + patLabel))
360 applyPostfix(process,
"selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag(
'selectedPat' + patLabel))
363 def switchToPFMET(process,input=cms.InputTag(
'pfMET'), type1=
False, postfix=
""):
364 print 'MET: using ', input
366 oldMETSource =
applyPostfix(process,
"patMETs",postfix).metSource
367 applyPostfix(process,
"patMETs",postfix).metSource = input
368 applyPostfix(process,
"patMETs",postfix).addMuonCorrections =
False
372 print 'Apply TypeI corrections for MET'
374 jecLabel = getattr(process,
'patJetCorrFactors'+postfix).payload.pythonValue().
replace(
"'",
"")
375 getattr(process,jecLabel+
'Type1CorMet'+postfix).src = input.getModuleLabel()
379 def switchToPFJets(process, input=cms.InputTag(
'pfNoTauClones'), algo=
'AK5', postfix =
"", jetCorrections=(
'AK5PFchs', [
'L1FastJet',
'L2Relative',
'L3Absolute']), type1=
False, outputModules=[
'out']):
381 print "Switching to PFJets, ", algo
382 print "************************ "
383 print "input collection: ", input
386 genJetCollection = cms.InputTag(
'iterativeCone5GenJetsNoNu')
388 genJetCollection = cms.InputTag(
'ak5GenJetsNoNu')
390 genJetCollection = cms.InputTag(
'ak7GenJetsNoNu')
392 print 'bad jet algorithm:', algo,
'! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
396 from CommonTools.ParticleFlow.Tools.jetTools
import jetAlgo
397 inputCollection = getattr(process,
"pfJets"+postfix).src
398 setattr(process,
"pfJets"+postfix,
jetAlgo(algo))
399 getattr(process,
"pfJets"+postfix).src = inputCollection
400 inputJetCorrLabel=jetCorrections
402 switchJetCollection(process,
406 jetTrackAssociation=
True,
407 jetCorrections=inputJetCorrLabel,
408 outputModules = outputModules,
413 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
False
414 for corr
in inputJetCorrLabel[1]:
415 if corr ==
'L1FastJet':
416 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
True
417 applyPostfix(process,
"pfJets", postfix).doAreaFastjet =
True
421 for mod
in process.producerNames().
split(
' '):
423 if mod.startswith(
"kt6")
and mod.endswith(
"Jets"+postfix)
and not 'GenJets' in mod:
424 prefix = mod.replace(postfix,
'')
425 prefix = prefix.replace(
'kt6PFJets',
'')
426 prefix = prefix.replace(
'kt6CaloJets',
'')
427 prefix = getattr(process,
'patJetCorrFactors'+prefix+postfix).payload.pythonValue().
replace(
"'",
"")
428 for essource
in process.es_sources_().
keys():
429 if essource == prefix+
'L1FastJet':
430 setattr(process,essource+postfix,getattr(process,essource).
clone(srcRho=cms.InputTag(mod,
'rho')))
431 setattr(process,prefix+
'CombinedCorrector'+postfix,getattr(process,prefix+
'CombinedCorrector').
clone())
432 getattr(process,prefix+
'CorMet'+postfix).corrector = prefix+
'CombinedCorrector'+postfix
433 for cor
in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
435 idx = getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.index(essource);
436 getattr(process,prefix+
'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
438 if hasattr( getattr( process,
"patJets" + postfix),
'embedCaloTowers' ):
439 applyPostfix(process,
"patJets", postfix).embedCaloTowers =
False
440 applyPostfix(process,
"patJets", postfix).embedPFCandidates =
True
447 removeMCMatching(process, names=[
'All'], postfix=postfix, outputModules=outputModules)
450 def adaptPVs(process, pvCollection=cms.InputTag(
'offlinePrimaryVertices'), postfix=
''):
451 print "Switching PV collection for PF2PAT:", pvCollection
452 print "***********************************"
455 pvExchange = [
'Vertices',
'vertices',
'pvSrc',
'primaryVertices',
'srcPVs']
461 for m
in process.producerNames().
split(
' '):
462 if m.startswith(
'patJets')
and m.endswith(postfix)
and not len(m)==len(
'patJets')+len(postfix):
463 interPostfix = m.replace(
'patJets',
'')
464 interPostfix = interPostfix.replace(postfix,
'')
465 interPostfixes.append(interPostfix)
468 for m
in process.producerNames().
split(
' '):
469 modName = m.replace(postfix,
'')
471 for namePvSrc
in pvExchange:
472 if hasattr(getattr(process,m),namePvSrc):
474 interPostFixFlag =
False
475 for pfix
in interPostfixes:
476 if modName.endswith(pfix):
477 interPostFixFlag =
True
479 if not interPostFixFlag:
480 setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
483 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']):
487 if typeIMetCorrections:
488 jetCorrections = (jetCorrections[0],jetCorrections[1],
'Type-1')
489 """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
494 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
497 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
522 switchToPFJets( process, cms.InputTag(
'pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
523 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
526 if not 'L2L3Residual' in jetCorrections[1]:
528 print '#################################################'
529 print 'WARNING! Not using L2L3Residual but this is data.'
530 print 'If this is okay with you, disregard this message.'
531 print '#################################################'
532 switchToPFJets( process, cms.InputTag(
'pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
533 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
537 adaptPFTaus( process, tauType=
'hpsPFTau', postfix=postfix )
539 switchToPFMET(process, cms.InputTag(
'pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
542 addPFCandidates(process,cms.InputTag(
'pfNoJetClones'+postfix),patLabel=
'PFParticles'+postfix,cut=
"",postfix=postfix)
545 adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
549 loadWithPostfix(process,
"CommonTools.ParticleFlow.genForPF2PAT_cff",postfix)
552 runOnData(process,postfix=postfix,outputModules=outputModules)
555 getattr(process,
"pfNoPileUp"+postfix).enable =
True
556 getattr(process,
"pfNoMuon"+postfix).enable =
True
557 getattr(process,
"pfNoElectron"+postfix).enable =
True
558 getattr(process,
"pfNoTau"+postfix).enable =
False
559 getattr(process,
"pfNoJet"+postfix).enable =
True
561 for object
in excludeFromTopProjection:
562 getattr(process,
"pfNo"+object+postfix).enable =
False
563 exclusionList=exclusionList+object+
','
564 exclusionList=exclusionList.rstrip(
',')
565 print "Done: PF2PAT interfaced to PAT, postfix=", postfix,
", Exluded from Top Projection:",exclusionList
string jetAlgo
Jet configuration.
def massSearchReplaceParam
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)