コード例 #1
0
ファイル: rendering.py プロジェクト: nabinpoudyal3/Varial
    def mk_poisson_errs_graph(cnv_wrp, data_rnd, div_hist, mc_histo_no_err,
                              par):
        data_hist = data_rnd.histo
        data_hist.SetBinErrorOption(
            ROOT.TH1.kPoisson)  # TODO: poisson erros for main histo
        data_hist.Sumw2(False)  # should be set elsewhere!
        gtop = ROOT.TGraphAsymmErrors(data_hist)
        gbot = ROOT.TGraphAsymmErrors(div_hist)
        for i in xrange(mc_histo_no_err.GetNbinsX(), 0, -1):
            mc_val = mc_histo_no_err.GetBinContent(i)
            if mc_val:
                e_up = data_hist.GetBinErrorUp(i)
                e_lo = data_hist.GetBinErrorLow(i)
                gtop.SetPointError(i - 1, 0., 0., e_lo, e_up)
                gbot.SetPointError(i - 1, 0., 0., e_lo / mc_val, e_up / mc_val)
            else:
                gtop.RemovePoint(i - 1)
                gbot.RemovePoint(i - 1)

        data_hist.Sumw2()
        data_rnd.graph_draw = gtop
        data_rnd.draw_option = '0P'
        par['draw_opt'] = '0P'
        h_x_ax, g_x_ax = div_hist.GetXaxis(), gbot.GetXaxis()
        g_x_ax.SetTitle(h_x_ax.GetTitle())
        g_x_ax.SetRangeUser(h_x_ax.GetXmin(), h_x_ax.GetXmax())
        settings.set_bottom_plot_ratio_style(gbot)
        cnv_wrp.bottom_graph = gbot
        return gbot
コード例 #2
0
ファイル: rendering.py プロジェクト: HeinerTholen/Varial
    def mk_poisson_errs_graph(cnv_wrp, data_rnd, div_hist, mc_histo_no_err, par):
        data_hist = data_rnd.histo
        data_hist.SetBinErrorOption(ROOT.TH1.kPoisson)  # TODO: poisson erros for main histo
        data_hist.Sumw2(False)                          # should be set elsewhere!
        gtop = ROOT.TGraphAsymmErrors(data_hist)
        gbot = ROOT.TGraphAsymmErrors(div_hist)
        for i in xrange(mc_histo_no_err.GetNbinsX(), 0, -1):
            mc_val = mc_histo_no_err.GetBinContent(i)
            if mc_val:
                e_up = data_hist.GetBinErrorUp(i)
                e_lo = data_hist.GetBinErrorLow(i)
                gtop.SetPointError(i - 1, 0., 0., e_lo, e_up)
                gbot.SetPointError(i - 1, 0., 0., e_lo/mc_val, e_up/mc_val)
            else:
                gtop.RemovePoint(i - 1)
                gbot.RemovePoint(i - 1)

        data_hist.Sumw2()
        data_rnd.graph_draw = gtop
        data_rnd.draw_option = '0P'
        par['draw_opt'] = '0P'
        h_x_ax, g_x_ax = div_hist.GetXaxis(), gbot.GetXaxis()
        g_x_ax.SetTitle(h_x_ax.GetTitle())
        g_x_ax.SetRangeUser(h_x_ax.GetXmin(), h_x_ax.GetXmax())
        settings.set_bottom_plot_ratio_style(gbot)
        cnv_wrp.bottom_graph = gbot
        return gbot
コード例 #3
0
ファイル: rendering.py プロジェクト: HeinerTholen/Varial
    def make_bottom_hist(cnv_wrp, kws):
        if not bottom_plot_canv_ok(cnv_wrp):
            return cnv_wrp

        par = dict(settings.defaults_BottomPlot)
        par.update(outer_kws)
        par.update(kws)
        cnv_wrp._par_mk_ratio_plot_func = par

        rnds = cnv_wrp._renderers
        div_wrp = op.div(bottom_plot_get_div_hists(rnds))
        div_wrp.histo.SetYTitle(par['y_title'] or (
            '#frac{Data}{MC}' if rnds[1].is_data else 'Ratio'))

        cnv_wrp.bottom_hist = div_wrp.histo
        settings.set_bottom_plot_general_style(cnv_wrp.bottom_hist)
        settings.set_bottom_plot_ratio_style(cnv_wrp.bottom_hist)
        _bottom_plot_y_bounds(cnv_wrp, cnv_wrp.bottom_hist, par)
