10from ROOT
import Belle2
21 """This module creates a DQMCommonUtils object and tests sensor
22 and chip numbering schemes.
"""
29 """ Initialize the DQMCommonUtils class here. It builds
30 its lookup arrrays, so we want to do it only once."""
34 basf2.B2FATAL(
"GeoTools not available!")
37 """ We test sensor and chip numbering by going from ID to
43 if (self.
gTools.getNumberOfLayers() != 6):
44 basf2.B2ERROR(f
'Layer count failure: \n {self.gTools.getNumberOfLayers()} layers reported, 6 actually.')
45 if (self.
gTools.getNumberOfPXDLayers() != 2):
46 basf2.B2ERROR(f
'PXD layer count failure: \n {self.gTools.getNumberOfPXDLayers()} layers reported, 2 actually.')
47 if (self.
gTools.getNumberOfSVDLayers() != 4):
48 basf2.B2ERROR(f
'SVD layer count failure: \n {self.gTools.getNumberOfSVDLayers()} layers reported, 4 actually.')
50 layers = self.
gTools.getLayers()
51 expected_layers = [1, 2, 3, 4, 5, 6]
53 for l1, l2
in zip(layers, expected_layers):
58 l1_string =
' '.join([str(x)
for x
in layers])
59 l2_string =
' '.join([str(x)
for x
in expected_layers])
60 basf2.B2ERROR(f
'Layer numbers do not match, expected {l2_string}, got {l1_string}!')
62 layers = self.
gTools.getPXDLayers()
63 expected_layers = [1, 2]
65 for l1, l2
in zip(layers, expected_layers):
70 l1_string =
' '.join([str(x)
for x
in layers])
71 l2_string =
' '.join([str(x)
for x
in expected_layers])
72 basf2.B2ERROR(f
'PXD layer numbers do not match, expected {l2_string}, got {l1_string}!')
74 layers = self.
gTools.getSVDLayers()
75 expected_layers = [3, 4, 5, 6]
77 for l1, l2
in zip(layers, expected_layers):
82 l1_string =
' '.join([str(x)
for x
in layers])
83 l2_string =
' '.join([str(x)
for x
in expected_layers])
84 basf2.B2ERROR(f
'SVD layer numbers do not match, expected {l2_string}, got {l1_string}!')
87 if (self.
gTools.getFirstLayer() != 1):
88 basf2.B2ERROR(f
'First layer number is 1, reported {self.gTools.getFirstLayer()}.')
89 if (self.
gTools.getLastLayer() != 6):
90 basf2.B2ERROR(f
'Last layer number is 6, reported {self.gTools.getLastLayer()}.')
91 if (self.
gTools.getFirstPXDLayer() != 1):
92 basf2.B2ERROR(f
'First PXD layer number is 1, reported {self.gTools.getFirstPXDLayer()}.')
93 if (self.
gTools.getLastPXDLayer() != 2):
94 basf2.B2ERROR(f
'Last PXD layer number is 2, reported {self.gTools.getLastPXDLayer()}.')
95 if (self.
gTools.getFirstSVDLayer() != 3):
96 basf2.B2ERROR(f
'First SVD layer number is 3, reported {self.gTools.getFirstSVDLayer()}.')
97 if (self.
gTools.getLastSVDLayer() != 6):
98 basf2.B2ERROR(f
'Last SVD layer number is 6, reported {self.gTools.getLastSVDLayer()}.')
102 idOfFirstPXDSensor = self.
gTools.getSensorIDFromPXDIndex(0)
103 layer = idOfFirstPXDSensor.getLayerNumber()
104 ladder = idOfFirstPXDSensor.getLadderNumber()
105 sensor = idOfFirstPXDSensor.getSensorNumber()
106 if layer != self.
gTools.getFirstPXDLayer()
or ladder != 1
or sensor != 1:
107 basf2.B2ERROR(
'Mismatch in first PXD sensor placement:\n' +
108 f
'Expected {layer}/{ladder}/{sensor}\nGot: {self.gTools.getFirstPXDLayer()}/{1}/{1}')
109 idOfLastPXDSensor = self.
gTools.getSensorIDFromPXDIndex(self.
gTools.getNumberOfPXDSensors() - 1)
110 layer = idOfLastPXDSensor.getLayerNumber()
111 if layer != self.
gTools.getLastPXDLayer():
112 basf2.B2ERROR(
'Mismatch in last PXD sensor placement:\n' +
113 f
'Expected layer {layer} got layer {self.gTools.getLastPXDLayer()}')
116 idOfFirstSVDSensor = self.
gTools.getSensorIDFromSVDIndex(0)
117 layer = idOfFirstSVDSensor.getLayerNumber()
118 ladder = idOfFirstSVDSensor.getLadderNumber()
119 sensor = idOfFirstSVDSensor.getSensorNumber()
120 if layer != self.
gTools.getFirstSVDLayer()
or ladder != 1
or sensor != 1:
121 basf2.B2ERROR(
'Mismatch in first SVD sensor placement:\n' +
122 f
'Expected {layer}/{ladder}/{sensor}\nGot: {self.gTools.getFirstSVDLayer()}/{1}/{1}')
123 idOfLastSVDSensor = self.
gTools.getSensorIDFromSVDIndex(self.
gTools.getNumberOfSVDSensors() - 1)
124 layer = idOfLastSVDSensor.getLayerNumber()
125 if layer != self.
gTools.getLastSVDLayer():
126 basf2.B2ERROR(
'Mismatch in last SVD sensor placement:\n' +
127 f
'Expected layer {layer} got layer {self.gTools.getLastSVDLayer()}')
133 init_sensor_index = self.
gTools.getSensorIndex(init_sensorID)
134 ret_sensorID = self.
gTools.getSensorIDFromIndex(init_sensor_index)
135 if init_sensorID.getID() != ret_sensorID.getID():
137 f
"Sensor index failure: \n Initial id: {init_sensorID} \n VXD index: {init_sensor_index} \n Retrieved id: " +
140 next_sensorID = self.
gTools.getSensorIDFromIndex(init_sensor_index + 1)
142 next_expected_sensorID.setSensorNumber(init_sensorID.getSensorNumber() + 1)
143 if next_expected_sensorID.getID() != next_sensorID.getID():
144 basf2.B2ERROR(
'Sensor index neighbourhood test failure: \n' +
145 f
'Initial id: {init_sensorID} \n Expected id: {next_expected_sensorID} \n Actaul id: ' +
146 f
'{next_sensorID} \n Index: {init_sensor_index + 1}.')
149 num_sensors_expected = 212
150 if (self.
gTools.getNumberOfSensors() != num_sensors_expected):
151 basf2.B2ERROR(
'Number of sensors mismatch: \n' +
152 f
'Expected: {num_sensors_expected}, got {self.gTools.getNumberOfSensors()}.')
158 init_sensor_index = self.
gTools.getPXDSensorIndex(
159 init_sensorID.getLayerNumber(),
160 init_sensorID.getLadderNumber(),
161 init_sensorID.getSensorNumber())
162 ret_sensorID = self.
gTools.getSensorIDFromPXDIndex(init_sensor_index)
163 if init_sensorID.getID() != ret_sensorID.getID():
165 f
"PXD sensor index failure: \n Initial id: {init_sensorID} \n VXD index: {init_sensor_index} \n " +
166 f
"Retrieved id: {ret_sensorID}.")
168 next_sensorID = self.
gTools.getSensorIDFromPXDIndex(init_sensor_index + 1)
170 next_expected_sensorID.setSensorNumber(init_sensorID.getSensorNumber() + 1)
171 if next_expected_sensorID.getID() != next_sensorID.getID():
173 'PXD sensor index neighbourhood test failure: \n' +
174 f
'Initial id: {init_sensorID} \n Expected id: {next_expected_sensorID} \n Actual id: {next_sensorID} \n ' +
175 f
'Index: {init_sensor_index + 1}.')
177 num_sensors_expected = 40
178 if (self.
gTools.getNumberOfPXDSensors() != num_sensors_expected):
179 basf2.B2ERROR(
'Number of PXD sensors mismatch: \n' +
180 f
'Expected: {num_sensors_expected}, got {self.gTools.getNumberOfPXDSensors()}.')
186 init_sensor_index = self.
gTools.getSVDSensorIndex(
187 init_sensorID.getLayerNumber(),
188 init_sensorID.getLadderNumber(),
189 init_sensorID.getSensorNumber())
190 ret_sensorID = self.
gTools.getSensorIDFromSVDIndex(init_sensor_index)
191 if init_sensorID.getID() != ret_sensorID.getID():
193 f
"SVD sensor index failure: \n Initial id: {init_sensorID} \n VXD index: {init_sensor_index} \n " +
194 f
"Retrieved id: {ret_sensorID}.")
196 next_sensorID = self.
gTools.getSensorIDFromSVDIndex(init_sensor_index + 1)
198 next_expected_sensorID.setSensorNumber(init_sensorID.getSensorNumber() + 1)
199 if next_expected_sensorID.getID() != next_sensorID.getID():
201 f
'SVD sensor index neighbourhood test failure: \nInitial id: {init_sensorID} \n Expected id: ' +
202 f
'{next_expected_sensorID} \n Actaul id: {next_sensorID} \n Index: {init_sensor_index + 1}.')
204 num_sensors_expected = 172
205 if (self.
gTools.getNumberOfSVDSensors() != num_sensors_expected):
206 basf2.B2ERROR(
'Number of SVD sensors mismatch: \n' +
207 f
'Expected: {num_sensors_expected}, got {self.gTools.getNumberOfSVDSensors()}.')
213 init_layer_index = self.
gTools.getLayerIndex(init_layer)
214 ret_layer = self.
gTools.getLayerNumberFromLayerIndex(init_layer_index)
215 if init_layer != ret_layer:
217 f
"Layer index failure: \n Initial: {init_layer} \n Index: {init_layer_index} \n Retrieved: {ret_layer}.")
219 next_layer = self.
gTools.getLayerNumberFromLayerIndex(init_layer_index + 1)
220 next_expected_layer = init_layer + 1
221 if next_layer != next_expected_layer:
223 f
"Layer index neighbourhood test failure: \n Initial id: {init_layer} \n Expected: " +
224 f
"{next_expected_layer} \n Actaul: {next_layer} \n Index: {init_layer_index + 1}.")
229 if self.
gTools.getTotalPXDChips() != 400:
230 basf2.B2ERROR(
'PXD chip count mismatch: \n' +
231 f
'Expected: {2120}, got {self.gTools.getTotalPXDChips()}.'
233 if self.
gTools.getNumberOfPXDUSideChips() != 4:
234 basf2.B2ERROR(
'PXD u-side chip count mismatch: \n' +
235 f
'Expected: {4}, got {self.gTools.getNumberOfPXDUSideChips()}.'
237 if self.
gTools.getNumberOfPXDVSideChips() != 6:
238 basf2.B2ERROR(
'PXD v-side chip count mismatch: \n' +
239 f
'Expected: {6}, got {self.gTools.getNumberOfPXDVSideChips()}.'
241 if self.
gTools.getTotalSVDChips() != 1748:
242 basf2.B2ERROR(
'SVD chip count mismatch: \n' +
243 f
'Expected: {2148}, got {self.gTools.getTotalSVDChips()}.'
245 if self.
gTools.getNumberOfSVDUSideChips() != 6:
246 basf2.B2ERROR(
'SVD u-side chip count mismatch: \n' +
247 f
'Expected: {6}, got {self.gTools.getNumberOfSVDUSideChips()}.'
249 if self.
gTools.getNumberOfSVDVSideChips(3) != 6:
250 basf2.B2ERROR(
'SVD v-side chip count mismatch: \n' +
251 f
'Expected: {6}, got {self.gTools.getNumberOfSVDVSideChips(3)}.'
253 if self.
gTools.getNumberOfSVDVSideChips(4) != 4:
254 basf2.B2ERROR(
'SVD v-side chip count mismatch: \n' +
255 f
'Expected: {4}, got {self.gTools.getNumberOfSVDVSideChips(4)}.'
263 index_with_vxdid = self.
gTools.getPXDChipIndex(
Belle2.VxdID(init_layer, init_ladder, init_sensor), init_uSide, init_chipNo)
264 index_with_llss = self.
gTools.getPXDChipIndex(init_layer, init_ladder, init_sensor, init_uSide, init_chipNo)
265 if index_with_vxdid != index_with_llss:
266 basf2.B2ERROR(
'Mismatch between VxdID-based and layer-ladder-sensor based index:\n' +
267 f
'VxdID-based: {index_with_vxdid}\nlayer-ladder-sensor: {index_with_llss}'
269 returned_chipID = self.
gTools.getChipIDFromPXDIndex(index_with_vxdid)
270 returned_layer = returned_chipID.getLayerNumber()
271 returned_ladder = returned_chipID.getLadderNumber()
272 returned_sensor = returned_chipID.getSensorNumber()
273 returned_uSide = self.
gTools.isPXDSideU(returned_chipID)
274 returned_chipNo = self.
gTools.getPXDChipNumber(returned_chipID)
275 match = (init_layer == returned_layer)
and \
276 (init_ladder == returned_ladder)
and \
277 (init_sensor == returned_sensor)
and \
278 (init_uSide == returned_uSide)
and \
279 (init_chipNo == returned_chipNo)
281 basf2.B2ERROR(
'Mismatch in PXD chip indexing:\n' +
282 f
'Initial: {init_layer} {init_ladder} {init_sensor} {init_uSide} {init_chipNo}\n' +
283 f
'Final: {returned_layer} {returned_ladder} {returned_sensor} {returned_uSide} {returned_chipNo}.'
287 expected_layer = init_layer
288 expected_ladder = init_ladder
289 expected_sensor = init_sensor
290 expected_uSide =
False
292 neighbour_chipID = self.
gTools.getChipIDFromPXDIndex(index_with_vxdid + 1)
293 neighbour_layer = neighbour_chipID.getLayerNumber()
294 neighbour_ladder = neighbour_chipID.getLadderNumber()
295 neighbour_sensor = neighbour_chipID.getSensorNumber()
296 neighbour_uSide = self.
gTools.isPXDSideU(neighbour_chipID)
297 neighbour_chipNo = self.
gTools.getPXDChipNumber(neighbour_chipID)
298 match = (expected_layer == neighbour_layer)
and \
299 (expected_ladder == neighbour_ladder)
and \
300 (expected_sensor == neighbour_sensor)
and \
301 (expected_uSide == neighbour_uSide)
and \
302 (expected_chipNo == neighbour_chipNo)
304 basf2.B2ERROR(
'Mismatch in PXD chip index neighbourship:\n' +
305 f
'Expected: {expected_layer} {expected_ladder} {expected_sensor} {expected_uSide} {expected_chipNo}\n' +
306 f
'Obtained: {neighbour_layer} {neighbour_ladder} {neighbour_sensor} {neighbour_uSide} {neighbour_chipNo}.'
315 index_with_vxdid = self.
gTools.getSVDChipIndex(
Belle2.VxdID(init_layer, init_ladder, init_sensor), init_uSide, init_chipNo)
316 index_with_llss = self.
gTools.getSVDChipIndex(init_layer, init_ladder, init_sensor, init_uSide, init_chipNo)
317 if index_with_vxdid != index_with_llss:
318 basf2.B2ERROR(
'Mismatch between VxdID-based and layer-ladder-sensor based index:\n' +
319 f
'VxdID-based: {index_with_vxdid}\nlayer-ladder-sensor: {index_with_llss}'
321 returned_chipID = self.
gTools.getChipIDFromSVDIndex(index_with_vxdid)
322 returned_layer = returned_chipID.getLayerNumber()
323 returned_ladder = returned_chipID.getLadderNumber()
324 returned_sensor = returned_chipID.getSensorNumber()
325 returned_uSide = self.
gTools.isSVDSideU(returned_chipID)
326 returned_chipNo = self.
gTools.getSVDChipNumber(returned_chipID)
327 match = (init_layer == returned_layer)
and \
328 (init_ladder == returned_ladder)
and \
329 (init_sensor == returned_sensor)
and \
330 (init_uSide == returned_uSide)
and \
331 (init_chipNo == returned_chipNo)
333 basf2.B2ERROR(
'Mismatch in SVD chip indexing:\n' +
334 f
'Initial: {init_layer} {init_ladder} {init_sensor} {init_uSide} {init_chipNo}\n' +
335 f
'Final: {returned_layer} {returned_ladder} {returned_sensor} {returned_uSide} {returned_chipNo}.'
339 expected_layer = init_layer
340 expected_ladder = init_ladder
341 expected_sensor = init_sensor
342 expected_uSide =
False
344 neighbour_chipID = self.
gTools.getChipIDFromSVDIndex(index_with_vxdid + 1)
345 neighbour_layer = neighbour_chipID.getLayerNumber()
346 neighbour_ladder = neighbour_chipID.getLadderNumber()
347 neighbour_sensor = neighbour_chipID.getSensorNumber()
348 neighbour_uSide = self.
gTools.isSVDSideU(neighbour_chipID)
349 neighbour_chipNo = self.
gTools.getSVDChipNumber(neighbour_chipID)
350 match = (expected_layer == neighbour_layer)
and \
351 (expected_ladder == neighbour_ladder)
and \
352 (expected_sensor == neighbour_sensor)
and \
353 (expected_uSide == neighbour_uSide)
and \
354 (expected_chipNo == neighbour_chipNo)
356 basf2.B2ERROR(
'Mismatch in SVD chip index neighbourship:\n' +
357 f
'Expected: {expected_layer} {expected_ladder} {expected_sensor} {expected_uSide} {expected_chipNo}\n' +
358 f
'Obtained: {neighbour_layer} {neighbour_ladder} {neighbour_sensor} {neighbour_uSide} {neighbour_chipNo}.'
362 indexOfFirstPXDChip = 0
365 idOfFirstPXDChip = self.
gTools.getChipIDFromPXDIndex(indexOfFirstPXDChip)
366 firstChipLayer = idOfFirstPXDChip.getLayerNumber()
367 firstChipLadder = idOfFirstPXDChip.getLadderNumber()
368 firstChipSensor = idOfFirstPXDChip.getSensorNumber()
369 firstChipUSide = self.
gTools.isPXDSideU(idOfFirstPXDChip)
370 firstChipNo = self.
gTools.getPXDChipNumber(idOfFirstPXDChip)
371 if (firstChipLayer != self.
gTools.getFirstPXDLayer()
or
372 firstChipLadder != 1
or
373 firstChipSensor != 1
or
374 not firstChipUSide
or
377 f
"Wrong 1st PXD chip assignment:\nExpected {self.gTools.getFirstPXDLayer()}/{1}/{1} side u chip {1},\nGot " +
378 f
"{firstChipLayer}/{firstChipLadder}/{firstChipSensor} side {'u' if firstChipUSide else 'v'} chip {firstChipNo}")
379 indexOfLastPXDChip = self.
gTools.getTotalPXDChips() - 1
381 idOfLastPXDChip = self.
gTools.getChipIDFromPXDIndex(indexOfLastPXDChip)
382 lastChipLayer = idOfLastPXDChip.getLayerNumber()
383 lastChipUSide = self.
gTools.isPXDSideU(idOfLastPXDChip)
384 lastChipNo = self.
gTools.getPXDChipNumber(idOfLastPXDChip)
385 expectedLastChipNo = self.
gTools.getNumberOfPXDVSideChips(self.
gTools.getLastPXDLayer())
386 if (lastChipLayer != self.
gTools.getLastPXDLayer()
or
388 lastChipNo != expectedLastChipNo):
390 'Wrong last PXD chip assignment:\n' +
391 f
"Expected layer {self.gTools.getLastPXDLayer()} side v chip {expectedLastChipNo},\nGot layer " +
392 f
"{lastChipLayer} side {'u' if lastChipUSide else 'v'} chip {lastChipNo}")
395 indexOfFirstSVDChip = 0
398 idOfFirstSVDChip = self.
gTools.getChipIDFromSVDIndex(indexOfFirstSVDChip)
399 firstChipLayer = idOfFirstSVDChip.getLayerNumber()
400 firstChipLadder = idOfFirstSVDChip.getLadderNumber()
401 firstChipSensor = idOfFirstSVDChip.getSensorNumber()
402 firstChipUSide = self.
gTools.isSVDSideU(idOfFirstSVDChip)
403 firstChipNo = self.
gTools.getSVDChipNumber(idOfFirstSVDChip)
404 if (firstChipLayer != self.
gTools.getFirstSVDLayer()
or
405 firstChipLadder != 1
or
406 firstChipSensor != 1
or
407 not firstChipUSide
or
410 f
"Wrong 1st SVD chip assignment:\nExpected {self.gTools.getFirstSVDLayer()}/{1}/{1} side u chip {1},\nGot " +
411 f
"{firstChipLayer}/{firstChipLadder}/{firstChipSensor} side {'u' if firstChipUSide else 'v'} chip {firstChipNo}")
412 indexOfLastSVDChip = self.
gTools.getTotalSVDChips() - 1
414 idOfLastSVDChip = self.
gTools.getChipIDFromSVDIndex(indexOfLastSVDChip)
415 lastChipLayer = idOfLastSVDChip.getLayerNumber()
416 lastChipUSide = self.
gTools.isSVDSideU(idOfLastSVDChip)
417 lastChipNo = self.
gTools.getSVDChipNumber(idOfLastSVDChip)
418 expectedLastChipNo = self.
gTools.getNumberOfSVDVSideChips(self.
gTools.getLastSVDLayer())
419 if (lastChipLayer != self.
gTools.getLastSVDLayer()
or
421 lastChipNo != expectedLastChipNo):
423 'Wrong last SVD chip assignment:\n' +
424 f
"Expected layer {self.gTools.getLastSVDLayer()} side v chip {expectedLastChipNo},\nGot layer " +
425 f
"{lastChipLayer} side {'u' if lastChipUSide else 'v'} chip {lastChipNo}")
430if __name__ ==
"__main__":
434 basf2.B2INFO(
'Setting up a basf2 run...')
436 check_numbering = basf2.create_path()
437 check_numbering.add_module(
'EventInfoSetter', expList=[0], runList=[0], evtNumList=[1])
438 check_numbering.add_module(
'Gearbox')
439 check_numbering.add_module(
'Geometry', components=[
'MagneticField',
'PXD',
'SVD'])
444 basf2.B2INFO(
'Test complete.')
static GeoCache & getInstance()
Return a reference to the singleton instance.
Class to uniquely identify a any structure of the PXD and SVD.
def clean_working_directory()
def safe_process(*args, **kwargs)