Ejemplo n.º 1
0
def buildSequence(process, patArgs):
    sequence = cms.Sequence()

    # Produce HPS taus from AK5 PF jets already in AOD
    process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
    sequence *= process.PFTau
    # Produce pat taus, assuming patDefaultSequence is already included to the process
    if not hasattr(process, "patTausHpsPFTau"):
        tauTools.addTauCollection(process,
                                  cms.InputTag('hpsPFTauProducer'),
                                  algoLabel="hps",
                                  typeLabel="PFTau")

    process.patTausHpsPFTauForPV = process.patTausHpsPFTau.clone(
        addGenJetMatch=False,
        embedGenJetMatch=False,
        addGenMatch=False,
        embedGenMatch=False,
        userIsolation=cms.PSet(),
        isoDeposits=cms.PSet(),
    )
    process.patTausHpsPFTauForPV.tauIDSources.byRawCombinedIsolationDeltaBetaCorr = cms.InputTag(
        "hpsPFTauDiscriminationByRawCombinedIsolationDBSumPtCorr")

    sequence *= process.patTausHpsPFTauForPV

    # Trigger matching
    sequence *= HChTriggerMatching.addTauHLTMatching(
        process,
        patArgs["matchingTauTrigger"],
        collections=["patTausHpsPFTauForPV"],
        postfix="ForPV")

    # Require decay mode finding
    process.selectedPatTausHpsPFTauForPV = cms.EDFilter(
        "PATTauSelector",
        src=cms.InputTag("patTausHpsPFTauForPVTriggerMatchedForPV"),
        cut=cms.string("tauID('decayModeFinding')"))
    sequence *= process.selectedPatTausHpsPFTauForPV

    # Obtain the index of the vertex of most isolated tau
    process.selectedPrimaryVertexIndex = cms.EDProducer(
        "HPlusVertexIndexTauMostIsolatedProducer",
        vertexSrc=cms.InputTag("offlinePrimaryVertices"),
        tauSrc=cms.InputTag("selectedPatTausHpsPFTauForPV"),
        tauDiscriminator=cms.string("byRawCombinedIsolationDeltaBetaCorr"),
        dz=cms.double(0.2),
    )
    sequence *= process.selectedPrimaryVertexIndex

    return sequence
def buildSequence(process, patArgs):
    sequence = cms.Sequence()

    # Produce HPS taus from AK5 PF jets already in AOD
    process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
    sequence *= process.PFTau
    # Produce pat taus, assuming patDefaultSequence is already included to the process
    if not hasattr(process, "patTausHpsPFTau"):
        tauTools.addTauCollection(process, cms.InputTag('hpsPFTauProducer'),
                                  algoLabel = "hps",
                                  typeLabel = "PFTau")

    process.patTausHpsPFTauForPV = process.patTausHpsPFTau.clone(
        addGenJetMatch = False,
        embedGenJetMatch = False,
        addGenMatch = False,
        embedGenMatch = False,
        userIsolation = cms.PSet(),
        isoDeposits = cms.PSet(),
    )
    process.patTausHpsPFTauForPV.tauIDSources.byRawCombinedIsolationDeltaBetaCorr = cms.InputTag("hpsPFTauDiscriminationByRawCombinedIsolationDBSumPtCorr")

    sequence *= process.patTausHpsPFTauForPV

    # Trigger matching
    sequence *= HChTriggerMatching.addTauHLTMatching(process, patArgs["matchingTauTrigger"], collections=["patTausHpsPFTauForPV"], postfix="ForPV")

    # Require decay mode finding
    process.selectedPatTausHpsPFTauForPV = cms.EDFilter("PATTauSelector",
        src = cms.InputTag("patTausHpsPFTauForPVTriggerMatchedForPV"),
        cut = cms.string("tauID('decayModeFinding')")
    )
    sequence *= process.selectedPatTausHpsPFTauForPV

    # Obtain the index of the vertex of most isolated tau
    process.selectedPrimaryVertexIndex = cms.EDProducer("HPlusVertexIndexTauMostIsolatedProducer",
        vertexSrc = cms.InputTag("offlinePrimaryVertices"),
        tauSrc = cms.InputTag("selectedPatTausHpsPFTauForPV"),
        tauDiscriminator = cms.string("byRawCombinedIsolationDeltaBetaCorr"),
        dz = cms.double(0.2),
    )
    sequence *= process.selectedPrimaryVertexIndex

    return sequence
