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