16from ROOT
import Belle2
20from rawdata
import add_packers
21from rawdata
import add_unpackers
23pxd_rawhits_pack_unpack_collection =
"PXDRawHits_test"
24pxd_rawhits_pack_unpack_collection_digits =
"PXDDigits_test"
25pxd_rawhits_pack_unpack_collection_adc = pxd_rawhits_pack_unpack_collection +
"_adc"
26pxd_rawhits_pack_unpack_collection_roi = pxd_rawhits_pack_unpack_collection +
"_roi"
33 Module which checks if a collection of PXDDigits and
34 a collection of PXDRawHits from the packing/unpacking procedure are equal.
35 The PXDUnpacker does not create PXDDigits but PXDRawHits and therefore these two lists
39 def __init__(self, rawhits_collection='PXDRawHits', digits_collection="PXDDigits"):
41 # call constructor of base class, required if you implement __init__ yourself!
43 # and do whatever else is necessary like declaring member variables
45 self.rawhits_collection = rawhits_collection
47 self.digits_collection = digits_collection
49 def sortDigits(self, unsortedPyStoreArray):
50 """ use a some digit information to sort the PXDDigits list
51 Returns a python-list containing the PXDDigts
54 # first convert to a python-list to be abple to sort
55 py_list = [x for x in unsortedPyStoreArray]
57 # sort via a hierarchy of sort keys
65 def sortRawHits(self, unsortedPyStoreArray):
66 """ use a some digit information to sort the PXDRawHits list
67 Returns a python-list containing the PXDRawHits
70 # first convert to a python-list to be able to sort
71 py_list = [x for x in unsortedPyStoreArray]
73 # sort via a hierarchy of sort keys
82 """ load the PXD Digits of the simulation and the packed/unpacked ones
85 # load the digits and the collection which results from the packer and unpacker
86 # processed by packer and unpacker
87 pxdRawHitsPackedUnpacked_unsorted = Belle2.PyStoreArray(self.rawhits_collection)
88 # direct from simulation
89 pxdDigits_unsorted = Belle2.PyStoreArray(self.digits_collection)
91 # sort the digits, because the order gets
92 # lost during the packing/unpacking process
93 pxdDigits = self.sortDigits(pxdDigits_unsorted)
94 pxdRawHitsPackedUnpacked = self.sortRawHits(pxdRawHitsPackedUnpacked_unsorted)
96 if not len(pxdDigits) == len(pxdRawHitsPackedUnpacked):
97 b2.B2FATAL("PXDDigits and PXDRawHits count not equal after packing and unpacking")
99 print(f"Comparing {len(pxdDigits)} pxd digits ")
101 # check all quantities between the direct and the packed/unpacked pxd digits
102 for i in range(len(pxdDigits)):
104 rawHitPackedUnpacked = pxdRawHitsPackedUnpacked[i]
106 # compare all available quantities
107 # cannot compare frame number, because it is not available on PXDDigits
108 assert rawHitPackedUnpacked.getSensorID().getID() == digit.getSensorID().getID()
109 assert rawHitPackedUnpacked.getRow() == digit.getVCellID()
110 assert rawHitPackedUnpacked.getColumn() == digit.getUCellID()
111 # There are some rare cases (~ every 10th event), where the PXD Digits have a charge
112 # larger than 255 which will be clipped by the packer to 8bit (at most 255)
113 # therefore, limit the maximal charge of the digit here in the comparison
114 assert numpy.isclose(min(255.0, digit.getCharge()), rawHitPackedUnpacked.getCharge())
117# to run the framework the used modules need to be registered
118particlegun = b2.register_module('ParticleGun')
119particlegun.param('pdgCodes', [13, -13])
120particlegun.param('nTracks', 10)
122# Create Event information
123eventinfosetter = b2.register_module('EventInfoSetter')
124eventinfosetter.param({'evtNumList': [50]})
125# Show progress of processing
126progress = b2.register_module('Progress')
128main = b2.create_path()
130main.add_module(eventinfosetter)
131main.add_module(particlegun)
132# add simulation for pxd only
133simulation.add_simulation(main, components=['PXD'], forceSetPXDDataReduction=True, usePXDDataReduction=False)
134b2.set_module_parameters(main, type="Geometry", useDB=False, components=["PXD"])
136main.add_module(progress)
138# Create raw data form simulated digits
139add_packers(main, components=['PXD'])
141# Unpack raw data to pack_unpack_collections
142add_unpackers(main, components=['PXD'])
144# Change names of collections to avoid conflicts
145for e in main.modules():
146 if e.name() == 'PXDUnpacker':
147 e.param("PXDRawHitsName", pxd_rawhits_pack_unpack_collection)
148 e.param("PXDRawAdcsName", pxd_rawhits_pack_unpack_collection_adc)
149 e.param("PXDRawROIsName", pxd_rawhits_pack_unpack_collection_roi)
151 if e.name() == 'PXDRawHitSorter':
152 e.param('rawHits', pxd_rawhits_pack_unpack_collection)
153 e.param('digits', pxd_rawhits_pack_unpack_collection_digits)
156# run custom test module to check if the simulated PXDDigits and the
157# pxd_digits_pack_unpack_collection collections are equal
158main.add_module(PxdPackerUnpackerTestModule(rawhits_collection=pxd_rawhits_pack_unpack_collection, digits_collection="PXDDigits"))
161# run custom test module 2nd time to check if the collection pxd_rawhits_pack_unpack_collection_digits
162# and the pxd_digits_pack_unpack_collection collections are equal
164 PxdPackerUnpackerTestModule(
165 rawhits_collection=pxd_rawhits_pack_unpack_collection,
166 digits_collection=pxd_rawhits_pack_unpack_collection_digits))
__init__(self, rawhits_collection='PXDRawHits', digits_collection="PXDDigits")