def make2DMAPS(sel, jets, suffix, uname):
    plots = []
    plots.append(
        Plot.make2D(
            f"{uname}_{suffix}_jetETA_vs_Phi",
            (op.map(jets, lambda j: j.eta), op.map(jets, lambda j: j.phi)),
            sel, (EqBin(50, -2.5, 2.5), EqBin(50, -2.5, 2.5)),
            title=" Eta vs #phi",
            plotopts=utils.getOpts(uname, **{"log-y": True})))
    #plots.append( Plot.make2D(f"{uname}_{suffix}_jetPT_vs_ETA",(op.map(jets, lambda j : j.pt), op.map(jets, lambda j : j.eta)), sel,
    #    (EqBin(50, 30., 600.), EqBin(50,  -2.5, 2.5)), title=" p_{T} vs Eta",
    #    plotopts=utils.getOpts(uname, **{"log-y": True})))
    lowerPtBinEdges = [30, 50, 70, 100, 140, 200, 300, 600]
    for i in range(len(lowerPtBinEdges) - 1):
        ptBin = str(lowerPtBinEdges[i]) + "to" + str(lowerPtBinEdges[i + 1])
        plots.append(
            Plot.make2D(
                f"{uname}_{suffix}_jetPT_vs_ETA_ptBin{ptBin}",
                (op.map(jets, lambda j: j.pt), op.map(jets, lambda j: j.eta)),
                sel, (EqBin(50, lowerPtBinEdges[i],
                            lowerPtBinEdges[i + 1]), EqBin(50, -2.5, 2.5)),
                title=" p_{T} vs Eta",
                plotopts=utils.getOpts(uname, **{"log-y": True})))

    return plots
Exemplo n.º 2
0
def plotMatching(contName, cont, sel, partName):
    plots = []

    #    plots.append(Plot.make1D(contName+"_deltaR",
    #                             op.map(cont,lambda m : op.deltaR(m[0].p4,m[1].p4)),
    #                             sel,
    #                             EquidistantBinning(1000,0.,0.2),
    #                             xTitle="#Delta R(%s_{gen},%s_{reco})"%(partName,partName)))
    #    plots.append(Plot.make1D(contName+"_deltaPtRel",
    #                             op.map(cont,lambda m : (m[1].pt-m[0].pt)/(m[0].pt+m[1].pt)),
    #                             sel,
    #                             EquidistantBinning(1000,-1.,1.),
    #                             xTitle="P_{T}(%s_{reco})-P_{T}(%s_{gen})/P_{T}(%s_{reco})+P_{T}(%s_{gen})"%(partName,partName,partName,partName)))
    #    plots.append(Plot.make2D(contName+"_Pt2D",
    #                             [op.map(cont,lambda m : m[0].pt),op.map(cont,lambda m : m[1].pt)],
    #                             sel,
    #                             [EquidistantBinning(1000,0,1000),EquidistantBinning(1000,0,1000)],
    #                             xTitle="P_{T}(gen)",
    #                             yTitle="P_{T}(reco)"))
    plots.append(
        Plot.make2D(contName + "_TF",
                    (op.map(cont, lambda m: m[0].p4.E()),
                     op.map(cont, lambda m: m[1].p4.E() - m[0].p4.E())),
                    sel, [
                        EquidistantBinning(3000, 0., 3000.),
                        EquidistantBinning(8000, -1000., 1000.)
                    ],
                    xTitle="E^{parton}(e^{-})",
                    yTitle="#Delta E = E^{reco}(%s)-E^{parton}(%s)" %
                    (partName, partName)))

    return plots
Exemplo n.º 3
0
def plotJetReco(contName, cont, sel, partName):
    plots = []

    plots.append(
        Plot.make1D(contName + "_deltaR",
                    op.map(cont, lambda m: op.deltaR(m.p4, m.genJet.p4)),
                    sel,
                    EquidistantBinning(100, 0., 0.2),
                    xTitle="#Delta R(%s_{gen},%s_{reco})" %
                    (partName, partName)))
    plots.append(
        Plot.make1D(
            contName + "_deltaR2",
            op.map(cont, lambda m: op.pow(op.deltaR(m.p4, m.genJet.p4), 2)),
            sel,
            EquidistantBinning(100, 0., 0.04),
            xTitle="#Delta R^{2}(%s_{gen},%s_{reco})" % (partName, partName)))

    plots.append(
        Plot.make1D(
            contName + "_deltaPtRel",
            op.map(cont, lambda m: (m.pt - m.genJet.pt) / m.pt),
            sel,
            EquidistantBinning(100, -2., 2.),
            xTitle="P_{T}(%s_{reco})-P_{T}(%s_{gen})/P_{T}(%s_{reco})" %
            (partName, partName, partName)))
    return plots
Exemplo n.º 4
0
def fatjetPlots(sel, fatjets, name):
    plots = []
    #    plots.append(Plot.make2D(name+'_Pt2D',
    #                             [op.map(fatjets, lambda fatjet : fatjet.subJet1.pt),op.map(fatjets, lambda fatjet : fatjet.subJet2.pt)],
    #                             sel,
    #                             [EquidistantBinning(1000,0.,1000.),EquidistantBinning(1000,0.,1000.)],
    #                             xTitle = "subjet 1 P_{T}",
    #                             yTitle = "subjet 2 P_{T}"))
    plots.append(
        Plot.make2D(name + '_E2D', [
            op.map(fatjets, lambda fatjet: fatjet.subJet1.p4.E()),
            op.map(fatjets, lambda fatjet: fatjet.subJet2.p4.E())
        ],
                    sel, [
                        EquidistantBinning(1000, 0., 1000.),
                        EquidistantBinning(1000, 0., 1000.)
                    ],
                    xTitle="subjet 1 E",
                    yTitle="subjet 2 E"))
    #    plots.append(Plot.make2D(name+'_partonflavour2D',
    #                             [op.map(fatjets, lambda fatjet : fatjet.subJet1.partonFlavour),op.map(fatjets, lambda fatjet : fatjet.subJet2.partonFlavour)],
    #                             sel,
    #                             [EquidistantBinning(7,0.,6.),EquidistantBinning(7,0.,6.)],
    #                             xTitle = "subjet 1 P_{T}",
    #                             yTitle = "subjet 2 P_{T}"))

    #    plots.append(Plot.make2D(name+'_subjet1VSFatjet_E2D',
    #                             [op.map(fatjets, lambda fatjet : fatjet.subJet1.p4.E()),op.map(fatjets, lambda fatjet : fatjet.p4.E())],
    #                             sel,
    #                             [EquidistantBinning(1000,0.,1000.),EquidistantBinning(1000,0.,1000.)],
    #                             xTitle = "subjet 1 E",
    #                             yTitle = "fatjet E"))
    #    plots.append(Plot.make2D(name+'_subjet2VSFatjet_E2D',
    #                             [op.map(fatjets, lambda fatjet : fatjet.subJet2.p4.E()),op.map(fatjets, lambda fatjet : fatjet.p4.E())],
    #                             sel,
    #                             [EquidistantBinning(1000,0.,1000.),EquidistantBinning(1000,0.,1000.)],
    #                             xTitle = "subjet 2 E",
    #                             yTitle = "fatjet E"))
    #
    #    plots.append(Plot.make2D(name+'_Eta2D',
    #                             [op.map(fatjets, lambda fatjet : fatjet.subJet1.p4.eta()),op.map(fatjets, lambda fatjet : fatjet.subJet2.p4.eta())],
    #                             sel,
    #                             [EquidistantBinning(500,-2.5,2.5),EquidistantBinning(500,-2.5,2.5)],
    #                             xTitle = "subjet 1 #eta",
    #                             yTitle = "subjet 2 #eta"))
    #    plots.append(Plot.make2D(name+'_Phi2D',
    #                             [op.map(fatjets, lambda fatjet : fatjet.subJet1.p4.phi()),op.map(fatjets, lambda fatjet : fatjet.subJet2.p4.phi())],
    #                             sel,
    #                             [EquidistantBinning(320,-3.2,3.2),EquidistantBinning(320,-3.2,3.2)],
    #                             xTitle = "subjet 1 #phi",
    #                             yTitle = "subjet 2 #phi"))

    return plots
