Belle II Software development
svd_packer_unpacker.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12from svd import add_svd_simulation
13from ROOT import Belle2
14import numpy
15
16
17svd_digits_pack_unpack_collection = "SVDShaperDigits_test"
18b2.set_random_seed(42)
19
20
22
23 """
24 module which ckecks if two collection of SVDShaperDigits are equal
25 """
26
27 def sortDigits(self, unsortedPyStoreArray):
28 """ use some digit information to sort the SVDShaperDigits list
29 Returns a python-list containing the SVDShaperDigits
30 """
31
32 # first convert to a python-list to be abple 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.getSensorID().getLayerNumber(),
40 x.getSensorID().getLadderNumber(),
41 x.getSensorID().getSensorNumber(),
42 x.isUStrip()))
43
44 def event(self):
45 """ load SVDShaperDigits of the simulation and the packed/unpacked ones
46 and compare them"""
47
48 svdDigitsPackedUnpacked = Belle2.PyStoreArray(svd_digits_pack_unpack_collection)
49 # direct from simulation
50 svdDigits = Belle2.PyStoreArray("SVDShaperDigits")
51
52 svdDigits_sorted = self.sortDigits(svdDigits)
53 svdDigitsPackedUnpacked_sorted = self.sortDigits(svdDigitsPackedUnpacked)
54
55 if not len(svdDigits_sorted) == len(svdDigitsPackedUnpacked_sorted):
56 b2.B2FATAL("SVDShaperDigits count not equal after packing and unpacking")
57
58 # check all quantities between the direct and the packed/unpacked svd digits
59 for i in range(len(svdDigits_sorted)):
60
61 # sort the digits, because the packer sorts the
62 # the 32-bit frames are sorted by FADC numbers by the packer module
63 hit = svdDigits_sorted[i]
64 hitPackedUnpacked = svdDigitsPackedUnpacked_sorted[i]
65
66 # check content of the digit
67 assert hit.getTime() == hitPackedUnpacked.getTime()
68 assert hit.getIndex() == hitPackedUnpacked.getIndex()
69
70 # note: The charge will only be checked if between 0 and 255
71 # These two cases will be addressed in future SVDShaperDigits and packer/unpacker version
72 assert numpy.isclose(hit.getCharge(), hitPackedUnpacked.getCharge())
73
74 # check the VxdID information
75 assert hit.getSensorID().getID() == hitPackedUnpacked.getSensorID().getID()
76 assert hit.getSensorID().getLayerNumber() == hitPackedUnpacked.getSensorID().getLayerNumber()
77 assert hit.getSensorID().getLadderNumber() == hitPackedUnpacked.getSensorID().getLadderNumber()
78 assert hit.getSensorID().getSensorNumber() == hitPackedUnpacked.getSensorID().getSensorNumber()
79 assert hit.getSensorID().getSegmentNumber() == hitPackedUnpacked.getSensorID().getSegmentNumber()
80
81
82# to run the framework the used modules need to be registered
83particlegun = b2.register_module('ParticleGun')
84particlegun.param('pdgCodes', [13, -13])
85particlegun.param('nTracks', 10)
86
87# Create Event information
88eventinfosetter = b2.register_module('EventInfoSetter')
89eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
90# Show progress of processing
91progress = b2.register_module('Progress')
92
93main = b2.create_path()
94# init path
95main.add_module(eventinfosetter)
96main.add_module(particlegun)
97# add simulation for svd only
98add_svd_simulation(main)
99
100main.add_module(progress)
101
102nodeid = 0
103Packer = b2.register_module('SVDPacker')
104Packer.param('NodeID', nodeid)
105Packer.param('svdShaperDigitListName', 'SVDShaperDigits')
106Packer.param('rawSVDListName', 'SVDRaw')
107main.add_module(Packer)
108
109unPacker = b2.register_module('SVDUnpacker')
110unPacker.param('rawSVDListName', 'SVDRaw')
111unPacker.param('svdShaperDigitListName', svd_digits_pack_unpack_collection)
112main.add_module(unPacker)
113
114# run custom test module to check if the SVDShaperDigits and the
115# svd_digits_pack_unpack_collection collections are equal
116main.add_module(SvdPackerUnpackerTestModule())
117
118# Process events
119b2.process(main)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72