def make_ratio_plot(ratio, analytic_scens, variable):
    """
    Make the comparison plot of the ratio and the analytical scenarios
    """
    can = mkplot(ratio,
                 drawOpt='PE',
                 attr=[{
                     'color': 1,
                     'size': 1,
                     'marker': 20
                 }],
                 yLabel=YLABELS.get('r_chic2_chic1'),
                 yRange=[0, 0.75],
                 **VAR_PLOT[variable])

    chi2_ndfs = get_chi2_ndf(ratio, analytic_scens)

    leg = setup_legend(0.2, 0.15, 0.65, 0.3)
    mkplot(analytic_scens.values(),
           drawOpt='sameL',
           can=can,
           attr=ANALYTIC_ATTRS,
           leg=leg,
           legEntries=analytic_scens.keys(),
           legOpt='L')

    add_auxiliary_info(can, 2012, prelim=True)
    return can
示例#2
0
def make_limit_plot(graphs, variable):
    """
    Make a limit plot
    """
    leg = setup_legend(0.675, 0.74, 0.88, 0.88)
    can = mkplot(graphs.values(),
                 xRange=[8, 30],
                 xLabel=PTLABEL,
                 drawOpt='PE',
                 yRange=[-0.5, 1.1],
                 yLabel=YLABELS[variable],
                 leg=leg,
                 legOpt='L',
                 legEntries=['{} % C.L.'.format(v) for v in graphs.keys()])

    mkplot(r.TLine(8, -0.33333, 30, -0.33333),
           can=can,
           drawOpt='same',
           attr=[{
               'color': 12,
               'line': 7,
               'linewidth': 2
           }])

    add_auxiliary_info(can, 2012, prelim=True, pos='left')

    return can
示例#3
0
def make_plot_comp_ana_shapes(graph, variable, is_mc=False):
    """
    Make the comparison plot with the analytical shapes
    """
    ana_shapes = get_analytic_scenarios(variable)
    fit_res = OrderedDict()
    for scen, shape in ana_shapes.iteritems():
        fit_res[scen] = fit_to_dist(shape, graph)

    can = mkplot(graph,
                 drawOpt='PE',
                 attr=RATIO_ATTR,
                 xRange=XRANGES[variable],
                 xLabel=XLABELS[variable],
                 yRange=[0, 1.2] if is_mc else [0, 0.75],
                 yLabel=YLABEL)

    mkplot(ana_shapes.values(),
           can=can,
           drawOpt='same',
           attr=SCEN_ATTR,
           legPos=LEG_POS[variable],
           legEntries=get_legend_keys(fit_res),
           legOpt='L')

    add_auxiliary_info(can, [YEAR], prelim=True, mc=is_mc)
    return can
def make_ratio_plot(uncorr_ratio, corr_ratio, variable):
    """
    Make the comparison plot of corrected and uncorrected graphs
    """
    leg = setup_legend(*LEGEND_POS[variable])
    leg.SetTextSize(0.03)

    can = mkplot(corr_ratio,
                 drawOpt='PE',
                 attr=[{
                     'color': 1,
                     'size': 1,
                     'marker': 20
                 }],
                 yLabel=YLABELS.get('r_chic2_chic1'),
                 yRange=[0, 0.75],
                 leg=leg,
                 legEntries=['corrected'],
                 **VAR_PLOT[variable])

    shift = HORIZONTAL_SHIFT[variable]
    mkplot([
        shift_graph_horizontal(rescale_graph(uncorr_ratio, corr_ratio), shift),
        shift_graph_horizontal(uncorr_ratio, -shift)
    ],
           can=can,
           drawOpt='samePE',
           attr=default_attributes(open_markers=True),
           leg=leg,
           legEntries=['fitted (scaled)', 'fitted'])

    add_auxiliary_info(can, 2012, prelim=True)

    return can