Ejemplo n.º 3
0
def addPlainPat(process, dataVersion, doPatTrigger=True, doPatTaus=True, doHChTauDiscriminators=True, doPatMET=True, doPatElectronID=True,
                doPatCalo=True, doBTagging=True, doPatMuonPFIsolation=False, doPatTauIsoDeposits=False,
                doTauHLTMatching=True, matchingTauTrigger=None, matchingJetTrigger=None,
                includePFCands=False):
    out = None
    outdict = process.outputModules_()
    if outdict.has_key("out"):
        out = outdict["out"]

    outputCommands = []

    # Tau Discriminators
    process.hplusPatTauSequence = cms.Sequence()
    if doPatTaus:
        process.hplusPatTauSequence = addPFTausAndDiscriminators(process, dataVersion, doPatCalo, doHChTauDiscriminators)

    # PAT Layer 0+1
    process.load("PhysicsTools.PatAlgos.patSequences_cff")

    sequence = cms.Sequence(
        process.hplusPatTauSequence
    )

    # Restrict input to AOD
    restrictInputToAOD(process, ["All"])

    # Remove MC stuff if we have collision data (has to be done any add*Collection!)
    # This also adds the L2L3Residual JEC correction to the process.patJetCorrFactors
    if dataVersion.isData():
        runOnData(process, outputInProcess = out!=None)

    # Jets
    # Produce kt6 rho for L1Fastjet
    process.load('RecoJets.Configuration.RecoPFJets_cff')
    process.kt6PFJets.doRhoFastjet = True
    process.ak5PFJets.doAreaFastjet = True
    process.ak5PFJetSequence = cms.Sequence(process.kt6PFJets * process.ak5PFJets)
   
    # Set defaults
    process.patJets.jetSource = cms.InputTag("ak5CaloJets")
    process.patJets.trackAssociationSource = cms.InputTag("ak5JetTracksAssociatorAtVertex")
    setPatJetDefaults(process.patJets)
    setPatJetCorrDefaults(process.patJetCorrFactors, dataVersion)
    process.patDefaultSequence.replace(process.patJetCorrFactors,
                                       process.ak5PFJetSequence*process.patJetCorrFactors)
    process.selectedPatJets.cut = jetPreSelection

    # The default JEC to be embedded to pat::Jets are L2Relative,
    # L3Absolute, L5Flavor and L7Parton. The default JEC to be applied
    # is L2L3Residual, or L3Absolute, or Uncorrected (in this order).

    if doPatCalo:
        # Add JPT jets
        # FIXME: Disabled for now until the JEC for JPT works again (with the latest JEC)
