示例#1
0
def plot(sampleset,
         channel,
         parallel=True,
         tag="",
         outdir="plots",
         histdir="",
         era=""):
    """Test plotting of SampleSet class for data/MC comparison."""
    LOG.header("plot")

    # SELECTIONS
    inclusive = "(q_1*q_2<0)"
    inclusive = inclusive.replace(" ", "")
    inclusive_cr_qcd = inclusive.replace(
        "q_1*q_2<0", "q_1*q_2>0"
    )  # inverting the opposite-sign requirement of the mutau pair into a same-sign requirment
    selections = [
        Sel('inclusive', inclusive),
        Sel('inclusive_cr_qcd', inclusive_cr_qcd),
    ]

    # VARIABLES
    # TODO section 5: extend with other variables, which are available in the flat n-tuples
    variables = [
        Var('m_vis', 40, 0, 200),
    ]

    # PLOT and HIST
    outdir = ensuredir(repkey(outdir, CHANNEL=channel, ERA=era))
    histdir = ensuredir(repkey(histdir, CHANNEL=channel, ERA=era))
    outhists = R.TFile.Open(histdir, 'recreate')
    exts = ['png', 'pdf']
    for selection in selections:
        outhists.mkdir(selection.filename)
        stacks = sampleset.getstack(
            variables,
            selection,
            method='QCD_OSSS',
            scale=1.1,
            parallel=parallel
        )  # the 'scale' keyword argument - chosen as 1.1 for mutau -
        # is an extrapolation factor for the QCD shape from the same-sign
        # to the opposite-sign region
        fname = "%s/$VAR_%s-%s-%s$TAG" % (outdir, channel, selection.filename,
                                          era)
        text = "%s: %s" % (channel.replace('mu', "#mu").replace(
            'tau', "#tau_{h}"), selection.title)
        for stack, variable in stacks.iteritems():
            outhists.cd(selection.filename)
            for h in stack.hists:
                h.Write(h.GetName().replace("QCD_", "QCD"), R.TH1.kOverwrite)
            stack.draw()
            stack.drawlegend(x1=0.6, x2=0.95, y1=0.35, y2=0.95)
            stack.drawtext(text)
            stack.saveas(fname, ext=exts, tag=tag)
            stack.close()
    outhists.Close()
