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=
'AK4', postfix =
"", jetCorrections=(
'AK4PFchs', [
'L1FastJet',
'L2Relative',
'L3Absolute']), type1=
False, outputModules=[
'out']):
352 print "Switching to PFJets, ", algo
353 print "************************ "
354 print "input collection: ", input
357 genJetCollection = cms.InputTag(
'ak4GenJetsNoNu'+postfix)
360 genJetCollection = cms.InputTag(
'ak7GenJetsNoNu'+postfix)
363 print 'bad jet algorithm:', algo,
'! for now, only AK4 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 genJetCollection=genJetCollection,
379 jetTrackAssociation=
True,
380 jetCorrections=inputJetCorrLabel,
381 outputModules = outputModules,
385 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
False
386 for corr
in inputJetCorrLabel[1]:
387 if corr ==
'L1FastJet':
388 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
True
389 applyPostfix(process,
"pfJets", postfix).doAreaFastjet =
True
393 for mod
in process.producerNames().
split(
' '):
395 if mod.startswith(
"kt6")
and mod.endswith(
"Jets"+postfix)
and not 'GenJets' in mod:
396 prefix = mod.replace(postfix,
'')
397 prefix = prefix.replace(
'kt6PFJets',
'')
398 prefix = prefix.replace(
'kt6CaloJets',
'')
399 prefix = getattr(process,
'patJetCorrFactors'+prefix+postfix).payload.pythonValue().
replace(
"'",
"")
400 for essource
in process.es_sources_().
keys():
401 if essource == prefix+
'L1FastJet':
402 setattr(process,essource+postfix,getattr(process,essource).
clone(srcRho=cms.InputTag(mod,
'rho')))
403 setattr(process,prefix+
'CombinedCorrector'+postfix,getattr(process,prefix+
'CombinedCorrector').
clone())
404 getattr(process,prefix+
'CorMet'+postfix).corrector = prefix+
'CombinedCorrector'+postfix
405 for cor
in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
407 idx = getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.index(essource);
408 getattr(process,prefix+
'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
410 if hasattr( getattr( process,
"patJets" + postfix),
'embedCaloTowers' ):
411 applyPostfix(process,
"patJets", postfix).embedCaloTowers =
False
412 applyPostfix(process,
"patJets", postfix).embedPFCandidates =
True
419 removeMCMatching(process, names=[
'All'], postfix=postfix, outputModules=outputModules)
422 def adaptPVs(process, pvCollection=cms.InputTag(
'offlinePrimaryVertices'), postfix=
''):
423 print "Switching PV collection for PF2PAT:", pvCollection
424 print "***********************************"
427 pvExchange = [
'Vertices',
'vertices',
'pvSrc',
'primaryVertices',
'srcPVs',
'primaryVertex']
432 for m
in (process.producerNames().
split(
' ') + process.filterNames().
split(
' ')):
434 for namePvSrc
in pvExchange:
435 if hasattr(getattr(process,m),namePvSrc):
437 setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
440 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']):
444 if typeIMetCorrections:
445 jetCorrections = (jetCorrections[0],jetCorrections[1],
'Type-1')
446 """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
451 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
454 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
479 switchToPFJets( process, cms.InputTag(
'pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
480 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
483 if not 'L2L3Residual' in jetCorrections[1]:
485 print '#################################################'
486 print 'WARNING! Not using L2L3Residual but this is data.'
487 print 'If this is okay with you, disregard this message.'
488 print '#################################################'
489 switchToPFJets( process, cms.InputTag(
'pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
490 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
494 adaptPFTaus( process, tauType=
'hpsPFTau', postfix=postfix )
496 switchToPFMET(process, cms.InputTag(
'pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
499 addPFCandidates(process,cms.InputTag(
'pfNoJetClones'+postfix),patLabel=
'PFParticles'+postfix,cut=
"",postfix=postfix)
502 adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
505 runOnData(process,postfix=postfix,outputModules=outputModules)
508 getattr(process,
"pfNoPileUpJME"+postfix).enable =
True
509 getattr(process,
"pfNoMuonJME"+postfix).enable =
True
510 getattr(process,
"pfNoElectronJME"+postfix).enable =
True
511 getattr(process,
"pfNoTau"+postfix).enable =
False
512 getattr(process,
"pfNoJet"+postfix).enable =
True
514 for object
in excludeFromTopProjection:
516 if object
in [
'Muon',
'Electron']:
518 getattr(process,
"pfNo"+object+jme+postfix).enable =
False
519 exclusionList=exclusionList+object+
','
520 exclusionList=exclusionList.rstrip(
',')
521 print "Done: PF2PAT interfaced to PAT, postfix=", postfix,
", Excluded from Top Projection:",exclusionList
string jetAlgo
Jet configuration.
def massSearchReplaceParam
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
if(conf.exists("allCellsPositionCalc"))