コード例 #1
0
ファイル: toymc.py プロジェクト: daritter/OpenMPIFitter
def draw_toyMC(hist,title,xlabel="",ylabel="",exponent=None, box="tl"):
    fit = root.TF1("gauss","gaus")
    textbox = r"\begin{align*}\mu&=%s\\\sigma&=%s\end{align*}"
    fig, a = utils.get_plotaxes((4,3.2))
    hist.Fit(fit,"LQ")
    r2mpl.plot(hist,axes=a, errors=True, color="k", zorder=1)
    r2mpl.plot(fit,axes=a, color="r", zorder=0)
    utils.text_box(a, box, textbox % (
        utils.format_error(fit.GetParameter(1), fit.GetParError(1), exponent=exponent),
        utils.format_error(fit.GetParameter(2), fit.GetParError(2), exponent=exponent)))

    a.set_title(title)
    a.set_xlabel(xlabel)
    a.set_ylabel(ylabel)
    return a, (fit.GetParameter(1), fit.GetParError(1)), (fit.GetParameter(2), fit.GetParError(2))
コード例 #2
0
ファイル: make_plots.py プロジェクト: daritter/OpenMPIFitter
def plot_dfs(name,data,fits,label,title=None,log=False, unit="GeV", stack=True):
    """Plot data, fit and normalized residuals"""
    fig, data_axes, sigma_axes = utils.get_plotaxes_stacked()
    colors = {"signal":"r", "misrecon":"m", "bbar":"g", "continuum":"b", "dummy":"r"}
    last = None
    for i,(l,f) in enumerate(fits):
        if last is not None:
            last.Add(f)
        else:
            last = f.Clone("tmp")

        hist = stack and last or f

        plot_fit(data_axes, hist, data, colors[l], l, i)

    if not stack and len(fits)>1:
        plot_fit(data_axes, last, data, "k", "combined", len(fits))

    r2mpl.plot(data,errors=True,axes=data_axes, color="k", label="data", linewidth=0.5, capsize=1.0, zorder=10)

    sigma = calc_sigmas(name + "_sigma",data, last)
    r2mpl.plot(sigma,errors=True,axes=sigma_axes, color="k", linewidth=0.5, capsize=1.0)
    data_axes.set_ylim(ymin=0)
    sigma_axes.set_ylim(-4,4)
    sigma_axes.axhline(-2, color="r")
    sigma_axes.axhline( 0, color="k")
    sigma_axes.axhline(+2, color="r")
    sigma_axes.set_yticks([-4,-3,-2,-1,0,1,2,3,4])
    sigma_axes.set_yticklabels(["","","$-2$","","$0$","","$2$","",""])
    sigma_axes.set_xlabel(label)
    sigma_axes.set_ylabel("normalized\nresiduals")
    data_axes.set_ylabel(r"Entries / \num{%.3g} %s" % (data.GetBinWidth(1), unit))
    data_axes.set_title(title)
    #data_axes.legend(loc="upper left", numpoints=2)

    if log:
        data_axes.set_yscale("log",nonposy="clip")
        ymin=data.GetMinimum(0.5)/2.0
        for (l,f) in fits:
            ymin = min(ymin,f.GetMaximum()/2.0)
        #data_axes.set_ylim(ymin=data.GetMinimum(0.5)/2.0)
        data_axes.set_ylim(ymin)

    return data_axes
コード例 #3
0
ファイル: make_plots.py プロジェクト: daritter/OpenMPIFitter
def plot_mBCdE(data, label=None, title=None, **argk):
    """Make a 2D Plot of mBC and dE"""
    f, a = utils.get_plotaxes()
    #f = pl.figure(figsize=(4,4))
    #a = f.add_axes((0.20,0.13,0.70,0.80))
    p = r2mpl.plot(data, a, **argk)
    if label is None:
        label = r"Entries / $\num{%.3g} \times \num{%.3g}\text{ GeV}^2$" % \
                (data.GetXaxis().GetBinWidth(1), data.GetYaxis().GetBinWidth(1))
    if title is not None:
        a.set_title(title)

    formatter = matplotlib.ticker.ScalarFormatter(False,False)
    formatter.set_powerlimits((-3,3))
    cb = f.colorbar(p, format=formatter, fraction=0.2)
    cb.set_label(label)
    a.grid()
    a.set_xlabel("$M_{BC}$ / GeV")
    a.set_ylabel("$\Delta E$ / GeV")

    #Draw rectangle to show signal enhanced area
    coords = (5.27,-0.04,5.29,0.04)
    a.add_patch(matplotlib.patches.Rectangle(coords[:2], coords[2]-coords[0], coords[3]-coords[1], edgecolor="k", facecolor="none"))
コード例 #4
0
ファイル: make_plots.py プロジェクト: daritter/OpenMPIFitter
def plot_asymmetry(data1, data2, fits1, fits2, label, val1, val2):
    """Plot 2 dT flavours and the asymmetry between them"""
    fig, a1, a2 = utils.get_plotaxes_stacked()

    f1 = accumulate(fits1)
    f2 = accumulate(fits2)
    asym_data = data1.GetAsymmetry(data2)
    asym_fit  = f1.GetAsymmetry(f2)

    plot_fit(a1, f1, data1, "r")
    plot_fit(a1, f2, data2, "b")
    r2mpl.plot(data1, axes=a1, errors=True, color="r", zorder=2, linewidth=0.5, capsize=1.0, label="$%s=%s$"% (label, val1))#, marker="^")
    r2mpl.plot(data2, axes=a1, errors=True, color="b", zorder=2, linewidth=0.5, capsize=1.0, label="$%s=%s$"% (label, val2))#, marker="o")

    plot_fit(a2, asym_fit, asym_data, "r")
    r2mpl.plot(asym_data, axes=a2, errors=True, color="k", zorder=2, linewidth=0.5, capsize=1.0)
    a1.legend(loc="upper left", numpoints=1)
    a2.set_ylim(-1.0,1.0)
    a1.set_ylabel(r"Entries / \num{%.3g} ps" % data1.GetBinWidth(1))
    a2.set_xlabel(r"$\Delta t$ / ps")
