19from ROOT
import Belle2
20from unittest
import TestCase
21from ROOT
import gRandom
25logLevel = b2.LogLevel.INFO
28eclDigitsDatastoreName =
'ECLDigits'
29unpackerOutputDatastoreName =
'someECLUnpackerDatastoreName'
34 Adds ECLDigits with very large/small time/amplitude values
40 amps = [0, 1, 100000, 262015]
41 times = [-2048, -100, 0, 100, 2047]
42 qualitys = [0, 1, 2, 3]
43 chis = [0, 1, 254, 511]
44 paramNames = ["amp", "time", "quality", "chi"]
45 ## ecl digit parameters
46 self.digitParams = [dict(zip(paramNames, params)) for params in itertools.product(amps, times, qualitys, chis)]
52 eclDigitsFromSimulation = Belle2.PyStoreArray(eclDigitsDatastoreName)
54 # Check for used cellIds
55 usedCellIds = list(map(lambda eclDigit: eclDigit.getCellId(), eclDigitsFromSimulation))
57 # Create new ECLDigits and add them to datastore
58 for digitParam in self.digitParams:
59 # Skip combination of quality != 2 and chi != 0. Electronics can't output this
60 if (digitParam['quality'] != 2) and (digitParam['chi'] != 0):
63 # Skip combination of quality == 2 and amp != 0. Electronics can't output this
64 if (digitParam['quality'] == 2) and (digitParam['time'] != 0):
67 # Choose cellId that's not already used
68 cellId = int(gRandom.Uniform(1, 8736))
69 while cellId in usedCellIds:
70 cellId = int(gRandom.Uniform(1, 8736))
72 usedCellIds.append(cellId)
74 eclDigit = Belle2.ECLDigit()
77 eclDigit.setCellId(cellId)
78 eclDigit.setAmp(digitParam['amp'])
79 eclDigit.setTimeFit(digitParam['time'])
80 eclDigit.setQuality(digitParam['quality'])
81 eclDigit.setChi(digitParam['chi'])
83 # Add ECLDigit to datastore
84 newDigit = eclDigitsFromSimulation.appendNew()
85 newDigit.__assign__(eclDigit)
88class ECLPackerUnpackerTestModule(b2.Module):
90 module which checks if two collections of ECLDigits are equal
93 def sortECLDigits(self, unsortedPyStoreArray):
94 """ use a some information to sort the ECLDigits list
95 Returns a python-list containing the ECLDigits
97 # first convert to a python-list to be able to sort
98 py_list = [x for x in unsortedPyStoreArray]
100 # sort via a hierarchy of sort keys
111 # load the ECLDigits that were packed and unpacked
112 eclDigitsPackedUnpacked_unsorted = Belle2.PyStoreArray(unpackerOutputDatastoreName)
113 # ECLDigits direct from simulation
114 eclDigitsFromSimulation_unsorted = Belle2.PyStoreArray(eclDigitsDatastoreName)
116 if not len(eclDigitsFromSimulation_unsorted) == len(eclDigitsPackedUnpacked_unsorted):
117 b2.B2FATAL("Different number of ECLDigits from simulation and after packing+unpacking")
119 eclDigitsPackedUnpacked = self.sortECLDigits(eclDigitsPackedUnpacked_unsorted)
120 eclDigitsFromSimulation = self.sortECLDigits(eclDigitsFromSimulation_unsorted)
122 tc = TestCase('__init__')
124 # check all quantities between the direct and the packed/unpacked ECLDigits
125 for idx in range(len(eclDigitsPackedUnpacked)):
126 digit = eclDigitsFromSimulation[idx]
127 digitPackedUnpacked = eclDigitsPackedUnpacked[idx]
129 b2.B2DEBUG(5, 'MC digit: cellid = ' +
130 str(digit.getCellId()) +
132 str(digit.getAmp()) +
134 str(digit.getTimeFit()) +
136 str(digit.getQuality()) +
138 str(digit.getChi()) +
139 '\nUnpackedDigit: cellid = ' +
140 str(digitPackedUnpacked.getCellId()) +
142 str(digitPackedUnpacked.getAmp()) +
144 str(digitPackedUnpacked.getTimeFit()) +
146 str(digitPackedUnpacked.getQuality()) +
148 str(digitPackedUnpacked.getChi()))
150 tc.assertEqual(digit.getCellId(), digitPackedUnpacked.getCellId())
151 tc.assertEqual(digit.getAmp(), digitPackedUnpacked.getAmp())
152 tc.assertEqual(digit.getTimeFit(), digitPackedUnpacked.getTimeFit())
153 tc.assertEqual(digit.getQuality(), digitPackedUnpacked.getQuality())
154 tc.assertEqual(digit.getChi(), digitPackedUnpacked.getChi())
157main = b2.create_path()
158# Create Event information
159eventinfosetter = b2.register_module('EventInfoSetter')
160eventinfosetter.param({'evtNumList': [10]})
161main.add_module(eventinfosetter)
163# to run the framework the used modules need to be registered
164particlegun = b2.register_module('ParticleGun')
165particlegun.param('pdgCodes', [13, -13])
166particlegun.param('nTracks', 10)
167main.add_module(particlegun)
169# add simulation for ECL only
170simulation.add_simulation(main, components=['ECL'])
171b2.set_module_parameters(main, type="Geometry", useDB=False, components=["ECL"])
173# Add ECLDigits with wide range of amp, time, quality, chi2
174main.add_module(addECLDigitsModule())
176# add the packer which packs the ECLDigits from the simulation
177ecl_packer = b2.register_module('ECLPacker')
178main.add_module(ecl_packer)
180# add the unpacker which unpacks the RawECL into ECLDigits and store them in a separate datstore container
181ecl_unpacker = b2.register_module('ECLUnpacker')
182# set the unpacker output datastore name, so that we don't overwrite the "normal" ECLDigits
183ecl_unpacker.param('ECLDigitsName', unpackerOutputDatastoreName)
184main.add_module(ecl_unpacker)
186# Run test module to check if the original ECLDigits and the ones that were packed and unpacked are identical
187eclPackUnpackerChecker = ECLPackerUnpackerTestModule()
188main.add_module(eclPackUnpackerChecker, logLevel=logLevel)