コード例 #1
0
def isGoodElectron(el, ptCut=10.):
    from bamboo import treefunctions as op
    return op.AND(
            el.pt > ptCut,
            op.abs(el.eta) < 2.5,
            ## TODO add the other cuts
            op.NOT(op.AND(el.jet.isValid, op.OR(el.jet.btagDeepB > .1522, el.jet.btagDeepB <= -999.)))
            ## ^^ this one is tricky, the rest are straightforward
            )
コード例 #2
0
ファイル: tt5TeV_B.py プロジェクト: beatrizlopes/tt5TeVCMSDAS
 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.)))
         )
コード例 #3
0
ファイル: tt5TeV_B.py プロジェクト: beatrizlopes/tt5TeVCMSDAS
 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.)))
         )
コード例 #4
0
    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

        plots = []

        # 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(
                    "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("3lMT", mt3lPlots))

        return plots
コード例 #5
0
def isGoodMuon(mu, ptCut=10.):
    from bamboo import treefunctions as op
    return op.AND(
        mu.pt > ptCut,
        op.abs(mu.eta) < 2.4,
        ## TODO add the other cuts
        mu.sip3d < 8,
        op.abs(mu.dxy) < 0.05,
        op.abs(mu.dz) < 0.1,
        mu.miniPFRelIso_all < 0.085,
        mu.mediumPromptId,
        mu.mvaTTH > 0.55,
        op.NOT(
            op.AND(mu.jet.isValid,
                   op.OR(mu.jet.btagDeepB > .1522,
                         mu.jet.btagDeepB <= -999.))))
コード例 #6
0
def isGoodMuon(mu, ptCut=10.):
    from bamboo import treefunctions as op
    return op.AND(
            mu.pt > ptCut,
            op.abs(mu.eta) < 2.4,
            ## TODO add the other cuts
            )
コード例 #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 = []

        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("sumCleanedJetPt",
                        op.rng_sum(cleanedJets30, lambda j: j.pt),
                        noSel,
                        EqBin(100, 15., 200.),
                        title="Sum p_{T} (GeV/c)"))

        return plots
コード例 #8
0
def isGoodElectron(el, ptCut=10.):
    from bamboo import treefunctions as op
    return op.AND(
        el.pt > ptCut,
        op.abs(el.eta) < 2.5,
        ## TODO add the other cuts
        el.sip3d < 8,
        op.abs(el.dxy) < 0.05,
        op.abs(el.dz) < 0.1,
        el.miniPFRelIso_all < 0.085,
        el.mvaTTH > 0.125,
        el.lostHits == 0,
        op.NOT(
            op.AND(el.jet.isValid,
                   op.OR(el.jet.btagDeepB > .1522, el.jet.btagDeepB <= -999.)))
        ## ^^ this one is tricky, the rest are straightforward
    )
コード例 #9
0
 def makeFatjetMatch(gen1, gen2, recoFatJet):
     return op.combine(
         (gen1, gen2, recoFatJet),
         pred=lambda g1, g2, fat: op.AND(
             fat.subJet1.idx == op.rng_min_element_by(
                 reco_subJet1_b_matched, lambda sub1_matched: op.deltaR(
                     g1.p4, sub1_matched.p4)).idx, fat.subJet2.idx == op
             .rng_min_element_by(
                 reco_subJet2_b_matched, lambda sub2_matched: op.deltaR(
                     g2.p4, sub2_matched.p4)).idx))
コード例 #10
0
 def reco_4l(leptons, lName, baseSel):
     ## select events with four leptons, and find the best Z candidate
     ## shared between 4el and 4mu
     has4l = baseSel.refine(f"has4{lName}", cut=[
         op.rng_len(leptons) == 4,
         op.rng_sum(leptons, lambda l : l.charge) == 0,
         ])
     allZcand = op.combine(leptons, N=2, pred=lambda l1,l2 : l1.charge != l2.charge)
     bestZ = op.rng_min_element_by(allZcand, lambda ll : op.abs(op.invariant_mass(ll[0].p4, ll[1].p4)-mZ))
     otherLeptons = op.select(leptons, partial(lambda l,oz=None : op.AND(l.idx != oz[0].idx, l.idx != oz[1].idx), oz=bestZ))
     return has4l, bestZ, otherLeptons
コード例 #11
0
    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
        plots = []
        metSel = noSel.refine("MET", cut=(tree.met.et > 30000))
        trigSel = metSel.refine("trig", cut=op.OR(tree.trigE, tree.trigM))
        goodLeptons = op.select(
            tree.lep, lambda l: op.AND(l.isTightID, l.pt > 35000., l.ptcone30 /
                                       l.pt < 0.1, l.etcone20 / l.pt < 0.1))
        oneLepSel = trigSel.refine("1goodlep",
                                   cut=(op.rng_len(goodLeptons) == 1))
        lep = goodLeptons[0]
        signalSel = oneLepSel.refine(
            "signalRegion",
            cut=op.AND(
                op.abs(lep.z0 * op.sin(lep.p4.theta())) < 0.5,
                op.multiSwitch(
                    (lep.type == 11,
                     op.AND(
                         op.abs(lep.eta) < 2.46,
                         op.NOT(op.in_range(1.37, op.abs(lep.eta), 1.52)),
                         op.abs(lep.trackd0pvunbiased /
                                lep.tracksigd0pvunbiased) < 5)),
                    (lep.type == 13,
                     op.AND(
                         op.abs(lep.eta) < 2.5,
                         op.abs(lep.trackd0pvunbiased /
                                lep.tracksigd0pvunbiased) < 3)),
                    op.c_bool(False))))
        metp4 = makePtEtaPhiEP4(tree.met.et, op.c_float(0.), tree.met.phi,
                                tree.met.et)
        plots.append(
            Plot.make1D("mt_w", (lep.p4 + metp4).Mt() / 1000.,
                        signalSel,
                        EqBin(40, 60., 180.),
                        title="m_{T}^{W#rightarrow l#nu} (GeV)",
                        plotopts={"log-y-axis-range": [25., 2.5e8]}))

        return plots
コード例 #12
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 = []

        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("dimuZ_MET",
                        tree.MET.pt,
                        hasDiMuZ,
                        EqBin(100, 0., 2000.),
                        title="MET (GeV)"))

        return plots
コード例 #13
0
 def comp_cosThetaSbetBeamAndHiggs(self, genColl):
     genh = op.select(
         genColl,
         lambda g: op.AND(g.pdgId == 25, g.statusFlags & (0x1 << 13)))
     HH_p4 = genh[0].p4 + genh[1].p4
     cm = HH_p4.BoostToCM()
     boosted_h1 = op.extMethod("ROOT::Math::VectorUtil::boost",
                               returnType=genh[0].p4._typeName)(genh[0].p4,
                                                                cm)
     boosted_h2 = op.extMethod("ROOT::Math::VectorUtil::boost",
                               returnType=genh[1].p4._typeName)(genh[1].p4,
                                                                cm)
     mHH = op.switch(
         op.rng_len(genh) == 2, op.invariant_mass(genh[0].p4, genh[1].p4),
         op.c_float(-9999))
     cosTheta1 = op.switch(
         op.rng_len(genh) == 2, op.abs(boosted_h1.Pz() / boosted_h1.P()),
         op.c_float(-9999))
     cosTheta2 = op.switch(
         op.rng_len(genh) == 2, op.abs(boosted_h1.Pz() / boosted_h2.P()),
         op.c_float(-9999))
     return [mHH, cosTheta1, cosTheta2]
コード例 #14
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        if 'type' not in sampleCfg.keys() or sampleCfg["type"] != "signal":
            raise RuntimeError("Sample needs to be HH signal LO GGF sample")

        era = sampleCfg.get("era") if sampleCfg else None

        # Select gen level Higgs #
        genh = op.select(
            t.GenPart,
            lambda g: op.AND(g.pdgId == 25, g.statusFlags & (0x1 << 13)))
        HH_p4 = genh[0].p4 + genh[1].p4
        cm = HH_p4.BoostToCM()
        boosted_h = op.extMethod("ROOT::Math::VectorUtil::boost",
                                 returnType=genh[0].p4._typeName)(genh[0].p4,
                                                                  cm)
        mHH = op.invariant_mass(genh[0].p4, genh[1].p4)
        cosHH = op.abs(boosted_h.Pz() / boosted_h.P())

        # Apply reweighting #

        benchmarks = [
            'BenchmarkSM',
            'Benchmark1',
            'Benchmark2',
            'Benchmark3',
            'Benchmark4',
            'Benchmark5',
            'Benchmark6',
            'Benchmark7',
            'Benchmark8',
            'Benchmark8a',
            'Benchmark9',
            'Benchmark10',
            'Benchmark11',
            'Benchmark12',
            'BenchmarkcHHH0',
            'BenchmarkcHHH1',
            'BenchmarkcHHH2p45',
            'BenchmarkcHHH5',
            'Benchmarkcluster1',
            'Benchmarkcluster2',
            'Benchmarkcluster3',
            'Benchmarkcluster4',
            'Benchmarkcluster5',
            'Benchmarkcluster6',
            'Benchmarkcluster7',
        ]
        selections = {'': noSel}
        reweights = {}
        if self.args.reweighting:
            for benchmark in benchmarks:
                json_file = os.path.join(
                    os.path.abspath(os.path.dirname(__file__)), 'data',
                    'ScaleFactors_GGF_LO',
                    '{}_to_{}_{}.json'.format(sample, benchmark, era))
                if os.path.exists(json_file):
                    print("Found file {}".format(json_file))
                    reweightLO = get_scalefactor("lepton",
                                                 json_file,
                                                 paramDefs={
                                                     'Eta': lambda x: mHH,
                                                     'Pt': lambda x: cosHH
                                                 })
                    selections[benchmark] = SelectionWithDataDriven.create(
                        parent=noSel,
                        name='noSel' + benchmark,
                        ddSuffix=benchmark,
                        cut=op.c_bool(True),
                        ddCut=op.c_bool(True),
                        weight=op.c_float(1.),
                        ddWeight=reweightLO(op.c_float(1.)),
                        enable=True)
                    reweights[benchmark] = reweightLO(op.c_float(1.))
                else:
                    print("Could not find file {}".format(json_file))

        # Plots #
        plots = []

        for name, reweight in reweights.items():
            plots.append(
                Plot.make1D("weight_{}".format(name),
                            reweight,
                            noSel,
                            EquidistantBinning(100, 0, 5.),
                            xTitle='weight'))

        for selName, sel in selections.items():
            plots.append(
                Plot.make2D(
                    f"mHHvsCosThetaStar{selName}", [mHH, cosHH],
                    sel, [
                        VariableBinning([
                            250., 270., 290., 310., 330., 350., 370., 390.,
                            410., 430., 450., 470., 490., 510., 530., 550.,
                            570., 590., 610., 630., 650., 670., 700., 750.,
                            800., 850., 900., 950., 1000., 1100., 1200., 1300.,
                            1400., 1500., 1750., 2000., 5000.
                        ]),
                        VariableBinning([0.0, 0.4, 0.6, 0.8, 1.0])
                    ],
                    xTitle='m_{HH}',
                    yTitle='cos(#theta^{*})'))
            plots.append(
                Plot.make1D(f"mHH{selName}",
                            mHH,
                            sel,
                            VariableBinning([
                                250., 270., 290., 310., 330., 350., 370., 390.,
                                410., 430., 450., 470., 490., 510., 530., 550.,
                                570., 590., 610., 630., 650., 670., 700., 750.,
                                800., 850., 900., 950., 1000., 1100., 1200.,
                                1300., 1400., 1500., 1750., 2000., 5000.
                            ]),
                            xTitle='m_{HH}'))
            plots.append(
                Plot.make1D(f"cosThetaStar{selName}",
                            cosHH,
                            sel,
                            VariableBinning([0.0, 0.4, 0.6, 0.8, 1.0]),
                            xTitle='cos(#theta^{*})'))

        return plots
