Belle II Software  release-08-01-10
arich_packer_unpacker.py
1 #!/usr/bin/env python
2 
3 
10 
11 import basf2 as b2
12 from ROOT import Belle2
13 from simulation import add_simulation
14 
15 
16 b2.set_random_seed(12345)
17 
18 
19 class 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.sortDigitssortDigits(digits)
54  digitsUnpacked_sorted = self.sortDigitssortDigits(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 
72 main = b2.create_path()
73 
74 eventinfosetter = b2.register_module('EventInfoSetter')
75 eventinfosetter.param({'evtNumList': [10]})
76 main.add_module(eventinfosetter)
77 
78 particlegun = b2.register_module('ParticleGun')
79 particlegun.param('momentumGeneration', 'fixed')
80 particlegun.param('momentumParams', 6.0)
81 particlegun.param('pdgCodes', [13, -13])
82 particlegun.param('nTracks', 10)
83 particlegun.param('thetaGeneration', 'uniformCos')
84 particlegun.param('thetaParams', [20.0, 25.0])
85 
86 main.add_module(particlegun)
87 
88 add_simulation(main, components=['ARICH'])
89 b2.set_module_parameters(main, type="Geometry", useDB=False, components=["ARICH"])
90 
91 Packer = b2.register_module('ARICHPacker')
92 main.add_module(Packer)
93 
94 unPacker = b2.register_module('ARICHUnpacker')
95 
96 unPacker.param('outputDigitsName', 'ARICHDigitsUnpacked')
97 main.add_module(unPacker)
98 
99 main.add_module(PackerUnpackerTest())
100 
101 progress = b2.register_module('Progress')
102 main.add_module(progress)
103 
104 b2.process(main)
105 print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
def sortDigits(self, unsortedPyStoreArray)