コード例 #5
0
ファイル: print_pars.py プロジェクト: daritter/OpenMPIFitter
    print "From cuts:  ", s2

ngenerated = np.array([(h_ngenerated.GetBinContent(i+1), h_ngenerated.GetBinContent(i+1)) for i in range(2)])

raw_eff = signal_yield / ngenerated
rec_eff = raw_eff * eff_DDKs

ctl_eff = raw_eff * eff_DsD0Km

rec_eff_c = rec_eff * np.array([utils.correction_mc, utils.correction_mc]).T
ctl_eff_c = ctl_eff * np.array([utils.correction_ctrl, utils.correction_ctrl]).T

h_nB0 = b0.draw("nB0", range=(200,0,200), option="goff")
b_mult = h_nB0.GetMean()
f,a = utils.get_plotaxes()
r2mpl.plot(h_nB0, axes=a, log=True)
a.set_title("\PBz Multiplicity")
a.set_xlabel("Number of reconstructed \PBz")
a.set_ylabel("Number of events")
r2mpl.save_all("bmult", png=False, single_pdf=False)
print """ngenerated = np.array([
    %d,
    %d,
])

efficiency_mc = np.array([
   [%.7e, %.7e],
   [%.7e, %.7e],
])""" % (tuple(ngenerated[:,0]) + tuple(rec_eff.flat))

print """efficiency_ctrl = np.array([
コード例 #6
0
            one_result.Fit(fit,"LQ")
            lin_result.SetBinContent(x,fit.GetParameter(1))
            lin_result.SetBinError(x,fit.GetParError(1))
            one_pull.Fit(fit,"LQ")
            lin_pull_mean.SetBinContent(x,fit.GetParameter(1))
            lin_pull_mean.SetBinError(x,fit.GetParError(1))
            lin_pull_sigma.SetBinContent(x,fit.GetParameter(2))
            lin_pull_sigma.SetBinError(x,fit.GetParError(2))

        fit = root.TF1("line","pol1",-0.8,0.8)
        for a,h in (a1,lin_result),(a2,lin_pull_mean),(a3,lin_pull_sigma):
            if par is not "yield_signal_br":
                h.Fit(fit,"Q")
            else:
                h.Fit(fit,"Q")
            r2mpl.plot(h, axes=a, errors=True, color=colors[par])
            r2mpl.plot(fit, axes=a, color=colors[par])
            utils.text_box(a, "tl", r"\begin{align*}m&=%s\\t&=%s\end{align*}" % (utils.format_error(fit.GetParameter(1), fit.GetParError(1)), utils.format_error(fit.GetParameter(0), fit.GetParError(0))))

        lin_res = lin_result.Clone("tmp")
        for i in range(1,lin_res.GetNbinsX()+1):
            lin_res.SetBinContent(i,lin_res.GetBinContent(i)-lin_res.GetBinCenter(i))
        r2mpl.plot(lin_res, axes=a1, errors=True, color="k")

        if par is not "yield_signal_br":
            #ymin = result.GetYaxis().GetXmin()
            #ymax = result.GetYaxis().GetXmax()
            a1.set_ylim(-1.2,1.2)
        a2.set_ylim(-1,1)
        a3.set_ylim(0,2)
コード例 #7
0
        for x in range(1,pull.GetNbinsX()+1):
            one_result = result.ProjectionY(result.GetName()+"_%d" % x,x,x)
            one_pull = pull.ProjectionY(pull.GetName()+"_%d" % x,x,x)

            one_result.Fit(fit,"LQ")
            lin_result.SetBinContent(x,fit.GetParameter(1))
            lin_result.SetBinError(x,fit.GetParError(1))
            one_pull.Fit(fit,"LQ")
            lin_pull_mean.SetBinContent(x,fit.GetParameter(1))
            lin_pull_mean.SetBinError(x,fit.GetParError(1))
            lin_pull_sigma.SetBinContent(x,fit.GetParameter(2))
            lin_pull_sigma.SetBinError(x,fit.GetParError(2))

        fit = root.TF1("line","pol1")
        lin_result.Fit(fit,"Q")
        r2mpl.plot(lin_result, axes=a1, errors=True, color=colors[cpv])#, label=cpv_name)
        r2mpl.plot(fit, axes=a1, color=colors[cpv], label=cpv_name)

        if cpv.find(lp)>=0:
            fig,a = utils.get_plotaxes()
            a.set_title("%s, linearity" % cpv_name)
            a.set_xlabel("input %s" % lp_name)
            a.set_ylabel("%s fit result" % cpv_name)
            r2mpl.plot(lin_result, axes=a, errors=True, color=colors[cpv])#, label=cpv_name)
            r2mpl.plot(fit, axes=a, color=colors[cpv], label="result")

            lin_res = lin_result.Clone("tmp")
            for i in range(1,lin_res.GetNbinsX()+1):
                lin_res.SetBinContent(i,lin_res.GetBinContent(i)-lin_res.GetBinCenter(i))
            r2mpl.plot(lin_res, axes=a, errors=True, color="k")