コード例 #1
0
def makeBoostedJetPLots(self, sel, jets, uname):
    maxJet = 1
    binScaling = 1
    plots = []
    for i in range(maxJet):
        plots.append(
            Plot.make1D(f"{uname}_boostedjet{i+1}_pt",
                        jets[i].pt,
                        sel,
                        EqB(60, 170., 800.),
                        title=f"{utils.getCounter(i+1)} jet p_{{T}} [GeV]",
                        plotopts=utils.getOpts(uname)))
        plots.append(
            Plot.make1D(f"{uname}_boostedjet{i+1}_eta",
                        jets[i].eta,
                        sel,
                        EqB(50 // binScaling, -2.4, 2.4),
                        title=f"{utils.getCounter(i+1)} jet eta",
                        plotopts=utils.getOpts(uname)))
        plots.append(
            Plot.make1D(f"{uname}_boostedjet{i+1}_phi",
                        jets[i].phi,
                        sel,
                        EqB(50 // binScaling, -3.1416, 3.1416),
                        title=f"{utils.getCounter(i+1)} jet phi",
                        plotopts=utils.getOpts(uname)))
        plots.append(
            Plot.make1D(f"{uname}_boostedjet{i+1}_mass",
                        jets[i].phi,
                        sel,
                        EqB(50 // binScaling, -3.1416, 3.1416),
                        title=f"{utils.getCounter(i+1)} jet mass [GeV]",
                        plotopts=utils.getOpts(uname)))

    return plots
コード例 #2
0
def MakeEllipsesPLots(self, sel, bjets, lepton, wp, uname, suffix):
    plots = []
    binScaling = 1
    for key in sel.keys():

        tagger = key.replace(wp, "")
        bjets_ = safeget(bjets, tagger, wp)

        plots.append(
            Plot.make1D(
                "jj_M_{0}_{1}_hZA_lljj_{2}_mll_and_met_cut".format(
                    suffix, uname, key),
                op.invariant_mass(bjets_[0].p4, bjets_[1].p4),
                sel.get(key),
                EqB(60 // binScaling, 0., 1000.),
                title="invariant mass of two b-tagged jets wrt {0} Discriminator"
                .format(suffix, key),
                xTitle="mjj {0} {1} [GeV]".format(suffix, key),
                plotopts=utils.getOpts(uname, **{"log-y": False})))

        plots.append(
            Plot.make1D(
                "lljj_M_{0}_{1}_hZA_lljj_{2}_mll_and_met_cut".format(
                    suffix, uname, key), (lepton[0].p4 + lepton[1].p4 +
                                          bjets_[0].p4 + bjets_[1].p4).M(),
                sel.get(key),
                EqB(60 // binScaling, 0., 1000.),
                title=
                "invariant mass of 2 leptons two b-tagged jets wrt {0} Discriminator"
                .format(suffix, key),
                xTitle="mlljj {0} {1} [GeV]".format(suffix, key),
                plotopts=utils.getOpts(uname, **{"log-y": False})))

        plots.append(
            Plot.make2D(
                "Mjj_vs_Mlljj_{0}_{1}_hZA_lljj_{2}_mll_and_met_cut".format(
                    suffix, uname,
                    key), (op.invariant_mass(bjets_[0].p4, bjets_[1].p4),
                           (lepton[0].p4 + lepton[1].p4 + bjets_[0].p4 +
                            bjets_[1].p4).M()),
                sel.get(key), (EqB(60 // binScaling, 0.,
                                   1000.), EqB(60 // binScaling, 0., 1000.)),
                title="mlljj vs mjj invariant mass {0} wrt {1} Discriminator".
                format(suffix, key),
                plotopts=utils.getOpts(uname, **{"log-y": False})))

        plots.append(
            Plot.make1D(
                "ll_M_{0}_{1}_hZA_lljj_{2}_mll_and_met_cut".format(
                    suffix, uname, key),
                op.invariant_mass(lepton[0].p4, lepton[1].p4),
                sel.get(key),
                EqB(60 // binScaling, 70., 110.),
                title=" dilepton invariant mass {0} wrt {1} Discriminator".
                format(suffix, key),
                xTitle="mll {0} {1} [GeV]".format(suffix, key),
                plotopts=utils.getOpts(uname)))
    return plots
コード例 #3
0
def makeControlPlotsForZpic(self, sel, lepton, uname):
    plots = []
    for i in range(2):
        if "mu" in uname:
            flav = "Muon"
        if "el" in uname:
            flav = "Electron"

        plots.append(
            Plot.make1D(f"{uname}_lep{i+1}_pt",
                        lepton[i].pt,
                        sel,
                        EqB(60 // binScaling, 30., 530.),
                        title="%s p_{T} [GeV]" % flav,
                        plotopts=utils.getOpts(uname)))
        plots.append(
            Plot.make1D(f"{uname}_lep{i+1}_eta",
                        lepton[i].eta,
                        sel,
                        EqB(50 // binScaling, -2.4, 2.4),
                        title="%s eta" % flav,
                        plotopts=utils.getOpts(uname, **{"log-y": False})))
        plots.append(
            Plot.make1D(f"{uname}_lep{i+1}_phi",
                        lepton[i].phi,
                        sel,
                        EqB(50 // binScaling, -3.1416, 3.1416),
                        title="%s phi" % flav,
                        plotopts=utils.getOpts(uname, **{"log-y": False})))

        plots.append(
            Plot.make1D("{0}_mll".format(uname),
                        op.invariant_mass(lepton[0].p4, lepton[1].p4),
                        sel,
                        EqB(60, 70., 110.),
                        title="mll [GeV]",
                        plotopts=utils.getOpts(uname)))
        plots.append(
            Plot.make1D("{0}_llpT".format(uname),
                        (dilepton[0].p4 + dilepton[1].p4).Pt(),
                        sel,
                        EqB(60, 0., 450.),
                        title="dilepton P_{T} [GeV]",
                        plotopts=utils.getOpts(uname)))
    # FIXME
    #plots.append(Plot.make1D("{0}_nVX".format(uname),
    #            t.PV.npvs, sel,
    #            EqB(10, 0., 60.),
    #            title="Distrubtion of the number of the reconstructed vertices",
    #            xTitle="number of reconstructed vertices "))
    #plots.append(Plot.make2D("{0}_Electron_dzdxy".format(uname),
    #            (lepton[0].dz ,lepton[0].dxy), sel,
    #            (EqB(10, 0., 2.),
    #            EqB(10, 0., 2.)) ,
    #            title="Electron in Barrel/EndCAP region" ))
    return plots
コード例 #4
0
def MakeExtraMETPlots(self, sel, lepton, met, uname, suffix):
    binScaling = 1
    plots = []
    for key in sel.keys():

        plots.append(
            Plot.make1D("{0}_{1}_{2}_MET_pt".format(uname, key, suffix),
                        met.pt,
                        sel.get(key),
                        EqB(60 // binScaling, 0., 600.),
                        title="MET p_{T} [GeV]",
                        plotopts=utils.getOpts(uname, **{"log-y": False})))
        plots.append(
            Plot.make1D("{0}_{1}_{2}_MET_phi".format(uname, key, suffix),
                        met.phi,
                        sel.get(key),
                        EqB(60 // binScaling, -3.1416, 3.1416),
                        title="MET #phi",
                        plotopts=utils.getOpts(uname, **{"log-y": False})))
        plots.append(
            Plot.make1D("{0}_{1}_{2}_MET_eta".format(uname, key, suffix),
                        met.phi,
                        sel.get(key),
                        EqB(60 // binScaling, -2.4, 2.4),
                        title="MET #eta",
                        plotopts=utils.getOpts(uname, **{"log-y": False})))

        for i in range(2):
            plots.append(
                Plot.make1D(
                    f"{uname}_{key}_{suffix}_MET_lep{i+1}_deltaPhi".format(
                        uname=uname, key=key, suffix=suffix),
                    op.Phi_mpi_pi(lepton[i].phi - met.phi),
                    sel.get(key),
                    EqB(60 // binScaling, -3.1416, 3.1416),
                    title="#Delta #phi (lepton, MET)",
                    plotopts=utils.getOpts(uname, **{"log-y": False})))

            MT = op.sqrt(
                2. * met.pt * lepton[i].p4.Pt() *
                (1. - op.cos(op.Phi_mpi_pi(met.phi - lepton[i].p4.Phi()))))
            plots.append(
                Plot.make1D(f"{uname}_{key}_{suffix}_MET_MT_lep{i+1}".format(
                    uname=uname, key=key, suffix=suffix),
                            MT,
                            sel.get(key),
                            EqB(60 // binScaling, 0., 600.),
                            title="Lepton M_{T} [GeV]",
                            plotopts=utils.getOpts(uname, **{"log-y": False})))
    return plots
コード例 #5
0
ファイル: tt5TeV.py プロジェクト: pieterdavid/tt5TeVCMSDAS
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        from bamboo.plots import Plot, CutFlowReport, SummedPlot
        from bamboo.plots import EquidistantBinning as EqB
        from bamboo import treefunctions as op

        isMC = self.isMC(sample)
        if isMC:
            noSel = noSel.refine("mcWeight", weight=[t.genWeight])
        noSel = noSel.refine(
            "trig",
            cut=op.OR(t.HLT.HIL3DoubleMu0,
                      t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ))

        plots = []

        muons = op.select(t.Muon, lambda mu: mu.pt > 20.)
        twoMuSel = noSel.refine("twoMuons", cut=[op.rng_len(muons) > 1])
        plots.append(
            Plot.make1D("dimu_M",
                        op.invariant_mass(muons[0].p4, muons[1].p4),
                        twoMuSel,
                        EqB(100, 20., 120.),
                        title="Dimuon invariant mass",
                        plotopts={
                            "show-overflow": False,
                            "legend-position": [0.2, 0.6, 0.5, 0.9]
                        }))

        return plots
コード例 #6
0
def makeResolvedBJetPlots(self, sel, bjets, wp, uname):
    plots = []
    binScaling = 1
    for key in sel.keys():

        tagger = key.replace(wp, "")
        bjets_ = safeget(bjets, tagger, wp)

        plots.append(
            Plot.make1D("{0}_nBJets_{1}".format(uname, key),
                        op.rng_len(bjets_),
                        sel.get(key),
                        EqB(5, 2., 6.),
                        xTitle="Jets multiplicty {0}".format(key),
                        plotopts=utils.getOpts(uname)))
        for i in range(1):
            plots.append(
                Plot.make1D(
                    f"{uname}_bjet{i+1}_pT_{key}",
                    bjets_[i].pt,
                    sel.get(key),
                    EqB(60, 0., 800.),
                    title=
                    f"{utils.getCounter(i+1)}-highest bjet pT {key} [GeV]",
                    plotopts=utils.getOpts(uname)))

            plots.append(
                Plot.make1D(
                    f"{uname}_bjet{i+1}_eta_{key}",
                    bjets_[i].eta,
                    sel.get(key),
                    EqB(50 // binScaling, -2.4, 2.4),
                    title=f"{utils.getCounter(i+1)}-highest bjet eta {key}",
                    plotopts=utils.getOpts(uname)))

            plots.append(
                Plot.make1D(
                    f"{uname}_bjet{i+1}_eta_{key}",
                    bjets_[i].phi,
                    sel.get(key),
                    EqB(50 // binScaling, -3.1416, 3.1416),
                    title=f"{utils.getCounter(i+1)}-highest bjet phi {key}",
                    plotopts=utils.getOpts(uname)))
    return plots
コード例 #7
0
def makeControlPlotsForFinalSel(self, sel, bjets, dilepton, uname):
    plots = []
    binScaling = 1
    for key in sel.keys():

        tagger = key.replace(wp, "")
        bjets_ = safeget(bjets, tagger, wp)

        plots.append(
            Plot.make1D("{0}_TwoBtaggedJets_pT_{1}".format(uname, key),
                        (bjets_[0].p4 + bjets_[1].p4).Pt(),
                        sel.get(key),
                        EqB(60, 170., 800.),
                        title="di-bjet P_{T} [GeV]",
                        plotopts=utils.getOpts(uname)))

        plots.append(
            Plot.make1D("{0}_mlljj_btagged_{1}".format(uname, key),
                        (lepton[0].p4 + lepton[1].p4 + bjets_[0].p4 +
                         bjets_[1].p4).M(),
                        sel.get(key),
                        EqB(60, 170., 1000.),
                        title="mlljj [GeV]",
                        plotopts=utils.getOpts(uname)))

        plots.append(
            Plot.make1D("{0}_mjj_btagged_{1}".format(uname, key),
                        op.invariant_mass(bjets_[0].p4 + bjets_[1].p4),
                        sel.get(key),
                        EqB(60, 170., 800.),
                        title="mjj [GeV]",
                        plotopts=utils.getOpts(uname)))

        plots.append(
            Plot.make2D("{0}_mlljjvsmjj_btagged_{1}".format(uname, key),
                        (op.invariant_mass(bjets_[0].p4 + bjets_[1].p4),
                         (lepton[0].p4 + lepton[1].p4 + bjets_[0].p4 +
                          bjets_[1].p4).M()),
                        sel.get(key),
                        (EqB(60, 170., 1000.), EqB(60, 170., 1000.)),
                        title="mlljj vs mjj invariant mass [GeV]",
                        plotopts=utils.getOpts(uname)))
    return plots
コード例 #8
0
def makeBoostedJetPLots(self, sel, bjets, wp, uname):
    maxJet = 1
    binScaling = 1
    plots = []

    for key in sel.keys():
        tagger = key.replace(wp, "")
        bjets_ = safeget(bjets, tagger, wp)

        for i in range(maxJet):
            plots.append(
                Plot.make1D(f"{uname}_boostedjet{i+1}_pt",
                            bjets_[i].pt,
                            sel,
                            EqB(60, 170., 800.),
                            title=f"{utils.getCounter(i+1)} jet p_{{T}} [GeV]",
                            plotopts=utils.getOpts(uname)))
            plots.append(
                Plot.make1D(f"{uname}_boostedjet{i+1}_eta",
                            bjets_[i].eta,
                            sel,
                            EqB(50 // binScaling, -2.4, 2.4),
                            title=f"{utils.getCounter(i+1)} jet eta",
                            plotopts=utils.getOpts(uname)))
            plots.append(
                Plot.make1D(f"{uname}_boostedjet{i+1}_phi",
                            bjets_[i].phi,
                            sel,
                            EqB(50 // binScaling, -3.1416, 3.1416),
                            title=f"{utils.getCounter(i+1)} jet phi",
                            plotopts=utils.getOpts(uname)))
            plots.append(
                Plot.make1D(f"{uname}_boostedjet{i+1}_mass",
                            bjets_[i].phi,
                            sel,
                            EqB(50 // binScaling, -3.1416, 3.1416),
                            title=f"{utils.getCounter(i+1)} jet mass [GeV]",
                            plotopts=utils.getOpts(uname)))

    return plots
コード例 #9
0
def MakeMETPlots(self, sel, corrmet, met, uname, suffix):
    plots = []
    binScaling = 1
    for key in sel.keys():

        plots.append(
            Plot.make1D("met_pt_{0}_{1}_hZA_lljj_{2}".format(
                suffix, uname, key),
                        met.pt,
                        sel.get(key),
                        EqB(60 // binScaling, 0., 600.),
                        title="MET p_{T} [GeV]",
                        plotopts=utils.getOpts(uname, **{"log-y": False})))
        plots.append(
            Plot.make1D("xycorrmet_pt_{0}_{1}_hZA_lljj_{2}".format(
                suffix, uname, key),
                        corrmet.pt,
                        sel.get(key),
                        EqB(60 // binScaling, 0., 600.),
                        title="corrMET p_{T} [GeV]",
                        plotopts=utils.getOpts(uname, **{"log-y": False})))
    return plots
コード例 #10
0
def makeResolvedJetPlots(self, sel, jets, uname):
    maxJet = 2
    binScaling = 1
    plots = []
    for i in range(maxJet):
        plots.append(
            Plot.make1D(f"{uname}_jet{i+1}_pt",
                        jets[i].pt,
                        sel,
                        EqB(60 // binScaling, 30., 730. - max(4, i) * 100),
                        title=f"{utils.getCounter(i+1)} jet p_{{T}} [GeV]",
                        plotopts=utils.getOpts(uname)))
        plots.append(
            Plot.make1D(f"{uname}_jet{i+1}_eta",
                        jets[i].eta,
                        sel,
                        EqB(50 // binScaling, -2.4, 2.4),
                        title=f"{utils.getCounter(i+1)} jet eta",
                        plotopts=utils.getOpts(uname, **{"log-y": False})))
        plots.append(
            Plot.make1D(f"{uname}_jet{i+1}_phi",
                        jets[i].phi,
                        sel,
                        EqB(50 // binScaling, -3.1416, 3.1416),
                        title=f"{utils.getCounter(i+1)} jet phi",
                        plotopts=utils.getOpts(uname, **{"log-y": False})))

    plots.append(
        Plot.make1D(f"{uname}_jet_DR",
                    op.deltaR(jets[0].p4, jets[1].p4),
                    sel,
                    EqB(50, 0.3, 3.),
                    title="Jets DR",
                    plotopts=utils.getOpts(uname, **{"log-y": False})))
    plots.append(
        Plot.make1D(f"{uname}_jet_M",
                    op.invariant_mass(jets[0].p4, jets[1].p4),
                    sel,
                    EqB(60, 0., 400.),
                    title="dijets invariant mass [GeV]",
                    plotopts=utils.getOpts(uname)))
    plots.append(
        Plot.make1D(f"{uname}_jet_pT", (jets[0].p4 + jets[1].p4).Pt(),
                    sel,
                    EqB(60, 0., 600.),
                    title=" dijets p_{T} [GeV]",
                    plotopts=utils.getOpts(uname)))
    return plots
コード例 #11
0
ファイル: tt5TeV_B.py プロジェクト: beatrizlopes/tt5TeVCMSDAS
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        from bamboo.plots import CutFlowReport, SummedPlot
        from bamboo.plots import EquidistantBinning as EqB
        from bamboo import treefunctions as op

        isMC = self.isMC(sample)
        trigCut, trigWeight = None, None
        if isMC:
            trigCut = op.OR(t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ, t.HLT.HIL3DoubleMu0, t.HLT.HIL3Mu20, t.HLT.HIEle20_WPLoose_Gsf)
            trigWeight = op.switch(op.OR(t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ, t.HLT.HIL3DoubleMu0), op.c_float(1.),
                    op.switch(t.HLT.HIL3Mu20, op.c_float(306.913/308.545), op.c_float(264.410/308.545))) ## FIXME these are wrong - you will get the final values from team A
        else:
            ## trigger order: dielectron, dimuon or single muon, single electron
            pd = sample.split("_")[0]
            if pd == "SingleMuon":
                trigCut = op.AND(op.NOT(t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ),
                    op.OR(t.HLT.HIL3DoubleMu0, t.HLT.HIL3Mu20))
            elif pd == "HighEGJet":
                trigCut = op.OR(t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ,
                    op.AND(op.NOT(op.OR(t.HLT.HIL3DoubleMu0, t.HLT.HIL3Mu20)),
                        t.HLT.HIEle20_WPLoose_Gsf))
        noSel = noSel.refine("trig", cut=trigCut, weight=trigWeight)

        plots = []

        def isGoodElectron(el, ptCut=10.):
            return op.AND(
                el.pt > ptCut,
                op.abs(el.eta) < 2.5,
                el.lostHits == 0, ## do you want this?
                op.abs(el.sip3d) < 8.,
                op.abs(el.dxy) < .05,
                op.abs(el.dz ) < .1,
                el.miniPFRelIso_all < 0.085,
                el.mvaTTH > 0.125,
                op.NOT(op.AND(el.jet.isValid, op.OR(el.jet.btagDeepB > .1522, el.jet.btagDeepB <= -999.)))
                )
        def isGoodMuon(mu, ptCut=10.):
            return op.AND(
                mu.pt > ptCut,
                op.abs(mu.eta) < 2.4,
                mu.mediumPromptId,
                op.abs(mu.sip3d) < 8.,
                op.abs(mu.dxy) < .05,
                op.abs(mu.dz ) < .1,
                mu.miniPFRelIso_all < 0.325,
                mu.mvaTTH > 0.55,
                op.NOT(op.AND(mu.jet.isValid, op.OR(mu.jet.btagDeepB > .1522, mu.jet.btagDeepB <= -999.)))
                )

        goodLeptons = {
            "el" : op.select(t.Electron, partial(isGoodElectron, ptCut=15.)),
            "mu" : op.select(t.Muon, partial(isGoodMuon, ptCut=15.))
            }
        plots += [
            Plot.make1D("trig_nLeptons15", op.rng_len(goodLeptons["el"])+op.rng_len(goodLeptons["mu"]), noSel, EqB(15, 0., 15.)),
            Plot.make1D("trig_nEl15", op.rng_len(goodLeptons["el"]), noSel, EqB(15, 0., 15.)),
            Plot.make1D("trig_nMu15", op.rng_len(goodLeptons["mu"]), noSel, EqB(15, 0., 15.)) 
            ]
        from bamboo.scalefactors import get_scalefactor
        sf_loose = {
            "mu": get_scalefactor("lepton", "Muon_RecoToLoose", sfLib=scalefactors_lepMVA, paramDefs=binningVariables_nano_noScaleSyst, systName="muLoose"),
            "el": get_scalefactor("lepton", "Electron_RecoToLoose", sfLib=scalefactors_lepMVA, paramDefs=binningVariables_nano_noScaleSyst, systName="elLoose")
            }
        sf_tight = {
            "mu": get_scalefactor("lepton", "Muon_LooseToTight", sfLib=scalefactors_lepMVA, paramDefs=binningVariables_nano_noScaleSyst, systName="muTight"),
            "el": get_scalefactor("lepton", "Electron_LooseToTight", sfLib=scalefactors_lepMVA, paramDefs=binningVariables_nano_noScaleSyst, systName="elTight")
            }

        nGoodLeptons = op.rng_len(goodLeptons["el"])+op.rng_len(goodLeptons["mu"])
        hasTwoGoodLeptons = noSel.refine("has2Lep", cut=(nGoodLeptons > 1)) # avoid overlap with 1l
        jets = op.sort(op.select(t.Jet, lambda j : op.AND(
            j.pt > 25.,
            op.abs(j.eta) < 2.4,
            j.jetId & 0x2,
            op.AND(
                op.NOT(op.rng_any(goodLeptons["el"], lambda l : op.deltaR(l.p4, j.p4) < 0.4)),
                op.NOT(op.rng_any(goodLeptons["mu"], lambda l : op.deltaR(l.p4, j.p4) < 0.4)))
            )), lambda j : -j.pt)
        ## WP: see https://twiki.cern.ch/twiki/bin/viewauth/CMS/BtagRecommendation94X
        loosebjets = op.select(jets, lambda j : j.btagDeepB > 0.1522)
        mediumbjets = op.select(jets, lambda j : j.btagDeepB > 0.4941)
        for fl1,fl2 in product(*repeat(goodLeptons.keys(), 2)):
            dilepSel = lambda l1,l2 : op.AND(
                    l1.charge != l2.charge,
                    (l1.p4+l2.p4).M() > 12.
                    )
            if fl1 == fl2:
                lGood = op.sort(goodLeptons[fl1], lambda l : -l.pt)
                dilep = op.combine(lGood, N=2, pred=dilepSel)
            else:
                l1Good = op.sort(goodLeptons[fl1], lambda l : -l.pt)
                l2Good = op.sort(goodLeptons[fl2], lambda l : -l.pt)
                dilep = op.combine((l1Good, l2Good), pred=dilepSel)
            ll = dilep[0]
            hasDilep = hasTwoGoodLeptons.refine(f"hasDilep{fl1}{fl2}", cut=(op.rng_len(dilep) > 0, ll[0].pt > 25.),
                    weight=([ sf_loose[fl1](ll[0]), sf_loose[fl2](ll[1]), sf_tight[fl1](ll[0]), sf_tight[fl2](ll[1]) ] if isMC else None))
            plots += [
                Plot.make1D(f"dilepton_{fl1}{fl2}_Mll", (ll[0].p4+ll[1].p4).M(), hasDilep, EqB(50, 70, 120.), title="Dilepton mass"),
                ]
#            for il,ifl in enumerate((fl1, fl2)):
##                plots += [
#                    Plot.make1D(f"dilepton_{fl1}{fl2}_L{il:d}PT", ll[il].pt, hasDilep, EqB(50, 0., 100.), title=f"Lepton {il:d} PT"),
#                    Plot.make1D(f"dilepton_{fl1}{fl2}_L{il:d}ETA", ll[il].eta, hasDilep, EqB(50, -2.5, 2.5), title=f"Lepton {il:d} ETA"),
#                    ]
#            plots += [
#                Plot.make1D(f"dilepton_{fl1}{fl2}_nJets", op.rng_len(jets), hasDilep, EqB(15, 0, 15.), title="Jet multiplicity"),
#                Plot.make1D(f"dilepton_{fl1}{fl2}_nLooseBJets", op.rng_len(loosebjets), hasDilep, EqB(15, 0, 15.), title="Loose b-jet multiplicity"),
#                Plot.make1D(f"dilepton_{fl1}{fl2}_nMediumBJets", op.rng_len(mediumbjets), hasDilep, EqB(15, 0, 15.), title="Medium b-jet multiplicity")
#                ]

        return plots
コード例 #12
0
 def __init__(self, name):
     self.name = name
     self.plotopts = dict()
     self.axisTitles = ("Yield", )
     self.binnings = [EqB(1, 0., 1.)]
コード例 #13
0
ファイル: tt5TeV.py プロジェクト: akssikdar/tt5TeVCMSDAS
    def createHistos(self):
    ''' Create all the histos for the analysis '''

        ### Analysis histos
        for key_chan in channel:
        ichan = channnel[key_chan]

        # Event
        self.NewHisto('HT',   ichan, 80, 0, 400)
        self.NewHisto('MET',  ichan, 30, 0, 150)
        self.NewHisto('NJets',ichan, 8 ,-0.5, 7.5)
        self.NewHisto('Btags',ichan, 4 ,-0.5, 3.5)
        self.NewHisto('Vtx',  ichan, 10, -0.5, 9.5)
        self.NewHisto('NBtagNJets', ichan, 7, -0.5, 6.5)
        self.NewHisto('NBtagNJets_3bins', ichan, 3, -0.5, 2.5)
        # Leptons
        self.NewHisto('Lep0Pt', ichan, 20, 20, 120)
        self.NewHisto('Lep1Pt', ichan, 16, 10, 90)
        self.NewHisto('Lep0Eta', ichan, 50, -2.5, 2.5)
        self.NewHisto('Lep1Eta', ichan, 50, -2.5, 2.5)
        self.NewHisto('Lep0Phi', ichan, 20, -1, 1)
        self.NewHisto('Lep1Phi', ichan, 20, -1, 1)
        self.NewHisto('DilepPt', ichan, 40, 0, 200)
        self.NewHisto('InvMass', ichan, 60, 0, 300)
        self.NewHisto('DYMass',  ichan, 200, 70, 110)
        self.NewHisto('DYMassBB',  ichan, 200, 70, 110)
        self.NewHisto('DYMassBE',  ichan, 200, 70, 110)
        self.NewHisto('DYMassEB',  ichan, 200, 70, 110)
        self.NewHisto('DYMassEE',  ichan, 200, 70, 110)
        self.NewHisto('DeltaPhi',  ichan, 20, 0, 1)
        if ichan == chan[ch.ElMu]:
           self.NewHisto('ElecEta', 'ElMu', 50, -2.5, 2.5)
           self.NewHisto('MuonEta', 'ElMu', 50, -2.5, 2.5)
           self.NewHisto('ElecPt', 'ElMu', 20, 10, 110)
           self.NewHisto('MuonPt', 'ElMu', 20, 10, 110)
           self.NewHisto('ElecPhi', 'ElMu', 20, -1, 1)
           self.NewHisto('MuonPhi', 'ElMu', 20, -1, 1)

    def FillHistograms(self, leptons, jets, pmet, ich, ilev, isys):
    ''' Fill all the histograms. Take the inputs from lepton list, jet list, pmet '''
        if self.SS: return               # Do not fill histograms for same-sign events
        if not len(leptons) >= 2: return # Just in case
    
        # Re-calculate the observables
        lep0  = leptons[0]; lep1 = leptons[1]
        l0pt  = lep0.Pt();  l1pt  = lep1.Pt()
        l0eta = lep0.Eta(); l1eta = lep1.Eta()
        l0phi = lep0.Phi(); l1phi = lep1.Phi()
        dphi  = DeltaPhi(lep0, lep1)
        mll   = InvMass(lep0, lep1)
        dipt  = DiPt(lep0, lep1)
        mupt  = 0; elpt  = 0
        mueta = 0; eleta = 0
        muphi = 0; elphi = 0
        if ich == channel.ElMu:
           if lep0.IsMuon():
           mu = lep0
           el = lep1
        else:
           mu = lep1
           el = lep0
        elpt  = el.Pt();  mupt  = mu.Pt()
        eleta = el.Eta(); mueta = mu.Eta()
        elphi = el.Phi(); muphi = mu.Phi()
          
        met = pmet.Pt()
        ht = 0; 
   
    
        ### Fill the histograms
        #if ich == ch.ElMu and ilev == lev.dilepton: print 'Syst = ', isys, ', weight = ', self.weight
        self.GetHisto('HT',   ich).Fill(ht)
        self.GetHisto('MET',  ich).Fill(met)
        self.GetHisto('NJets',ich).Fill(njet)
        self.GetHisto('Btags',ich).Fill(nbtag)
        self.GetHisto('Vtx',  ich).Fill(self.nvtx)
        self.GetHisto("InvMass", ich, ).Fill(mll)

    
       # Leptons
       self.GetHisto('Lep0Pt', ich).Fill(l0pt)
       self.GetHisto('Lep1Pt', ich).Fill(l1pt)
       self.GetHisto('Lep0Eta', ich).Fill(l0eta)
       self.GetHisto('Lep1Eta', ich).Fill(l1eta)
       self.GetHisto('Lep0Phi', ich).Fill(l0phi/3.141592)
       self.GetHisto('Lep1Phi', ich).Fill(l1phi/3.141592)
       self.GetHisto('DilepPt', ich).Fill(dipt, self.weight)
       self.GetHisto('DeltaPhi',  ich).Fill(dphi/3.141592)
       self.GetHisto('InvMass', ich).Fill(mll, self.weight)
       if mll > 70 and mll < 110: 
          self.GetHisto('DYMass',  ich).Fill(mll)
       l0eta = abs(l0eta); l1eta = abs(l1eta)
       if ich == chan.ElEl:
          if   l0eta <= 1.479 and l1eta <= 1.479: self.GetHisto('DYMassBB',  ich).Fill(mll)
          elif l0eta <= 1.479 and l1eta  > 1.479: self.GetHisto('DYMassBE',  ich).Fill(mll)
          elif l0eta  > 1.479 and l1eta <= 1.479: self.GetHisto('DYMassEB',  ich).Fill(mll)
          elif l0eta  > 1.479 and l1eta  > 1.479: self.GetHisto('DYMassEE',  ich).Fill(mll)
      if ich == chan.ElMu:
         self.GetHisto('ElecEta', ich).Fill(eleta)
         self.GetHisto('ElecPt',  ich).Fill(elpt)
         self.GetHisto('ElecPhi', ich).Fill(elphi)
         self.GetHisto('MuonEta', ich).Fill(mueta)
         self.GetHisto('MuonPt',  ich).Fill(mupt)
         self.GetHisto('MuonPhi', ich).Fill(muphi)


        muons = op.select(t.Muon, lambda mu : mu.pt > 20.)
        twoMuSel = noSel.refine("twoMuons", cut=[ op.rng_len(muons) > 1 ])
        plots.append(Plot.make1D("dimu_M",
            op.invariant_mass(muons[0].p4, muons[1].p4), twoMuSel, EqB(100, 20., 120.),
            title="Dimuon invariant mass", plotopts={"show-overflow":False,
            "legend-position": [0.2, 0.6, 0.5, 0.9]}))

        electrons = op.select(t.Electron, lambda el : el.pt > 22.)
        twoElSel = noSel.refine("twoElectrons", cut=[ op.rng_len(electrons) > 1 ])
        plots.append(Plot.make1D("diel_M",
            op.invariant_mass(electrons[0].p4, electrons[1].p4), twoElSel, EqB(100, 20., 120.),
            title="Dielectron invariant mass", plotopts={"show-overflow":False,
            "legend-position": [0.2, 0.6, 0.5, 0.9]}))



        return plots
コード例 #14
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        from bamboo.plots import Plot, CutFlowReport
        from bamboo.plots import EquidistantBinning as EqB
        from bamboo import treefunctions as op

        plots = []

        #definitions

        electrons = op.select(t.elec, lambda el : op.AND(
        el.pt > 20., op.abs(el.eta) < 2.5
        ))
        
        muons = op.select(t.muon, lambda mu : op.AND(
        mu.pt > 20., op.abs(mu.eta) < 2.5
        ))
        
        cleanedElectrons = op.select(electrons, lambda el : op.NOT(
        op.rng_any(muons, lambda mu : op.deltaR(el.p4, mu.p4) < 0.3 )
        ))

        # we are taking the second isopass to be on which is equal to the medium working point
        isolatedElectrons = op.select(cleanedElectrons, lambda el : el.isopass & (1<<2) )
        
        identifiedElectrons = op.select(isolatedElectrons, lambda el : el.idpass & (1<<2) )
        
        cleanedMuons = op.select(muons, lambda mu : op.NOT(
        op.rng_any(electrons, lambda el : op.deltaR(mu.p4, el.p4) < 0.3 )
        ))
        
        isolatedMuons = op.select(cleanedMuons, lambda mu : mu.isopass & (1<<2) )
        
        identifiedMuons = op.select(isolatedMuons, lambda mu : mu.idpass & (1<<2) )
        
        InvMassMuMU = op.invariant_mass(identifiedMuons[0].p4, identifiedMuons[1].p4 )
        
        cleanedJets = op.select(t.jetpuppi, lambda j : op.AND(
        op.NOT(op.rng_any(identifiedElectrons, lambda el : op.deltaR(el.p4, j.p4) < 0.3) ),
        op.NOT(op.rng_any(identifiedMuons, lambda mu : op.deltaR(mu.p4, j.p4) < 0.3) )
        ))

        cleanedGoodJets = op.select(cleanedJets, lambda j : op.AND(
        j.pt > 30, op.abs(j.eta) < 2.5
        ))

        btaggedJets = op.select(cleanedGoodJets, lambda j : j.btag & (1<<2))

        met = op.select(t.metpuppi)

        #selections

        #selection1 : Oppositely charged MuMu selection
        sel1 = noSel.refine("nmumu", cut = [op.AND(
            (op.rng_len(identifiedMuons) > 1), (op.product(identifiedMuons[0].charge, identifiedMuons[1].charge) < 0 ))]) 

        #selection2 : Invariant mass selection
        sel2 = sel1.refine("InvM", cut = [op.NOT(op.in_range(76, InvMassMuMU, 106))])

        #selection3 : two jets selection
        sel3 = sel2.refine("njet", cut = [op.rng_len(cleanedGoodJets) > 1])
    
        #selection4 : at least 1 among two leading jets is b-tagged
        sel4 = sel3.refine("btag", cut = [op.OR(
            cleanedGoodJets[0].btag & (1<<2), cleanedGoodJets[1].btag & (1<<2))])

        #selection5 : MET > 40 GeV
        sel5 = sel4.refine("MET", cut = [met[0].pt > 40])

        #plots
            
            #noSel
        plots.append(Plot.make1D("nJetsNoSel", op.rng_len(cleanedGoodJets), noSel, EqB(10, 0., 10.), title="nJets"))

        plots.append(Plot.make1D("nbtaggedJetsNoSel", op.rng_len(btaggedJets), noSel, EqB(10, 0., 10.), title="nbtaggedJets"))
  
        plots.append(Plot.make1D("nMuNoSel", op.rng_len(identifiedMuons), noSel, EqB(15, 0., 15.), title="nMuons"))
        
        plots.append(Plot.make1D("METptNoSel", met[0].pt, noSel, EqB(50, 0., 250), title="MET_PT"))
        
            #sel1
        
        plots.append(Plot.make1D("nJetsSel1", op.rng_len(cleanedGoodJets), sel1, EqB(10, 0., 10.), title="nJets"))

        plots.append(Plot.make1D("nbtaggedJetsSel1", op.rng_len(btaggedJets), sel1, EqB(10, 0., 10.), title="nbtaggedJets"))

        plots.append(Plot.make1D("nMuSel1", op.rng_len(identifiedMuons), sel1, EqB(10, 0., 10.), title="nMuons"))

        plots.append(Plot.make1D("InvMassTwoMuonsSel1", InvMassMuMU, sel1, EqB(30, 0, 300), title="m(ll)"))
                  
        plots.append(Plot.make1D("LeadingMuonPTSel1", muons[0].pt, sel1, EqB(30, 0., 250.), title=" Leading Muon PT"))
            
        plots.append(Plot.make1D("SubLeadingMuonPTSel1", muons[1].pt, sel1, EqB(30, 0., 250.), title="SubLeading Muon PT"))

        plots.append(Plot.make1D("LeadingMuonEtaSel1", muons[0].eta, sel1, EqB(30, -3, 3), title=" Leading Muon eta"))
            
        plots.append(Plot.make1D("SubLeadingMuonEtaSel1", muons[1].eta, sel1, EqB(30, -3, 3), title="SubLeading Muon eta"))
        
        plots.append(Plot.make1D("METptSel1", met[0].pt, sel1, EqB(50, 0., 250), title="MET_PT"))
                            
            #sel2

        plots.append(Plot.make1D("nJetsSel2", op.rng_len(cleanedGoodJets), sel2, EqB(10, 0., 10.), title="nJets"))

        plots.append(Plot.make1D("nbtaggedJetsSel2", op.rng_len(btaggedJets), sel2, EqB(10, 0., 10.), title="nbtaggedJets"))

        plots.append(Plot.make1D("nMuSel2", op.rng_len(identifiedMuons), sel2, EqB(10, 0., 10.), title="nMuons"))

        plots.append(Plot.make1D("InvMassTwoMuonsSel2", InvMassMuMU, sel2, EqB(20, 20., 300.), title="m(ll)"))
        
        plots.append(Plot.make1D("LeadingMuonPTSel2", muons[0].pt, sel2, EqB(30, 0., 250.), title=" Leading Muon PT"))

        plots.append(Plot.make1D("SubLeadingMuonPTSel2", muons[1].pt, sel2, EqB(30, 0., 200.), title=" SubLeading Muon PT"))

        plots.append(Plot.make1D("LeadingMuonEtaSel2", muons[0].eta, sel2, EqB(30, -3, 3), title=" Leading Muon Eta"))
            
        plots.append(Plot.make1D("SubLeadingMuonEtaSel2", muons[1].eta, sel2, EqB(30, -3, 3), title=" SubLeading Muon Eta"))

        plots.append(Plot.make1D("METptSel2", met[0].pt, sel2, EqB(50, 0., 250), title="MET_PT"))
                        
            #sel3
            
        plots.append(Plot.make1D("nJetsSel3", op.rng_len(cleanedGoodJets), sel3, EqB(10, 0., 10.), title="nJets"))

        plots.append(Plot.make1D("nbtaggedJetsSel3", op.rng_len(btaggedJets), sel3, EqB(10, 0., 10.), title="nbtaggedJets"))

        plots.append(Plot.make1D("LeadingJetPTSel3", cleanedGoodJets[0].pt, sel3, EqB(50, 0., 350.), title="Leading jet PT"))
            
        plots.append(Plot.make1D("SubLeadingJetPTSel3", cleanedGoodJets[1].pt, sel3, EqB(50, 0., 350.), title="SubLeading jet PT"))
            
        plots.append(Plot.make1D("LeadingJetEtaSel3", cleanedGoodJets[0].eta, sel3, EqB(30, -3, 3), title="Leading jet Eta"))
            
        plots.append(Plot.make1D("SubLeadingJetEtaSel3", cleanedGoodJets[1].eta, sel3, EqB(30, -3, 3), title="SubLeading jet Eta"))

        plots.append(Plot.make1D("nMuSel3", op.rng_len(identifiedMuons), sel3, EqB(10, 0., 10.), title="nMuons"))
        
        plots.append(Plot.make1D("LeadingMuonPTSel3", muons[0].pt, sel3, EqB(30, 0., 250.), title=" Leading Muon PT"))
            
        plots.append(Plot.make1D("SubLeadingMuonPTSel3", muons[1].pt, sel3, EqB(30, 0., 200.), title=" SubLeading Muon PT"))

        plots.append(Plot.make1D("LeadingMuonEtaSel3", muons[0].eta, sel3, EqB(30, -3, 3), title=" Leading Muon Eta"))
            
        plots.append(Plot.make1D("SubLeadingMuonEtaSel3", muons[1].eta, sel3, EqB(30, -3, 3), title=" SubLeading Muon Eta"))
                
        plots.append(Plot.make1D("InvMassTwoMuonsSel3", InvMassMuMU, sel3, EqB(30, 0, 300), title="m(ll)"))
        
        plots.append(Plot.make1D("METptSel3", met[0].pt, sel3, EqB(50, 0., 250), title="MET_PT"))
        
            #sel4
             
        plots.append(Plot.make1D("nJetsSel4", op.rng_len(cleanedGoodJets), sel4, EqB(10, 0, 10), title="nJets"))

        plots.append(Plot.make1D("nbtaggedJetsSel4", op.rng_len(btaggedJets), sel4, EqB(10, 0., 10.), title="nbtaggedJets"))

        plots.append(Plot.make1D("LeadingJetPTSel4", cleanedGoodJets[0].pt, sel4, EqB(50, 0., 250.), title="Leading jet PT"))
            
        plots.append(Plot.make1D("SubLeadingJetPTSel4", cleanedGoodJets[1].pt, sel4, EqB(50, 0., 250.), title="SubLeading jet PT"))
            
        plots.append(Plot.make1D("LeadingJetEtaSel4", cleanedGoodJets[0].eta, sel4, EqB(30, -3, 3.), title="Leading jet Eta"))
            
        plots.append(Plot.make1D("SubLeadingJetEtaSel4", cleanedGoodJets[1].eta, sel4, EqB(30, -3, 3.), title="SubLeading jet Eta"))
        
        plots.append(Plot.make1D("nMuSel4", op.rng_len(identifiedMuons), sel4, EqB(10, 0., 10.), title="nMuons"))
                
        plots.append(Plot.make1D("LeadingMuonPTSel4", muons[0].pt, sel4, EqB(30, 0., 250.), title=" Leading Muon PT"))
        
        plots.append(Plot.make1D("SubLeadingMuonPTSel4", muons[1].pt, sel4, EqB(30, 0., 200.), title=" SubLeading Muon PT"))
        
        plots.append(Plot.make1D("LeadingMuonEtaSel4", muons[0].eta, sel4, EqB(30, -3, 3), title=" Leading Muon Eta"))
        
        plots.append(Plot.make1D("SubLeadingMuonEtaSel4", muons[1].eta, sel4, EqB(30, -3, 3), title=" SubLeading Muon Eta"))

        plots.append(Plot.make1D("InvMassTwoMuonsSel4", InvMassMuMU, sel4, EqB(30, 0, 300), title="m(ll)"))
        
        plots.append(Plot.make1D("METptSel4", met[0].pt, sel4, EqB(50, 0., 250), title="MET_PT"))

            #sel5
                
        plots.append(Plot.make1D("nJetsSel5", op.rng_len(cleanedGoodJets), sel5, EqB(10, 0, 10), title="nJets"))

        plots.append(Plot.make1D("nbtaggedJetsSel5", op.rng_len(btaggedJets), sel5, EqB(10, 0., 10.), title="nbtaggedJets"))

        plots.append(Plot.make1D("LeadingJetPTSel5", cleanedGoodJets[0].pt, sel5, EqB(50, 0., 250.), title="Leading jet PT"))
            
        plots.append(Plot.make1D("SubLeadingJetPTSel5", cleanedGoodJets[1].pt, sel5, EqB(50, 0., 250.), title="SubLeading jet PT"))
            
        plots.append(Plot.make1D("LeadingJetEtaSel5", cleanedGoodJets[0].eta, sel5, EqB(30, -3, 3.), title="Leading jet Eta"))
            
        plots.append(Plot.make1D("SubLeadingJetEtaSel5", cleanedGoodJets[1].eta, sel5, EqB(30, -3, 3.), title="SubLeading jet Eta"))
        
        plots.append(Plot.make1D("nMuSel5", op.rng_len(identifiedMuons), sel5, EqB(10, 0., 10.), title="nMuons"))
                
        plots.append(Plot.make1D("LeadingMuonPTSel5", muons[0].pt, sel5, EqB(30, 0., 250.), title=" Leading Muon PT"))
        
        plots.append(Plot.make1D("SubLeadingMuonPTSel5", muons[1].pt, sel5, EqB(30, 0., 200.), title=" SubLeading Muon PT"))
        
        plots.append(Plot.make1D("LeadingMuonEtaSel5", muons[0].eta, sel5, EqB(30, -3, 3), title=" Leading Muon Eta"))
        
        plots.append(Plot.make1D("SubLeadingMuonEtaSel5", muons[1].eta, sel5, EqB(30, -3, 3), title=" SubLeading Muon Eta"))

        plots.append(Plot.make1D("InvMassTwoMuonsSel5", InvMassMuMU, sel5, EqB(30, 0, 300), title="m(ll)"))

        plots.append(Plot.make1D("METptSel5", met[0].pt, sel5, EqB(50, 0., 250), title="MET_PT > 40"))

        # Efficiency Report on terminal and the .tex output

        cfr = CutFlowReport("yields")
        cfr.add(noSel, "Sel0: No selection")
        cfr.add(sel1, "Sel1: nMuMu >= 2")
        cfr.add(sel2, "Sel2: InvM")
        cfr.add(sel3, "Sel3: nJet >= 2")
        cfr.add(sel4, "Sel4: btag")
        cfr.add(sel5, "Sel5: MET")

        plots.append(cfr)
                            
        return plots
コード例 #15
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        from bamboo.plots import Plot, CutFlowReport, SummedPlot
        from bamboo.plots import EquidistantBinning as EqB
        from bamboo import treefunctions as op

        isMC = self.isMC(sample)
        trigCut, trigWeight = None, None
        if isMC:
            noSel = noSel.refine("mcWeight", weight=[ t.genWeight, t.puWeight, t.PrefireWeight ])
            trigCut = op.OR(t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ, t.HLT.HIL3DoubleMu0, t.HLT.HIL3Mu20, t.HLT.HIEle20_WPLoose_Gsf)
            ## TODO add a correction for prescaled triggers
        else:
            ## suggested trigger order: dielectron, dimuon or single muon, single electron (to minimise loss due to prescales). Electron triggered-events should be taken from the HighEGJet primary datasets, muon-triggered events from the SingleMuon primary datset
            pd = sample.split("_")[0]
            if pd == "SingleMuon":
                ## TODO fill trigger cut
            elif pd == "HighEGJet":
                ## TODO fill trigger cut
        noSel = noSel.refine("trig", cut=trigCut, weight=trigWeight)

        plots = []

        goodLeptons = {
            "el" : op.select(t.Electron, partial(isGoodElectron, ptCut=15.)),
            "mu" : op.select(t.Muon, partial(isGoodMuon, ptCut=15.))
            }
        plots += [
            Plot.make1D("trig_nLeptons15", op.rng_len(goodLeptons["el"])+op.rng_len(goodLeptons["mu"]), noSel, EqB(15, 0., 15.)),
            Plot.make1D("trig_nEl15", op.rng_len(goodLeptons["el"]), noSel, EqB(15, 0., 15.)),
            Plot.make1D("trig_nMu15", op.rng_len(goodLeptons["mu"]), noSel, EqB(15, 0., 15.)) 
            ]
        from bamboo.scalefactors import get_scalefactor
        sf_loose = {
            "mu": get_scalefactor("lepton", "Muon_RecoToLoose", sfLib=scalefactors_lepMVA, paramDefs=binningVariables_nano_noScaleSyst, systName="muLoose"),
            "el": get_scalefactor("lepton", "Electron_RecoToLoose", sfLib=scalefactors_lepMVA, paramDefs=binningVariables_nano_noScaleSyst, systName="elLoose")
            }
        sf_tight = {
            "mu": get_scalefactor("lepton", "Muon_LooseToTight", sfLib=scalefactors_lepMVA, paramDefs=binningVariables_nano_noScaleSyst, systName="muTight"),
            "el": get_scalefactor("lepton", "Electron_LooseToTight", sfLib=scalefactors_lepMVA, paramDefs=binningVariables_nano_noScaleSyst, systName="elTight")
            }

        nGoodLeptons = op.rng_len(goodLeptons["el"])+op.rng_len(goodLeptons["mu"])
        hasTwoGoodLeptons = noSel.refine("has2Lep", cut=(nGoodLeptons > 1)) # avoid overlap with 1l
        jets = op.sort(op.select(t.Jet, lambda j : op.AND(
            j.pt > 25., ## you decide...
            op.abs(j.eta) < 2.4,
            j.jetId & 0x2, ## tight JetID
            op.AND( ## lepton-jet cross-cleaning
                op.NOT(op.rng_any(goodLeptons["el"], lambda l : op.deltaR(l.p4, j.p4) < 0.4)),
                op.NOT(op.rng_any(goodLeptons["mu"], lambda l : op.deltaR(l.p4, j.p4) < 0.4)))
            )), lambda j : -j.pt)
        for fl1,fl2 in product(*repeat(goodLeptons.keys(), 2)):
            dilepSel = lambda l1,l2 : op.AND(
                    l1.charge != l2.charge,
                    (l1.p4+l2.p4).M() > 12.
                    )
            if fl1 == fl2:
                lGood = op.sort(goodLeptons[fl1], lambda l : -l.pt)
                dilep = op.combine(lGood, N=2, pred=dilepSel)
            else:
                l1Good = op.sort(goodLeptons[fl1], lambda l : -l.pt)
                l2Good = op.sort(goodLeptons[fl2], lambda l : -l.pt)
                dilep = op.combine((l1Good, l2Good), pred=dilepSel)
            ll = dilep[0]
            hasDilep = hasTwoGoodLeptons.refine(f"hasDilep{fl1}{fl2}", cut=(op.rng_len(dilep) > 0, ll[0].pt > 25.),
                    weight=([ sf_loose[fl1](ll[0]), sf_loose[fl2](ll[1]), sf_tight[fl1](ll[0]), sf_tight[fl2](ll[1]) ] if isMC else None))
            plots += [
                Plot.make1D(f"dilepton_{fl1}{fl2}_Mll", (ll[0].p4+ll[1].p4).M(), hasDilep, EqB(50, 70, 120.), title="Dilepton mass"),
                ]
            for il,ifl in enumerate((fl1, fl2)):
                plots += [
                    Plot.make1D(f"dilepton_{fl1}{fl2}_L{il:d}PT", ll[il].pt, hasDilep, EqB(50, 0., 100.), title=f"Lepton {il:d} PT"),
                    Plot.make1D(f"dilepton_{fl1}{fl2}_L{il:d}ETA", ll[il].eta, hasDilep, EqB(50, -2.5, 2.5), title=f"Lepton {il:d} ETA"),
                    ]
            plots += [
                Plot.make1D(f"dilepton_{fl1}{fl2}_nJets", op.rng_len(jets), hasDilep, EqB(15, 0, 15.), title="Jet multiplicity"),
                ]

        return plots
コード例 #16
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        from bamboo.plots import Plot, CutFlowReport, SummedPlot
        from bamboo.plots import EquidistantBinning as EqB
        from bamboo import treefunctions as op

        isMC = self.isMC(sample)

        if sampleCfg.get("alt-syst"):
            noSel = noSel.refine("withoutsyst", autoSyst=False)

        plots = []

        trigCut, trigWeight = None, None
        if isMC:
            muR = op.systematic(op.c_float(1.),
                                name="muR",
                                up=t.PSWeight[2],
                                down=t.PSWeight[0])
            muF = op.systematic(op.c_float(1.),
                                name="muF",
                                up=t.PSWeight[3],
                                down=t.PSWeight[1])

            noSel = noSel.refine(
                "mcWeight",
                weight=[t.genWeight, t.puWeight, t.PrefireWeight, muR, muF])

            trigCut = op.OR(t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ,
                            t.HLT.HIL3DoubleMu0, t.HLT.HIL3Mu20,
                            t.HLT.HIEle20_WPLoose_Gsf)
            trigWeight = op.switch(
                op.OR(t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ,
                      t.HLT.HIL3DoubleMu0), op.c_float(1.),
                op.switch(t.HLT.HIL3Mu20, op.c_float(306.913 / 308.545),
                          op.c_float(264.410 / 308.545))
            )  ## FIXME these are wrong - you will get the final values from team A

        else:
            ## trigger order: dielectron, dimuon or single muon, single electron
            pd = sample.split("_")[0]
            if pd == "SingleMuon":
                trigCut = op.AND(
                    op.NOT(t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ),
                    op.OR(t.HLT.HIL3DoubleMu0, t.HLT.HIL3Mu20))
            elif pd == "HighEGJet":
                trigCut = op.OR(
                    t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ,
                    op.AND(op.NOT(op.OR(t.HLT.HIL3DoubleMu0, t.HLT.HIL3Mu20)),
                           t.HLT.HIEle20_WPLoose_Gsf))

        noSel = noSel.refine("trig", cut=trigCut, weight=trigWeight)
        #plots += [Plot.make1D("nTotalEvents", op.rng_len([1]), noSel , EqB(1, 0, 1.), title="nTotalEvents")]
        plots.append(
            Plot.make1D("nTotalJets",
                        op.rng_len(t.Jet),
                        noSel,
                        EqB(15, 0, 15.),
                        title="Initial Jet multiplicity"))
        #noSel = noSel.refine("trig", cut=op.OR(t.HLT.HIL3DoubleMu0, t.HLT.HIEle20_Ele12_CaloIdL_TrackIdL_IsoVL_DZ))

        # plots = []
        goodLeptons = {
            "el":
            op.select(
                t.Electron, lambda el: op.AND(el.pt > 15.,
                                              op.abs(el.p4.Eta()) < 2.5)
            ),  # op.select(t.Electron, partial(isGoodElectron, ptCut=15.)),
            "mu":
            op.select(t.Muon, lambda mu: mu.pt > 20.
                      )  # op.select(t.Muon, partial(isGoodMuon, ptCut=15.))
        }
        plots += [
            Plot.make1D(
                "trig_nLeptons15",
                op.rng_len(goodLeptons["el"]) + op.rng_len(goodLeptons["mu"]),
                noSel, EqB(15, 0., 15.)),
            Plot.make1D("trig_nEl15", op.rng_len(goodLeptons["el"]), noSel,
                        EqB(15, 0., 15.)),
            Plot.make1D("trig_nMu15", op.rng_len(goodLeptons["mu"]), noSel,
                        EqB(15, 0., 15.))
        ]
        from bamboo.scalefactors import get_scalefactor
        sf_loose = {
            "mu":
            get_scalefactor("lepton",
                            "Muon_RecoToLoose",
                            sfLib=scalefactors_lepMVA,
                            paramDefs=binningVariables_nano_noScaleSyst,
                            systName="muLoose"),
            "el":
            get_scalefactor("lepton",
                            "Electron_RecoToLoose",
                            sfLib=scalefactors_lepMVA,
                            paramDefs=binningVariables_nano_noScaleSyst,
                            systName="elLoose")
        }
        sf_tight = {
            "mu":
            get_scalefactor("lepton",
                            "Muon_LooseToTight",
                            sfLib=scalefactors_lepMVA,
                            paramDefs=binningVariables_nano_noScaleSyst,
                            systName="muTight"),
            "el":
            get_scalefactor("lepton",
                            "Electron_LooseToTight",
                            sfLib=scalefactors_lepMVA,
                            paramDefs=binningVariables_nano_noScaleSyst,
                            systName="elTight")
        }

        nGoodLeptons = op.rng_len(goodLeptons["el"]) + op.rng_len(
            goodLeptons["mu"])
        hasTwoGoodLeptons = noSel.refine(
            "has2Lep", cut=(nGoodLeptons > 1))  # avoid overlap with 1l
        jets = op.sort(
            op.select(
                t.Jet, lambda j: op.AND(
                    j.pt > 25.,
                    op.abs(j.eta) < 2.4, j.jetId & 0x2,
                    op.AND(
                        op.NOT(
                            op.rng_any(goodLeptons["el"], lambda l: op.deltaR(
                                l.p4, j.p4) < 0.4)),
                        op.NOT(
                            op.rng_any(goodLeptons["mu"], lambda l: op.deltaR(
                                l.p4, j.p4) < 0.4))))), lambda j: -j.pt)
        ## WP: see https://twiki.cern.ch/twiki/bin/viewauth/CMS/BtagRecommendation94X
        loosebjets = op.select(jets, lambda j: j.btagDeepB > 0.1522)
        mediumbjets = op.select(jets, lambda j: j.btagDeepB > 0.4941)
        for fl1, fl2 in product(*repeat(goodLeptons.keys(), 2)):
            dilepSel = lambda l1, l2: op.AND(l1.charge != l2.charge,
                                             (l1.p4 + l2.p4).M() > 12.)
            if fl1 == fl2:
                lGood = op.sort(goodLeptons[fl1], lambda l: -l.pt)
                dilep = op.combine(lGood, N=2, pred=dilepSel)
            else:
                l1Good = op.sort(goodLeptons[fl1], lambda l: -l.pt)
                l2Good = op.sort(goodLeptons[fl2], lambda l: -l.pt)
                dilep = op.combine((l1Good, l2Good), pred=dilepSel)
            ll = dilep[0]
            hasDilep = hasTwoGoodLeptons.refine(
                f"hasDilep{fl1}{fl2}",
                cut=(op.rng_len(dilep) > 0, ll[0].pt > 25.),
                weight=([
                    sf_loose[fl1](ll[0]), sf_loose[fl2](ll[1]), sf_tight[fl1](
                        ll[0]), sf_tight[fl2](ll[1])
                ] if isMC else None))
            plots += [
                Plot.make1D(f"dilepton_{fl1}{fl2}_Mll",
                            (ll[0].p4 + ll[1].p4).M(),
                            hasDilep,
                            EqB(50, 70, 120.),
                            title="Dilepton mass"),
            ]
            for il, ifl in enumerate((fl1, fl2)):
                plots += [
                    Plot.make1D(f"dilepton_{fl1}{fl2}_L{il:d}PT",
                                ll[il].pt,
                                hasDilep,
                                EqB(50, 0., 100.),
                                title=f"Lepton {il:d} PT"),
                    Plot.make1D(f"dilepton_{fl1}{fl2}_L{il:d}ETA",
                                ll[il].eta,
                                hasDilep,
                                EqB(50, -2.5, 2.5),
                                title=f"Lepton {il:d} ETA"),
                ]
            plots += [
                Plot.make1D(f"dilepton_{fl1}{fl2}_nJets",
                            op.rng_len(jets),
                            hasDilep,
                            EqB(15, 0, 15.),
                            title="Jet multiplicity"),
                Plot.make1D(f"dilepton_{fl1}{fl2}_nLooseBJets",
                            op.rng_len(loosebjets),
                            hasDilep,
                            EqB(15, 0, 15.),
                            title="Loose b-jet multiplicity"),
                Plot.make1D(f"dilepton_{fl1}{fl2}_nMediumBJets",
                            op.rng_len(mediumbjets),
                            hasDilep,
                            EqB(15, 0, 15.),
                            title="Medium b-jet multiplicity"),
                #Plot.make1D(f"dilepton_{fl1}{fl2}_nSelectedEvents", 1, hasDilep, EqB(1, 0, 1.), title="nSelectedEvents")
            ]

        #muons = op.select(t.Muon, lambda mu : mu.pt > 20.)
        #twoMuSel = noSel.refine("twoMuons", cut=[ op.rng_len(muons) > 1 ])

        #electrons = op.select(t.Electron, lambda el : op.AND(el.pt > 15. , op.abs(el.p4.Eta()) < 2.5))
        #twoElSel = noSel.refine("twoElectrons", cut=[ op.rng_len(electrons) > 1 ])

        #oselmu = op.combine((electrons, muons))
        #leptons = oselmu[0]
        #twoLepSel = noSel.refine("twoLeptons", cut=[ op.rng_len(electrons) == 1 , op.rng_len(muons) == 1 ])

        #jets = op.select(t.Jet, lambda j : j.pt > 30.)

        #bjets = op.select(jets, lambda j : j.btagDeepFlavB > 0.2217)

        #plots.append(Plot.make1D("dimu_M",
        #    op.invariant_mass(muons[0].p4, muons[1].p4), twoMuSel, EqB(100, 20., 120.),
        #    title="Dimuon invariant mass", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))
        #plots.append(Plot.make1D("diel_M",
        #    op.invariant_mass(electrons[0].p4, electrons[1].p4), twoElSel, EqB(100, 20., 120.),
        #    title="Dielectron invariant mass", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))
        #plots.append(Plot.make1D("dilep_M",
        #    op.invariant_mass(leptons[0].p4, leptons[1].p4) , twoLepSel, EqB(100, 20., 120.),
        #    title="Dimuon invariant mass", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))
        #plots.append(SummedPlot("Mjj", plots, title="m(jj)"))

        #plots.append(Plot.make1D("nJets_dimu",op.rng_len(jets), twoMuSel, EqB(10, -0.5, 9.5),
        #    title="Jet multiplicity", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))

        #plots.append(Plot.make1D("nBJets_dimu",op.rng_len(bjets), twoMuSel, EqB(10, -0.5, 9.5),
        #    title="Jet multiplicity", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))

        #plots.append(Plot.make1D("nJets_diel",op.rng_len(jets), twoElSel, EqB(10, -0.5, 9.5),
        #    title="Jet multiplicity", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))

        #plots.append(Plot.make1D("nBJets_diel",op.rng_len(bjets), twoElSel, EqB(10, -0.5, 9.5),
        #    title="Jet multiplicity", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))

        #plots.append(Plot.make1D("nJets_elmu",op.rng_len(jets), twoLepSel, EqB(10, -0.5, 9.5),
        #    title="Jet multiplicity", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))

        #plots.append(Plot.make1D("nBJets_elmu",op.rng_len(bjets), twoLepSel, EqB(10, -0.5, 9.5),
        #    title="Jet multiplicity", plotopts={"show-overflow":False,
        #    "legend-position": [0.2, 0.6, 0.5, 0.9]}))

        return plots
コード例 #17
0
def makeControlPlotsForBasicSel(self, sel, jets, dilepton, uname):
    binScaling = 1
    plots = []
    plots.append(
        Plot.make1D("{0}_leadJetPT".format(uname),
                    jets[0].pt,
                    sel,
                    EqB(60, 0., 450.),
                    title="P_{T} (leading Jet) [GeV]",
                    plotopts=utils.getOpts(uname)))
    plots.append(
        Plot.make1D("{0}_subleadJetPT".format(uname),
                    jets[1].pt,
                    sel,
                    EqB(60, 0., 450.),
                    title="P_{T} (sub-leading Jet) [GeV]",
                    plotopts=utils.getOpts(uname)))

    plots.append(
        Plot.make1D("{0}_leadJetETA".format(uname),
                    jets[0].eta,
                    sel,
                    EqB(10, -2.4, 2.4),
                    title="Eta (leading Jet)",
                    plotopts=utils.getOpts(uname)))
    plots.append(
        Plot.make1D("{0}_subleadJetETA".format(uname),
                    jets[1].eta,
                    sel,
                    EqB(10, -2.4, 2.4),
                    title="Eta (sub-leading Jet)",
                    plotopts=utils.getOpts(uname)))

    for i in range(2):
        plots.append(
            Plot.make1D(f"{uname}_jet{i+1}_phi",
                        jets[i].phi,
                        sel,
                        EqB(50 // binScaling, -3.1416, 3.1416),
                        title=f"{utils.getCounter(i+1)} jet phi",
                        plotopts=utils.getOpts(uname, **{"log-y": False})))

    plots.append(
        Plot.make1D("{0}_jjpT".format(uname), (jets[0].p4 + jets[1].p4).pt,
                    sel,
                    EqB(100, 0., 450.),
                    title="dijet P_{T} [GeV]",
                    plotopts=utils.getOpts(uname)))

    plots.append(
        Plot.make1D("{0}_jjPhi".format(uname), (jets[0].p4 + jets[1].p4).phi,
                    sel,
                    EqB(50 // binScaling, -3.1416, 3.1416),
                    title="dijet phi",
                    plotopts=utils.getOpts(uname)))

    plots.append(
        Plot.make1D("{0}_jjEta".format(uname), (jets[0].p4 + jets[1].p4).eta,
                    sel,
                    EqB(50 // binScaling, -2.4, 2.4),
                    title="dijet eta",
                    plotopts=utils.getOpts(uname)))

    plots.append(
        Plot.make1D("{0}_mjj".format(uname),
                    op.invariant_mass(jets[0].p4, jets[1].p4),
                    sel,
                    EqB(100, 0., 800.),
                    title="mjj [GeV]",
                    plotopts=utils.getOpts(uname)))

    plots.append(
        Plot.make1D("{0}_mlljj".format(uname),
                    (dilepton[0].p4 + dilepton[1].p4 + jets[0].p4 +
                     jets[1].p4).M(),
                    sel,
                    EqB(100, 0., 1000.),
                    title="mlljj [GeV]",
                    plotopts=utils.getOpts(uname)))
    plots.append(
        Plot.make2D(
            "{0}_mlljjvsmjj".format(uname),
            (op.invariant_mass(jets[0].p4, jets[1].p4),
             (dilepton[0].p4 + dilepton[1].p4 + jets[0].p4 + jets[1].p4).M()),
            sel, (EqB(1000, 0., 1000.), EqB(1000, 0., 1000.)),
            title="mlljj vs mjj invariant mass [Gev]",
            plotopts=utils.getOpts(uname)))
    return plots