def addTriggerMatchingForLeptons(process, postfix='') :
    # define the trigger matchers
    process.muTriggerMatchPF = cms.EDProducer( "PATTriggerMatcherDRLessByR",
                                               src     = cms.InputTag( "selectedPatMuons"+postfix ),
                                               matched = cms.InputTag( "patTrigger" ),
                                               matchedCuts = cms.string( 'type( "TriggerMuon" ) && ( path("HLT_Mu8_*") || path("HLT_Mu12_*") || path("HLT_Mu13_Mu8_*") || path("HLT_DoubleMu7_*" || path("HLT_Mu17_Mu8_*)' ), 
                                               maxDPtRel   = cms.double( 0.5 ), # no effect here
                                               maxDeltaR   = cms.double( 0.5 ),
                                               maxDeltaEta = cms.double( 0.2 ), # no effect here
                                               # definition of matcher output
                                               resolveAmbiguities    = cms.bool( False ),
                                               resolveByMatchQuality = cms.bool( False )
                                               )
    
    process.eleTriggerMatchPF = cms.EDProducer( "PATTriggerMatcherDRLessByR",
                                                src     = cms.InputTag( "selectedPatElectrons"+postfix ),
                                                matched = cms.InputTag( "patTrigger" ),
                                                #matchedCuts = cms.string( 'type( "TriggerL1NoIsoEG" ) || type( "TriggerL1IsoEG" ) || type( "TriggerElectron" )' ),
                                                matchedCuts = cms.string( 'type( "TriggerElectron" )' ),
                                                maxDPtRel   = cms.double( 0.5 ), # no effect here
                                                maxDeltaR   = cms.double( 0.5 ),
                                                maxDeltaEta = cms.double( 0.2 ), # no effect here
                                                # definition of matcher output
                                                resolveAmbiguities    = cms.bool( False ),
                                                resolveByMatchQuality = cms.bool( False )
                                                )

    from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning
    removeCleaning( process )
    setattr( process, 'muTriggerMatch' + postfix, process.muTriggerMatchPF )
    setattr( process, 'eleTriggerMatch' + postfix, process.eleTriggerMatchPF )
    switchOnTriggerMatching( process, triggerMatchers = [ 'muTriggerMatchPFlow','eleTriggerMatchPFlow' ], sequence = 'patPF2PATSequence' + postfix )
    removeCleaningFromTriggerMatching( process, sequence = 'patPF2PATSequence' + postfix )
Example #2
0
    def Pat(self) :

        from PhysicsTools.PatAlgos.tools.coreTools import removeMCMatching,removeCleaning,restrictInputToAOD,removeAllPATObjectsBut
        from PhysicsTools.PatAlgos.tools.jetTools import switchJetCollection 
        from PhysicsTools.PatAlgos.tools.jetTools import addJetCollection 

        if self.options.isData: removeMCMatching(self.process, ['All'])
        restrictInputToAOD(self.process)
        removeCleaning(self.process)
        removeAllPATObjectsBut(self.process, ['Jets','METs','Muons'])
        addJetCollection(self.process,
	    		    cms.InputTag('ak5CaloJets'),
			    'AK5',
			    'Calo',
			    jetCorrLabel = ('AK5Calo',self.options.jetCorrections),
			    genJetCollection = cms.InputTag('ak5GenJets'),
			    doType1MET = False,
                       )
        switchJetCollection(self.process,
	    		    cms.InputTag('ak5PFJets'),
			    doJTA = True,
		  	    doBTagging = True,
			    doJetID = True,
			    jetCorrLabel = ('AK5PF',self.options.jetCorrections),
			    genJetCollection = cms.InputTag('ak5GenJets'),
			    doType1MET = False,
			    jetIdLabel = 'ak5pf'
                       )

        self.process.selectedPatJets.cut = cms.string("pt > 30 && \
                                                       abs(eta) < 3.0 && \
                                                       neutralHadronEnergyFraction < 0.9 && \
                                                       neutralEmEnergyFraction < 0.90 && \
                                                       nConstituents > 1 && \
                                                       (? abs(eta)<2.4 ? chargedHadronEnergyFraction : 1) > 0 && \
                                                       (? abs(eta)<2.4 ? chargedHadronMultiplicity : 1) > 0 && \
                                                       (? abs(eta)<2.4 ? chargedEmEnergyFraction : 0) < 0.99")

        del self.process.out
        del self.process.outpath
	return self.process.patDefaultSequence
