Belle II Software development
cdc_packer_unpacker.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12from ROOT import Belle2
13
14import simulation
15
16cdc_hits = "CDCHits"
17cdc_hits_pack_unpack_collection = "CDCHits_test_output"
18b2.set_random_seed(42)
19
20
21class PackerUnpackerTestModule(b2.Module):
22
23 """
24 module which checks if two collection of CDCHits are equal
25 """
26
27 def sortHits(self, unsortedPyStoreArray):
28 """ use a some information to sort the CDCHits list
29 Returns a python-list containing the CDCHits
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.getILayer(),
40 x.getISuperLayer(),
41 x.getIWire()))
42
43 def event(self):
44 """
45 event function
46 """
47
48 # load the cdcHits and the collection which results from the packer and unpacker
49 # processed by packer and unpacker
50 cdcHitsPackedUnpacked_unsorted = Belle2.PyStoreArray(cdc_hits_pack_unpack_collection)
51 # direct from simulation
52 cdcHits_unsorted = Belle2.PyStoreArray(cdc_hits)
53
54 # sort the hits, because they have been shuffled in the packing/unpacking process
55 cdcHitsPackedUnpacked = self.sortHits(cdcHitsPackedUnpacked_unsorted)
56 cdcHits = self.sortHits(cdcHits_unsorted)
57
58 if not len(cdcHits) == len(cdcHitsPackedUnpacked):
59 b2.B2FATAL("CDC Hit count not equal after packing and unpacking")
60
61 # check all quantities between the direct and the packed/unpacked CDC hit
62 for i in range(len(cdcHits)):
63 hit = cdcHits[i]
64 hitPackedUnpacked = cdcHitsPackedUnpacked[i]
65
66 assert hit.getILayer() == hitPackedUnpacked.getILayer()
67 assert hit.getISuperLayer() == hitPackedUnpacked.getISuperLayer()
68 assert hit.getIWire() == hitPackedUnpacked.getIWire()
69 assert hit.getID() == hitPackedUnpacked.getID()
70 assert hit.getTDCCount() == hitPackedUnpacked.getTDCCount()
71 assert hit.getADCCount() == hitPackedUnpacked.getADCCount()
72 assert hit.getStatus() == hitPackedUnpacked.getStatus()
73
74
75main = b2.create_path()
76# Create Event information
77eventinfosetter = b2.register_module('EventInfoSetter')
78eventinfosetter.param({'evtNumList': [10]})
79main.add_module(eventinfosetter)
80
81# to run the framework the used modules need to be registered
82particlegun = b2.register_module('ParticleGun')
83particlegun.param('pdgCodes', [13, -13])
84particlegun.param('nTracks', 10)
85main.add_module(particlegun)
86
87# add simulation for CDC only
88simulation.add_simulation(main, components=['CDC'])
89b2.set_module_parameters(main, type="Geometry", useDB=False, components=["CDC"])
90
91# add the packer which packs the CDCHits resulting from the simulation
92cdc_packer = b2.register_module('CDCPacker')
93cdc_packer.param('cdcHitName', "CDCHits")
94main.add_module(cdc_packer)
95
96# add the unpacker which unpacks the RawCDC hits and stores
97# them in the dedicated store array "cdcHit_test_output"
98cdc_unpacker = b2.register_module('CDCUnpacker')
99cdc_unpacker.param('cdcHitName', cdc_hits_pack_unpack_collection)
100cdc_unpacker.param('enablePrintOut', False)
101cdc_unpacker.param('pedestalSubtraction', False)
102main.add_module(cdc_unpacker)
103
104# run custom test module to check if the CDCHits and the
105# cdcHit_test_output collections are equal
106main.add_module(PackerUnpackerTestModule())
107
108# Process events
109b2.process(main)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
def sortHits(self, unsortedPyStoreArray)
def add_simulation(path, components=None, bkgfiles=None, bkgOverlay=True, forceSetPXDDataReduction=False, usePXDDataReduction=True, cleanupPXDDataReduction=True, generate_2nd_cdc_hits=False, simulateT0jitter=True, isCosmics=False, FilterEvents=False, usePXDGatedMode=False, skipExperimentCheckForBG=False, save_slow_pions_in_mc=False)
Definition: simulation.py:126