Belle II Software  release-05-02-19
misalignment.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 import basf2 as b2
4 
5 import ROOT
6 from ROOT import Belle2
7 
8 import math
9 
10 
12  """
13  Base class to calculate global deformation of the detector
14  """
15 
16  def __init__(self, scale):
17  """ Constructor, sets the scale of the transformation """
18 
19 
20  self.scale = scale
21 
22  def __call__(self, xyz):
23  """ Return TVector3 with difference in global position induced by the deformation,
24  given the original x,y,z position as TVector3 or a list with length of 3.
25  """
26 
27  rphiz = self._xyz_to_rphiz(xyz)
28  d_rphiz = self._transform(rphiz[0], rphiz[1], rphiz[2])
29 
30  rphiz[0] += d_rphiz[0]
31  rphiz[1] += d_rphiz[1]
32  rphiz[2] += d_rphiz[2]
33 
34  new_xyz = self._rphiz_to_xyz(rphiz)
35 
36  d_xyz = ROOT.TVector3(new_xyz[0] - xyz[0], new_xyz[1] - xyz[1], new_xyz[2] - xyz[2])
37 
38  return d_xyz
39 
40  def _transform(self, r, phi, z):
41  """ Fcn to be overriden by child classes, return vector (list of 3 numbers) of displacement """
42 
43  def _xyz_to_rphiz(self, xyz):
44  """ Convert (x,y,z) to (r,phi,z) """
45  import math
46  x = xyz[0]
47  y = xyz[1]
48  z = xyz[2]
49  r = math.sqrt(x * x + y * y)
50  phi = math.atan2(y, x)
51  rphiz = [r, phi, z]
52  return rphiz
53 
54  def _rphiz_to_xyz(self, rphiz):
55  """ Convert (r,phi,z) to (x,y,z) """
56  import math
57  z = rphiz[2]
58  y = rphiz[0] * math.sin(rphiz[1])
59  x = rphiz[0] * math.cos(rphiz[1])
60  return [x, y, z]
61 
62 
64  """ radial expansion """
65 
66  def __init__(self, scale):
67  """ init """
68  super().__init__(scale)
69 
70  def _transform(self, r, phi, z):
71  """ the transformation """
72  return [self.scale * r, 0., 0.]
73 
74 
76  """ Curl """
77 
78  def __init__(self, scale, scale2=0.):
79  """ init with scale, optionally scale2 for 1/r dependency """
80 
81 
82  self.scale2 = scale2
83  super().__init__(scale)
84 
85  def _transform(self, r, phi, z):
86  """ the transformation """
87  return [0., self.scale * r + self.scale2 / r, 0.]
88 
89 
91  """ Telescope """
92 
93  def __init__(self, scale):
94  """ init """
95  super().__init__(scale)
96 
97  def _transform(self, r, phi, z):
98  """ the transformation """
99  return [0., 0., self.scale * r]
100 
101 
103  """ Elliptical distortion """
104 
105  def __init__(self, scale):
106  """ init """
107  super().__init__(scale)
108 
109  def _transform(self, r, phi, z):
110  """ the transformation """
111  import math
112  return [self.scale * 1. / 2. * math.cos(2 * phi) * r, 0., 0.]
113 
114 
116  """ Clamshell deformation """
117 
118  def __init__(self, scale):
119  """ init """
120  super().__init__(scale)
121 
122  def _transform(self, r, phi, z):
123  """ the transformation """
124  import math
125 
126  return [0., self.scale * math.cos(phi), 0.]
127 
128 
130  """ Skew distortion """
131 
132  def __init__(self, scale):
133  """ init """
134  super().__init__(scale)
135 
136  def _transform(self, r, phi, z):
137  """ the transformation """
138  return [0., 0., self.scale * math.cos(phi) * r]
139 
140 
142  """ Bowing """
143 
144  def __init__(self, scale):
145  """ init """
146  super().__init__(scale)
147 
148  def _transform(self, r, phi, z):
149  """ the transformation """
150  return [self.scale * abs(z), 0., 0.]
151 
152 
154  """ Twist deformation """
155 
156  def __init__(self, scale):
157  """ init """
158  super().__init__(scale)
159 
160  def _transform(self, r, phi, z):
161  """ the transformation """
162  return [0., self.scale * z, 0.]
163 
164 
166  """ Z-expansion """
167 
168  def __init__(self, scale):
169  """ init """
170  super().__init__(scale)
171 
172  def _transform(self, r, phi, z):
173  """ the transformation """
174  return [0., 0., self.scale * z]
175 
176 
177 class CreateMisalignmentModule(b2.Module):
178  """ Module to create misalignment (first reads real sensor positions, then applies misalignment and returns DB payload)
179  TODO: random misalignment not finished...
180  """
181 
182  def __init__(self, global_deformations=None, random_misalignments=None, iov=Belle2.IntervalOfValidity(0, 0, -1, -1)):
183  """ Constructor with with input misalignment """
184 
185 
186  self.global_deformations = global_deformations
187 
188  self.random_misalignments = random_misalignments
189 
190  self.iov = iov
191 
192  super().__init__()
193 
194  def initialize(self):
195  """ module initialize - read geometry, apply misalignment, create and store payloads """
196 
197  alignment = Belle2.VXDAlignment()
198  txt = open('generated_misalignment.txt', 'w')
199  txt.write('layer ladder sensor x_orig y_orig z_orig x y z u v w\n')
200 
201  for sensor in Belle2.VXD.GeoCache.getInstance().getListOfSensors():
202  info = Belle2.VXD.GeoCache.getInstance().get(sensor)
203  global_pos = info.pointToGlobal(ROOT.TVector3(0., 0., 0.))
204 
205  delta = ROOT.TVector3(0., 0., 0.)
206 
207  if self.global_deformations is not None:
208  if not isinstance(self.global_deformations, list):
210 
211  for deformation in self.global_deformations:
212  delta += deformation(global_pos)
213 
214  if sensor == Belle2.VxdID(1, 1, 1):
215  delta = ROOT.TVector3(0., 0., 0.)
216 
217  new_global_pos = global_pos + delta
218  new_local_pos = info.pointToLocal(new_global_pos)
219 
220  if self.random_misalignments is not None:
221  if not isinstance(self.random_misalignments, list):
223 
224  for random in self.random_misalignments:
225  pass
226 
227  for i in range(0, 3):
228  if abs(new_local_pos[i]) < 1.e-14:
229  new_local_pos[i] = 0.
230 
231  alignment.set(sensor.getID(), i + 1, new_local_pos[i])
232 
233  # helper = GlobalDeformation(0.)
234 
235  # global_pos = helper._xyz_to_rphiz(global_pos)
236  # new_global_pos = helper._xyz_to_rphiz(new_global_pos)
237 
238  txt.write(
239  '{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}\n'.format(
240  str(sensor.getLayerNumber()),
241  str(sensor.getLadderNumber()),
242  str(sensor.getSensorNumber()),
243  str(global_pos[0]),
244  str(global_pos[1]),
245  str(global_pos[2]),
246  str(new_global_pos[0]),
247  str(new_global_pos[1]),
248  str(new_global_pos[2]),
249  str(new_local_pos[0]),
250  str(new_local_pos[1]),
251  str(new_local_pos[2])
252  ))
253 
254  txt.close()
255 
256  Belle2.Database.Instance().storeData('VXDAlignment', alignment, self.iov)
257  txt.close()
alignment.misalignment.Bowing
Definition: misalignment.py:141
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
alignment.misalignment.GlobalDeformation._xyz_to_rphiz
def _xyz_to_rphiz(self, xyz)
Definition: misalignment.py:43
alignment.misalignment.Clamshell
Definition: misalignment.py:115
alignment.misalignment.Elliptical.__init__
def __init__(self, scale)
Definition: misalignment.py:105
alignment.misalignment.Clamshell.__init__
def __init__(self, scale)
Definition: misalignment.py:118
alignment.misalignment.Bowing._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:148
alignment.misalignment.Twist
Definition: misalignment.py:153
alignment.misalignment.ZExpansion.__init__
def __init__(self, scale)
Definition: misalignment.py:168
alignment.misalignment.Telescope
Definition: misalignment.py:90
alignment.misalignment.RadialExpansion.__init__
def __init__(self, scale)
Definition: misalignment.py:66
alignment.misalignment.GlobalDeformation._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:40
alignment.misalignment.Twist.__init__
def __init__(self, scale)
Definition: misalignment.py:156
alignment.misalignment.CreateMisalignmentModule.random_misalignments
random_misalignments
random misalignments
Definition: misalignment.py:188
alignment.misalignment.Skew
Definition: misalignment.py:129
alignment.misalignment.Elliptical
Definition: misalignment.py:102
alignment.misalignment.RadialExpansion
Definition: misalignment.py:63
alignment.misalignment.Twist._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:160
alignment.misalignment.Skew.__init__
def __init__(self, scale)
Definition: misalignment.py:132
alignment.misalignment.Skew._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:136
alignment.misalignment.GlobalDeformation.__call__
def __call__(self, xyz)
Definition: misalignment.py:22
alignment.misalignment.Curl
Definition: misalignment.py:75
alignment.misalignment.Curl._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:85
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
alignment.misalignment.CreateMisalignmentModule.__init__
def __init__(self, global_deformations=None, random_misalignments=None, iov=Belle2.IntervalOfValidity(0, 0, -1, -1))
Definition: misalignment.py:182
alignment.misalignment.ZExpansion
Definition: misalignment.py:165
alignment.misalignment.GlobalDeformation._rphiz_to_xyz
def _rphiz_to_xyz(self, rphiz)
Definition: misalignment.py:54
alignment.misalignment.RadialExpansion._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:70
alignment.misalignment.ZExpansion._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:172
alignment.misalignment.Clamshell._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:122
alignment.misalignment.GlobalDeformation.scale
scale
scaling parameter of the deformation
Definition: misalignment.py:20
alignment.misalignment.Bowing.__init__
def __init__(self, scale)
Definition: misalignment.py:144
alignment.misalignment.GlobalDeformation.__init__
def __init__(self, scale)
Definition: misalignment.py:16
Belle2::Database::Instance
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:54
alignment.misalignment.Elliptical._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:109
alignment.misalignment.CreateMisalignmentModule.initialize
def initialize(self)
Definition: misalignment.py:194
alignment.misalignment.CreateMisalignmentModule.iov
iov
interval of validity for the generated payload
Definition: misalignment.py:190
alignment.misalignment.GlobalDeformation
Definition: misalignment.py:11
alignment.misalignment.Telescope.__init__
def __init__(self, scale)
Definition: misalignment.py:93
alignment.misalignment.Curl.__init__
def __init__(self, scale, scale2=0.)
Definition: misalignment.py:78
alignment.misalignment.Curl.scale2
scale2
second scale for 1/r member
Definition: misalignment.py:82
alignment.misalignment.CreateMisalignmentModule.global_deformations
global_deformations
systematic deformations
Definition: misalignment.py:186
Belle2::VXDAlignment
VXD alignment (and maybe some calibration) parameters.
Definition: VXDAlignment.h:29
alignment.misalignment.CreateMisalignmentModule
Definition: misalignment.py:177
alignment.misalignment.Telescope._transform
def _transform(self, r, phi, z)
Definition: misalignment.py:97