Ejemplo n.º 1
0
def perform_simulations():
    cq = CorsikaQuery(OVERVIEW)
    s = set()
    for energy in pbar(cq.available_parameters('energy', particle='proton')):
        for zenith in cq.available_parameters('zenith',
                                              particle='proton',
                                              energy=energy):
            sims = cq.simulations(particle='proton',
                                  zenith=zenith,
                                  energy=energy,
                                  iterator=False)
            selected_seeds = cq.seeds(sims)
            n = min(len(selected_seeds), N)
            for seeds in choice(selected_seeds, n, replace=False):
                if seeds in s:
                    continue
                if not os.path.exists(
                        '/data/hisparc/corsika/data/{seeds}/corsika.h5'.format(
                            seeds=seeds)):
                    continue
                s.add(seeds)
                if energy >= 16:
                    perform_job(seeds, 'long')
                elif energy >= 14.5:
                    perform_job(seeds, 'generic')
                else:
                    perform_job(seeds, 'short')
    cq.finish()
Ejemplo n.º 2
0
def plot_shower_size(leptons=['electron', 'muon']):
    plot = Plot(axis='semilogy')
    cq = CorsikaQuery(OVERVIEW)
    p = 'proton'
    for e in sorted(cq.available_parameters('energy', particle=p)):
        median_size = []
        min_size = []
        max_size = []
        zeniths = sorted(cq.available_parameters('zenith', energy=e, particle=p))
        for z in zeniths:
            selection = cq.simulations(zenith=z, energy=e, particle=p)
            n_leptons = selection['n_%s' % leptons[0]]
            for lepton in leptons[1:]:
                n_leptons += selection['n_%s' % lepton]
            sizes = percentile(n_leptons, [16, 50, 84])
            min_size.append(sizes[0] if sizes[0] else 0.1)
            median_size.append(sizes[1] if sizes[1] else 0.1)
            max_size.append(sizes[2] if sizes[2] else 0.1)
        if len(zeniths):
            plot.plot(zeniths, median_size, linestyle='very thin')
            plot.shade_region(zeniths, min_size, max_size,
                              color='lightgray, semitransparent')
            plot.add_pin('%.1f' % e, relative_position=0)

    plot.set_xticks([t for t in arange(0, 60.1, 7.5)])
    plot.set_ylimits(1, 1e9)
    plot.set_ylabel(r'Shower size (leptons)')
    plot.set_xlabel(r'Zenith [\si{\degree}]')
    plot.save_as_pdf('shower_sizes_%s' % '_'.join(leptons))
    cq.finish()
Ejemplo n.º 3
0
def collect_efficiencies():
    """Reconstruct shower (direction) for eligible events"""
    counts = {}
    all_counts = {}
    n = {}
    cq = CorsikaQuery(OVERVIEW)
    for path in glob.glob(PATHS):
        seeds = os.path.basename(path)[:-3]
        sim = cq.get_info(seeds)
        energy = log10(sim['energy'])
        zenith = degrees(sim['zenith'])
        count, all_count = detection_efficiency(path)

        # Check if its the first of this energy
        try:
            counts[energy]
            all_counts[energy]
        except KeyError:
            counts[energy] = {}
            all_counts[energy] = {}

        # Check if its the first of this energy and zenith
        try:
            counts[energy][zenith] += count
            all_counts[energy][zenith] += all_count
        except KeyError:
            counts[energy][zenith] = count
            all_counts[energy][zenith] = all_count
    cq.finish()

    efficiencies = {}
    errors = {}
    for e in counts.keys():
        efficiencies[e] = {}
        errors[e] = {}
        for z in counts[e].keys():
            efficiencies[e][z] = counts[e][z] / all_counts[e][z]
            errors[e][z] = sqrt(counts[e][z] + 1) / all_counts[e][z]

    return efficiencies, errors
Ejemplo n.º 4
0
def plot_shower_size_distributions():
    plot = Plot(axis='semilogx')
    cq = CorsikaQuery(OVERVIEW)
    p = 'proton'
    z = 0
    for e in sorted(cq.available_parameters('energy', particle=p, zenith=z)):
        selection = cq.simulations(zenith=z, energy=e, particle=p)
        n_leptons = selection['n_muon'] + selection['n_electron']
        plot.histogram(*histogram(n_leptons, bins=logspace(0, 9, 200)))
        plot.add_pin('%.1f' % e, x=mean(n_leptons), location='above')
    plot.set_ylimits(min=0)
    plot.set_xlimits(1, 1e9)
    plot.set_ylabel(r'pdf')
    plot.set_xlabel(r'Shower size (leptons)')
    plot.save_as_pdf('shower_size_distribution')
    cq.finish()
Ejemplo n.º 5
0
def get_info(seeds):
    cq = CorsikaQuery(OVERVIEW)
    info = cq.get_info(seeds)
    cq.finish()
    return info
Ejemplo n.º 6
0
    plot.set_xlabel(r'First interaction altitude [m]')
    plot.set_ylabel(r'Counts')
    plot.save_as_pdf('plots/interaction_altitude_distribution')


def plot_interaction_altitude_size(cq):
    for p in ['proton', 'iron', 'gamma']:
        for z in cq.available_parameters('zenith', particle=p):
            sims = cq.simulations(zenith=z, particle=p)
            altitudes = sims['first_interaction_altitude'] / 1e3
            size = sims['n_electron'] + sims['n_muon']
            alt_size_hist = histogram2d(
                altitudes,
                size,
                bins=[linspace(0, 70, 100),
                      logspace(0, 9, 100)])
            plot = Plot('semilogy')
            plot.histogram2d(*alt_size_hist, bitmap=True, type='color')
            plot.set_xlabel(r'First interaction altitude [m]')
            plot.set_ylabel(r'Shower size')
            plot.save_as_pdf('plots/interaction_altitude_v_size_%s_%.1f.pdf' %
                             (p if p is not None else 'all', z))


