Belle II Software development
test_shaperdigit_sorter.py
1
8
9import basf2
10import ROOT
11from ROOT import Belle2
12import b2test_utils
13from svd import add_svd_reconstruction
14
15
16class CreateDigits(basf2.Module):
17 """Create SVD ShaperDigits"""
18
19 def __init__(self, digits):
20 """digits is a list of (sensor, side, strip) for which to generate a digit"""
21 super().__init__()
22
23 self.svddigits = Belle2.PyStoreArray("SVDShaperDigits")
24
25 self.digits = digits
26
27 self.samples = ROOT.array('unsigned char', 6)()
28
29 for i, sample in zip(range(6), [0, 0, 12, 18, 12, 8]):
30 self.samples[i] = sample
31
33
34 self.fadc_time = 0
35
36 def initialize(self):
37 '''initialize'''
38
39 self.svddigits.registerInDataStore()
40
41 def event(self):
42 '''event'''
43
44 for sensor, side, strip in self.digits:
45 d = self.svddigits.appendNew()
46 d.__assign__(Belle2.SVDShaperDigit(Belle2.VxdID(3, 1, sensor), side, strip, self.samples, self.fadc_time, self.mode))
47 print('\nGenerated digits:')
48 for digit in self.svddigits:
49 print("digit: sensor %s, side %s, strip %d" %
50 (digit.getSensorID(), 'u' if digit.isUStrip() else 'v', digit.getCellID()))
51
52
53class CheckOrderingOfDigits(basf2.Module):
54 """Check ordering of SVD digits"""
55
56 def event(self):
57 '''event'''
58
59 digits = Belle2.PyStoreArray("SVDShaperDigits")
60 current_ID = 0
61 for d in digits:
62 new_ID = d.getUniqueChannelID()
63 if new_ID > current_ID:
64 current_ID = new_ID
65 else:
66 Belle2.B2ERROR('Wrong ordering!')
67
68
69class PrintDigitsAndClusters(basf2.Module):
70 """Print all SVD digits and clusters"""
71
72 def event(self):
73 '''event'''
74
75 digits = Belle2.PyStoreArray("SVDShaperDigits")
76 clusters = Belle2.PyStoreArray("SVDClusters")
77 print('\nSorted digits and clusters:')
78 for d in digits:
79 print("digit: sensor %s, u-side %s, strip %d" %
80 (d.getSensorID(), d.isUStrip(), d.getCellID()))
81 for c in clusters:
82 print("cluster: sensor %s, side %s, position %d size %d" %
83 (c.getSensorID(), 'u' if c.isUCluster() else 'v', c.getPosition(), c.getSize()))
84
85
86if __name__ == "__main__":
88 # basf2.set_log_level(basf2.LogLevel.ERROR)
89 sig_digits = [
90 (2, False, 112),
91 (2, True, 66),
92 (1, True, 12),
93 (2, True, 65),
94 (1, True, 11),
95 (2, False, 113),
96 (1, True, 10)
97 ]
98
99 basf2.B2INFO('Test SVDShaperDigitSorter\n' +
100 'In this test, we generate some ShaperDigits in radnom order\n' +
101 'and insert them in the DataStore. Then we call shaper digit\n' +
102 'sorter module and check whether the digits are correctly sorted.\n')
103
104 test_ordering = basf2.create_path()
105 test_ordering.add_module("EventInfoSetter")
106 test_ordering.add_module("Gearbox")
107 test_ordering.add_module("Geometry", components=["SVD"])
108 test_ordering.add_module(CreateDigits(sig_digits))
109 test_ordering.add_module("SVDShaperDigitSorter")
110 add_svd_reconstruction(test_ordering)
111 test_ordering.add_module(PrintDigitsAndClusters())
112 test_ordering.add_module(CheckOrderingOfDigits())
113
114 result = b2test_utils.safe_process(test_ordering)
115 basf2.B2INFO(f'\nTest finished {["successfully", "with failure"][result]}.\n')
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
Class to store SVD mode information.
Definition: SVDModeByte.h:69
The SVD ShaperDigit class.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
def clean_working_directory()
Definition: __init__.py:189
def safe_process(*args, **kwargs)
Definition: __init__.py:236