diff --git a/km3buu/output.py b/km3buu/output.py index dea5c4aeae78c1807038f7814d72921c6fc1ddac..b4da6cdbe552b2177ad9e3af99a4729d5076634b 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 18e2a13ec87d2122279a0a15a349da9e2a446e9c..65436a054e56e37945cb31052ebd130f6d406112 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 cfa278a1a80f00343e27eb59be56c26e4f12f2e6..6ed8493e8654bf12995f61719ce8f5a0395d7248 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 247690b1e66adda9d5c3c93be01c24a19f5738d8..b5d76bf3b4819b7aecf1d7fe1452ee86ee2d1c58 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 195dc38f45be7cc756e64d75ff3689beffa97f79..20f7fb19e155a343a219025b7d10a7bba36964dd 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 dd30ad5f223a4e6147c331adb8d32400231993f6..fe6141f7ef7dfddcb35974bde1106bfbb8fddea4 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 29efb84ccf8800d1806eb17f54d26ab04f4bf7af..ac11fae0d72e58730b3214ce5424437cbb556f08 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 27d17044e99561100afe8ee46058e0732a1d1420..b1cbea92d9438be21a0338bf6da515b32b386950 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": [