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

Added object for parsing neutrino Xsection output

parent 2247a605
No related branches found
No related tags found
1 merge request!1Merge python environment
Pipeline #9411 passed with warnings
# 1:var 2:sum 3:QE 4:Delta 5:highRES 6:1pi 7:DIS 8:2p2h-QE 9:2p2h-Delta 10:2pi
1.0000 0.61548 0.0000 0.61537 0.10661E-03 0.0000 0.0000 0.0000 0.0000 0.0000
......@@ -12,12 +12,29 @@ __maintainer__ = "Johannes Schumann"
__email__ = "jschumann@km3net.de"
__status__ = "Development"
import re
import mmap
import numpy as np
from io import StringIO
from os import listdir
from os.path import isfile, join, abspath
EVENT_FILENAME = "FinalEvents.dat"
XSECTION_FILENAMES = {"all": "neutrino_absorption_cross_section_ALL.dat"}
class NeutrinoAbsorptionXSection:
def __init__(self, filepath):
self._filepath = filepath
with open(self._filepath, "r") as f:
lines = f.readlines()
header = re.sub(r'\d+:|#', '', lines[0]).split()
values = map(float, lines[1].split())
self._xsections = dict(zip(header, values))
def __getitem__(self, key):
return self._xsections[key]
class FinalEvents:
def __init__(self, filepath):
......
......@@ -19,9 +19,21 @@ from os.path import abspath, join, dirname
TESTDATA_DIR = abspath(join(dirname(__file__), "../data/test-data/"))
class TestXSection(unittest.TestCase):
def test_xsection_all(self):
filename = join(TESTDATA_DIR, XSECTION_FILENAMES["all"])
xsection = NeutrinoAbsorptionXSection(filename)
self.assertAlmostEqual(xsection['var'], 1.0)
self.assertAlmostEqual(xsection['sum'], 0.61548)
self.assertAlmostEqual(xsection['Delta'], 0.61537)
self.assertAlmostEqual(xsection['highRES'], 1.0661e-4)
self.assertAlmostEqual(xsection['Delta'], 0.61537)
class TestFinalEvents(unittest.TestCase):
def setUp(self):
self.filename = join(TESTDATA_DIR, "FinalEvents.dat")
self.filename = join(TESTDATA_DIR, EVENT_FILENAME)
self.final_events = FinalEvents(self.filename)
def test_values(self):
......
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