def usePF2PAT_WREdition(
        process,
        runPF2PAT=True,
        jetAlgo='AK5',
        runOnMC=True,
        postfix="",
        jetCorrections=('AK5PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute']),
        pvCollection=cms.InputTag('offlinePrimaryVertices'),
        typeIMetCorrections=False,
        outputModules=['out']):
    # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
    # CREATE ADDITIONAL FUNCTIONS IF NEEDED.
    """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""

    # -------- CORE ---------------
    if runPF2PAT:
        process.load("CommonTools.ParticleFlow.PF2PAT_cff")
        process.patPF2PATSequence = cms.Sequence(process.PF2PAT +
                                                 process.patDefaultSequence)
    else:
        process.patPF2PATSequence = cms.Sequence(process.patDefaultSequence)

    if not postfix == "":
        from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
        cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)

    removeCleaning(process, postfix=postfix, outputModules=outputModules)

    # Photons
    print "Temporarily switching off photons completely"

    removeSpecificPATObjects(process,
                             names=['Photons', 'Taus', "Muons", "Electrons"],
                             outputModules=outputModules,
                             postfix=postfix)
    removeIfInSequence(process, "patPhotonIsolation", "patDefaultSequence",
                       postfix)

    # Jets
    if runOnMC:
        switchToPFJets(process,
                       cms.InputTag('pfNoTau' + postfix),
                       jetAlgo,
                       postfix=postfix,
                       jetCorrections=jetCorrections,
                       type1=typeIMetCorrections,
                       outputModules=outputModules)
        applyPostfix(process, "patDefaultSequence", postfix).replace(
            applyPostfix(process, "patJetGenJetMatch", postfix),
            getattr(process, "genForPF2PATSequence") *
            applyPostfix(process, "patJetGenJetMatch", postfix))
    else:
        if not 'L2L3Residual' in jetCorrections[1]:
            print '#################################################'
            print 'WARNING! Not using L2L3Residual but this is data.'
            print 'If this is okay with you, disregard this message.'
            print '#################################################'
        switchToPFJets(process,
                       cms.InputTag('pfNoTau' + postfix),
                       jetAlgo,
                       postfix=postfix,
                       jetCorrections=jetCorrections,
                       type1=typeIMetCorrections,
                       outputModules=outputModules)

    # Taus
    if ishpsPFTau:
        adaptPFTaus(process, tauType='hpsPFTau', postfix=postfix)

    # MET
    switchToPFMET(process,
                  cms.InputTag('pfMET' + postfix),
                  type1=typeIMetCorrections,
                  postfix=postfix)
    if not runOnMC:
        if hasattr(process, 'patPFMet' + postfix):
            getattr(process, 'patPFMet' + postfix).addGenMET = cms.bool(False)

    # Unmasked PFCandidates
    addPFCandidates(process,
                    cms.InputTag('pfNoJet' + postfix),
                    patLabel='PFParticles' + postfix,
                    cut="",
                    postfix=postfix)

    # adapt primary vertex collection
    adaptPVs(process, pvCollection=pvCollection, postfix=postfix)

    if runOnMC:
        process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
        getattr(process, "patDefaultSequence" + postfix).replace(
            applyPostfix(process, "patCandidates",
                         postfix), process.genForPF2PATSequence +
            applyPostfix(process, "patCandidates", postfix))
    else:
        removeMCMatchingPF2PAT(process,
                               postfix=postfix,
                               outputModules=outputModules)

    print "Done: PF2PAT interfaced to PAT, postfix=", postfix
    from PhysicsTools.PatAlgos.tools.coreTools import *
    if isPFJets:
        removeMCMatchingPF2PAT(process, '')
    if cmsswRelease == 42:
        removeMCMatching(process, ['All'], outputInProcess=False)
    else:
        removeMCMatching(process, ['All'], outputModules=[])

## ============================== ##
## Python tools --> Order matters ##
## ============================== ##

from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning
from PhysicsTools.PatAlgos.tools.coreTools import removeSpecificPATObjects
if (cmsswRelease == 42):
    removeCleaning(process, False)
elif (cmsswRelease == 44):
    removeCleaning(process, outputModules=[])
else:
    removeCleaning(process, outputModules=[])
    removeSpecificPATObjects(process,
                             names=['Jets', 'Taus', 'METs'],
                             outputModules=[])

# Special change for saving good products in data
if isData:
    process.out.outputCommands = cms.untracked.vstring("keep *")

#--- Trigger matching ---#
process.load("HeavyNu.AnalysisModules.hnutrigmatch_cfi")
from PhysicsTools.PatAlgos.tools.trigTools import *
Example #5
0
def usePF2PAT_WREdition(process, runPF2PAT=True, jetAlgo='AK5', runOnMC=True, postfix="", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative','L3Absolute']), pvCollection=cms.InputTag('offlinePrimaryVertices'), typeIMetCorrections=False, outputModules=['out']):
    # PLEASE DO NOT CLOBBER THIS FUNCTION WITH CODE SPECIFIC TO A GIVEN PHYSICS OBJECT.
    # CREATE ADDITIONAL FUNCTIONS IF NEEDED.

    """Switch PAT to use PF2PAT instead of AOD sources. if 'runPF2PAT' is true, we'll also add PF2PAT in front of the PAT sequence"""

    # -------- CORE ---------------
    if runPF2PAT:
        process.load("CommonTools.ParticleFlow.PF2PAT_cff")
        process.patPF2PATSequence = cms.Sequence( process.PF2PAT + process.patDefaultSequence)
    else:
        process.patPF2PATSequence = cms.Sequence( process.patDefaultSequence )

    if not postfix == "":
        from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
        cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)

    removeCleaning(process, postfix=postfix, outputModules=outputModules)

    # Photons
    print "Temporarily switching off photons completely"

    removeSpecificPATObjects(process,names=['Photons', 'Taus', "Muons", "Electrons"],outputModules=outputModules,postfix=postfix)
    removeIfInSequence(process,"patPhotonIsolation","patDefaultSequence",postfix)

    # Jets
    if runOnMC :
        switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
                        jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
        applyPostfix(process,"patDefaultSequence",postfix).replace(
            applyPostfix(process,"patJetGenJetMatch",postfix),
            getattr(process,"genForPF2PATSequence") *
            applyPostfix(process,"patJetGenJetMatch",postfix)
            )
    else :
        if not 'L2L3Residual' in jetCorrections[1]:
            print '#################################################'
            print 'WARNING! Not using L2L3Residual but this is data.'
            print 'If this is okay with you, disregard this message.'
            print '#################################################'
        switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
                        jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
                        

    # Taus
    if ishpsPFTau:
        adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )

    # MET
    switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)
    if not runOnMC :
        if hasattr(process,'patPFMet'+postfix):
            getattr(process,'patPFMet'+postfix).addGenMET = cms.bool(False)

    # Unmasked PFCandidates
    addPFCandidates(process,cms.InputTag('pfNoJet'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)

    # adapt primary vertex collection
    adaptPVs(process, pvCollection=pvCollection, postfix=postfix)

    if runOnMC:
        process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
        getattr(process, "patDefaultSequence"+postfix).replace(
            applyPostfix(process,"patCandidates",postfix),
            process.genForPF2PATSequence+applyPostfix(process,"patCandidates",postfix)
            )
    else:
        removeMCMatchingPF2PAT(process,postfix=postfix,outputModules=outputModules)

    print "Done: PF2PAT interfaced to PAT, postfix=", postfix
Example #6
0
process.plep35_35_prescale += process.prescaleFilter

if isData:
    from PhysicsTools.PatAlgos.tools.coreTools import *
    if isPFJets:
        removeMCMatchingPF2PAT( process, '' )
    if cmsswRelease == 53:
        removeMCMatching(process, ['All'], outputModules = [])    

## ============================== ##
## Python tools --> Order matters ##
## ============================== ##
from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning
from PhysicsTools.PatAlgos.tools.coreTools import removeSpecificPATObjects
if cmsswRelease == 53:
    removeCleaning( process, outputModules = [] )
    removeSpecificPATObjects(process, names = ['Jets','Taus','METs'], outputModules = [])

#-------------------------------#
#--- Output Module specifics ---#
#-------------------------------#
#--- Restore the event content after PAT ---#
process.out.outputCommands = cms.untracked.vstring("keep *","drop *_*_*_HNUSKIMS","keep edmTriggerResults_TriggerResults__HNUSKIMS")
#--- List of skims that will be kept ---#
process.out.SelectEvents = cms.untracked.PSet(SelectEvents=cms.vstring('plep35_35_prescale','plep50_35','pemu50_35'))

#----------------#
#--- LumiList ---#
#----------------#
process.lumilist = cms.EDAnalyzer('LumiList')
if not isMC:
Example #7
0
process.selectionSequence = cms.Sequence()

from PhysicsTools.PatAlgos.tools.coreTools import removeSpecificPATObjects, removeCleaning
from HiggsAnalysis.HeavyChHiggsToTauNu.HChPatTuple import addPat
from HiggsAnalysis.HeavyChHiggsToTauNu.HChDataSelection import addDataSelection

if options.doPat != 0:
    process.collisionDataSelection = cms.Sequence()
    if dataVersion.isData():
        process.collisionDataSelection = addDataSelection(process, dataVersion, trigger)
    
    process.patSequence = addPat(process, dataVersion, doPatTrigger=False, doTauHLTMatching=False,
                                 doPatTaus=False, doPatElectronID=False)
    removeSpecificPATObjects(process, ["Photons"], False)
    removeCleaning(process, False)    
    process.patMuons.embedTrack = False # In order to avoid transient references and generalTracks is available anyway

    process.selectionSequence = cms.Sequence(
        process.collisionDataSelection * 
        process.patSequence
    )

# Override the outputCommands here, since PAT modifies it
process.out.outputCommands = cms.untracked.vstring(
    "drop *",
    "keep edmMergeableCounter_*_*_*", # in lumi block
    "keep *_muonNtp_*_MUONNTUPLE",
    "keep *_metNtp_*_MUONNTUPLE",
    "keep *_jetNtp_*_MUONNTUPLE",
    "keep *_jetIdNtp_*_MUONNTUPLE",
Example #8
0
def usePF2PAT_WREdition(
        process,
        runPF2PAT=True,
        jetAlgo='AK5',
        runOnMC=True,
        postfix="",
        jetCorrections=('AK5PFchs', ['L1FastJet', 'L2Relative', 'L3Absolute']),
        pvCollection=cms.InputTag('offlinePrimaryVertices'),
        typeIMetCorrections=False,
        outputModules=['out']):

    # -------- CORE ---------------
    if runPF2PAT:
        process.load("CommonTools.ParticleFlow.PF2PAT_cff")
        #add Pf2PAT *before* cloning so that overlapping modules are cloned too
        #process.patDefaultSequence.replace( process.patCandidates, process.PF2PAT+process.patCandidates)
        process.patPF2PATSequence = cms.Sequence(process.PF2PAT +
                                                 process.patDefaultSequence)
    else:
        process.patPF2PATSequence = cms.Sequence(process.patDefaultSequence)

    if not postfix == "":
        from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
        cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)
        #delete everything pat PF2PAT modules! if you want to test the postfixing for completeness
        #from PhysicsTools.PatAlgos.tools.helpers import listModules,listSequences
        #for module in listModules(process.patDefaultSequence):
        #    if not module.label() is None: process.__delattr__(module.label())
        #for sequence in listSequences(process.patDefaultSequence):
        #    if not sequence.label() is None: process.__delattr__(sequence.label())
        #del process.patDefaultSequence

    removeCleaning(process, postfix=postfix, outputModules=outputModules)

    # -------- OBJECTS ------------
    # Muons
    #adaptPFMuons(process,
    #             applyPostfix(process,"patMuons",postfix),
    #             postfix)

    # Electrons
    #adaptPFElectrons(process,
    #                 applyPostfix(process,"patElectrons",postfix),
    #                 postfix)

    # Photons
    print "Temporarily switching off photons completely"

    removeSpecificPATObjects(process,
                             names=['Photons', 'Taus', "Muons", "Electrons"],
                             outputModules=outputModules,
                             postfix=postfix)
    removeIfInSequence(process, "patPhotonIsolation", "patDefaultSequence",
                       postfix)

    # Jets
    if runOnMC:
        if ishpsPFTau:
            switchToPFJets(process,
                           cms.InputTag('pfNoTau' + postfix),
                           jetAlgo,
                           postfix=postfix,
                           jetCorrections=jetCorrections,
                           type1=typeIMetCorrections,
                           outputModules=outputModules)
        else:
            switchToPFJets(process,
                           cms.InputTag('pfJets' + postfix),
                           jetAlgo,
                           postfix=postfix,
                           jetCorrections=jetCorrections,
                           type1=typeIMetCorrections,
                           outputModules=outputModules)
            applyPostfix(process, "patDefaultSequence", postfix).replace(
                applyPostfix(process, "patJetGenJetMatch", postfix),
                getattr(process, "genForPF2PATSequence") *
                applyPostfix(process, "patJetGenJetMatch", postfix))
    else:
        if not 'L2L3Residual' in jetCorrections[1]:
            print '#################################################'
            print 'WARNING! Not using L2L3Residual but this is data.'
            print 'If this is okay with you, disregard this message.'
            print '#################################################'
        if ishpsPFTau:
            switchToPFJets(process,
                           cms.InputTag('pfNoTau' + postfix),
                           jetAlgo,
                           postfix=postfix,
                           jetCorrections=jetCorrections,
                           type1=typeIMetCorrections,
                           outputModules=outputModules)
        else:
            switchToPFJets(process,
                           cms.InputTag('pfJets' + postfix),
                           jetAlgo,
                           postfix=postfix,
                           jetCorrections=jetCorrections,
                           type1=typeIMetCorrections,
                           outputModules=outputModules)

    # Taus
    #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
    #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
    if ishpsPFTau:
        adaptPFTaus(process, tauType='hpsPFTau', postfix=postfix)

    # MET
    switchToPFMET(process,
                  cms.InputTag('pfMET' + postfix),
                  type1=typeIMetCorrections,
                  postfix=postfix)

    # Unmasked PFCandidates
    addPFCandidates(process,
                    cms.InputTag('pfNoJet' + postfix),
                    patLabel='PFParticles' + postfix,
                    cut="",
                    postfix=postfix)

    # adapt primary vertex collection
    adaptPVs(process, pvCollection=pvCollection, postfix=postfix)

    if runOnMC:
        process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
        getattr(process, "patDefaultSequence" + postfix).replace(
            applyPostfix(process, "patCandidates",
                         postfix), process.genForPF2PATSequence +
            applyPostfix(process, "patCandidates", postfix))
    else:
        removeMCMatchingPF2PAT(process,
                               postfix=postfix,
                               outputModules=outputModules)

    print "Done: PF2PAT interfaced to PAT, postfix=", postfix
    maxDeltaR=cms.double(0.5),
    maxDeltaEta=cms.double(0.2)  # no effect here
    # definition of matcher output
    ,
    resolveAmbiguities=cms.bool(True),
    resolveByMatchQuality=cms.bool(True))