def make_plot(lth_g, dlth_g, lth2_g):
    """
    Make the plot as a function of pT/M according to Carlos specifications
    """
    lth_g = scale_graph_x(lth_g, 1 / m_psiPDG)
    dlth_g = scale_graph_x(dlth_g, 1 / m_psiPDG)
    lth2_g = scale_graph_x(lth2_g, 1 / m_psiPDG)
    lth2_g = shift_graph_horizontal(lth2_g, 0.1)

    leg = setup_legend(0.675, 0.74, 0.88, 0.88)
    can = mkplot([lth_g],
                 drawOpt='P',
                 attr=[ATTR['lth']],
                 xRange=XRANGE,
                 xLabel=PTMLABEL,
                 yRange=YRANGE,
                 yLabel='#lambda',
                 leg=leg,
                 legEntries=[YLABELS['lth']])
    mkplot([dlth_g, lth2_g],
           drawOpt='samePE',
           can=can,
           attr=[ATTR['dlth'], ATTR['lth2']],
           leg=leg,
           legEntries=[YLABELS['dlth'], YLABELS['lth2']])

    add_auxiliary_info(can, 2012, prelim=True, pos='left')

    return can
示例#6
0
def main(args):
    """Main"""
    with open(args.configfile, 'r') as configfile:
        config = json.load(configfile)

    model = BinnedFitModel(config)
    ffile = r.TFile.Open(args.fitfile)
    wsp = ffile.Get('ws_mass_fit')


    if args.outdir is None:
        outdir = dirname(args.fitfile)
    else:
        outdir = args.outdir

    cond_mkdir(outdir)

    if args.publication:
        set_TDR_style()

    # Saving the plots
    if not args.no_plots:
        cans = model.plot(wsp, verbose=args.verbose, publication=args.publication,
                          preliminary=args.preliminary)
        canp = model.plot_fit_params(wsp)

        for bin_name in model.bins:
            plotname = '/'.join([outdir, bin_name+'_massfit.pdf'])
            if args.publication:
                add_auxiliary_info(cans[bin_name], 2012, prelim=True)
            cans[bin_name].SaveAs(plotname)

            parname = '/'.join([outdir, bin_name+'_massfit_res.pdf'])
            canp[bin_name].SaveAs(parname)

    if args.graphs:
        outfile = '/'.join([outdir, 'proto_param_graphs.root'])
        store_proto_pars(wsp, model, outfile, args.symmetric)
示例#7
0
def make_uncer_plot(graphs, variable, levels):
    """
    Make the plot plotting the uncertainties and return the canvas
    """
    # All graphs have the same central values so it doesn't matter which one we
    # take
    cent_graph = remove_y_errors(graphs.values()[0])

    leg = setup_legend(0.675, 0.74, 0.88, 0.88)

    can = mkplot(cent_graph,
                 drawOpt='PE',
                 attr=ATTR['central'],
                 xRange=[8, 30],
                 xLabel=PTLABEL,
                 yRange=YRANGES[variable],
                 yLabel=YLABELS[variable],
                 leg=leg,
                 legEntries=['central'],
                 legOpt='P')

    for n_sig in levels:
        graph = graphs[n_sig]
        mkplot(graph,
               can=can,
               drawOpt='E2same',
               legOpt='F',
               attr=ATTR[n_sig],
               leg=leg,
               legEntries=[LEG_KEYS[n_sig]])

    mkplot(cent_graph, can=can, drawOpt='samePE', attr=ATTR['central'])

    add_auxiliary_info(can, 2012, prelim=True, pos='left')

    return can
