diff --git a/km3buu/jobcard.py b/km3buu/jobcard.py index 14013d9eac9933658691b5d8a92b275078d82d58..a03f217c936a97dfac60369874d56046135eb491 100644 --- a/km3buu/jobcard.py +++ b/km3buu/jobcard.py @@ -104,6 +104,7 @@ def generate_neutrino_jobcard(events, do_decay=False, photon_propagation=True, fluxfile=None, + seed=0, input_path=INPUT_PATH): # pragma: no cover """ Generate a jobcard for neutrino interaction @@ -130,6 +131,9 @@ def generate_neutrino_jobcard(events, Propagate photons and write it out fluxfile: str (default: None) Fluxfile, 1st col energy [GeV] and 2nd col flux [A.U.] + seed: int (default: 0) + Input seed for the random number generator in GiBUU + (0: some seed will be drawn based on system time) input_path: str The input path pointing to the GiBUU lookup data which should be used """ @@ -175,6 +179,7 @@ def generate_neutrino_jobcard(events, jc["eventoutput"]["writeperturbativeparticles"] = write_pert jc["eventoutput"]["writerealparticles"] = write_real # MISC + jc["initRandom"]["Seed"] = seed jc["insertion"]["propagateNoPhoton"] = not photon_propagation return jc diff --git a/km3buu/tests/test_jobcard.py b/km3buu/tests/test_jobcard.py index 66b1162161db75a41876da0375604cdee621821f..6fc45b08949ab74b1a53076233d43e7375dec8fa 100644 --- a/km3buu/tests/test_jobcard.py +++ b/km3buu/tests/test_jobcard.py @@ -12,8 +12,11 @@ __status__ = "Development" import unittest import numpy as np +from itertools import combinations from km3buu.jobcard import * -from tempfile import TemporaryFile +from km3buu.ctrl import run_jobcard +from km3buu.output import GiBUUOutput +from tempfile import TemporaryFile, TemporaryDirectory class TestJobcard(unittest.TestCase): @@ -127,3 +130,22 @@ class TestNeutrinoSingleEnergyJobcard(unittest.TestCase): def test_photon_propagation_flag(self): self.assertEqual(self.test_jobcard["insertion"]["propagateNoPhoton"], not self.photon_propagation_flag) + + +class TestJobcardSeed(unittest.TestCase): + def setUp(self): + jc = generate_neutrino_jobcard(100, + "CC", + "electron", (1.0, 2.0), (1, 1), + do_decay=False, + photon_propagation=False, + seed=1234) + self.dfs = [] + for i in range(2): + output_dir = TemporaryDirectory() + run_jobcard(jc, output_dir.name, container=True) + self.dfs.append(GiBUUOutput(output_dir.name).df) + + def test_output(self): + for a, b in combinations(self.dfs, 2): + assert all((a == b).all(1))