コード例 #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
            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)

    elif isinstance(result,root.TH1D):
        toymc.draw_toyMC(result,title)