示例#8
0
def make_plot_with_syst(graphs,
                        variable,
                        syst_file,
                        add_fit=False,
                        vs_pt_m=False):
    """
    Make a plot including the systematic uncertainties.
    First combine the stat. and syst. errors by summing them in quadrature then
    plot the combined as well as the stat. only graphs onto the plot.
    Only uses the +/- 1 sigma stat. uncertainties
    """
    syst_graph = syst_file.Get('{}_v_pt_syst'.format(variable))
    stat_graph = graphs['1']
    comb_graph = get_combined_graph(stat_graph, syst_graph)

    xran = [8, 30]
    xlab = PTLABEL

    if vs_pt_m:
        xran = [v / m_psiPDG for v in xran]
        comb_graph = scale_graph_x(comb_graph, 1 / m_psiPDG)
        stat_graph = scale_graph_x(stat_graph, 1 / m_psiPDG)
        xlab = PTMLABEL

    leg = setup_legend(0.675, 0.74, 0.88, 0.88)
    can = mkplot(comb_graph,
                 drawOpt='PE2',
                 attr=ATTR['combined'],
                 xRange=xran,
                 xLabel=xlab,
                 yRange=YRANGES[variable],
                 yLabel=YLABELS[variable],
                 leg=leg,
                 legEntries=['stat. + syst.'],
                 legOpt='PF')

    # remove the x uncertainties to avoid having the vertical line in the plot
    # stat_graph = remove_x_errors(stat_graph)
    mkplot(stat_graph,
           can=can,
           drawOpt='PE2same',
           attr=ATTR['stat only'],
           leg=leg,
           legEntries=['stat. only'],
           legOpt='F')

    # stat only covers the point of the combined one. Plot them again
    mkplot(comb_graph, drawOpt='PEX0same', attr=ATTR['combined'], can=can)

    add_auxiliary_info(can, 2012, prelim=True, pos='left')

    if add_fit:
        lin_func = r.TF1('lin_func', '[0] + [1] * x[0]', *xran)
        fit_res = comb_graph.Fit(lin_func, 'SEX00')
        chi2, ndf = fit_res.Chi2(), fit_res.Ndf()
        p0, p1 = [lin_func.GetParameter(i) for i in [0, 1]]

        const_func = r.TF1('const_func', '[0]', *xran)
        fit_res = comb_graph.Fit(const_func, 'SEX00')
        chi2_c, ndf_c = fit_res.Chi2(), fit_res.Ndf()
        p0c, p0ce = [const_func.GetParameter(0), const_func.GetParError(0)]

        mkplot(lin_func, drawOpt='Lsame', can=can, attr=ATTR['fit'])

        ltx = setup_latex()
        put_on_latex(ltx, [
            (0.5, 0.35, 'linear fit: {:.3f} + {:.3f} x p_{{T}}'.format(p0,
                                                                       p1)),
            (0.5, 0.3, '#chi^{{2}} / ndf = {:.2f} / {}'.format(chi2, ndf)),
            (0.5, 0.25, 'const. fit: {:.3f} #pm {:.3f}'.format(p0c, p0ce)),
            (0.5, 0.2, '#chi^{{2}} / ndf = {:.2f} / {}'.format(chi2_c, ndf_c))
        ],
                     ndc=True)
        ltx.Draw()
        can.Update()

    return can
def make_ratio_pull_plot(ratio, analytic_scens, variable):
    """
    Make a comparison plot with an additional pull panel at the bottom
    """
    # Scale all analytic scenarios first
    chi2_ndfs = get_chi2_ndf(ratio, analytic_scens)

    can = mkplot([])  # get a canvas that is already a TCanvasWrapper
    can.cd()
    rpad = r.TPad('ratio_pad', 'ratio pad', 0, 0.3, 1, 0.98)
    r.SetOwnership(rpad, False)
    rpad.SetBottomMargin(0)
    rpad.Draw()

    rpad = mkplot(ratio,
                  drawOpt='PE',
                  can=rpad,
                  attr=[{
                      'color': 1,
                      'size': 1,
                      'marker': 20
                  }],
                  yLabel=YLABELS.get('r_chic2_chic1'),
                  yRange=[0.001, 0.75],
                  **VAR_PLOT[variable])

    leg = setup_legend(0.2, 0.15, 0.65, 0.32)
    mkplot(analytic_scens.values(),
           drawOpt='sameL',
           can=rpad,
           attr=ANALYTIC_ATTRS,
           leg=leg,
           legEntries=analytic_scens.keys(),
           legOpt='L')

    can.cd()
    ppad = r.TPad('pull_pad', 'pull pad', 0, 0, 1, 0.3)
    r.SetOwnership(ppad, False)
    ppad.SetTopMargin(0)
    ppad.SetBottomMargin(0.3)
    ppad.Draw()

    # Draw grid first so that it is not overlaying the plotted points
    xran = VAR_PLOT[variable]['xRange']
    ppad = mkplot(
        r.TLine(xran[0], 0, xran[1], 0),
        can=ppad,
        attr=[{
            'color': 1,
            'width': 2,
            'line': 1
        }],
        yLabel='pulls',
        yRange=[-4.99, 4.99],  # grid=True,
        **VAR_PLOT[variable])
    mkplot([r.TLine(xran[0], v, xran[1], v) for v in [-3, 3]],
           drawOpt='same',
           can=ppad,
           attr=[{
               'color': 12,
               'width': 2,
               'line': 7
           }])

    pulls = [pull_graph(ratio, s) for s in analytic_scens.values()]
    ppad = mkplot(pulls,
                  drawOpt='samePE',
                  can=ppad,
                  attr=default_attributes(open_markers=False),
                  **VAR_PLOT[variable])

    phist = ppad.pltables[0]
    phist.SetNdivisions(505, "XYZ")
    phist.SetLabelFont(42, "XYZ")
    phist.SetLabelOffset(0.007, "XYZ")
    phist.SetLabelSize(0.12, "XYZ")
    phist.GetXaxis().SetTitleOffset(0.95)
    phist.GetYaxis().SetTitleOffset(0.52)
    phist.SetTitleSize(0.14, "XYZ")
    # ppad.SetGridy()

    can.add_tobject(rpad)
    can.add_tobject(ppad)

    add_auxiliary_info(can, 2012, prelim=True)
    return can
