Belle II Software  release-08-01-10
seqroot_output.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # Test whether we can create and read a sequential root file with 5 events
12 
13 from basf2 import create_path, process, set_random_seed, statistics, LogLevel, conditions
14 import os
15 import multiprocessing
16 from b2test_utils import skip_test_if_light
17 
18 skip_test_if_light() # light builds don't contain particle gun
19 set_random_seed(42)
20 
21 # create a path
22 main = create_path()
23 
24 # generate 5 events
25 main.add_module("EventInfoSetter", evtNumList=[5])
26 
27 # Add particle gun to shoot some pions and kaons at the ARICH
28 main.add_module('ParticleGun', pdgCodes=[211, -211, 321, -321],
29  momentumGeneration="fixed", momentumParams=[3],
30  thetaGeneration="uniform", thetaParams=[17, 25])
31 
32 # Add everything we need to simulate just ARICH
33 main.add_module('Progress')
34 main.add_module('Gearbox')
35 main.add_module('Geometry', useDB=False, components=['MagneticField', 'ARICH'], logLevel=LogLevel.ERROR)
36 main.add_module('FullSim', logLevel=LogLevel.ERROR)
37 # Add seqoutput but ignore write rate
38 main.add_module('SeqRootOutput', outputFileName='seqout_test.sroot', logLevel=LogLevel.WARNING)
39 
40 # Run in sub process to avoid side effects
41 sub = multiprocessing.Process(target=process, args=(main,))
42 sub.start()
43 sub.join()
44 
45 # Read file again
46 conditions.disable_globaltag_replay()
47 readpath = create_path()
48 readpath.add_module('SeqRootInput', inputFileName='seqout_test.sroot')
49 readpath.add_module('Progress')
50 process(readpath)
51 
52 # remove input file
53 os.remove('seqout_test.sroot')
54 
55 # and make sure everything is fine
56 assert statistics.modules[1].name == 'Progress'
57 assert statistics.modules[1].calls(statistics.EVENT) == 5