Belle II Software development
GeoCacheHierarchy.py
1#!/usr/bin/env python3
2
3
10
11""" Test for the hierarchy in VXD
12
13Ensure that hierarchy can compute the same global positions
14of sensors as what is stored in GeoCache.
15+ checks, that moving a ladder really moves a sensor in expected manner
16
17If anyone changes the geometry construction (e.g. ladder coordinate system)
18and does not correctly change hierarchy filling, this test will fail.
19
20
21"""
22
23import basf2 as b2
24import ROOT
25from ROOT import Belle2
26
27
29 """Python module to compare transformations stored in GeoCache and computed by the hierarchy"""
30
31 def __init__(self):
32 """ constructor """
33 super().__init__()
34
35 self.test_shift_z = 10.
36
37 def initialize(self):
38 """ module initialization - after geometry, so GeoCache is ready """
40
41 print("Now testing hierarchy can compute nominal sensor positions...")
42 # We check the trafos for EACH sensor
43 for sensor in cache.getListOfSensors():
44 # Nominal trafo stored by findVolumes() after geometry is created
45 nominal = cache.getSensorInfo(sensor).getTransformation(False)
46 # Trafo computed by the stored matrix chain in hierarchy (includes alignment,
47 # but as we use exp=0, run=0 we should always get zero alignment. Therefore
48 # we know both matrices have to be the same. Let's compare them element by element
49 reco = cache.getSensorInfo(sensor).getTransformation(True)
50
51 # First rotation component
52 for i in range(0, 9):
53 assert (abs(nominal.GetRotationMatrix()[i] - reco.GetRotationMatrix()[i]) < 1.e-14)
54 # Then translations
55 for i in range(0, 3):
56 assert (abs(nominal.GetTranslation()[i] - reco.GetTranslation()[i]) < 1.e-14)
57
58 def event(self):
59 """ test that moving a ladder moves the sensor in the event processing """
61
62 original_global_sensor_z = cache.getSensorInfo(Belle2.VxdID("1.1.1")).pointToGlobal(ROOT.Math.XYZVector(0, 0, 0), True).Z()
63
64 # Now move ladder... we need a copy of the current alignment
65 alignment = Belle2.PyDBObj("VXDAlignment").obj().Clone()
66 # Set the ladder here, not the sensor
67 alignment.set(Belle2.VxdID("1.1.0").getID(), Belle2.VXDAlignment.dW, self.test_shift_z)
68 # and add the object to the database store. This will run the callback
69 Belle2.DBStore.Instance().addConstantOverride("VXDAlignment", alignment)
70
71 new_global_sensor_z = cache.getSensorInfo(Belle2.VxdID("1.1.1")).pointToGlobal(ROOT.Math.XYZVector(0, 0, 0), True).Z()
72
73 # expect that sensor moved with the ladder
74 print("Now testing that moving a ladder moves a sensor correspondingly...")
75 assert (abs(new_global_sensor_z - original_global_sensor_z - self.test_shift_z) < 1.e-14)
76
77
78main = b2.create_path()
79# No params for EventInfoSetter means exp=0, run=0 --> Monte Carlo, no alignment corrections
80main.add_module('EventInfoSetter')
81main.add_module('Gearbox')
82main.add_module('Geometry')
83main.add_module(CompareTransformationsModule())
84b2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:28