コード例 #15
0
    def defineSkimSelection(self, t, noSel, sample=None, sampleCfg=None):
        noSel = super(SkimmerNanoHHtobbWWSL,
                      self).prepareObjects(t,
                                           noSel,
                                           sample,
                                           sampleCfg,
                                           "SL",
                                           forSkimmer=True)
        # For the Skimmer, SF must not use defineOnFirstUse -> segmentation fault

        era = sampleCfg['era']

        # Initialize varsToKeep dict #
        varsToKeep = dict()

        #---------------------------------------------------------------------------------------#
        #                                     Selections                                        #
        #---------------------------------------------------------------------------------------#
        # keep the exact same order of nodes as mentioned in respective JPA model xml files
        ResolvedJPANodeList = [
            '2b2Wj', '2b1Wj', '1b2Wj', '2b0Wj', '1b1Wj', '1b0Wj', '0b'
        ]
        BoostedJPANodeList = ['Hbb2Wj', 'Hbb1Wj', 'Hbb0Wj']

        # JPA Models
        basepath = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                'MachineLearning', 'ml-models',
                                'JPA_Loose_ttH')
        resolvedModelDict = getResolvedJpaModelDict(basepath,
                                                    ResolvedJPANodeList, era)
        boostedModelDict = getBoostedJpaModelDict(basepath, BoostedJPANodeList,
                                                  era)

        if not self.inclusive_sel:
            #----- Check arguments -----#
            jet_level = [
                "Ak4", "Ak8", "Res2b2Wj", "Res2b1Wj", "Res2b0Wj", "Res1b2Wj",
                "Res1b1Wj", "Res1b0Wj", "Res0b", "Hbb2Wj", "Hbb1Wj", "Hbb0Wj"
            ]

            if [
                    boolean for (level, boolean) in self.args.__dict__.items()
                    if level in jet_level
            ].count(True) != 1:
                raise RuntimeError(
                    "Only one of the jet arguments must be used, check --help")

            if self.args.Channel not in ["El", "Mu"]:
                raise RuntimeError("Channel must be either 'El' or 'Mu'")

            #----- Lepton selection -----#
            ElSelObj, MuSelObj = makeSingleLeptonSelection(
                self, noSel, use_dd=False, fake_selection=self.args.FakeCR)

            if self.args.Channel is None:
                raise RuntimeError("You need to specify --Channel")
            if self.args.Channel == "El":
                selObj = ElSelObj
                lep = self.electronsTightSel[0]
            if self.args.Channel == "Mu":
                selObj = MuSelObj
                lep = self.muonsTightSel[0]

            #----- Apply jet corrections -----#
            ElSelObject.sel = self.beforeJetselection(ElSelObj.sel, 'El')
            MuSelObject.sel = self.beforeJetselection(MuSelObj.sel, 'Mu')

            #----- Jet selection -----#
            if any([
                    self.args.__dict__[item] for item in [
                        "Ak4", "Res2b2Wj", "Res2b1Wj", "Res2b0Wj", "Res1b2Wj",
                        "Res1b1Wj", "Res1b0Wj", "Res0b"
                    ]
            ]):
                makeResolvedSelection(self, selObj)
                if self.args.Channel == "El":
                    print('... Resolved :: El Channel')
                    L1out, L2out, selObjAndJetsPerJpaCatDict = findJPACategoryResolved(
                        self,
                        selObj,
                        lep,
                        self.muonsPreSel,
                        self.electronsPreSel,
                        self.ak4Jets,
                        self.ak4BJetsLoose,
                        self.ak4BJets,
                        self.corrMET,
                        resolvedModelDict,
                        t.event,
                        self.HLL,
                        ResolvedJPANodeList,
                        plot_yield=False)

                if self.args.Channel == "Mu":
                    print('... Resolved :: Mu Channel')
                    L1out, L2out, selObjAndJetsPerJpaCatDict = findJPACategoryResolved(
                        self,
                        selObj,
                        lep,
                        self.muonsPreSel,
                        self.electronsPreSel,
                        self.ak4Jets,
                        self.ak4BJetsLoose,
                        self.ak4BJets,
                        self.corrMET,
                        resolvedModelDict,
                        t.event,
                        self.HLL,
                        ResolvedJPANodeList,
                        plot_yield=False)

            if any([
                    self.args.__dict__[item]
                    for item in ["Ak8", "Hbb2Wj", "Hbb1Wj", "Hbb0Wj"]
            ]):
                makeBoostedSelection(self, selObj)
                if self.args.Channel == "El":
                    print('... Boosted :: El Channel')
                    L1out, L2out, selObjAndJetsPerJpaCatDict = findJPACategoryBoosted(
                        self,
                        selObj,
                        lep,
                        self.muonsPreSel,
                        self.electronsPreSel,
                        self.ak8BJets,
                        self.ak4JetsCleanedFromAk8b,
                        self.ak4BJetsLoose,
                        self.ak4BJets,
                        self.corrMET,
                        boostedModelDict,
                        t.event,
                        self.HLL,
                        BoostedJPANodeList,
                        plot_yield=False)

                if self.args.Channel == "Mu":
                    print('... Boosted :: Mu Channel')
                    L1out, L2out, selObjAndJetsPerJpaCatDict = findJPACategoryBoosted(
                        self,
                        selObj,
                        lep,
                        self.muonsPreSel,
                        self.electronsPreSel,
                        self.ak8BJets,
                        self.ak4JetsCleanedFromAk8b,
                        self.ak4BJetsLoose,
                        self.ak4BJets,
                        self.corrMET,
                        boostedModelDict,
                        t.event,
                        self.HLL,
                        BoostedJPANodeList,
                        plot_yield=False)

            if self.args.Res2b2Wj:
                print("...... 2b2Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('2b2Wj')[0]
                jpaJets = selObjAndJetsPerJpaCatDict.get('2b2Wj')[1]
                jpaarg = "Res2b2Wj"

            if self.args.Res2b1Wj:
                print("...... 2b1Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('2b1Wj')[0]
                jpaJets = selObjAndJetsPerJpaCatDict.get('2b1Wj')[1]
                jpaarg = "Res2b1Wj"

            if self.args.Res1b2Wj:
                print("...... 1b2Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('1b2Wj')[0]
                jpaJets = selObjAndJetsPerJpaCatDict.get('1b2Wj')[1]
                jpaarg = "Res1b2Wj"

            if self.args.Res2b0Wj:
                print("...... 2b0Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('2b0Wj')[0]
                jpaJets = selObjAndJetsPerJpaCatDict.get('2b0Wj')[1]
                jpaarg = "Res2b0Wj"

            if self.args.Res1b1Wj:
                print("...... 1b1Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('1b1Wj')[0]
                jpaJets = selObjAndJetsPerJpaCatDict.get('1b1Wj')[1]
                jpaarg = "Res1b1Wj"

            if self.args.Res1b0Wj:
                print("...... 1b0Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('1b0Wj')[0]
                jpaJets = selObjAndJetsPerJpaCatDict.get('1b0Wj')[1]
                jpaarg = "Res1b0Wj"

            if self.args.Res0b:
                print("...... 0b")
                selObj = selObjAndJetsPerJpaCatDict.get('0b')[0]
                jpaJets = None
                jpaarg = "Res0b"

            #######################################
            # Hbb2Wj : jet1 jet2   jet3   jet4
            # Hbb1Wj : jet1 jet2   jet3   jet4=0
            # Hbb0Wj : jet1 jet2   jet3=0 jet4=0
            #######################################
            if self.args.Hbb2Wj:
                print("...... Hbb2Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('Hbb2Wj')[0]
                jpaJets = selObjAndJetsPerJpaCatDict.get('Hbb2Wj')[1]
                jpaarg = "Hbb2Wj"

            if self.args.Hbb1Wj:
                print("...... Hbb1Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('Hbb1Wj')[0]
                jpaJets = selObjAndJetsPerJpaCatDict.get('Hbb1Wj')[1]
                jpaarg = "Hbb1Wj"

            if self.args.Hbb0Wj:
                print("...... Hbb0Wj")
                selObj = selObjAndJetsPerJpaCatDict.get('Hbb0Wj')[0]
                jpaJets = None
                jpaarg = "Hbb0Wj"

        else:
            noSel = self.beforeJetselection(noSel)

        #---------------------------------------------------------------------------------------#
        #                                 Synchronization tree                                  #
        #---------------------------------------------------------------------------------------#
        if self.args.Synchronization:
            # Event variables #
            varsToKeep["event"] = None  # Already in tree
            varsToKeep["run"] = None  # Already in tree
            varsToKeep["ls"] = t.luminosityBlock
            varsToKeep["n_presel_mu"] = op.static_cast(
                "UInt_t", op.rng_len(self.muonsPreSel))
            varsToKeep["n_fakeablesel_mu"] = op.static_cast(
                "UInt_t", op.rng_len(self.muonsFakeSel))
            varsToKeep["n_mvasel_mu"] = op.static_cast(
                "UInt_t", op.rng_len(self.muonsTightSel))
            varsToKeep["n_presel_ele"] = op.static_cast(
                "UInt_t", op.rng_len(self.electronsPreSel))
            varsToKeep["n_fakeablesel_ele"] = op.static_cast(
                "UInt_t", op.rng_len(self.electronsFakeSel))
            varsToKeep["n_mvasel_ele"] = op.static_cast(
                "UInt_t", op.rng_len(self.electronsTightSel))
            varsToKeep["n_presel_ak4Jet"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak4Jets))
            varsToKeep["n_presel_ak8Jet"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak8Jets))
            varsToKeep["n_presel_ak8BJet"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak8BJets))
            varsToKeep["n_loose_ak4BJet"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak4BJetsLoose))
            varsToKeep["n_medium_ak4BJet"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak4BJets))
            varsToKeep["n_ak4JetsCleanAk8b"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak4JetsCleanedFromAk8b))
            varsToKeep["n_presel_ak4JetVBF"] = op.static_cast(
                "UInt_t", op.rng_len(self.VBFJetsPreSel))

            varsToKeep["is_SR"] = op.static_cast(
                "UInt_t",
                op.OR(
                    op.rng_len(self.electronsTightSel) == 1,
                    op.rng_len(self.muonsTightSel) == 1))

            varsToKeep["is_e"] = op.c_float(
                True) if self.args.Channel == 'El' else op.c_float(False)
            varsToKeep["is_m"] = op.c_float(
                False) if self.args.Channel == 'El' else op.c_float(True)

            varsToKeep["is_resolved"] = op.switch(
                op.AND(
                    op.rng_len(self.ak4Jets) >= 3,
                    op.rng_len(self.ak4BJets) >= 1,
                    op.rng_len(self.ak8BJets) == 0), op.c_bool(True),
                op.c_bool(False))
            varsToKeep["is_boosted"] = op.switch(
                op.AND(
                    op.rng_len(self.ak8BJets) >= 1,
                    op.rng_len(self.ak4JetsCleanedFromAk8b) >= 1),
                op.c_bool(True), op.c_bool(False))

            varsToKeep["n_tau"] = op.static_cast("UInt_t",
                                                 op.rng_len(self.tauCleanSel))

            varsToKeep['resolved_tag'] = op.static_cast(
                "UInt_t",
                op.AND(
                    op.rng_len(self.ak4Jets) >= 3,
                    op.rng_len(self.ak4BJets) >= 1,
                    op.rng_len(self.ak8BJets) == 0))
            varsToKeep['boosted_tag'] = op.static_cast(
                "UInt_t",
                op.AND(
                    op.rng_len(self.ak8BJets) >= 1,
                    op.rng_len(self.ak4JetsCleanedFromAk8b) >= 1))

            # Triggers #
            '''
            varsToKeep["triggers"]                  = self.triggers
            varsToKeep["triggers_SingleElectron"]   = op.OR(*self.triggersPerPrimaryDataset['SingleElectron'])
            varsToKeep["triggers_SingleMuon"]       = op.OR(*self.triggersPerPrimaryDataset['SingleMuon'])
            varsToKeep["triggers_DoubleElectron"]   = op.OR(*self.triggersPerPrimaryDataset['DoubleEGamma'])
            varsToKeep["triggers_DoubleMuon"]       = op.OR(*self.triggersPerPrimaryDataset['DoubleMuon'])
            varsToKeep["triggers_MuonElectron"]     = op.OR(*self.triggersPerPrimaryDataset['MuonEG'])
            '''
            # Muons #

            for i in range(1, 3):  # 2 leading muons
                varsToKeep["mu{}_pt".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].pt, op.c_float(-9999., "float"))
                varsToKeep["mu{}_eta".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].eta, op.c_float(-9999.))
                varsToKeep["mu{}_phi".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].phi, op.c_float(-9999.))
                varsToKeep["mu{}_E".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].p4.E(),
                    op.c_float(-9999., "float"))
                varsToKeep["mu{}_charge".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].charge, op.c_int(-9999.))
                varsToKeep["mu{}_conept".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muon_conept[self.muonsPreSel[i - 1].idx],
                    op.c_float(-9999.))
                varsToKeep["mu{}_miniRelIso".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].miniPFRelIso_all,
                    op.c_float(-9999.))
                varsToKeep["mu{}_PFRelIso04".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].pfRelIso04_all, op.c_float(-9999.))
                varsToKeep["mu{}_jetNDauChargedMVASel".format(i)] = op.c_float(
                    -9999.)
                varsToKeep["mu{}_jetPtRel".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].jetPtRelv2, op.c_float(-9999.))
                varsToKeep["mu{}_jetRelIso".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].jetRelIso, op.c_float(-9999.))
                varsToKeep["mu{}_jetDeepJet".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].jet.btagDeepFlavB,
                    op.c_float(-9999.))
                varsToKeep["mu{}_sip3D".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].sip3d, op.c_float(-9999.))
                varsToKeep["mu{}_dxy".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].dxy, op.c_float(-9999.))
                varsToKeep["mu{}_dxyAbs".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    op.abs(self.muonsPreSel[i - 1].dxy), op.c_float(-9999.))
                varsToKeep["mu{}_dz".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].dz, op.c_float(-9999.))
                varsToKeep["mu{}_segmentCompatibility".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].segmentComp, op.c_float(-9999.))
                varsToKeep["mu{}_leptonMVA".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].mvaTTH, op.c_float(-9999.))
                varsToKeep["mu{}_mediumID".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].mediumId,
                    op.c_float(-9999., "Bool_t"))
                varsToKeep["mu{}_dpt_div_pt".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].tunepRelPt,
                    op.c_float(-9999.))  # Not sure
                varsToKeep["mu{}_isfakeablesel".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    op.switch(self.lambda_muonFakeSel(self.muonsPreSel[i - 1]),
                              op.c_int(1), op.c_int(0)), op.c_int(-9999))
                varsToKeep["mu{}_ismvasel".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    op.switch(
                        op.AND(
                            self.lambda_muonTightSel(self.muonsPreSel[i - 1]),
                            self.lambda_muonFakeSel(self.muonsPreSel[i - 1])),
                        op.c_int(1), op.c_int(0)),
                    op.c_int(-9999))  # mvasel encompasses fakeablesel
                varsToKeep["mu{}_isGenMatched".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    op.switch(self.lambda_is_matched(self.muonsPreSel[i - 1]),
                              op.c_int(1), op.c_int(0)), op.c_int(-9999))
                varsToKeep["mu{}_genPartFlav".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].genPartFlav, op.c_int(-9999))
                varsToKeep["mu{}_FR".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.lambda_FR_mu(self.muonsPreSel[i - 1]),
                    op.c_int(-9999))
                varsToKeep["mu{}_FRcorr".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.lambda_FRcorr_mu(self.muonsPreSel[i - 1]),
                    op.c_int(-9999))
                varsToKeep["mu{}_FF".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.lambda_FF_mu(self.muonsPreSel[i - 1]),
                    op.c_int(-9999))
                varsToKeep["mu{}_looseSF".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    reduce(mul,
                           self.lambda_MuonLooseSF(self.muonsPreSel[i - 1])),
                    op.c_int(-9999))
                varsToKeep["mu{}_tightSF".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    reduce(mul,
                           self.lambda_MuonTightSF(self.muonsPreSel[i - 1])),
                    op.c_int(-9999))

            # Electrons #
            for i in range(1, 3):  # 2 leading electrons
                varsToKeep["ele{}_pt".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].pt, op.c_float(-9999.))
                varsToKeep["ele{}_eta".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].eta, op.c_float(-9999.))
                varsToKeep["ele{}_phi".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].phi, op.c_float(-9999.))
                varsToKeep["ele{}_E".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].p4.E(), op.c_float(-9999., ))
                varsToKeep["ele{}_charge".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].charge, op.c_int(-9999.))
                varsToKeep["ele{}_conept".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electron_conept[self.electronsPreSel[i - 1].idx],
                    op.c_float(-9999.))
                varsToKeep["ele{}_miniRelIso".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].miniPFRelIso_all,
                    op.c_float(-9999.))
                varsToKeep["ele{}_PFRelIso03".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].pfRelIso03_all,
                    op.c_float(-9999.))  # Iso03, Iso04 not in NanoAOD
                varsToKeep["ele{}_jetNDauChargedMVASel".format(
                    i)] = op.c_float(-9999.)
                varsToKeep["ele{}_jetPtRel".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].jetPtRelv2, op.c_float(-9999.))
                varsToKeep["ele{}_jetRelIso".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].jetRelIso, op.c_float(-9999.))
                varsToKeep["ele{}_jetDeepJet".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].jet.btagDeepFlavB,
                    op.c_float(-9999.))
                varsToKeep["ele{}_sip3D".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].sip3d, op.c_float(-9999.))

                varsToKeep["ele{}_dxy".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].dxy, op.c_float(-9999.))
                varsToKeep["ele{}_dxyAbs".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    op.abs(self.electronsPreSel[i - 1].dxy),
                    op.c_float(-9999.))
                varsToKeep["ele{}_dz".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].dz, op.c_float(-9999.))
                varsToKeep["ele{}_ntMVAeleID".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].mvaFall17V2noIso,
                    op.c_float(-9999.))
                varsToKeep["ele{}_leptonMVA".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].mvaTTH, op.c_float(-9999.))
                varsToKeep["ele{}_passesConversionVeto".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].convVeto,
                    op.c_float(-9999., "Bool_t"))
                varsToKeep["ele{}_nMissingHits".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].lostHits,
                    op.c_float(-9999., "UChar_t"))
                varsToKeep["ele{}_sigmaEtaEta".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].sieie, op.c_float(-9999.))
                varsToKeep["ele{}_HoE".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].hoe, op.c_float(-9999.))
                varsToKeep["ele{}_OoEminusOoP".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].eInvMinusPInv,
                    op.c_float(-9999.))
                varsToKeep["ele{}_isfakeablesel".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    op.switch(
                        self.lambda_electronFakeSel(self.electronsPreSel[i -
                                                                         1]),
                        op.c_int(1), op.c_int(0)), op.c_int(-9999))
                varsToKeep["ele{}_ismvasel".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    op.switch(
                        op.AND(
                            self.lambda_electronTightSel(
                                self.electronsPreSel[i - 1]),
                            self.lambda_electronFakeSel(
                                self.electronsPreSel[i - 1])), op.c_int(1),
                        op.c_int(0)),
                    op.c_int(-9999))  # mvasel encompasses fakeablesel
                varsToKeep["ele{}_isGenMatched".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    op.switch(
                        self.lambda_is_matched(self.electronsPreSel[i - 1]),
                        op.c_int(1), op.c_int(0)), op.c_int(-9999))
                varsToKeep["ele{}_genPartFlav".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].genPartFlav, op.c_int(-9999))
                varsToKeep["ele{}_deltaEtaSC".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].deltaEtaSC, op.c_int(-9999))
                varsToKeep["ele{}_FR".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.lambda_FR_el(self.electronsPreSel[i - 1]),
                    op.c_int(-9999))
                varsToKeep["ele{}_FRcorr".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.lambda_FRcorr_el(self.electronsPreSel[i - 1]),
                    op.c_int(-9999))
                varsToKeep["ele{}_FF".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.lambda_FF_el(self.electronsPreSel[i - 1]),
                    op.c_int(-9999))
                varsToKeep["ele{}_looseSF".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    reduce(
                        mul,
                        self.lambda_ElectronLooseSF(self.electronsPreSel[i -
                                                                         1])),
                    op.c_int(-9999))
                varsToKeep["ele{}_tightSF".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    reduce(
                        mul,
                        self.lambda_ElectronTightSF(self.electronsPreSel[i -
                                                                         1])),
                    op.c_int(-9999))

            # AK4 Jets #
            for i in range(1, 5):  # 4 leading jets
                varsToKeep["ak4Jet{}_pt".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i - 1].pt,
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_eta".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i - 1].eta,
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_phi".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i - 1].phi,
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_E".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i - 1].p4.E(),
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_CSV".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i,
                    self.ak4Jets[i - 1].btagDeepFlavB, op.c_float(-9999.))
                varsToKeep["ak4Jet{}_hadronFlavour".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i,
                    self.ak4Jets[i - 1].hadronFlavour, op.c_float(-9999.))
                varsToKeep["ak4Jet{}_btagSF".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i,
                    self.DeepJetDiscReshapingSF(self.ak4Jets[i - 1]),
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_puid_eff".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i,
                    self.jetpuid_mc_eff(self.ak4Jets[i - 1]),
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_puid_sfeff".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i,
                    self.jetpuid_sf_eff(self.ak4Jets[i - 1]),
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_puid_mis".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i,
                    self.jetpuid_mc_mis(self.ak4Jets[i - 1]),
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_puid_sfmis".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i,
                    self.jetpuid_sf_mis(self.ak4Jets[i - 1]),
                    op.c_float(-9999.))

            # VBF Jets #
            for i in range(1, 6):  # 5 leading jets
                varsToKeep["ak4JetVBF{}_pt".format(i)] = op.switch(
                    op.rng_len(self.VBFJetsPreSel) >= i,
                    self.VBFJetsPreSel[i - 1].pt, op.c_float(-9999.))
                varsToKeep["ak4JetVBF{}_eta".format(i)] = op.switch(
                    op.rng_len(self.VBFJetsPreSel) >= i,
                    self.VBFJetsPreSel[i - 1].eta, op.c_float(-9999.))
                varsToKeep["ak4JetVBF{}_phi".format(i)] = op.switch(
                    op.rng_len(self.VBFJetsPreSel) >= i,
                    self.VBFJetsPreSel[i - 1].phi, op.c_float(-9999.))
                varsToKeep["ak4JetVBF{}_E".format(i)] = op.switch(
                    op.rng_len(self.VBFJetsPreSel) >= i,
                    self.VBFJetsPreSel[i - 1].p4.E(), op.c_float(-9999.))
                varsToKeep["ak4JetVBF{}_CSV".format(i)] = op.switch(
                    op.rng_len(self.VBFJetsPreSel) >= i,
                    self.VBFJetsPreSel[i - 1].btagDeepFlavB,
                    op.c_float(-9999.))
                varsToKeep["ak4JetVBF{}_btagSF".format(i)] = op.switch(
                    op.rng_len(self.VBFJetsPreSel) >= i,
                    self.DeepJetDiscReshapingSF(self.VBFJetsPreSel[i - 1]),
                    op.c_float(-9999.))

            if not self.inclusive_sel:
                if not any([self.args.Res0b, self.args.Ak4, self.args.Ak8]):
                    varsToKeep["ak4JetVBFPair1_pt"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][0].pt, op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair1_eta"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][0].eta, op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair1_phi"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][0].phi, op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair1_E"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][0].p4.E(), op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair1_CSV"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][0].btagDeepFlavB, op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair1_btagSF"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        self.DeepJetDiscReshapingSF(VBFJetPairsJPA[0][0]),
                        op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair2_pt"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][1].pt, op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair2_eta"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][1].eta, op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair2_phi"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][1].phi, op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair2_E"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][1].p4.E(), op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair2_CSV"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        VBFJetPairsJPA[0][1].btagDeepFlavB, op.c_float(-9999.))
                    varsToKeep["ak4JetVBFPair2_btagSF"] = op.switch(
                        op.rng_len(VBFJetPairsJPA) >= 1,
                        self.DeepJetDiscReshapingSF(VBFJetPairsJPA[0][1]),
                        op.c_float(-9999.))
                else:
                    varsToKeep["ak4JetVBFPair1_pt"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair1_eta"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair1_phi"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair1_E"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair1_CSV"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair1_btagSF"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair2_pt"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair2_eta"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair2_phi"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair2_E"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair2_CSV"] = op.c_float(-9999.)
                    varsToKeep["ak4JetVBFPair2_btagSF"] = op.c_float(-9999.)

            # AK8 Jets #
            for i in range(1, 3):  # 2 leading fatjets
                varsToKeep["ak8Jet{}_pt".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].pt,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_eta".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].eta,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_phi".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].phi,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_E".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].p4.E(), op.c_float(-9999.))
                varsToKeep["ak8Jet{}_msoftdrop".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].msoftdrop, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_tau1".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].tau1,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_tau2".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].tau2,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet0_pt".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet1.pt, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet0_eta".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet1.eta, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet0_phi".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet1.phi, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet0_CSV".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet1.btagDeepB, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet1_pt".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet2.pt, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet1_eta".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet2.eta, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet1_phi".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet2.phi, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet1_CSV".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet2.btagDeepB, op.c_float(-9999.))

            varsToKeep["PFMET"] = self.corrMET.pt
            varsToKeep["PFMETphi"] = self.corrMET.phi
            varsToKeep["met1_E"] = self.corrMET.p4.E()
            varsToKeep["met1_pt"] = self.corrMET.pt
            varsToKeep["met1_eta"] = self.corrMET.eta
            varsToKeep["met1_phi"] = self.corrMET.phi

            # SF #
            electronMuon_cont = op.combine(
                (self.electronsFakeSel, self.muonsFakeSel))

            varsToKeep["trigger_SF"] = op.multiSwitch(
                (op.AND(
                    op.rng_len(self.electronsTightSel) == 1,
                    op.rng_len(self.muonsTightSel) == 0),
                 self.ttH_singleElectron_trigSF(self.electronsTightSel[0])),
                (op.AND(
                    op.rng_len(self.electronsTightSel) == 0,
                    op.rng_len(self.muonsTightSel)
                    == 1), self.ttH_singleMuon_trigSF(self.muonsTightSel[0])),
                (op.AND(
                    op.rng_len(self.electronsTightSel) >= 2,
                    op.rng_len(self.muonsTightSel) == 0),
                 self.lambda_ttH_doubleElectron_trigSF(
                     self.electronsTightSel)),
                (op.AND(
                    op.rng_len(self.electronsTightSel) == 0,
                    op.rng_len(self.muonsTightSel) >= 2),
                 self.lambda_ttH_doubleMuon_trigSF(self.muonsTightSel)),
                (op.AND(
                    op.rng_len(self.electronsTightSel) >= 1,
                    op.rng_len(self.muonsTightSel) >= 1),
                 self.lambda_ttH_electronMuon_trigSF(electronMuon_cont[0])),
                op.c_float(1.))

            if not self.inclusive_sel:
                varsToKeep["weight_trigger_el_sf"] = op.switch(
                    op.rng_len(self.electronsTightSel) > 0,
                    self.ttH_singleElectron_trigSF(lep), op.c_float(1.))
                varsToKeep["weight_trigger_mu_sf"] = op.switch(
                    op.rng_len(self.muonsTightSel) > 0,
                    self.ttH_singleMuon_trigSF(lep), op.c_float(1.))

                varsToKeep["lepton_IDSF"] = op.rng_product(self.electronsFakeSel, lambda el : reduce(mul,self.lambda_ElectronLooseSF(el)+self.lambda_ElectronTightSF(el))) * \
                                            op.rng_product(self.muonsFakeSel, lambda mu : reduce(mul,self.lambda_MuonLooseSF(mu)+self.lambda_MuonTightSF(mu)))

                varsToKeep["lepton_IDSF_recoToLoose"]  = op.rng_product(self.electronsFakeSel, lambda el : reduce(mul,self.lambda_ElectronLooseSF(el))) * \
                                                        op.rng_product(self.muonsFakeSel, lambda mu : reduce(mul,self.lambda_MuonLooseSF(mu)))
                varsToKeep["lepton_IDSF_looseToTight"] = op.rng_product(self.electronsFakeSel, lambda el : reduce(mul,self.lambda_ElectronTightSF(el))) * \
                                                         op.rng_product(self.muonsFakeSel, lambda mu : reduce(mul,self.lambda_MuonTightSF(mu)))
                if era == "2016" or era == "2017":
                    if self.args.Channel == "El":
                        varsToKeep["weight_electron_reco_low"] = op.switch(
                            op.AND(self.lambda_is_matched(lep), lep.pt <= 20.),
                            self.elLooseRecoPtLt20(lep), op.c_float(1.))
                        varsToKeep["weight_electron_reco_high"] = op.switch(
                            op.AND(self.lambda_is_matched(lep), lep.pt > 20.),
                            self.elLooseRecoPtGt20(lep), op.c_float(1.))
                        varsToKeep["weight_muon_idiso_loose"] = op.c_float(1.)
                        varsToKeep["weight_electron_id_loose_01"] = op.switch(
                            self.lambda_is_matched(lep), self.elLooseEff(lep),
                            op.c_float(1.))
                        varsToKeep["weight_electron_id_loose_02"] = op.switch(
                            self.lambda_is_matched(lep), self.elLooseId(lep),
                            op.c_float(1.))
                        varsToKeep[
                            "weight_electron_tth_loose"] = self.lambda_ElectronTightSF(
                                lep)[0]
                        varsToKeep["weight_muon_tth_loose"] = op.c_float(1.)

                    if self.args.Channel == "Mu":
                        varsToKeep["weight_muon_idiso_loose"] = op.switch(
                            self.lambda_is_matched(lep), self.muLooseId(lep),
                            op.c_float(1.))
                        varsToKeep["weight_electron_reco_low"] = op.c_float(1.)
                        varsToKeep["weight_electron_reco_high"] = op.c_float(
                            1.)
                        varsToKeep["weight_electron_id_loose_01"] = op.c_float(
                            1.)
                        varsToKeep["weight_electron_id_loose_02"] = op.c_float(
                            1.)
                        varsToKeep["weight_electron_tth_loose"] = op.c_float(
                            1.)
                        varsToKeep[
                            "weight_muon_tth_loose"] = self.lambda_MuonTightSF(
                                lep)[0]
                else:
                    raise NotImplementedError

            # L1 Prefire #
            if era in ["2016", "2017"]:
                varsToKeep["L1prefire"] = self.L1Prefiring
                varsToKeep["weight_l1_ecal_prefiring"] = self.L1Prefiring
            else:
                varsToKeep["L1prefire"] = op.c_float(-9999.)
                varsToKeep["weight_l1_ecal_prefiring"] = op.c_float(-9999.)

            # Fake rate #
            if self.args.Channel == "El":
                varsToKeep["fakeRate"] = op.switch(
                    self.lambda_electronTightSel(self.electronsFakeSel[0]),
                    self.ElFakeFactor(self.electronsFakeSel[0]),
                    op.c_float(1.))
                varsToKeep["weight_fake_electrons"] = op.switch(
                    self.lambda_electronTightSel(self.electronsFakeSel[0]),
                    op.abs(self.ElFakeFactor(self.electronsFakeSel[0])),
                    op.c_float(1.))
                varsToKeep["weight_fake_muons"] = op.c_float(1.)
                varsToKeep["weight_fake_two_non_tight"] = op.c_float(999.0)
            if self.args.Channel == "Mu":
                varsToKeep["fakeRate"] = op.switch(
                    self.lambda_muonTightSel(self.muonsFakeSel[0]),
                    self.MuFakeFactor(self.muonsFakeSel[0]), op.c_float(1.))
                varsToKeep["weight_fake_electrons"] = op.c_float(1.)
                varsToKeep["weight_fake_muons"] = op.switch(
                    self.lambda_muonTightSel(self.muonsFakeSel[0]),
                    op.abs(self.MuFakeFactor(self.muonsFakeSel[0])),
                    op.c_float(1.))
                varsToKeep["weight_fake_two_non_tight"] = op.c_float(999.0)

            if self.is_MC:
                varsToKeep["weight_fake_is_mc"] = op.c_float(-1.)
            else:
                varsToKeep["weight_fake_is_mc"] = op.c_float(1.)

            # PU ID SF #
            varsToKeep["PU_jetID_SF"] = self.puid_reweighting
            varsToKeep[
                "weight_jet_PUid_efficiency"] = self.puid_reweighting_efficiency
            varsToKeep["weight_jet_PUid_mistag"] = self.puid_reweighting_mistag

            # Btagging SF #
            varsToKeep["btag_SF"] = self.btagAk4SF
            varsToKeep["weight_btagWeight"] = self.btagAk4SF
            if "BtagRatioWeight" in self.__dict__.keys():
                varsToKeep["btag_ratio_SF"] = self.BtagRatioWeight
                varsToKeep["weight_btagNorm"] = self.BtagRatioWeight

            # PS weights #
            varsToKeep["weight_PSWeight_ISR"] = self.psISRSyst
            varsToKeep["weight_PSWeight_FSR"] = self.psFSRSyst

            # ttbar PT reweighting #
            if "group" in sampleCfg and sampleCfg["group"] == 'ttbar':
                varsToKeep["topPt_wgt"] = self.ttbar_weight(
                    self.genTop[0], self.genAntitop[0])

        # Event Weight #
            if self.is_MC:
                varsToKeep["MC_weight"] = t.genWeight
                puWeightsFile = os.path.join(os.path.dirname(__file__), "data",
                                             "pileup",
                                             sample + '_%s.json' % era)
                #puWeightsFile = os.path.join(os.path.dirname(__file__), "data" , "pileup", sampleCfg["pufile"])
                varsToKeep["PU_weight"] = makePileupWeight(
                    puWeightsFile,
                    t.Pileup_nTrueInt,
                    nameHint=f"puweightFromFile{sample}".replace('-', '_'))
                varsToKeep[
                    "eventWeight"] = noSel.weight if self.inclusive_sel else selObj.sel.weight

            if self.inclusive_sel:
                return noSel, varsToKeep
            else:
                return selObj.sel, varsToKeep

        #---------------------------------------------------------------------------------------#
        #                                    Selection tree                                     #
        #---------------------------------------------------------------------------------------#
        #----- EVT variables -----#
        varsToKeep["event"] = None  # Already in tree
        varsToKeep["run"] = None  # Already in tree
        varsToKeep["ls"] = t.luminosityBlock

        genVarsList = self.HLL.comp_cosThetaSbetBeamAndHiggs(t.GenPart)
        varsToKeep['mHH_gen'] = genVarsList[0]
        varsToKeep['consTheta1_gen'] = genVarsList[1]
        varsToKeep['consTheta2_gen'] = genVarsList[2]

        if any([
                self.args.__dict__[item] for item in [
                    "Ak4", "Res2b2Wj", "Res2b1Wj", "Res2b0Wj", "Res1b2Wj",
                    "Res1b1Wj", "Res1b0Wj", "Res0b"
                ]
        ]):
            commonInputs_Resolved = returnCommonInputs_Resolved(self=self)
            classicInputs_Resolved = returnClassicInputs_Resolved(
                self=self,
                lepton=lep,
                jpaSelectedJets=jpaJets,
                L1out=L1out,
                L2out=L2out,
                jpaArg=jpaarg)
            inputs_resolved = {
                **commonInputs_Resolved,
                **classicInputs_Resolved
            }

            for (varname, _, _), var in inputs_resolved.items():
                varsToKeep[varname] = var

        #----- Fatjet variables -----#
        if any([
                self.args.__dict__[item]
                for item in ["Ak8", "Hbb2Wj", "Hbb1Wj", "Hbb0Wj"]
        ]):
            commonInputs_Boosted = returnCommonInputs_Boosted(self=self)
            classicInputs_Boosted = returnClassicInputs_Boosted(
                self=self,
                lepton=lep,
                jpaSelectedJets=jpaJets,
                L1out=L1out,
                L2out=L2out,
                jpaArg=jpaarg)
            inputs_boosted = {**commonInputs_Boosted, **classicInputs_Boosted}

            for (varname, _, _), var in inputs_boosted.items():
                varsToKeep[varname] = var

        #----- Additional variables -----#
        varsToKeep["MC_weight"] = t.genWeight
        varsToKeep['total_weight'] = selObj.sel.weight

        #return leptonSel.sel, varsToKeep
        return selObj.sel, varsToKeep
コード例 #16
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
コード例 #17
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        noSel = super(TransferFunction,
                      self).prepareObjects(t, noSel, sample, sampleCfg, 'DL')
        noSel = self.beforeJetselection(noSel)
        era = sampleCfg['era']
        plots = []

        if not self.is_MC:
            return plots

        lambda_is_matched = lambda lep: op.OR(
            lep.genPartFlav == 1,  # Prompt muon or electron
            lep.genPartFlav == 15)  # From tau decay
        #lep.genPartFlav==22) # From photon conversion (only available for electrons)

        plots.append(
            Plot.make1D("totalWeight",
                        noSel.weight,
                        noSel,
                        EquidistantBinning(100, -int(10**5), int(10**5)),
                        xTitle="total weight"))
        plots.append(
            Plot.make1D("genWeight",
                        t.genWeight,
                        noSel,
                        EquidistantBinning(100, -int(10**5), int(10**5)),
                        xTitle="gen weight"))

        ##########################################################
        #                       Leptons                          #
        ##########################################################
        #----- Gen particles -----#
        gen_e = op.select(
            t.GenPart, lambda g: op.AND(
                op.abs(g.pdgId) == 11, g.statusFlags & (0x1 << 13), g.pt >= 10,
                op.abs(g.eta) < 2.5))
        gen_m = op.select(
            t.GenPart, lambda g: op.AND(
                op.abs(g.pdgId) == 13, g.statusFlags & (0x1 << 13), g.pt >= 10,
                op.abs(g.eta) < 2.4))

        #----- Reco particles -----#
        lambda_reco_e = lambda el: op.AND(
            op.abs(el.pdgId) == 11, el.pt >= 10,
            op.abs(el.eta) < 2.5, lambda_is_matched(el))
        lambda_reco_m = lambda mu: op.AND(
            op.abs(mu.pdgId) == 13, mu.pt >= 10,
            op.abs(mu.eta) < 2.4, lambda_is_matched(mu))

        reco_e = op.select(self.electronsFakeSel, lambda_reco_e)
        reco_m = op.select(self.muonsFakeSel, lambda_reco_m)

        #---- Matching -----#
        lambda_lepton_match = lambda gen, reco: op.AND(
            op.deltaR(gen.p4, reco.p4) < 0.1, (op.abs(gen.pt - reco.pt) /
                                               (gen.pt + reco.pt)) < 0.2)

        #        reco_e_matched = op.select(reco_e, lambda re : op.rng_any(gen_e, lambda ge: lambda_lepton_match(ge,re)))
        #        reco_m_matched = op.select(reco_m, lambda rm : op.rng_any(gen_m, lambda gm: lambda_lepton_match(gm,rm)))

        #match_e = op.combine((gen_e,reco_e), pred = lambda ge,re : re.idx == op.rng_min_element_by(reco_e_matched,lambda re_matched : op.deltaR(ge.p4,re_matched.p4)).idx)
        #match_m = op.combine((gen_m,reco_m), pred = lambda gm,rm : rm.idx == op.rng_min_element_by(reco_m_matched,lambda rm_matched : op.deltaR(gm.p4,rm_matched.p4)).idx)

        match_e = op.combine((gen_e, reco_e), pred=lambda_lepton_match)
        match_m = op.combine((gen_m, reco_m), pred=lambda_lepton_match)

        plots.extend(plotMatching("e", match_e, noSel, "e^{#pm}"))
        plots.extend(plotMatching("m", match_m, noSel, "#mu^{#pm}"))

        #        plots.append(plotRecoForGen(noSel,gen_e,tight_e,lambda_lepton_match,"e_tight"))
        #        plots.append(plotRecoForGen(noSel,gen_e,tight_m,lambda_lepton_match,"m_tight"))

        ##########################################################
        #                       Ak4 B jets                       #
        ##########################################################
        #----- RecoJets -----#
        recoJet_b = op.select(
            t.Jet, lambda j: op.AND(
                op.abs(j.partonFlavour) == 5, j.pt >= 20,
                op.abs(j.eta) < 2.4, j.genJet.isValid))
        #----- Parton -----#
        gen_b = op.select(
            t.GenPart, lambda g: op.AND(
                op.abs(g.pdgId) == 5, g.statusFlags & (0x1 << 13), g.pt >= 20,
                op.abs(g.eta) < 2.4))
        #----- Matching -----#
        lambda_jet_match = lambda gen, reco: op.AND(
            op.deltaR(gen.p4, reco.p4) < 0.2)
        reco_b_matched = op.select(
            recoJet_b, lambda jetb: op.rng_any(
                gen_b, lambda gb: lambda_jet_match(gb, jetb)))
        match_b = op.combine(
            (gen_b, recoJet_b),
            pred=lambda gb, jetb: jetb.idx == op.rng_min_element_by(
                reco_b_matched, lambda rb_matched: op.deltaR(
                    gb.p4, rb_matched.p4)).idx)
        plots.extend(plotMatching("ak4b", match_b, noSel, "b"))

        ##########################################################
        #                       Ak4 C jets                       #
        ##########################################################
        #----- RecoJets -----#
        recoJet_c = op.select(
            t.Jet, lambda j: op.AND(
                op.abs(j.partonFlavour) == 4, j.pt >= 20,
                op.abs(j.eta) < 2.4, j.genJet.isValid))
        #----- Parton -----#
        gen_c = op.select(
            t.GenPart, lambda g: op.AND(
                op.abs(g.pdgId) == 4, g.statusFlags & (0x1 << 13), g.pt >= 20,
                op.abs(g.eta) < 2.4))
        #----- Matching -----#
        reco_c_matched = op.select(
            recoJet_c, lambda jetc: op.rng_any(
                gen_c, lambda gc: lambda_jet_match(gc, jetc)))
        match_c = op.combine(
            (gen_c, recoJet_c),
            pred=lambda gc, jetc: jetc.idx == op.rng_min_element_by(
                reco_c_matched, lambda rc_matched: op.deltaR(
                    gc.p4, rc_matched.p4)).idx)
        plots.extend(plotMatching("ak4c", match_c, noSel, "c"))

        ##########################################################
        #                     Ak4 lightjets                      #
        ##########################################################
        #----- RecoJets -----#
        recoJet_l = op.select(
            t.Jet, lambda j: op.AND(
                op.OR(
                    op.abs(j.partonFlavour) == 1,
                    op.abs(j.partonFlavour) == 2,
                    op.abs(j.partonFlavour) == 3), j.pt >= 20,
                op.abs(j.eta) < 2.4, j.genJet.isValid))
        #----- Parton -----#
        gen_l = op.select(
            t.GenPart, lambda g: op.AND(
                op.OR(
                    op.abs(g.pdgId) == 1,
                    op.abs(g.pdgId) == 2,
                    op.abs(g.pdgId) == 3), g.statusFlags &
                (0x1 << 13), g.pt >= 20,
                op.abs(g.eta) < 2.4))
        #----- Matching -----#
        reco_l_matched = op.select(
            recoJet_l, lambda jetl: op.rng_any(
                gen_l, lambda gl: lambda_jet_match(gl, jetl)))
        match_l = op.combine(
            (gen_l, recoJet_l),
            pred=lambda gl, jetl: jetl.idx == op.rng_min_element_by(
                reco_l_matched, lambda rl_matched: op.deltaR(
                    gl.p4, rl_matched.p4)).idx)
        plots.extend(plotMatching("ak4l", match_l, noSel, "l"))

        ##########################################################
        #                        Ak8 jets                        #
        ##########################################################
        #----- RecoJets -----#
        recoFatJet = op.select(
            t.FatJet, lambda j: op.AND(
                j.pt >= 100,
                op.abs(j.eta) < 2.4,
                op.AND(j.subJet1.isValid, j.subJet1.pt >= 20.,
                       op.abs(j.subJet1.eta) <= 2.4, j.subJet2.isValid, j.
                       subJet2.pt >= 20.,
                       op.abs(j.subJet2.eta) <= 2.4),
                op.AND(j.msoftdrop >= 30, j.msoftdrop <= 210), j.tau2 / j.tau1
                <= 0.75))

        #plots.extend(fatjetPlots(noSel,recoFatJet,"fatjet"))

        reco_subJet1_b_matched = op.select(
            recoFatJet, lambda fat: op.rng_any(
                gen_b, lambda gb: lambda_jet_match(gb, fat.subJet1)))
        reco_subJet2_b_matched = op.select(
            recoFatJet, lambda fat: op.rng_any(
                gen_b, lambda gb: lambda_jet_match(gb, fat.subJet2)))
        reco_subJet1_c_matched = op.select(
            recoFatJet, lambda fat: op.rng_any(
                gen_c, lambda gc: lambda_jet_match(gc, fat.subJet1)))
        reco_subJet2_c_matched = op.select(
            recoFatJet, lambda fat: op.rng_any(
                gen_c, lambda gc: lambda_jet_match(gc, fat.subJet2)))
        reco_subJet1_l_matched = op.select(
            recoFatJet, lambda fat: op.rng_any(
                gen_l, lambda gl: lambda_jet_match(gl, fat.subJet1)))
        reco_subJet2_l_matched = op.select(
            recoFatJet, lambda fat: op.rng_any(
                gen_l, lambda gl: lambda_jet_match(gl, fat.subJet2)))

        def makeFatjetMatch(gen1, gen2, recoFatJet):
            return op.combine(
                (gen1, gen2, recoFatJet),
                pred=lambda g1, g2, fat: op.AND(
                    fat.subJet1.idx == op.rng_min_element_by(
                        reco_subJet1_b_matched, lambda sub1_matched: op.deltaR(
                            g1.p4, sub1_matched.p4)).idx, fat.subJet2.idx == op
                    .rng_min_element_by(
                        reco_subJet2_b_matched, lambda sub2_matched: op.deltaR(
                            g2.p4, sub2_matched.p4)).idx))

        match_fat_bb = makeFatjetMatch(gen_b, gen_b, recoFatJet)
        match_fat_bc = makeFatjetMatch(gen_b, gen_c, recoFatJet)
        match_fat_bl = makeFatjetMatch(gen_b, gen_l, recoFatJet)
        match_fat_cb = makeFatjetMatch(gen_c, gen_b, recoFatJet)
        match_fat_cc = makeFatjetMatch(gen_c, gen_c, recoFatJet)
        match_fat_cl = makeFatjetMatch(gen_c, gen_l, recoFatJet)
        match_fat_lb = makeFatjetMatch(gen_l, gen_b, recoFatJet)
        match_fat_lc = makeFatjetMatch(gen_l, gen_c, recoFatJet)
        match_fat_ll = makeFatjetMatch(gen_l, gen_l, recoFatJet)
        #        match_fat_bb = op.combine((gen_b,gen_b,recoFatJet), pred = lambda g1,g2,fat : op.AND(
        #                                                fat.subJet1.idx == op.rng_min_element_by(reco_subJet1_b_matched,
        #                                                                                         lambda sub1_matched : op.deltaR(gb1.p4,sub1_matched.p4)).idx,
        #                                                fat.subJet2.idx == op.rng_min_element_by(reco_subJet2_b_matched,
        #                                                                                         lambda sub2_matched : op.deltaR(gb2.p4,sub2_matched.p4)).idx))
        #        match_fat_bc = op.combine((gen_b,gen_b,recoFatJet), pred = lambda gb1,gb2,fat : op.AND(
        #                                                fat.subJet1.idx == op.rng_min_element_by(reco_subJet1_b_matched,
        #                                                                                         lambda sub1_matched : op.deltaR(gb1.p4,sub1_matched.p4)).idx,
        #                                                fat.subJet2.idx == op.rng_min_element_by(reco_subJet2_b_matched,
        #                                                                                         lambda sub2_matched : op.deltaR(gb2.p4,sub2_matched.p4)).idx))

        plots.extend(plotFatjetMatching(match_fat_bb, noSel, 'b', 'b'))
        plots.extend(plotFatjetMatching(match_fat_bc, noSel, 'b', 'c'))
        plots.extend(plotFatjetMatching(match_fat_bl, noSel, 'b', 'l'))
        plots.extend(plotFatjetMatching(match_fat_cb, noSel, 'c', 'b'))
        plots.extend(plotFatjetMatching(match_fat_cc, noSel, 'c', 'c'))
        plots.extend(plotFatjetMatching(match_fat_cl, noSel, 'c', 'l'))
        plots.extend(plotFatjetMatching(match_fat_bb, noSel, 'l', 'b'))
        plots.extend(plotFatjetMatching(match_fat_bc, noSel, 'l', 'c'))
        plots.extend(plotFatjetMatching(match_fat_bl, noSel, 'l', 'l'))

        return plots
コード例 #18
0
    def defineSkimSelection(self, t, noSel, sample=None, sampleCfg=None): 
        noSel = super(SkimmerMEMNanoHHtobbWWDL,self).prepareObjects(t, noSel, sample, sampleCfg, "DL", forSkimmer=True)
            # For the Skimmer, SF must not use defineOnFirstUse -> segmentation fault

        era = sampleCfg['era'] 

        # Initialize varsToKeep dict #
        varsToKeep = dict()  

        if self.inclusive_sel:
            raise RuntimeError("Inclusive analysis not possible")

        #---------------------------------------------------------------------------------------# 
        #                                     Selections                                        #
        #---------------------------------------------------------------------------------------#
        #----- Check arguments -----#
        jet_level = ["Resolved0Btag","Resolved1Btag","Resolved2Btag","Boosted0Btag","Boosted1Btag"] # Only one must be in args

        if [boolean for (level,boolean) in self.args.__dict__.items() if level in jet_level].count(True) != 1:
            raise RuntimeError("Only one of the jet arguments must be used, check --help")
        if self.args.Channel not in ["ElEl","MuMu","ElMu"]:
            raise RuntimeError("Channel must be either 'ElEl', 'MuMu' or 'ElMu'")

        #----- Lepton selection -----#
        # Args are passed within the self #
        ElElSelObj,MuMuSelObj,ElMuSelObj = makeDoubleLeptonSelection(self,noSel,use_dd=False,fake_selection=self.args.FakeCR)
        if self.args.Channel == "ElEl":
            selObj = ElElSelObj
            dilepton = self.ElElFakeSel[0]
        if self.args.Channel == "MuMu":
            selObj = MuMuSelObj
            dilepton = self.MuMuFakeSel[0]
        if self.args.Channel == "ElMu":
            selObj = ElMuSelObj
            dilepton = self.ElMuFakeSel[0]

        #----- Jet selection -----#
        # Since the selections in one line, we can use the non copy option of the selection to modify the selection object internally
        if any([self.args.__dict__[item] for item in ["Ak4","Resolved0Btag","Resolved1Btag","Resolved2Btag"]]):
            makeAtLeastTwoAk4JetSelection(self,selObj,use_dd=False) 
        if any([self.args.__dict__[item] for item in ["Ak8","Boosted0Btag","Boosted1Btag"]]):
           makeAtLeastOneAk8JetSelection(self,selObj,use_dd=False) 
        if self.args.Resolved0Btag:
            makeExclusiveResolvedNoBtagSelection(self,selObj,use_dd=False)
        if self.args.Resolved1Btag:
            makeExclusiveResolvedOneBtagSelection(self,selObj,use_dd=False)
        if self.args.Resolved2Btag:
            makeExclusiveResolvedTwoBtagsSelection(self,selObj,use_dd=False)
        if self.args.Boosted0Btag:
            makeInclusiveBoostedNoBtagSelection(self,selObj,use_dd=False)
        if self.args.Boosted1Btag:
            makeInclusiveBoostedOneBtagSelection(self,selObj,use_dd=False)


        #---------------------------------------------------------------------------------------# 
        #                                    Selection tree                                     #
        #---------------------------------------------------------------------------------------#

        #----- MET variables -----#
        MET = self.corrMET

        varsToKeep['met_pt']  = MET.pt
        varsToKeep['met_phi']  = MET.phi
        varsToKeep['met_E'] = MET.p4.E()
        varsToKeep['met_Px'] = MET.p4.Px()
        varsToKeep['met_Py'] = MET.p4.Py()
        varsToKeep['met_Pz'] = MET.p4.Pz()

        #----- Lepton variables -----#
        if self.args.Channel is None:
            raise RuntimeError("You need to specify --Channel")
        if self.args.Channel == "ElEl": dilepton = self.ElElTightSel[0]
        if self.args.Channel == "MuMu": dilepton = self.MuMuTightSel[0]
        if self.args.Channel == "ElMu": dilepton = self.ElMuTightSel[0]

        varsToKeep["is_SR"] = op.static_cast("UInt_t",op.OR(op.rng_len(self.ElElTightSel)>0,
                                                            op.rng_len(self.MuMuTightSel)>0,
                                                            op.rng_len(self.ElMuTightSel)>0))
        varsToKeep['is_ee'] = op.static_cast("UInt_t",op.rng_len(self.ElElTightSel)>0)
        varsToKeep['is_mm'] = op.static_cast("UInt_t",op.rng_len(self.MuMuTightSel)>0)
        varsToKeep['is_em'] = op.static_cast("UInt_t",op.rng_len(self.ElMuTightSel)>0)
        varsToKeep['resolved1b_tag'] = op.static_cast("UInt_t",op.AND(op.rng_len(self.ak4BJets)==1,op.rng_len(self.ak8BJets)==0))
        varsToKeep['resolved2b_tag'] = op.static_cast("UInt_t",op.AND(op.rng_len(self.ak4BJets)>=2,op.rng_len(self.ak8BJets)==0))
        varsToKeep['boosted1b_tag'] = op.static_cast("UInt_t",op.AND(op.rng_len(self.ak8BJets)>0))

        l1 = dilepton[0]
        l2 = dilepton[1]

        varsToKeep['l1_Px']     = l1.p4.Px()
        varsToKeep['l1_Py']     = l1.p4.Py()
        varsToKeep['l1_Pz']     = l1.p4.Pz()
        varsToKeep['l1_E']      = l1.p4.E()
        varsToKeep['l1_pt']     = l1.pt
        varsToKeep['l1_eta']    = l1.eta
        varsToKeep['l1_phi']    = l1.phi
        varsToKeep['l1_pdgId']  = l1.pdgId
        varsToKeep['l1_charge'] = l1.charge

        varsToKeep['l2_Px']     = l2.p4.Px()
        varsToKeep['l2_Py']     = l2.p4.Py()
        varsToKeep['l2_Pz']     = l2.p4.Pz()
        varsToKeep['l2_E']      = l2.p4.E()
        varsToKeep['l2_pt']     = l2.pt
        varsToKeep['l2_eta']    = l2.eta
        varsToKeep['l2_phi']    = l2.phi
        varsToKeep['l2_pdgId']  = l2.pdgId
        varsToKeep['l2_charge'] = l2.charge

        #----- Jet variables -----#
        jets = self.ak4JetsByBtagScore
        for idx in range(1,5):
            varsToKeep[f'j{idx}_Px']  = op.switch(op.rng_len(jets)>=idx, jets[idx-1].p4.Px(), op.c_float(-9999))
            varsToKeep[f'j{idx}_Py']  = op.switch(op.rng_len(jets)>=idx, jets[idx-1].p4.Py(), op.c_float(-9999))
            varsToKeep[f'j{idx}_Pz']  = op.switch(op.rng_len(jets)>=idx, jets[idx-1].p4.Pz(), op.c_float(-9999))
            varsToKeep[f'j{idx}_E']   = op.switch(op.rng_len(jets)>=idx, jets[idx-1].p4.E(), op.c_float(-9999))
            varsToKeep[f'j{idx}_pt']  = op.switch(op.rng_len(jets)>=idx, jets[idx-1].pt, op.c_float(-9999))
            varsToKeep[f'j{idx}_eta'] = op.switch(op.rng_len(jets)>=idx, jets[idx-1].eta, op.c_float(-9999))
            varsToKeep[f'j{idx}_phi'] = op.switch(op.rng_len(jets)>=idx, jets[idx-1].phi, op.c_float(-9999))
            varsToKeep[f'j{idx}_btag']= op.switch(op.rng_len(jets)>=idx, jets[idx-1].btagDeepFlavB, op.c_float(-9999))


        varsToKeep['n_ak4'] = op.static_cast("UInt_t",op.rng_len(self.ak4Jets))
        varsToKeep['n_ak4_btag'] = op.static_cast("UInt_t",op.rng_len(self.ak4BJets))


        #----- Fatjet variables -----#
        fatjets = self.ak8BJets
        subJet1 = fatjets[0].subJet1
        subJet2 = fatjets[0].subJet2

        varsToKeep['fatj_sub1_Px']   = op.switch(op.rng_len(fatjets)>0, subJet1.p4.Px(), op.c_float(-9999))
        varsToKeep['fatj_sub1_Py']   = op.switch(op.rng_len(fatjets)>0, subJet1.p4.Py(), op.c_float(-9999))
        varsToKeep['fatj_sub1_Pz']   = op.switch(op.rng_len(fatjets)>0, subJet1.p4.Pz(), op.c_float(-9999))
        varsToKeep['fatj_sub1_E']    = op.switch(op.rng_len(fatjets)>0, subJet1.p4.E(), op.c_float(-9999))
        varsToKeep['fatj_sub1_pt']   = op.switch(op.rng_len(fatjets)>0, subJet1.pt, op.c_float(-9999))
        varsToKeep['fatj_sub1_eta']  = op.switch(op.rng_len(fatjets)>0, subJet1.eta, op.c_float(-9999))
        varsToKeep['fatj_sub1_phi']  = op.switch(op.rng_len(fatjets)>0, subJet1.phi, op.c_float(-9999))
        varsToKeep['fatj_sub1_btag'] = op.switch(op.rng_len(fatjets)>0, subJet1.btagDeepB, op.c_float(-9999))

        varsToKeep['fatj_sub2_Px']   = op.switch(op.rng_len(fatjets)>0, subJet2.p4.Px(), op.c_float(-9999))
        varsToKeep['fatj_sub2_Py']   = op.switch(op.rng_len(fatjets)>0, subJet2.p4.Py(), op.c_float(-9999))
        varsToKeep['fatj_sub2_Pz']   = op.switch(op.rng_len(fatjets)>0, subJet2.p4.Pz(), op.c_float(-9999))
        varsToKeep['fatj_sub2_E']    = op.switch(op.rng_len(fatjets)>0, subJet2.p4.E(), op.c_float(-9999))
        varsToKeep['fatj_sub2_pt']   = op.switch(op.rng_len(fatjets)>0, subJet2.pt, op.c_float(-9999))
        varsToKeep['fatj_sub2_eta']  = op.switch(op.rng_len(fatjets)>0, subJet2.eta, op.c_float(-9999))
        varsToKeep['fatj_sub2_phi']  = op.switch(op.rng_len(fatjets)>0, subJet2.phi, op.c_float(-9999))
        varsToKeep['fatj_sub2_btag'] = op.switch(op.rng_len(fatjets)>0, subJet2.btagDeepB, op.c_float(-9999))

        varsToKeep['fatj_Px']             = op.switch(op.rng_len(fatjets)>0, fatjets[0].p4.Px(), op.c_float(-9999))
        varsToKeep['fatj_Py']             = op.switch(op.rng_len(fatjets)>0, fatjets[0].p4.Py(), op.c_float(-9999))
        varsToKeep['fatj_Pz']             = op.switch(op.rng_len(fatjets)>0, fatjets[0].p4.Pz(), op.c_float(-9999))
        varsToKeep['fatj_E']              = op.switch(op.rng_len(fatjets)>0, fatjets[0].p4.E(), op.c_float(-9999))
        varsToKeep['fatj_pt']             = op.switch(op.rng_len(fatjets)>0, fatjets[0].pt, op.c_float(-9999))
        varsToKeep['fatj_eta']            = op.switch(op.rng_len(fatjets)>0, fatjets[0].eta, op.c_float(-9999))
        varsToKeep['fatj_phi']            = op.switch(op.rng_len(fatjets)>0, fatjets[0].phi, op.c_float(-9999))
        varsToKeep['fatj_softdropMass']   = op.switch(op.rng_len(fatjets)>0, fatjets[0].msoftdrop, op.c_float(-9999))
        varsToKeep['fatj_btagDeepB']      = op.switch(op.rng_len(fatjets)>0, fatjets[0].btagDeepB, op.c_float(-9999))
        varsToKeep['fatj_btagHbb']        = op.switch(op.rng_len(fatjets)>0, fatjets[0].btagHbb, op.c_float(-9999))

        varsToKeep['n_ak8'] = op.static_cast("UInt_t",op.rng_len(self.ak8Jets))
        varsToKeep['n_ak8_btag'] = op.static_cast("UInt_t",op.rng_len(self.ak8BJets))

        #----- Additional variables -----#
        if self.is_MC:
            varsToKeep["MC_weight"]         = t.genWeight
        varsToKeep['total_weight']      = selObj.sel.weight
        varsToKeep["event"]             = None # Already in tree
        varsToKeep["run"]               = None # Already in tree 
        varsToKeep["ls"]                = t.luminosityBlock

        return selObj.sel, varsToKeep
