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