### ============
### Python tools
### ============

## --
## Switch to selected PAT objects in the main work flow
## --
from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning
removeCleaning(process)
# to save a bit of disk space
process.out.outputCommands += [
    'drop recoBaseTagInfosOwned_*_*_*', 'drop CaloTowers_*_*_*',
    'drop recoGenJets_*_*_*'
]

## --
## Switch on PAT trigger
## --
from PhysicsTools.PatAlgos.tools.trigTools import *
switchOnTrigger(process)  # This is optional and can be omitted.
switchOnTriggerMatching(process, triggerMatchers=['muonTriggerMatchHLTMuons'])
# Switch to selected PAT objects in the trigger matching
removeCleaningFromTriggerMatching(process)
    maxDeltaEta=cms.double(0.2)  # no effect here
    # definition of matcher output
    ,
    resolveAmbiguities=cms.bool(True),
    resolveByMatchQuality=cms.bool(True))

### ============
### Python tools
### ============

## --
## Switch to selected PAT objects in the main work flow
## --
from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning

removeCleaning(process, outputInProcess=False)

## --
## Switch on PAT trigger
## --
from PhysicsTools.PatAlgos.tools.trigTools import *

switchOnTriggerMatching(process,
                        triggerMatchers=['muonTriggerMatchHLTMuons'],
                        outputModule='')