#        addJetCollection(process, cms.InputTag('JetPlusTrackZSPCorJetAntiKt5'),
#                         'AK5', 'JPT',
#                         doJTA        = True,
#                         doBTagging   = doBTagging,
#                         jetCorrLabel = ('AK5JPT', process.patJetCorrFactors.levels),
#                         doType1MET   = False,
#                         doL1Cleaning = False,
#                         doL1Counters = True,
#                         genJetCollection = cms.InputTag("ak5GenJets"),
#                         doJetID      = True
#        )
    
        # Add PF jets
        addJetCollection(process, cms.InputTag('ak5PFJets'),
                         'AK5', 'PF',
                         doJTA        = True,
                         doBTagging   = doBTagging,
                         jetCorrLabel = ('AK5PF', process.patJetCorrFactors.levels),
                         doType1MET   = False,
                         doL1Cleaning = False,
                         doL1Counters = True,
                         genJetCollection = cms.InputTag("ak5GenJets"),
                         doJetID      = True
        )
        setPatJetCorrDefaults(process.patJetCorrFactorsAK5PF, dataVersion, True)

    else:
        setPatJetCorrDefaults(process.patJetCorrFactors, dataVersion, True)
        switchJetCollection(process, cms.InputTag('ak5PFJets'),
                            doJTA        = True,
                            doBTagging   = doBTagging,
                            jetCorrLabel = ('AK5PF', process.patJetCorrFactors.levels),
                            doType1MET   = False,
                            genJetCollection = cms.InputTag("ak5GenJets"),
                            doJetID      = True
        )
    
    outputCommands.extend([
            "keep *_selectedPatJets_*_*",
            "keep *_selectedPatJetsAK5JPT_*_*",
            "keep *_selectedPatJetsAK5PF_*_*",
            'drop *_selectedPatJets_pfCandidates_*', ## drop for default patJets which are CaloJets
            'drop *_*PF_caloTowers_*',
            'drop *_*JPT_pfCandidates_*',
            'drop *_*Calo_pfCandidates_*',
            ])

    # Taus

    # Set default PATTauProducer options here, they should be
    # replicated to all added tau collections (and the first call to
    # addTauCollection should replace the default producer modified
    # here)
    setPatTauDefaults(process.patTaus, includePFCands)
    process.selectedPatTaus.cut = tauPreSelection

    if doPatTaus:
        if doHChTauDiscriminators:
            addHChTauDiscriminators()

        # Don't enable TCTau nor shrinking cone tau
        # if doPatCalo:
        #     tauTools.addTauCollection(process,cms.InputTag('caloRecoTauProducer'),
        #                      algoLabel = "caloReco",
        #                      typeLabel = "Tau")
        #     setPatTauDefaults(process.patTausCaloRecoTau, True)
        #     process.patTausCaloRecoTau.embedLeadTrack = not includePFCands
        #     process.patTausCaloRecoTau.embedLeadPFChargedHadrCand = False
    
        # tauTools.addTauCollection(process,cms.InputTag('shrinkingConePFTauProducer'),
        #                  algoLabel = "shrinkingCone",
        #                  typeLabel = "PFTau")
        # # Disable isoDeposits like this until the problem with doPFIsoDeposits is fixed 
        # if not doPatTauIsoDeposits:
        #     process.patTausShrinkingConePFTau.isoDeposits = cms.PSet()

        tauTools.addTauCollection(process,cms.InputTag('hpsPFTauProducer'),
                         algoLabel = "hps",
                         typeLabel = "PFTau")
        if not doPatTauIsoDeposits:
            process.patTausHpsPFTau.isoDeposits = cms.PSet()
        addPatTauIsolationEmbedding(process, process.patDefaultSequence, "HpsPFTau")

        tauTools.addTauCollection(process,cms.InputTag('hpsTancTaus'),
                                  algoLabel = "hpsTanc",
                                  typeLabel = "PFTau")
        if not doPatTauIsoDeposits:
            process.patTausHpsTancPFTau.isoDeposits = cms.PSet()
        # Disable discriminators which are not in AOD
