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