# Switch to selected PAT objects in the trigger matching
removeCleaningFromTriggerMatching(process, outputModule='')

## ---
## Add analysis
## ---
Example #11
0
def addPat(process, isData, doRECO, doTTEffShrinkingConePFTau):
    sequence = cms.Sequence()

    # If running together with RECO
    # We get another kt6PFJets from PAT, and as-is they clash producing an exception
    runningWithReco = hasattr(process, "recoAllPFJets")
    if runningWithReco:
        process.recoAllPFJets.remove(process.kt6PFJets)
        process.recoPFJets.remove(process.kt6PFJets)

    process.load("PhysicsTools.PatAlgos.patSequences_cff")

    if runningWithReco:
        process.recoAllPFJets.replace(process.kt4PFJets,
                                      process.kt4PFJets * process.kt6PFJets)
        process.recoPFJets.replace(process.kt4PFJets,
                                   process.kt4PFJets * process.kt6PFJets)

#    process.load("PhysicsTools.PatAlgos.producersLayer1.patCandidates_cff")

# Calculate PF isolation of the muon
#process.muonPFIsolationSequence = MuonPFIsolation.addMuonPFIsolation(process, "muons", process.patMuons)
#sequence += process.muonPFIsolationSequence

    if doRECO:
        process.pfPileUpIso.PFCandidates = "particleFlowTmp"  # I don't know why I have to do this
        process.pfNoPileUpIso.bottomCollection = "particleFlowTmp"

    jetCorr = ["L1FastJet", "L2Relative", "L3Absolute"]
    if isData:
        jetCorr.append("L2L3Residual")
        #        coreTools.removeMCMatching(process, ["All"], outputInProcess=False)
        coreTools.removeMCMatching(process, ["All"], outputModules=[])
        ####    coreTools.removeCleaning(process, False)
        coreTools.removeCleaning(process, outputModules=[])
        ####    coreTools.removeSpecificPATObjects(process, ["Electrons", "Photons", "METs"], False)
        coreTools.removeSpecificPATObjects(process,
                                           ["Electrons", "Photons", "METs"],
                                           outputModules=[])
    tauTools.addTauCollection(process,
                              cms.InputTag('hpsPFTauProducer'),
                              algoLabel="hps",
                              typeLabel="PFTau")

    jetTools.switchJetCollection(process,
                                 cms.InputTag('ak5PFJets'),
                                 doJTA=True,
                                 doBTagging=True,
                                 jetCorrLabel=('AK5PF', jetCorr),
                                 doType1MET=False,
                                 genJetCollection=cms.InputTag("ak5GenJets"),
                                 doJetID=False,
                                 jetIdLabel="ak5",
                                 outputModules=[])

    # If the reference tau should be the old TTEff shrinking cone
    # if doTTEffShrinkingConePFTau:
    #     process.patTaus.tauSource = "TTEffShrinkingConePFTauProducer"
    #     for module in [process.tauIsoDepositPFCandidates, process.tauIsoDepositPFChargedHadrons, process.tauIsoDepositPFGammas, process.tauIsoDepositPFNeutralHadrons]:
    #         module.src = "TTEffShrinkingConePFTauProducer"
    #         module.ExtractorPSet.tauSource = "TTEffShrinkingConePFTauProducer"
    #     process.tauMatch.src = "TTEffShrinkingConePFTauProducer"
    #     process.patTaus.tauIDSources.leadingPionPtCut = "TTEffPFTauDiscriminationByLeadingPionPtCut"
    #     process.patTaus.tauIDSources.byIsolationUsingLeadingPion = "TTEffPFTauDiscriminationByIsolationUsingLeadingPion"
    #     process.patTaus.tauIDSources.leadingTrackFinding = "TTEffPFTauDiscriminationByLeadingTrackFinding"
    #     process.patTaus.tauIDSources.againstMuon = "TTEffPFTauDiscriminationAgainstMuon"
    #     process.patTaus.tauIDSources.againstElectron = "TTEffPFTauDiscriminationAgainstElectron"
    #     process.selectedPatTaus.cut = "pt() > 15 && abs(eta()) < 2.5 && tauID('leadingPionPtCut')"

    sequence += process.patDefaultSequence
    return sequence
