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