#        del process.patTausHpsTancPFTau.tauIDSources.againstCaloMuon
#        del process.patTausHpsTancPFTau.tauIDSources.byHPSvloose
        addPatTauIsolationEmbedding(process, process.patDefaultSequence, "HpsTancPFTau")

        # Add visible taus    
        if dataVersion.isMC():
            process.VisibleTaus = cms.EDProducer("HLTTauMCProducer",
                GenParticles  = cms.untracked.InputTag("genParticles"),
                ptMinTau      = cms.untracked.double(3),
                ptMinMuon     = cms.untracked.double(3),
                ptMinElectron = cms.untracked.double(3),
                BosonID       = cms.untracked.vint32(23),
                EtaMax         = cms.untracked.double(2.5)
            )
            sequence *= process.VisibleTaus
            outputCommands.append("keep *_VisibleTaus_*_*")

    else:
        # FIXME: this is broken at the moment
        #removeSpecificPATObjects(process, ["Taus"], outputInProcess= out != None)
        process.patDefaultSequence.remove(process.patTaus)
        process.patDefaultSequence.remove(process.selectedPatTaus)

    outputCommands.extend(["drop *_selectedPatTaus_*_*",
#                           "keep *_selectedPatTausCaloRecoTau_*_*",
#                           "keep *_selectedPatTausShrinkingConePFTau_*_*",
                           "keep *_selectedPatTausHpsPFTau_*_*",
                           "keep *_selectedPatTausHpsTancPFTau_*_*",
                           #"keep *_cleanPatTaus_*_*",
                           #"drop *_cleanPatTaus_*_*",
                           #"keep *_patTaus*_*_*",
                           #"keep *_patPFTauProducerFixedCone_*_*",
                           # keep these until the embedding problem with pat::Tau is fixed
                           #"keep recoPFCandidates_particleFlow_*_*",
                           #"keep recoTracks_generalTracks_*_*"
                           ])

    # MET
    addPfMET(process, 'PF')
    if doPatCalo:
        addTcMET(process, 'TC')
    else:
        # FIXME: This is broken at the moment...
        #removeSpecificPATObjects(process, ["METs"], outputInProcess= out != None)
        #process.patDefaultSequen
        process.patDefaultSequence.remove(process.patMETCorrections)
        process.patDefaultSequence.remove(process.patMETs)
        del process.patMETCorrections
        del process.patMETs

    outputCommands.extend([
            "keep *_patMETs_*_*",
            "keep *_patMETsTC_*_*",
            "keep *_patMETsPF_*_*",
            "keep *_genMetTrue_*_*",
            ])

    # Muons
    setPatLeptonDefaults(process.patMuons, includePFCands)
    if doPatMuonPFIsolation:
        addPFMuonIsolation(process, process.patMuons, sequence, verbose=True)

    outputCommands.extend([
            "keep *_selectedPatMuons_*_*"
            ])

    # Electrons
    # In order to calculate the transverse impact parameter w.r.t.
    # beam spot instead of primary vertex, see
    setPatLeptonDefaults(process.patMuons, includePFCands)

    # Electron ID, see
    # https://twiki.cern.ch/twiki/bin/view/CMS/SimpleCutBasedEleID
    if doPatElectronID:
        addPatElectronID(process, process.patElectrons, process.patDefaultSequence)

    outputCommands.extend([
            "keep *_selectedPatElectrons_*_*"
            ])

    # Photons
#    process.patPhotons.embedGenMatch = False
    outputCommands.extend([
            "keep *_selectedPatPhotons_*_*"
            ])

    # Trigger
    if doPatTrigger:
        outMod= ''
        if out != None:
            outMod  = 'out'
        switchOnTrigger(process, hltProcess=dataVersion.getTriggerProcess(), outputModule=outMod)
        process.patTrigger.addL1Algos = cms.bool(True)
        process.patTrigger.l1ExtraMu = cms.InputTag("l1extraParticles")
        process.patTrigger.l1ExtraCenJet = cms.InputTag("l1extraParticles", "Central")
        process.patTrigger.l1ExtraTauJet = cms.InputTag("l1extraParticles", "Tau")
        process.patTrigger.l1ExtraForJet = cms.InputTag("l1extraParticles", "Forward")
        process.patTrigger.l1ExtraETM = cms.InputTag("l1extraParticles", "MET")
        process.patTrigger.l1ExtraHTM = cms.InputTag("l1extraParticles", "MHT")


        # Keep StandAlone trigger objects for enabling trigger
        # matching in the analysis phase with PAT tools
        outputCommands.extend(patTriggerStandAloneEventContent)


    # Remove cleaning step and set the event content
    if out == None:
        myRemoveCleaning(process)
    else:
        backup = out.outputCommands[:]
        myRemoveCleaning(process)
#        backup_pat = out.outputCommands[:]

        # Remove PFParticles here, they are explicitly included when needed
#        backup_pat = filter(lambda n: "selectedPatPFParticles" not in n, backup_pat)

        out.outputCommands = backup
#        out.outputCommands.extend(backup_pat)
        out.outputCommands.extend(outputCommands)

    # Build sequence
    sequence *= process.patDefaultSequence

    # Tau+HLT matching
    if doTauHLTMatching:
        sequence *= HChTriggerMatching.addTauHLTMatching(process, matchingTauTrigger, matchingJetTrigger)

    return sequence
Ejemplo n.º 4
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
Ejemplo n.º 5
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