From d8622aca3249c1d8ebe510166b34125fae00ef9e Mon Sep 17 00:00:00 2001 From: Johannes Schumann <johannes.schumann@fau.de> Date: Sun, 4 Sep 2022 00:47:29 +0000 Subject: [PATCH] w2 write problem --- km3buu/output.py | 16 ++++++++++++---- km3buu/tests/test_config.py | 1 + km3buu/tests/test_ctrl.py | 2 ++ km3buu/tests/test_environment.py | 1 + km3buu/tests/test_jobcard.py | 4 ++++ km3buu/tests/test_output.py | 4 ++++ km3buu/tests/test_physics.py | 3 +++ km3buu/tests/test_propagation.py | 1 + 8 files changed, 28 insertions(+), 4 deletions(-) diff --git a/km3buu/output.py b/km3buu/output.py index dea5c4a..b4da6cd 100644 --- a/km3buu/output.py +++ b/km3buu/output.py @@ -276,6 +276,7 @@ def read_nu_abs_xsection(filepath): class GiBUUOutput: + def __init__(self, data_dir): """ Class for parsing GiBUU output files @@ -352,7 +353,13 @@ class GiBUUOutput: def _read_flux_file(self): fpath = join(self._data_path, FLUXDESCR_FILENAME) - self.flux_data = np.loadtxt(fpath, dtype=FLUX_INFORMATION_DTYPE) + self.flux_data = np.loadtxt(fpath, + dtype=FLUX_INFORMATION_DTYPE, + usecols=( + 0, + 1, + 2, + )) self.flux_interpolation = UnivariateSpline(self.flux_data["energy"], self.flux_data["events"]) self._energy_min = np.min(self.flux_data["energy"]) @@ -594,6 +601,7 @@ class GiBUUOutput: return self._generated_events def _determine_flux_index(self): + def fluxfunc(x, a, b): return a * x**b @@ -709,8 +717,8 @@ def write_detector_file(gibuu_output, header_dct = EMPTY_KM3NET_HEADER_DICT.copy() header_dct["target"] = element.name - for k,v in geometry.header_entries(gibuu_output._generated_events // - no_files).items(): + for k, v in geometry.header_entries(gibuu_output._generated_events // + no_files).items(): header_dct[k] = v header_dct["coord_origin"] = "{} {} {}".format(*geometry.coord_origin) header_dct["flux"] = "{:d} 0 0".format(nu_type) @@ -750,7 +758,7 @@ def write_detector_file(gibuu_output, evt.mc_run_id = mc_event_id # Weights evt.w.push_back(geometry.volume) #w1 (can volume) - evt.w.push_back(w2[mc_event_id]) #w2 + evt.w.push_back(w2[start_id + mc_event_id]) #w2 evt.w.push_back(-1.0) #w3 (= w2*flux) # Event Information (w2list) evt.w2list.resize(W2LIST_LENGTH) diff --git a/km3buu/tests/test_config.py b/km3buu/tests/test_config.py index 18e2a13..65436a0 100644 --- a/km3buu/tests/test_config.py +++ b/km3buu/tests/test_config.py @@ -32,6 +32,7 @@ path=/tmp/gseagen class TestConfig(unittest.TestCase): + def setUp(self): self.cfg_tmpfile = NamedTemporaryFile(delete=False) self.mock_image_file = NamedTemporaryFile(delete=False) diff --git a/km3buu/tests/test_ctrl.py b/km3buu/tests/test_ctrl.py index cfa278a..6ed8493 100644 --- a/km3buu/tests/test_ctrl.py +++ b/km3buu/tests/test_ctrl.py @@ -29,6 +29,7 @@ GIBUU_INSTALL_AVAILABLE = environ.get("CONTAINER_GIBUU_EXEC") is not None @pytest.mark.skipif(not GIBUU_INSTALL_AVAILABLE, reason="GiBUU not installed") class TestCTRLbyJobcardFile(unittest.TestCase): + def setUp(self): self.filename = join(TESTDATA_DIR, "km3net_testdata.job") self.output_dir = TemporaryDirectory() @@ -53,6 +54,7 @@ class TestCTRLbyJobcardFile(unittest.TestCase): @pytest.mark.skipif(not GIBUU_INSTALL_AVAILABLE, reason="GiBUU not installed") class TestCTRLbyJobcardObject(unittest.TestCase): + def setUp(self): log = get_logger("ctrl.py") log.setLevel("INFO") diff --git a/km3buu/tests/test_environment.py b/km3buu/tests/test_environment.py index 247690b..b5d76bf 100644 --- a/km3buu/tests/test_environment.py +++ b/km3buu/tests/test_environment.py @@ -19,6 +19,7 @@ from km3buu import DOCKER_URL, IMAGE_NAME class TestBuild(unittest.TestCase): + def test_wrong_dir_path(self): wrong_path = "foobar" try: diff --git a/km3buu/tests/test_jobcard.py b/km3buu/tests/test_jobcard.py index 195dc38..20f7fb1 100644 --- a/km3buu/tests/test_jobcard.py +++ b/km3buu/tests/test_jobcard.py @@ -26,6 +26,7 @@ if GIBUU_INSTALL_AVAILABLE: class TestJobcard(unittest.TestCase): + def setUp(self): self.test_jobcard = Jobcard() # Insert some test elements @@ -55,6 +56,7 @@ class TestJobcard(unittest.TestCase): class TestNeutrinoEnergyRangeJobcard(unittest.TestCase): + def setUp(self): self.test_fluxfile = TemporaryFile() self.test_Z = np.random.randint(1, 100) @@ -105,6 +107,7 @@ class TestNeutrinoEnergyRangeJobcard(unittest.TestCase): class TestNeutrinoSingleEnergyJobcard(unittest.TestCase): + def setUp(self): self.test_fluxfile = TemporaryFile() self.test_Z = np.random.randint(1, 100) @@ -140,6 +143,7 @@ class TestNeutrinoSingleEnergyJobcard(unittest.TestCase): @pytest.mark.skipif(not GIBUU_INSTALL_AVAILABLE, reason="GiBUU not installed") class TestJobcardSeed(unittest.TestCase): + def setUp(self): jc = generate_neutrino_jobcard(100, "CC", diff --git a/km3buu/tests/test_output.py b/km3buu/tests/test_output.py index dd30ad5..fe6141f 100644 --- a/km3buu/tests/test_output.py +++ b/km3buu/tests/test_output.py @@ -37,6 +37,7 @@ except ModuleNotFoundError: class TestXSection(unittest.TestCase): + def test_xsection_all(self): filename = join(TESTDATA_DIR, XSECTION_FILENAMES["all"]) xsection = read_nu_abs_xsection(filename) @@ -47,6 +48,7 @@ class TestXSection(unittest.TestCase): class TestGiBUUOutput(unittest.TestCase): + def setup_class(self): self.output = GiBUUOutput(TESTDATA_DIR) @@ -91,6 +93,7 @@ class TestGiBUUOutput(unittest.TestCase): @pytest.mark.skipif(not KM3NET_LIB_AVAILABLE, reason="KM3NeT dataformat required") class TestOfflineFile(unittest.TestCase): + def setUp(self): output = GiBUUOutput(TESTDATA_DIR) datafile = NamedTemporaryFile(suffix=".root") @@ -145,6 +148,7 @@ class TestOfflineFile(unittest.TestCase): @pytest.mark.skipif(not KM3NET_LIB_AVAILABLE, reason="KM3NeT dataformat required") class TestMultiFileOutput(unittest.TestCase): + def setUp(self): output = GiBUUOutput(TESTDATA_DIR) datafile = NamedTemporaryFile(suffix=".root") diff --git a/km3buu/tests/test_physics.py b/km3buu/tests/test_physics.py index 29efb84..ac11fae 100644 --- a/km3buu/tests/test_physics.py +++ b/km3buu/tests/test_physics.py @@ -28,6 +28,7 @@ MUON_TESTFILE = join(dirname(__file__), "data/muon_range_seawater.txt") class TestMuonRangeSeaWater(unittest.TestCase): + def setUp(self): self.ref_values = np.loadtxt(MUON_TESTFILE).T @@ -39,6 +40,7 @@ class TestMuonRangeSeaWater(unittest.TestCase): class TestVisEnergyParticle(unittest.TestCase): + def setUp(self): with open(PARTICLE_TESTFILE, "r") as f: tmp = f.readline() @@ -57,6 +59,7 @@ class TestVisEnergyParticle(unittest.TestCase): class TestVisEnergyWeightFunctions(unittest.TestCase): + def setUp(self): self.ref_values = np.loadtxt(FUNCTIONS_TESTFILE).T diff --git a/km3buu/tests/test_propagation.py b/km3buu/tests/test_propagation.py index 27d1704..b1cbea9 100644 --- a/km3buu/tests/test_propagation.py +++ b/km3buu/tests/test_propagation.py @@ -28,6 +28,7 @@ pp.RandomGenerator.get().set_seed(1234) @pytest.mark.skip(reason="CI boost lib problem") class TestTauPropagation(unittest.TestCase): + def setUp(self): data = ak.Array({ "lepOut_E": [ -- GitLab