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