示例#2
0
def plot(sampleset,
         channel,
         parallel=True,
         tag="",
         outdir="plots",
         histdir="",
         era=""):
    """Test plotting of SampleSet class for data/MC comparison."""
    LOG.header("plot")

    # SELECTIONS
    inclusive = "(q_1*q_2<0)"
    inclusive = inclusive.replace(" ", "")
    inclusive_cr_qcd = inclusive.replace(
        "q_1*q_2<0", "q_1*q_2>0"
    )  # inverting the opposite-sign requirement of the mutau pair into a same-sign requirment
    general_cuts = "(pt_1>26.0)&&(pt_2>20.0)&&(eta_1>-2.1)&&(eta_1<2.1)&&(eta_2>-2.3)&&(eta_2<2.3)"
    selections = [
        Sel('kinematic sel.', general_cuts),
        #Sel('inclusive',inclusive),
        #Sel('inclusive_cr_qcd',inclusive_cr_qcd),
    ]

    # VARIABLES
    # TODO section 5: extend with other variables, which are available in the flat n-tuples
    variables = [
        Var('m_vis', 40, 0, 200),
        Var('pt_1',
            "Muon pt",
            40,
            0,
            120,
            ctitle={
                'etau': "Electron pt",
                'tautau': "Leading tau_h pt",
                'emu': "Electron pt"
            }),
        Var('pt_2',
            "tau_h pt",
            40,
            0,
            120,
            ctitle={
                'tautau': "Subleading tau_h pt",
                'emu': "Muon pt"
            }),
        Var('eta_1',
            "Muon eta",
            30,
            -3,
            3,
            ctitle={
                'etau': "Electron eta",
                'tautau': "Leading tau_h eta",
                'emu': "Electron eta"
            },
            ymargin=1.6,
            pos='T',
            ncols=2),
        Var('eta_2',
            "tau_h eta",
            30,
            -3,
            3,
            ctitle={
                'etau': "Electron eta",
                'tautau': "Subleading tau_h eta",
                'emu': "Muon eta"
            },
            ymargin=1.6,
            pos='T',
            ncols=2),
        #Var('m_vis',  40,  0, 200),
        Var('mt_1', "mt(mu,MET)", 40, 0, 200),
        #Var("jpt_1",  29,   10,  300, veto=[r"njets\w*==0"]),
        #Var("jpt_2",  29,   10,  300, veto=[r"njets\w*==0"]),
        #     #Var("jeta_1", 53, -5.4,  5.2, ymargin=1.6,pos='T',ncols=2,veto=[r"njets\w*==0"]),
        #     #Var("jeta_2", 53, -5.4,  5.2, ymargin=1.6,pos='T',ncols=2,veto=[r"njets\w*==0"]),
        #     Var('njets',   8,  0,   8),
        Var('met', 50, 0, 150),
        Var('pt_ll',
            "p_{T}(mutau_h)",
            25,
            0,
            200,
            ctitle={
                'etau': "p_{T}(etau_h)",
                'tautau': "p_{T}(tau_htau_h)",
                'emu': "p_{T}(emu)"
            }),
        #Var('dR_ll',   "DR(mutau_h)",    30, 0, 6.0, ctitle={'etau':"DR(etau_h)",'tautau':"DR(tau_htau_h)",'emu':"DR(emu)"}),
        #Var('deta_ll', "deta(mutau_h)",  20, 0, 6.0, ctitle={'etau':"deta(etau_h)",'tautau':"deta(tautau)",'emu':"deta(emu)"},logy=True,pos='TRR'), #, ymargin=8, logyrange=2.6
        #Var('dzeta',  56, -180, 100, pos='L;y=0.88',units='GeV'),
        #Var("pzetavis", 50,    0, 200 ),
        Var('rawDeepTau2017v2p1VSjet_2',
            "rawDeepTau2017v2p1VSjet",
            100,
            0.0,
            1,
            ncols=2,
            pos='L;y=0.85',
            logy=True,
            ymargin=2.5),
        Var('rawDeepTau2017v2p1VSjet_2',
            "rawDeepTau2017v2p1VSjet",
            20,
            0.80,
            1,
            fname="$VAR_zoom",
            ncols=2,
            pos='L;y=0.85'),
        Var('rawDeepTau2017v2p1VSe_2',
            "rawDeepTau2017v2p1VSe",
            30,
            0.0,
            1,
            fname="$VAR",
            ncols=2,
            logy=True,
            pos='L;y=0.85'),
        Var('rawDeepTau2017v2p1VSe_2',
            "rawDeepTau2017v2p1VSe",
            30,
            0.70,
            1,
            fname="$VAR_zoom",
            ncols=2,
            logy=True,
            pos='L;y=0.85'),
        # Var('rawDeepTau2017v2p1VSmu_2',  "rawDeepTau2017v2p1VSmu",  20, 0.80, 1, fname="$VAR_zoom",ncols=2,logy=True,logyrange=4,pos='L;y=0.85'),
        #     Var('npv',    40,    0,  80 ),
    ]

    # PLOT and HIST
    outdir = ensuredir(repkey(outdir, CHANNEL=channel, ERA=era))
    histdir = ensuredir(repkey(histdir, CHANNEL=channel, ERA=era))
    outhists = R.TFile.Open(histdir, 'recreate')
    exts = ['png', 'pdf']
    for selection in selections:
        outhists.mkdir(selection.filename)
        stacks = sampleset.getstack(
            variables,
            selection,
            method='QCD_OSSS',
            scale=1.1,
            parallel=parallel
        )  # the 'scale' keyword argument - chosen as 1.1 for mutau -
        # is an extrapolation factor for the QCD shape from the same-sign
        # to the opposite-sign region
        fname = "%s/$VAR_%s-%s-%s$TAG" % (outdir, channel, selection.filename,
                                          era)
        text = "%s: %s" % (channel.replace('mu', "#mu").replace(
            'tau', "#tau_{h}"), selection.title)
        for stack, variable in stacks.iteritems():
            outhists.cd(selection.filename)
            for h in stack.hists:
                h.Write(h.GetName().replace("QCD_", "QCD"), R.TH1.kOverwrite)
            stack.draw()
            stack.drawlegend(x1=0.6, x2=0.95, y1=0.35, y2=0.95)
            stack.drawtext(text)
            stack.saveas(fname, ext=exts, tag=tag)
            stack.close()
    outhists.Close()
