Esempio n. 1
0
def MuonSetup(process, conf = None):

    goodMuonCut = 'isPFMuon'
    goodMuonCut += ' && isGlobalMuon'
    goodMuonCut += ' && pt > 26.'
    goodMuonCut += ' && abs(eta) < 2.1'
    goodMuonCut += ' && normChi2 < 10.'
    goodMuonCut += ' && userFloat("track_hitPattern_trackerLayersWithMeasurement") > 5'
    goodMuonCut += ' && userFloat("globalTrack_hitPattern_numberOfValidMuonHits") > 0'
    goodMuonCut += ' && abs(dB) < 0.2'
    goodMuonCut += ' && userFloat("innerTrack_hitPattern_numberOfValidPixelHits") > 0'
    goodMuonCut += ' && numberOfMatchedStations > 1'
    goodMuonCut += ' && abs(userFloat("dz")) < 0.5'
    goodSignalMuonCut = goodMuonCut

    if conf.Muons.cutOnIso:
        if conf.Muons.reverseIsoCut:
        #Choose anti-isolated region
            goodSignalMuonCut += ' && userFloat("{0}") >= {1} && userFloat("{0}") < {2}'.format(
                conf.Muons.relIsoType,
                conf.Muons.relIsoCutRangeAntiIsolatedRegion[0],
                conf.Muons.relIsoCutRangeAntiIsolatedRegion[1]
                )
        #Choose isolated region
        else:
            goodSignalMuonCut += " && (userFloat('{0}') >= {1}) && (userFloat('{0}') < {2})".format(
                conf.Muons.relIsoType,
                conf.Muons.relIsoCutRangeIsolatedRegion[0],
                conf.Muons.relIsoCutRangeIsolatedRegion[1]
            )
    print "goodSignalMuonCut = %s" % goodSignalMuonCut

    looseVetoMuonCut = "isPFMuon"
    looseVetoMuonCut += " && (isGlobalMuon | isTrackerMuon)"
    looseVetoMuonCut += " && pt > 10"
    looseVetoMuonCut += " && abs(eta)<2.5"
    looseVetoMuonCut += " && userFloat('{0}') < {1}".format(conf.Muons.relIsoType, conf.Muons.looseVetoRelIsoCut)
    looseVetoMuonCut += " && !(%s)" % goodSignalMuonCut #Remove 'good signal muons from the veto collection'


    process.goodSignalMuons = cms.EDFilter("CandViewSelector",
      src=cms.InputTag("muonsWithTriggerMatch"), cut=cms.string(goodSignalMuonCut)
    )

    process.looseVetoMuons = cms.EDFilter("CandViewSelector",
      src=cms.InputTag("muonsWithIso"), cut=cms.string(looseVetoMuonCut)
    )

    process.oneIsoMu = cms.EDFilter(
        "PATCandViewCountFilter",
        src=cms.InputTag("goodSignalMuons"),
        minNumber=cms.uint32(1),
        maxNumber=cms.uint32(1),
    )
    process.zeroIsoEle = cms.EDFilter(
        "PATCandViewCountFilter",
        src=cms.InputTag("goodSignalElectrons"),
        minNumber=cms.uint32(0),
        maxNumber=cms.uint32(0),
    )

    #####################
    # Loose lepton veto #
    #####################
    #In Muon path we must have 0 loose muons (good signal muons removed) or electrons
    process.looseMuVetoMu = cms.EDFilter(
        "PATCandViewCountFilter",
        src=cms.InputTag("looseVetoMuons"),
        minNumber=cms.uint32(0),
        maxNumber=cms.uint32(0)
    )
    process.looseEleVetoMu = cms.EDFilter(
        "PATCandViewCountFilter",
        src=cms.InputTag("looseVetoElectrons"),
        minNumber=cms.uint32(0),
        maxNumber=cms.uint32(0),
    )

    goodMET = metSequence(process, conf, "mu", conf.metSource, "goodSignalLeptons")

    process.muonWeightsProducer = cms.EDProducer("MuonEfficiencyProducer",
        src=cms.InputTag("singleIsoMu"),
        dataRun=cms.string(conf.dataRun),

        #Variate all the scale factors by this value
        SFError=cms.double(0.01),
        applyConservativeSyst=cms.bool(True)
    )

    process.recoNuProducerMu = cms.EDProducer('ClassicReconstructedNeutrinoProducer',
        leptonSrc=cms.InputTag("singleIsoMu"),
        bjetSrc=cms.InputTag("btaggedJets"),
        metSrc=cms.InputTag(goodMET)
    )