コード例 #19
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        era = sampleCfg['era']
        plots = []

        ##########################################################
        #                       Leptons                          #
        ##########################################################
        #----- Gen particles -----#
        gen_e_minus = op.select(
            t.GenPart, lambda g: op.AND(g.pdgId == 11, g.statusFlags &
                                        (0x1 << 13), g.pt > 10,
                                        op.abs(g.eta) < 2.5))
        gen_e_plus = op.select(
            t.GenPart, lambda g: op.AND(g.pdgId == -11, g.statusFlags &
                                        (0x1 << 13), g.pt > 10,
                                        op.abs(g.eta) < 2.5))
        gen_mu_minus = op.select(
            t.GenPart, lambda g: op.AND(g.pdgId == 13, g.statusFlags &
                                        (0x1 << 13), g.pt > 10,
                                        op.abs(g.eta) < 2.4))
        gen_mu_plus = op.select(
            t.GenPart, lambda g: op.AND(g.pdgId == -13, g.statusFlags &
                                        (0x1 << 13), g.pt > 10,
                                        op.abs(g.eta) < 2.4))

        plots.extend(
            plotNumber("N_e_minus_gen", gen_e_minus, noSel, 10,
                       "N(e^{-}) gen level"))
        plots.extend(
            plotNumber("N_e_plus_gen", gen_e_plus, noSel, 10,
                       "N(e^{+}) gen level"))
        plots.extend(
            plotNumber("N_mu_minus_gen", gen_mu_minus, noSel, 10,
                       "N(\mu^{-}) gen level"))
        plots.extend(
            plotNumber("N_mu_plus_gen", gen_mu_plus, noSel, 10,
                       "N(\mu^{+}) gen level"))

        #----- Reco particles -----#
        reco_e_minus = op.select(
            t.Electron, lambda ele: op.AND(
                ele.charge == -1, ele.pdgId == 11, ele.pt > 10,
                op.abs(ele.eta) < 2.5,
                op.OR(ele.genPartFlav == 1, ele.genPartFlav == 15, ele.
                      genPartFlav == 22)))
        reco_e_plus = op.select(
            t.Electron, lambda ele: op.AND(
                ele.charge == +1, ele.pdgId == -11, ele.pt > 10,
                op.abs(ele.eta) < 2.5,
                op.OR(ele.genPartFlav == 1, ele.genPartFlav == 15, ele.
                      genPartFlav == 22)))
        reco_mu_minus = op.select(
            t.Muon, lambda mu: op.AND(
                mu.charge == -1, mu.pdgId == 13, mu.pt > 10,
                op.abs(mu.eta) < 2.4,
                op.OR(mu.genPartFlav == 1, mu.genPartFlav == 15)))
        reco_mu_plus = op.select(
            t.Muon, lambda mu: op.AND(
                mu.charge == +1, mu.pdgId == -13, mu.pt > 10,
                op.abs(mu.eta) < 2.4,
                op.OR(mu.genPartFlav == 1, mu.genPartFlav == 15)))

        plots.extend(
            plotNumber("N_e_minus_reco", reco_e_minus, noSel, 10,
                       "N(e^{-}) reco level"))
        plots.extend(
            plotNumber("N_e_plus_reco", reco_e_plus, noSel, 10,
                       "N(e^{+}) reco level"))
        plots.extend(
            plotNumber("N_mu_minus_reco", reco_mu_minus, noSel, 10,
                       "N(\mu^{-}) reco level"))
        plots.extend(
            plotNumber("N_mu_plus_reco", reco_mu_plus, noSel, 10,
                       "N(\mu^{+}) reco level"))

        #---- Matching -----#
        lambda_lepton_match = lambda l_gen, l_reco: op.AND(
            op.deltaR(l_gen.p4, l_reco.p4) < 0.1,
            op.abs(l_gen.pt - l_reco.pt) / l_gen.pt < 0.2)

        match_e_minus = op.combine((gen_e_minus, reco_e_minus),
                                   pred=lambda_lepton_match)
        match_e_plus = op.combine((gen_e_plus, reco_e_plus),
                                  pred=lambda_lepton_match)
        match_mu_minus = op.combine((gen_mu_minus, reco_mu_minus),
                                    pred=lambda_lepton_match)
        match_mu_plus = op.combine((gen_mu_plus, reco_mu_plus),
                                   pred=lambda_lepton_match)

        SelEMinusMatch = noSel.refine("SelEMinusMatch",
                                      cut=[op.rng_len(match_e_minus) >= 1])
        SelEPlusMatch = noSel.refine("SelEPlusMatch",
                                     cut=[op.rng_len(match_e_plus) >= 1])
        SelMuMinusMatch = noSel.refine("SelMuMinusMatch",
                                       cut=[op.rng_len(match_mu_minus) >= 1])
        SelMuPlusMatch = noSel.refine("SelMuPlusMatch",
                                      cut=[op.rng_len(match_mu_plus) >= 1])

        plots.extend(
            plotNumber("N_e_minus_match", match_e_minus, noSel, 10,
                       "N(e^{-}) match level"))
        plots.extend(
            plotNumber("N_e_plus_match", match_e_plus, noSel, 10,
                       "N(e^{+}) match level"))
        plots.extend(
            plotNumber("N_mu_minus_match", match_mu_minus, noSel, 10,
                       "N(\mu^{-}) match level"))
        plots.extend(
            plotNumber("N_mu_plus_match", match_mu_plus, noSel, 10,
                       "N(\mu^{+}) match level"))

        plots.extend(
            plotMatching("e", [match_e_minus, match_e_plus],
                         [SelEMinusMatch, SelEPlusMatch], "e^{#pm}"))
        plots.extend(
            plotMatching("mu", [match_mu_minus, match_mu_plus],
                         [SelMuMinusMatch, SelMuPlusMatch], "#mu^{#pm}"))

        ##########################################################
        #                       B jets                           #
        ##########################################################
        #----- RecoJets -----#
        #recoJet_b = op.select(t.Jet, lambda j : op.AND(j.partonFlavour == 5, j.pt>10, op.abs(j.eta)<2.4 ,(op.abs(j.pt-j.genJet.pt)/j.genJet.pt)<1 ))
        #recoJet_bbar = op.select(t.Jet, lambda j : op.AND(j.partonFlavour == -5, j.pt>10, op.abs(j.eta)<2.4 ,(op.abs(j.pt-j.genJet.pt)/j.genJet.pt)<1  ))
        recoJet_b = op.select(
            t.Jet, lambda j: op.AND(j.partonFlavour == 5, j.pt > 10,
                                    op.abs(j.eta) < 2.4, j.genJet.isValid))
        recoJet_bbar = op.select(
            t.Jet, lambda j: op.AND(j.partonFlavour == -5, j.pt > 10,
                                    op.abs(j.eta) < 2.4, j.genJet.isValid))
        plots.extend(
            plotNumber("N_jetb_reco", recoJet_b, noSel, 5, "N(b) reco jet"))
        plots.extend(
            plotNumber("N_jetbbar_reco", recoJet_bbar, noSel, 5,
                       "N(#bar{b}) reco jet"))

        SelBReco = noSel.refine("SelBReco", cut=[op.rng_len(recoJet_b) >= 1])
        SelBBarReco = noSel.refine("SelBBarReco",
                                   cut=[op.rng_len(recoJet_bbar) >= 1])

        #        plots.extend(plotJetReco("bjet",recoJet_b,SelBReco,"b jet"))
        #        plots.extend(plotJetReco("bbarjet",recoJet_bbar,SelBBarReco,"#bar{b} jet"))
        #
        #
        #       #----- Parton -----#
        #        gen_b = op.select(t.GenPart,lambda g : op.AND( g.pdgId==5 , g.statusFlags & ( 0x1 << 13) , g.pt>10, op.abs(g.eta)<2.4))
        #        gen_bbar = op.select(t.GenPart,lambda g : op.AND( g.pdgId==-5 , g.statusFlags & ( 0x1 << 13) , g.pt>10, op.abs(g.eta)<2.4))
        #        plots.extend(plotNumber("N_b_gen",gen_b,noSel,5,"N(b) gen quark"))
        #        plots.extend(plotNumber("N_bbar_gen",gen_bbar,noSel,5,"N(#bar{b}) gen quark"))
        #
        #        #----- Matching -----#
        #        lambda_bjet_match = lambda b_gen,b_jet : op.deltaR(b_gen.p4,b_jet.genJet.p4)<0.2
        #
        #        match_b = op.combine((gen_b,recoJet_b),pred=lambda_bjet_match)
        #        match_bbar = op.combine((gen_bbar,recoJet_bbar),pred=lambda_bjet_match)
        #
        #        plots.extend(plotNumber("N_b_match",match_b,noSel,5,"N(b) match level"))
        #        plots.extend(plotNumber("N_bbar_match",match_bbar,noSel,5,"N(#bar{b}) match level"))
        #
        #        SelBMatch = noSel.refine("SelBMatch",cut=[op.rng_len(match_b)>=1])
        #        SelBBarMatch = noSel.refine("SelBBarMatch",cut=[op.rng_len(match_bbar)>=1])
        #
        #        plots.extend(plotMatching("b",[match_b,match_bbar],[SelBMatch,SelBBarMatch],"b"))

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

        era = sampleCfg.get("era") if sampleCfg else None
        noSel = noSel.refine("passMETFlags", cut=METFilter(t.Flag, era) )
        puWeightsFile = None
        
        if era == "2016":
            sfTag="94X"
            puWeightsFile = os.path.join(os.path.dirname(__file__), "data/PileupFullRunII", "puweights2016.json")
        
        elif era == "2017":
            sfTag="94X"     
            puWeightsFile = os.path.join(os.path.dirname(__file__), "data/PileupFullRunII", "puweights2017.json")
        
        elif era == "2018":
            sfTag="102X"
            puWeightsFile = os.path.join(os.path.dirname(__file__), "data/PileupFullRunII", "puweights2018.json")
        
        if self.isMC(sample) and puWeightsFile is not None:
            from bamboo.analysisutils import makePileupWeight
            noSel = noSel.refine("puWeight", weight=makePileupWeight(puWeightsFile, t.Pileup_nTrueInt, systName="pileup"))
        
        isMC = self.isMC(sample)
        plots = []
        forceDefine(t._Muon.calcProd, noSel)

        # Wp // 2016- 2017 -2018 : Muon_mediumId   // https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonIdRun2#Muon_Isolation
        #To suppress nonprompt lep-tons, the impact parameter in three dimensions of the lepton track, with respect to the primaryvertex, is required to be less than 4 times its uncertainty (|SIP3D|<4)
        sorted_muons = op.sort(t.Muon, lambda mu : -mu.pt)
        muons = op.select(sorted_muons, lambda mu : op.AND(mu.pt > 10., op.abs(mu.eta) < 2.4, mu.mediumId, mu.pfRelIso04_all<0.15, op.abs(mu.sip3d < 4.)))
      
        # i pass 2016 seprate from 2017 &2018  because SFs need to be combined for BCDEF and GH eras !
        if era=="2016":
            doubleMuTrigSF = get_scalefactor("dilepton", ("doubleMuLeg_HHMoriond17_2016"), systName="mumutrig")    
            muMediumIDSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "id_medium"), combine="weight", systName="muid")
            muMediumISOSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "iso_tight_id_medium"), combine="weight", systName="muiso")
        else:
            doubleMuTrigSF = get_scalefactor("dilepton", ("doubleMuLeg_HHMoriond17_2016"), systName="mumutrig")    
            muMediumIDSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "id_medium"), systName="muid")
            muMediumISOSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "iso_tight_id_medium"), systName="muiso") 
        
        #Wp  // 2016: Electron_cutBased_Sum16==3  -> medium     // 2017 -2018  : Electron_cutBased ==3   --> medium ( Fall17_V2)
        # asking for electrons to be in the Barrel region with dz<1mm & dxy< 0.5mm   //   Endcap region dz<2mm & dxy< 0.5mm 
        # cut-based ID Fall17 V2 the recomended one from POG for the FullRunII
        sorted_electrons = op.sort(t.Electron, lambda ele : -ele.pt)
        electrons = op.select(sorted_electrons, lambda ele : op.AND(ele.pt > 15., op.abs(ele.eta) < 2.5 , ele.cutBased>=3, op.abs(ele.sip3d)< 4., op.OR(op.AND(op.abs(ele.dxy) < 0.05, op.abs(ele.dz) < 0.1), op.AND(op.abs(ele.dxy) < 0.05, op.abs(ele.dz) < 0.2) ))) 

        elMediumIDSF = get_scalefactor("lepton", ("electron_{0}_{1}".format(era,sfTag), "id_medium"), systName="elid")
        doubleEleTrigSF = get_scalefactor("dilepton", ("doubleEleLeg_HHMoriond17_2016"), systName="eleltrig")     

        elemuTrigSF = get_scalefactor("dilepton", ("elemuLeg_HHMoriond17_2016"), systName="elmutrig")
        mueleTrigSF = get_scalefactor("dilepton", ("mueleLeg_HHMoriond17_2016"), systName="mueltrig")
        

        MET = t.MET if era != "2017" else t.METFixEE2017
        corrMET=METcorrection(MET,t.PV,sample,era,self.isMC(sample))
        
        
        #######  select jets  
        ##################################
        #// 2016 - 2017 - 2018   ( j.jetId &2) ->      tight jet ID
        # For 2017 data, there is the option of "Tight" or "TightLepVeto", depending on how much you want to veto jets that overlap with/are faked by leptons
        sorted_AK4jets=op.sort(t.Jet, lambda j : -j.pt)
        AK4jetsSel = op.select(sorted_AK4jets, lambda j : op.AND(j.pt > 20., op.abs(j.eta)< 2.4, (j.jetId &2)))#   j.jetId == 6))# oldcut: (j.jetId &2)))        
        # exclude from the jetsSel any jet that happens to include within its reconstruction cone a muon or an electron.
        AK4jets= op.select(AK4jetsSel, lambda j : op.AND(op.NOT(op.rng_any(electrons, lambda ele : op.deltaR(j.p4, ele.p4) < 0.3 )), op.NOT(op.rng_any(muons, lambda mu : op.deltaR(j.p4, mu.p4) < 0.3 ))))
        
        # order jets by *decreasing* deepFlavour
        cleaned_AK4JetsByDeepFlav = op.sort(AK4jets, lambda j: -j.btagDeepFlavB)
        cleaned_AK4JetsByDeepB = op.sort(AK4jets, lambda j: -j.btagDeepB)

        # Boosted Region
        sorted_AK8jets=op.sort(t.FatJet, lambda j : -j.pt)
        AK8jetsSel = op.select(sorted_AK8jets, lambda j : op.AND(j.pt > 200., op.abs(j.eta)< 2.4, (j.jetId &2), j.subJet1._idx.result != -1, j.subJet2._idx.result != -1))

        AK8jets= op.select(AK8jetsSel, lambda j : op.AND(op.NOT(op.rng_any(electrons, lambda ele : op.deltaR(j.p4, ele.p4) < 0.3 )), op.NOT(op.rng_any(muons, lambda mu : op.deltaR(j.p4, mu.p4) < 0.3 ))))
        
        cleaned_AK8JetsByDeepB = op.sort(AK8jets, lambda j: -j.btagDeepB)
        
        # Now,  let's ask for the jets to be a b-jets 
        # DeepCSV or deepJet Medium b-tag working point
        btagging = {
                "DeepCSV":{ # era: (loose, medium, tight)
                            "2016":(0.2217, 0.6321, 0.8953), 
                            "2017":(0.1522, 0.4941, 0.8001), 
                            "2018":(0.1241, 0.4184, 0.7527) 
                          },
                "DeepFlavour":{
                            "2016":(0.0614, 0.3093, 0.7221), 
                            "2017":(0.0521, 0.3033, 0.7489), 
                            "2018":(0.0494, 0.2770, 0.7264) 
                          }
                   }
        
        # bjets ={ "DeepFlavour": {"L": jets pass loose  , "M":  jets pass medium  , "T":jets pass tight    }     
        #           "DeepCSV":    {"L":    ---           , "M":         ---        , "T":   ----            }
        #        }
        # FIXME 
        bjets_boosted = {}
        bjets_resolved = {}
        
        #WorkingPoints = ["L", "M", "T"]
        WorkingPoints = ["M"]
        for tagger  in btagging.keys():
            
            bJets_AK4_deepflavour ={}
            bJets_AK4_deepcsv ={}
            bJets_AK8_deepcsv ={}
            # FIXME idx is not propagated properly when i pass only one or two wp !! 
            for wp in sorted(WorkingPoints):
                
                suffix = ("loose" if wp=='L' else ("medium" if wp=='M' else "tight"))
                idx = ( 0 if wp=="L" else ( 1 if wp=="M" else 2))
                if tagger=="DeepFlavour":
                    
                    print ("Btagging: Era= {0}, Tagger={1}, Pass_{2}_working_point={3}".format(era, tagger, suffix, btagging[tagger][era][idx] ))
                    print ("***********************************************", idx, wp)
                    print ("btag_{0}_94X".format(era).replace("94X", "102X" if era=="2018" else "94X"), "{0}_{1}".format('DeepJet', suffix))
                    
                    bJets_AK4_deepflavour[wp] = op.select(cleaned_AK4JetsByDeepFlav, lambda j : j.btagDeepFlavB >= btagging[tagger][era][idx] )
                    Jet_DeepFlavourBDisc = { "BTagDiscri": lambda j : j.btagDeepFlavB }
                    deepBFlavScaleFactor = get_scalefactor("jet", ("btag_{0}_94X".format(era).replace("94X", "102X" if era=="2018" else "94X"), "{0}_{1}".format('DeepJet', suffix)),
                                                        additionalVariables=Jet_DeepFlavourBDisc, 
                                                        getFlavour=(lambda j : j.hadronFlavour),
                                                        systName="btagging{0}".format(era))  
                    
                    bjets_resolved[tagger]=bJets_AK4_deepflavour
                    
                else:
                    print ("Btagging: Era= {0}, Tagger={1}, Pass_{2}_working_point={3}".format(era, tagger, suffix, btagging[tagger][era][idx] ))
                    print ("***********************************************", idx, wp)
                    print ("btag_{0}_94X".format(era).replace("94X", "102X" if era=="2018" else "94X"), "{0}_{1}".format('DeepCSV', suffix))
                    
                    bJets_AK4_deepcsv[wp] = op.select(cleaned_AK4JetsByDeepB, lambda j : j.btagDeepB >= btagging[tagger][era][idx] )   
                    bJets_AK8_deepcsv[wp] = op.select(cleaned_AK8JetsByDeepB, lambda j : op.AND(j.subJet1.btagDeepB >= btagging[tagger][era][idx] , j.subJet2.btagDeepB >= btagging[tagger][era][idx]))   
                    Jet_DeepCSVBDis = { "BTagDiscri": lambda j : j.btagDeepB }
                    subJet_DeepCSVBDis = { "BTagDiscri": lambda j : op.AND(j.subJet1.btagDeepB, j.subJet2.btagDeepB) }
                    
                    # FIXME for boosted and resolved i will use # tagger need to pass jsons files to scale factors above ! 
                    deepB_AK4ScaleFactor = get_scalefactor("jet", ("btag_{0}_94X".format(era).replace("94X", "102X" if era=="2018" else "94X"), "{0}_{1}".format('DeepCSV', suffix)), 
                                                additionalVariables=Jet_DeepCSVBDis,
                                                getFlavour=(lambda j : j.hadronFlavour),
                                                systName="btagging{0}".format(era))  
                    # FIXME
                    #deepB_AK8ScaleFactor = get_scalefactor("jet", ("btag_{0}_94X".format(era).replace("94X", "102X" if era=="2018" else "94X"), "subjet_{0}_{1}".format('DeepCSV', suffix)), 
                                                #additionalVariables=Jet_DeepCSVBDis,
                                                #getFlavour=(lambda j : j.subJet1.hadronFlavour),
                                                #systName="btagging{0}".format(era))  
                    
                    bjets_resolved[tagger]=bJets_AK4_deepcsv
                    bjets_boosted[tagger]=bJets_AK8_deepcsv
        
        bestDeepFlavourPair={}
        bestDeepCSVPair={}
        bestJetPairs= {}
        bjets = {}
        # For the Resolved only 
        class GetBestJetPair(object):
            JetsPair={}
            def __init__(self, JetsPair, tagger, wp):
                def ReturnHighestDiscriminatorJet(tagger, wp):
                    if tagger=="DeepCSV":
                        return op.sort(safeget(bjets_resolved, tagger, wp), lambda j: - j.btagDeepB)
                    elif tagger=="DeepFlavour":
                        return op.sort(safeget(bjets_resolved, tagger, wp), lambda j: - j.btagDeepFlavB)
                    else:
                        raise RuntimeError("Something went wrong in returning {0} discriminator !".format(tagger))
               
                firstBest=ReturnHighestDiscriminatorJet(tagger, wp)[0]
                JetsPair[0]=firstBest
                secondBest=ReturnHighestDiscriminatorJet(tagger, wp)[1]
                JetsPair[1]=secondBest
        #  bestJetPairs= { "DeepFlavour": bestDeepFlavourPair,
        #                  "DeepCSV":     bestDeepCSVPair    
        #                }
        
        #######  Zmass reconstruction : Opposite Sign , Same Flavour leptons
        ########################################################
        # supress quaronika resonances and jets misidentified as leptons
        LowMass_cut = lambda dilep: op.invariant_mass(dilep[0].p4, dilep[1].p4)>12.
        ## Dilepton selection: opposite sign leptons in range 70.<mll<120. GeV 
        osdilep_Z = lambda l1,l2 : op.AND(l1.charge != l2.charge, op.in_range(70., op.invariant_mass(l1.p4, l2.p4), 120.))

        osLLRng = {
                "MuMu" : op.combine(muons, N=2, pred= osdilep_Z),
                "ElEl" : op.combine(electrons, N=2, pred=osdilep_Z),
                #"ElMu" : op.combine((electrons, muons), pred=lambda ele,mu : op.AND(osdilep_Z(ele,mu), ele.pt > mu.pt )),
                #"MuEl" : op.combine((muons, electrons), pred=lambda mu,ele : op.AND(osdilep_Z(mu,ele), mu.pt > ele.pt))
                }

        hasOSLL_cmbRng = lambda cmbRng : op.AND(op.rng_len(cmbRng) > 0, cmbRng[0][0].pt > 25.) # TODO The leading pT for the µµ channel should be above 20 Gev !

        
        ## helper selection (OR) to make sure jet calculations are only done once
        hasOSLL = noSel.refine("hasOSLL", cut=op.OR(*( hasOSLL_cmbRng(rng) for rng in osLLRng.values())))
        forceDefine(t._Jet.calcProd, hasOSLL)
        forceDefine(getattr(t, "_{0}".format("MET" if era != "2017" else "METFixEE2017")).calcProd, hasOSLL)
        
        llSFs = {
            "MuMu" : (lambda ll : [ muMediumIDSF(ll[0]), muMediumIDSF(ll[1]), muMediumISOSF(ll[0]), muMediumISOSF(ll[1]), doubleMuTrigSF(ll) ]),
            "ElMu" : (lambda ll : [ elMediumIDSF(ll[0]), muMediumIDSF(ll[1]), muMediumISOSF(ll[1]), elemuTrigSF(ll) ]),
            "MuEl" : (lambda ll : [ muMediumIDSF(ll[0]), muMediumISOSF(ll[0]), elMediumIDSF(ll[1]), mueleTrigSF(ll) ]),
            "ElEl" : (lambda ll : [ elMediumIDSF(ll[0]), elMediumIDSF(ll[1]), doubleEleTrigSF(ll) ])
            }
        
        categories = dict((channel, (catLLRng[0], hasOSLL.refine("hasOS{0}".format(channel), cut=hasOSLL_cmbRng(catLLRng), weight=(llSFs[channel](catLLRng[0]) if isMC else None)) )) for channel, catLLRng in osLLRng.items())

        ## btagging efficiencies plots
        #plots.extend(MakeBtagEfficienciesPlots(self, jets, bjets, categories))
        
        for channel, (dilepton, catSel) in categories.items():
            #----  Zmass (2Lepton OS && SF ) --------
            #plots.extend(MakeControlPlotsForZpic(self, catSel, dilepton, channel))
            
            #----  add Jets selection 
            TwoLeptonsTwoJets_Resolved = catSel.refine("TwoJet_{0}Sel_resolved".format(channel), cut=[ op.rng_len(AK4jets) > 1 ])
            TwoLeptonsTwoJets_Boosted = catSel.refine("OneJet_{0}Sel_boosted".format(channel), cut=[ op.rng_len(AK8jets) > 0 ])
            #plots.extend(makeJetPlots(self, TwoLeptonsTwoJets_Resolved, AK4jets, channel))
            #plots.extend(makeBoostedJetPLots(self, TwoLeptonsTwoJets_Boosted, AK8jets, channel))
            
            # ----- plots : mll, mlljj, mjj, nVX, pT, eta  : basic selection plots ------
            #plots.extend(MakeControlPlotsForBasicSel(self, TwoLeptonsTwoJets_Resolved, AK4jets, dilepton, channel))
            #plots.extend(MakeControlPlotsForBasicSel(self, TwoLeptonsTwoJets_boosted, AK8jets, dilepton, channel))

            
            for wp in WorkingPoints: 
                # Get the best AK4 JETS 
                GetBestJetPair(bestDeepCSVPair,"DeepCSV", wp)
                GetBestJetPair(bestDeepFlavourPair,"DeepFlavour", wp)
                bestJetPairs["DeepCSV"]=bestDeepCSVPair
                bestJetPairs["DeepFlavour"]=bestDeepFlavourPair
                print ("bestJetPairs AK4--->", bestJetPairs, wp)
                print ("bestJetPairs_deepcsv  AK4--->", bestJetPairs["DeepCSV"][0], bestJetPairs["DeepCSV"][1], wp)
                print ("bestJetPairs_deepflavour  AK4 --->", bestJetPairs["DeepFlavour"][0],bestJetPairs["DeepFlavour"][1], wp)
                # resolved 
                bJets_resolved_PassdeepflavourWP=safeget(bjets_resolved, "DeepFlavour", wp)
                bJets_resolved_PassdeepcsvWP=safeget(bjets_resolved, "DeepCSV", wp)
                # boosted
                bJets_boosted_PassdeepcsvWP=safeget(bjets_boosted, "DeepCSV", wp)

                TwoLeptonsTwoBjets_NoMETCut_Res = {
                    "DeepFlavour{0}".format(wp) :  TwoLeptonsTwoJets_Resolved.refine("TwoLeptonsTwoBjets_NoMETcut_DeepFlavour{0}_{1}_Resolved".format(wp, channel),
                                                                        cut=[ op.rng_len(bJets_resolved_PassdeepflavourWP) > 1 ],
                                                                        weight=([ deepBFlavScaleFactor(bJets_resolved_PassdeepflavourWP[0]), deepBFlavScaleFactor(bJets_resolved_PassdeepflavourWP[1]) ]if isMC else None)),
                    "DeepCSV{0}".format(wp)     :  TwoLeptonsTwoJets_Resolved.refine("TwoLeptonsTwoBjets_NoMETcut_DeepCSV{0}_{1}_Resolved".format(wp, channel), 
                                                                        cut=[ op.rng_len(bJets_resolved_PassdeepcsvWP) > 1 ],
                                                                        weight=([ deepB_AK4ScaleFactor(bJets_resolved_PassdeepcsvWP[0]), deepB_AK4ScaleFactor(bJets_resolved_PassdeepcsvWP[1]) ]if isMC else None))
                                                }


                TwoLeptonsTwoBjets_NoMETCut_Boo = {
                    "DeepCSV{0}".format(wp)     :  TwoLeptonsTwoJets_Boosted.refine("TwoLeptonsTwoBjets_NoMETcut_DeepCSV{0}_{1}_Boosted".format(wp, channel), 
                                                                        cut=[ op.rng_len(bJets_boosted_PassdeepcsvWP) > 1 ]), 
                                                                        # FIXME ! can't pass boosted jets SFs with current version ---> move to v7  
                                                                        #weight=([ deepB_AK8ScaleFactor(bJets_boosted_PassdeepcsvWP[0]), deepB_AK8ScaleFactor(bJets_boosted_PassdeepcsvWP[1]) ]if isMC else None))
                                                }
                
                ## needed to optimize the MET cut 
                # FIXME  Rerun again  &&& pass signal and bkg  
                # The MET cut is passed to TwoLeptonsTwoBjets selection for the # tagger and for the # wp 
                plots.extend(MakeMETPlots(self, TwoLeptonsTwoBjets_NoMETCut_Res, corrMET, MET, channel, "resolved"))
                plots.extend(MakeMETPlots(self, TwoLeptonsTwoBjets_NoMETCut_Boo, corrMET, MET, channel, "boosted"))
                plots.extend(MakeExtraMETPlots(self, TwoLeptonsTwoBjets_NoMETCut_Res, dilepton, MET, channel, "resolved"))
                plots.extend(MakeExtraMETPlots(self, TwoLeptonsTwoBjets_NoMETCut_Boo, dilepton, MET, channel, "boosted"))

                TwoLeptonsTwoBjets_Res = dict((key, selNoMET.refine("TwoLeptonsTwoBjets_{0}_{1}_Resolved".format(key, channel), cut=[ corrMET.pt < 80. ])) for key, selNoMET in TwoLeptonsTwoBjets_NoMETCut_Res.items())
                TwoLeptonsTwoBjets_Boo = dict((key, selNoMET.refine("TwoLeptonsTwoBjets_{0}_{1}_Boosted".format(key, channel), cut=[ corrMET.pt < 80. ])) for key, selNoMET in TwoLeptonsTwoBjets_NoMETCut_Boo.items())
                #plots.extend(MakeDiscriminatorPlots(self, TwoLeptonsTwoBjets_Res, bjets_resolved, wp, channel, "resolved"))
                #plots.extend(MakeDiscriminatorPlots(self, TwoLeptonsTwoBjets_Boo, bjets_boosted, wp, channel, "boosted"))
                
                #plots.extend(makeResolvedBJetPlots(self, TwoLeptonsTwoBjets_Res, bjets_resolved, dilepton, wp, channel))
                #plots.extend(makeBoostedBJetPlots(self, TwoLeptonsTwoBjets_NoMETCut_Boo, bjets_boosted, dilepton, wp, channel))

                # --- to get the Ellipses plots  
                plots.extend(MakeEllipsesPLots(self, TwoLeptonsTwoBjets_Res, bjets_resolved, dilepton, wp, channel, "resolved"))
                plots.extend(MakeEllipsesPLots(self, TwoLeptonsTwoBjets_Boo, bjets_boosted, dilepton, wp, channel, "boosted"))
        
        return plots