if __name__ == "__main__":
    cq = CorsikaQuery(OVERVIEW)
    plot_interaction_height(cq)
    plot_interaction_altitude_distribution(cq)
    plot_interaction_altitude_size(cq)
    cq.finish()
Ejemplo n.º 7
0
def plot_size_energy():
    cq = CorsikaQuery(OVERVIEW)
    p = 'proton'
    plot = Plot(axis='semilogy')
    for z in cq.available_parameters('zenith', particle=p):
        zen_plot = Plot(axis='semilogy')
        shade = 'black!%f' % (100 - z)

        energies = sorted(cq.available_parameters('energy', particle=p,
                                                  zenith=z))
        sizes_m = []
        sizes_e = []
        sizes_l = []
        energies_m = []
        energies_e = []
        energies_l = []

        for e in energies:
            selection = cq.simulations(zenith=z, energy=e, particle=p)
            if median(selection['n_muon']):
                sizes_m.append(median(selection['n_muon']))
                energies_m.append(e)
            if median(selection['n_electron']):
                sizes_e.append(median(selection['n_electron']))
                energies_e.append(e)
            if median(selection['n_muon'] + selection['n_electron']):
                sizes_l.append(median(selection['n_muon'] + selection['n_electron']))
                energies_l.append(e)

        # Plot data points
        zen_plot.scatter(energies_m, sizes_m, mark='+')
        zen_plot.scatter(energies_e, sizes_e, mark='x')
        zen_plot.scatter(energies_l, sizes_l, mark='square')
        plot.scatter(energies_l, sizes_l, mark='square', markstyle=shade)

        # Fit
        initial = (10.2, 1.)
        popt_m, pcov_m = curve_fit(f, energies_m, log10(sizes_m), p0=initial)
        popt_e, pcov_e = curve_fit(f, energies_e, log10(sizes_e), p0=initial)
        popt, pcov = curve_fit(f, energies_l, log10(sizes_l), p0=initial)

        # Plot fits
        fit_energies = arange(10, 20, 0.25)
        sizes = [10 ** f(e, *popt_m) for e in fit_energies]
        zen_plot.plot(fit_energies, sizes, mark=None, linestyle='red')

        sizes = [10 ** f(e, *popt_e) for e in fit_energies]
        zen_plot.plot(fit_energies, sizes, mark=None, linestyle='blue')

        sizes = [10 ** f(e, *popt) for e in fit_energies]
        zen_plot.plot(fit_energies, sizes, mark=None)
        plot.plot(fit_energies, sizes, mark=None, linestyle=shade)

        zen_plot.set_ylimits(1, 1e9)
        zen_plot.set_xlimits(10.5, 18.5)
        zen_plot.set_ylabel(r'Shower size [number of leptons]')
        zen_plot.set_xlabel(r'Shower energy [log10(E/eV)]')
        zen_plot.save_as_pdf('shower_size_v_energy_%.1f.pdf' % z)
    plot.set_ylimits(1, 1e9)
    plot.set_xlimits(10.5, 18.5)
    plot.set_ylabel(r'Shower size [number of leptons]')
    plot.set_xlabel(r'Shower energy [log10(E/eV)]')
    plot.save_as_pdf('shower_size_v_energy')
    cq.finish()
Ejemplo n.º 8
0
        return choice(result)
    except IndexError:
        return None


def get_seed_matrix(seeds, particle, energy, zenith):
    """Get random seed for each combination of Zenith and Energy.

    :param seeds,particle,energy,zenith: columns from simulations table.

    """
    unique_energy = get_unique(energy)
    unique_zenith = get_unique(zenith)

    for en in unique_energy:
        for zen in unique_zenith:
            seed = get_random_seed(seeds, particle, energy, zenith, en, zen)
            print('Energy: 10^%d, Zenith: %4.1f: %s' %
                  (en, numpy.degrees(zen), seed))


if __name__ == '__main__':
    with tables.open_file(OVERVIEW, 'r') as overview:
        cq = CorsikaQuery(overview)
        plot_n_leptons(cq)
        plot_energy_zenith(cq)
        plot_energy_zenith_per_particle(cq)

#     plot_azimuth(azimuth)
#     get_seed_matrix(seeds, particle, energy, zenith)
Ejemplo n.º 9
0
import os

from sapphire import CorsikaQuery, qsub

OVERVIEW = '/data/hisparc/corsika/corsika_overview.h5'
SCRIPT = """\
#!/usr/bin/env bash
python /data/hisparc/adelaat/corsika_accuracy/simulation_station_time.py {seeds}
"""

if __name__ == "__main__":
    cq = CorsikaQuery(OVERVIEW)
    for e in [15, 15.5, 16, 16.5, 17]:
        sims = cq.simulations(zenith=0, energy=e, particle='proton')
        seeds_set = set(cq.seeds(sims))
        print e
        for n in range(min(20, len(seeds_set), qsub.check_queue('generic'))):
            seeds = seeds_set.pop()
            if os.path.exists('%s.h5' % seeds):
                continue
            print seeds,
            qsub.submit_job(SCRIPT.format(seeds=seeds), 'cors_accu_%s' % seeds,
                            'generic')
    cq.finish()