Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:02

0001 from __future__ import print_function
0002 import FWCore.ParameterSet.Config as cms
0003 
0004 from PhysicsTools.PatAlgos.tools.coreTools import *
0005 from PhysicsTools.PatAlgos.tools.jetTools import *
0006 from PhysicsTools.PatAlgos.tools.tauTools import *
0007 
0008 from PhysicsTools.PatAlgos.tools.helpers import listModules, applyPostfix, getPatAlgosToolsTask, addToProcessAndTask
0009 
0010 from copy import deepcopy
0011 
0012 def warningIsolation():
0013     print("WARNING: particle based isolation must be studied")
0014 
0015 def adaptPFMuons(process,module,postfix="", muonMatchModule=None ):
0016     print("Adapting PF Muons ")
0017     print("***************** ")
0018     #warningIsolation()
0019     print()
0020     module.useParticleFlow = True
0021     module.pfMuonSource    = cms.InputTag("pfIsolatedMuonsPFBRECO" + postfix)
0022     module.userIsolation   = cms.PSet()
0023     ## module.isoDeposits = cms.PSet(
0024     ##     pfChargedHadrons = cms.InputTag("muPFIsoDepositCharged" + postfix),
0025     ##     pfChargedAll = cms.InputTag("muPFIsoDepositChargedAll" + postfix),
0026     ##     pfPUChargedHadrons = cms.InputTag("muPFIsoDepositPU" + postfix),
0027     ##     pfNeutralHadrons = cms.InputTag("muPFIsoDepositNeutral" + postfix),
0028     ##     pfPhotons = cms.InputTag("muPFIsoDepositGamma" + postfix)
0029     ##     )
0030     ## module.isolationValues = cms.PSet(
0031     ##     pfChargedHadrons = cms.InputTag("muPFIsoValueCharged04"+ postfix),
0032     ##     pfChargedAll = cms.InputTag("muPFIsoValueChargedAll04"+ postfix),
0033     ##     pfPUChargedHadrons = cms.InputTag("muPFIsoValuePU04" + postfix),
0034     ##     pfNeutralHadrons = cms.InputTag("muPFIsoValueNeutral04" + postfix),
0035     ##     pfPhotons = cms.InputTag("muPFIsoValueGamma04" + postfix)
0036     ##     )
0037     # matching the pfMuons, not the standard muons.
0038     if muonMatchModule == None :
0039         applyPostfix(process,"muonMatch",postfix).src = module.pfMuonSource
0040     else :
0041         muonMatchModule.src = module.pfMuonSource
0042 
0043     print(" muon source:", module.pfMuonSource)
0044     ## print " isolation  :",
0045     ## print module.isolationValues
0046     ## print " isodeposits: "
0047     ## print module.isoDeposits
0048     print()
0049 
0050 
0051 def adaptPFElectrons(process,module, postfix):
0052     # module.useParticleFlow = True
0053     print("Adapting PF Electrons ")
0054     print("********************* ")
0055     #warningIsolation()
0056     print()
0057     module.useParticleFlow = True
0058     module.pfElectronSource = cms.InputTag("pfIsolatedElectronsPFBRECO" + postfix)
0059     module.userIsolation   = cms.PSet()
0060     ## module.isoDeposits = cms.PSet(
0061     ##     pfChargedHadrons = cms.InputTag("elPFIsoDepositCharged" + postfix),
0062     ##     pfChargedAll = cms.InputTag("elPFIsoDepositChargedAll" + postfix),
0063     ##     pfPUChargedHadrons = cms.InputTag("elPFIsoDepositPU" + postfix),
0064     ##     pfNeutralHadrons = cms.InputTag("elPFIsoDepositNeutral" + postfix),
0065     ##     pfPhotons = cms.InputTag("elPFIsoDepositGamma" + postfix)
0066     ##     )
0067     ## module.isolationValues = cms.PSet(
0068     ##     pfChargedHadrons = cms.InputTag("elPFIsoValueCharged04PFId"+ postfix),
0069     ##     pfChargedAll = cms.InputTag("elPFIsoValueChargedAll04PFId"+ postfix),
0070     ##     pfPUChargedHadrons = cms.InputTag("elPFIsoValuePU04PFId" + postfix),
0071     ##     pfNeutralHadrons = cms.InputTag("elPFIsoValueNeutral04PFId" + postfix),
0072     ##     pfPhotons = cms.InputTag("elPFIsoValueGamma04PFId" + postfix)
0073     ##     )
0074 
0075     # COLIN: since we take the egamma momentum for pat Electrons, we must
0076     # match the egamma electron to the gen electrons, and not the PFElectron.
0077     # -> do not uncomment the line below.
0078     # process.electronMatch.src = module.pfElectronSource
0079     # COLIN: how do we depend on this matching choice?
0080 
0081     print(" PF electron source:", module.pfElectronSource)
0082     ## print " isolation  :"
0083     ## print module.isolationValues
0084     ## print " isodeposits: "
0085     ## print module.isoDeposits
0086     print()
0087 
0088 
0089 
0090 
0091 def adaptPFPhotons(process,module):
0092     raise RuntimeError("Photons are not supported yet")
0093 
0094 from RecoTauTag.RecoTau.TauDiscriminatorTools import adaptTauDiscriminator, producerIsTauTypeMapper
0095 
0096 def reconfigurePF2PATTaus(process,
0097       tauType='shrinkingConePFTau',
0098       pf2patSelection=["DiscriminationByIsolation", "DiscriminationByLeadingPionPtCut"],
0099       selectionDependsOn=["DiscriminationByLeadingTrackFinding"],
0100       producerFromType=lambda producer: producer+"Producer",
0101       postfix = ""):
0102     print("patTaus will be produced from taus of type: %s that pass %s" \
0103           % (tauType, pf2patSelection))
0104 
0105 
0106 
0107     # Get the prototype of tau producer to make, i.e. fixedConePFTauProducer
0108     producerName = producerFromType(tauType)
0109     # Set as the source for the pf2pat taus (pfTaus) selector
0110     applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
0111     # Start our pf2pat taus base sequence
0112     oldTauSansRefs = getattr(process,'pfTausProducerSansRefs'+postfix)
0113     oldTau = getattr(process,'pfTausProducer'+postfix)
0114     ## copy tau and setup it properly
0115     newTauSansRefs = None
0116     newTau = getattr(process,producerName+postfix).clone()
0117 
0118     ## adapted to new structure in RecoTauProducers PLEASE CHECK!!!
0119     if tauType=='shrinkingConePFTau':
0120         newTauSansRefs = getattr(process,producerName+"SansRefs").clone()
0121         newTauSansRefs.modifiers[1] = cms.PSet(
0122             pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
0123             name = cms.string('pfTauTTIworkaround'+postfix),
0124             plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
0125             )
0126         newTau.modifiers[1] = newTauSansRefs.modifiers[1]
0127         newTauSansRefs.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
0128         newTau.piZeroSrc = newTauSansRefs.piZeroSrc
0129         newTauSansRefs.builders[0].pfCandSrc = oldTauSansRefs.builders[0].pfCandSrc
0130         newTauSansRefs.jetRegionSrc = oldTauSansRefs.jetRegionSrc
0131         newTauSansRefs.jetSrc = oldTauSansRefs.jetSrc
0132     elif tauType=='fixedConePFTau':
0133         newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
0134     elif tauType=='hpsPFTau':
0135         newTau = getattr(process,'combinatoricRecoTaus'+postfix).clone()
0136         newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
0137         newTau.modifiers[3] = cms.PSet(
0138             pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
0139             name = cms.string('pfTauTTIworkaround'+postfix),
0140             plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
0141             )
0142         from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
0143         #cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix, addToTask = True)
0144         setattr(process,'produceHPSPFTaus'+postfix,cms.Sequence(applyPostfix(process,'hpsSelectionDiscriminator',postfix)+applyPostfix(process,'hpsPFTauProducerSansRefs',postfix)+applyPostfix(process,'hpsPFTauProducer',postfix)))
0145         massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
0146                                "PFTauProducer",
0147                                cms.InputTag("combinatoricRecoTaus"+postfix),
0148                                cms.InputTag("pfTausBase"+postfix) )
0149         massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
0150                                "src",
0151                                cms.InputTag("combinatoricRecoTaus"+postfix),
0152                                cms.InputTag("pfTausBase"+postfix) )
0153     ### Next three lines crash, oldTau does not have any of these attributes. Why?###
0154     #newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
0155     #newTau.jetRegionSrc = oldTau.jetRegionSrc
0156     #newTau.jetSrc = oldTau.jetSrc
0157     #newTau.builders[0].pfCandSrc = cms.InputTag("pfNoElectronJME" + postfix)
0158     #newTau.jetRegionSrc = cms.InputTag("pfTauPFJets08Region" + postfix)
0159     #newTau.jetSrc = cms.InputTag("pfJetsPFBRECO" + postfix)
0160     # replace old tau producer by new one put it into baseSequence
0161     task = getPatAlgosToolsTask(process)
0162     addToProcessAndTask("pfTausBase"+postfix, newTau, process, task)
0163     if tauType=='shrinkingConePFTau':
0164         addToProcessAndTask("pfTausBaseSansRefs"+postfix, newTauSansRefs, process, task)
0165         getattr(process,"pfTausBase"+postfix).src = "pfTausBaseSansRefs"+postfix
0166         baseSequence += getattr(process,"pfTausBaseSansRefs"+postfix)
0167 
0168     #make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
0169     def producerIsTauTypeMapperWithPostfix(tauProducer):
0170         return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
0171 
0172     def recoTauTypeMapperWithGroup(tauProducer):
0173         return "%s(.*)"%recoTauTypeMapper(tauProducer)
0174 
0175     # Get our prediscriminants
0176     for predisc in selectionDependsOn:
0177         # Get the prototype
0178         originalName = tauType+predisc # i.e. fixedConePFTauProducerDiscriminationByLeadingTrackFinding
0179         clonedName = "pfTausBase"+predisc+postfix
0180         clonedDisc = getattr(process, originalName).clone()
0181         addToProcessAndTask(clonedName, clonedDisc, process, task)
0182 
0183         tauCollectionToSelect = None
0184         if tauType != 'hpsPFTau' :
0185             tauCollectionToSelect = "pfTausBase"+postfix
0186             #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
0187         else:
0188             tauCollectionToSelect = "hpsPFTauProducer"+postfix
0189         # Adapt this discriminator for the cloned prediscriminators
0190         adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
0191                               oldTauTypeMapper=recoTauTypeMapperWithGroup,
0192                               newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
0193                               preservePFTauProducer=True)
0194         clonedDisc.PFTauProducer = tauCollectionToSelect
0195 
0196     # Reconfigure the pf2pat PFTau selector discrimination sources
0197     getattr(process,"pfTaus" + postfix).discriminators = cms.VPSet()
0198     for selection in pf2patSelection:
0199         # Get our discriminator that will be used to select pfTaus
0200         originalName = tauType+selection
0201         clonedName = "pfTausBase"+selection+postfix
0202         clonedDisc = getattr(process, originalName).clone()
0203         addToProcessAndTask(clonedName, clonedDisc, process, task)
0204 
0205         tauCollectionToSelect = None
0206 
0207         if tauType != 'hpsPFTau' :
0208             tauCollectionToSelect = cms.InputTag("pfTausBase"+postfix)
0209             #cms.InputTag(clonedDisc.PFTauProducer.value()+postfix)
0210         else:
0211             tauCollectionToSelect = cms.InputTag("hpsPFTauProducer"+postfix)
0212         #Adapt our cloned discriminator to the new prediscriminants
0213         adaptTauDiscriminator(clonedDisc, newTauProducer="pfTausBase",
0214                               oldTauTypeMapper=recoTauTypeMapperWithGroup,
0215                               newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
0216                               preservePFTauProducer=True)
0217         clonedDisc.PFTauProducer = tauCollectionToSelect
0218 
0219         # Add this selection to our pfTau selectors
0220         getattr(process,"pfTaus" + postfix).discriminators.append(cms.PSet(
0221            discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
0222         # Set the input of the final selector.
0223         if tauType != 'hpsPFTau':
0224             getattr(process,"pfTaus" + postfix).src = "pfTausBase"+postfix
0225         else:
0226             # If we are using HPS taus, we need to take the output of the clenaed
0227             # collection
0228             getattr(process,"pfTaus" + postfix).src = "hpsPFTauProducer"+postfix
0229 
0230 
0231 
0232 def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
0233     # Set up the collection used as a preselection to use this tau type
0234     if tauType != 'hpsPFTau' :
0235         reconfigurePF2PATTaus(process, tauType, postfix=postfix)
0236     else:
0237         reconfigurePF2PATTaus(process, tauType,
0238                               ["DiscriminationByDecayModeFinding"],
0239                               ["DiscriminationByDecayModeFinding"],
0240                               postfix=postfix)
0241     # new default use unselected taus (selected only for jet cleaning)
0242     if tauType != 'hpsPFTau' :
0243         getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
0244     else:
0245         getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
0246     # to use preselected collection (old default) uncomment line below
0247     #applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)
0248 
0249         ### apparently not needed anymore, function gone from tauTools.py###
0250     #redoPFTauDiscriminators(process,
0251                             #cms.InputTag(tauType+'Producer'),
0252                             #applyPostfix(process,"patTaus", postfix).tauSource,
0253                             #tauType, postfix=postfix)
0254 
0255 
0256     if tauType != 'hpsPFTau' :
0257         switchToPFTauByType(process, pfTauType=tauType,
0258                                 patTauLabel="pfTausBase"+postfix,
0259                                 tauSource=cms.InputTag(tauType+'Producer'+postfix),
0260                                 postfix=postfix)
0261         getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
0262     else:
0263         switchToPFTauByType(process, pfTauType=tauType,
0264                                 patTauLabel="",
0265                                 tauSource=cms.InputTag(tauType+'Producer'+postfix),
0266                                 postfix=postfix)
0267         getattr(process,"patTaus" + postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
0268 
0269 
0270 
0271 #helper function for PAT on PF2PAT sample
0272 def tauTypeInPF2PAT(process,tauType='shrinkingConePFTau', postfix = ""):
0273     process.load("CommonTools.ParticleFlow.pfTaus_cff")
0274     applyPostfix(process, "pfTaus",postfix).src = cms.InputTag(tauType+'Producer'+postfix)
0275 
0276 
0277 def addPFCandidates(process,src,patLabel='PFParticles',cut="",postfix=""):
0278     from PhysicsTools.PatAlgos.producersLayer1.pfParticleProducer_cfi import patPFParticles
0279     # make modules
0280     producer = patPFParticles.clone(pfCandidateSource = src)
0281     filter   = cms.EDFilter("PATPFParticleSelector",
0282                     src = cms.InputTag("pat" + patLabel),
0283                     cut = cms.string(cut))
0284     counter  = cms.EDFilter("PATCandViewCountFilter",
0285                     minNumber = cms.uint32(0),
0286                     maxNumber = cms.uint32(999999),
0287                     src       = cms.InputTag("pat" + patLabel))
0288     # add modules to process
0289     task = getPatAlgosToolsTask(process)
0290     addToProcessAndTask("pat" + patLabel, producer, process, task)
0291     addToProcessAndTask("selectedPat" + patLabel, filter, process, task)
0292     addToProcessAndTask("countPat" + patLabel, counter, process, task)
0293 
0294     # summary tables
0295     applyPostfix(process, "patCandidateSummary", postfix).candidates.append(cms.InputTag('pat' + patLabel))
0296     applyPostfix(process, "selectedPatCandidateSummary", postfix).candidates.append(cms.InputTag('selectedPat' + patLabel))
0297 
0298 
0299 def switchToPFMET(process,input=cms.InputTag('pfMETPFBRECO'), type1=False, postfix=""):
0300     print('MET: using ', input)
0301     if( not type1 ):
0302         oldMETSource = applyPostfix(process, "patMETs",postfix).metSource
0303         applyPostfix(process, "patMETs",postfix).metSource = input
0304         applyPostfix(process, "patMETs",postfix).addMuonCorrections = False
0305     else:
0306         # type1 corrected MET
0307         # name of corrected MET hardcoded in PAT and meaningless
0308         print('Apply TypeI corrections for MET')
0309         #getattr(process, "patPF2PATSequence"+postfix).remove(applyPostfix(process, "patMETCorrections",postfix))
0310         jecLabel = getattr(process,'patJetCorrFactors'+postfix).payload.pythonValue().replace("'","")
0311         getattr(process,jecLabel+'Type1CorMet'+postfix).src = input.getModuleLabel()
0312         #getattr(process,'patMETs'+postfix).metSource = jecLabel+'Type1CorMet'+postfix
0313         #getattr(process,'patMETs'+postfix).addMuonCorrections = False
0314 
0315 def switchToPFJets(process, input=cms.InputTag('pfNoTauClones'), algo='AK4', postfix = "", jetCorrections=('AK4PFchs', ['L1FastJet','L2Relative', 'L3Absolute']), type1=False, outputModules=['out']):
0316 
0317     print("Switching to PFJets,  ", algo)
0318     print("************************ ")
0319     print("input collection: ", input)
0320 
0321     if algo == 'AK4':
0322         genJetCollection = cms.InputTag('ak4GenJetsNoNu'+postfix)
0323         rParam=0.4
0324     elif algo == 'AK7':
0325         genJetCollection = cms.InputTag('ak7GenJetsNoNu'+postfix)
0326         rParam=0.7
0327     else:
0328         print('bad jet algorithm:', algo, '! for now, only AK4 and AK7 are allowed. If you need other algorithms, please contact Colin')
0329         sys.exit(1)
0330 
0331     # changing the jet collection in PF2PAT:
0332     from CommonTools.ParticleFlow.Tools.jetTools import jetAlgo
0333     inputCollection = getattr(process,"pfJetsPFBRECO"+postfix).src
0334     setattr(process,"pfJetsPFBRECO"+postfix,jetAlgo(algo)) # problem for cfgBrowser
0335     getattr(process,"pfJetsPFBRECO"+postfix).src = inputCollection
0336     inputJetCorrLabel=jetCorrections
0337 
0338     switchJetCollection(process,
0339                         jetSource = input,
0340                         algo=algo,
0341                         rParam=rParam,
0342                         genJetCollection=genJetCollection,
0343                         postfix=postfix,
0344                         jetTrackAssociation=True,
0345                         jetCorrections=inputJetCorrLabel,
0346                         outputModules = outputModules,
0347                         )
0348 
0349     # check whether L1FastJet is in the list of correction levels or not
0350     applyPostfix(process, "patJetCorrFactors", postfix).useRho = False
0351     task = getPatAlgosToolsTask(process)
0352     for corr in inputJetCorrLabel[1]:
0353         if corr == 'L1FastJet':
0354             applyPostfix(process, "patJetCorrFactors", postfix).useRho = True
0355             applyPostfix(process, "pfJetsPFBRECO", postfix).doAreaFastjet = True
0356             # do correct treatment for TypeI MET corrections
0357             #type1=True
0358             if type1:
0359                 for mod in process.producerNames().split(' '):
0360 
0361                     if mod.startswith("kt6") and mod.endswith("Jets"+postfix) and not 'GenJets' in mod:
0362                         prefix = mod.replace(postfix,'')
0363                         prefix = prefix.replace('kt6PFJets','')
0364                         prefix = prefix.replace('kt6CaloJets','')
0365                         prefix = getattr(process,'patJetCorrFactors'+prefix+postfix).payload.pythonValue().replace("'","")
0366                         for essource in process.es_sources_().keys():
0367                             if essource == prefix+'L1FastJet':
0368                                 setattr(process,essource+postfix,getattr(process,essource).clone(srcRho=cms.InputTag(mod,'rho')))
0369                                 addToProcessAndTask(prefix+'CombinedCorrector'+postfix,
0370                                                     getattr(process,prefix+'CombinedCorrector').clone(), process, task)
0371                                 getattr(process,prefix+'CorMet'+postfix).corrector = prefix+'CombinedCorrector'+postfix
0372                                 for cor in getattr(process,prefix+'CombinedCorrector'+postfix).correctors:
0373                                     if cor == essource:
0374                                         idx = getattr(process,prefix+'CombinedCorrector'+postfix).correctors.index(essource);
0375                                         getattr(process,prefix+'CombinedCorrector'+postfix).correctors[idx] = essource+postfix
0376 
0377     if hasattr( getattr( process, "patJets" + postfix), 'embedCaloTowers' ): # optional parameter, which defaults to 'False' anyway
0378         applyPostfix(process, "patJets", postfix).embedCaloTowers = False
0379     applyPostfix(process, "patJets", postfix).embedPFCandidates = True
0380 
0381 #-- Remove MC dependence ------------------------------------------------------
0382 def removeMCMatchingPF2PAT( process, postfix="", outputModules=['out'] ):
0383     #from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching
0384     ### no longe needed in unscheduled mode###
0385     #removeIfInSequence(process, "genForPF2PATSequence", "patDefaultSequence", postfix)
0386     removeMCMatching(process, names=['All'], postfix=postfix, outputModules=outputModules)
0387 
0388 
0389 def adaptPVs(process, pvCollection=cms.InputTag('offlinePrimaryVertices'), postfix=''):
0390     print("Switching PV collection for PF2PAT:", pvCollection)
0391     print("***********************************")
0392 
0393     # PV sources to be exchanged:
0394     pvExchange = ['Vertices','vertices','pvSrc','primaryVertices','srcPVs','primaryVertex']
0395     # PV sources NOT to be exchanged:
0396     #noPvExchange = ['src','PVProducer','primaryVertexSrc','vertexSrc']
0397 
0398     # exchange the primary vertex source of all relevant modules
0399     for m in (process.producerNames().split(' ') + process.filterNames().split(' ')):
0400         # only if the module has a source with a relevant name
0401         for namePvSrc in pvExchange:
0402             if hasattr(getattr(process,m),namePvSrc):
0403                 #print m
0404                 setattr(getattr(process,m),namePvSrc,deepcopy(pvCollection))
0405 
0406 
0407 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']):
0408     # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
0409     # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
0410 
0411     if typeIMetCorrections:
0412         jetCorrections = (jetCorrections[0],jetCorrections[1],'Type-1')
0413     """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""
0414 
0415     # -------- CORE ---------------
0416     from PhysicsTools.PatAlgos.tools.helpers import loadWithPostfix
0417     patAlgosToolsTask = getPatAlgosToolsTask(process)
0418     taskLabel = patAlgosToolsTask.label()
0419     if runPF2PAT:
0420         loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix, loadedProducersAndFilters=taskLabel)
0421         loadWithPostfix(process,"CommonTools.ParticleFlow.PFBRECO_cff",postfix, loadedProducersAndFilters=taskLabel)
0422     else:
0423         loadWithPostfix(process,'PhysicsTools.PatAlgos.patSequences_cff',postfix, loadedProducersAndFilters=taskLabel)
0424 
0425 
0426 
0427 
0428     # -------- OBJECTS ------------
0429     # Muons
0430 
0431     adaptPFMuons(process,
0432                  applyPostfix(process,"patMuons",postfix),
0433                  postfix)
0434 
0435     # Electrons
0436 
0437     adaptPFElectrons(process,
0438                      applyPostfix(process,"patElectrons",postfix),
0439                      postfix)
0440 
0441     # Photons
0442     #print "Temporarily switching off photons completely"
0443 
0444     #removeSpecificPATObjects(process,names=['Photons'],outputModules=outputModules,postfix=postfix)
0445 
0446     # Jets
0447     if runOnMC :
0448         switchToPFJets( process, cms.InputTag('pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
0449                         jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
0450 
0451     else :
0452         if not 'L2L3Residual' in jetCorrections[1]:
0453                 ### think of a more accurate warning
0454             print('#################################################')
0455             print('WARNING! Not using L2L3Residual but this is data.')
0456             print('If this is okay with you, disregard this message.')
0457             print('#################################################')
0458         switchToPFJets( process, cms.InputTag('pfNoTauClonesPFBRECO'+postfix), jetAlgo, postfix=postfix,
0459                         jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
0460     # Taus
0461     #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
0462     #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
0463     adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )
0464     # MET
0465     switchToPFMET(process, cms.InputTag('pfMETPFBRECO'+postfix), type1=typeIMetCorrections, postfix=postfix)
0466 
0467     # Unmasked PFCandidates
0468     addPFCandidates(process,cms.InputTag('pfNoJetClones'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)
0469 
0470     # adapt primary vertex collection
0471     adaptPVs(process, pvCollection=pvCollection, postfix=postfix)
0472 
0473     if not runOnMC:
0474         runOnData(process,postfix=postfix,outputModules=outputModules)
0475 
0476     # Configure Top Projections
0477     getattr(process,"pfNoPileUpJME"+postfix).enable = True
0478     getattr(process,"pfNoMuonJMEPFBRECO"+postfix).enable = True
0479     getattr(process,"pfNoElectronJMEPFBRECO"+postfix).enable = True
0480     getattr(process,"pfNoTauPFBRECO"+postfix).enable = False
0481     getattr(process,"pfNoJetPFBRECO"+postfix).enable = True
0482     exclusionList = ''
0483     for object in excludeFromTopProjection:
0484         jme = ''
0485         if object in ['Muon','Electron']:
0486             jme = 'JME'
0487         getattr(process,"pfNo"+object+jme+'PFBRECO'+postfix).enable = False
0488         exclusionList=exclusionList+object+','
0489     exclusionList=exclusionList.rstrip(',')
0490     print("Done: PFBRECO interfaced to PAT, postfix=", postfix,", Excluded from Top Projection:",exclusionList)