Example #12
0
# PAT Trigger matching
########################################
# imported directly from PhysicsTools/PatExamples/test/analyzePatTrigger_onTheFly_cfg.py
#
process.load("HeavyNu.AnalysisModules.hnutrigmatch_cfi")

### ============
### Python tools
### ============
### Attention: order matters!

## --
## Switch to selected PAT objects in the main work flow
## --
from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning
removeCleaning( process, isData )

## --
## Switch on PAT trigger - but only for data!
## --
from PhysicsTools.PatAlgos.tools.trigTools import *
if isData:
    switchOnTriggerMatching( process, triggerMatchers = [ 'muonTriggerMatchHLTMuons' ] )
    removeCleaningFromTriggerMatching( process )
    if isRun2010LoLumi: process.muonTriggerMatchHLTMuons.pathNames = cms.vstring('HLT_Mu9')
    else:               process.muonTriggerMatchHLTMuons.pathNames = cms.vstring('HLT_Mu15_v1')

##########################################
## Add analysis
##########################################
Example #13
0
def addPat(process, isData, doRECO, doTTEffShrinkingConePFTau):
    sequence = cms.Sequence()

    # If running together with RECO
    # We get another kt6PFJets from PAT, and as-is they clash producing an exception
    runningWithReco = hasattr(process, "recoAllPFJets")
    if runningWithReco:
        process.recoAllPFJets.remove(process.kt6PFJets)
        process.recoPFJets.remove(process.kt6PFJets)
    
    process.load("PhysicsTools.PatAlgos.patSequences_cff")

    if runningWithReco:
        process.recoAllPFJets.replace(process.kt4PFJets, process.kt4PFJets*process.kt6PFJets)
        process.recoPFJets.replace(process.kt4PFJets, process.kt4PFJets*process.kt6PFJets)