コード例 #4
0
ファイル: rendering.py プロジェクト: nabinpoudyal3/Varial
    def make_bottom_hist(cnv_wrp, kws):
        if not bottom_plot_canv_ok(cnv_wrp):
            return cnv_wrp

        par = dict(settings.defaults_BottomPlot)
        par.update(outer_kws)
        par.update(kws)
        par['y_title'] = par.get('y_title', '') or '#frac{Data-MC}{MC}'
        cnv_wrp._par_mk_split_err_ratio_plot_func = par

        rnds = cnv_wrp._renderers
        mcee_rnd, data_rnd = bottom_plot_get_div_hists(rnds)

        # overlaying ratio histogram
        mc_histo_no_err = mcee_rnd.histo.Clone()
        mc_histo_no_err.GetXaxis().SetCanExtend(0)
        data_hist = data_rnd.histo
        div_hist = data_hist.Clone()
        div_hist.GetXaxis().SetCanExtend(0)
        div_hist.Sumw2()
        for i in xrange(1, mc_histo_no_err.GetXaxis().GetNbins() + 1):
            mc_histo_no_err.SetBinError(i, 0.)
            if not div_hist.GetBinContent(i):
                div_hist.SetBinError(i, 1.)
        div_hist.Add(mc_histo_no_err, -1)
        div_hist.Divide(mc_histo_no_err)

        settings.set_bottom_plot_ratio_style(div_hist)
        _bottom_plot_y_bounds(cnv_wrp, div_hist, par)
        cnv_wrp.bottom_hist = div_hist

        # underlying error bands
        _err_ratio_util_mk_sys_stt_histos(cnv_wrp, mcee_rnd)

        # poisson errs or not..
        if par['poisson_errs']:
            mk_poisson_errs_graph(cnv_wrp, data_rnd, div_hist, mc_histo_no_err,
                                  par)

        # ugly fix: move zeros out of range
        for i in xrange(1, mc_histo_no_err.GetNbinsX() + 1):
            if not (div_hist.GetBinContent(i) or div_hist.GetBinError(i)):
                div_hist.SetBinContent(i, -500)
コード例 #5
0
ファイル: rendering.py プロジェクト: nabinpoudyal3/Varial
    def make_bottom_hist(cnv_wrp, kws):
        if not bottom_plot_canv_ok(cnv_wrp):
            return cnv_wrp

        par = dict(settings.defaults_BottomPlot)
        par.update(outer_kws)
        par.update(kws)
        cnv_wrp._par_mk_ratio_plot_func = par

        rnds = cnv_wrp._renderers
        div_wrp = op.div(bottom_plot_get_div_hists(rnds))
        div_wrp.histo.SetYTitle(
            par['y_title']
            or ('#frac{Data}{MC}' if rnds[1].is_data else 'Ratio'))

        cnv_wrp.bottom_hist = div_wrp.histo
        settings.set_bottom_plot_general_style(cnv_wrp.bottom_hist)
        settings.set_bottom_plot_ratio_style(cnv_wrp.bottom_hist)
        _bottom_plot_y_bounds(cnv_wrp, cnv_wrp.bottom_hist, par)
コード例 #6
0
ファイル: rendering.py プロジェクト: HeinerTholen/Varial
    def make_bottom_hist(cnv_wrp, kws):
        if not bottom_plot_canv_ok(cnv_wrp):
            return cnv_wrp

        par = dict(settings.defaults_BottomPlot)
        par.update(outer_kws)
        par.update(kws)
        par['y_title'] = par.get('y_title', '') or '#frac{Data-MC}{MC}'
        cnv_wrp._par_mk_split_err_ratio_plot_func = par


        rnds = cnv_wrp._renderers
        mcee_rnd, data_rnd = bottom_plot_get_div_hists(rnds)

        # overlaying ratio histogram
        mc_histo_no_err = mcee_rnd.histo.Clone()
        mc_histo_no_err.GetXaxis().SetCanExtend(0)
        data_hist = data_rnd.histo
        div_hist = data_hist.Clone()
        div_hist.GetXaxis().SetCanExtend(0)
        div_hist.Sumw2()
        for i in xrange(1, mc_histo_no_err.GetXaxis().GetNbins()+1):
            mc_histo_no_err.SetBinError(i, 0.)
            if not div_hist.GetBinContent(i):
                div_hist.SetBinError(i, 1.)
        div_hist.Add(mc_histo_no_err, -1)
        div_hist.Divide(mc_histo_no_err)

        settings.set_bottom_plot_ratio_style(div_hist)
        _bottom_plot_y_bounds(cnv_wrp, div_hist, par)
        cnv_wrp.bottom_hist = div_hist

        # underlying error bands
        _err_ratio_util_mk_sys_stt_histos(cnv_wrp, mcee_rnd)

        # poisson errs or not..
        if par['poisson_errs']:
            mk_poisson_errs_graph(cnv_wrp, data_rnd, div_hist, mc_histo_no_err, par)

        # ugly fix: move zeros out of range
        for i in xrange(1, mc_histo_no_err.GetNbinsX()+1):
            if not (div_hist.GetBinContent(i) or div_hist.GetBinError(i)):
                div_hist.SetBinContent(i, -500)