Skip to content
Snippets Groups Projects
Commit 787c2fbe authored by Johannes Schumann's avatar Johannes Schumann
Browse files

Tests for output objects and corrected read to four-vector

parent ce8a5a0c
No related branches found
No related tags found
1 merge request!1Merge python environment
Pipeline #9397 passed
# 1:Run 2:Event 3:ID 4:Charge 5:perweight 6:position(1) 7:position(2) 8:position(3) 9:momentum(0) 10:momentum(1) 11:momentum(2) 12:momentum(3) 13:history 14:production_ID 15:enu
1 1 901 -1 6.154773E-01 0.000000E+00 0.000000E+00 0.000000E+00 5.050394E-01 2.619802E-02 3.290991E-01 3.821936E-01 0 2 1.000000E+00
1 1 1 1 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 9.380000E-01 0.000000E+00 0.000000E+00 0.000000E+00 0 2 1.000000E+00
1 1 101 1 6.154773E-01 0.000000E+00 0.000000E+00 0.000000E+00 3.918515E-01 -1.150792E-01 2.178788E-02 3.475423E-01 1000002 2 1.000000E+00
1 1 1 1 6.154773E-01 0.000000E+00 0.000000E+00 0.000000E+00 1.041109E+00 8.888118E-02 -3.508870E-01 2.702641E-01 1000002 2 1.000000E+00
......@@ -52,10 +52,11 @@ class FinalEvents:
('id', np.int32), ('charge', np.float64),
('perweight', np.float64), ('x', np.float64),
('y', np.float64), ('z', np.float64),
('p_x', np.float64), ('p_y', np.float64),
('p_z', np.float64), ('history', np.int32),
('pID', np.int32), ('energy', np.float64)])
return np.genfromtxt(StringIO('\n'.join(s)), dtype=dt)[::1]
('p_t', np.float64), ('p_x', np.float64),
('p_y', np.float64), ('p_z', np.float64),
('history', np.int32), ('pID', np.int32),
('energy', np.float64)])
return np.genfromtxt(StringIO('\n'.join(s)), dtype=dt)
def __len__(self):
return len(self._line_pos)
......
#!/usr/bin/env python
# coding=utf-8
# Filename: test_output.py
__author__ = "Johannes Schumann"
__copyright__ = "Copyright 2020, Johannes Schumann and the KM3NeT collaboration."
__credits__ = []
__license__ = "MIT"
__maintainer__ = "Johannes Schumann"
__email__ = "jschumann@km3net.de"
__status__ = "Development"
import unittest
import numpy as np
from km3buu.output import *
from os import listdir
from os.path import abspath, join, dirname
TESTDATA_DIR = abspath(join(dirname(__file__), "../data/test-data/"))
class TestFinalEvents(unittest.TestCase):
def setUp(self):
self.filename = join(TESTDATA_DIR, "FinalEvents.dat")
self.final_events = FinalEvents(self.filename)
def test_values(self):
assert self.final_events[0]["id"] == 901
assert self.final_events[0]["charge"] == -1
self.assertAlmostEqual(self.final_events[0]["perweight"], 6.154773e-1)
self.assertAlmostEqual(self.final_events[0]["p_t"], 5.050394e-1)
self.assertAlmostEqual(self.final_events[0]["p_x"], 2.619802e-2)
self.assertAlmostEqual(self.final_events[0]["p_y"], 3.290991e-1)
self.assertAlmostEqual(self.final_events[0]["p_z"], 3.821936e-1)
self.assertAlmostEqual(self.final_events[0]["energy"], 1.0)
assert self.final_events[3]["id"] == 1
assert self.final_events[3]["charge"] == 1
self.assertAlmostEqual(self.final_events[3]["perweight"], 6.154773e-1)
def test_index(self):
assert self.final_events[0] is not None
def test_slicing(self):
assert self.final_events[0:2] is not None
class TestGiBUUOutput(unittest.TestCase):
def setUp(self):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment