Ejemplo n.º 1
0
Archivo: mu.py Proyecto: vedant8/nuVeto
def hist_preach(infile):
    """ Builds histograms of P_reach based on MMC output text
    """
    Hist = namedtuple('Hist', 'counts edges')
    df = pd.read_csv(infile,
                     delim_whitespace=True,
                     header=None,
                     names='ei l ef'.split())
    # If the muon doesn't reach, MMC saves ef as -distance traveled
    df[df < 0] = 0
    preach = []
    for (ei, l), efs in df.groupby(['ei', 'l']):
        bins = calc_bins(efs['ef'])
        histo = Hist(*np.histogram(efs['ef'], bins=bins, density=True))
        [
            preach.append((ei, l, ef, ew, val)) for ef, ew, val in zip(
                centers(histo.edges), np.ediff1d(histo.edges), histo.counts)
        ]

    return np.asarray(preach)
Ejemplo n.º 2
0
def hist_preach(infile, plotdir=None):
    import pandas as pd
    napf = 36
    df = pd.read_csv(infile,
                     delim_whitespace=True,
                     header=None,
                     names='ei l ef'.split())
    # If the muon doesn't reach, MMC saves ef as -distance traveled
    df[df < 0] = 0
    for idx, (ei, sdf) in enumerate(df.groupby('ei')):
        if idx % napf == 0:
            if idx > 0:
                # plt.legend(fontsize=6)
                plt.tight_layout()
                if plotdir is not None:
                    plt.savefig(
                        os.path.join(os.path.expanduser(plotdir),
                                     '{}.png'.format((idx - 1) / napf)))
            fig, axs = plt.subplots(6, 6, figsize=(10, 10))
            # fig.text(0.5, 0.04, r'$E_f$', ha='center', va='center')
            # fig.text(0.06, 0.5, r'$P(E_f|E_i, l)$', ha='center', va='center', rotation='vertical')
            axs = axs.flatten()
        ax = axs[idx % napf]
        ax.set_prop_cycle('color', plt.cm.Blues(np.linspace(0.3, 1, 100)))
        plt.sca(ax)
        plt.title(r'${:.2g}$ GeV'.format(ei), fontdict={'fontsize': 8})
        for l, efs in sdf.groupby('l'):
            bins = calc_bins(efs['ef'])
            counts, edges = np.histogram(efs['ef'], bins=bins, density=True)
            plt.plot(centers(edges), counts, label='{:.3g} km'.format(l / 1e3))
        plt.yscale('log')
        # plt.xlim(sdf['ef'].min(), sdf['ef'].max()*1.1)
    # plt.legend(fontsize=6)
    plt.tight_layout()
    if plotdir is not None:
        plt.savefig(
            os.path.join(os.path.expanduser(plotdir), '{}.png'.format(
                (idx - 1) / napf)))