def plot(sampleset,
         channel,
         parallel=True,
         tag="",
         outdir="plots",
         histdir="",
         era=""):
    """Test plotting of SampleSet class for data/MC comparison."""
    LOG.header("plot")

    # SELECTIONS
    inclusive = "(q_1*q_2<0)"
    inclusive = inclusive.replace(" ", "")
    #inclusive_cr_qcd = inclusive.replace("q_1*q_2<0","q_1*q_2>0") # inverting the opposite-sign requirement of the mutau pair into a same-sign requirment
    zregion = "%s && mt_1_puppimet<60 && nbjets==0 && m_vis>40 && m_vis<100 && dzeta_puppimet>-50 " % (
        inclusive)
    selections = [
        Sel('inclusive', inclusive),
        Sel('zregion', zregion),
        #Sel('inclusive_cr_qcd',inclusive_cr_qcd),
    ]

    # VARIABLES
    # TODO section 5: extend with other variables, which are available in the flat n-tuples
    variables = [
        Var('m_vis', 40, 0, 200),
        Var('pt_vis', "p_{T}^{vis} ", 40, 0, 200),
        Var('pt_Z_puppimet', "p_{T}^{Z} with puppi", 40, 0, 200),
        #Var('pt_Z_PFmet',  "p_{T}^{Z} with PF", 40,  0, 200),
        #Var('m_2',   "m_tau_h",     28,  0.2, 1.6),
        Var('mt_1_puppimet', "mt(mu,MET) with puppi", 40, 0, 200),
        #Var('mt_1_PFmet',  "mt(mu,MET) with PF", 40,  0, 200),
        Var('dzeta_puppimet',
            "D_{zeta} with puppi",
            56,
            -180,
            100,
            pos='L;y=0.88',
            units='GeV'),
        #Var('dzeta_PFmet',  "D_{zeta} with PF",  56, -180, 100, pos='L;y=0.88',units='GeV'),
        Var(
            'pt_1',
            "Muon pt",
            40,
            0,
            120,
        ),
        Var(
            'pt_2',
            "tau_h pt",
            40,
            0,
            120,
        ),
        Var('eta_1', "Muon eta", 30, -3, 3, ymargin=1.6, ncols=2),
        Var('eta_2', "tau_h eta", 30, -3, 3, ymargin=1.6, ncols=2),
        Var('njets', 8, 0, 8),
        Var('nbjets', 8, 0, 8),
        Var('dR_ll',
            "DR(mutau_h)",
            30,
            0,
            6.0,
            ctitle={
                'etau': "DR(etau_h)",
                'tautau': "DR(tau_htau_h)",
                'emu': "DR(emu)"
            }),
        #Var('met_puppimet',    "p_{T}^{miss} with puppi",   50,  0, 150),
        #Var('met_PFmet',    "p_{T}^{miss} with PF",   50,  0, 150),
        Var('rho', "#rho", 40, 0, 80),
        Var('npv', 40, 0, 80),
        Var('npv_good', "npv_{good}", 40, 0, 80),
        Var('id_2', "tau ID vs jet", 65, 0, 65),
        Var('anti_e_2', "tau ID vs ele", 65, 0, 65),
        Var('anti_mu_2', "tau ID vs muon", 20, 0, 20),
    ]

    # PLOT and HIST
    outdir = ensuredir(repkey(outdir, CHANNEL=channel, ERA=era))
    histdir = ensuredir(repkey(histdir, CHANNEL=channel, ERA=era))
    outhists = R.TFile.Open(histdir, 'recreate')
    exts = ['png']
    #exts     = ['png','pdf']
    for selection in selections:
        outhists.mkdir(selection.filename)
        stacks = sampleset.getstack(
            variables,
            selection,
            method='QCD_OSSS',
            scale=1.1,
            parallel=parallel
        )  # the 'scale' keyword argument - chosen as 1.1 for mutau -
        # is an extrapolation factor for the QCD shape from the same-sign
        # to the opposite-sign region
        fname = "%s/$VAR_%s-%s-%s$TAG" % (outdir, channel, selection.filename,
                                          era)
        text = "%s: %s" % (channel.replace('mu', "#mu").replace(
            'tau', "#tau_{h}"), selection.title)
        for stack, variable in stacks.iteritems():
            outhists.cd(selection.filename)
            for h in stack.hists:
                h.Write(h.GetName().replace("QCD_", "QCD"), R.TH1.kOverwrite)
            stack.draw()
            stack.drawlegend(x1=0.6, x2=0.95, y1=0.35, y2=0.95)
            stack.drawtext(text)
            stack.saveas(fname, ext=exts, tag=tag)
            stack.close()
    outhists.Close()
