10 from 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.
gToolsgTools.getNumberOfLayers() != 6):
44 basf2.B2ERROR(
'Layer count failure: \n {0} layers reported, 6 actually.'.format(self.
gToolsgTools.getNumberOfLayers()))
45 if (self.
gToolsgTools.getNumberOfPXDLayers() != 2):
46 basf2.B2ERROR(
'PXD layer count failure: \n {0} layers reported, 2 actually.'.format(self.
gToolsgTools.getNumberOfPXDLayers()))
47 if (self.
gToolsgTools.getNumberOfSVDLayers() != 4):
48 basf2.B2ERROR(
'SVD layer count failure: \n {0} layers reported, 4 actually.'.format(self.
gToolsgTools.getNumberOfSVDLayers()))
50 layers = self.
gToolsgTools.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(
'Layer numbers do not match, expected {0}, got {1}!'.format(l2_string, l1_string))
62 layers = self.
gToolsgTools.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(
'PXD layer numbers do not match, expected {0}, got {1}!'.format(l2_string, l1_string))
74 layers = self.
gToolsgTools.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(
'SVD layer numbers do not match, expected {0}, got {1}!'.format(l2_string, l1_string))
87 if (self.
gToolsgTools.getFirstLayer() != 1):
88 basf2.B2ERROR(
'First layer number is 1, reported {0}.'.format(self.
gToolsgTools.getFirstLayer()))
89 if (self.
gToolsgTools.getLastLayer() != 6):
90 basf2.B2ERROR(
'Last layer number is 6, reported {0}.'.format(self.
gToolsgTools.getLastLayer()))
91 if (self.
gToolsgTools.getFirstPXDLayer() != 1):
92 basf2.B2ERROR(
'First PXD layer number is 1, reported {0}.'.format(self.
gToolsgTools.getFirstPXDLayer()))
93 if (self.
gToolsgTools.getLastPXDLayer() != 2):
94 basf2.B2ERROR(
'Last PXD layer number is 2, reported {0}.'.format(self.
gToolsgTools.getLastPXDLayer()))
95 if (self.
gToolsgTools.getFirstSVDLayer() != 3):
96 basf2.B2ERROR(
'First SVD layer number is 3, reported {0}.'.format(self.
gToolsgTools.getFirstSVDLayer()))
97 if (self.
gToolsgTools.getLastSVDLayer() != 6):
98 basf2.B2ERROR(
'Last SVD layer number is 6, reported {0}.'.format(self.
gToolsgTools.getLastSVDLayer()))
102 idOfFirstPXDSensor = self.
gToolsgTools.getSensorIDFromPXDIndex(0)
103 layer = idOfFirstPXDSensor.getLayerNumber()
104 ladder = idOfFirstPXDSensor.getLadderNumber()
105 sensor = idOfFirstPXDSensor.getSensorNumber()
106 if layer != self.
gToolsgTools.getFirstPXDLayer()
or ladder != 1
or sensor != 1:
107 basf2.B2ERROR(
'Mismatch in first PXD sensor placement:\n' +
108 'Expected {0}/{1}/{2}\nGot: {3}/{4}/{5}'.format(
109 layer, ladder, sensor,
110 self.
gToolsgTools.getFirstPXDLayer(), 1, 1))
111 idOfLastPXDSensor = self.
gToolsgTools.getSensorIDFromPXDIndex(self.
gToolsgTools.getNumberOfPXDSensors() - 1)
112 layer = idOfLastPXDSensor.getLayerNumber()
113 if layer != self.
gToolsgTools.getLastPXDLayer():
114 basf2.B2ERROR(
'Mismatch in last PXD sensor placement:\n' +
115 'Expected layer {0} got layer {1}'.format(
116 layer, self.
gToolsgTools.getLastPXDLayer()))
119 idOfFirstSVDSensor = self.
gToolsgTools.getSensorIDFromSVDIndex(0)
120 layer = idOfFirstSVDSensor.getLayerNumber()
121 ladder = idOfFirstSVDSensor.getLadderNumber()
122 sensor = idOfFirstSVDSensor.getSensorNumber()
123 if layer != self.
gToolsgTools.getFirstSVDLayer()
or ladder != 1
or sensor != 1:
124 basf2.B2ERROR(
'Mismatch in first SVD sensor placement:\n' +
125 'Expected {0}/{1}/{2}\nGot: {3}/{4}/{5}'.format(
126 layer, ladder, sensor,
127 self.
gToolsgTools.getFirstSVDLayer(), 1, 1))
128 idOfLastSVDSensor = self.
gToolsgTools.getSensorIDFromSVDIndex(self.
gToolsgTools.getNumberOfSVDSensors() - 1)
129 layer = idOfLastSVDSensor.getLayerNumber()
130 if layer != self.
gToolsgTools.getLastSVDLayer():
131 basf2.B2ERROR(
'Mismatch in last SVD sensor placement:\n' +
132 'Expected layer {0} got layer {1}'.format(
133 layer, self.
gToolsgTools.getLastSVDLayer()))
139 init_sensor_index = self.
gToolsgTools.getSensorIndex(init_sensorID)
140 ret_sensorID = self.
gToolsgTools.getSensorIDFromIndex(init_sensor_index)
141 if init_sensorID.getID() != ret_sensorID.getID():
143 "Sensor index failure: \n Initial id: {0} \n VXD index: {1} \n Retrieved id: {2}.".format(
144 init_sensorID, init_sensor_index, ret_sensorID))
146 next_sensorID = self.
gToolsgTools.getSensorIDFromIndex(init_sensor_index + 1)
148 next_expected_sensorID.setSensorNumber(init_sensorID.getSensorNumber() + 1)
149 if next_expected_sensorID.getID() != next_sensorID.getID():
150 basf2.B2ERROR(
'Sensor index neighbourhood test failure: \n' +
151 'Initial id: {0} \n Expected id: {1} \n Actaul id: {2} \n Index: {3}.'.format(
152 init_sensorID, next_expected_sensorID,
153 next_sensorID, init_sensor_index + 1
157 num_sensors_expected = 212
158 if (self.
gToolsgTools.getNumberOfSensors() != num_sensors_expected):
159 basf2.B2ERROR(
'Number of sensors mismatch: \n' +
160 'Expected: {0}, got {1}.'.format(
161 num_sensors_expected, self.
gToolsgTools.getNumberOfSensors()
168 init_sensor_index = self.
gToolsgTools.getPXDSensorIndex(
169 init_sensorID.getLayerNumber(),
170 init_sensorID.getLadderNumber(),
171 init_sensorID.getSensorNumber())
172 ret_sensorID = self.
gToolsgTools.getSensorIDFromPXDIndex(init_sensor_index)
173 if init_sensorID.getID() != ret_sensorID.getID():
175 "PXD sensor index failure: \n Initial id: {0} \n VXD index: {1} \n Retrieved id: {2}.".format(
176 init_sensorID, init_sensor_index, ret_sensorID))
178 next_sensorID = self.
gToolsgTools.getSensorIDFromPXDIndex(init_sensor_index + 1)
180 next_expected_sensorID.setSensorNumber(init_sensorID.getSensorNumber() + 1)
181 if next_expected_sensorID.getID() != next_sensorID.getID():
183 'PXD sensor index neighbourhood test failure: \n' +
184 f
'Initial id: {init_sensorID} \n Expected id: {next_expected_sensorID} \n Actual id: {next_sensorID} \n ' +
185 f
'Index: {init_sensor_index + 1}.')
187 num_sensors_expected = 40
188 if (self.
gToolsgTools.getNumberOfPXDSensors() != num_sensors_expected):
189 basf2.B2ERROR(
'Number of PXD sensors mismatch: \n' +
190 'Expected: {0}, got {1}.'.format(
191 num_sensors_expected, self.
gToolsgTools.getNumberOfPXDSensors()
198 init_sensor_index = self.
gToolsgTools.getSVDSensorIndex(
199 init_sensorID.getLayerNumber(),
200 init_sensorID.getLadderNumber(),
201 init_sensorID.getSensorNumber())
202 ret_sensorID = self.
gToolsgTools.getSensorIDFromSVDIndex(init_sensor_index)
203 if init_sensorID.getID() != ret_sensorID.getID():
205 "SVD sensor index failure: \n Initial id: {0} \n VXD index: {1} \n Retrieved id: {2}.".format(
206 init_sensorID, init_sensor_index, ret_sensorID))
208 next_sensorID = self.
gToolsgTools.getSensorIDFromSVDIndex(init_sensor_index + 1)
210 next_expected_sensorID.setSensorNumber(init_sensorID.getSensorNumber() + 1)
211 if next_expected_sensorID.getID() != next_sensorID.getID():
213 'SVD sensor index neighbourhood test failure: \n'
214 'Initial id: {0} \n Expected id: {1} \n Actaul id: {2} \n '
215 'Index: {3}.'.format(init_sensorID, next_expected_sensorID,
216 next_sensorID, init_sensor_index + 1))
218 num_sensors_expected = 172
219 if (self.
gToolsgTools.getNumberOfSVDSensors() != num_sensors_expected):
220 basf2.B2ERROR(
'Number of SVD sensors mismatch: \n' +
221 'Expected: {0}, got {1}.'.format(
222 num_sensors_expected, self.
gToolsgTools.getNumberOfSVDSensors()
229 init_layer_index = self.
gToolsgTools.getLayerIndex(init_layer)
230 ret_layer = self.
gToolsgTools.getLayerNumberFromLayerIndex(init_layer_index)
231 if init_layer != ret_layer:
233 "Layer index failure: \n Initial: {0} \n Index: {1} \n Retrieved: {2}.".format(
234 init_layer, init_layer_index, ret_layer))
236 next_layer = self.
gToolsgTools.getLayerNumberFromLayerIndex(init_layer_index + 1)
237 next_expected_layer = init_layer + 1
238 if next_layer != next_expected_layer:
240 "Layer index neighbourhood test failure: \n Initial id: {0} \n Expected: {1} \n Actaul: {2} \n Index: {3}.".format(
250 if self.
gToolsgTools.getTotalPXDChips() != 400:
251 basf2.B2ERROR(
'PXD chip count mismatch: \n' +
252 'Expected: {0}, got {1}.'.format(
253 2120, self.
gToolsgTools.getTotalPXDChips())
255 if self.
gToolsgTools.getNumberOfPXDUSideChips() != 4:
256 basf2.B2ERROR(
'PXD u-side chip count mismatch: \n' +
257 'Expected: {0}, got {1}.'.format(
258 4, self.
gToolsgTools.getNumberOfPXDUSideChips())
260 if self.
gToolsgTools.getNumberOfPXDVSideChips() != 6:
261 basf2.B2ERROR(
'PXD v-side chip count mismatch: \n' +
262 'Expected: {0}, got {1}.'.format(
263 6, self.
gToolsgTools.getNumberOfPXDVSideChips())
265 if self.
gToolsgTools.getTotalSVDChips() != 1748:
266 basf2.B2ERROR(
'SVD chip count mismatch: \n' +
267 'Expected: {0}, got {1}.'.format(
268 2148, self.
gToolsgTools.getTotalSVDChips())
270 if self.
gToolsgTools.getNumberOfSVDUSideChips() != 6:
271 basf2.B2ERROR(
'SVD u-side chip count mismatch: \n' +
272 'Expected: {0}, got {1}.'.format(
273 6, self.
gToolsgTools.getNumberOfSVDUSideChips())
275 if self.
gToolsgTools.getNumberOfSVDVSideChips(3) != 6:
276 basf2.B2ERROR(
'SVD v-side chip count mismatch: \n' +
277 'Expected: {0}, got {1}.'.format(
278 6, self.
gToolsgTools.getNumberOfSVDVSideChips(3))
280 if self.
gToolsgTools.getNumberOfSVDVSideChips(4) != 4:
281 basf2.B2ERROR(
'SVD v-side chip count mismatch: \n' +
282 'Expected: {0}, got {1}.'.format(
283 4, self.
gToolsgTools.getNumberOfSVDVSideChips(4))
291 index_with_vxdid = self.
gToolsgTools.getPXDChipIndex(
Belle2.VxdID(init_layer, init_ladder, init_sensor), init_uSide, init_chipNo)
292 index_with_llss = self.
gToolsgTools.getPXDChipIndex(init_layer, init_ladder, init_sensor, init_uSide, init_chipNo)
293 if index_with_vxdid != index_with_llss:
294 basf2.B2ERROR(
'Mismatch between VxdID-based and layer-ladder-sensor based index:\n' +
295 'VxdID-based: {0}\nlayer-ladder-sensor: {1}'.format(
296 index_with_vxdid, index_with_llss)
298 returned_chipID = self.
gToolsgTools.getChipIDFromPXDIndex(index_with_vxdid)
299 returned_layer = returned_chipID.getLayerNumber()
300 returned_ladder = returned_chipID.getLadderNumber()
301 returned_sensor = returned_chipID.getSensorNumber()
302 returned_uSide = self.
gToolsgTools.isPXDSideU(returned_chipID)
303 returned_chipNo = self.
gToolsgTools.getPXDChipNumber(returned_chipID)
304 match = (init_layer == returned_layer)
and \
305 (init_ladder == returned_ladder)
and \
306 (init_sensor == returned_sensor)
and \
307 (init_uSide == returned_uSide)
and \
308 (init_chipNo == returned_chipNo)
310 basf2.B2ERROR(
'Mismatch in PXD chip indexing:\n' +
311 'Initial: {0} {1} {2} {3} {4}\n'.format(
312 init_layer, init_ladder, init_sensor, init_uSide, init_chipNo) +
313 'Final: {0} {1} {2} {3} {4}.'.format(
314 returned_layer, returned_ladder, returned_sensor, returned_uSide, returned_chipNo)
318 expected_layer = init_layer
319 expected_ladder = init_ladder
320 expected_sensor = init_sensor
321 expected_uSide =
False
323 neighbour_chipID = self.
gToolsgTools.getChipIDFromPXDIndex(index_with_vxdid + 1)
324 neighbour_layer = neighbour_chipID.getLayerNumber()
325 neighbour_ladder = neighbour_chipID.getLadderNumber()
326 neighbour_sensor = neighbour_chipID.getSensorNumber()
327 neighbour_uSide = self.
gToolsgTools.isPXDSideU(neighbour_chipID)
328 neighbour_chipNo = self.
gToolsgTools.getPXDChipNumber(neighbour_chipID)
329 match = (expected_layer == neighbour_layer)
and \
330 (expected_ladder == neighbour_ladder)
and \
331 (expected_sensor == neighbour_sensor)
and \
332 (expected_uSide == neighbour_uSide)
and \
333 (expected_chipNo == neighbour_chipNo)
335 basf2.B2ERROR(
'Mismatch in PXD chip index neighbourship:\n' +
336 'Expected: {0} {1} {2} {3} {4}\n'.format(
337 expected_layer, expected_ladder, expected_sensor, expected_uSide, expected_chipNo) +
338 'Obtained: {0} {1} {2} {3} {4}.'.format(
339 neighbour_layer, neighbour_ladder, neighbour_sensor, neighbour_uSide, neighbour_chipNo)
348 index_with_vxdid = self.
gToolsgTools.getSVDChipIndex(
Belle2.VxdID(init_layer, init_ladder, init_sensor), init_uSide, init_chipNo)
349 index_with_llss = self.
gToolsgTools.getSVDChipIndex(init_layer, init_ladder, init_sensor, init_uSide, init_chipNo)
350 if index_with_vxdid != index_with_llss:
351 basf2.B2ERROR(
'Mismatch between VxdID-based and layer-ladder-sensor based index:\n' +
352 'VxdID-based: {0}\nlayer-ladder-sensor: {1}'.format(
353 index_with_vxdid, index_with_llss)
355 returned_chipID = self.
gToolsgTools.getChipIDFromSVDIndex(index_with_vxdid)
356 returned_layer = returned_chipID.getLayerNumber()
357 returned_ladder = returned_chipID.getLadderNumber()
358 returned_sensor = returned_chipID.getSensorNumber()
359 returned_uSide = self.
gToolsgTools.isSVDSideU(returned_chipID)
360 returned_chipNo = self.
gToolsgTools.getSVDChipNumber(returned_chipID)
361 match = (init_layer == returned_layer)
and \
362 (init_ladder == returned_ladder)
and \
363 (init_sensor == returned_sensor)
and \
364 (init_uSide == returned_uSide)
and \
365 (init_chipNo == returned_chipNo)
367 basf2.B2ERROR(
'Mismatch in SVD chip indexing:\n' +
368 'Initial: {0} {1} {2} {3} {4}\n'.format(
369 init_layer, init_ladder, init_sensor, init_uSide, init_chipNo) +
370 'Final: {0} {1} {2} {3} {4}.'.format(
371 returned_layer, returned_ladder, returned_sensor, returned_uSide, returned_chipNo)
375 expected_layer = init_layer
376 expected_ladder = init_ladder
377 expected_sensor = init_sensor
378 expected_uSide =
False
380 neighbour_chipID = self.
gToolsgTools.getChipIDFromSVDIndex(index_with_vxdid + 1)
381 neighbour_layer = neighbour_chipID.getLayerNumber()
382 neighbour_ladder = neighbour_chipID.getLadderNumber()
383 neighbour_sensor = neighbour_chipID.getSensorNumber()
384 neighbour_uSide = self.
gToolsgTools.isSVDSideU(neighbour_chipID)
385 neighbour_chipNo = self.
gToolsgTools.getSVDChipNumber(neighbour_chipID)
386 match = (expected_layer == neighbour_layer)
and \
387 (expected_ladder == neighbour_ladder)
and \
388 (expected_sensor == neighbour_sensor)
and \
389 (expected_uSide == neighbour_uSide)
and \
390 (expected_chipNo == neighbour_chipNo)
392 basf2.B2ERROR(
'Mismatch in SVD chip index neighbourship:\n' +
393 'Expected: {0} {1} {2} {3} {4}\n'.format(
394 expected_layer, expected_ladder, expected_sensor, expected_uSide, expected_chipNo) +
395 'Obtained: {0} {1} {2} {3} {4}.'.format(
396 neighbour_layer, neighbour_ladder, neighbour_sensor, neighbour_uSide, neighbour_chipNo)
400 indexOfFirstPXDChip = 0
403 idOfFirstPXDChip = self.
gToolsgTools.getChipIDFromPXDIndex(indexOfFirstPXDChip)
404 firstChipLayer = idOfFirstPXDChip.getLayerNumber()
405 firstChipLadder = idOfFirstPXDChip.getLadderNumber()
406 firstChipSensor = idOfFirstPXDChip.getSensorNumber()
407 firstChipUSide = self.
gToolsgTools.isPXDSideU(idOfFirstPXDChip)
408 firstChipNo = self.
gToolsgTools.getPXDChipNumber(idOfFirstPXDChip)
409 if (firstChipLayer != self.
gToolsgTools.getFirstPXDLayer()
or
410 firstChipLadder != 1
or
411 firstChipSensor != 1
or
412 not firstChipUSide
or
415 'Wrong 1st PXD chip assignment:\nExpected {0}/{1}/{2} side {3} chip {4},\nGot {5}/{6}/{7} side {8} chip {9}'.format(
416 self.
gToolsgTools.getFirstPXDLayer(),
424 'u' if firstChipUSide
else 'v',
426 indexOfLastPXDChip = self.
gToolsgTools.getTotalPXDChips() - 1
428 idOfLastPXDChip = self.
gToolsgTools.getChipIDFromPXDIndex(indexOfLastPXDChip)
429 lastChipLayer = idOfLastPXDChip.getLayerNumber()
430 lastChipUSide = self.
gToolsgTools.isPXDSideU(idOfLastPXDChip)
431 lastChipNo = self.
gToolsgTools.getPXDChipNumber(idOfLastPXDChip)
432 expectedLastChipNo = self.
gToolsgTools.getNumberOfPXDVSideChips(self.
gToolsgTools.getLastPXDLayer())
433 if (lastChipLayer != self.
gToolsgTools.getLastPXDLayer()
or
435 lastChipNo != expectedLastChipNo):
437 'Wrong last PXD chip assignment:\n' +
438 'Expected layer {0} side {1} chip {2},\nGot layer {3} side {4} chip {5}'.format(
439 self.
gToolsgTools.getLastPXDLayer(),
443 'u' if lastChipUSide
else 'v',
447 indexOfFirstSVDChip = 0
450 idOfFirstSVDChip = self.
gToolsgTools.getChipIDFromSVDIndex(indexOfFirstSVDChip)
451 firstChipLayer = idOfFirstSVDChip.getLayerNumber()
452 firstChipLadder = idOfFirstSVDChip.getLadderNumber()
453 firstChipSensor = idOfFirstSVDChip.getSensorNumber()
454 firstChipUSide = self.
gToolsgTools.isSVDSideU(idOfFirstSVDChip)
455 firstChipNo = self.
gToolsgTools.getSVDChipNumber(idOfFirstSVDChip)
456 if (firstChipLayer != self.
gToolsgTools.getFirstSVDLayer()
or
457 firstChipLadder != 1
or
458 firstChipSensor != 1
or
459 not firstChipUSide
or
462 'Wrong 1st SVD chip assignment:\nExpected {0}/{1}/{2} side {3} chip {4},\nGot {5}/{6}/{7} side {8} chip {9}'.format(
463 self.
gToolsgTools.getFirstSVDLayer(),
471 'u' if firstChipUSide
else 'v',
473 indexOfLastSVDChip = self.
gToolsgTools.getTotalSVDChips() - 1
475 idOfLastSVDChip = self.
gToolsgTools.getChipIDFromSVDIndex(indexOfLastSVDChip)
476 lastChipLayer = idOfLastSVDChip.getLayerNumber()
477 lastChipUSide = self.
gToolsgTools.isSVDSideU(idOfLastSVDChip)
478 lastChipNo = self.
gToolsgTools.getSVDChipNumber(idOfLastSVDChip)
479 expectedLastChipNo = self.
gToolsgTools.getNumberOfSVDVSideChips(self.
gToolsgTools.getLastSVDLayer())
480 if (lastChipLayer != self.
gToolsgTools.getLastSVDLayer()
or
482 lastChipNo != expectedLastChipNo):
484 'Wrong last SVD chip assignment:\n' +
485 'Expected layer {0} side {1} chip {2},\nGot layer {3} side {4} chip {5}'.format(
486 self.
gToolsgTools.getLastSVDLayer(),
490 'u' if lastChipUSide
else 'v',
496 if __name__ ==
"__main__":
500 basf2.B2INFO(
'Setting up a basf2 run...')
502 check_numbering = basf2.create_path()
503 check_numbering.add_module(
'EventInfoSetter', expList=[0], runList=[0], evtNumList=[1])
504 check_numbering.add_module(
'Gearbox')
505 check_numbering.add_module(
'Geometry', components=[
'MagneticField',
'PXD',
'SVD'])
510 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)