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)
55 def adaptPFMuons(process,module,postfix="", muonMatchModule=None ):
56 print "Adapting PF Muons "
57 print "***************** "
60 module.useParticleFlow =
True
61 module.pfMuonSource = cms.InputTag(
"pfIsolatedMuons" + postfix)
62 module.userIsolation = cms.PSet()
78 if muonMatchModule ==
None :
79 applyPostfix(process,
"muonMatch",postfix).src = module.pfMuonSource
81 muonMatchModule.src = module.pfMuonSource
83 print " muon source:", module.pfMuonSource
93 print "Adapting PF Electrons "
94 print "********************* "
97 module.useParticleFlow =
True
98 module.pfElectronSource = cms.InputTag(
"pfIsolatedElectrons" + postfix)
99 module.userIsolation = cms.PSet()
121 print " PF electron source:", module.pfElectronSource
132 raise RuntimeError,
"Photons are not supported yet"
137 tauType=
'shrinkingConePFTau',
138 pf2patSelection=[
"DiscriminationByIsolation",
"DiscriminationByLeadingPionPtCut"],
139 selectionDependsOn=[
"DiscriminationByLeadingTrackFinding"],
140 producerFromType=
lambda producer: producer+
"Producer",
142 print "patTaus will be produced from taus of type: %s that pass %s" \
143 % (tauType, pf2patSelection)
148 producerName = producerFromType(tauType)
150 applyPostfix(process,
"pfTaus", postfix).src = producerName+postfix
152 oldTauSansRefs = getattr(process,
'pfTausProducerSansRefs'+postfix)
153 oldTau = getattr(process,
'pfTausProducer'+postfix)
155 newTauSansRefs =
None
156 newTau = getattr(process,producerName+postfix).
clone()
159 if tauType==
'shrinkingConePFTau':
160 newTauSansRefs = getattr(process,producerName+
"SansRefs").
clone()
161 newTauSansRefs.modifiers[1] = cms.PSet(
162 pfTauTagInfoSrc = cms.InputTag(
"pfTauTagInfoProducer"+postfix),
163 name = cms.string(
'pfTauTTIworkaround'+postfix),
164 plugin = cms.string(
'RecoTauTagInfoWorkaroundModifer')
166 newTau.modifiers[1] = newTauSansRefs.modifiers[1]
167 newTauSansRefs.piZeroSrc =
"pfJetsLegacyTaNCPiZeros"+postfix
168 newTau.piZeroSrc = newTauSansRefs.piZeroSrc
169 newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
170 newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
171 newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
172 elif tauType==
'fixedConePFTau':
173 newTau.piZeroSrc =
"pfJetsLegacyTaNCPiZeros"+postfix
174 elif tauType==
'hpsPFTau':
175 newTau = getattr(process,
'combinatoricRecoTaus'+postfix).
clone()
176 newTau.piZeroSrc=
"pfJetsLegacyHPSPiZeros"+postfix
177 newTau.modifiers[3] = cms.PSet(
178 pfTauTagInfoSrc = cms.InputTag(
"pfTauTagInfoProducer"+postfix),
179 name = cms.string(
'pfTauTTIworkaround'+postfix),
180 plugin = cms.string(
'RecoTauTagInfoWorkaroundModifer')
184 setattr(process,
'produceHPSPFTaus'+postfix,cms.Sequence(
applyPostfix(process,
'hpsSelectionDiscriminator',postfix)+
applyPostfix(process,
'hpsPFTauProducerSansRefs',postfix)+
applyPostfix(process,
'hpsPFTauProducer',postfix)))
187 cms.InputTag(
"combinatoricRecoTaus"+postfix),
188 cms.InputTag(
"pfTausBase"+postfix) )
191 cms.InputTag(
"combinatoricRecoTaus"+postfix),
192 cms.InputTag(
"pfTausBase"+postfix) )
201 setattr(process,
"pfTausBase"+postfix,newTau)
202 if tauType==
'shrinkingConePFTau':
203 setattr(process,
"pfTausBaseSansRefs"+postfix,newTauSansRefs)
204 getattr(process,
"pfTausBase"+postfix).src =
"pfTausBaseSansRefs"+postfix
205 baseSequence += getattr(process,
"pfTausBaseSansRefs"+postfix)
208 def producerIsTauTypeMapperWithPostfix(tauProducer):
211 def recoTauTypeMapperWithGroup(tauProducer):
215 for predisc
in selectionDependsOn:
217 originalName = tauType+predisc
218 clonedName =
"pfTausBase"+predisc+postfix
219 clonedDisc = getattr(process, originalName).
clone()
220 setattr(process, clonedName, clonedDisc)
222 tauCollectionToSelect =
None
223 if tauType !=
'hpsPFTau' :
224 tauCollectionToSelect =
"pfTausBase"+postfix
227 tauCollectionToSelect =
"hpsPFTauProducer"+postfix
230 oldTauTypeMapper=recoTauTypeMapperWithGroup,
231 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
232 preservePFTauProducer=
True)
233 clonedDisc.PFTauProducer = tauCollectionToSelect
236 getattr(process,
"pfTaus" + postfix).discriminators = cms.VPSet()
237 for selection
in pf2patSelection:
239 originalName = tauType+selection
240 clonedName =
"pfTausBase"+selection+postfix
241 clonedDisc = getattr(process, originalName).
clone()
242 setattr(process, clonedName, clonedDisc)
244 tauCollectionToSelect =
None
246 if tauType !=
'hpsPFTau' :
247 tauCollectionToSelect = cms.InputTag(
"pfTausBase"+postfix)
250 tauCollectionToSelect = cms.InputTag(
"hpsPFTauProducer"+postfix)
253 oldTauTypeMapper=recoTauTypeMapperWithGroup,
254 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
255 preservePFTauProducer=
True)
256 clonedDisc.PFTauProducer = tauCollectionToSelect
259 getattr(process,
"pfTaus" + postfix).discriminators.append(cms.PSet(
260 discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
262 if tauType !=
'hpsPFTau':
263 getattr(process,
"pfTaus" + postfix).src =
"pfTausBase"+postfix
267 getattr(process,
"pfTaus" + postfix).src =
"hpsPFTauProducer"+postfix
271 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
273 if tauType !=
'hpsPFTau' :
277 [
"DiscriminationByDecayModeFinding"],
278 [
"DiscriminationByDecayModeFinding"],
281 if tauType !=
'hpsPFTau' :
282 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
284 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
295 if tauType !=
'hpsPFTau' :
297 patTauLabel=
"pfTausBase"+postfix,
298 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
300 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"pfTausBase"+postfix)
304 tauSource=cms.InputTag(tauType+
'Producer'+postfix),
306 getattr(process,
"patTaus" + postfix).tauSource = cms.InputTag(
"hpsPFTauProducer"+postfix)
312 process.load(
"CommonTools.ParticleFlow.pfTaus_cff")
313 applyPostfix(process,
"pfTaus",postfix).src = cms.InputTag(tauType+
'Producer'+postfix)
317 from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi
import patPFParticles
319 producer = patPFParticles.clone(pfCandidateSource = src)
320 filter = cms.EDFilter(
"PATPFParticleSelector",
321 src = cms.InputTag(
"pat" + patLabel),
322 cut = cms.string(cut))
323 counter = cms.EDFilter(
"PATCandViewCountFilter",
324 minNumber = cms.uint32(0),
325 maxNumber = cms.uint32(999999),
326 src = cms.InputTag(
"pat" + patLabel))
328 setattr(process,
"pat" + patLabel, producer)
329 setattr(process,
"selectedPat" + patLabel, filter)
330 setattr(process,
"countPat" + patLabel, counter)
333 applyPostfix(process,
"patCandidateSummary", postfix).candidates.append(cms.InputTag(
'pat' + patLabel))
334 applyPostfix(process,
"selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag(
'selectedPat' + patLabel))
337 def switchToPFMET(process,input=cms.InputTag(
'pfMET'), type1=
False, postfix=
""):
338 print 'MET: using ', input
340 oldMETSource =
applyPostfix(process,
"patMETs",postfix).metSource
341 applyPostfix(process,
"patMETs",postfix).metSource = input
342 applyPostfix(process,
"patMETs",postfix).addMuonCorrections =
False
346 print 'Apply TypeI corrections for MET'
348 jecLabel = getattr(process,
'patJetCorrFactors'+postfix).payload.pythonValue().
replace(
"'",
"")
349 getattr(process,jecLabel+
'Type1CorMet'+postfix).src = input.getModuleLabel()
353 def switchToPFJets(process, input=cms.InputTag(
'pfNoTauClones'), algo=
'AK4', postfix =
"", jetCorrections=(
'AK4PFchs', [
'L1FastJet',
'L2Relative',
'L3Absolute']), type1=
False, outputModules=[
'out']):
355 print "Switching to PFJets, ", algo
356 print "************************ "
357 print "input collection: ", input
360 genJetCollection = cms.InputTag(
'ak4GenJetsNoNu'+postfix)
363 genJetCollection = cms.InputTag(
'ak7GenJetsNoNu'+postfix)
366 print 'bad jet algorithm:', algo,
'! for now, only AK4 and AK7 are allowed. If you need other algorithms, please contact Colin'
370 from CommonTools.ParticleFlow.Tools.jetTools
import jetAlgo
371 inputCollection = getattr(process,
"pfJets"+postfix).src
372 setattr(process,
"pfJets"+postfix,
jetAlgo(algo))
373 getattr(process,
"pfJets"+postfix).src = inputCollection
374 inputJetCorrLabel=jetCorrections
376 switchJetCollection(process,
380 genJetCollection=genJetCollection,
382 jetTrackAssociation=
True,
383 jetCorrections=inputJetCorrLabel,
384 outputModules = outputModules,
388 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
False
389 for corr
in inputJetCorrLabel[1]:
390 if corr ==
'L1FastJet':
391 applyPostfix(process,
"patJetCorrFactors", postfix).useRho =
True
392 applyPostfix(process,
"pfJets", postfix).doAreaFastjet =
True
396 for mod
in process.producerNames().
split(
' '):
398 if mod.startswith(
"kt6")
and mod.endswith(
"Jets"+postfix)
and not 'GenJets' in mod:
399 prefix = mod.replace(postfix,
'')
400 prefix = prefix.replace(
'kt6PFJets',
'')
401 prefix = prefix.replace(
'kt6CaloJets',
'')
402 prefix = getattr(process,
'patJetCorrFactors'+prefix+postfix).payload.pythonValue().
replace(
"'",
"")
403 for essource
in process.es_sources_().
keys():
404 if essource == prefix+
'L1FastJet':
405 setattr(process,essource+postfix,getattr(process,essource).
clone(srcRho=cms.InputTag(mod,
'rho')))
406 setattr(process,prefix+
'CombinedCorrector'+postfix,getattr(process,prefix+
'CombinedCorrector').
clone())
407 getattr(process,prefix+
'CorMet'+postfix).corrector = prefix+
'CombinedCorrector'+postfix
408 for cor
in getattr(process,prefix+
'CombinedCorrector'+postfix).correctors:
410 idx = getattr(process,prefix+
'CombinedCorrector'+postfix).correctors.index(essource);
411 getattr(process,prefix+
'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
413 if hasattr( getattr( process,
"patJets" + postfix),
'embedCaloTowers' ):
414 applyPostfix(process,
"patJets", postfix).embedCaloTowers =
False
415 applyPostfix(process,
"patJets", postfix).embedPFCandidates =
True
422 removeMCMatching(process, names=[
'All'], postfix=postfix, outputModules=outputModules)
425 def adaptPVs(process, pvCollection=cms.InputTag(
'offlinePrimaryVertices'), postfix=
''):
426 print "Switching PV collection for PF2PAT:", pvCollection
427 print "***********************************"
430 pvExchange = [
'Vertices',
'vertices',
'pvSrc',
'primaryVertices',
'srcPVs',
'primaryVertex']
435 for m
in (process.producerNames().
split(
' ') + process.filterNames().
split(
' ')):
437 for namePvSrc
in pvExchange:
438 if hasattr(getattr(process,m),namePvSrc):
440 setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
443 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']):
447 if typeIMetCorrections:
448 jetCorrections = (jetCorrections[0],jetCorrections[1],
'Type-1')
449 """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
454 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
457 loadWithPostfix(process,
'PhysicsTools.PatAlgos.patSequences_cff',postfix)
482 switchToPFJets( process, cms.InputTag(
'pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
483 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
486 if not 'L2L3Residual' in jetCorrections[1]:
488 print '#################################################'
489 print 'WARNING! Not using L2L3Residual but this is data.'
490 print 'If this is okay with you, disregard this message.'
491 print '#################################################'
492 switchToPFJets( process, cms.InputTag(
'pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
493 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
497 adaptPFTaus( process, tauType=
'hpsPFTau', postfix=postfix )
499 switchToPFMET(process, cms.InputTag(
'pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
502 addPFCandidates(process,cms.InputTag(
'pfNoJetClones'+postfix),patLabel=
'PFParticles'+postfix,cut=
"",postfix=postfix)
505 adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
508 runOnData(process,postfix=postfix,outputModules=outputModules)
511 getattr(process,
"pfNoPileUpJME"+postfix).enable =
True
512 getattr(process,
"pfNoMuonJME"+postfix).enable =
True
513 getattr(process,
"pfNoElectronJME"+postfix).enable =
True
514 getattr(process,
"pfNoTau"+postfix).enable =
False
515 getattr(process,
"pfNoJet"+postfix).enable =
True
517 for object
in excludeFromTopProjection:
519 if object
in [
'Muon',
'Electron']:
521 getattr(process,
"pfNo"+object+jme+postfix).enable =
False
522 exclusionList=exclusionList+object+
','
523 exclusionList=exclusionList.rstrip(
',')
524 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"))