def makePrimaryANDSecondaryVerticesPlots(sel, t, uname):
    binScaling = 1
    plots = []
    sv_mass = op.map(t.SV, lambda sv: sv.mass)
    sv_eta = op.map(t.SV, lambda sv: sv.eta)
    sv_phi = op.map(t.SV, lambda sv: sv.phi)
    sv_pt = op.map(t.SV, lambda sv: sv.pt)

    plots.append(
        Plot.make1D(f"{uname}_number_primary_reconstructed_vertices",
                    t.PV.npvsGood,
                    sel,
                    EqBin(50 // binScaling, 0., 60.),
                    title="reconstructed vertices",
                    plotopts=utils.getOpts(uname, **{"log-y": True})))
    plots.append(
        Plot.make1D(f"{uname}_secondary_vertices_mass",
                    sv_mass,
                    sel,
                    EqBin(50 // binScaling, 0., 450.),
                    title="SV mass",
                    plotopts=utils.getOpts(uname, **{"log-y": True})))
    plots.append(
        Plot.make1D(f"{uname}_secondary_vertices_eta",
                    sv_eta,
                    sel,
                    EqBin(50 // binScaling, -2.4, 2.4),
                    title="SV eta",
                    plotopts=utils.getOpts(uname, **{"log-y": True})))
    plots.append(
        Plot.make1D(f"{uname}_secondary_vertices_phi",
                    sv_phi,
                    sel,
                    EqBin(50 // binScaling, -3.1416, 3.1416),
                    title="SV #phi",
                    plotopts=utils.getOpts(uname, **{"log-y": True})))
    plots.append(
        Plot.make1D(f"{uname}_secondary_vertices_pt",
                    sv_pt,
                    sel,
                    EqBin(50 // binScaling, 0., 450.),
                    title="SV p_{T} [GeV]",
                    plotopts=utils.getOpts(uname, **{"log-y": True})))

    return plots
Exemplo n.º 6
0
def plotFatjetMatching(cont, sel, sub1, sub2):
    plots = []

    plots.append(
        Plot.make1D(f"fatjet{sub1}{sub2}_sub1_dE",
                    op.map(cont, lambda m: m[2].subJet1.p4.E() - m[0].p4.E()),
                    sel,
                    EquidistantBinning(1000, -1000., 1000.),
                    xTitle=f"subJet1 {sub1} E - gen {sub1} E"))
    plots.append(
        Plot.make2D(
            f"fatjet{sub1}{sub2}_sub1_TF", [
                op.map(cont, lambda m: m[0].p4.E()),
                op.map(cont, lambda m: m[2].subJet1.p4.E() - m[0].p4.E())
            ],
            sel, [
                EquidistantBinning(3000, 0., 3000.),
                EquidistantBinning(8000, -1000., 1000.)
            ],
            xTitle="E^{{parton}}({sub1})",
            yTitle=f"#Delta E = E^{{reco}}({sub1})-E^{{parton}}({sub1})"))

    plots.append(
        Plot.make1D(f"fatjet{sub1}{sub2}_sub2_dE",
                    op.map(cont, lambda m: m[2].subJet2.p4.E() - m[1].p4.E()),
                    sel,
                    EquidistantBinning(1000, -1000., 1000.),
                    xTitle=f"subJet2 {sub2} E - gen {sub2} E"))
    plots.append(
        Plot.make2D(
            f"fatjet{sub1}{sub2}_sub2_TF", [
                op.map(cont, lambda m: m[1].p4.E()),
                op.map(cont, lambda m: m[2].subJet1.p4.E() - m[1].p4.E())
            ],
            sel, [
                EquidistantBinning(3000, 0., 3000.),
                EquidistantBinning(8000, -1000., 1000.)
            ],
            xTitle="E^{{parton}}({sub2})",
            yTitle=f"#Delta E = E^{{reco}}({sub2})-E^{{parton}}({sub2})"))

    plots.append(
        Plot.make2D(f"fatjet{sub1}{sub2}_dE2D", [
            op.map(cont, lambda m: m[2].subJet1.p4.E() - m[0].p4.E()),
            op.map(cont, lambda m: m[2].subJet2.p4.E() - m[1].p4.E())
        ],
                    sel, [
                        EquidistantBinning(1000, -1000., 1000.),
                        EquidistantBinning(1000, -1000., 1000.)
                    ],
                    xTitle=f"subJet1 {sub1} E - gen {sub1} E",
                    yTitle=f"subJet2 {sub2} E - gen {sub2} E"))

    return plots
Exemplo n.º 7
0
    def definePlots(self, tree, noSel, sample=None, sampleCfg=None):
        from bamboo.plots import Plot
        from bamboo.plots import EquidistantBinning as EqBin
        from bamboo import treefunctions as op

        plots = []

        plots.append(
            Plot.make1D("jetPt",
                        op.map(tree.Jet, lambda j: j.pt),
                        noSel,
                        EqBin(100, 15., 60.),
                        title="Jet p_{T} (GeV/c)"))

        return plots
Exemplo n.º 8
0
    def defineSkimSelection(self, t, noSel, sample=None, sampleCfg=None):
        noSel, PUWeight, corrMET, muons, electrons, AK4jets, AK8jets, bjets_resolved, bjets_boosted, categories, TwoLeptonsTwoJets_Resolved, TwoLeptonsTwoJets_Boosted, TwoLeptonsTwoBjets_Res, TwoLeptonsTwoBjets_Boo, TwoLeptonsTwoBjets_NoMETCut_Res, TwoLeptonsTwoBjets_NoMETCut_Boo, WorkingPoints = self.defineObjects(
            t, noSel, sample, sampleCfg)

        era = sampleCfg["era"]
        isMC = self.isMC(sample)

        if self.SetSel not in ["noSel", "catSel", "2Lep2Jets", "2Lep2bJets"]:
            print('[Skimedtree_NanoHtoZA]: %s Unkown selection ' % self.SetSel)
            sys.exit(0)

        if self.SetRegion not in ["boosted", "resolved"]:
            print(' Region of studies should be : boosted or resolved ! ')
            sys.exit(0)

        if self.SetRegion == "boosted":
            self.SetTagger = "DeepCSV"  # FIXME add later DeepDoubleB
        else:
            if self.SetTagger not in ["DeepFlavour", "DeepCSV"]:
                print(
                    '[Skimedtree_NanoHtoZA]: %s Unknown tagger for resolved region'
                    % self.SetTagger)
                sys.exit(0)

        if self.SetCat not in categories.keys():
            print('[Skimedtree_NanoHtoZA] channel %s not found in categories' %
                  self.SetCat)
            print('Available channel are :')
            print(categories.keys())
            sys.exit(0)

        if self.SetWP is None:
            print(
                '[Skimedtree_NanoHtoZA]: WP is MANDATORY, this is the working point as defined in the ZAtollbb_PreSelection.py'
            )
            sys.exit(0)

        if self.SetWP not in WorkingPoints:
            print(
                '[Skimedtree_NanoHtoZA] WP %s not found in working points definitions'
                % self.SetWP)
            print('  --> define in settings first')
            print('  In settings I found WPs: ')
            print(WorkingPoints)
            sys.exit(1)

        key = self.SetTagger + self.SetWP
        if self.SetRegion == "resolved":
            jets = AK4jets
            bjets = bjets_resolved
            suffix = "AK4Jets"
        elif self.SetRegion == "boosted":
            jets = AK8jets
            bjets = bjets_boosted
            suffix = "AK8Jets"
        else:
            raise RuntimeError('ERROR : %s Unkown args' % self.SetRegion)

        #variables to keep from the input tree
        varsToKeep = {"run": None, "luminosityBlock": None, "event": None}

        if isMC:
            varsToKeep["MC_weight"] = t.genWeight
            varsToKeep["PU_weight"] = PUWeight

        if self.SetSel == "noSel":
            FinalSel = noSel
            # Muons && Electrons selections
            for obj, flav in zip([muons, electrons], ["Muons", "Electrons"]):
                varsToKeep["n%s" % flav] = op.static_cast(
                    "UInt_t", op.rng_len(obj))
                varsToKeep["%s_pt" % flav] = op.map(obj, lambda lep: lep.pt)
                varsToKeep["%s_eta" % flav] = op.map(obj, lambda lep: lep.eta)
                varsToKeep["%s_phi" % flav] = op.map(obj, lambda lep: lep.phi)

            # resolved or boosted
            ### Jets selections
            varsToKeep["%s_pt" % suffix] = op.map(jets, lambda j: j.pt)
            varsToKeep["%s_eta" % suffix] = op.map(jets, lambda j: j.eta)
            varsToKeep["%s_phi" % suffix] = op.map(jets, lambda j: j.phi)
            varsToKeep["n%s" % suffix] = op.static_cast(
                "UInt_t", op.rng_len(jets))

            # MET selections
            varsToKeep["CorrMET_pt"] = corrMET.pt
            varsToKeep["CorrMET_phi"] = corrMET.phi

        for channel, (dilepton, catSel) in categories.items():

            ### Opposite sign leptons , Same Flavour  selection
            if self.SetSel == "catSel":
                FinalSel = catSel
                for i in range(2):
                    varsToKeep["lep{0}_pt_{1}".format(
                        i, self.SetCat)] = dilepton[i].p4.pt
                    varsToKeep["lep{0}_eta_{1}".format(
                        i, self.SetCat)] = dilepton[i].p4.eta
                    varsToKeep["lep{0}_phi_{1}".format(
                        i, self.SetCat)] = dilepton[i].p4.phi
                ll_M = op.invariant_mass(dilepton[0].p4, dilepton[1].p4)
                varsToKeep["ll_M_{0}".format(channel)] = ll_M

            # boosted or resolved
            ### Two OS SF Leptons _ Two Jets  selection
            elif self.SetSel == "2Lep2Jets":
                if self.SetRegion == "resolved":
                    FinalSel = TwoLeptonsTwoJets_Resolved.get(key)
                elif self.SetRegion == "boosted":
                    FinaSel = TwoLeptonsTwoJets_Boosted.get(key)

                lljj_M = (dilepton[0].p4 + dilepton[1].p4 + jets[0].p4 +
                          jets[1].p4).M()
                jj_M = op.invariant_mass(jets[0].p4, jets[1].p4)
                varsToKeep["lljj_M_{0}_{1}{2}_{3}".format(
                    self.SetRegion, self.SetTagger, self.SetWP,
                    self.SetCat)] = lljj_M
                varsToKeep["jj_M_{0}_{1}{2}_{3}".format(
                    self.SetRegion, self.SetTagger, self.SetWP,
                    self.SetCat)] = jj_M

                varsToKeep["nB_{0}_{1}{2}_{3}".format(
                    suffix, self.SetTagger, self.SetWP,
                    self.SetCat)] = op.static_cast("UInt_t", op.rng_len(bJets))

                ### Two OS SF Leptons _ Two bJets  selection +MET cut (xy corr applied too )
            elif self.SetSel == "2Lep2bJets":
                bJets = safeget(bjets, self.SetTagger, self.SetWP)
                if self.SetRegion == "resolved":
                    FinalSel = TwoLeptonsTwoBjets_Res.get(key)
                elif self.SetRegion == "boosted":
                    FinalSel = TwoLeptonsTwoBjets_Boo.get(key)

                llbb_M = (dilepton[0].p4 + dilepton[1].p4 + bJets[0].p4 +
                          bJets[1].p4).M()
                bb_M = op.invariant_mass(bJets[0].p4 + bJets[1].p4)
                varsToKeep["llbb_M_{0}_{1}{2}_{3}".format(
                    self.SetRegion, self.SetTagger, self.SetWP,
                    self.SetCat)] = llbb_M
                varsToKeep["bb_M_{0}_{1}{2}_{3}".format(
                    self.SetRegion, self.SetTagger, self.SetWP,
                    self.SetCat)] = bb_M

                varsToKeep["nB_{0}_{1}{2}_{3}".format(
                    suffix, self.SetTagger, self.SetWP,
                    self.SetCat)] = op.static_cast("UInt_t", op.rng_len(bJets))
            else:
                raise RuntimeError('ERROR : %s  in selection args' %
                                   self.SetSel)

            #sample_weight=
            #event_weight=
            #total_weight=
            #cross_section=

        return FinalSel, varsToKeep
    def definePlots(self, tree, noSel, sample=None, sampleCfg=None):
        from bamboo.plots import Plot, SummedPlot
        from bamboo.plots import EquidistantBinning as EqBin
        from bamboo import treefunctions as op

        if self.args.examples == "all":
            examples = list(i+1 for i in range(self.nExamples)) # 1-4 are fine, so is 7
        else:
            examples = list(set(int(tk) for tk in self.args.examples.split(",")))
        logger.info("Running the following examples: {0}".format(",".join(str(i) for i in examples)))
                
        plots = []
        if 1 in examples:
            ## Example 1: Plot the missing ET of all events.
            plots.append(Plot.make1D("Ex1_MET",
                tree.MET.pt, noSel,
                EqBin(100, 0., 2000.), title="MET (GeV)"))

        if 2 in examples:
            ## Example 2: Plot pT of all jets in all events.
            plots.append(Plot.make1D("Ex2_jetPt",
                op.map(tree.Jet, lambda j : j.pt), noSel,
                EqBin(100, 15., 60.), title="Jet p_{T} (GeV/c)"))

        if 3 in examples:
            ## Example 3: Plot pT of jets with |η| < 1.
            centralJets1 = op.select(tree.Jet, lambda j : op.abs(j.eta) < 1.)
            plots.append(Plot.make1D("Ex3_central1_jetPt",
                op.map(centralJets1, lambda j : j.pt), noSel,
                EqBin(100, 15., 60.), title="Jet p_{T} (GeV/c)"))

        if 4 in examples:
            ## Example 4: Plot the missing ET of events that have at least two jets with pT > 40 GeV.
            jets40 = op.select(tree.Jet, lambda j : j.pt > 40)
            hasTwoJets40 = noSel.refine("twoJets40", cut=(op.rng_len(jets40) >= 2))
            plots.append(Plot.make1D("Ex4_twoJets40_MET",
                tree.MET.pt, hasTwoJets40,
                EqBin(100, 0., 2000.), title="MET (GeV)"))

        if 5 in examples:
            ## Example 5: Plot the missing ET of events that have an opposite-sign muon pair with an invariant mass between 60 and 120 GeV.
            dimu_Z = op.combine(tree.Muon, N=2, pred=(lambda mu1, mu2 : op.AND(
                mu1.charge != mu2.charge,
                op.in_range(60., op.invariant_mass(mu1.p4, mu2.p4), 120.)
                )))
            hasDiMuZ = noSel.refine("hasDiMuZ", cut=(op.rng_len(dimu_Z) > 0))
            plots.append(Plot.make1D("Ex5_dimuZ_MET",
                tree.MET.pt, hasDiMuZ,
                EqBin(100, 0., 2000.), title="MET (GeV)"))

        if 6 in examples:
            ## Example 6: Plot pT of the trijet system with the mass closest to 172.5 GeV in each event and plot the maximum b-tagging discriminant value among the jets in the triplet.
            trijets = op.combine(tree.Jet, N=3)
            hadTop = op.rng_min_element_by(trijets,
                fun=lambda comb: op.abs((comb[0].p4+comb[1].p4+comb[2].p4).M()-172.5))
            hadTop_p4 = (hadTop[0].p4 + hadTop[1].p4 + hadTop[2].p4)
            hasTriJet = noSel.refine("hasTriJet", cut=(op.rng_len(trijets) > 0))
            plots.append(Plot.make1D("Ex6_trijet_topPt",
                hadTop_p4.Pt(), hasTriJet,
                EqBin(100, 15., 40.), title="Trijet p_{T} (GeV/c)"))
            plots.append(Plot.make1D("Ex6_trijet_maxbtag",
                op.max(op.max(hadTop[0].btag, hadTop[1].btag), hadTop[2].btag), hasTriJet,
                EqBin(100, 0., 1.), title="Trijet maximum b-tag"))
            if verbose:
                plots.append(Plot.make1D("Ex6_njets",
                    op.rng_len(tree.Jet), noSel,
                    EqBin(20, 0., 20.), title="Number of jets"))
                plots.append(Plot.make1D("Ex6_ntrijets",
                    op.rng_len(trijets), noSel,
                    EqBin(100, 0., 1000.), title="Number of 3-jet combinations"))
                plots.append(Plot.make1D("Ex6_trijet_mass",
                    hadTop_p4.M(), hasTriJet,
                    EqBin(100, 0., 250.), title="Trijet mass (GeV/c^{2})"))

        if 7 in examples:
            ## Example 7: Plot the sum of pT of jets with pT > 30 GeV that are not within 0.4 in ΔR of any lepton with pT > 10 GeV.
            el10  = op.select(tree.Electron, lambda el : el.pt > 10.)
            mu10  = op.select(tree.Muon    , lambda mu : mu.pt > 10.)
            cleanedJets30 = op.select(tree.Jet, lambda j : op.AND(
                j.pt > 30.,
                op.NOT(op.rng_any(el10, lambda el : op.deltaR(j.p4, el.p4) < 0.4 )),
                op.NOT(op.rng_any(mu10, lambda mu : op.deltaR(j.p4, mu.p4) < 0.4 ))
                ))
            plots.append(Plot.make1D("Ex7_sumCleanedJetPt",
                op.rng_sum(cleanedJets30, lambda j : j.pt), noSel,
                EqBin(100, 15., 200.), title="Sum p_{T} (GeV/c)"))

        if 8 in examples:
            ## Example 8: For events with at least three leptons and a same-flavor opposite-sign lepton pair, find the same-flavor opposite-sign lepton pair with the mass closest to 91.2 GeV and plot the transverse mass of the missing energy and the leading other lepton.
            # The plot is made for each of the different flavour categories (l+/- l-/+ l') and then summed,
            # because concatenation of containers is not (yet) supported.
            lepColl = { "El" : tree.Electron, "Mu" : tree.Muon }
            mt3lPlots = []
            for dlNm,dlCol in lepColl.items():
                dilep = op.combine(dlCol, N=2, pred=(lambda l1,l2 : op.AND(l1.charge != l2.charge)))
                hasDiLep = noSel.refine("hasDilep{0}{0}".format(dlNm), cut=(op.rng_len(dilep) > 0))
                dilepZ = op.rng_min_element_by(dilep, fun=lambda ll : op.abs(op.invariant_mass(ll[0].p4, ll[1].p4)-91.2))
                for tlNm,tlCol in lepColl.items():
                    if tlCol == dlCol:
                        hasTriLep = hasDiLep.refine("hasTrilep{0}{0}{1}".format(dlNm,tlNm),
                            cut=(op.rng_len(tlCol) > 2))
                        residLep = op.select(tlCol, lambda l : op.AND(l.idx != dilepZ[0].idx, l.idx != dilepZ[1].idx))
                        l3 = op.rng_max_element_by(residLep, lambda l : l.pt)
                    else:
                        hasTriLep = hasDiLep.refine("hasTriLep{0}{0}{1}".format(dlNm,tlNm),
                            cut=(op.rng_len(tlCol) > 0))
                        l3 = op.rng_max_element_by(tlCol, lambda l : l.pt)
                    mtPlot = Plot.make1D("Ex8_3lMT_{0}{0}{1}".format(dlNm,tlNm),
                        op.sqrt(2*l3.pt*tree.MET.pt*(1-op.cos(l3.phi-tree.MET.phi))), hasTriLep,
                        EqBin(100, 15., 250.), title="M_{T} (GeV/c^2)")
                    mt3lPlots.append(mtPlot)
                    plots.append(mtPlot)
            plots.append(SummedPlot("Ex8_3lMT", mt3lPlots))

        return plots
Exemplo n.º 10
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        noSel = super(BtagEffAndMistagNano,
                      self).prepareObjects(t,
                                           noSel,
                                           sample,
                                           sampleCfg,
                                           channel='DL',
                                           forSkimmer=True)

        era = sampleCfg['era']
        plots = []

        forceDefine(self.tree._Jet.calcProd, noSel)  # Jets for configureJets
        forceDefine(self.tree._FatJet.calcProd,
                    noSel)  # FatJets for configureJets
        forceDefine(
            getattr(
                self.tree, "_{0}".format(
                    "MET" if self.era != "2017" else "METFixEE2017")).calcProd,
            noSel)  # MET for configureMET

        # protection against data #
        if not self.is_MC:
            return []

        #############################################################################
        #                                   AK4                                     #
        #############################################################################
        ak4_truth_lightjets = op.select(self.ak4Jets,
                                        lambda j: j.hadronFlavour == 0)
        ak4_truth_cjets = op.select(self.ak4Jets,
                                    lambda j: j.hadronFlavour == 4)
        ak4_truth_bjets = op.select(self.ak4Jets,
                                    lambda j: j.hadronFlavour == 5)

        N_ak4_truth_lightjets = Plot.make3D(
            'N_ak4_truth_lightjets', [
                op.map(ak4_truth_lightjets, lambda j: op.abs(j.eta)),
                op.map(ak4_truth_lightjets, lambda j: j.pt),
                op.map(ak4_truth_lightjets, lambda j: j.btagDeepFlavB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='lightjet #eta',
            yTitle='lightjet P_{T}',
            zTitle='lightjet Btagging score')

        N_ak4_truth_cjets = Plot.make3D('N_ak4_truth_cjets', [
            op.map(ak4_truth_cjets, lambda j: op.abs(j.eta)),
            op.map(ak4_truth_cjets, lambda j: j.pt),
            op.map(ak4_truth_cjets, lambda j: j.btagDeepFlavB)
        ],
                                        noSel, [
                                            EquidistantBinning(100, 0., 2.5),
                                            EquidistantBinning(100, 0., 1000),
                                            EquidistantBinning(100, 0., 1.)
                                        ],
                                        xTitle='cjet #eta',
                                        yTitle='cjet P_{T}',
                                        zTitle='cjet Btagging score')

        N_ak4_truth_bjets = Plot.make3D('N_ak4_truth_bjets', [
            op.map(ak4_truth_bjets, lambda j: op.abs(j.eta)),
            op.map(ak4_truth_bjets, lambda j: j.pt),
            op.map(ak4_truth_bjets, lambda j: j.btagDeepFlavB)
        ],
                                        noSel, [
                                            EquidistantBinning(100, 0., 2.5),
                                            EquidistantBinning(100, 0., 1000),
                                            EquidistantBinning(100, 0., 1.)
                                        ],
                                        xTitle='bjet #eta',
                                        yTitle='bjet P_{T}',
                                        zTitle='bjet Btagging score')

        plots.extend(
            [N_ak4_truth_lightjets, N_ak4_truth_cjets, N_ak4_truth_bjets])

        ak4_btagged_lightjets = op.select(ak4_truth_lightjets,
                                          self.lambda_ak4Btag)
        ak4_btagged_cjets = op.select(ak4_truth_cjets, self.lambda_ak4Btag)
        ak4_btagged_bjets = op.select(ak4_truth_bjets, self.lambda_ak4Btag)

        N_ak4_btagged_lightjets = Plot.make3D(
            'N_ak4_btagged_lightjets', [
                op.map(ak4_btagged_lightjets, lambda j: op.abs(j.eta)),
                op.map(ak4_btagged_lightjets, lambda j: j.pt),
                op.map(ak4_btagged_lightjets, lambda j: j.btagDeepFlavB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='lightjet #eta',
            yTitle='lightjet P_{T}',
            zTitle='lightjet Btagging score')

        N_ak4_btagged_cjets = Plot.make3D(
            'N_ak4_btagged_cjets', [
                op.map(ak4_btagged_cjets, lambda j: op.abs(j.eta)),
                op.map(ak4_btagged_cjets, lambda j: j.pt),
                op.map(ak4_btagged_cjets, lambda j: j.btagDeepFlavB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='cjet #eta',
            yTitle='cjet P_{T}',
            zTitle='cjet Btagging score')

        N_ak4_btagged_bjets = Plot.make3D(
            'N_ak4_btagged_bjets', [
                op.map(ak4_btagged_bjets, lambda j: op.abs(j.eta)),
                op.map(ak4_btagged_bjets, lambda j: j.pt),
                op.map(ak4_btagged_bjets, lambda j: j.btagDeepFlavB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='bjet #eta',
            yTitle='bjet P_{T}',
            zTitle='bjet Btagging score')

        plots.extend([
            N_ak4_btagged_lightjets, N_ak4_btagged_cjets, N_ak4_btagged_bjets
        ])

        #############################################################################
        #                                   AK8                                     #
        #############################################################################

        # Truth MC object hadron flavour #
        # subjet.nBHadrons>0 : bjet
        # subjet.nCHadrons>0 : cjet
        # else               : lightjet
        ak8subJet1_truth_lightjets = op.select(
            self.ak8Jets, lambda j: op.AND(j.subJet1.nBHadrons == 0, j.subJet1.
                                           nCHadrons == 0))
        ak8subJet2_truth_lightjets = op.select(
            self.ak8Jets, lambda j: op.AND(j.subJet2.nBHadrons == 0, j.subJet2.
                                           nCHadrons == 0))
        ak8subJet1_truth_cjets = op.select(self.ak8Jets,
                                           lambda j: j.subJet1.nCHadrons > 0)
        ak8subJet2_truth_cjets = op.select(self.ak8Jets,
                                           lambda j: j.subJet2.nCHadrons > 0)
        ak8subJet1_truth_bjets = op.select(self.ak8Jets,
                                           lambda j: j.subJet1.nBHadrons > 0)
        ak8subJet2_truth_bjets = op.select(self.ak8Jets,
                                           lambda j: j.subJet2.nBHadrons > 0)

        N_ak8_truth_subJet1_lightjets = Plot.make3D(
            'N_ak8_truth_subJet1_lightjets', [
                op.map(ak8subJet1_truth_lightjets,
                       lambda j: op.abs(j.subJet1.eta)),
                op.map(ak8subJet1_truth_lightjets, lambda j: j.subJet1.pt),
                op.map(ak8subJet1_truth_lightjets,
                       lambda j: j.subJet1.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='lightjet subJet1 #eta',
            yTitle='lightjet subJet1 P_{T}',
            zTitle='lightjet subJet1 Btagging score')
        N_ak8_truth_subJet2_lightjets = Plot.make3D(
            'N_ak8_truth_subJet2_lightjets', [
                op.map(ak8subJet2_truth_lightjets,
                       lambda j: op.abs(j.subJet2.eta)),
                op.map(ak8subJet2_truth_lightjets, lambda j: j.subJet2.pt),
                op.map(ak8subJet2_truth_lightjets,
                       lambda j: j.subJet2.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='lightjet subJet2 #eta',
            yTitle='lightjet subJet2 P_{T}',
            zTitle='lightjet subJet2 Btagging score')
        N_ak8_truth_subJet1_cjets = Plot.make3D(
            'N_ak8_truth_subJet1_cjets', [
                op.map(ak8subJet1_truth_cjets,
                       lambda j: op.abs(j.subJet1.eta)),
                op.map(ak8subJet1_truth_cjets, lambda j: j.subJet1.pt),
                op.map(ak8subJet1_truth_cjets, lambda j: j.subJet1.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='cjet subJet1 #eta',
            yTitle='cjet subJet1 P_{T}',
            zTitle='cjet subJet1 Btagging score')
        N_ak8_truth_subJet2_cjets = Plot.make3D(
            'N_ak8_truth_subJet2_cjets', [
                op.map(ak8subJet2_truth_cjets,
                       lambda j: op.abs(j.subJet2.eta)),
                op.map(ak8subJet2_truth_cjets, lambda j: j.subJet2.pt),
                op.map(ak8subJet2_truth_cjets, lambda j: j.subJet2.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='cjet subJet2 #eta',
            yTitle='cjet subJet2 P_{T}',
            zTitle='cjet subJet2 Btagging score')
        N_ak8_truth_subJet1_bjets = Plot.make3D(
            'N_ak8_truth_subJet1_bjets', [
                op.map(ak8subJet1_truth_bjets,
                       lambda j: op.abs(j.subJet1.eta)),
                op.map(ak8subJet1_truth_bjets, lambda j: j.subJet1.pt),
                op.map(ak8subJet1_truth_bjets, lambda j: j.subJet1.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='bjet subJet1 #eta',
            yTitle='bjet subJet1 P_{T}',
            zTitle='bjet subJet1 Btagging score')
        N_ak8_truth_subJet2_bjets = Plot.make3D(
            'N_ak8_truth_subJet2_bjets', [
                op.map(ak8subJet2_truth_bjets,
                       lambda j: op.abs(j.subJet2.eta)),
                op.map(ak8subJet2_truth_bjets, lambda j: j.subJet2.pt),
                op.map(ak8subJet2_truth_bjets, lambda j: j.subJet2.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='bjet subJet2 #eta',
            yTitle='bjet subJet2 P_{T}',
            zTitle='bjet subJet2 Btagging score')

        plots.extend([
            N_ak8_truth_subJet1_lightjets, N_ak8_truth_subJet2_lightjets,
            N_ak8_truth_subJet1_cjets, N_ak8_truth_subJet2_cjets,
            N_ak8_truth_subJet1_bjets, N_ak8_truth_subJet2_bjets
        ])
        plots.append(
            SummedPlot(
                'N_ak8_truth_lightjets',
                [N_ak8_truth_subJet1_lightjets, N_ak8_truth_subJet2_lightjets],
                xTitle='lightjet #eta',
                yTitle='lightjet P_{T}',
                zTitle='lightjet Btagging score'))
        plots.append(
            SummedPlot('N_ak8_truth_cjets',
                       [N_ak8_truth_subJet1_cjets, N_ak8_truth_subJet2_cjets],
                       xTitle='cjet #eta',
                       yTitle='cjet P_{T}',
                       zTitle='cjet Btagging score'))
        plots.append(
            SummedPlot('N_ak8_truth_bjets',
                       [N_ak8_truth_subJet1_bjets, N_ak8_truth_subJet2_bjets],
                       xTitle='bjet #eta',
                       yTitle='bjet P_{T}',
                       zTitle='bjet Btagging score'))

        # Btagged objects per flavour #
        ak8subJet1_btagged_lightjets = op.select(
            ak8subJet1_truth_lightjets,
            lambda j: self.lambda_subjetBtag(j.subJet1))
        ak8subJet2_btagged_lightjets = op.select(
            ak8subJet2_truth_lightjets,
            lambda j: self.lambda_subjetBtag(j.subJet2))
        ak8subJet1_btagged_cjets = op.select(
            ak8subJet1_truth_cjets,
            lambda j: self.lambda_subjetBtag(j.subJet1))
        ak8subJet2_btagged_cjets = op.select(
            ak8subJet2_truth_cjets,
            lambda j: self.lambda_subjetBtag(j.subJet2))
        ak8subJet1_btagged_bjets = op.select(
            ak8subJet1_truth_bjets,
            lambda j: self.lambda_subjetBtag(j.subJet1))
        ak8subJet2_btagged_bjets = op.select(
            ak8subJet2_truth_bjets,
            lambda j: self.lambda_subjetBtag(j.subJet2))

        N_ak8_btagged_subJet1_lightjets = Plot.make3D(
            'N_ak8_btagged_subJet1_lightjets', [
                op.map(ak8subJet1_btagged_lightjets,
                       lambda j: op.abs(j.subJet1.eta)),
                op.map(ak8subJet1_btagged_lightjets, lambda j: j.subJet1.pt),
                op.map(ak8subJet1_btagged_lightjets,
                       lambda j: j.subJet1.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='lightjet subJet1 #eta',
            yTitle='lightjet subJet1 P_{T}',
            zTitle='lightjet subJet1 Btagging score')
        N_ak8_btagged_subJet2_lightjets = Plot.make3D(
            'N_ak8_btagged_subJet2_lightjets', [
                op.map(ak8subJet2_btagged_lightjets,
                       lambda j: op.abs(j.subJet2.eta)),
                op.map(ak8subJet2_btagged_lightjets, lambda j: j.subJet2.pt),
                op.map(ak8subJet2_btagged_lightjets,
                       lambda j: j.subJet2.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='lightjet subJet2 #eta',
            yTitle='lightjet subJet2 P_{T}',
            zTitle='lightjet subJet2 Btagging score')
        N_ak8_btagged_subJet1_cjets = Plot.make3D(
            'N_ak8_btagged_subJet1_cjets', [
                op.map(ak8subJet1_btagged_cjets,
                       lambda j: op.abs(j.subJet1.eta)),
                op.map(ak8subJet1_btagged_cjets, lambda j: j.subJet1.pt),
                op.map(ak8subJet1_btagged_cjets, lambda j: j.subJet1.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='cjet subJet1 #eta',
            yTitle='cjet subJet1 P_{T}',
            zTitle='cjet subJet1 Btagging score')
        N_ak8_btagged_subJet2_cjets = Plot.make3D(
            'N_ak8_btagged_subJet2_cjets', [
                op.map(ak8subJet2_btagged_cjets,
                       lambda j: op.abs(j.subJet2.eta)),
                op.map(ak8subJet2_btagged_cjets, lambda j: j.subJet2.pt),
                op.map(ak8subJet2_btagged_cjets, lambda j: j.subJet2.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='cjet subJet2 #eta',
            yTitle='cjet subJet2 P_{T}',
            zTitle='cjet subJet2 Btagging score')
        N_ak8_btagged_subJet1_bjets = Plot.make3D(
            'N_ak8_btagged_subJet1_bjets', [
                op.map(ak8subJet1_btagged_bjets,
                       lambda j: op.abs(j.subJet1.eta)),
                op.map(ak8subJet1_btagged_bjets, lambda j: j.subJet1.pt),
                op.map(ak8subJet1_btagged_bjets, lambda j: j.subJet1.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='bjet subJet1 #eta',
            yTitle='bjet subJet1 P_{T}',
            zTitle='bjet subJet1 Btagging score')
        N_ak8_btagged_subJet2_bjets = Plot.make3D(
            'N_ak8_btagged_subJet2_bjets', [
                op.map(ak8subJet2_btagged_bjets,
                       lambda j: op.abs(j.subJet2.eta)),
                op.map(ak8subJet2_btagged_bjets, lambda j: j.subJet2.pt),
                op.map(ak8subJet2_btagged_bjets, lambda j: j.subJet2.btagDeepB)
            ],
            noSel, [
                EquidistantBinning(100, 0., 2.5),
                EquidistantBinning(100, 0., 1000),
                EquidistantBinning(100, 0., 1.)
            ],
            xTitle='bjet subJet2 #eta',
            yTitle='bjet subJet2 P_{T}',
            zTitle='bjet subJet2 Btagging score')

        plots.extend([
            N_ak8_btagged_subJet1_lightjets, N_ak8_btagged_subJet2_lightjets,
            N_ak8_btagged_subJet1_cjets, N_ak8_btagged_subJet2_cjets,
            N_ak8_btagged_subJet1_bjets, N_ak8_btagged_subJet2_bjets
        ])
        plots.append(
            SummedPlot('N_ak8_btagged_lightjets', [
                N_ak8_btagged_subJet1_lightjets,
                N_ak8_btagged_subJet2_lightjets
            ],
                       xTitle='lightjet #eta',
                       yTitle='lightjet P_{T}',
                       zTitle='lightjet Btagging score'))
        plots.append(
            SummedPlot(
                'N_ak8_btagged_cjets',
                [N_ak8_btagged_subJet1_cjets, N_ak8_btagged_subJet2_cjets],
                xTitle='cjet #eta',
                yTitle='cjet P_{T}',
                zTitle='cjet Btagging score'))
        plots.append(
            SummedPlot(
                'N_ak8_btagged_bjets',
                [N_ak8_btagged_subJet1_bjets, N_ak8_btagged_subJet2_bjets],
                xTitle='bjet #eta',
                yTitle='bjet P_{T}',
                zTitle='bjet Btagging score'))

        return plots
Exemplo n.º 11
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        noSel = super(BtagEffAndMistagNano,
                      self).prepareObjects(t, noSel, sample, sampleCfg)

        era = sampleCfg['era']
        plots = []

        # protection against data #
        if not self.is_MC:
            return []

        # Get ScaleFactor binning #
        instance = ScaleFactorsbbWW()
        all_SF = instance.all_scalefactors

        tuple_medium_DeepJet_json = all_SF['btag_' + era]['DeepJet_medium']
        variables = []
        binning = []
        index = ['x', 'y', 'z']
        for json_file in tuple_medium_DeepJet_json:
            with open(json_file, 'r') as handle:
                content = json.load(handle)
            var = content['variables']
            bins = content['binning']
            variables.append(var)
            binning.append(bins)

            print('Variables in file %s' % json_file)
            for var, bin_name in zip(var, index):
                print(('... Variable : %s' % var).ljust(30, ' ') +
                      'Binning (index %s) :' % bin_name, bins[bin_name])

        # Find best binning (finest)  #
        opt_binning = {}
        for var, bins in zip(variables, binning):
            for v, bn in zip(var, index):
                if v == 'AbsEta':
                    continue
                b = bins[bn]
                if not v in opt_binning.keys():
                    opt_binning[v] = b
                else:
                    opt_binning[v].extend(
                        [a for a in b if a not in opt_binning[v]])

        # Sort #
        for var, bins in opt_binning.items():
            opt_binning[var] = sorted(opt_binning[var])

        print("Optimal Binning chosen")
        for var, bins in opt_binning.items():
            print(('... Variable : %s' % var).ljust(30, ' ') + 'Binning :',
                  bins)

        # Truth MC object hadron flavour #
        ak4_truth_lightjets = op.select(self.ak4Jets,
                                        lambda j: op.abs(j.hadronFlavour) == 0)
        ak4_truth_cjets = op.select(self.ak4Jets,
                                    lambda j: op.abs(j.hadronFlavour) == 4)
        ak4_truth_bjets = op.select(self.ak4Jets,
                                    lambda j: op.abs(j.hadronFlavour) == 5)

        plots.append(
            Plot.make3D('N_total_lightjets', [
                op.map(ak4_truth_lightjets, lambda j: j.eta),
                op.map(ak4_truth_lightjets, lambda j: j.pt),
                op.map(ak4_truth_lightjets, lambda j: j.btagDeepFlavB)
            ],
                        noSel, [
                            VariableBinning(opt_binning['Eta']),
                            VariableBinning(opt_binning['Pt']),
                            VariableBinning(opt_binning['BTagDiscri'])
                        ],
                        xTitle='lightjet #eta',
                        yTitle='lightjet P_{T}',
                        zTitle='lightjet Btagging score'))
        plots.append(
            Plot.make3D('N_total_cjets', [
                op.map(ak4_truth_cjets, lambda j: j.eta),
                op.map(ak4_truth_cjets, lambda j: j.pt),
                op.map(ak4_truth_cjets, lambda j: j.btagDeepFlavB)
            ],
                        noSel, [
                            VariableBinning(opt_binning['Eta']),
                            VariableBinning(opt_binning['Pt']),
                            VariableBinning(opt_binning['BTagDiscri'])
                        ],
                        xTitle='cjet #eta',
                        yTitle='cjet P_{T}',
                        zTitle='cjet Btagging score'))
        plots.append(
            Plot.make3D('N_total_bjets', [
                op.map(ak4_truth_bjets, lambda j: j.eta),
                op.map(ak4_truth_bjets, lambda j: j.pt),
                op.map(ak4_truth_bjets, lambda j: j.btagDeepFlavB)
            ],
                        noSel, [
                            VariableBinning(opt_binning['Eta']),
                            VariableBinning(opt_binning['Pt']),
                            VariableBinning(opt_binning['BTagDiscri'])
                        ],
                        xTitle='bjet #eta',
                        yTitle='bjet P_{T}',
                        zTitle='bjet Btagging score'))

        # Btagged objects per flavour #
        ak4_btagged_lightjets = op.select(ak4_truth_lightjets,
                                          self.lambda_ak4Btag)
        ak4_btagged_cjets = op.select(ak4_truth_cjets, self.lambda_ak4Btag)
        ak4_btagged_bjets = op.select(ak4_truth_bjets, self.lambda_ak4Btag)

        plots.append(
            Plot.make3D('N_btagged_lightjets', [
                op.map(ak4_btagged_lightjets, lambda j: j.eta),
                op.map(ak4_btagged_lightjets, lambda j: j.pt),
                op.map(ak4_btagged_lightjets, lambda j: j.btagDeepFlavB)
            ],
                        noSel, [
                            VariableBinning(opt_binning['Eta']),
                            VariableBinning(opt_binning['Pt']),
                            VariableBinning(opt_binning['BTagDiscri'])
                        ],
                        xTitle='lightjet #eta',
                        yTitle='lightjet P_{T}',
                        zTitle='lightjet Btagging score'))
        plots.append(
            Plot.make3D('N_btagged_cjets', [
                op.map(ak4_btagged_cjets, lambda j: j.eta),
                op.map(ak4_btagged_cjets, lambda j: j.pt),
                op.map(ak4_btagged_cjets, lambda j: j.btagDeepFlavB)
            ],
                        noSel, [
                            VariableBinning(opt_binning['Eta']),
                            VariableBinning(opt_binning['Pt']),
                            VariableBinning(opt_binning['BTagDiscri'])
                        ],
                        xTitle='cjet #eta',
                        yTitle='cjet P_{T}',
                        zTitle='cjet Btagging score'))
        plots.append(
            Plot.make3D('N_btagged_bjets', [
                op.map(ak4_btagged_bjets, lambda j: j.eta),
                op.map(ak4_btagged_bjets, lambda j: j.pt),
                op.map(ak4_btagged_bjets, lambda j: j.btagDeepFlavB)
            ],
                        noSel, [
                            VariableBinning(opt_binning['Eta']),
                            VariableBinning(opt_binning['Pt']),
                            VariableBinning(opt_binning['BTagDiscri'])
                        ],
                        xTitle='bjet #eta',
                        yTitle='bjet P_{T}',
                        zTitle='bjet Btagging score'))

        return plots
Exemplo n.º 12
0
def plotMatching(contName, list_cont, list_sel, partName):
    plots = []

    dr_plots = []
    dr2_plots = []
    ptrel_plots = []
    TF_plots = []
    for idx, (cont, sel) in enumerate(zip(list_cont, list_sel)):
        dr_plots.append(
            Plot.make1D(contName + str(idx) + "_deltaR",
                        op.map(cont, lambda m: op.deltaR(m[0].p4, m[1].p4)),
                        sel,
                        EquidistantBinning(100, 0., 0.2),
                        xTitle="#Delta R(%s_{gen},%s_{reco})" %
                        (partName, partName)))
        dr2_plots.append(
            Plot.make1D(contName + str(idx) + "_deltaR2",
                        op.map(
                            cont,
                            lambda m: op.pow(op.deltaR(m[0].p4, m[1].p4), 2)),
                        sel,
                        EquidistantBinning(100, 0., 0.04),
                        xTitle="#Delta R^{2}(%s_{gen},%s_{reco})" %
                        (partName, partName)))

        ptrel_plots.append(
            Plot.make1D(
                contName + str(idx) + "_deltaPtRel",
                op.map(cont, lambda m: (m[1].pt - m[0].pt) / m[1].pt),
                sel,
                EquidistantBinning(100, -2., 2.),
                xTitle="P_{T}(%s_{reco})-P_{T}(%s_{gen})/P_{T}(%s_{reco})" %
                (partName, partName, partName)))
        TF_plots.append(
            Plot.make2D(contName + str(idx) + "_TF",
                        (op.map(cont, lambda m: m[0].p4.E()),
                         op.map(cont, lambda m: m[1].p4.E() - m[0].p4.E())),
                        sel, [
                            EquidistantBinning(100, 0., 500.),
                            EquidistantBinning(400, -200., 200.)
                        ],
                        xTitle="E^{parton}(e^{-})",
                        yTitle="#Delta E = E^{reco}(%s)-E^{parton}(%s)" %
                        (partName, partName)))

    plots.append(
        SummedPlot(contName + "_deltaR",
                   dr_plots,
                   xTitle="#Delta R(%s_{gen},%s_{reco})" %
                   (partName, partName)))
    plots.append(
        SummedPlot(contName + "_deltaR2",
                   dr2_plots,
                   xTitle="#Delta R^{2}(%s_{gen},%s_{reco})" %
                   (partName, partName)))
    plots.append(
        SummedPlot(contName + "_deltaPtRel",
                   ptrel_plots,
                   xTitle="P_{T}(%s_{reco})-P_{T}(%s_{gen}/P_{T}(%s_{reco})" %
                   (partName, partName, partName)))
    plots.append(
        SummedPlot(contName + "_TF",
                   TF_plots,
                   xTitle="#Delta E = E^{reco}(%s)-E^{patron}(%s)" %
                   (partName, partName)))

    return plots