Пример #1
0
    def test(self):
        print sys.argv
        global filename
        if filename is None: filename = corsika.example_data_dir + '/DAT000002-32'
        assert os.path.exists(filename)
        f = corsika.ShowerFile(filename)
        assert f.find_event(1) == corsika.Status.eSuccess

        shower = f.current_shower

        assert shower.primary == 2212
        assert shower.energy == 100000.0
        assert shower.muon_number == 1335.0
        self.assertAlmostEqual(shower.zenith, 0.3490658, 6)
        self.assertAlmostEqual(shower.azimuth, 3.0609822, 6)
        assert shower.min_radius_cut == 0.
        assert shower.shower_number == 1
        self.assertAlmostEqual(shower.em_energy_cutoff, 0.003)
        self.assertAlmostEqual(shower.muon_energy_cutoff, 0.3)

        a=0
        for i,p in enumerate(shower.particles):
            if i < reference.shape[0]:
                assert numpy.all(numpy.isclose([p.description, p.px, p.py, p.pz, p.x, p.y, p.t_or_z], reference[i], 3))
                assert p.weight == 1
                assert p.observing_level == 0
                assert p.corsika_code == int(reference[i,0]/1e3)
                assert p.pdg_code == corsika.ParticleList.corsika_to_pdg(int(reference[i,0]/1e3))
                assert p.hadronic_generation == int((reference[i,0]%1000)/10)
                assert p.has_muon_info == (p.corsika_code == 5 or p.corsika_code == 6) # muons
                assert p.has_parent == False
            a += 1
        assert a == 181992
        assert f.find_event(2) == corsika.Status.eFail
Пример #2
0
    def test(self):
        global filename
        if filename is None:
            filename = corsika.example_data_dir + '/DAT000011-proton-EHISTORY-MUPROD'
        assert os.path.exists(filename)

        #print 'opening', filename
        f = corsika.ShowerFile(filename)
        f.find_event(1)
        shower = f.current_shower
        particle_it = shower.particles

        raw = corsika.RawStream(filename)
        block = corsika.Block()
        raw.get_next_block(block)  # RUNH
        raw.get_next_block(block)  # EVTH
        raw_particle_it = raw.particles()

        raw_particles = numpy.zeros(len([p for p in raw_particle_it]),
                                    dtype=raw_ptype)
        raw_particle_it.rewind()
        i = 0
        for p in raw_particle_it:
            raw_particle2dtype(p, raw_particles[i])
            i += 1

        particle_it = shower.particles
        l = len([p for p in particle_it])
        particles = numpy.zeros(l, dtype=ptype)
        parents = numpy.zeros(l, dtype=ptype)
        grand_parents = numpy.zeros(l, dtype=ptype)
        parents['code'] = -99999999999
        grand_parents['code'] = -99999999999
        particle_it.rewind()
        i = 0
        for p in particle_it:
            particle2dtype(p, particles[i])
            if p.has_parent:
                particle2dtype(p.parent, parents[i])
                particle2dtype(p.grand_parent, grand_parents[i])
            i += 1

        parent_mask = parents['code'] != -99999999999
        grandparent_mask = grand_parents['code'] != -99999999999

        muon_mask = (particles['code'] == 6) + (particles['code'] == 5) + (
            particles['code'] == 95) + (particles['code'] == 96)
        electron_mask = (particles['code'] == 3) + (particles['code'] == 2)
        gamma_mask = (particles['code'] == 1)

        raw_muon_mask = (raw_particles['code'] == 6) + (
            raw_particles['code'] == 5) + (raw_particles['code'] == 95) + (
                raw_particles['code'] == 96)
        raw_electron_mask = (raw_particles['code']
                             == 3) + (raw_particles['code'] == 2)
        raw_gamma_mask = (raw_particles['code'] == 1)

        # the following raw entries are filtered by the high-level interface:
        raw_invalid_mask = raw_particles[
            'description'] == 0  # these are trailing particles, between the last particle and the end of the block
        raw_history_mask = raw_particles[
            'description'] < 0  # these are EHISTORY particles, which are accessed as members of high-level particles
        raw_undefined_mask = raw_particles[
            'pdg'] == 0  # these entries have no entry in the particle table (very rare particles)

        muons = particles[muon_mask]
        raw_muons = raw_particles[raw_muon_mask * ~raw_invalid_mask *
                                  ~raw_history_mask * ~raw_undefined_mask *
                                  (raw_particles['level'] == 1)]

        def test(condition, message):
            if not condition: print 'FAIL:', message
            assert test

        def test_equal(left, right, message):
            if not left == right:
                print 'FAIL:', message, ":", left, "!=", right
            assert left == right

        test_equal(len(raw_particles), 294645, "total number of raw particles")

        test_equal(len(particles), 254188, "total number of particles")

        test_equal(
            len(particles),
            len(raw_particles[~raw_invalid_mask * ~raw_history_mask *
                              ~raw_undefined_mask *
                              (raw_particles['level'] == 1)]),
            "discrepancy in number of particles")

        test_equal(
            len(raw_particles[raw_muon_mask * ~raw_invalid_mask *
                              ~raw_history_mask * ~raw_undefined_mask *
                              (raw_particles['level'] == 1)]),
            len(particles[muon_mask]), "discrepancy in number of muons")

        test_equal(
            len(raw_particles[raw_electron_mask * ~raw_invalid_mask *
                              ~raw_history_mask * ~raw_undefined_mask *
                              (raw_particles['level'] == 1)]),
            len(particles[electron_mask]),
            "discrepancy in number of electrons")

        test_equal(
            len(raw_particles[raw_gamma_mask * ~raw_invalid_mask *
                              ~raw_history_mask * ~raw_undefined_mask *
                              (raw_particles['level'] == 1)]),
            len(particles[gamma_mask]), "discrepancy in number of gammas")

        test_equal(len(particles[parent_mask * muon_mask]),
                   len(particles[muon_mask]),
                   "discrepancy in number of muons and muon parents")

        test(numpy.all(raw_muons['x'] == muons['x']), 'x differs')
        test(numpy.all(raw_muons['y'] == muons['y']), 'y differs')
        test(numpy.all(raw_muons['px'] == muons['px']), 'px differs')
        test(numpy.all(raw_muons['py'] == muons['py']), 'py differs')

        t_offset = numpy.mean(
            raw_muons['z_or_t'] -
            muons['z_or_t'])  # particle times might be shifted
        test(
            numpy.all(
                numpy.abs(raw_muons['z_or_t'] - muons['z_or_t'] -
                          t_offset) < 1e-1), 'T or z differs')
Пример #3
0
import sys

try:
    import icecube
    within_icecube = True
except:
    within_icecube = False

if within_icecube: from icecube import corsika
else: import corsika

from ROOT import *

if len(sys.argv)>1:
    filename = sys.argv[1]
else:
    filename = corsika.example_data_dir + '/DAT000002-32'

f = corsika.ShowerFile(filename)

h = TH2F('ground_particles', 'Ground Particles', 100, -5000, 5000, 100, -5000, 5000)
h.GetXaxis().SetTitle('X/m')
h.GetYaxis().SetTitle('Y/m')

f.find_event(1)
for particle in f.current_shower.particles:
    c = h.Fill(particle.x/100., particle.y/100.)

h.Draw('surf1')
gPad.SetLogz()