コード例 #21
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
コード例 #22
0
    def defineSkimSelection(self, t, noSel, sample=None, sampleCfg=None):
        noSel = super(SkimmerNanoHHtobbWWSL,
                      self).prepareObjects(t,
                                           noSel,
                                           sample,
                                           sampleCfg,
                                           "SL",
                                           forSkimmer=True)
        era = sampleCfg['era']
        # Initialize varsToKeep dict #
        varsToKeep = dict()
        if not self.inclusive_sel:
            jet_level = ["Resolved2Btag", "Resolved1Btag", "Boosted"]
            # Only one lepton_level must be in args and Only one jet_level must be in args
            if [
                    boolean for (level, boolean) in self.args.__dict__.items()
                    if level in jet_level
            ].count(True) != 1:
                raise RuntimeError(
                    "Only one of the jet arguments must be used, check --help")

            if self.args.Channel not in ["El", "Mu"]:
                raise RuntimeError("Channel must be either 'El' or 'Mu'")

            #----- Machine Learning Model -----#
            model_nums = ["01", "02"]
            path_model_01 = os.path.join(
                os.path.abspath(os.path.dirname(__file__)), 'MachineLearning',
                'ml-models', 'models', 'multi-classification', 'dnn', 'SL',
                model_nums[0], 'model', 'model.pb')
            path_model_02 = os.path.join(
                os.path.abspath(os.path.dirname(__file__)), 'MachineLearning',
                'ml-models', 'models', 'multi-classification', 'dnn', 'SL',
                model_nums[1], 'model', 'model.pb')
            input_names_01 = [
                "lep", "jet", "fat", "met", "hl", "param", "eventnr"
            ]
            input_names_02 = [
                "lep", "jet", "fat", "met", "nu", "hl", "param", "eventnr"
            ]
            output_name = "Identity"

            if not self.args.OnlyYield:
                print("DNN model : %s" % path_model_02)
                if not os.path.exists(path_model_02):
                    raise RuntimeError('Could not find model file %s' %
                                       path_model_02)
                try:
                    DNN_02 = op.mvaEvaluator(path_model_02,
                                             mvaType='Tensorflow',
                                             otherArgs=(input_names_02,
                                                        output_name))
                except:
                    raise RuntimeError('Could not load model %s' %
                                       path_model_02)

            self.nodes = ['GGF', 'VBF', 'TT', 'ST', 'WJets', 'H', 'Other']

            #----- Lepton selection -----#
            # Args are passed within the self #
            #ElSelObj, MuSelObj = makeSingleLeptonSelection(self,noSel,use_dd=False)
            ElSelObj, MuSelObj = makeSingleLeptonSelection(
                self, noSel, use_dd=False, fake_selection=self.args.FakeCR)

            # --- apply jet correction --- #
            ElSelObj.sel = self.beforeJetselection(ElSelObj.sel, 'El')
            MuSelObj.sel = self.beforeJetselection(MuSelObj.sel, 'Mu')

            if self.args.Channel == "El":
                selObj = ElSelObj
                #lepton = self.electronsTightSel[0]
                lepton = self.electronsFakeSel[0]
                lepconep4 = self.getElectronConeP4(lepton)

            if self.args.Channel == "Mu":
                selObj = MuSelObj
                #lepton = self.muonsTightSel[0]
                lepton = self.muonsFakeSel[0]
                lepconep4 = self.getMuonConeP4(lepton)

            #----- Jet selection -----#
            # Since the selections in one line, we can use the non copy option of the selection to modify the selection object internally
            if any([
                    self.args.__dict__[item]
                    for item in ["Resolved2Btag", "Resolved1Btag"]
            ]):
                makeResolvedSelection(self, selObj)
                #VBFJetPairs = mvaEvaluatorSL_nonres_DNN01.VBFJetPairs_Resolved(self)
                VBFJetPairs = self.VBFJetPairsResolved
                if self.args.Resolved2Btag:
                    makeExclusiveResolvedSelection(self, selObj, nbJet=2)
                    print('Resolved2Btag')

                if self.args.Resolved1Btag:
                    makeExclusiveResolvedSelection(self, selObj, nbJet=1)
                    print('Resolved1Btag')

            if self.args.Boosted:
                makeBoostedSelection(self, selObj)
                #VBFJetPairs = mvaEvaluatorSL_nonres_DNN01.VBFJetPairs_Boosted(self)
                VBFJetPairs = self.VBFJetPairsBoosted
                print('BoostedHbb')

        else:
            noSel = self.beforeJetselection(noSel)

        #---------------------------------------------------------------------------------------#
        #                                Synchronization tree                                   #
        #---------------------------------------------------------------------------------------#
        if self.args.Synchronization:
            # Event variables #
            varsToKeep["event"] = None  # Already in tree
            varsToKeep["run"] = None  # Already in tree
            varsToKeep["ls"] = t.luminosityBlock

            varsToKeep["n_presel_mu"] = op.static_cast(
                "UInt_t", op.rng_len(self.muonsPreSel))
            varsToKeep["n_fakeablesel_mu"] = op.static_cast(
                "UInt_t", op.rng_len(self.muonsFakeSel))
            varsToKeep["n_tightsel_mu"] = op.static_cast(
                "UInt_t", op.rng_len(self.muonsTightSel))
            varsToKeep["n_presel_ele"] = op.static_cast(
                "UInt_t", op.rng_len(self.electronsPreSel))
            varsToKeep["n_fakeablesel_ele"] = op.static_cast(
                "UInt_t", op.rng_len(self.electronsFakeSel))
            varsToKeep["n_tightsel_ele"] = op.static_cast(
                "UInt_t", op.rng_len(self.electronsTightSel))

            varsToKeep["n_ak4Jet"] = op.static_cast("UInt_t",
                                                    op.rng_len(self.ak4Jets))

            varsToKeep["n_ak8Jet"] = op.static_cast("UInt_t",
                                                    op.rng_len(self.ak8Jets))
            varsToKeep["n_presel_ak8BJet"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak8BJets))
            varsToKeep["n_loose_ak4BJet"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak4BJetsLoose))
            varsToKeep["n_medium_ak4BJet"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak4BJets))
            varsToKeep["n_ak4JetsCleanAk8b"] = op.static_cast(
                "UInt_t", op.rng_len(self.ak4JetsCleanedFromAk8b))
            varsToKeep["n_presel_ak4JetVBF"] = op.static_cast(
                "UInt_t", op.rng_len(self.VBFJetsPreSel))

            #varsToKeep["is_SR"]             = op.static_cast("UInt_t",op.OR(op.rng_len(self.electronsTightSel)==1,
            #                                                                op.rng_len(self.muonsTightSel)==1))

            varsToKeep["is_e_SR_prompt"] = op.switch(
                op.rng_len(self.electronsTightSel) == 1, op.c_bool(True),
                op.c_bool(False))
            varsToKeep["is_m_SR_prompt"] = op.switch(
                op.rng_len(self.muonsTightSel) == 1, op.c_bool(True),
                op.c_bool(False))
            varsToKeep["is_e_FR_prompt"] = op.switch(
                op.AND(
                    op.rng_len(self.electronsFakeSel) > 0,
                    op.AND(
                        self.lambda_is_matched(self.electronsFakeSel[0]),
                        op.NOT(
                            self.lambda_electronTightSel(
                                self.electronsFakeSel[0])))), op.c_bool(True),
                op.c_bool(False))
            varsToKeep["is_m_FR_prompt"] = op.switch(
                op.AND(
                    op.rng_len(self.muonsFakeSel) > 0,
                    op.AND(
                        self.lambda_is_matched(self.muonsFakeSel[0]),
                        op.NOT(self.lambda_muonTightSel(
                            self.muonsFakeSel[0])))), op.c_bool(True),
                op.c_bool(False))

            varsToKeep["is_resolved"] = op.switch(
                op.AND(
                    op.rng_len(self.ak4Jets) >= 3,
                    op.rng_len(self.ak4BJets) >= 1,
                    op.rng_len(self.ak8BJets) == 0), op.c_bool(True),
                op.c_bool(False))
            varsToKeep["is_boosted"] = op.switch(
                op.AND(
                    op.rng_len(self.ak8BJets) >= 1,
                    op.rng_len(self.ak4JetsCleanedFromAk8b) >= 1),
                op.c_bool(True), op.c_bool(False))

            varsToKeep["is_resolved_1b"] = op.switch(
                op.AND(
                    op.rng_len(self.ak4Jets) >= 3,
                    op.rng_len(self.ak4BJets) == 1,
                    op.rng_len(self.ak8BJets) == 0), op.c_bool(True),
                op.c_bool(False))
            varsToKeep["is_resolved_2b"] = op.switch(
                op.AND(
                    op.rng_len(self.ak4Jets) >= 3,
                    op.rng_len(self.ak4BJets) >= 2,
                    op.rng_len(self.ak8BJets) == 0), op.c_bool(True),
                op.c_bool(False))

            varsToKeep["n_tau"] = op.static_cast("UInt_t",
                                                 op.rng_len(self.tauCleanSel))

            #varsToKeep['resolved_tag']  = op.static_cast("UInt_t",op.AND(op.rng_len(self.ak4Jets) >= 3,
            #                                                             op.rng_len(self.ak4BJets) >= 1,
            #                                                             op.rng_len(self.ak8BJets) == 0))
            #varsToKeep['boosted_tag']   = op.static_cast("UInt_t",op.AND(op.rng_len(self.ak8BJets) >= 1,op.rng_len(self.ak4JetsCleanedFromAk8b) >= 1))

            # Triggers #
            '''
            varsToKeep["triggers"]                  = self.triggers
            varsToKeep["triggers_SingleElectron"]   = op.OR(*self.triggersPerPrimaryDataset['SingleElectron'])
            varsToKeep["triggers_SingleMuon"]       = op.OR(*self.triggersPerPrimaryDataset['SingleMuon'])
            varsToKeep["triggers_DoubleElectron"]   = op.OR(*self.triggersPerPrimaryDataset['DoubleEGamma'])
            varsToKeep["triggers_DoubleMuon"]       = op.OR(*self.triggersPerPrimaryDataset['DoubleMuon'])
            varsToKeep["triggers_MuonElectron"]     = op.OR(*self.triggersPerPrimaryDataset['MuonEG'])
            '''
            # Muons #

            for i in range(1, 3):  # 2 leading muons
                varsToKeep["mu{}_pt".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].pt, op.c_float(-9999., "float"))
                varsToKeep["mu{}_eta".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].eta, op.c_float(-9999.))
                varsToKeep["mu{}_phi".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].phi, op.c_float(-9999.))
                varsToKeep["mu{}_E".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].p4.E(),
                    op.c_float(-9999., "float"))
                varsToKeep["mu{}_charge".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].charge, op.c_int(-9999.))
                varsToKeep["mu{}_conept".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muon_conept[self.muonsPreSel[i - 1].idx],
                    op.c_float(-9999.))
                varsToKeep["mu{}_miniRelIso".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].miniPFRelIso_all,
                    op.c_float(-9999.))
                varsToKeep["mu{}_PFRelIso04".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].pfRelIso04_all, op.c_float(-9999.))
                varsToKeep["mu{}_jetNDauChargedMVASel".format(i)] = op.c_float(
                    -9999.)
                varsToKeep["mu{}_jetPtRel".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].jetPtRelv2, op.c_float(-9999.))
                varsToKeep["mu{}_jetRelIso".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].jetRelIso, op.c_float(-9999.))
                varsToKeep["mu{}_jetDeepJet".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].jet.btagDeepFlavB,
                    op.c_float(-9999.))
                varsToKeep["mu{}_sip3D".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].sip3d, op.c_float(-9999.))
                varsToKeep["mu{}_dxy".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].dxy, op.c_float(-9999.))
                varsToKeep["mu{}_dxyAbs".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    op.abs(self.muonsPreSel[i - 1].dxy), op.c_float(-9999.))
                varsToKeep["mu{}_dz".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].dz, op.c_float(-9999.))
                varsToKeep["mu{}_segmentCompatibility".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].segmentComp, op.c_float(-9999.))
                varsToKeep["mu{}_leptonMVA".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].mvaTTH, op.c_float(-9999.))
                varsToKeep["mu{}_mediumID".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].mediumId,
                    op.c_float(-9999., "Bool_t"))
                varsToKeep["mu{}_dpt_div_pt".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    self.muonsPreSel[i - 1].tunepRelPt,
                    op.c_float(-9999.))  # Not sure
                varsToKeep["mu{}_isfakeablesel".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    op.switch(self.lambda_muonFakeSel(self.muonsPreSel[i - 1]),
                              op.c_int(1), op.c_int(0)), op.c_int(-9999))
                varsToKeep["mu{}_ismvasel".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    op.switch(
                        op.AND(
                            self.lambda_muonTightSel(self.muonsPreSel[i - 1]),
                            self.lambda_muonFakeSel(self.muonsPreSel[i - 1])),
                        op.c_int(1), op.c_int(0)),
                    op.c_int(-9999))  # mvasel encompasses fakeablesel
                varsToKeep["mu{}_isGenMatched".format(i)] = op.switch(
                    op.rng_len(self.muonsPreSel) >= i,
                    op.switch(self.lambda_is_matched(self.muonsPreSel[i - 1]),
                              op.c_int(1), op.c_int(0)), op.c_int(-9999))
                '''
                varsToKeep["mu{}_genPartFlav".format(i)]           = op.switch(op.rng_len(self.muonsPreSel) >= i, self.muonsPreSel[i-1].genPartFlav, op.c_int(-9999))
                varsToKeep["mu{}_FR".format(i)]                    = op.switch(op.rng_len(self.muonsPreSel) >= i, self.lambda_FR_mu(self.muonsPreSel[i-1]), op.c_int(-9999))
                varsToKeep["mu{}_FRcorr".format(i)]                = op.switch(op.rng_len(self.muonsPreSel) >= i, self.lambda_FRcorr_mu(self.muonsPreSel[i-1]), op.c_int(-9999))
                varsToKeep["mu{}_FF".format(i)]                    = op.switch(op.rng_len(self.muonsPreSel) >= i, self.lambda_FF_mu(self.muonsPreSel[i-1]), op.c_int(-9999))
                varsToKeep["mu{}_looseSF".format(i)]               = op.switch(op.rng_len(self.muonsPreSel) >= i, reduce(mul,self.lambda_MuonLooseSF(self.muonsPreSel[i-1])), op.c_int(-9999))
                varsToKeep["mu{}_tightSF".format(i)]               = op.switch(op.rng_len(self.muonsPreSel) >= i, reduce(mul,self.lambda_MuonTightSF(self.muonsPreSel[i-1])), op.c_int(-9999))
                '''
            # Electrons #
            for i in range(1, 3):  # 2 leading electrons
                varsToKeep["ele{}_pt".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].pt, op.c_float(-9999.))
                varsToKeep["ele{}_eta".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].eta, op.c_float(-9999.))
                varsToKeep["ele{}_phi".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].phi, op.c_float(-9999.))
                varsToKeep["ele{}_E".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].p4.E(), op.c_float(-9999., ))
                varsToKeep["ele{}_charge".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].charge, op.c_int(-9999.))
                varsToKeep["ele{}_conept".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electron_conept[self.electronsPreSel[i - 1].idx],
                    op.c_float(-9999.))
                varsToKeep["ele{}_miniRelIso".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].miniPFRelIso_all,
                    op.c_float(-9999.))
                varsToKeep["ele{}_PFRelIso03".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].pfRelIso03_all,
                    op.c_float(-9999.))  # Iso03, Iso04 not in NanoAOD
                varsToKeep["ele{}_jetNDauChargedMVASel".format(
                    i)] = op.c_float(-9999.)
                varsToKeep["ele{}_jetPtRel".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].jetPtRelv2, op.c_float(-9999.))
                varsToKeep["ele{}_jetRelIso".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].jetRelIso, op.c_float(-9999.))
                varsToKeep["ele{}_jetDeepJet".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].jet.btagDeepFlavB,
                    op.c_float(-9999.))
                varsToKeep["ele{}_sip3D".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].sip3d, op.c_float(-9999.))

                varsToKeep["ele{}_dxy".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].dxy, op.c_float(-9999.))
                varsToKeep["ele{}_dxyAbs".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    op.abs(self.electronsPreSel[i - 1].dxy),
                    op.c_float(-9999.))
                varsToKeep["ele{}_dz".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].dz, op.c_float(-9999.))
                varsToKeep["ele{}_ntMVAeleID".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].mvaFall17V2noIso,
                    op.c_float(-9999.))
                varsToKeep["ele{}_leptonMVA".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].mvaTTH, op.c_float(-9999.))
                varsToKeep["ele{}_passesConversionVeto".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].convVeto,
                    op.c_float(-9999., "Bool_t"))
                varsToKeep["ele{}_nMissingHits".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].lostHits,
                    op.c_float(-9999., "UChar_t"))
                varsToKeep["ele{}_sigmaEtaEta".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].sieie, op.c_float(-9999.))
                varsToKeep["ele{}_HoE".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].hoe, op.c_float(-9999.))
                varsToKeep["ele{}_OoEminusOoP".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    self.electronsPreSel[i - 1].eInvMinusPInv,
                    op.c_float(-9999.))
                varsToKeep["ele{}_isfakeablesel".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    op.switch(
                        self.lambda_electronFakeSel(self.electronsPreSel[i -
                                                                         1]),
                        op.c_int(1), op.c_int(0)), op.c_int(-9999))
                varsToKeep["ele{}_ismvasel".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    op.switch(
                        op.AND(
                            self.lambda_electronTightSel(
                                self.electronsPreSel[i - 1]),
                            self.lambda_electronFakeSel(
                                self.electronsPreSel[i - 1])), op.c_int(1),
                        op.c_int(0)),
                    op.c_int(-9999))  # mvasel encompasses fakeablesel
                varsToKeep["ele{}_isGenMatched".format(i)] = op.switch(
                    op.rng_len(self.electronsPreSel) >= i,
                    op.switch(
                        self.lambda_is_matched(self.electronsPreSel[i - 1]),
                        op.c_int(1), op.c_int(0)), op.c_int(-9999))
                '''
                varsToKeep["ele{}_genPartFlav".format(i)]           = op.switch(op.rng_len(self.electronsPreSel) >= i, self.electronsPreSel[i-1].genPartFlav, op.c_int(-9999))
                varsToKeep["ele{}_deltaEtaSC".format(i)]            = op.switch(op.rng_len(self.electronsPreSel) >= i, self.electronsPreSel[i-1].deltaEtaSC, op.c_int(-9999))
                varsToKeep["ele{}_FR".format(i)]                    = op.switch(op.rng_len(self.electronsPreSel) >= i, self.lambda_FR_el(self.electronsPreSel[i-1]), op.c_int(-9999))
                varsToKeep["ele{}_FRcorr".format(i)]                = op.switch(op.rng_len(self.electronsPreSel) >= i, self.lambda_FRcorr_el(self.electronsPreSel[i-1]), op.c_int(-9999))
                varsToKeep["ele{}_FF".format(i)]                    = op.switch(op.rng_len(self.electronsPreSel) >= i, self.lambda_FF_el(self.electronsPreSel[i-1]), op.c_int(-9999))
                varsToKeep["ele{}_looseSF".format(i)]               = op.switch(op.rng_len(self.electronsPreSel) >= i, reduce(mul,self.lambda_ElectronLooseSF(self.electronsPreSel[i-1])), op.c_int(-9999))
                varsToKeep["ele{}_tightSF".format(i)]               = op.switch(op.rng_len(self.electronsPreSel) >= i, reduce(mul,self.lambda_ElectronTightSF(self.electronsPreSel[i-1])), op.c_int(-9999))
                '''
            # AK4 Jets #
            for i in range(1, 5):  # 4 leading jets
                varsToKeep["ak4Jet{}_pt".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i - 1].pt,
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_eta".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i - 1].eta,
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_phi".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i - 1].phi,
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_E".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i - 1].p4.E(),
                    op.c_float(-9999.))
                varsToKeep["ak4Jet{}_CSV".format(i)] = op.switch(
                    op.rng_len(self.ak4Jets) >= i,
                    self.ak4Jets[i - 1].btagDeepFlavB, op.c_float(-9999.))
                #varsToKeep["ak4Jet{}_hadronFlavour".format(i)]      = op.switch(op.rng_len(self.ak4Jets) >= i, self.ak4Jets[i-1].hadronFlavour, op.c_float(-9999.))
                #varsToKeep["ak4Jet{}_btagSF".format(i)]             = op.switch(op.rng_len(self.ak4Jets) >= i, self.DeepJetDiscReshapingSF(self.ak4Jets[i-1]), op.c_float(-9999.))
                #varsToKeep["ak4Jet{}_puid_eff".format(i)]           = op.switch(op.rng_len(self.ak4Jets) >= i, self.jetpuid_mc_eff(self.ak4Jets[i-1]), op.c_float(-9999.))
                #varsToKeep["ak4Jet{}_puid_sfeff".format(i)]         = op.switch(op.rng_len(self.ak4Jets) >= i, self.jetpuid_sf_eff(self.ak4Jets[i-1]), op.c_float(-9999.))
                #varsToKeep["ak4Jet{}_puid_mis".format(i)]           = op.switch(op.rng_len(self.ak4Jets) >= i, self.jetpuid_mc_mis(self.ak4Jets[i-1]), op.c_float(-9999.))
                #varsToKeep["ak4Jet{}_puid_sfmis".format(i)]         = op.switch(op.rng_len(self.ak4Jets) >= i, self.jetpuid_sf_mis(self.ak4Jets[i-1]), op.c_float(-9999.))

            # VBF Jets #
            if not self.inclusive_sel:
                varsToKeep["ak4JetVBFPair1_pt"] = op.switch(
                    op.rng_len(VBFJetPairs) >= 1, VBFJetPairs[0][0].pt,
                    op.c_float(-9999.))
                varsToKeep["ak4JetVBFPair1_eta"] = op.switch(
                    op.rng_len(VBFJetPairs) >= 1, VBFJetPairs[0][0].eta,
                    op.c_float(-9999.))
                varsToKeep["ak4JetVBFPair1_phi"] = op.switch(
                    op.rng_len(VBFJetPairs) >= 1, VBFJetPairs[0][0].phi,
                    op.c_float(-9999.))
                varsToKeep["ak4JetVBFPair1_E"] = op.switch(
                    op.rng_len(VBFJetPairs) >= 1, VBFJetPairs[0][0].p4.E(),
                    op.c_float(-9999.))
                varsToKeep["ak4JetVBFPair2_pt"] = op.switch(
                    op.rng_len(VBFJetPairs) >= 1, VBFJetPairs[0][1].pt,
                    op.c_float(-9999.))
                varsToKeep["ak4JetVBFPair2_eta"] = op.switch(
                    op.rng_len(VBFJetPairs) >= 1, VBFJetPairs[0][1].eta,
                    op.c_float(-9999.))
                varsToKeep["ak4JetVBFPair2_phi"] = op.switch(
                    op.rng_len(VBFJetPairs) >= 1, VBFJetPairs[0][1].phi,
                    op.c_float(-9999.))
                varsToKeep["ak4JetVBFPair2_E"] = op.switch(
                    op.rng_len(VBFJetPairs) >= 1, VBFJetPairs[0][1].p4.E(),
                    op.c_float(-9999.))
                '''
                # inputs : 
                inputsLeps = mvaEvaluatorSL_nonres_DNN01.returnLeptonsMVAInputs (self  = self, lep  = lepton)
                inputsJets = mvaEvaluatorSL_nonres_DNN01.returnJetsMVAInputs    (self  = self, bjets = self.bJetsByScore, jets = self.probableWJets)
                inputsMET = mvaEvaluatorSL_nonres_DNN01.returnMETMVAInputs      (self  = self, met  = self.corrMET)
                inputsFatjet = mvaEvaluatorSL_nonres_DNN01.returnFatjetMVAInputs(self  = self, fatjets = self.ak8Jets)
                inputsHL = mvaEvaluatorSL_nonres_DNN01.returnHighLevelMVAInputs (self  = self,
                                                                                 lep   = lepton,
                                                                                 bjets = self.bJetsByScore,
                                                                                 wjets = self.wJetsByPt,
                                                                                 VBFJetPairs = VBFJetPairs,
                                                                                 channel   = self.args.Channel)
                inputsParam   = mvaEvaluatorSL_nonres_DNN01.returnParamMVAInputs    (self)
                inputsEventNr = mvaEvaluatorSL_nonres_DNN01.returnEventNrMVAInputs  (self,t)

                inputDict = {**inputsLeps, **inputsJets, **inputsMET, **inputsFatjet, **inputsHL} 

                for (varname,_,_),var in inputDict.items():
                    varsToKeep[varname] = var

                from  mvaEvaluatorSL_nonres_DNN01 import inputStaticCast

                inputs = [op.array("double",*inputStaticCast(inputsLeps,"float")),
                          op.array("double",*inputStaticCast(inputsJets,"float")),
                          op.array("double",*inputStaticCast(inputsFatjet,"float")),
                          op.array("double",*inputStaticCast(inputsMET,"float")),
                          op.array("double",*inputStaticCast(inputsHL,"float")),
                          op.array("double",*inputStaticCast(inputsParam,"float")),
                          op.array("long",*inputStaticCast(inputsEventNr,"long"))]
                
                output_01 = DNN_01(*inputs)
                
                for node, output in zip(self.nodes,output_01):
                    varsToKeep['DNN_node_'+node] = output
                '''
            # AK8 Jets #
            for i in range(1, 3):  # 2 leading fatjets
                varsToKeep["ak8Jet{}_pt".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].pt,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_eta".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].eta,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_phi".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].phi,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_E".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].p4.E(), op.c_float(-9999.))
                varsToKeep["ak8Jet{}_msoftdrop".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].msoftdrop, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_tau1".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].tau1,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_tau2".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i, self.ak8BJets[i - 1].tau2,
                    op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet0_pt".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet1.pt, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet0_eta".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet1.eta, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet0_phi".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet1.phi, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet0_CSV".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet1.btagDeepB, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet1_pt".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet2.pt, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet1_eta".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet2.eta, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet1_phi".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet2.phi, op.c_float(-9999.))
                varsToKeep["ak8Jet{}_subjet1_CSV".format(i)] = op.switch(
                    op.rng_len(self.ak8BJets) >= i,
                    self.ak8BJets[i - 1].subJet2.btagDeepB, op.c_float(-9999.))

            varsToKeep["PFMET"] = self.corrMET.pt
            varsToKeep["PFMETphi"] = self.corrMET.phi
            varsToKeep["met1_E"] = self.corrMET.p4.E()
            varsToKeep["met1_pt"] = self.corrMET.pt
            varsToKeep["met1_eta"] = self.corrMET.eta
            varsToKeep["met1_phi"] = self.corrMET.phi

            # SF #
            electronMuon_cont = op.combine(
                (self.electronsFakeSel, self.muonsFakeSel))
            '''
            varsToKeep["trigger_SF"] = op.multiSwitch(
                (op.AND(op.rng_len(self.electronsTightSel)==1,op.rng_len(self.muonsTightSel)==0) , self.ttH_singleElectron_trigSF(self.electronsTightSel[0])),
                (op.AND(op.rng_len(self.electronsTightSel)==0,op.rng_len(self.muonsTightSel)==1) , self.ttH_singleMuon_trigSF(self.muonsTightSel[0])),
                (op.AND(op.rng_len(self.electronsTightSel)>=2,op.rng_len(self.muonsTightSel)==0) , self.lambda_ttH_doubleElectron_trigSF(self.electronsTightSel)),
                (op.AND(op.rng_len(self.electronsTightSel)==0,op.rng_len(self.muonsTightSel)>=2) , self.lambda_ttH_doubleMuon_trigSF(self.muonsTightSel)),
                (op.AND(op.rng_len(self.electronsTightSel)>=1,op.rng_len(self.muonsTightSel)>=1) , self.lambda_ttH_electronMuon_trigSF(electronMuon_cont[0])),
                op.c_float(1.))

            if not self.inclusive_sel:
                #varsToKeep["weight_trigger_el_sf"] = op.switch(op.rng_len(self.electronsTightSel)>0, self.ttH_singleElectron_trigSF(lepton),op.c_float(1.))
                #varsToKeep["weight_trigger_mu_sf"] = op.switch(op.rng_len(self.muonsTightSel)>0, self.ttH_singleMuon_trigSF(lepton),op.c_float(1.))

                varsToKeep["lepton_IDSF"] = op.rng_product(self.electronsFakeSel, lambda el : reduce(mul,self.lambda_ElectronLooseSF(el)+self.lambda_ElectronTightSF(el))) * \
                                            op.rng_product(self.muonsFakeSel, lambda mu : reduce(mul,self.lambda_MuonLooseSF(mu)+self.lambda_MuonTightSF(mu))) 
                
                varsToKeep["lepton_IDSF_recoToLoose"]  = op.rng_product(self.electronsFakeSel, lambda el : reduce(mul,self.lambda_ElectronLooseSF(el))) * \
                                                        op.rng_product(self.muonsFakeSel, lambda mu : reduce(mul,self.lambda_MuonLooseSF(mu)))
                varsToKeep["lepton_IDSF_looseToTight"] = op.rng_product(self.electronsFakeSel, lambda el : reduce(mul,self.lambda_ElectronTightSF(el))) * \
                                                         op.rng_product(self.muonsFakeSel, lambda mu : reduce(mul,self.lambda_MuonTightSF(mu)))

                if era == "2016" or era == "2017": 
                    if self.args.Channel == "El":
                        varsToKeep["weight_electron_reco_low"]    = op.switch(op.AND(self.lambda_is_matched(lepton),lepton.pt<=20.), self.elLooseRecoPtLt20(lepton), op.c_float(1.))
                        varsToKeep["weight_electron_reco_high"]   = op.switch(op.AND(self.lambda_is_matched(lepton),lepton.pt>20.), self.elLooseRecoPtGt20(lepton), op.c_float(1.))
                        varsToKeep["weight_muon_idiso_loose"]     = op.c_float(1.)
                        varsToKeep["weight_electron_id_loose_01"] = op.switch(self.lambda_is_matched(lepton), self.elLooseEff(lepton), op.c_float(1.))
                        varsToKeep["weight_electron_id_loose_02"] = op.switch(self.lambda_is_matched(lepton), self.elLooseId(lepton),  op.c_float(1.))
                        varsToKeep["weight_electron_tth_loose"]   = self.lambda_ElectronTightSF(lepton)[0]
                        varsToKeep["weight_muon_tth_loose"]       = op.c_float(1.)

                    if self.args.Channel == "Mu":
                        varsToKeep["weight_muon_idiso_loose"]     = op.switch(self.lambda_is_matched(lepton), self.muLooseId(lepton), op.c_float(1.))
                        varsToKeep["weight_electron_reco_low"]    = op.c_float(1.)
                        varsToKeep["weight_electron_reco_high"]   = op.c_float(1.)
                        varsToKeep["weight_electron_id_loose_01"] = op.c_float(1.)
                        varsToKeep["weight_electron_id_loose_02"] = op.c_float(1.)
                        varsToKeep["weight_electron_tth_loose"]   = op.c_float(1.)
                        varsToKeep["weight_muon_tth_loose"]       = self.lambda_MuonTightSF(lepton)[0]
                else:
                    raise NotImplementedError

            # L1 Prefire #
            if era in ["2016","2017"]:
                varsToKeep["L1prefire"] = self.L1Prefiring
                varsToKeep["weight_l1_ecal_prefiring"] = self.L1Prefiring
            else:
                varsToKeep["L1prefire"] = op.c_float(-9999.)
                varsToKeep["weight_l1_ecal_prefiring"] = op.c_float(-9999.)

            # Fake rate #
            if self.args.Channel == "El":
                varsToKeep["fakeRate"]                  = op.switch(self.lambda_electronTightSel(self.electronsFakeSel[0]), self.ElFakeFactor(self.electronsFakeSel[0]), op.c_float(1.))
                varsToKeep["weight_fake_electrons"]     = op.switch(self.lambda_electronTightSel(self.electronsFakeSel[0]), op.abs(self.ElFakeFactor(self.electronsFakeSel[0])), op.c_float(1.))
                varsToKeep["weight_fake_muons"]         = op.c_float(1.)
                varsToKeep["weight_fake_two_non_tight"] = op.c_float(999.0)
            if self.args.Channel == "Mu":
                varsToKeep["fakeRate"]                  = op.switch(self.lambda_muonTightSel(self.muonsFakeSel[0]), self.MuFakeFactor(self.muonsFakeSel[0]), op.c_float(1.))
                varsToKeep["weight_fake_electrons"]     = op.c_float(1.)
                varsToKeep["weight_fake_muons"]         = op.switch(self.lambda_muonTightSel(self.muonsFakeSel[0]), op.abs(self.MuFakeFactor(self.muonsFakeSel[0])), op.c_float(1.))
                varsToKeep["weight_fake_two_non_tight"] = op.c_float(999.0)

            if self.is_MC:
                varsToKeep["weight_fake_is_mc"] = op.c_float(-1.)
            else:
                varsToKeep["weight_fake_is_mc"] = op.c_float(1.)

            # PU ID SF #
            #varsToKeep["PU_jetID_SF"]                = self.puid_reweighting
            #varsToKeep["weight_jet_PUid_efficiency"] = self.puid_reweighting_efficiency
            #varsToKeep["weight_jet_PUid_mistag"]     = self.puid_reweighting_mistag

            # Btagging SF #
            varsToKeep["btag_SF"]           = self.btagAk4SF
            varsToKeep["weight_btagWeight"] = self.btagAk4SF
            if "BtagRatioWeight" in self.__dict__.keys():
                varsToKeep["btag_ratio_SF"]   = self.BtagRatioWeight
                varsToKeep["weight_btagNorm"] = self.BtagRatioWeight

            # PS weights #
            varsToKeep["weight_PSWeight_ISR"] = self.psISRSyst
            varsToKeep["weight_PSWeight_FSR"] = self.psFSRSyst
            '''
            # ttbar PT reweighting #
            if "group" in sampleCfg and sampleCfg["group"] == 'ttbar':
                varsToKeep["topPt_wgt"] = self.ttbar_weight(
                    self.genTop[0], self.genAntitop[0])

        # Event Weight #
            if self.is_MC:
                varsToKeep["MC_weight"] = t.genWeight
                puWeightsFile = os.path.join(os.path.dirname(__file__), "data",
                                             "pileup",
                                             sample + '_%s.json' % era)
                #puWeightsFile = os.path.join(os.path.dirname(__file__), "data" , "pileup", sampleCfg["pufile"])
                varsToKeep["PU_weight"] = makePileupWeight(
                    puWeightsFile,
                    t.Pileup_nTrueInt,
                    nameHint=f"puweightFromFile{sample}".replace('-', '_'))
                varsToKeep[
                    "eventWeight"] = noSel.weight if self.inclusive_sel else selObj.sel.weight

            if self.inclusive_sel:
                return noSel, varsToKeep
            else:
                return selObj.sel, varsToKeep

        #---------------------------------------------------------------------------------------#
        #                                    Selection tree                                     #
        #---------------------------------------------------------------------------------------#
        #----- EVT variables -----#
        varsToKeep["event"] = None  # Already in tree
        varsToKeep["run"] = None  # Already in tree
        varsToKeep["ls"] = t.luminosityBlock
        '''
        inputsLeps   = mva02.returnLeptonsMVAInputs   (self  = self, lep  = lepton)
        inputsJets   = mva02.returnJetsMVAInputs      (self  = self, bjets = self.bJetsByScore, jets = self.probableWJets)
        inputsMET    = mva02.returnMETMVAInputs       (self  = self, met  = self.corrMET)
        inputsFatjet = mva02.returnFatjetMVAInputs    (self  = self, fatbjets = self.ak8BJets)
        inputNeu     = mva02.returnNuMVAInputs        (self  = self)
        inputsHL     = mva02.returnHighLevelMVAInputs (self  = self,
                                                       lep   = lepton,
                                                       bjets = self.bJetsByScore,
                                                       wjets = self.wJetsByPt,
                                                       VBFJetPairs = VBFJetPairs,
                                                       channel   = self.args.Channel)
        inputsParam   = mva02.returnParamMVAInputs    (self)
        inputsEventNr = mva02.returnEventNrMVAInputs  (self,t)
        '''

        inputsLeps = mva02.returnLeptonsMVAInputs(self=self,
                                                  lep=lepton,
                                                  conep4=lepconep4)
        inputsJets = mva02.returnJetsMVAInputs(self=self,
                                               bjets=self.bJetsByScore,
                                               jets=self.probableWJets)
        inputsMET = mva02.returnMETMVAInputs(self=self, met=self.corrMET)
        inputsFatjet = mva02.returnFatjetMVAInputs(self=self,
                                                   fatbjets=self.ak8BJets)
        inputNeu = mva02.returnNuMVAInputs(self=self)
        inputsHL = mva02.returnHighLevelMVAInputs(self=self,
                                                  lep=lepton,
                                                  conep4=lepconep4,
                                                  bjets=self.bJetsByScore,
                                                  wjets=self.wJetsByPt,
                                                  VBFJetPairs=VBFJetPairs,
                                                  channel=self.args.Channel)
        inputsParam = mva02.returnParamMVAInputs(self)
        inputsEventNr = mva02.returnEventNrMVAInputs(self, t)

        inputDict = {
            **inputsLeps,
            **inputsJets,
            **inputsFatjet,
            **inputsMET,
            **inputNeu,
            **inputsHL,
            **inputsParam,
            **inputsEventNr
        }

        for (varname, _, _), var in inputDict.items():
            varsToKeep[varname] = var

        #from  mvaEvaluatorSL_nonres_DNN01 import inputStaticCast

        inputs = [
            op.array("double", *mva02.inputStaticCast(inputsLeps, "float")),
            op.array("double", *mva02.inputStaticCast(inputsJets, "float")),
            op.array("double", *mva02.inputStaticCast(inputsFatjet, "float")),
            op.array("double", *mva02.inputStaticCast(inputsMET, "float")),
            op.array("double", *mva02.inputStaticCast(inputNeu, "float")),
            op.array("double", *mva02.inputStaticCast(inputsHL, "float")),
            op.array("double", *mva02.inputStaticCast(inputsParam, "float")),
            op.array("long", *mva02.inputStaticCast(inputsEventNr, "long"))
        ]

        output_02 = DNN_02(*inputs)

        for node, output in zip(self.nodes, output_02):
            varsToKeep['DNN_node_' + node] = output

        #----- Additional variables -----#
        varsToKeep["MC_weight"] = t.genWeight
        varsToKeep['total_weight'] = selObj.sel.weight

        #return leptonSel.sel, varsToKeep
        return selObj.sel, varsToKeep
