15Check that random numbers don't change and are consistent.
17This steering file runs through a set of exp/run combinations and prints
18the first few random numbers in initialize(), beginRun(), event() and endRun().
20It also sets the framework to debugging output and shows the information used
21to calculate the random generator state.
26from ROOT
import gRandom
29def double_to_hex(double):
30 """Convert a double to a hex string representation"""
33 return f
"{struct.unpack('<Q', struct.pack('<d', double))[0]:016X}"
36class RandomTestModule(basf2.Module):
37 """Print some random numbers to check reproducibility"""
39 def __init__(self, name):
40 """Make sure we can run in multiple processes"""
42 self.set_property_flags(basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED)
46 def get_numbers(self, name):
47 """Print the first 20 random numbers"""
48 numbers = [f
"First 20 random values in {self.name}::{name}()"]
50 numbers.append(
", ".join(double_to_hex(gRandom.Rndm())
for i
in range(4)))
51 basf2.B2INFO(
"\n ".join(numbers))
54 """Show random numbers in initialize"""
55 self.get_numbers(
"initialize")
58 """Show random numbers in beginRun"""
59 self.get_numbers(
"beginRun")
62 """Show random numbers in event"""
63 self.get_numbers(
"event")
66 """Show random numbers in endRun"""
67 self.get_numbers(
"endRun")
73main.add_module(
"EventInfoSetter", evtNumList=[3, 4, 5],
74 runList=[0x11121314, 0x21222324, 0x31323334],
75 expList=[0x123, 0x234, 0x345])
80main.add_module(
"EventInfoPrinter")
81main.add_module(RandomTestModule(
"test1"))
82main.add_module(
"RandomBarrier")
83main.add_module(RandomTestModule(
"test2"))
86logging_framework = basf2.logging.package(
"framework")
89logging_framework.set_log_level(basf2.LogLevel.DEBUG)
90logging_framework.set_debug_level(200)
91logging_framework.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
92basf2.set_random_seed(
"this is the seed")