#    process.load("PhysicsTools.PatAlgos.producersLayer1.patCandidates_cff")

    # Calculate PF isolation of the muon
    #process.muonPFIsolationSequence = MuonPFIsolation.addMuonPFIsolation(process, "muons", process.patMuons)
    #sequence += process.muonPFIsolationSequence
    
    if doRECO:
        process.pfPileUpIso.PFCandidates = "particleFlowTmp" # I don't know why I have to do this
        process.pfNoPileUpIso.bottomCollection = "particleFlowTmp"

    jetCorr = ["L1FastJet", "L2Relative", "L3Absolute"]
    if isData:
        jetCorr.append("L2L3Residual")
#        coreTools.removeMCMatching(process, ["All"], outputInProcess=False)
	coreTools.removeMCMatching(process, ["All"], outputModules = [])
####    coreTools.removeCleaning(process, False)
        coreTools.removeCleaning(process, outputModules = [])
####    coreTools.removeSpecificPATObjects(process, ["Electrons", "Photons", "METs"], False)
        coreTools.removeSpecificPATObjects(process, ["Electrons", "Photons", "METs"], outputModules = [])
    tauTools.addTauCollection(process, cms.InputTag('hpsPFTauProducer'),
                              algoLabel = "hps", typeLabel = "PFTau")
    
    jetTools.switchJetCollection(process, cms.InputTag('ak5PFJets'),   
                                 doJTA            = True,            
                                 doBTagging       = True,            
                                 jetCorrLabel     = ('AK5PF', jetCorr),
                                 doType1MET       = False,            
                                 genJetCollection = cms.InputTag("ak5GenJets"),
                                 doJetID      = False,
                                 jetIdLabel   = "ak5",
                                 outputModules = [])
    
    # If the reference tau should be the old TTEff shrinking cone
    # if doTTEffShrinkingConePFTau:
    #     process.patTaus.tauSource = "TTEffShrinkingConePFTauProducer"
    #     for module in [process.tauIsoDepositPFCandidates, process.tauIsoDepositPFChargedHadrons, process.tauIsoDepositPFGammas, process.tauIsoDepositPFNeutralHadrons]:
    #         module.src = "TTEffShrinkingConePFTauProducer"
    #         module.ExtractorPSet.tauSource = "TTEffShrinkingConePFTauProducer"
    #     process.tauMatch.src = "TTEffShrinkingConePFTauProducer"
    #     process.patTaus.tauIDSources.leadingPionPtCut = "TTEffPFTauDiscriminationByLeadingPionPtCut"
    #     process.patTaus.tauIDSources.byIsolationUsingLeadingPion = "TTEffPFTauDiscriminationByIsolationUsingLeadingPion"
    #     process.patTaus.tauIDSources.leadingTrackFinding = "TTEffPFTauDiscriminationByLeadingTrackFinding"
    #     process.patTaus.tauIDSources.againstMuon = "TTEffPFTauDiscriminationAgainstMuon"
    #     process.patTaus.tauIDSources.againstElectron = "TTEffPFTauDiscriminationAgainstElectron"
    #     process.selectedPatTaus.cut = "pt() > 15 && abs(eta()) < 2.5 && tauID('leadingPionPtCut')"

    sequence += process.patDefaultSequence
    return sequence