示例#10
0
def main(args):
    """Main"""
    set_TDR_style()
    fitfile = r.TFile.Open(args.fitfile)

    cont_1sigma = get_contour(fitfile.Get('chi2_scan_contour_1sigma'))
    cont_2sigma = get_contour(fitfile.Get('chi2_scan_contour_2sigma'))
    cont_3sigma = get_contour(fitfile.Get('chi2_scan_contour_3sigma'))

    leg = setup_legend(0.5, 0.78, 0.8, 0.94)
    leg.SetTextSize(0.035)
    leg.SetEntrySeparation(0.005)
    leg.SetFillStyle(1001)

    can = mkplot([cont_1sigma, cont_2sigma, cont_3sigma],
                 drawOpt='L',
                 xRange=[-1, 1.6],
                 xLabel='#lambda_{#vartheta}^{#chi_{c1}}',
                 yRange=[-1.2, 1.6],
                 yLabel='#lambda_{#vartheta}^{#chi_{c2}}',
                 attr=CONT_ATTR,
                 leg=leg,
                 legEntries=['{} % CL'.format(v) for v in [68, 95, 99]],
                 legOpt='L')

    mkplot(get_phys_region(),
           can=can,
           drawOpt='same',
           attr=[{
               'color': r.kRed,
               'line': 7,
               'width': 3
           }])

    mkplot([r.TLine(0, -1.2, 0, 1.6),
            r.TLine(-1, 0, 1.6, 0)],
           can=can,
           drawOpt='same',
           attr=[{
               'color': 12,
               'line': 7,
               'width': 2
           }])

    mkplot(r.TGraph(1, np.array([0]), np.array([0])),
           can=can,
           drawOpt='Psame',
           attr=[{
               'color': 1,
               'marker': 24,
               'size': 2.75
           }])

    mkplot(get_jz_graph(),
           can=can,
           drawOpt='Psame',
           attr=[{
               'color': 1,
               'marker': 30,
               'size': 3
           }])

    ltx = setup_latex()
    ltx.SetTextSize(0.04)
    put_on_latex(ltx, [(-0.4, 1.3, 'J_{z}'), (-0.4, 1.1, '#pm1'),
                       (0.975, 1.1, '0'), (-0.54, 0.95, '#pm2'),
                       (-0.54, -0.38, '#pm1'), (-0.47, -0.65, '0')],
                 ndc=False)

    add_auxiliary_info(can, 2012, 'left')
    can.SaveAs(args.outfile)
def add_info(can, pos='right'):
    add_auxiliary_info(can, 2012, prelim=True, pos=pos)
    return can
示例#12
0
def make_nice(can):
    """
    Add auxiliary info and adapt y-axis labeling
    """
    add_auxiliary_info(can, 2012, prelim=True)