Belle II Software light-2406-ragdoll
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
13from basf2 import create_path, process, set_random_seed, statistics, LogLevel, conditions
14import os
15import multiprocessing
16from b2test_utils import skip_test_if_light
17
18skip_test_if_light() # light builds don't contain particle gun
19set_random_seed(42)
20
21# create a path
22main = create_path()
23
24# generate 5 events
25main.add_module("EventInfoSetter", evtNumList=[5])
26
27# Add particle gun to shoot some pions and kaons at the ARICH
28main.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
33main.add_module('Progress')
34main.add_module('Gearbox')
35main.add_module('Geometry', useDB=False, components=['MagneticField', 'ARICH'], logLevel=LogLevel.ERROR)
36main.add_module('FullSim', logLevel=LogLevel.ERROR)
37# Add seqoutput but ignore write rate
38main.add_module('SeqRootOutput', outputFileName='seqout_test.sroot', logLevel=LogLevel.WARNING)
39
40# Run in sub process to avoid side effects
41sub = multiprocessing.Process(target=process, args=(main,))
42sub.start()
43sub.join()
44
45# Read file again
46conditions.disable_globaltag_replay()
47readpath = create_path()
48readpath.add_module('SeqRootInput', inputFileName='seqout_test.sroot')
49readpath.add_module('Progress')
50process(readpath)
51
52# remove input file
53os.remove('seqout_test.sroot')
54
55# and make sure everything is fine
56assert statistics.modules[1].name == 'Progress'
57assert statistics.modules[1].calls(statistics.EVENT) == 5