Example #14
0
    # definition of matcher output
    ,
    resolveAmbiguities=cms.bool(True),
    resolveByMatchQuality=cms.bool(True),
)

### ============
### Python tools
### ============

## --
## Switch to selected PAT objects in the main work flow
## --
from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning

removeCleaning(process, outputInProcess=False)

## --
## Switch on PAT trigger
## --
from PhysicsTools.PatAlgos.tools.trigTools import *

switchOnTriggerMatching(process, triggerMatchers=["muonTriggerMatchHLTMuons"], outputModule="")
# Switch to selected PAT objects in the trigger matching
removeCleaningFromTriggerMatching(process, outputModule="")

## ---
## Add analysis
## ---
process.TFileService = cms.Service("TFileService", fileName=cms.string("analyzePatTrigger_onTheFly.root"))
process.triggerAnalysis = cms.EDAnalyzer(
                  doBTagging   = False,
                  jetCorrLabel = ('AK5PF', cms.vstring(['L1Offset', 'L2Relative', 'L3Absolute'])),
                  doType1MET   = True,
                  doL1Cleaning = True,                
                  doL1Counters = False,
                  genJetCollection=cms.InputTag("ak5GenJets"),
                  doJetID      = True,
                  jetIdLabel   = "ak5"
 )
 
process.selectedJetsL1Corrected = process.selectedJets.clone(src = cms.InputTag("patJetsAK5PFL1corrected"))
 
process.recjetsSequence += process.selectedJetsL1Corrected

from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning
removeCleaning( process )

##################################
## adding electron identification
##################################
process.load("ElectroWeakAnalysis.WENu.simpleEleIdSequence_cff")

