00001 import FWCore.ParameterSet.Config as cms
00002
00003 from PhysicsTools.PatAlgos.tools.coreTools import *
00004 from PhysicsTools.PatAlgos.tools.jetTools import *
00005 from PhysicsTools.PatAlgos.tools.tauTools import *
00006
00007 from PhysicsTools.PatAlgos.tools.helpers import listModules, applyPostfix
00008
00009 from copy import deepcopy
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 def warningIsolation():
00030 print "WARNING: particle based isolation must be studied"
00031
00032 from CommonTools.ParticleFlow.Tools.pfIsolation import setupPFElectronIso, setupPFMuonIso
00033
00034 def useGsfElectrons(process, postfix, dR = "04"):
00035 print "using Gsf Electrons in PF2PAT"
00036 print "WARNING: this will destory the feature of top projection which solves the ambiguity between leptons and jets because"
00037 print "WARNING: there will be overlap between non-PF electrons and jets even though top projection is ON!"
00038 print "********************* "
00039 module = applyPostfix(process,"patElectrons",postfix)
00040 module.useParticleFlow = False
00041 print "Building particle-based isolation for GsfElectrons in PF2PAT(PFBRECO)"
00042 print "********************* "
00043 adaptPFIsoElectrons( process, module, postfix+"PFIso", dR )
00044 getattr(process,'patDefaultSequence'+postfix).replace( getattr(process,"patElectrons"+postfix),
00045 setupPFElectronIso(process, 'gsfElectrons', "PFIso", postfix, runPF2PAT=True) +
00046 getattr(process,"patElectrons"+postfix) )
00047
00048 def adaptPFIsoElectrons(process,module, postfix = "PFIso", dR = "04"):
00049
00050 module.isoDeposits = cms.PSet(
00051 pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
00052 pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
00053 pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
00054 pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
00055 pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
00056 )
00057 module.isolationValues = cms.PSet(
00058 pfChargedHadrons = cms.InputTag("elPFIsoValueCharged"+dR+"PFId"+ postfix),
00059 pfChargedAll = cms.InputTag("elPFIsoValueChargedAll"+dR+"PFId"+ postfix),
00060 pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU"+dR+"PFId" + postfix),
00061 pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral"+dR+"PFId" + postfix),
00062 pfPhotons = cms.InputTag("elPFIsoValueGamma"+dR+"PFId" + postfix)
00063 )
00064 module.isolationValuesNoPFId = cms.PSet(
00065 pfChargedHadrons = cms.InputTag("elPFIsoValueCharged"+dR+"NoPFId"+ postfix),
00066 pfChargedAll = cms.InputTag("elPFIsoValueChargedAll"+dR+"NoPFId"+ postfix),
00067 pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU"+dR+"NoPFId" + postfix),
00068 pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral"+dR+"NoPFId" + postfix),
00069 pfPhotons = cms.InputTag("elPFIsoValueGamma"+dR+"NoPFId" + postfix)
00070 )
00071
00072 def adaptPFIsoMuons(process,module, postfix = "PFIso", dR = "04"):
00073
00074 module.isoDeposits = cms.PSet(
00075 pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
00076 pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
00077 pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
00078 pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
00079 pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
00080 )
00081 module.isolationValues = cms.PSet(
00082 pfChargedHadrons = cms.InputTag("muPFIsoValueCharged" + dR + postfix),
00083 pfChargedAll = cms.InputTag("muPFIsoValueChargedAll" + dR + postfix),
00084 pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU" + dR + postfix),
00085 pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral" + dR + postfix),
00086 pfPhotons = cms.InputTag("muPFIsoValueGamma" + dR + postfix)
00087 )
00088
00089 def usePFIso(process, postfix = "PFIso"):
00090 print "Building particle-based isolation "
00091 print "***************** "
00092 process.eleIsoSequence = setupPFElectronIso(process, 'gsfElectrons', postfix)
00093 process.muIsoSequence = setupPFMuonIso(process, 'muons', postfix)
00094 adaptPFIsoMuons( process, applyPostfix(process,"patMuons",""), postfix)
00095 adaptPFIsoElectrons( process, applyPostfix(process,"patElectrons",""), postfix)
00096 getattr(process,'patDefaultSequence').replace( getattr(process,"patCandidates"),
00097 process.pfParticleSelectionSequence +
00098 process.eleIsoSequence +
00099 process.muIsoSequence +
00100 getattr(process,"patCandidates") )
00101
00102 def adaptPFMuons(process,module,postfix="" ):
00103 print "Adapting PF Muons "
00104 print "***************** "
00105 warningIsolation()
00106 print
00107 module.useParticleFlow = True
00108 module.pfMuonSource = cms.InputTag("pfIsolatedMuonsClones" + postfix)
00109 module.userIsolation = cms.PSet()
00110 module.isoDeposits = cms.PSet(
00111 pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
00112 pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
00113 pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
00114 pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
00115 pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
00116 )
00117 module.isolationValues = cms.PSet(
00118 pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
00119 pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
00120 pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
00121 pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
00122 pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
00123 )
00124
00125 applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
00126
00127 print " muon source:", module.pfMuonSource
00128 print " isolation :",
00129 print module.isolationValues
00130 print " isodeposits: "
00131 print module.isoDeposits
00132 print
00133
00134
00135 def adaptPFElectrons(process,module, postfix):
00136
00137 print "Adapting PF Electrons "
00138 print "********************* "
00139 warningIsolation()
00140 print
00141 module.useParticleFlow = True
00142 module.pfElectronSource = cms.InputTag("pfIsolatedElectronsClones" + postfix)
00143 module.userIsolation = cms.PSet()
00144 module.isoDeposits = cms.PSet(
00145 pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
00146 pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
00147 pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
00148 pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
00149 pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
00150 )
00151 module.isolationValues = cms.PSet(
00152 pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
00153 pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
00154 pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
00155 pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
00156 pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
00157 )
00158
00159
00160
00161
00162
00163
00164
00165 print " PF electron source:", module.pfElectronSource
00166 print " isolation :"
00167 print module.isolationValues
00168 print " isodeposits: "
00169 print module.isoDeposits
00170 print
00171
00172 print "removing traditional isolation"
00173
00174 removeIfInSequence(process, "patElectronIsolation", "patDefaultSequence", postfix)
00175
00176 def adaptPFPhotons(process,module):
00177 raise RuntimeError, "Photons are not supported yet"
00178
00179 from RecoTauTag.RecoTau.TauDiscriminatorTools import adaptTauDiscriminator, producerIsTauTypeMapper
00180
00181 def reconfigurePF2PATTaus(process,
00182 tauType='shrinkingConePFTau',
00183 pf2patSelection=["DiscriminationByIsolation", "DiscriminationByLeadingPionPtCut"],
00184 selectionDependsOn=["DiscriminationByLeadingTrackFinding"],
00185 producerFromType=lambda producer: producer+"Producer",
00186 postfix = ""):
00187 print "patTaus will be produced from taus of type: %s that pass %s" \
00188 % (tauType, pf2patSelection)
00189
00190
00191 baseSequence = getattr(process,"pfTausBaseSequence"+postfix)
00192
00193 for oldBaseModuleName in baseSequence.moduleNames():
00194 oldBaseModule = getattr(process,oldBaseModuleName)
00195 baseSequence.remove(oldBaseModule)
00196
00197
00198 producerName = producerFromType(tauType)
00199
00200 applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
00201
00202 oldTauSansRefs = getattr(process,'pfTausProducerSansRefs'+postfix)
00203 oldTau = getattr(process,'pfTausProducer'+postfix)
00204
00205 newTauSansRefs = None
00206 newTau = getattr(process,producerName).clone()
00207
00208 if tauType=='shrinkingConePFTau':
00209 newTauSansRefs = getattr(process,producerName+"SansRefs").clone()
00210 newTauSansRefs.modifiers[1] = cms.PSet(
00211 pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
00212 name = cms.string('pfTauTTIworkaround'+postfix),
00213 plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
00214 )
00215 newTau.modifiers[1] = newTauSansRefs.modifiers[1]
00216 newTauSansRefs.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
00217 newTau.piZeroSrc = newTauSansRefs.piZeroSrc
00218 newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
00219 newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
00220 newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
00221 elif tauType=='fixedConePFTau':
00222 newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
00223 elif tauType=='hpsPFTau':
00224 newTau = process.combinatoricRecoTaus.clone()
00225 newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
00226 newTau.modifiers[3] = cms.PSet(
00227 pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
00228 name = cms.string('pfTauTTIworkaround'+postfix),
00229 plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
00230 )
00231 from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00232 cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix)
00233 massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
00234 "PFTauProducer",
00235 cms.InputTag("combinatoricRecoTaus"),
00236 cms.InputTag("pfTausBase"+postfix) )
00237 massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
00238 "src",
00239 cms.InputTag("combinatoricRecoTaus"),
00240 cms.InputTag("pfTausBase"+postfix) )
00241
00242 newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
00243 newTau.jetRegionSrc = oldTau.jetRegionSrc
00244 newTau.jetSrc = oldTau.jetSrc
00245
00246
00247 setattr(process,"pfTausBase"+postfix,newTau)
00248 if tauType=='shrinkingConePFTau':
00249 setattr(process,"pfTausBaseSansRefs"+postfix,newTauSansRefs)
00250 getattr(process,"pfTausBase"+postfix).src = "pfTausBaseSansRefs"+postfix
00251 baseSequence += getattr(process,"pfTausBaseSansRefs"+postfix)
00252 baseSequence += getattr(process,"pfTausBase"+postfix)
00253 if tauType=='hpsPFTau':
00254 baseSequence += getattr(process,"produceHPSPFTaus"+postfix)
00255
00256 def producerIsTauTypeMapperWithPostfix(tauProducer):
00257 return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
00258
00259 def recoTauTypeMapperWithGroup(tauProducer):
00260 return "%s(.*)"%recoTauTypeMapper(tauProducer)
00261
00262
00263 for predisc in selectionDependsOn:
00264
00265 originalName = tauType+predisc
00266 clonedName = "pfTausBase"+predisc+postfix
00267 clonedDisc = getattr(process, originalName).clone()
00268
00269 setattr(process, clonedName, clonedDisc)
00270 baseSequence += getattr(process, clonedName)
00271
00272 tauCollectionToSelect = None
00273 if tauType != 'hpsPFTau' :
00274 tauCollectionToSelect = "pfTausBase"+postfix
00275
00276 else:
00277 tauCollectionToSelect = "hpsPFTauProducer"+postfix
00278
00279 adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
00280 oldTauTypeMapper=recoTauTypeMapperWithGroup,
00281 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
00282 preservePFTauProducer=True)
00283 clonedDisc.PFTauProducer = tauCollectionToSelect
00284
00285
00286 applyPostfix(process,"pfTaus", postfix).discriminators = cms.VPSet()
00287 for selection in pf2patSelection:
00288
00289 originalName = tauType+selection
00290 clonedName = "pfTausBase"+selection+postfix
00291 clonedDisc = getattr(process, originalName).clone()
00292
00293 setattr(process, clonedName, clonedDisc)
00294
00295 tauCollectionToSelect = None
00296
00297 if tauType != 'hpsPFTau' :
00298 tauCollectionToSelect = cms.InputTag("pfTausBase"+postfix)
00299
00300 else:
00301 tauCollectionToSelect = cms.InputTag("hpsPFTauProducer"+postfix)
00302
00303 adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
00304 oldTauTypeMapper=recoTauTypeMapperWithGroup,
00305 newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
00306 preservePFTauProducer=True)
00307 clonedDisc.PFTauProducer = tauCollectionToSelect
00308 baseSequence += clonedDisc
00309
00310 applyPostfix(process,"pfTaus", postfix).discriminators.append(cms.PSet(
00311 discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
00312
00313 if tauType != 'hpsPFTau':
00314 applyPostfix(process,"pfTaus", postfix).src = "pfTausBase"+postfix
00315 else:
00316
00317
00318 applyPostfix(process,"pfTaus", postfix).src = "hpsPFTauProducer"+postfix
00319
00320
00321
00322 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
00323
00324 if tauType != 'hpsPFTau' :
00325 reconfigurePF2PATTaus(process, tauType, postfix=postfix)
00326 else:
00327 reconfigurePF2PATTaus(process, tauType,
00328 ["DiscriminationByLooseCombinedIsolationDBSumPtCorr"],
00329 ["DiscriminationByDecayModeFinding"],
00330 postfix=postfix)
00331
00332 if tauType != 'hpsPFTau' :
00333 applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
00334 else:
00335 applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
00336
00337
00338
00339
00340 redoPFTauDiscriminators(process,
00341 cms.InputTag(tauType+'Producer'),
00342 applyPostfix(process,"patTaus", postfix).tauSource,
00343 tauType, postfix=postfix)
00344
00345 switchToPFTauByType(process, pfTauType=tauType,
00346 pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource,
00347 pfTauLabelOld=cms.InputTag(tauType+'Producer'),
00348 postfix=postfix)
00349
00350 applyPostfix(process,"makePatTaus", postfix).remove(
00351 applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix)
00352 )
00353
00354
00355 def tauTypeInPF2PAT(process,tauType='shrinkingConePFTau', postfix = ""):
00356 process.load("CommonTools.ParticleFlow.pfTaus_cff")
00357 applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
00358
00359
00360 def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""):
00361 from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
00362
00363 producer = patPFParticles.clone(pfCandidateSource = src)
00364 filter = cms.EDFilter("PATPFParticleSelector",
00365 src = cms.InputTag("pat" + patLabel),
00366 cut = cms.string(cut))
00367 counter = cms.EDFilter("PATCandViewCountFilter",
00368 minNumber = cms.uint32(0),
00369 maxNumber = cms.uint32(999999),
00370 src = cms.InputTag("pat" + patLabel))
00371
00372 setattr(process, "pat" + patLabel, producer)
00373 setattr(process, "selectedPat" + patLabel, filter)
00374 setattr(process, "countPat" + patLabel, counter)
00375
00376 getattr(process, "patDefaultSequence"+postfix).replace(
00377 applyPostfix(process, "patCandidateSummary", postfix),
00378 producer+applyPostfix(process, "patCandidateSummary", postfix)
00379 )
00380 getattr(process, "patDefaultSequence"+postfix).replace(
00381 applyPostfix(process, "selectedPatCandidateSummary", postfix),
00382 filter+applyPostfix(process, "selectedPatCandidateSummary", postfix)
00383 )
00384 index = len( applyPostfix( process, "patDefaultSequence", postfix ).moduleNames() )
00385 applyPostfix( process, "patDefaultSequence", postfix ).insert( index, counter )
00386
00387 applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
00388 applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
00389
00390
00391 def switchToPFMET(process,input=cms.InputTag('pfMET'), type1=False, postfix=""):
00392 print 'MET: using ', input
00393 if( not type1 ):
00394 oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
00395 applyPostfix(process, "patMETs",postfix).metSource = input
00396 applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
00397 getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
00398 else:
00399
00400
00401 print 'Apply TypeI corrections for MET'
00402 getattr(process, "patDefaultSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
00403 jecLabel = getattr(process,'patJetCorrFactors'+postfix).payload.pythonValue().replace("'","")
00404 getattr(process,jecLabel+'CorMet'+postfix).inputUncorMetLabel = input.getModuleLabel()
00405 getattr(process,'patMETs'+postfix).metSource = jecLabel+'CorMet'+postfix
00406 getattr(process,'patMETs'+postfix).addMuonCorrections = False
00407
00408 def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK5', postfix = "", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out']):
00409
00410 print "Switching to PFJets, ", algo
00411 print "************************ "
00412 print "input collection: ", input
00413
00414 if( algo == 'IC5' ):
00415 genJetCollection = cms.InputTag('iterativeCone5GenJetsNoNu')
00416 elif algo == 'AK5':
00417 genJetCollection = cms.InputTag('ak5GenJetsNoNu')
00418 elif algo == 'AK7':
00419 genJetCollection = cms.InputTag('ak7GenJetsNoNu')
00420 else:
00421 print 'bad jet algorithm:', algo, '! for now, only IC5, AK5 and AK7 are allowed. If you need other algorithms, please contact Colin'
00422 sys.exit(1)
00423
00424
00425 from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
00426 inputCollection = getattr(process,"pfJets"+postfix).src
00427 setattr(process,"pfJets"+postfix,jetAlgo(algo))
00428 getattr(process,"pfJets"+postfix).src = inputCollection
00429 inputJetCorrLabel=jetCorrections
00430 switchJetCollection(process,
00431 input,
00432 jetIdLabel = algo,
00433 doJTA=True,
00434 doBTagging=True,
00435 jetCorrLabel=inputJetCorrLabel,
00436 doType1MET=type1,
00437 genJetCollection = genJetCollection,
00438 doJetID = True,
00439 postfix = postfix,
00440 outputModules = outputModules
00441 )
00442
00443 applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
00444 for corr in inputJetCorrLabel[1]:
00445 if corr == 'L1FastJet':
00446 applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
00447 applyPostfix(process, "pfJets", postfix).doAreaFastjet = True
00448
00449 if type1:
00450 for mod in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00451 if mod.startswith("kt6"):
00452 prefix = mod.replace(postfix,'')
00453 prefix = prefix.replace('kt6PFJets','')
00454 prefix = prefix.replace('kt6CaloJets','')
00455 prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
00456 for essource in process.es_sources_().keys():
00457 if essource == prefix+'L1FastJet':
00458 setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
00459 setattr(process,prefix+'CombinedCorrector'+postfix,getattr(process,prefix+'CombinedCorrector').clone())
00460 getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
00461 for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
00462 if cor == essource:
00463 idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
00464 getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
00465
00466 if hasattr( getattr( process, "patJets" + postfix), 'embedCaloTowers' ):
00467 applyPostfix(process, "patJets", postfix).embedCaloTowers = False
00468 applyPostfix(process, "patJets", postfix).embedPFCandidates = True
00469
00470
00471 def removeMCMatchingPF2PAT( process, postfix="", outputModules=['out'] ):
00472 from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
00473 removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
00474 removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
00475
00476
00477 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix=''):
00478
00479 print "Switching PV collection for PF2PAT:", pvCollection
00480 print "***********************************"
00481
00482
00483 pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs']
00484
00485
00486
00487
00488 interPostfixes = []
00489 for m in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00490 if m.startswith('patJets') and m.endswith(postfix) and not len(m)==len('patJets')+len(postfix):
00491 interPostfix = m.replace('patJets','')
00492 interPostfix = interPostfix.replace(postfix,'')
00493 interPostfixes.append(interPostfix)
00494
00495
00496 for m in getattr(process,'patPF2PATSequence'+postfix).moduleNames():
00497 modName = m.replace(postfix,'')
00498
00499 for namePvSrc in pvExchange:
00500 if hasattr(getattr(process,m),namePvSrc):
00501
00502 interPostFixFlag = False
00503 for pfix in interPostfixes:
00504 if modName.endswith(pfix):
00505 interPostFixFlag = True
00506 break
00507 if not interPostFixFlag:
00508 setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
00509
00510
00511 def usePF2PAT(process, runPF2PAT=True, jetAlgo='AK5', runOnMC=True, postfix="", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative','L3Absolute']), pvCollection=cms.InputTag('offlinePrimaryVertices'), typeIMetCorrections=False, outputModules=['out']):
00512
00513
00514
00515 """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
00516
00517
00518 if runPF2PAT:
00519 process.load("CommonTools.ParticleFlow.PF2PAT_cff")
00520
00521
00522
00523 process.patPFClones = cms.Sequence(process.pfNoJetClones+process.pfNoTauClones)
00524 process.patPF2PATSequence = cms.Sequence( process.PF2PAT + process.patPFClones + process.patDefaultSequence)
00525 else:
00526 process.patPF2PATSequence = cms.Sequence( process.patDefaultSequence )
00527
00528 if not postfix == "":
00529 from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
00530 cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)
00531
00532
00533
00534
00535
00536
00537
00538
00539 removeCleaning(process, postfix=postfix, outputModules=outputModules)
00540
00541
00542
00543 adaptPFMuons(process,
00544 applyPostfix(process,"patMuons",postfix),
00545 postfix)
00546
00547
00548 adaptPFElectrons(process,
00549 applyPostfix(process,"patElectrons",postfix),
00550 postfix)
00551
00552
00553 print "Temporarily switching off photons completely"
00554
00555 removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
00556 removeIfInSequence(process,"patPhotonIsolation","patDefaultSequence",postfix)
00557
00558
00559 if runOnMC :
00560 switchToPFJets( process, cms.InputTag('pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
00561 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
00562 applyPostfix(process,"patDefaultSequence",postfix).replace(
00563 applyPostfix(process,"patJetGenJetMatch",postfix),
00564 getattr(process,"genForPF2PATSequence") *
00565 applyPostfix(process,"patJetGenJetMatch",postfix)
00566 )
00567 else :
00568 if not 'L2L3Residual' in jetCorrections[1]:
00569 print '#################################################'
00570 print 'WARNING! Not using L2L3Residual but this is data.'
00571 print 'If this is okay with you, disregard this message.'
00572 print '#################################################'
00573 switchToPFJets( process, cms.InputTag('pfNoTauClones'+postfix), jetAlgo, postfix=postfix,
00574 jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
00575
00576
00577
00578
00579 adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
00580
00581
00582 switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
00583
00584
00585 addPFCandidates(process,cms.InputTag('pfNoJetClones'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
00586
00587
00588 adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
00589
00590 if runOnMC:
00591 process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
00592 getattr(process, "patDefaultSequence"+postfix).replace(
00593 applyPostfix(process,"patCandidates",postfix),
00594 process.genForPF2PATSequence+applyPostfix(process,"patCandidates",postfix)
00595 )
00596 else:
00597 removeMCMatchingPF2PAT(process,postfix=postfix,outputModules=outputModules)
00598
00599 print "Done: PF2PAT interfaced to PAT, postfix=", postfix