cpv_result = [jc_result, js1_result, js2_result, bl_result, bbar_svd1_result, bbar_svd2_result] cpv_pull = [root.TH1D(e.GetName()+"_pull","",100,-5,5) for e in cpv_result] cpv_params = ["signal_dt_Jc", "signal_dt_Js1", "signal_dt_Js2", "signal_dt_blifetime", "yield_bbar_svd1", "yield_bbar_svd2"] cpv_input = [params(e).value for e in cpv_params] for parfile in run_jobs(False, True): if not os.path.exists(parfile): continue params.load(parfile) br = params("yield_signal_br").value br_error = params("yield_signal_br").error br_result.Fill(br) br_pull.Fill((br-utils.br)/br_error) for i,p in enumerate([params(e) for e in cpv_params]): cpv_result[i].Fill(p.value) cpv_pull[i].Fill((p.value-cpv_input[i])/p.error) a,m,s = draw_toyMC(br_result, r"fit results, input=$%s$" % utils.format_error(utils.br, precision=1), "$\mathcal{B}(\ddk)$", exponent=-3, ylabel=r"Entries / \num{%s}" % br_result.GetBinWidth(1)) a.set_ylim(0, br_result.GetMaximum()*1.5) draw_toyMC(br_pull,"pull distribution", xlabel=r"Pull($\mathcal{B}(\ddk)$)", ylabel="Entries / %s" % br_pull.GetBinWidth(1)) names = [r"$J_C/J_0$", r"$(2J_{s1}/J_0) \sin(2\phi_1)$", r"$(2J_{s2}/J_0) \cos(2\phi_1)$",r"$\tau / ps$","m1","m2"] for i,name in enumerate(names): hist = cpv_result[i] pull = cpv_pull[i] draw_toyMC(hist, r"fit results, input=$%.3g$" % cpv_input[i], xlabel=name, ylabel="Entries / %s" % hist.GetBinWidth(1)) draw_toyMC(pull, r"pull distribution", xlabel="Pull(%s)" % name, ylabel="Entries / %s" % pull.GetBinWidth(1)) r2mpl.save_all("toymc/toymc-%s" % toyname, png=False, single_pdf=True)
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([ [%.7e, %.7e], [%.7e, %.7e], ])""" % tuple(ctl_eff.flat)
if axes[0] and axes[1]: plot_asymmetry(data[0], data[1], fits[0], fits[1], label, val1, val2) # Make sure the two plots have the same y-axis range ymax = max(a.get_ylim()[1] for a in axes) ymin = min(a.get_ylim()[0] for a in axes) for a in axes: a.set_ylim(ymin=ymin, ymax=ymax) try: make_mBCdE_plots("mbcde_svd1", "SVD1") except ValueError: pl.close("all") make_mBCdE_plots("mbcde_svd2", "SVD2") make_mBCdE_plots("mbcde", "SVD1 + SVD2") r2mpl.save_all(filename + "-mBCdE", png=False, single_pdf=True) qname = "pm" qval = ["-1","+1"] tname = ["q","qe"] tval = ["q", "q\eta"] #dT plots for svd in range(3): svdtitle = svd>0 and "SVD{0}, ".format(svd) or "SVD1 + SVD2, " for q in range(2): for eta in range(2): make_dT_plots("dT_svd{0}_q{1}_e{2}".format(svd, qname[q], qname[eta]), title1="{0}$q={1}$, $\eta={2}$".format(svdtitle, qval[q], qval[eta])) for qt in range(2): names = ["dT_svd{0}_{1}{2}".format(svd, tname[qt], qname[val]) for val in range(2)]
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) toymc.draw_toyMC(pull,title + ", pull") r2mpl.save_all(infile,png=False,single_pdf=True)
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") lin_pull_mean.Fit(fit,"Q") r2mpl.plot(lin_pull_mean, axes=a2, errors=True, color=colors[cpv])#, label=cpv_name) r2mpl.plot(fit, axes=a2, color=colors[cpv], label=cpv_name) lin_pull_sigma.Fit(fit,"Q") r2mpl.plot(lin_pull_sigma, axes=a3, errors=True, color=colors[cpv])#, label=cpv_name) r2mpl.plot(fit, axes=a3, color=colors[cpv], label=cpv_name) a1.set_ylim(-1.5,1.5) a2.set_ylim(-1.0,1.0) a3.set_ylim( 0.0,2.0) a1.legend(loc="upper left") a2.legend(loc="upper left") a3.legend(loc="upper left") r2mpl.save_all(infile,png=False)
import sys import os import glob import dspdsmks import utils import matplotlib from matplotlib import pyplot as pl import pyroot as pr import r2mpl import toymc params = dspdsmks.Parameters() lifetime = root.TH1D("b_lifetime", "b_lifetime", 40, 1.20, 1.55) pull_lifetime = root.TH1D("p_lifetime", "b_lifetime", 40, -3, 3) for par in glob.glob("toymc/ctrl-dt/*.out"): params.load(par) v = params("signal_dt_blifetime").value e = params("signal_dt_blifetime").error lifetime.Fill(v) pull_lifetime.Fill((v-1.519)/(e**2+0.007**2)**.5) toymc.draw_toyMC(lifetime, r"fit result", r"$\tau_{\PBz}$ / ps", ylabel=r"Entries / \num{%s}" % lifetime.GetBinWidth(1), box="tr")[0].axvline(1.519,c="b",ls="--") toymc.draw_toyMC(pull_lifetime, r"pull distribution", r"Pull($\tau_{\PBz}$)", ylabel=r"Entries / \num{%s}" % pull_lifetime.GetBinWidth(1), box="tr")[0].axvline(0,c="b",ls="--") r2mpl.save_all("vary_lifetime", png=False, single_pdf=True)