process.patElectrons.addElectronID     = cms.bool( True )
process.patElectrons.electronIDSources = cms.PSet(
    simpleEleId95relIso = cms.InputTag("simpleEleId95relIso"),
    simpleEleId90relIso = cms.InputTag("simpleEleId90relIso"),
    simpleEleId85relIso = cms.InputTag("simpleEleId85relIso"),
    simpleEleId80relIso = cms.InputTag("simpleEleId80relIso"),
    simpleEleId70relIso = cms.InputTag("simpleEleId70relIso"),
    simpleEleId60relIso = cms.InputTag("simpleEleId60relIso"),
    simpleEleId95cIso   = cms.InputTag("simpleEleId95cIso"),
Example #16
0
# PAT Trigger matching
########################################
# imported directly from PhysicsTools/PatExamples/test/analyzePatTrigger_onTheFly_cfg.py
#
process.load("HeavyNu.AnalysisModules.hnutrigmatch_cfi")

### ============
### Python tools
### ============
### Attention: order matters!

## --
## Switch to selected PAT objects in the main work flow
## --
from PhysicsTools.PatAlgos.tools.coreTools import removeCleaning
removeCleaning(process, False)

## --
## Switch on PAT trigger - but only for data!
## --
from PhysicsTools.PatAlgos.tools.trigTools import *
if isData:
    switchOnTriggerMatching(process,
                            triggerMatchers=['muonTriggerMatchHLTMuons'])
    removeCleaningFromTriggerMatching(process, outputModule='')
    if isRun2011:
        process.muonTriggerMatchHLTMuons.matchedCuts = cms.string(
            'path( "HLT_Mu24_v*" )')
    else:
        if isRun2010LoLumi:
            process.muonTriggerMatchHLTMuons.matchedCuts = cms.string(
Example #17
0
def usePF2PAT_WREdition(process, runPF2PAT=True, jetAlgo='AK5', runOnMC=True, postfix="", jetCorrections=('AK5PFchs', ['L1FastJet','L2Relative','L3Absolute']), pvCollection=cms.InputTag('offlinePrimaryVertices'), typeIMetCorrections=False, outputModules=['out']):

    # -------- CORE ---------------
    if runPF2PAT:
        process.load("CommonTools.ParticleFlow.PF2PAT_cff")
        #add Pf2PAT *before* cloning so that overlapping modules are cloned too
        #process.patDefaultSequence.replace( process.patCandidates, process.PF2PAT+process.patCandidates)
        process.patPF2PATSequence = cms.Sequence( process.PF2PAT + process.patDefaultSequence)
    else:
        process.patPF2PATSequence = cms.Sequence( process.patDefaultSequence )

    if not postfix == "":
        from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
        cloneProcessingSnippet(process, process.patPF2PATSequence, postfix)
        #delete everything pat PF2PAT modules! if you want to test the postfixing for completeness
        #from PhysicsTools.PatAlgos.tools.helpers import listModules,listSequences
        #for module in listModules(process.patDefaultSequence):
        #    if not module.label() is None: process.__delattr__(module.label())
        #for sequence in listSequences(process.patDefaultSequence):
        #    if not sequence.label() is None: process.__delattr__(sequence.label())
        #del process.patDefaultSequence

    removeCleaning(process, postfix=postfix, outputModules=outputModules)

    # -------- OBJECTS ------------
    # Muons
    #adaptPFMuons(process,
    #             applyPostfix(process,"patMuons",postfix),
    #             postfix)

    # Electrons
    #adaptPFElectrons(process,
    #                 applyPostfix(process,"patElectrons",postfix),
    #                 postfix)

    # Photons
    print "Temporarily switching off photons completely"

    removeSpecificPATObjects(process,names=['Photons', 'Taus', "Muons", "Electrons"],outputModules=outputModules,postfix=postfix)
    removeIfInSequence(process,"patPhotonIsolation","patDefaultSequence",postfix)

    # Jets
    if runOnMC :
       if ishpsPFTau:
         switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
                        jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
       else:
         switchToPFJets( process, cms.InputTag('pfJets'+postfix), jetAlgo, postfix=postfix,
                           jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
         applyPostfix(process,"patDefaultSequence",postfix).replace(
            applyPostfix(process,"patJetGenJetMatch",postfix),
            getattr(process,"genForPF2PATSequence") *
            applyPostfix(process,"patJetGenJetMatch",postfix)
            )
    else :
        if not 'L2L3Residual' in jetCorrections[1]:
            print '#################################################'
            print 'WARNING! Not using L2L3Residual but this is data.'
            print 'If this is okay with you, disregard this message.'
            print '#################################################'
        if ishpsPFTau:
            switchToPFJets( process, cms.InputTag('pfNoTau'+postfix), jetAlgo, postfix=postfix,
                            jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )
        else:
            switchToPFJets( process, cms.InputTag('pfJets'+postfix), jetAlgo, postfix=postfix,
                            jetCorrections=jetCorrections, type1=typeIMetCorrections, outputModules=outputModules )

    # Taus
    #adaptPFTaus( process, tauType='shrinkingConePFTau', postfix=postfix )
    #adaptPFTaus( process, tauType='fixedConePFTau', postfix=postfix )
    if ishpsPFTau:
        adaptPFTaus( process, tauType='hpsPFTau', postfix=postfix )

    # MET
    switchToPFMET(process, cms.InputTag('pfMET'+postfix), type1=typeIMetCorrections, postfix=postfix)

    # Unmasked PFCandidates
    addPFCandidates(process,cms.InputTag('pfNoJet'+postfix),patLabel='PFParticles'+postfix,cut="",postfix=postfix)

    # adapt primary vertex collection
    adaptPVs(process, pvCollection=pvCollection, postfix=postfix)

    if runOnMC:
        process.load("CommonTools.ParticleFlow.genForPF2PAT_cff")
        getattr(process, "patDefaultSequence"+postfix).replace(
            applyPostfix(process,"patCandidates",postfix),
            process.genForPF2PATSequence+applyPostfix(process,"patCandidates",postfix)
            )
    else:
        removeMCMatchingPF2PAT(process,postfix=postfix,outputModules=outputModules)

    print "Done: PF2PAT interfaced to PAT, postfix=", postfix