diff --git a/eos-toys/plot-sample.py b/eos-toys/plot-sample.py index e3dc8b8..70cd247 100644 --- a/eos-toys/plot-sample.py +++ b/eos-toys/plot-sample.py @@ -2,7 +2,7 @@ # @Author: Elena Graverini # @Date: 2017-03-16 11:20:45 # @Last Modified by: Elena Graverini -# @Last Modified time: 2017-03-22 08:25:24 +# @Last Modified time: 2017-04-04 17:53:49 # import matplotlib from __future__ import division import sys, os, gc @@ -45,11 +45,30 @@ # p1d.histogram(0, xmin=None, xmax=None, kde=None) -def superimpose(files, labels, outname): +def make_pickle(pkl_file, input_file): + datafile = MCMCDataFile(input_file) + gc.collect() + data = datafile.data()[:, 0] + d = {} + reduced_data = data[::10] + d['reduced_data'] = reduced_data + n, bins, patches = plt.hist(reduced_data, bins=100, normed=True, alpha=0.3) + bin_centers = (bins[:-1] + bins[1:]) / 2 + d['bin_contents'] = n + d['bin_centers'] = bin_centers + pickle.dump(d, open(pkl_file, 'wb')) + plt.savefig(pkl_file.replace('.pkl', '.pdf')) + + +def superimpose(files, datafiles, labels, outname): colors = ['#0078FF', '#FF6600', '#0AAFB6', '#FF3333', '#0000FF', '#00CC00', '#BF8040', '#FF33CC', '#FF7733'] ds = [] - for f in files: - ds.append(pickle.load(open(f, 'rb'))) + for i, f in enumerate(files): + try: + ds.append(pickle.load(open(f, 'rb'))) + except IOError: + make_pickle(f, datafiles[i]) + ds.append(pickle.load(open(f, 'rb'))) for i in range(len(files)): plt.plot(ds[i]['bin_centers'], ds[i]['bin_contents'], label=labels[i], color=colors[i], linewidth=2.0) plt.legend(loc='best') @@ -75,12 +94,49 @@ my = [0.147214, 0.14805, 0.147707, 0.147292, 0.145776, 0.143623, 0.140846, 0.137443, 0.133406, 0.12872, 0.123359, 0.117288, 0.110451, 0.102761, 0.0940879, 0.0842141, 0.0727531, 0.0589096, 0.0404804] mxt = [3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5] myt = [0.00641833, 0.0194386, 0.0789258, 0.140122, 0.189971, 0.225482, 0.24678, 0.254695, 0.249817, 0.231917, 0.198965, 0.143346] - makeFileFromMarzia(mx, my, marzia_f) - makeFileFromMarzia(mxt, myt, marzia_ft) - files_mu = ['constantFF/mcmc_gamma_muons.pkl', '1pole/mcmc_gamma_muons_1pole.pkl', '1pole_x_sqrtlambda/mcmc_gamma_muonss_1pole_x_sqrtlambda.pkl', marzia_f] + # makeFileFromMarzia(mx, my, marzia_f) + # makeFileFromMarzia(mxt, myt, marzia_ft) + files_mu = ['constantFF/mcmc_gamma_muons.pkl', + '1pole/mcmc_gamma_muons_1pole.pkl', + '1pole_x_sqrtlambda/mcmc_gamma_muonss_1pole_x_sqrtlambda.pkl', + marzia_f, + 'linear/mcmc_gamma_muons_linear_rho-0_05.pkl', + 'linear/mcmc_gamma_muons_linear_rho0_00.pkl', + 'linear/mcmc_gamma_muons_linear_rho0_05.pkl', + ] + datafiles_mu = ['constantFF/mcmc_gamma-mu.hdf5', + '1pole/mcmc_samples-mu.hdf5', + '1pole_x_sqrtlambda/mcmc_samples-mu-sqrtlambda.hdf5', + None, + 'linear/mcmc_samples-rho-0.05-mu.hdf5', + 'linear/mcmc_samples-rho0.00-mu.hdf5', + 'linear/mcmc_samples-rho0.05-mu.hdf5' + ] out_mu = 'comparison_mu.pdf' - files_tau = ['constantFF/mcmc_gamma_taus.pkl', '1pole/mcmc_gamma_taus_1pole.pkl', '1pole_x_sqrtlambda/mcmc_gamma_taus_1pole_x_sqrtlambda.pkl', marzia_ft] + files_tau = ['constantFF/mcmc_gamma_taus.pkl', + '1pole/mcmc_gamma_taus_1pole.pkl', + '1pole_x_sqrtlambda/mcmc_gamma_taus_1pole_x_sqrtlambda.pkl', + marzia_ft, + 'linear/mcmc_gamma_taus_linear_rho-0_05.pkl', + 'linear/mcmc_gamma_taus_linear_rho0_00.pkl', + 'linear/mcmc_gamma_taus_linear_rho0_05.pkl', + ] + datafiles_tau = ['constantFF/mcmc_gamma-tau.hdf5', + '1pole/mcmc_samples-tau.hdf5', + '1pole_x_sqrtlambda/mcmc_samples-tau-sqrtlambda.hdf5', + None, + 'linear/mcmc_samples-rho-0.05-tau.hdf5', + 'linear/mcmc_samples-rho0.00-tau.hdf5', + 'linear/mcmc_samples-rho0.05-tau.hdf5', + ] out_tau = 'comparison_tau.pdf' - labels = ['Constant FF', 'One pole', r'One pole $\times\; \sqrt{\lambda}$', 'MB: constant FF'] - superimpose(files_mu, labels, out_mu) - superimpose(files_tau, labels, out_tau) + labels = ['Constant FF', + 'One pole', + r'One pole $\times\; \sqrt{\lambda}$', + 'MB: constant FF', + r'linear, $\rho=-0.05$', + r'linear, $\rho=0.0$', + r'linear, $\rho=0.05$', + ] + superimpose(files_mu, datafiles_mu, labels, out_mu) + superimpose(files_tau, datafiles_tau, labels, out_tau)