def fbDiffDist(xi): x, y = np.meshgrid(np.linspace(-1., 1., 101), np.linspace(-1., 1., 101)) z = csec2DRaw(x, y, xi) z = z / z.max() plt.figure(num=1, figsize=(5, 4)) cnt = plt.contourf(x, y, z, levels=100, cmap=plt.cm.viridis, vmin=0, vmax=1) plt.colorbar(cnt) plt.axis('equal') plt.xlabel(r'$\cos{\theta}$', fontsize=16) plt.ylabel(r'$\cos{\theta_1}$', fontsize=16) plt.tight_layout() plt.savefig('/'.join([plotpath, 'fbdist_xi{}.pdf'.format(strxi(xi))])) plt.savefig('/'.join([plotpath, 'fbdist_xi{}.png'.format(strxi(xi))])) plt.show()
def drawCorrMtx(lbl, mtx, xi=None, show=True): """ """ labels = [varttl[key] for key in list(varttl.keys())[:mtx.shape[0]]] print(labels) fig, ax = plt.subplots() im, cbar = heatmap(mtx, labels, labels, ax=ax, cmap="coolwarm_r", cbarlabel=None) texts = annotate_heatmap(im, valfmt="{x:.2f}") fig.tight_layout() fname = 'corr_mtx_{}'.format(lbl) if xi is not None: fname = fname + '_xi_{}'.format(strxi(xi)) print('Correlation matrix saved in file {}'.format(fname)) plt.savefig('/'.join([plotpath, '{}.pdf'.format(fname)])) plt.savefig('/'.join([plotpath, '{}.png'.format(fname)])) if show: plt.show()
def drawFitBiasXi(lbl, fresxi, nevt): """ """ xil = [floxi(xi) for xi in fresxi.keys()] keys = list(fresxi[strxi(xil[0])].keys()) vals = {key: [] for key in keys} for xi, fres in fresxi.items(): for key, [mean, err] in fres.items(): tval = floxi(xi) if key == 'xi' else pars[key] err = err / np.sqrt(nevt) bias = (mean - tval) / err vals[key].append(bias) for key, val in vals.items(): val = np.array(val) plt.figure(figsize=(6, 5)) plt.errorbar(xil, val, yerr=1., marker='.', markersize=12, linestyle='none', label=varttl[key]) print('chi2 = {:.3}'.format(np.sum(val**2) / val.shape[0])) ylabel = r'pull({})'.format(varttl[key]) plt.xlabel(r'$\xi$', fontsize=16) plt.ylabel(ylabel, fontsize=16) plt.ylim([-3., 3.]) plt.grid() plt.tight_layout() fname = 'bias_{}_{}'.format(lbl, key) print('Save in {}'.format(fname)) plt.savefig('/'.join([plotpath, fname + '.png'])) plt.savefig('/'.join([plotpath, fname + '.pdf'])) plt.show()
def drawPrecisionNevt(lbl, var, xil, fresxi): """ """ plt.rc('font', size=14) n = np.logspace(6, 9) for xi in xil: err = fresxi[strxi(xi)][var][1] print(xi, err) if err is not None: plt.plot(n, err / np.sqrt(n) / xi, label=r'$\xi=${:.1f}'.format(xi)) plt.grid(which='both') plt.semilogx() plt.semilogy() plt.ylabel(r'$d\xi/\xi$') plt.xlabel(r'$N$') plt.xlim((10**6, 10**9)) plt.ylim((1e-4, 2e-2)) plt.legend(loc='best') plt.tight_layout() plt.savefig('/'.join([plotpath, '{}_{}_prec.pdf'.format(lbl, var)])) plt.savefig('/'.join([plotpath, '{}_{}_prec.png'.format(lbl, var)])) plt.show()
def corxi(dataxi): return OrderedDict([[strxi(xi), d['fitcor']] for xi, d in dataxi.items()])
def frexi(dataxi): return OrderedDict([[strxi(xi), d['fitres']] for xi, d in dataxi.items()])