def plot(sampleset,
         channel,
         parallel=True,
         tag="",
         outdir="plots",
         histdir="",
         era=""):
    """Test plotting of SampleSet class for data/MC comparison."""
    LOG.header("plot")

    # SELECTIONS
    inclusive = "(q_1*q_2<0)"
    inclusive = inclusive.replace(" ", "")
    # inclusive_cr_qcd = inclusive.replace("q_1*q_2<0","q_1*q_2>0") # inverting the opposite-sign requirement of the mutau pair into a same-sign requirment
    general_cuts = "(pt_1>26.0)&&(pt_2>20.0)&&(eta_1>-2.1)&&(eta_1<2.1)&&(eta_2>-2.3)&&(eta_2<2.3)"
    isolation = "(iso_1<0.15)"
    mt_cut = "(mt<40.0)"
    mt_pmet_cut = "(mt_pmet<40.0)"
    topo_cut = "(miss_Pdz-0.85*vis_Pdz>-20)"
    isdDT = "(iso_2>0.8)"
    deeptau = "(anti_e_2>=2)&&(anti_mu_2>=8)&&(id_2>=16)"

    final = general_cuts + "&&" + isolation + "&&" + mt_cut + "&&" + mt_pmet_cut + "&&" + topo_cut + "&&" + deeptau + "&&" + isdDT

    selections = [
        Sel('nominal', inclusive),
        Sel('kinematic sel.', general_cuts),
        Sel('isolation', isolation),
        Sel('mt<40.0', mt_cut),
        Sel('mtPmet<40.0', mt_pmet_cut),
        Sel('TopologicalDis', topo_cut),
        Sel('DeepTau', deeptau),
        Sel('isoDeepTau', isdDT),
        Sel('FinalSelection', final),

        # Sel('inclusive_cr_qcd',inclusive_cr_qcd),
    ]

    # VARIABLES
    # TODO section 5: extend with other variables, which are available in the flat n-tuples
    variables = [
        Var('m_vis', 40, 0, 200),

        # For nominal cuts
        # Var('miss_Pdz - 0.85*vis_Pdz', 40, -200, 150),
        # Var('pt_1', 40, 10, 100),
        # Var('eta_1', 40, -3, 3),
        # Var('iso_1', 40, -0.1, 0.5),
        # # Var('decayMode_1', 30, 0, 30),
        #
        # Var('pt_2', 40, 10, 100),
        # Var('eta_2', 40, -3, 3),
        # Var('anti_e_2', 40, -10, 10),
        # Var('anti_mu_2', 40, -10, 10),
        # Var('iso_2', 40,  0.0, 1.2),
        # Var('decayMode_2', 30, 0, 30),
        #
        # Var('genWeight', 40, -1, 2),
        #
        # Var('n_jet',10, 0, 10),
        # Var('jet1_pt', 40, 10, 100),
        # Var('jet1_eta',40, -3, 3),
        # Var('jet2_pt', 40, 10, 100),
        # Var('jet2_eta', 40, -3, 3),
        #
        # Var('n_bjet', 10, 0, 10),
        # Var('bjet1_pt', 40, 10, 100),
        # Var('bjet1_eta',40, -3, 3),
        # Var('bjet2_pt', 40, 10, 100),
        # Var('bjet2_eta', 40, -3, 3),
        #
        # Var('rawMET_phi', 40, -3.5, 3.5),
        # Var('rawMET_pt', 40, 0, 150),
        # Var('rawMET_sumEt', 40, 30, 3000),
        # Var('puppiMET_phi', 40, -3.5, 3.5),
        # Var('puppiMET_pt', 40, 0, 150),
        # Var('puppiMET_sumEt', 40, 30, 500),
        #
        # Var('vis_Z_pt',40, 0, 200),
        # Var('real_Z_pt',40, 0, 200),
        # Var('real_Z_pt_pmet',40, 0, 200),
        #
        # Var('dphi',40, -3.5, 3.5),
        # Var('dphi_pmet',40, -3.5, 3.5),
        #
        # Var('mt', 40,  0, 250),
        # Var('mt_pmet', 40,  0, 250),
        #
        # Var('deltaR', 40, 0, 10.0),
        # Var('puRho', 40,  2, 50),
        # Var('n_pvert', 50,  0, 50),
        # Var('n_pileup', 10,  0, 10),
    ]

    # PLOT and HIST
    outdir = ensuredir(repkey(outdir, CHANNEL=channel, ERA=era))
    histdir = ensuredir(repkey(histdir, CHANNEL=channel, ERA=era))
    outhists = R.TFile.Open(histdir, 'recreate')
    exts = ['png', 'pdf']
    for selection in selections:
        outhists.mkdir(selection.filename)
        stacks = sampleset.getstack(
            variables,
            selection,
            method='QCD_OSSS',
            scale=1.1,
            parallel=parallel
        )  # the 'scale' keyword argument - chosen as 1.1 for mutau -
        # is an extrapolation factor for the QCD shape from the same-sign
        # to the opposite-sign region
        fname = "%s/$VAR_%s-%s-%s$TAG" % (outdir, channel, selection.filename,
                                          era)
        text = "%s: %s" % (channel.replace('mu', "#mu").replace(
            'tau', "#tau_{h}"), selection.title)
        for stack, variable in stacks.iteritems():
            outhists.cd(selection.filename)
            for h in stack.hists:
                print("-----", h.Integral())
                h.Write(h.GetName().replace("QCD_", "QCD"), R.TH1.kOverwrite)
            stack.draw()
            stack.drawlegend(x1=0.6, x2=0.95, y1=0.35, y2=0.95)
            stack.drawtext(text)
            stack.saveas(fname, ext=exts, tag=tag)
            stack.close()
    outhists.Close()