Esempio n. 2
0
def ElectronSetup(process, conf):

    goodElectronCut = "%s>30" % conf.Electrons.pt
    goodElectronCut += " && (abs(eta) < 2.5)"
    goodElectronCut += " && !(1.4442 < abs(superCluster.eta) < 1.5660)"
    goodElectronCut += " && passConversionVeto() "
    goodSignalElectronCut = goodElectronCut

    #Sanity cut
    goodSignalElectronCut += " && (electronID('mvaTrigV0') > 0.0)"
    if not conf.Electrons.reverseIsoCut:
        #Top ref. sel.
        #https://twiki.cern.ch/twiki/bin/view/CMS/TWikiTopRefEventSel
        goodSignalElectronCut += "&& (electronID('mvaTrigV0') > %f)" %conf.Electrons.mvaCut

    #Impact parameter dropped because using MVA ID
    #https://hypernews.cern.ch/HyperNews/CMS/get/egamma-elecid/72.html
    #goodSignalElectronCut += " && abs(userFloat('dxy')) < 0.02"
    goodSignalElectronCut += " && userInt('gsfTrack_trackerExpectedHitsInner_numberOfHits') <= 0"

    if conf.Electrons.cutOnIso:
        if conf.Electrons.reverseIsoCut:
        #Choose anti-isolated region
            goodSignalElectronCut += ' && userFloat("{0}") >= {1} && userFloat("{0}") < {2}'.format(
                conf.Electrons.relIsoType,
                conf.Electrons.relIsoCutRangeAntiIsolatedRegion[0],
                conf.Electrons.relIsoCutRangeAntiIsolatedRegion[1]
                )
        #Choose isolated region
        else:
            goodSignalElectronCut += ' && userFloat("{0}") >= {1} && userFloat("{0}") < {2}'.format(
                conf.Electrons.relIsoType,
                conf.Electrons.relIsoCutRangeIsolatedRegion[0],
                conf.Electrons.relIsoCutRangeIsolatedRegion[1]
            )

    #Trigger preselection emulation
    #https://twiki.cern.ch/twiki/bin/viewauth/CMS/MultivariateElectronIdentification#Training_of_the_MVA
    goodSignalElectronCut += " && (\
            (abs(superCluster.eta()) < 1.479 && \
            sigmaIetaIeta() < 0.014 && \
            hadronicOverEm() < 0.15 && \
            dr03TkSumPt()/pt() < 0.2 && \
            dr03EcalRecHitSumEt()/pt() < 0.2 && \
            dr03HcalTowerSumEt()/pt() < 0.2 && \
            userInt('gsfTrack_trackerExpectedHitsInner_numberOfHitsLost') == 0) || \
            (abs(superCluster.eta()) >= 1.479 && \
            sigmaIetaIeta() < 0.035 && \
            hadronicOverEm() < 0.10 && \
            dr03TkSumPt()/pt() < 0.2 && \
            dr03EcalRecHitSumEt()/pt < 0.2 && \
            dr03HcalTowerSumEt()/pt < 0.2 && \
            userInt('gsfTrack_trackerExpectedHitsInner_numberOfHitsLost') == 0)\
        )"
    goodSignalElectronCut = clean_whitespace(goodSignalElectronCut)

    looseVetoElectronCut = "%s > 20.0" % conf.Electrons.pt
    looseVetoElectronCut += " && (abs(superCluster().eta()) < 2.5)"

    #Veto cut based ID: https://twiki.cern.ch/twiki/bin/view/CMS/EgammaCutBasedIdentification
    cutBasedLooseID = " && \
        ((abs(superCluster().eta()) < 1.479 && (\
            abs(deltaEtaSuperClusterTrackAtVtx()) < 0.007 && \
            abs(deltaPhiSuperClusterTrackAtVtx()) < 0.8 && \
            sigmaIetaIeta() < 0.01 && \
            hadronicOverEm() < 0.15 && \
            userFloat('dxy') < 0.04 && \
            userFloat('dz') < 0.2 \
        )) || (\
        abs(superCluster().eta())>1.479 && abs(superCluster().eta())<2.5 && (\
            abs(deltaEtaSuperClusterTrackAtVtx()) < 0.01 && \
            abs(deltaPhiSuperClusterTrackAtVtx()) < 0.7 && \
            sigmaIetaIeta() < 0.03 && \
            userFloat('dxy') < 0.04 && \
            userFloat('dz') < 0.2 \
        )))"
    looseVetoElectronCut += cutBasedLooseID
    looseVetoElectronCut += " && (userFloat('{0}') < {1})".format(conf.Electrons.relIsoType, conf.Electrons.looseVetoRelIsoCut)
    looseVetoElectronCut = clean_whitespace(looseVetoElectronCut)

    #Loose veto electrons must not overlap with good signal electrons
    looseVetoElectronCut += " && !(%s)" % goodSignalElectronCut

    process.goodSignalElectrons = cms.EDFilter("CandViewSelector",
      src=cms.InputTag("electronsWithTriggerMatch"), cut=cms.string(goodSignalElectronCut)
    )

    process.looseVetoElectrons = cms.EDFilter("CandViewSelector",
      src=cms.InputTag("electronsWithCorrectedEcalIso"),
      cut=cms.string(looseVetoElectronCut)
    )

    process.oneIsoEle = cms.EDFilter(
        "PATCandViewCountFilter",
        src=cms.InputTag("goodSignalElectrons"),
        minNumber=cms.uint32(1),
        maxNumber=cms.uint32(1),
    )
#Must throw away multilepton events in order to have unambiguity in reconstruction
    process.noIsoMu = cms.EDFilter(
        "PATCandViewCountFilter",
        src=cms.InputTag("goodSignalMuons"),
        minNumber=cms.uint32(0),
        maxNumber=cms.uint32(0),
    )


    # Scale factors #
    process.electronWeightsProducer = cms.EDProducer("ElectronEfficiencyProducer",
        src = cms.InputTag("singleIsoEle"),

        SFError=cms.double(0.02),
        applyConservativeSyst=cms.bool(True)
    )

    goodMET = metSequence(process, conf, "ele", conf.metSource, "goodSignalLeptons")

    process.recoNuProducerEle = cms.EDProducer('ClassicReconstructedNeutrinoProducer',
        leptonSrc=cms.InputTag("singleIsoEle"),
        bjetSrc=cms.InputTag("btaggedJets"),
        metSrc=cms.InputTag(goodMET)
    )

    if conf.doDebug:
        process.eleAnalyzer = cms.EDAnalyzer('SimpleElectronAnalyzer', interestingCollections=cms.untracked.VInputTag("electronsWithID", "electronsWithIDAll", "electronsWithIso", "goodSignalElectrons", "looseVetoElectrons"))