Belle II Software development
arich_packer_unpacker.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12from ROOT import Belle2
13from simulation import add_simulation
14
15
16b2.set_random_seed(12345)
17
18
19class PackerUnpackerTest(b2.Module):
20
21 """
22 module which ckecks if two collections of ARICHDigits are equal
23 """
24
25 def sortDigits(self, unsortedPyStoreArray):
26 """
27 Use some digit information to sort the digits
28 Returns a python-list containing the sorted digits
29 """
30
31 # first convert to a python-list to be able to sort
32 py_list = [x for x in unsortedPyStoreArray]
33
34 # sort via a hierachy of sort keys
35 return sorted(
36 py_list,
37 key=lambda x: (
38 x.getModuleID(),
39 x.getChannelID())
40 )
41
42 def event(self):
43 """
44 load original ARICHDigits and the packed/unpacked ones, sort and compare them
45 """
46
47 # direct from simulation
48 digits = Belle2.PyStoreArray("ARICHDigits")
49 # processed by packer and unpacker
50 digitsUnpacked = Belle2.PyStoreArray("ARICHDigitsUnpacked")
51
52 # sort digits
53 digits_sorted = self.sortDigits(digits)
54 digitsUnpacked_sorted = self.sortDigits(digitsUnpacked)
55
56 # check the sizes
57 if not len(digits_sorted) == len(digitsUnpacked_sorted):
58 b2.B2FATAL("ARICHDigits: size not equal after packing and unpacking")
59
60 # check all quantities between the direct and the packed/unpacked
61 for i in range(len(digits_sorted)):
62
63 digit = digits_sorted[i]
64 digitUnpacked = digitsUnpacked_sorted[i]
65
66 # check the content of the digit
67 assert digit.getModuleID() == digitUnpacked.getModuleID()
68 assert digit.getChannelID() == digitUnpacked.getChannelID()
69 assert digit.getBitmap() == digitUnpacked.getBitmap()
70
71
72main = b2.create_path()
73
74eventinfosetter = b2.register_module('EventInfoSetter')
75eventinfosetter.param({'evtNumList': [10]})
76main.add_module(eventinfosetter)
77
78particlegun = b2.register_module('ParticleGun')
79particlegun.param('momentumGeneration', 'fixed')
80particlegun.param('momentumParams', 6.0)
81particlegun.param('pdgCodes', [13, -13])
82particlegun.param('nTracks', 10)
83particlegun.param('thetaGeneration', 'uniformCos')
84particlegun.param('thetaParams', [20.0, 25.0])
85
86main.add_module(particlegun)
87
88add_simulation(main, components=['ARICH'])
89b2.set_module_parameters(main, type="Geometry", useDB=False, components=["ARICH"])
90
91Packer = b2.register_module('ARICHPacker')
92main.add_module(Packer)
93
94unPacker = b2.register_module('ARICHUnpacker')
95
96unPacker.param('outputDigitsName', 'ARICHDigitsUnpacked')
97main.add_module(unPacker)
98
99main.add_module(PackerUnpackerTest())
100
101progress = b2.register_module('Progress')
102main.add_module(progress)
103
104b2.process(main)
105print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
def sortDigits(self, unsortedPyStoreArray)