コード例 #23
0
def returnHighLevelMVAInputs(self,l1,l2,met,jets,bjets,electrons,muons,channel):
    if channel == "ElEl":
        cone_l1 = self.getElectronConeP4(l1) 
        cone_l2 = self.getElectronConeP4(l2)
    elif channel == "MuMu":
        cone_l1 = self.getMuonConeP4(l1)
        cone_l2 = self.getMuonConeP4(l2)
    elif channel == "ElMu":
        cone_l1 = self.getElectronConeP4(l1)
        cone_l2 = self.getMuonConeP4(l2)
    else:
        raise RuntimeError("Wrong channel")

    dijets = op.combine(jets, N=2)

    import bamboo.treeoperations as _to
    def rng_min(rng, fun=(lambda x : x), typeName="float"):
        return op._to.Reduce.fromRngFun(rng, op.c_float(float("+inf"), typeName), ( lambda fn : (
                lambda res, elm : op.extMethod("std::min", returnType="Float_t")(res, fn(elm))
                        ) )(fun) )

    if self.args.Boosted0Btag or self.args.Boosted1Btag:
        VBFJetPairs = self.VBFJetPairsBoosted
    elif self.args.Resolved0Btag or self.args.Resolved1Btag or self.args.Resolved2Btag:
        VBFJetPairs = self.VBFJetPairsResolved
    else:
        raise RuntimeError("Wrong selection to be used by the DNN")

    return {
            ('m_bb_bregcorr',          'Di-bjet invariant mass (regcorr) [GeV]',  (100,0.,1000.))   : op.multiSwitch((op.rng_len(bjets) == 0, op.c_float(0.)),
                                                                                                                     (op.rng_len(bjets) == 1, self.HLL.getCorrBp4(bjets[0]).M()),
                                                                                                                     op.invariant_mass(self.HLL.getCorrBp4(bjets[0]),self.HLL.getCorrBp4(bjets[1]))),
            ('ht',                     'HT(jets) [GeV]',                          (100,0.,1000.))   : op.rng_sum(jets, lambda j : j.pt),
            ('min_dr_jets_lep1',       'Min(#Delta R(lead lepton,jets))',         (25,0.,5.))       : op.switch(op.rng_len(jets) > 0,
                                                                                                                op.switch(cone_l1.Pt() >= cone_l2.Pt(),
                                                                                                                          self.HLL.MinDR_part1_partCont(cone_l1,jets),
                                                                                                                          self.HLL.MinDR_part1_partCont(cone_l2,jets)),
                                                                                                                op.c_float(0.)),
            ('min_dr_jets_lep2',       'Min(#Delta R(sublead lepton,jets))',      (25,0.,5.))       : op.switch(op.rng_len(jets) > 0,
                                                                                                                op.switch(cone_l1.Pt() >= cone_l2.Pt(),
                                                                                                                          self.HLL.MinDR_part1_partCont(cone_l2,jets),
                                                                                                                          self.HLL.MinDR_part1_partCont(cone_l1,jets)),
                                                                                                                op.c_float(0.)),
            ('m_ll',                   'Dilepton invariant mass [GeV]',           (100,0.,1000.))   : op.invariant_mass(cone_l1,cone_l2),
            ('dr_ll',                  'Dilepton #Delta R',                       (25,0.,5.))       : op.deltaR(cone_l1,cone_l2),
            ('min_dr_jet',             'Min(#Delta R(jets))',                     (25,0.,5.))       : op.switch(op.rng_len(dijets) > 0,
                                                                                                                op.rng_min(dijets,lambda dijet : op.deltaR(dijet[0].p4,dijet[1].p4)),
                                                                                                                op.c_float(0.)),
            ('min_dhi_jet',            'Min(#Delta #Phi(jets))',                  (16,0.,3.2))      : op.switch(op.rng_len(dijets) > 0,
                                                                                                                rng_min(dijets,lambda dijet : op.abs(op.deltaPhi(dijet[0].p4,dijet[1].p4)),typeName='double'),
                                                                                                                op.c_float(0.)),
            ('m_hh_simplemet_bregcorr','M_{HH} (simple MET) (regcorr) [GeV]',     (100,0.,1000.))   : op.invariant_mass(op.rng_sum(bjets,
                                                                                                                                   lambda bjet : self.HLL.getCorrBp4(bjet),
                                                                                                                                   start=self.HLL.empty_p4),
                                                                                                                        cone_l1,
                                                                                                                        cone_l2,
                                                                                                                        met.p4),
            ('met_ld',                 'MET_{LD}',                                (100,0.,1000.))   : self.HLL.MET_LD_DL(met,jets,electrons,muons),
            ('dr_bb',                  'Di-bjet #Delta R',                        (25,0.,5.))       : op.switch(op.rng_len(bjets)>=2,
                                                                                                                op.deltaR(bjets[0].p4,bjets[1].p4),
                                                                                                                op.c_float(0.)),
            ('min_dr_leps_b1',         'Min(#Delta R(lead bjet,dilepton))',       (25,0.,5.))       : op.switch(op.rng_len(bjets)>=1,
                                                                                                                self.HLL.MinDR_part1_dipart(bjets[0].p4,[cone_l1,cone_l2]),
                                                                                                                op.c_float(0.)),
            ('min_dr_leps_b2',         'Min(#Delta R(sublead bjet,dilepton))',    (25,0.,5.))       : op.switch(op.rng_len(bjets)>=2,
                                                                                                                self.HLL.MinDR_part1_dipart(bjets[1].p4,[cone_l1,cone_l2]),
                                                                                                                op.c_float(0.)),
            ('lep1_conept',            'Lead lepton cone-P_T [GeV]',              (40,0.,200.))     : op.switch(cone_l1.Pt() >= cone_l2.Pt() , cone_l1.Pt() , cone_l2.Pt()),
            ('lep2_conept',            'Sublead lepton cone-P_T [GeV]',           (40,0.,200.))     : op.switch(cone_l1.Pt() >= cone_l2.Pt() , cone_l2.Pt() , cone_l1.Pt()),
            ('mww_simplemet',          'M_{WW} (simple MET) [GeV]',               (100,0.,1000.))   : op.invariant_mass(cone_l1,cone_l2,met.p4),
            ('vbf_tag',                'VBF tag',                                 (2,0.,2.))        : op.c_int(op.rng_len(VBFJetPairs)>0),
            ('boosted_tag',            'Boosted tag',                             (2,0.,2.))        : op.c_int(op.OR(op.rng_len(self.ak8BJets) > 0,           # Boosted 1B
                                                                                                                     op.AND(op.rng_len(self.ak8BJets) == 0,   # Boosted 0B
                                                                                                                            op.rng_len(self.ak8Jets) > 0,
                                                                                                                            op.rng_len(self.ak4BJets) == 0))),
            ('dphi_met_dilep',         'Dilepton-MET #Delta #Phi',                (32,-3.2,3.2))    : op.abs(op.deltaPhi(met.p4,(cone_l1+cone_l2))),
            ('dphi_met_dibjet',        'Dibjet-MET #Delta #Phi',                  (32,-3.2,3.2))    : op.multiSwitch((op.rng_len(bjets) == 0, op.c_float(0.)),
                                                                                                                     (op.rng_len(bjets) == 1, op.abs(op.deltaPhi(met.p4,bjets[0].p4))),
                                                                                                                     op.abs(op.deltaPhi(met.p4,(bjets[0].p4+bjets[1].p4)))),
            ('dr_dilep_dijet',         'Dilepton-dijet #Delta R',                 (25,0.,5.))       : op.multiSwitch((op.rng_len(jets) == 0, op.c_float(0.)),
                                                                                                                     (op.rng_len(jets) == 1, op.deltaR((cone_l1+cone_l2),jets[0].p4)),
                                                                                                                     op.deltaR((cone_l1+cone_l2),(jets[0].p4+jets[1].p4))),
            ('dr_dilep_dibjet',        'Dilepton-dibjet #Delta R',                (25,0.,5.))       : op.multiSwitch((op.rng_len(bjets) == 0, op.c_float(0.)),
                                                                                                                     (op.rng_len(bjets) == 1, op.deltaR((cone_l1+cone_l2),bjets[0].p4)),
                                                                                                                     op.deltaR((cone_l1+cone_l2),(bjets[0].p4+bjets[1].p4))),
            ('vbf_pair_mass',          'VBF pair M_{jj}',                         (100,0.,1000.))   : op.switch(op.rng_len(VBFJetPairs)>0,
                                                                                                                op.invariant_mass(VBFJetPairs[0][0].p4,VBFJetPairs[0][1].p4),
                                                                                                                op.c_float(0.)),
            ('vbf_pairs_absdeltaeta',  'VBF pair #Delta#eta',                     (25,0.,5.))       : op.switch(op.rng_len(VBFJetPairs)>0,
                                                                                                                op.abs(VBFJetPairs[0][0].eta-VBFJetPairs[0][1].eta),
                                                                                                                op.c_float(0.)),
            ('sphericity',             'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('sphericity_T',           'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('aplanarity',             'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('eventshape_C',           'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('eventshape_D',           'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('eventshape_Y',           'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('foxwolfram1',            'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('foxwolfram2',            'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('foxwolfram3',            'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('foxwolfram4',            'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('foxwolfram5',            'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('centrality',             'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('centrality_jets',        'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('eigenvalue1',            'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('eigenvalue2',            'None',                                    (1,0.,1.))        : op.c_float(0.),
            ('eigenvalue3',            'None',                                    (1,0.,1.))        : op.c_float(0.),
            }
コード例 #24
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
コード例 #25
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        # Some imports #
        from bamboo.analysisutils import forceDefine

        era = sampleCfg['era']
        # Get pile-up configs #
        puWeightsFile = None
        if era == "2016":
            sfTag = "94X"
            puWeightsFile = os.path.join(os.path.dirname(__file__), "data",
                                         "puweights2016.json")
        elif era == "2017":
            sfTag = "94X"
            puWeightsFile = os.path.join(os.path.dirname(__file__), "data",
                                         "puweights2017.json")
        elif era == "2018":
            sfTag = "102X"
            puWeightsFile = os.path.join(os.path.dirname(__file__), "data",
                                         "puweights2018.json")
        if self.isMC(sample) and puWeightsFile is not None:
            from bamboo.analysisutils import makePileupWeight
            noSel = noSel.refine("puWeight",
                                 weight=makePileupWeight(puWeightsFile,
                                                         t.Pileup_nTrueInt,
                                                         systName="pileup"))
        isMC = self.isMC(sample)
        plots = []

        forceDefine(t._Muon.calcProd, noSel)

        #############################################################################
        ################################  Muons #####################################
        #############################################################################
        # Wp // 2016- 2017 -2018 : Muon_mediumId   // https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonIdRun2#Muon_Isolation
        muonsByPt = op.sort(t.Muon, lambda mu: -mu.p4.Pt())
        muons = op.select(
            muonsByPt, lambda mu: op.AND(mu.p4.Pt() > 10.,
                                         op.abs(mu.p4.Eta()) < 2.4, mu.tightId,
                                         mu.pfRelIso04_all < 0.15))

        # Scalefactors #
        #if era=="2016":
        #    doubleMuTrigSF = get_scalefactor("dilepton", ("doubleMuLeg_HHMoriond17_2016"), systName="mumutrig")
        #    muMediumIDSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "id_medium"), combine="weight", systName="muid")
        #    muMediumISOSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "iso_tight_id_medium"), combine="weight", systName="muiso")
        #    TrkIDSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "highpt"), combine="weight")
        #    TrkISOSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "isotrk_loose_idtrk_tightidandipcut"), combine="weight")
        #else:
        #    muMediumIDSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "id_medium"), systName="muid")
        #    muMediumISOSF = get_scalefactor("lepton", ("muon_{0}_{1}".format(era, sfTag), "iso_tight_id_medium"), systName="muiso")

        #############################################################################
        #############################  Electrons  ###################################
        #############################################################################
        #Wp  // 2016: Electron_cutBased_Sum16==3  -> medium     // 2017 -2018  : Electron_cutBased ==3   --> medium ( Fall17_V2)
        # asking for electrons to be in the Barrel region with dz<1mm & dxy< 0.5mm   //   Endcap region dz<2mm & dxy< 0.5mm
        electronsByPt = op.sort(t.Electron, lambda ele: -ele.p4.Pt())
        electrons = op.select(
            electronsByPt,
            lambda ele: op.AND(ele.p4.Pt() > 15.,
                               op.abs(ele.p4.Eta()) < 2.5, ele.cutBased >= 3)
        )  # //cut-based ID Fall17 V2 the recomended one from POG for the FullRunII

        # Scalefactors #
        #elMediumIDSF = get_scalefactor("lepton", ("electron_{0}_{1}".format(era,sfTag), "id_medium"), systName="elid")
        #doubleEleTrigSF = get_scalefactor("dilepton", ("doubleEleLeg_HHMoriond17_2016"), systName="eleltrig")

        #elemuTrigSF = get_scalefactor("dilepton", ("elemuLeg_HHMoriond17_2016"), systName="elmutrig")
        #mueleTrigSF = get_scalefactor("dilepton", ("mueleLeg_HHMoriond17_2016"), systName="mueltrig")

        OsElEl = op.combine(
            electrons,
            N=2,
            pred=lambda el1, el2: op.AND(el1.charge != el2.charge,
                                         el1.p4.Pt() > 25,
                                         el2.p4.Pt() > 15))
        OsMuMu = op.combine(
            muons,
            N=2,
            pred=lambda mu1, mu2: op.AND(mu1.charge != mu2.charge,
                                         mu1.p4.Pt() > 25,
                                         mu2.p4.Pt() > 15))
        OsElMu = op.combine((electrons, muons),
                            pred=lambda el, mu: op.AND(el.charge != mu.charge,
                                                       el.p4.Pt() > 25,
                                                       mu.p4.Pt() > 15))
        OsMuEl = op.combine((electrons, muons),
                            pred=lambda el, mu: op.AND(el.charge != mu.charge,
                                                       el.p4.Pt() > 15,
                                                       mu.p4.Pt() > 25))

        hasOsElEl = noSel.refine("hasOsElEl", cut=[op.rng_len(OsElEl) >= 1])
        hasOsMuMu = noSel.refine("hasOsMuMu", cut=[op.rng_len(OsMuMu) >= 1])
        hasOsElMu = noSel.refine("hasOsElMu", cut=[op.rng_len(OsElMu) >= 1])
        hasOsMuEl = noSel.refine("hasOsMuEl", cut=[op.rng_len(OsMuEl) >= 1])

        plots.append(
            Plot.make1D("ElEl_channel",
                        op.rng_len(OsElEl),
                        noSel,
                        EquidistantBinning(10, 0, 10.),
                        title='Number of dilepton events in ElEl channel',
                        xTitle='N_{dilepton} (ElEl channel)'))
        plots.append(
            Plot.make1D("MuMu_channel",
                        op.rng_len(OsMuMu),
                        noSel,
                        EquidistantBinning(10, 0, 10.),
                        title='Number of dilepton events in MuMu channel',
                        xTitle='N_{dilepton} (MuMu channel)'))
        plots.append(
            Plot.make1D("ElMu_channel",
                        op.rng_len(OsElMu),
                        noSel,
                        EquidistantBinning(10, 0, 10.),
                        title='Number of dilepton events in ElMu channel',
                        xTitle='N_{dilepton} (ElMu channel)'))
        plots.append(
            Plot.make1D("MuEl_channel",
                        op.rng_len(OsMuEl),
                        noSel,
                        EquidistantBinning(10, 0, 10.),
                        title='Number of dilepton events in MuEl channel',
                        xTitle='N_{dilepton} (MuEl channel)'))

        plots += makeDileptonPlots(self,
                                   sel=hasOsElEl,
                                   dilepton=OsElEl[0],
                                   suffix='hasOsdilep',
                                   channel='ElEl')
        plots += makeDileptonPlots(self,
                                   sel=hasOsMuMu,
                                   dilepton=OsMuMu[0],
                                   suffix='hasOsdilep',
                                   channel='MuMu')
        plots += makeDileptonPlots(self,
                                   sel=hasOsElMu,
                                   dilepton=OsElMu[0],
                                   suffix='hasOsdilep',
                                   channel='ElMu')
        plots += makeDileptonPlots(self,
                                   sel=hasOsMuEl,
                                   dilepton=OsMuEl[0],
                                   suffix='hasOsdilep',
                                   channel='MuEl')

        # Dilepton Z peak exclusion (charge already done in previous selection) #
        lambda_mllLowerband = lambda dilep: op.in_range(
            12., op.invariant_mass(dilep[0].p4, dilep[1].p4), 80.)
        lambda_mllUpperband = lambda dilep: op.invariant_mass(
            dilep[0].p4, dilep[1].p4) > 100.
        lambda_mllCut = lambda dilep: op.OR(lambda_mllLowerband(dilep),
                                            lambda_mllUpperband(dilep))

        hasOsElElOutZ = hasOsElEl.refine("hasOsElElOutZ",
                                         cut=[lambda_mllCut(OsElEl[0])])
        hasOsMuMuOutZ = hasOsMuMu.refine("hasOsMuMuOutZ",
                                         cut=[lambda_mllCut(OsMuMu[0])])
        hasOsElMuOutZ = hasOsElMu.refine("hasOsElMuOutZ",
                                         cut=[lambda_mllCut(OsElMu[0])])
        hasOsMuElOutZ = hasOsMuEl.refine("hasOsMuElOutZ",
                                         cut=[lambda_mllCut(OsMuEl[0])])

        plots += makeDileptonPlots(self,
                                   sel=hasOsElElOutZ,
                                   dilepton=OsElEl[0],
                                   suffix='hasOsdilep_OutZ',
                                   channel='ElEl')
        plots += makeDileptonPlots(self,
                                   sel=hasOsMuMuOutZ,
                                   dilepton=OsMuMu[0],
                                   suffix='hasOsdilep_OutZ',
                                   channel='MuMu')
        plots += makeDileptonPlots(self,
                                   sel=hasOsElMuOutZ,
                                   dilepton=OsElMu[0],
                                   suffix='hasOsdilep_OutZ',
                                   channel='ElMu')
        plots += makeDileptonPlots(self,
                                   sel=hasOsMuElOutZ,
                                   dilepton=OsMuEl[0],
                                   suffix='hasOsdilep_OutZ',
                                   channel='MuEl')

        #############################################################################
        ################################  Jets  #####################################
        #############################################################################
        # select jets   // 2016 - 2017 - 2018   ( j.jetId &2) ->      tight jet ID
        jetsByPt = op.sort(t.Jet, lambda jet: -jet.p4.Pt())
        jetsSel = op.select(jetsByPt,
                            lambda j: op.AND(j.p4.Pt() > 20.,
                                             op.abs(j.p4.Eta()) < 2.4,
                                             (j.jetId & 2)))  # Jets = AK4 jets
        fatjetsByPt = op.sort(t.FatJet, lambda fatjet: -fatjet.p4.Pt())
        fatjetsSel = op.select(
            fatjetsByPt, lambda j: op.AND(j.p4.Pt() > 20.,
                                          op.abs(j.p4.Eta()) < 2.4,
                                          (j.jetId & 2)))  # FatJets = AK8 jets
        # exclude from the jetsSel any jet that happens to include within its reconstruction cone a muon or an electron.
        jets = op.select(
            jetsSel, lambda j: op.AND(
                op.NOT(
                    op.rng_any(electrons, lambda ele: op.deltaR(j.p4, ele.p4) <
                               0.3)),
                op.NOT(
                    op.rng_any(muons, lambda mu: op.deltaR(j.p4, mu.p4) < 0.3))
            ))
        fatjets = op.select(
            fatjetsSel, lambda j: op.AND(
                op.NOT(
                    op.rng_any(electrons, lambda ele: op.deltaR(j.p4, ele.p4) <
                               0.3)),
                op.NOT(
                    op.rng_any(muons, lambda mu: op.deltaR(j.p4, mu.p4) < 0.3))
            ))
        # Boosted and resolved jets categories #
        if era == "2016":  # Must check that subJet exists before looking at the btag
            lambda_boosted = lambda fatjet: op.OR(
                op.AND(fatjet.subJet1._idx.result != -1, fatjet.subJet1.
                       btagDeepB > 0.6321),
                op.AND(fatjet.subJet2._idx.result != -1, fatjet.subJet2.
                       btagDeepB > 0.6321))
            lambda_resolved = lambda jet: jet.btagDeepB > 0.6321
        elif era == "2017":
            lambda_boosted = lambda fatjet: op.OR(
                op.AND(fatjet.subJet1._idx.result != -1, fatjet.subJet1.
                       btagDeepB > 0.4941),
                op.AND(fatjet.subJet2._idx.result != -1, fatjet.subJet2.
                       btagDeepB > 0.4941))
            lambda_resolved = lambda jet: jet.btagDeepB > 0.4941
        elif era == "2018":
            lambda_boosted = lambda fatjet: op.OR(
                op.AND(fatjet.subJet1._idx.result != -1, fatjet.subJet1.
                       btagDeepB > 0.4184),
                op.AND(fatjet.subJet2._idx.result != -1, fatjet.subJet2.
                       btagDeepB > 0.4184))
            lambda_resolved = lambda jet: jet.btagDeepB > 0.4184

        # Select the bjets we want #
        bjetsResolved = op.select(jets, lambda_resolved)
        bjetsBoosted = op.select(fatjets, lambda_boosted)

        # Define the boosted and Resolved (+exclusive) selections #
        hasBoostedJets = noSel.refine("hasBoostedJets",
                                      cut=[op.rng_len(bjetsBoosted) >= 1])
        hasNotBoostedJets = noSel.refine("hasNotBoostedJets",
                                         cut=[op.rng_len(bjetsBoosted) == 0])
        hasResolvedJets = noSel.refine(
            "hasResolvedJets",
            cut=[op.rng_len(jets) >= 2,
                 op.rng_len(bjetsResolved) >= 1])
        hasNotResolvedJets = noSel.refine(
            "hasNotResolvedJets",
            cut=[op.OR(op.rng_len(jets) <= 1,
                       op.rng_len(bjetsResolved) == 0)])
        hasBoostedAndResolvedJets = noSel.refine(
            "hasBoostedAndResolvedJets",
            cut=[
                op.rng_len(bjetsBoosted) >= 1,
                op.rng_len(jets) >= 2,
                op.rng_len(bjetsResolved) >= 1
            ])
        hasNotBoostedAndResolvedJets = noSel.refine(
            "hasNotBoostedAndResolvedJets",
            cut=[
                op.OR(
                    op.rng_len(bjetsBoosted) == 0,
                    op.rng_len(jets) <= 1,
                    op.rng_len(bjetsResolved) == 0)
            ])
        hasExlusiveResolvedJets = noSel.refine(
            "hasExlusiveResolved",
            cut=[
                op.rng_len(jets) >= 2,
                op.rng_len(bjetsResolved) >= 1,
                op.rng_len(bjetsBoosted) == 0
            ])
        hasNotExlusiveResolvedJets = noSel.refine(
            "hasNotExlusiveResolved",
            cut=[
                op.OR(
                    op.OR(
                        op.rng_len(jets) <= 1,
                        op.rng_len(bjetsResolved) == 0),
                    op.AND(
                        op.rng_len(bjetsBoosted) >= 1,
                        op.rng_len(jets) >= 2,
                        op.rng_len(bjetsResolved) >= 1))
            ])
        hasExlusiveBoostedJets = noSel.refine(
            "hasExlusiveBoostedJets",
            cut=[
                op.rng_len(bjetsBoosted) >= 1,
                op.OR(op.rng_len(jets) <= 1,
                      op.rng_len(bjetsResolved) == 0)
            ])
        hasNotExlusiveBoostedJets = noSel.refine(
            "hasNotExlusiveBoostedJets",
            cut=[
                op.OR(
                    op.rng_len(bjetsBoosted) == 0,
                    op.AND(
                        op.rng_len(jets) >= 2,
                        op.rng_len(bjetsResolved) >= 1))
            ])

        # Counting events from different selections for debugging #
        # Passing Boosted selection #
        PassedBoosted = Plot.make1D("PassedBoosted",
                                    op.c_int(1),
                                    hasBoostedJets,
                                    EquidistantBinning(2, 0., 2.),
                                    title='Passed Boosted',
                                    xTitle='Passed Boosted')
        FailedBoosted = Plot.make1D("FailedBoosted",
                                    op.c_int(0),
                                    hasNotBoostedJets,
                                    EquidistantBinning(2, 0., 2.),
                                    title='Failed Boosted',
                                    xTitle='Failed Boosted')
        plots.append(
            SummedPlot("BoostedCase", [FailedBoosted, PassedBoosted],
                       xTitle="Boosted selection"))

        # Passing Resolved selection #
        PassedResolved = Plot.make1D("PassedResolved",
                                     op.c_int(1),
                                     hasResolvedJets,
                                     EquidistantBinning(2, 0., 2.),
                                     title='Passed Resolved',
                                     xTitle='Passed Resolved')
        FailedResolved = Plot.make1D("FailedResolved",
                                     op.c_int(0),
                                     hasNotResolvedJets,
                                     EquidistantBinning(2, 0., 2.),
                                     title='Failed Resolved',
                                     xTitle='Failed Resolved')
        plots.append(
            SummedPlot("ResolvedCase", [FailedResolved, PassedResolved],
                       xTitle="Resolved selection"))

        # Passing Exclusive Resolved (Resolved AND NOT Boosted) #
        PassedExclusiveResolved = Plot.make1D(
            "PassedExclusiveResolved",
            op.c_int(1),
            hasExlusiveResolvedJets,
            EquidistantBinning(2, 0., 2.),
            title='Passed Exclusive Resolved',
            xTitle='Passed Exclusive Resolved')
        FailedExclusiveResolved = Plot.make1D(
            "FailedExclusiveResolved",
            op.c_int(0),
            hasNotExlusiveResolvedJets,
            EquidistantBinning(2, 0., 2.),
            title='Failed Exclusive Resolved',
            xTitle='Failed Exclusive Resolved')
        plots.append(
            SummedPlot("ExclusiveResolvedCase",
                       [FailedExclusiveResolved, PassedExclusiveResolved],
                       xTitle="Exclusive Resolved selection"))

        # Passing Exclusive Boosted (Boosted AND NOT Resolved) #
        PassedExclusiveBoosted = Plot.make1D("PassedExclusiveBoosted",
                                             op.c_int(1),
                                             hasExlusiveBoostedJets,
                                             EquidistantBinning(2, 0., 2.),
                                             title='Passed Exclusive Boosted',
                                             xTitle='Passed Exclusive Boosted')
        FailedExclusiveBoosted = Plot.make1D("FailedExclusiveBoosted",
                                             op.c_int(0),
                                             hasNotExlusiveBoostedJets,
                                             EquidistantBinning(2, 0., 2.),
                                             title='Failed Exclusive Boosted',
                                             xTitle='Failed Exclusive Boosted')
        plots.append(
            SummedPlot("ExclusiveBoostedCase",
                       [FailedExclusiveBoosted, PassedExclusiveBoosted],
                       xTitle="Exclusive Boosted selection"))

        # Passing Boosted AND Resolved #
        PassedBoth = Plot.make1D("PassedBoth",
                                 op.c_int(1),
                                 hasBoostedAndResolvedJets,
                                 EquidistantBinning(2, 0., 2.),
                                 title='Passed Both Boosted and Resolved',
                                 xTitle='Passed Boosted and Resolved')
        FailedBoth = Plot.make1D(
            "FailedBoth",  # Means failed the (Boosted AND Resolved) = either one or the other 
            op.c_int(0),
            hasNotBoostedAndResolvedJets,
            EquidistantBinning(2, 0., 2.),
            title='Failed combination Boosted and Resolved',
            xTitle='Failed combination')
        plots.append(
            SummedPlot("BoostedAndResolvedCase", [FailedBoth, PassedBoth],
                       xTitle="Boosted and Resolved selection"))

        # Count number of boosted and resolved jets #
        plots.append(
            Plot.make1D("NBoostedJets",
                        op.rng_len(bjetsBoosted),
                        hasBoostedJets,
                        EquidistantBinning(5, 0., 5.),
                        title='Number of boosted jets in boosted case',
                        xTitle='N boosted bjets'))
        plots.append(
            Plot.make1D(
                "NResolvedJets",
                op.rng_len(bjetsResolved),
                hasExlusiveResolvedJets,
                EquidistantBinning(5, 0., 5.),
                title='Number of resolved jets in exclusive resolved case',
                xTitle='N resolved bjets'))

        # Plot number of subjets in the boosted fatjets #
        lambda_noSubjet = lambda fatjet: op.AND(
            fatjet.subJet1._idx.result == -1,
            op.AND(fatjet.subJet2._idx.result == -1))
        lambda_oneSubjet = lambda fatjet: op.AND(
            fatjet.subJet1._idx.result != -1,
            op.AND(fatjet.subJet2._idx.result == -1))
        lambda_twoSubjet = lambda fatjet: op.AND(
            fatjet.subJet1._idx.result != -1,
            op.AND(fatjet.subJet2._idx.result != -1))

        hasNoSubjet = hasBoostedJets.refine(
            "hasNoSubjet", cut=[lambda_noSubjet(bjetsBoosted[0])])
        hasOneSubjet = hasBoostedJets.refine(
            "hasOneSubjet", cut=[lambda_oneSubjet(bjetsBoosted[0])])
        hasTwoSubjet = hasBoostedJets.refine(
            "hasTwoSubjet", cut=[lambda_twoSubjet(bjetsBoosted[0])])

        plot_hasNoSubjet = Plot.make1D(
            "plot_hasNoSubjet",  # Fill bin 0
            op.c_int(0),
            hasNoSubjet,
            EquidistantBinning(3, 0., 3.),
            title='Boosted jet without subjet')
        plot_hasOneSubjet = Plot.make1D(
            "plot_hasOneSubjet",  # Fill bin 1
            op.c_int(1),
            hasOneSubjet,
            EquidistantBinning(3, 0., 3.),
            title='Boosted jet with one subjet')
        plot_hasTwoSubjet = Plot.make1D(
            "plot_hasTwoSubjet",  # Fill bin 2
            op.c_int(2),
            hasTwoSubjet,
            EquidistantBinning(3, 0., 3.),
            title='Boosted jet with two subjets')
        plots.append(
            SummedPlot(
                "NumberOfSubjets",
                [plot_hasNoSubjet, plot_hasOneSubjet, plot_hasTwoSubjet],
                xTitle="Number of subjets in boosted jet"))

        # Plot jets quantities without the dilepton selections #
        plots += makeFatJetPlots(self,
                                 sel=hasBoostedJets,
                                 fatjet=bjetsBoosted[0],
                                 suffix="BoostedJets",
                                 channel="NoChannel")
        plots += makeJetsPlots(self,
                               sel=hasResolvedJets,
                               jets=bjetsResolved,
                               suffix="ResolvedJets",
                               channel="NoChannel")

        #############################################################################
        ##################### Jets + Dilepton combination ###########################
        #############################################################################
        # Combine dilepton and Resolved (Exclusive = NOT Boosted) selections #
        hasOsElElOutZResolvedJets = hasOsElElOutZ.refine(
            "hasOsElElOutZResolvedJets",
            cut=[
                op.rng_len(jets) >= 2,
                op.rng_len(bjetsResolved) >= 1,
                op.rng_len(bjetsBoosted) == 0
            ])
        hasOsMuMuOutZResolvedJets = hasOsMuMuOutZ.refine(
            "hasOsMuMuOutZResolvedJets",
            cut=[
                op.rng_len(jets) >= 2,
                op.rng_len(bjetsResolved) >= 1,
                op.rng_len(bjetsBoosted) == 0
            ])
        hasOsElMuOutZResolvedJets = hasOsElMuOutZ.refine(
            "hasOsElMuOutZResolvedJets",
            cut=[
                op.rng_len(jets) >= 2,
                op.rng_len(bjetsResolved) >= 1,
                op.rng_len(bjetsBoosted) == 0
            ])
        hasOsMuElOutZResolvedJets = hasOsMuElOutZ.refine(
            "hasOsMuElOutZResolvedJets",
            cut=[
                op.rng_len(jets) >= 2,
                op.rng_len(bjetsResolved) >= 1,
                op.rng_len(bjetsBoosted) == 0
            ])

        # Combine dilepton and Boosted selections #
        hasOsElElOutZBoostedJets = hasOsElElOutZ.refine(
            "hasOsElElOutZBoostedJets", cut=[op.rng_len(bjetsBoosted) >= 1])
        hasOsMuMuOutZBoostedJets = hasOsMuMuOutZ.refine(
            "hasOsMuMuOutZBoostedJets", cut=[op.rng_len(bjetsBoosted) >= 1])
        hasOsElMuOutZBoostedJets = hasOsElMuOutZ.refine(
            "hasOsElMuOutZBoostedJets", cut=[op.rng_len(bjetsBoosted) >= 1])
        hasOsMuElOutZBoostedJets = hasOsMuElOutZ.refine(
            "hasOsMuElOutZBoostedJets", cut=[op.rng_len(bjetsBoosted) >= 1])

        # Plot dilepton with OS, Z peak and Resolved jets selections #
        plots += makeDileptonPlots(self,
                                   sel=hasOsElElOutZResolvedJets,
                                   dilepton=OsElEl[0],
                                   suffix='hasOsdilep_OutZ_ResolvedJets',
                                   channel='ElEl')
        plots += makeDileptonPlots(self,
                                   sel=hasOsMuMuOutZResolvedJets,
                                   dilepton=OsMuMu[0],
                                   suffix='hasOsdilep_OutZ_ResolvedJets',
                                   channel='MuMu')
        plots += makeDileptonPlots(self,
                                   sel=hasOsElMuOutZResolvedJets,
                                   dilepton=OsElMu[0],
                                   suffix='hasOsdilep_OutZ_ResolvedJets',
                                   channel='ElMu')
        plots += makeDileptonPlots(self,
                                   sel=hasOsMuElOutZResolvedJets,
                                   dilepton=OsMuEl[0],
                                   suffix='hasOsdilep_OutZ_ResolvedJets',
                                   channel='MuEl')

        # Plot dilepton with OS dilepton, Z peak and Boosted jets selections #
        plots += makeDileptonPlots(self,
                                   sel=hasOsElElOutZBoostedJets,
                                   dilepton=OsElEl[0],
                                   suffix='hasOsdilep_OutZ_BoostedJets',
                                   channel='ElEl')
        plots += makeDileptonPlots(self,
                                   sel=hasOsMuMuOutZBoostedJets,
                                   dilepton=OsMuMu[0],
                                   suffix='hasOsdilep_OutZ_BoostedJets',
                                   channel='MuMu')
        plots += makeDileptonPlots(self,
                                   sel=hasOsElMuOutZBoostedJets,
                                   dilepton=OsElMu[0],
                                   suffix='hasOsdilep_OutZ_BoostedJets',
                                   channel='ElMu')
        plots += makeDileptonPlots(self,
                                   sel=hasOsMuElOutZBoostedJets,
                                   dilepton=OsMuEl[0],
                                   suffix='hasOsdilep_OutZ_BoostedJets',
                                   channel='MuEl')

        # Plotting the fatjet for OS dilepton, Z peak and Boosted jets selections #
        plots += makeFatJetPlots(self,
                                 sel=hasOsElElOutZBoostedJets,
                                 fatjet=bjetsBoosted[0],
                                 suffix="hasOsdilep_OutZ_BoostedJets",
                                 channel="ElEl")
        plots += makeFatJetPlots(self,
                                 sel=hasOsMuMuOutZBoostedJets,
                                 fatjet=bjetsBoosted[0],
                                 suffix="hasOsdilep_OutZ_BoostedJets",
                                 channel="MuMu")
        plots += makeFatJetPlots(self,
                                 sel=hasOsElMuOutZBoostedJets,
                                 fatjet=bjetsBoosted[0],
                                 suffix="hasOsdilep_OutZ_BoostedJets",
                                 channel="ElMu")
        plots += makeFatJetPlots(self,
                                 sel=hasOsMuElOutZBoostedJets,
                                 fatjet=bjetsBoosted[0],
                                 suffix="hasOsdilep_OutZ_BoostedJets",
                                 channel="MuEl")

        # Plotting the jets for OS dilepton, Z peak and Resolved jets selections #
        plots += makeJetsPlots(self,
                               sel=hasOsElElOutZResolvedJets,
                               jets=bjetsResolved,
                               suffix="hasOsdilep_OutZ_ResolvedJets",
                               channel="ElEl")
        plots += makeJetsPlots(self,
                               sel=hasOsMuMuOutZResolvedJets,
                               jets=bjetsResolved,
                               suffix="hasOsdilep_OutZ_ResolvedJets",
                               channel="MuMu")
        plots += makeJetsPlots(self,
                               sel=hasOsElMuOutZResolvedJets,
                               jets=bjetsResolved,
                               suffix="hasOsdilep_OutZ_ResolvedJets",
                               channel="ElMu")
        plots += makeJetsPlots(self,
                               sel=hasOsMuElOutZResolvedJets,
                               jets=bjetsResolved,
                               suffix="hasOsdilep_OutZ_ResolvedJets",
                               channel="MuEl")

        ## helper selection (OR) to make sure jet calculations are only done once
        #hasOSLL = noSel.refine("hasOSLL", cut=op.OR(*( hasOSLL_cmbRng(rng) for rng in osLLRng.values())))
        #forceDefine(t._Jet.calcProd, hasOSLL)
        #for varNm in t._Jet.available:
        #    forceDefine(t._Jet[varNm], hasOSLL)
        return plots
コード例 #26
0
def returnResonantMVAInputs(self, l1, l2, channel, jets, bjets, fatjets, met,
                            electrons, muons):
    if channel == "ElEl":
        l1conept = lambda l1: self.electron_conept[l1.idx]
        l2conept = lambda l2: self.electron_conept[l2.idx]
    elif channel == "MuMu":
        l1conept = lambda l1: self.muon_conept[l1.idx]
        l2conept = lambda l2: self.muon_conept[l2.idx]
    elif channel == "ElMu":
        l1conept = lambda l1: self.electron_conept[l1.idx]
        l2conept = lambda l2: self.muon_conept[l2.idx]
    else:
        raise RuntimeError("Wrong channel")

    dijets = op.combine(jets, N=2)

    import bamboo.treeoperations as _to

    def rng_min(rng, fun=(lambda x: x), typeName="float"):
        return op._to.Reduce.fromRngFun(
            rng, op.c_float(float("+inf"), typeName),
            (lambda fn:
             (lambda res, elm: op.extMethod("std::min", returnType="Float_t")
              (res, fn(elm))))(fun))

    if self.args.era is None:
        era = op.c_int(int(self.era))
    else:
        era = op.c_int(int(self.args.era))
        print(f'Using {self.args.era} as DNN input')

    return {
        ('eventnr', 'Event number', (100, 0., 1e6)):
        self.tree.event,
        ('era', 'Era', (3, 2016., 2019.)):
        era,
        ('l1_E', 'Lead lepton E [GeV]', (50, 0., 500.)):
        op.switch(l1conept(l1) >= l2conept(l2), l1.p4.E(), l2.p4.E()),
        ('l1_Px', 'Lead lepton P_x [GeV]', (40, -200., 200.)):
        op.switch(l1conept(l1) >= l2conept(l2), l1.p4.Px(), l2.p4.Px()),
        ('l1_Py', 'Lead lepton P_y [GeV]', (40, -200., 200.)):
        op.switch(l1conept(l1) >= l2conept(l2), l1.p4.Py(), l2.p4.Py()),
        ('l1_Pz', 'Lead lepton P_z [GeV]', (40, -200., 200.)):
        op.switch(l1conept(l1) >= l2conept(l2), l1.p4.Pz(), l2.p4.Pz()),
        ('l1_charge', 'Lead lepton charge', (2, 0., 2.)):
        op.switch(l1conept(l1) >= l2conept(l2), l1.charge, l2.charge),
        ('l1_pdgId', 'Lead lepton pdg ID', (45, -22., 22.)):
        op.switch(l1conept(l1) >= l2conept(l2), l1.pdgId, l2.pdgId),
        ('l2_E', 'Sublead lepton E [GeV]', (50, 0., 500.)):
        op.switch(l1conept(l1) >= l2conept(l2), l2.p4.E(), l1.p4.E()),
        ('l2_Px', 'Sublead lepton P_x [GeV]', (40, -200., 200.)):
        op.switch(l1conept(l1) >= l2conept(l2), l2.p4.Px(), l1.p4.Px()),
        ('l2_Py', 'Sublead lepton P_y [GeV]', (40, -200., 200.)):
        op.switch(l1conept(l1) >= l2conept(l2), l2.p4.Py(), l1.p4.Py()),
        ('l2_Pz', 'Sublead lepton P_z [GeV]', (40, -200., 200.)):
        op.switch(l1conept(l1) >= l2conept(l2), l2.p4.Pz(), l1.p4.Pz()),
        ('l2_charge', 'Sublead lepton charge', (2, 0., 2.)):
        op.switch(l1conept(l1) >= l2conept(l2), l2.charge, l1.charge),
        ('l2_pdgId', 'Sublead lepton pdg ID', (45, -22., 22.)):
        op.switch(l1conept(l1) >= l2conept(l2), l2.pdgId, l1.pdgId),
        ('j1_E', 'Lead jet E [GeV]', (50, 0., 500.)):
        op.switch(op.rng_len(jets) > 0, jets[0].p4.E(), op.c_float(0.)),
        ('j1_Px', 'Lead jet P_x [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 0, jets[0].p4.Px(), op.c_float(0.)),
        ('j1_Py', 'Lead jet P_y [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 0, jets[0].p4.Py(), op.c_float(0.)),
        ('j1_Pz', 'Lead jet P_z [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 0, jets[0].p4.Pz(), op.c_float(0.)),
        ('j2_E', 'Sublead jet E [GeV]', (50, 0., 500.)):
        op.switch(op.rng_len(jets) > 1, jets[1].p4.E(), op.c_float(0.)),
        ('j2_Px', 'Sublead jet P_x [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 1, jets[1].p4.Px(), op.c_float(0.)),
        ('j2_Py', 'Sublead jet P_y [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 1, jets[1].p4.Py(), op.c_float(0.)),
        ('j2_Pz', 'Sublead jet P_z [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 1, jets[1].p4.Pz(), op.c_float(0.)),
        ('j3_E', 'Subsublead jet E [GeV]', (50, 0., 500.)):
        op.switch(op.rng_len(jets) > 2, jets[2].p4.E(), op.c_float(0.)),
        ('j3_Px', 'Subsublead jet P_x [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 2, jets[2].p4.Px(), op.c_float(0.)),
        ('j3_Py', 'Subsublead jet P_y [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 2, jets[2].p4.Py(), op.c_float(0.)),
        ('j3_Pz', 'Subsublead jet P_z [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 2, jets[2].p4.Pz(), op.c_float(0.)),
        ('j4_E', 'Subsubsublead jet E [GeV]', (50, 0., 500.)):
        op.switch(op.rng_len(jets) > 3, jets[3].p4.E(), op.c_float(0.)),
        ('j4_Px', 'Subsubsublead jet P_x [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 3, jets[3].p4.Px(), op.c_float(0.)),
        ('j4_Py', 'Subsubsublead jet P_y [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 3, jets[3].p4.Py(), op.c_float(0.)),
        ('j4_Pz', 'Subsubsublead jet P_z [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(jets) > 3, jets[3].p4.Pz(), op.c_float(0.)),
        ('fatjet_E', 'Fatjet E [GeV]', (50, 0., 500.)):
        op.switch(op.rng_len(fatjets) > 0, fatjets[0].p4.E(), op.c_float(0.)),
        ('fatjet_Px', 'Fatjet P_x [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(fatjets) > 0, fatjets[0].p4.Px(), op.c_float(0.)),
        ('fatjet_Py', 'Fatjet P_y [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(fatjets) > 0, fatjets[0].p4.Py(), op.c_float(0.)),
        ('fatjet_Pz', 'Fatjet P_z [GeV]', (40, -200., 200.)):
        op.switch(op.rng_len(fatjets) > 0, fatjets[0].p4.Pz(), op.c_float(0.)),
        ('fatjet_tau1', 'Fatjet #tau_1', (50, 0., 1.)):
        op.switch(op.rng_len(fatjets) > 0, fatjets[0].tau1, op.c_float(0.)),
        ('fatjet_tau2', 'Fatjet #tau_2', (50, 0., 1.)):
        op.switch(op.rng_len(fatjets) > 0, fatjets[0].tau2, op.c_float(0.)),
        ('fatjet_tau3', 'Fatjet #tau_3', (50, 0., 1.)):
        op.switch(op.rng_len(fatjets) > 0, fatjets[0].tau3, op.c_float(0.)),
        ('fatjet_tau4', 'Fatjet #tau_4', (50, 0., 1.)):
        op.switch(op.rng_len(fatjets) > 0, fatjets[0].tau4, op.c_float(0.)),
        ('fatjet_softdrop', 'Fatjet softdrop mass [GeV]', (50, 0., 1000.)):
        op.switch(
            op.rng_len(fatjets) > 0, fatjets[0].msoftdrop, op.c_float(0.)),
        ('met_E', 'MET Energy', (50, 0., 500.)):
        met.p4.E(),
        ('met_Px', 'MET P_x', (40, -200., 200.)):
        met.p4.Px(),
        ('met_Py', 'MET P_y', (40, -200., 200.)):
        met.p4.Py(),
        ('met_Pz', 'MET P_z', (40, -200., 200.)):
        met.p4.Pz(),
        ('m_bb_bregcorr', 'Di-bjet invariant mass (regcorr) [GeV]', (100, 0., 1000.)):
        op.multiSwitch(
            (op.rng_len(bjets) == 0, op.c_float(0.)),
            (op.rng_len(bjets) == 1, self.HLL.getCorrBp4(bjets[0]).M()),
            op.invariant_mass(self.HLL.getCorrBp4(bjets[0]),
                              self.HLL.getCorrBp4(bjets[1]))),
        ('ht', 'HT(jets) [GeV]', (100, 0., 1000.)):
        op.rng_sum(jets, lambda j: j.pt),
        ('min_dr_jets_lep1', 'Min(#Delta R(lead lepton,jets))', (25, 0., 5.)):
        op.switch(
            op.rng_len(jets) > 0,
            op.switch(
                l1conept(l1) >= l2conept(l2),
                self.HLL.MinDR_part1_partCont(l1.p4, jets),
                self.HLL.MinDR_part1_partCont(l2.p4, jets)), op.c_float(0.)),
        ('min_dr_jets_lep2', 'Min(#Delta R(sublead lepton,jets))', (25, 0., 5.)):
        op.switch(
            op.rng_len(jets) > 0,
            op.switch(
                l1conept(l1) >= l2conept(l2),
                self.HLL.MinDR_part1_partCont(l2.p4, jets),
                self.HLL.MinDR_part1_partCont(l1.p4, jets)), op.c_float(0.)),
        ('m_ll', 'Dilepton invariant mass [GeV]', (100, 0., 1000.)):
        op.invariant_mass(l1.p4, l2.p4),
        ('dr_ll', 'Dilepton #Delta R', (25, 0., 5.)):
        op.deltaR(l1.p4, l2.p4),
        ('min_dr_jet', 'Min(#Delta R(jets))', (25, 0., 5.)):
        op.switch(
            op.rng_len(dijets) > 0,
            op.rng_min(dijets,
                       lambda dijet: op.deltaR(dijet[0].p4, dijet[1].p4)),
            op.c_float(0.)),
        ('min_dphi_jet', 'Min(#Delta #Phi(jets))', (16, 0., 3.2)):
        op.switch(
            op.rng_len(dijets) > 0,
            rng_min(
                dijets,
                lambda dijet: op.abs(op.deltaPhi(dijet[0].p4, dijet[1].p4)),
                typeName='double'), op.c_float(0.)),
        ('m_hh_simplemet_bregcorr', 'M_{HH} (simple MET) (regcorr) [GeV]', (100, 0., 1000.)):
        op.invariant_mass(
            op.rng_sum(bjets,
                       lambda bjet: self.HLL.getCorrBp4(bjet),
                       start=self.HLL.empty_p4), l1.p4, l2.p4, met.p4),
        ('met_ld', 'MET_{LD}', (100, 0., 1000.)):
        self.HLL.MET_LD_DL(met, jets, electrons, muons),
        ('dr_bb', 'Di-bjet #Delta R', (25, 0., 5.)):
        op.switch(
            op.rng_len(bjets) >= 2, op.deltaR(bjets[0].p4, bjets[1].p4),
            op.c_float(0.)),
        ('min_dr_leps_b1', 'Min(#Delta R(lead bjet,dilepton))', (25, 0., 5.)):
        op.switch(
            op.rng_len(bjets) >= 1,
            self.HLL.MinDR_part1_dipart(bjets[0].p4, [l1.p4, l2.p4]),
            op.c_float(0.)),
        ('min_dr_leps_b2', 'Min(#Delta R(sublead bjet,dilepton))', (25, 0., 5.)):
        op.switch(
            op.rng_len(bjets) >= 2,
            self.HLL.MinDR_part1_dipart(bjets[1].p4, [l1.p4, l2.p4]),
            op.c_float(0.)),
        ('lep1_conept', 'Lead lepton cone-P_T [GeV]', (40, 0., 200.)):
        op.switch(l1conept(l1) >= l2conept(l2), l1conept(l1), l2conept(l2)),
        ('lep2_conept', 'Sublead lepton cone-P_T [GeV]', (40, 0., 200.)):
        op.switch(l1conept(l1) >= l2conept(l2), l2conept(l2), l1conept(l1)),
        ('mww_simplemet', 'M_{WW} (simple MET) [GeV]', (100, 0., 1000.)):
        op.invariant_mass(l1.p4, l2.p4, met.p4),
        ('boosted_tag', 'Boosted tag', (2, 0., 2.)):
        op.c_int(
            op.OR(
                op.rng_len(self.ak8BJets) > 0,  # Boosted 1B
                op.AND(
                    op.rng_len(self.ak8BJets) == 0,  # Boosted 0B
                    op.rng_len(self.ak8Jets) > 0,
                    op.rng_len(self.ak4BJets) == 0))),
        ('dphi_met_dilep', 'Dilepton-MET #Delta #Phi', (32, -3.2, 3.2)):
        op.abs(op.deltaPhi(met.p4, (l1.p4 + l2.p4))),
        ('dphi_met_dibjet', 'Dibjet-MET #Delta #Phi', (32, -3.2, 3.2)):
        op.multiSwitch(
            (op.rng_len(bjets) == 0, op.c_float(0.)),
            (op.rng_len(bjets) == 1, op.abs(op.deltaPhi(met.p4, bjets[0].p4))),
            op.abs(op.deltaPhi(met.p4, (bjets[0].p4 + bjets[1].p4)))),
        ('dr_dilep_dijet', 'Dilepton-dijet #Delta R', (25, 0., 5.)):
        op.multiSwitch(
            (op.rng_len(jets) == 0, op.c_float(0.)),
            (op.rng_len(jets) == 1, op.deltaR((l1.p4 + l2.p4), jets[0].p4)),
            op.deltaR((l1.p4 + l2.p4), (jets[0].p4 + jets[1].p4))),
        ('dr_dilep_dibjet', 'Dilepton-dibjet #Delta R', (25, 0., 5.)):
        op.multiSwitch(
            (op.rng_len(bjets) == 0, op.c_float(0.)),
            (op.rng_len(bjets) == 1, op.deltaR((l1.p4 + l2.p4), bjets[0].p4)),
            op.deltaR((l1.p4 + l2.p4), (bjets[0].p4 + bjets[1].p4))),
        ('m_T', 'Transverse mass', (100, 0., 1000.)):
        op.sqrt(2 * (l1.p4 + l2.p4).Pt() * met.p4.E() *
                (1 - op.cos((l1.p4 + l2.p4).Phi() - met.p4.Phi()))),
        ('cosThetaS_Hbb', 'Helicity angle between Hbb and bjet', (20, 0., 1.)):
        op.switch(
            op.rng_len(bjets) == 2,
            op.extMethod("HHbbWWJPA::cosThetaS",
                         returnType="float")(bjets[0].p4, bjets[1].p4),
            op.c_float(0.)),
        ('LBN_inputs', 'LBN inputs', None): [
            op.switch(l1conept(l1) >= l2conept(l2), l1.p4.E(), l2.p4.E()),
            op.switch(l1conept(l1) >= l2conept(l2), l1.p4.Px(), l2.p4.Px()),
            op.switch(l1conept(l1) >= l2conept(l2), l1.p4.Py(), l2.p4.Py()),
            op.switch(l1conept(l1) >= l2conept(l2), l1.p4.Pz(), l2.p4.Pz()),
            op.switch(l1conept(l1) >= l2conept(l2), l2.p4.E(), l1.p4.E()),
            op.switch(l1conept(l1) >= l2conept(l2), l2.p4.Px(), l1.p4.Px()),
            op.switch(l1conept(l1) >= l2conept(l2), l2.p4.Py(), l1.p4.Py()),
            op.switch(l1conept(l1) >= l2conept(l2), l2.p4.Pz(), l1.p4.Pz()),
            op.switch(op.rng_len(jets) > 0, jets[0].p4.E(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 0, jets[0].p4.Px(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 0, jets[0].p4.Py(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 0, jets[0].p4.Pz(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 1, jets[1].p4.E(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 1, jets[1].p4.Px(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 1, jets[1].p4.Py(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 1, jets[1].p4.Pz(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 2, jets[2].p4.E(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 2, jets[2].p4.Px(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 2, jets[2].p4.Py(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 2, jets[2].p4.Pz(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 3, jets[3].p4.E(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 3, jets[3].p4.Px(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 3, jets[3].p4.Py(), op.c_float(0.)),
            op.switch(op.rng_len(jets) > 3, jets[3].p4.Pz(), op.c_float(0.)),
            op.switch(
                op.rng_len(fatjets) > 0, fatjets[0].p4.E(), op.c_float(0.)),
            op.switch(
                op.rng_len(fatjets) > 0, fatjets[0].p4.Px(), op.c_float(0.)),
            op.switch(
                op.rng_len(fatjets) > 0, fatjets[0].p4.Py(), op.c_float(0.)),
            op.switch(
                op.rng_len(fatjets) > 0, fatjets[0].p4.Pz(), op.c_float(0.))
        ]
    }
コード例 #27
0
    def definePlots(self, t, noSel, sample=None, sampleCfg=None):
        from bamboo.plots import Plot, CutFlowReport, EquidistantBinning, VariableBinning
        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))

        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))))

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

        cleanedGoodJets30_1_5to3 = op.select(
            cleanedJets, lambda j: op.AND(
                j.pt > 30,
                op.NOT(op.AND(op.abs(j.eta) < 1.5,
                              op.abs(j.eta) > 3))))

        cleanedGoodJets30_3toInf = op.select(
            cleanedJets, lambda j: op.AND(j.pt > 30,
                                          op.abs(j.eta) > 3))

        cleanedGoodJets50_0to1_5 = op.select(
            cleanedJets, lambda j: op.AND(j.pt > 50,
                                          op.abs(j.eta) < 1.5))

        cleanedGoodJets50_1_5to3 = op.select(
            cleanedJets, lambda j: op.AND(
                j.pt > 50,
                op.NOT(op.AND(op.abs(j.eta) < 1.5,
                              op.abs(j.eta) > 3))))

        cleanedGoodJets50_3toInf = op.select(
            cleanedJets, lambda j: op.AND(j.pt > 50,
                                          op.abs(j.eta) > 3))

        cleanedGoodJets100_0to1_5 = op.select(
            cleanedJets, lambda j: op.AND(j.pt > 100,
                                          op.abs(j.eta) < 1.5))

        cleanedGoodJets100_1_5to3 = op.select(
            cleanedJets, lambda j: op.AND(
                j.pt > 100,
                op.NOT(op.AND(op.abs(j.eta) < 1.5,
                              op.abs(j.eta) > 3))))

        cleanedGoodJets100_3toInf = op.select(
            cleanedJets, lambda j: op.AND(j.pt > 100,
                                          op.abs(j.eta) > 3))

        cleanedGoodJets30 = op.select(cleanedJets, lambda j: j.pt > 30)

        cleanedGoodJets50 = op.select(cleanedJets, lambda j: j.pt > 50)

        cleanedGoodJets100 = op.select(cleanedJets, lambda j: j.pt > 100)

        met = op.select(t.metpuppi)

        sel1 = noSel.refine("nJet30", cut=[op.rng_len(cleanedGoodJets30) > 0])
        sel2 = noSel.refine("nJet50", cut=[op.rng_len(cleanedGoodJets50) > 0])
        sel3 = noSel.refine("nJet100",
                            cut=[op.rng_len(cleanedGoodJets100) > 0])

        sel1_1 = noSel.refine("nJet30_1",
                              cut=[op.rng_len(cleanedGoodJets30) > 0])
        sel1_1_1 = noSel.refine("nJet30_1_1",
                                cut=[op.rng_len(cleanedGoodJets30_0to1_5) > 0])
        sel1_1_2 = noSel.refine("nJet30_1_2",
                                cut=[op.rng_len(cleanedGoodJets30_1_5to3) > 0])
        sel1_1_3 = noSel.refine("nJet30_1_3",
                                cut=[op.rng_len(cleanedGoodJets30_3toInf) > 0])
        sel2_1 = noSel.refine("nJet50_1",
                              cut=[op.rng_len(cleanedGoodJets50) > 0])
        sel1_2_1 = noSel.refine("nJet50_1_1",
                                cut=[op.rng_len(cleanedGoodJets50_0to1_5) > 0])
        sel1_2_2 = noSel.refine("nJet50_1_2",
                                cut=[op.rng_len(cleanedGoodJets50_1_5to3) > 0])
        sel1_2_3 = noSel.refine("nJet50_1_3",
                                cut=[op.rng_len(cleanedGoodJets50_3toInf) > 0])
        sel3_1 = noSel.refine("nJet100_1",
                              cut=[op.rng_len(cleanedGoodJets100) > 0])
        sel1_3_1 = noSel.refine(
            "nJet100_1_1", cut=[op.rng_len(cleanedGoodJets100_0to1_5) > 0])
        sel1_3_2 = noSel.refine(
            "nJet100_1_2", cut=[op.rng_len(cleanedGoodJets100_1_5to3) > 0])
        sel1_3_3 = noSel.refine(
            "nJet100_1_3", cut=[op.rng_len(cleanedGoodJets100_3toInf) > 0])

        sel1_2 = noSel.refine("nJet30_2",
                              cut=[op.rng_len(cleanedGoodJets30) > 1])
        sel2_1_1 = noSel.refine("nJet30_2_1",
                                cut=[op.rng_len(cleanedGoodJets30_0to1_5) > 1])
        sel2_1_2 = noSel.refine("nJet30_2_2",
                                cut=[op.rng_len(cleanedGoodJets30_1_5to3) > 1])
        sel2_1_3 = noSel.refine("nJet30_2_3",
                                cut=[op.rng_len(cleanedGoodJets30_3toInf) > 1])
        sel2_2 = noSel.refine("nJet50_2",
                              cut=[op.rng_len(cleanedGoodJets50) > 1])
        sel2_2_1 = noSel.refine("nJet50_2_1",
                                cut=[op.rng_len(cleanedGoodJets50_0to1_5) > 1])
        sel2_2_2 = noSel.refine("nJet50_2_2",
                                cut=[op.rng_len(cleanedGoodJets50_1_5to3) > 1])
        sel2_2_3 = noSel.refine("nJet50_2_3",
                                cut=[op.rng_len(cleanedGoodJets50_3toInf) > 1])
        sel3_2 = noSel.refine("nJet100_2",
                              cut=[op.rng_len(cleanedGoodJets100) > 1])
        sel2_3_1 = noSel.refine(
            "nJet100_2_1", cut=[op.rng_len(cleanedGoodJets100_0to1_5) > 1])
        sel2_3_2 = noSel.refine(
            "nJet100_2_2", cut=[op.rng_len(cleanedGoodJets100_1_5to3) > 1])
        sel2_3_3 = noSel.refine(
            "nJet100_2_3", cut=[op.rng_len(cleanedGoodJets100_3toInf) > 1])

        sel1_3 = noSel.refine("nJet30_3",
                              cut=[op.rng_len(cleanedGoodJets30) > 2])
        sel3_1_1 = noSel.refine("nJet30_3_1",
                                cut=[op.rng_len(cleanedGoodJets30_0to1_5) > 2])
        sel3_1_2 = noSel.refine("nJet30_3_2",
                                cut=[op.rng_len(cleanedGoodJets30_1_5to3) > 2])
        sel3_1_3 = noSel.refine("nJet30_3_3",
                                cut=[op.rng_len(cleanedGoodJets30_3toInf) > 2])
        sel2_3 = noSel.refine("nJet50_3",
                              cut=[op.rng_len(cleanedGoodJets50) > 2])
        sel3_2_1 = noSel.refine("nJet50_3_1",
                                cut=[op.rng_len(cleanedGoodJets50_0to1_5) > 2])
        sel3_2_2 = noSel.refine("nJet50_3_2",
                                cut=[op.rng_len(cleanedGoodJets50_1_5to3) > 2])
        sel3_2_3 = noSel.refine("nJet50_3_3",
                                cut=[op.rng_len(cleanedGoodJets50_3toInf) > 2])
        sel3_3 = noSel.refine("nJet100_3",
                              cut=[op.rng_len(cleanedGoodJets100) > 2])
        sel3_3_1 = noSel.refine(
            "nJet100_3_1", cut=[op.rng_len(cleanedGoodJets100_0to1_5) > 2])
        sel3_3_2 = noSel.refine(
            "nJet100_3_2", cut=[op.rng_len(cleanedGoodJets100_1_5to3) > 2])
        sel3_3_3 = noSel.refine(
            "nJet100_3_3", cut=[op.rng_len(cleanedGoodJets100_3toInf) > 2])

        sel1_4 = noSel.refine("nJet30_4",
                              cut=[op.rng_len(cleanedGoodJets30) > 3])
        sel4_1_1 = noSel.refine("nJet30_4_1",
                                cut=[op.rng_len(cleanedGoodJets30_0to1_5) > 3])
        sel4_1_2 = noSel.refine("nJet30_4_2",
                                cut=[op.rng_len(cleanedGoodJets30_1_5to3) > 3])
        sel4_1_3 = noSel.refine("nJet30_4_3",
                                cut=[op.rng_len(cleanedGoodJets30_3toInf) > 3])
        sel2_4 = noSel.refine("nJet50_4",
                              cut=[op.rng_len(cleanedGoodJets50) > 3])
        sel4_2_1 = noSel.refine("nJet50_4_1",
                                cut=[op.rng_len(cleanedGoodJets50_0to1_5) > 3])
        sel4_2_2 = noSel.refine("nJet50_4_2",
                                cut=[op.rng_len(cleanedGoodJets50_1_5to3) > 3])
        sel4_2_3 = noSel.refine("nJet50_4_3",
                                cut=[op.rng_len(cleanedGoodJets50_3toInf) > 3])
        sel3_4 = noSel.refine("nJet100_4",
                              cut=[op.rng_len(cleanedGoodJets100) > 3])
        sel4_3_1 = noSel.refine(
            "nJet100_4_1", cut=[op.rng_len(cleanedGoodJets100_0to1_5) > 3])
        sel4_3_2 = noSel.refine(
            "nJet100_4_2", cut=[op.rng_len(cleanedGoodJets100_1_5to3) > 3])
        sel4_3_3 = noSel.refine(
            "nJet100_4_3", cut=[op.rng_len(cleanedGoodJets100_3toInf) > 3])

        # plots

        #     # ### 30 GeV

        plots.append(
            Plot.make1D("nJets_jetPT_30GeV",
                        op.rng_len(cleanedGoodJets30),
                        noSel,
                        EquidistantBinning(15, 0., 15.),
                        title="nJets (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_jetPT_30GeV",
                        cleanedGoodJets30[0].pt,
                        sel1_1,
                        EquidistantBinning(50, 0., 4000.),
                        title="Jet1_pT (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet1_eta_jetPT_30GeV",
                        cleanedGoodJets30[0].eta,
                        sel1_1,
                        EquidistantBinning(30, -3, 3),
                        title="Jet1_eta (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_0to1_5_jetPT_30GeV",
                        cleanedGoodJets30_0to1_5[0].pt,
                        sel1_1_1,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet1_pT 0 < eta < 1.5, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_1_5to3_jetPT_30GeV",
                        cleanedGoodJets30_1_5to3[0].pt,
                        sel1_1_2,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet1_pT 1.5 < eta < 3, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_3toInf_jetPT_30GeV",
                        cleanedGoodJets30_3toInf[0].pt,
                        sel1_1_3,
                        EquidistantBinning(50, 0, 1000),
                        title="Jet1_pT eta > 3, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_jetPT_30GeV",
                        cleanedGoodJets30[1].pt,
                        sel1_2,
                        EquidistantBinning(50, 0., 4000.),
                        title="Jet2_pT (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet2_eta_jetPT_30GeV",
                        cleanedGoodJets30[1].eta,
                        sel1_2,
                        EquidistantBinning(30, -3, 3),
                        title="Jet2_eta (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_0to1_5_jetPT_30GeV",
                        cleanedGoodJets30_0to1_5[1].pt,
                        sel2_1_1,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet2_pT 0 < eta < 1.5, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_1_5to3_jetPT_30GeV",
                        cleanedGoodJets30_1_5to3[1].pt,
                        sel2_1_2,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet2_pT 1.5 < eta < 3, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_3toInf_jetPT_30GeV",
                        cleanedGoodJets30_3toInf[1].pt,
                        sel2_1_3,
                        EquidistantBinning(50, 0, 500),
                        title="Jet2_pT eta > 3, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_jetPT_30GeV",
                        cleanedGoodJets30[2].pt,
                        sel1_3,
                        EquidistantBinning(50, 0., 2000.),
                        title="Jet3_pT (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet3_eta_jetPT_30GeV",
                        cleanedGoodJets30[2].eta,
                        sel1_3,
                        EquidistantBinning(30, -3, 3),
                        title="Jet3_eta (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_0to1_5_jetPT_30GeV",
                        cleanedGoodJets30_0to1_5[2].pt,
                        sel3_1_1,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet3_pT 0 < eta < 1.5, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_1_5to3_jetPT_30GeV",
                        cleanedGoodJets30_1_5to3[2].pt,
                        sel3_1_2,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet3_pT 1.5 < eta < 3, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_3toInf_jetPT_30GeV",
                        cleanedGoodJets30_3toInf[2].pt,
                        sel3_1_3,
                        EquidistantBinning(50, 0, 200),
                        title="Jet3_pT eta > 3, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_jetPT_30GeV",
                        cleanedGoodJets30[3].pt,
                        sel1_4,
                        EquidistantBinning(50, 0., 2000.),
                        title="Jet4_pT (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet4_eta_jetPT_30GeV",
                        cleanedGoodJets30[3].eta,
                        sel1_4,
                        EquidistantBinning(30, -3, 3),
                        title="Jet4_eta (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_0to1_5_jetPT_30GeV",
                        cleanedGoodJets30_0to1_5[3].pt,
                        sel4_1_1,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet4_pT 0 < eta < 1.5, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_1_5to3_jetPT_30GeV",
                        cleanedGoodJets30_1_5to3[3].pt,
                        sel4_1_2,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet4_pT 1.5 < eta < 3, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_3toInf_jetPT_30GeV",
                        cleanedGoodJets30_3toInf[3].pt,
                        sel4_1_3,
                        EquidistantBinning(50, 0, 200),
                        title="Jet4_pT eta > 3, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("MET_jetPT_30GeV",
                        met[0].pt,
                        sel1,
                        EquidistantBinning(50, 0, 1000),
                        title="MET (jet p_{T} > 30GeV)"))

        #     # ### 50 GeV

        plots.append(
            Plot.make1D("nJets_jetPT_50GeV",
                        op.rng_len(cleanedGoodJets50),
                        noSel,
                        EquidistantBinning(15, 0., 15.),
                        title="nJets (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_jetPT_50GeV",
                        cleanedGoodJets50[0].pt,
                        sel2_1,
                        EquidistantBinning(50, 0., 4000.),
                        title="Jet1_pT (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet1_eta_jetPT_50GeV",
                        cleanedGoodJets50[0].eta,
                        sel2_1,
                        EquidistantBinning(30, -3, 3),
                        title="Jet1_eta (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_0to1_5_jetPT_50GeV",
                        cleanedGoodJets50_0to1_5[0].pt,
                        sel1_2_1,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet1_pT 0 < eta < 1.5, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_1_5to3_jetPT_50GeV",
                        cleanedGoodJets50_1_5to3[0].pt,
                        sel1_2_2,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet1_pT 1.5 < eta < 3, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_3toInf_jetPT_50GeV",
                        cleanedGoodJets50_3toInf[0].pt,
                        sel1_2_3,
                        EquidistantBinning(50, 0, 1000),
                        title="Jet1_pT eta > 3, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_jetPT_50GeV",
                        cleanedGoodJets50[1].pt,
                        sel2_2,
                        EquidistantBinning(50, 0., 4000.),
                        title="Jet2_pT (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet2_eta_jetPT_50GeV",
                        cleanedGoodJets50[1].eta,
                        sel2_2,
                        EquidistantBinning(30, -3, 3),
                        title="Jet2_eta (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_0to1_5_jetPT_50GeV",
                        cleanedGoodJets50_0to1_5[1].pt,
                        sel2_2_1,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet2_pT 0 < eta < 1.5, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_1_5to3_jetPT_50GeV",
                        cleanedGoodJets50_1_5to3[1].pt,
                        sel2_2_2,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet2_pT 1.5 < eta < 3, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_3toInf_jetPT_50GeV",
                        cleanedGoodJets50_3toInf[1].pt,
                        sel2_2_3,
                        EquidistantBinning(50, 0, 500),
                        title="Jet2_pT eta > 3, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_jetPT_50GeV",
                        cleanedGoodJets50[2].pt,
                        sel2_3,
                        EquidistantBinning(50, 0., 2000.),
                        title="Jet3_pT (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet3_eta_jetPT_50GeV",
                        cleanedGoodJets50[2].eta,
                        sel2_3,
                        EquidistantBinning(30, -3, 3),
                        title="Jet3_eta (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_0to1_5_jetPT_50GeV",
                        cleanedGoodJets50_0to1_5[2].pt,
                        sel3_2_1,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet3_pT 0 < eta < 1.5, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_1_5to3_jetPT_50GeV",
                        cleanedGoodJets50_1_5to3[2].pt,
                        sel3_2_2,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet3_pT 1.5 < eta < 3, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_3toInf_jetPT_50GeV",
                        cleanedGoodJets50_3toInf[2].pt,
                        sel3_2_3,
                        EquidistantBinning(50, 0, 200),
                        title="Jet3_pT eta > 3, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_jetPT_50GeV",
                        cleanedGoodJets50[3].pt,
                        sel2_4,
                        EquidistantBinning(50, 0., 2000.),
                        title="Jet4_pT (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet4_eta_jetPT_50GeV",
                        cleanedGoodJets50[3].eta,
                        sel2_4,
                        EquidistantBinning(30, -3, 3),
                        title="Jet4_eta (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_0to1_5_jetPT_50GeV",
                        cleanedGoodJets50_0to1_5[3].pt,
                        sel4_2_1,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet4_pT 0 < eta < 1.5, (jet p_{T} > 30GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_1_5to3_jetPT_50GeV",
                        cleanedGoodJets50_1_5to3[3].pt,
                        sel4_2_2,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet4_pT 1.5 < eta < 3, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_3toInf_jetPT_50GeV",
                        cleanedGoodJets50_3toInf[3].pt,
                        sel4_2_3,
                        EquidistantBinning(50, 0, 200),
                        title="Jet4_pT eta > 3, (jet p_{T} > 50GeV)"))

        plots.append(
            Plot.make1D("MET_jetPT_50GeV",
                        met[0].pt,
                        sel2,
                        EquidistantBinning(50, 0, 1000),
                        title="MET (jet p_{T} > 50GeV)"))

        #  ### 100 GeV

        plots.append(
            Plot.make1D("nJets_jetPT_100GeV",
                        op.rng_len(cleanedGoodJets100),
                        noSel,
                        EquidistantBinning(15, 0., 15.),
                        title="nJets (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_jetPT_100GeV",
                        cleanedGoodJets100[0].pt,
                        sel3_1,
                        EquidistantBinning(50, 0., 4000.),
                        title="Jet1_pT (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet1_eta_jetPT_100GeV",
                        cleanedGoodJets100[0].eta,
                        sel3_1,
                        EquidistantBinning(30, -3, 3),
                        title="Jet1_eta (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_0to1_5_jetPT_100GeV",
                        cleanedGoodJets100_0to1_5[0].pt,
                        sel1_3_1,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet1_pT 0 < eta < 1.5, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_1_5to3_jetPT_100GeV",
                        cleanedGoodJets100_1_5to3[0].pt,
                        sel1_3_2,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet1_pT 1.5 < eta < 3, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet1_pT_3toInf_jetPT_100GeV",
                        cleanedGoodJets100_3toInf[0].pt,
                        sel1_3_3,
                        EquidistantBinning(50, 0, 1000),
                        title="Jet1_pT eta > 3, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_jetPT_100GeV",
                        cleanedGoodJets100[1].pt,
                        sel3_2,
                        EquidistantBinning(50, 0., 4000.),
                        title="Jet2_pT (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet2_eta_jetPT_100GeV",
                        cleanedGoodJets100[1].eta,
                        sel3_2,
                        EquidistantBinning(30, -3, 3),
                        title="Jet2_eta (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_0to1_5_jetPT_100GeV",
                        cleanedGoodJets100_0to1_5[1].pt,
                        sel2_3_1,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet2_pT 0 < eta < 1.5, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_1_5to3_jetPT_100GeV",
                        cleanedGoodJets100_1_5to3[1].pt,
                        sel2_3_2,
                        EquidistantBinning(50, 0, 4000),
                        title="Jet2_pT 1.5 < eta < 3, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet2_pT_3toInf_jetPT_100GeV",
                        cleanedGoodJets100_3toInf[1].pt,
                        sel2_3_3,
                        EquidistantBinning(50, 0, 500),
                        title="Jet2_pT eta > 3, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_jetPT_100GeV",
                        cleanedGoodJets100[2].pt,
                        sel3_3,
                        EquidistantBinning(50, 0., 2000.),
                        title="Jet3_pT (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet3_eta_jetPT_100GeV",
                        cleanedGoodJets100[2].eta,
                        sel3_3,
                        EquidistantBinning(30, -3, 3),
                        title="Jet3_eta (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_0to1_5_jetPT_100GeV",
                        cleanedGoodJets100_0to1_5[2].pt,
                        sel3_3_1,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet3_pT 0 < eta < 1.5, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_1_5to3_jetPT_100GeV",
                        cleanedGoodJets100_1_5to3[2].pt,
                        sel3_3_2,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet3_pT 1.5 < eta < 3, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet3_pT_3toInf_jetPT_100GeV",
                        cleanedGoodJets100_3toInf[2].pt,
                        sel3_3_3,
                        EquidistantBinning(50, 0, 200),
                        title="Jet3_pT eta > 3, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_jetPT_100GeV",
                        cleanedGoodJets100[3].pt,
                        sel3_4,
                        EquidistantBinning(50, 0., 2000.),
                        title="Jet4_pT (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet4_eta_jetPT_100GeV",
                        cleanedGoodJets100[3].eta,
                        sel3_4,
                        EquidistantBinning(30, -3, 3),
                        title="Jet4_eta (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_0to1_5_jetPT_100GeV",
                        cleanedGoodJets100_0to1_5[3].pt,
                        sel4_3_1,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet4_pT 0 < eta < 1.5, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_1_5to3_jetPT_100GeV",
                        cleanedGoodJets100_1_5to3[3].pt,
                        sel4_3_2,
                        EquidistantBinning(50, 0, 2000),
                        title="Jet4_pT 1.5 < eta < 3, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("Jet4_pT_3toInf_jetPT_100GeV",
                        cleanedGoodJets100_3toInf[3].pt,
                        sel4_3_3,
                        EquidistantBinning(50, 0, 200),
                        title="Jet4_pT eta > 3, (jet p_{T} > 100GeV)"))

        plots.append(
            Plot.make1D("MET_jetPT_100GeV",
                        met[0].pt,
                        sel3,
                        EquidistantBinning(50, 0, 1000),
                        title="MET (jet p_{T} > 100GeV)"))

        # Efficiency Report on terminal and the .tex output

        cfr = CutFlowReport("yields")
        cfr.add(noSel, "None")
        cfr.add(sel1, "30GeV")
        cfr.add(sel2, "50GeV")
        cfr.add(sel3, "100GeV")

        plots.append(cfr)

        return plots
コード例 #28
0
    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
コード例 #29
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
コード例 #30
0
ファイル: JPA.py プロジェクト: gsaha009/HHbbWWAnalysis
def findJPACategoryResolved (self, selObj, lepton, muons, electrons, jets, bJetsL, bJetsM, met, modelPathDict, event, HLL, nodeList, plot_yield=False):
    JPAfuncDict = {'f1':evaluateJPA_2b2Wj, 
                   'f2':evaluateJPA_2b1Wj, 
                   'f3':evaluateJPA_1b2Wj, 
                   'f4':evaluateJPA_2b0Wj, 
                   'f5':evaluateJPA_1b1Wj, 
                   'f6':evaluateJPA_1b0Wj}

    JPAMaxScoreList = []
    bestCombo_per_cat = []
    
    combo2_1b0W_1Wj = op.combine(jets, N=2, samePred=lambda j1,j2 : j1.idx != j2.idx)
    combo2_2b0Wj    = op.combine(jets, N=2, pred=lambda j1,j2 : j1.pt > j2.pt,  samePred=lambda j1,j2 : j1.idx != j2.idx)
    combo3_1b2Wj    = op.combine(jets, N=3, pred=lambda j1,j2,j3 : j2.pt > j3.pt,  samePred=lambda j1,j2 : j1.idx != j2.idx)
    combo3_2b1Wj    = op.combine(jets, N=3, pred=lambda j1,j2,j3 : j1.pt > j2.pt,  samePred=lambda j1,j2 : j1.idx != j2.idx)
    combo4          = op.combine(jets, N=4, pred=lambda j1,j2,j3,j4 : op.AND(j1.pt > j2.pt, j3.pt > j4.pt), samePred=lambda j1,j2 : j1.idx != j2.idx)

    funckeys = [k for k in JPAfuncDict.keys()]
    
    for idx, func in enumerate(funckeys):
        node        = nodeList[idx]
        modelpaths  = modelPathDict.get(node)
        model = makeOddEvenEvaluator(event%2, modelpaths[1], modelpaths[0], mvaType="TMVA")
        lambdaFunc = lambda jetCombo : JPAfuncDict[func](lepton, muons, electrons, jets, jetCombo, bJetsL, bJetsM, met, model, HLL)
        
        if idx == 0:
            best = op.rng_max_element_by(combo4, lambdaFunc)
            maxScore = op.switch(best.idx != -1, best.idx.op.this.result.second, op.c_float(-1.)) 
            #best.idx.op.this.canDefine=False
        elif idx == 1:
            best = op.rng_max_element_by(combo3_2b1Wj, lambdaFunc)            ## hack: index of best is first in a pair, with the maximum value as second
            maxScore = best.idx.op.this.result.second
        elif idx == 2:
            best = op.rng_max_element_by(combo3_1b2Wj, lambdaFunc)            ## hack: index of best is first in a pair, with the maximum value as second
            maxScore = best.idx.op.this.result.second
        elif idx == 3:
            best = op.rng_max_element_by(combo2_2b0Wj, lambdaFunc)            ## hack: index of best is first in a pair, with the maximum value as second
            maxScore = best.idx.op.this.result.second
        elif idx == 4:
            best = op.rng_max_element_by(combo2_1b0W_1Wj, lambdaFunc)            ## hack: index of best is first in a pair, with the maximum value as second
            maxScore = best.idx.op.this.result.second
        else:
            best = op.rng_max_element_by(combo2_1b0W_1Wj, lambdaFunc)            ## hack: index of best is first in a pair, with the maximum value as second
            maxScore = best.idx.op.this.result.second
            
        JPAMaxScoreList.append(op.pow((1.0 + op.sqrt((1 - maxScore)/(1 + maxScore))), -1))
        #JPAMaxScoreList.append(maxScore)
        bestCombo_per_cat.append(best)

    evtCat = makeOddEvenEvaluator(event%2, modelPathDict.get('evCat')[1], modelPathDict.get('evCat')[0], mvaType="TMVA")
    
    evtCatOutList = evtCat(*JPAMaxScoreList)
    maxIdx = op.rng_max_element_index(evtCatOutList)

    newSelObj  = copy(selObj)
    selObjJPAjetsIdxDict = {}

    for i, node in enumerate(nodeList):
        outSelObj = copy(newSelObj)
        outSelObj.selName += '%s'%node
        outSelObj.yieldTitle += " in %s node"%node 
        outSelObj.refine(cut = (maxIdx == i)) 
        if i < 6:
            selObjJPAjetsIdxDict[node] = [outSelObj, bestCombo_per_cat[i]]
        else:
            selObjJPAjetsIdxDict[node] = [outSelObj, None]

    return JPAMaxScoreList, evtCatOutList, selObjJPAjetsIdxDict