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
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")