Ejemplo n.º 1
0
def draw_pt_bins(in_file, out_dir, eff=0.7, rej_flavor='U', ext='.pdf', 
                 subset=None): 
    fig = Figure(figsize=(8,6))
    canvas = FigureCanvas(fig)
    ax = fig.add_subplot(1,1,1)
    ax.grid(which='both')
    ax.set_xscale('log')
    for tagger in tagschema.get_taggers(in_file, subset): 
        pt_bins = tagschema.get_pt_bins(in_file['B/btag/ptBins'])
        eff_group = in_file['B/btag/ptBins']
        rej_group = in_file['{}/btag/ptBins'.format(rej_flavor.upper())]
        x_vals, y_vals, x_err, y_err = _get_pt_xy(
            eff_group, rej_group, pt_bins, eff, tagger=tagger)
        with tagschema.ColorScheme('colors.yml') as colors: 
            ax.errorbar(
                x_vals, y_vals, label=tagger, #xerr=x_err, 
                yerr=y_err, color=colors[tagger])
    ax.legend(numpoints=1, loc='upper left')
    ax.set_xlim(20, np.max(x_vals) * 1.1)
    ax.set_xlabel('$p_{\mathrm{T}}$ [GeV]', x=0.98, ha='right')
    ax.set_ylabel(rej_label(rej_flavor, eff), y=0.98, ha='right')
    x_formatter = FuncFormatter(tick_format)
    ax.xaxis.set_minor_formatter(x_formatter)
    ax.xaxis.set_major_formatter(x_formatter)
    out_name = '{}/{}Rej{}_ptbins{}'.format(
        out_dir, rej_flavor.lower(), int(eff*100), ext)
    canvas.print_figure(out_name, bbox_inches='tight')
Ejemplo n.º 2
0
def draw_btag_roc(in_file, out_dir, min_eff=0.5, ext='.pdf',
                  baseline=None, flavor='U', propaganda=False, subset=None):
    textsize = 16
    fig = Figure(figsize=(8,6))
    canvas = FigureCanvas(fig)
    grid = GridSpec(2,1, height_ratios=[3,1])
    ax = fig.add_subplot(grid[0])
    ra = fig.add_subplot(grid[1],sharex=ax)

    _setup_ax(ax, textsize)
    _setup_ratio(ra, textsize)
    bname = tagschema.display_name(baseline) if propaganda else baseline
    ra.set_ylabel('X / {}'.format(bname))

    taggers = tagschema.get_taggers(in_file, subset)
    base_x = None

    def get_xy(tagger):
        return _get_roc_xy(*_get_datasets(in_file, tagger, flavor=flavor))

    if baseline and baseline in taggers:
        base_x, base_y = get_xy(baseline)
    for tagger in taggers:
        x_pts, y_pts = get_xy(tagger)
        valid_eff = x_pts > min_eff
        tname = tagschema.display_name(tagger) if propaganda else tagger
        with tagschema.ColorScheme('colors.yml') as colors:
            color = colors[tname]
        valid_x = x_pts[valid_eff]
        valid_y = y_pts[valid_eff]
        ax.plot(valid_x, valid_y, '-', label=tname, color=color, lw=_line_width)
        if base_x is not None and tagger != baseline:
            interp_y = np.interp(valid_x, base_x, base_y)
            ra.plot(valid_x, valid_y / interp_y, color=color, lw=_line_width)
    if not isdir(out_dir):
        os.mkdir(out_dir)
    ax.legend()
    ax.set_xlim(min_eff, 1.0)
    ax.set_ylabel('$1/\epsilon_{{ {} }}$'.format(flavor.lower()),
                  y=0.98, ha='right', size=textsize)
    # plt.setp(ax.get_xticklabels(), visible=False)
    for tk in ax.get_xticklabels():
        tk.set_visible(False)
    fig.tight_layout(pad=0, h_pad=0, w_pad=0)
    file_name = '{}/{}RejRoc{}'.format(out_dir, flavor.lower(), ext)
    canvas.print_figure(file_name, bbox_inches='tight')