Belle II Software  release-08-01-10
svd_packer_unpacker.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 from svd import add_svd_simulation
14 from ROOT import Belle2
15 import numpy
16 
17 
18 svd_digits_pack_unpack_collection = "SVDShaperDigits_test"
19 b2.set_random_seed(42)
20 
21 
22 class SvdPackerUnpackerTestModule(b2.Module):
23 
24  """
25  module which ckecks if two collection of SVDShaperDigits are equal
26  """
27 
28  def sortDigits(self, unsortedPyStoreArray):
29  """ use some digit information to sort the SVDShaperDigits list
30  Returns a python-list containing the SVDShaperDigits
31  """
32 
33  # first convert to a python-list to be abple to sort
34  py_list = [x for x in unsortedPyStoreArray]
35 
36  # sort via a hierachy of sort keys
37  return sorted(
38  py_list,
39  key=lambda x: (
40  x.getSensorID().getLayerNumber(),
41  x.getSensorID().getLadderNumber(),
42  x.getSensorID().getSensorNumber(),
43  x.isUStrip()))
44 
45  def event(self):
46  """ load SVDShaperDigits of the simulation and the packed/unpacked ones
47  and compare them"""
48 
49  svdDigitsPackedUnpacked = Belle2.PyStoreArray(svd_digits_pack_unpack_collection)
50  # direct from simulation
51  svdDigits = Belle2.PyStoreArray("SVDShaperDigits")
52 
53  svdDigits_sorted = self.sortDigitssortDigits(svdDigits)
54  svdDigitsPackedUnpacked_sorted = self.sortDigitssortDigits(svdDigitsPackedUnpacked)
55 
56  if not len(svdDigits_sorted) == len(svdDigitsPackedUnpacked_sorted):
57  b2.B2FATAL("SVDShaperDigits count not equal after packing and unpacking")
58 
59  # check all quantities between the direct and the packed/unpacked svd digits
60  for i in range(len(svdDigits_sorted)):
61 
62  # sort the digits, because the packer sorts the
63  # the 32-bit frames are sorted by FADC numbers by the packer module
64  hit = svdDigits_sorted[i]
65  hitPackedUnpacked = svdDigitsPackedUnpacked_sorted[i]
66 
67  # check content of the digit
68  assert hit.getTime() == hitPackedUnpacked.getTime()
69  assert hit.getIndex() == hitPackedUnpacked.getIndex()
70 
71  # note: The charge will only be checked if between 0 and 255
72  # These two cases will be addressed in future SVDShaperDigits and packer/unpacker version
73  assert numpy.isclose(hit.getCharge(), hitPackedUnpacked.getCharge())
74 
75  # check the VxdID information
76  assert hit.getSensorID().getID() == hitPackedUnpacked.getSensorID().getID()
77  assert hit.getSensorID().getLayerNumber() == hitPackedUnpacked.getSensorID().getLayerNumber()
78  assert hit.getSensorID().getLadderNumber() == hitPackedUnpacked.getSensorID().getLadderNumber()
79  assert hit.getSensorID().getSensorNumber() == hitPackedUnpacked.getSensorID().getSensorNumber()
80  assert hit.getSensorID().getSegmentNumber() == hitPackedUnpacked.getSensorID().getSegmentNumber()
81 
82 
83 # to run the framework the used modules need to be registered
84 particlegun = b2.register_module('ParticleGun')
85 particlegun.param('pdgCodes', [13, -13])
86 particlegun.param('nTracks', 10)
87 
88 # Create Event information
89 eventinfosetter = b2.register_module('EventInfoSetter')
90 eventinfosetter.param({'evtNumList': [10], 'runList': [1]})
91 # Show progress of processing
92 progress = b2.register_module('Progress')
93 
94 main = b2.create_path()
95 # init path
96 main.add_module(eventinfosetter)
97 main.add_module(particlegun)
98 # add simulation for svd only
99 add_svd_simulation(main)
100 
101 main.add_module(progress)
102 
103 nodeid = 0
104 Packer = b2.register_module('SVDPacker')
105 Packer.param('NodeID', nodeid)
106 Packer.param('svdShaperDigitListName', 'SVDShaperDigits')
107 Packer.param('rawSVDListName', 'SVDRaw')
108 main.add_module(Packer)
109 
110 unPacker = b2.register_module('SVDUnpacker')
111 unPacker.param('rawSVDListName', 'SVDRaw')
112 unPacker.param('svdShaperDigitListName', svd_digits_pack_unpack_collection)
113 main.add_module(unPacker)
114 
115 # run custom test module to check if the SVDShaperDigits and the
116 # svd_digits_pack_unpack_collection collections are equal
117 main.add_module(SvdPackerUnpackerTestModule())
118 
119 # Process events
120 b2.process(main)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
int getID(const std::vector< double > &breaks, double t)
get id of the time point t
Definition: calibTools.h:60