CMS 3D CMS Logo

makeMuonMisalignmentScenario.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from optparse import OptionParser
3 from random import gauss
4 from math import sqrt
5 import os
6 execfile("Alignment/MuonAlignment/data/idealTransformation.py")
7 
8 ### Get variances and covariances from the commandline
9 
10 parser = OptionParser(usage="Usage: python %prog outputName [options] (default is unit matrix times 1e-15)")
11 
12 parser.add_option("--xx", dest="xx", help="variance of x (cm*cm)", default="1e-15")
13 parser.add_option("--xy", dest="xy", help="covariance of x and y (cm*cm)", default="0")
14 parser.add_option("--xz", dest="xz", help="covariance of x and z (cm*cm)", default="0")
15 parser.add_option("--xphix", dest="xphix", help="covariance of x and phix (cm*rad)", default="0")
16 parser.add_option("--xphiy", dest="xphiy", help="covariance of x and phiy (cm*rad)", default="0")
17 parser.add_option("--xphiz", dest="xphiz", help="covariance of x and phiz (cm*rad)", default="0")
18 
19 parser.add_option("--yy", dest="yy", help="variance of y (cm*cm)", default="1e-15")
20 parser.add_option("--yz", dest="yz", help="covariance of y and z (cm*cm)", default="0")
21 parser.add_option("--yphix", dest="yphix", help="covariance of y and phix (cm*rad)", default="0")
22 parser.add_option("--yphiy", dest="yphiy", help="covariance of y and phiy (cm*rad)", default="0")
23 parser.add_option("--yphiz", dest="yphiz", help="covariance of y and phiz (cm*rad)", default="0")
24 
25 parser.add_option("--zz", dest="zz", help="variance of z (cm*cm)", default="1e-15")
26 parser.add_option("--zphix", dest="zphix", help="covariance of z and phix (cm*rad)", default="0")
27 parser.add_option("--zphiy", dest="zphiy", help="covariance of z and phiy (cm*rad)", default="0")
28 parser.add_option("--zphiz", dest="zphiz", help="covariance of z and phiz (cm*rad)", default="0")
29 
30 parser.add_option("--phixphix", dest="phixphix", help="variance of phix (rad*rad)", default="1e-15")
31 parser.add_option("--phixphiy", dest="phixphiy", help="covariance of phix and phiy (rad*rad)", default="0")
32 parser.add_option("--phixphiz", dest="phixphiz", help="covariance of phix and phiz (rad*rad)", default="0")
33 
34 parser.add_option("--phiyphiy", dest="phiyphiy", help="variance of phiy (rad*rad)", default="1e-15")
35 parser.add_option("--phiyphiz", dest="phiyphiz", help="covariance of phiy and phiz (rad*rad)", default="0")
36 
37 parser.add_option("--phizphiz", dest="phizphiz", help="variance of phiz (rad*rad)", default="1e-15")
38 
39 parser.add_option("-f", dest="force", help="force overwrite of output files", action="store_true")
40 
41 options, args = parser.parse_args()
42 if args is None or len(args) != 1:
43  parser.print_help()
44  exit(-1)
45 outputName = args[0]
46 
47 if not options.force:
48  if os.path.exists(outputName + ".xml"):
49  raise Exception(outputName + ".xml exists!")
50  if os.path.exists(outputName + "_convert_cfg.py"):
51  raise Exception(outputName + "_convert_cfg.py exists!")
52  if os.path.exists(outputName + ".db"):
53  raise Exception(outputName + ".db exists!")
54  if os.path.exists(outputName + "_correlations.txt"):
55  raise Exception(outputName + "_correlations.txt exists!")
56 
57 components = "xx", "xy", "xz", "xphix", "xphiy", "xphiz", "yy", "yz", "yphix", "yphiy", "yphiz", "zz", "zphix", "zphiy", "zphiz", "phixphix", "phixphiy", "phixphiz", "phiyphiy", "phiyphiz", "phizphiz"
58 for component in components:
59  exec("%s = float(options.%s)" % (component, component))
60 
61 ### Print out user's choices as diagnostics
62 
63 print("Spread in each parameter: x %g mm" % (sqrt(xx)*10.))
64 print(" y %g mm" % (sqrt(yy)*10.))
65 print(" z %g mm" % (sqrt(zz)*10.))
66 print(" phix %g mrad" % (sqrt(phixphix)*1000.))
67 print(" phiy %g mrad" % (sqrt(phiyphiy)*1000.))
68 print(" phiz %g mrad" % (sqrt(phizphiz)*1000.))
69 print()
70 
71 print("Covariance matrix (x, y, z, phix, phiy, phiz):")
72 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xx, xy, xz, xphix, xphiy, xphiz))
73 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xy, yy, yz, yphix, yphiy, yphiz))
74 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xz, yz, zz, zphix, zphiy, zphiz))
75 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xphix, yphix, zphix, phixphix, phixphiy, phixphiz))
76 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xphiy, yphiy, zphiy, phixphiy, phiyphiy, phiyphiz))
77 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xphiz, yphiz, zphiz, phixphiz, phiyphiz, phizphiz))
78 print()
79 
80 print("Correlation (x, y, z, phix, phiy, phiz):")
81 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xx/sqrt(xx)/sqrt(xx), xy/sqrt(xx)/sqrt(yy), xz/sqrt(xx)/sqrt(zz), xphix/sqrt(xx)/sqrt(phixphix), xphiy/sqrt(xx)/sqrt(phiyphiy), xphiz/sqrt(xx)/sqrt(phizphiz)))
82 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xy/sqrt(yy)/sqrt(xx), yy/sqrt(yy)/sqrt(yy), yz/sqrt(yy)/sqrt(zz), yphix/sqrt(yy)/sqrt(phixphix), yphiy/sqrt(yy)/sqrt(phiyphiy), yphiz/sqrt(yy)/sqrt(phizphiz)))
83 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xz/sqrt(zz)/sqrt(xx), yz/sqrt(zz)/sqrt(yy), zz/sqrt(zz)/sqrt(zz), zphix/sqrt(zz)/sqrt(phixphix), zphiy/sqrt(zz)/sqrt(phiyphiy), zphiz/sqrt(zz)/sqrt(phizphiz)))
84 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xphix/sqrt(phixphix)/sqrt(xx), yphix/sqrt(phixphix)/sqrt(yy), zphix/sqrt(phixphix)/sqrt(zz), phixphix/sqrt(phixphix)/sqrt(phixphix), phixphiy/sqrt(phixphix)/sqrt(phiyphiy), phixphiz/sqrt(phixphix)/sqrt(phizphiz)))
85 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xphiy/sqrt(phiyphiy)/sqrt(xx), yphiy/sqrt(phiyphiy)/sqrt(yy), zphiy/sqrt(phiyphiy)/sqrt(zz), phixphiy/sqrt(phiyphiy)/sqrt(phixphix), phiyphiy/sqrt(phiyphiy)/sqrt(phiyphiy), phiyphiz/sqrt(phiyphiy)/sqrt(phizphiz)))
86 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (xphiz/sqrt(phizphiz)/sqrt(xx), yphiz/sqrt(phizphiz)/sqrt(yy), zphiz/sqrt(phizphiz)/sqrt(zz), phixphiz/sqrt(phizphiz)/sqrt(phixphix), phiyphiz/sqrt(phizphiz)/sqrt(phiyphiy), phizphiz/sqrt(phizphiz)/sqrt(phizphiz)))
87 print()
88 
89 for correlation_coefficient in [abs(xy/sqrt(xx)/sqrt(yy)), abs(xz/sqrt(xx)/sqrt(zz)), abs(xphix/sqrt(xx)/sqrt(phixphix)), abs(xphiy/sqrt(xx)/sqrt(phiyphiy)), abs(xphiz/sqrt(xx)/sqrt(phizphiz)), \
90  abs(yz/sqrt(yy)/sqrt(zz)), abs(yphix/sqrt(yy)/sqrt(phixphix)), abs(yphiy/sqrt(yy)/sqrt(phiyphiy)), abs(yphiz/sqrt(yy)/sqrt(phizphiz)),
91  abs(zphix/sqrt(zz)/sqrt(phixphix)), abs(zphiy/sqrt(zz)/sqrt(phiyphiy)), abs(zphiz/sqrt(zz)/sqrt(phizphiz)),
92  abs(phixphiy/sqrt(phixphix)/sqrt(phiyphiy)), abs(phixphiz/sqrt(phixphix)/sqrt(phizphiz)),
93  abs(phiyphiz/sqrt(phiyphiy)/sqrt(phizphiz))]:
94  if correlation_coefficient > 1.:
95  raise Exception("Correlations must not be larger than one!")
96 
97 ### Some useful mathematical transformations (why don't we have access to numpy?)
98 
99 def mmult(a, b):
100  """Matrix multiplication: mmult([[11, 12], [21, 22]], [[-1, 0], [0, 1]]) returns [[-11, 12], [-21, 22]]"""
101  return [[sum([i*j for i, j in zip(row, col)]) for col in zip(*b)] for row in a]
102 
103 def mvdot(m, v):
104  """Applies matrix m to vector v: mvdot([[-1, 0], [0, 1]], [12, 55]) returns [-12, 55]"""
105  return [i[0] for i in mmult(m, [[vi] for vi in v])]
106 
107 def mtrans(a):
108  """Matrix transposition: mtrans([[11, 12], [21, 22]]) returns [[11, 21], [12, 22]]"""
109  return [[a[j][i] for j in range(len(a[i]))] for i in range(len(a))]
110 
111 def cholesky(A):
112  """Cholesky decomposition of the correlation matrix to properly normalize the transformed random deviates"""
113 
114  # A = L * D * L^T = (L * D^0.5) * (L * D^0.5)^T where we want (L * D^0.5), the "square root" of A
115  # find L and D from A using recurrence relations
116  L = {}
117  D = {}
118  for j in range(len(A[0])):
119  D[j] = A[j][j] - sum([L[j,k]**2 * D[k] for k in range(j)])
120  for i in range(len(A)):
121  if i > j:
122  L[i,j] = (A[i][j] - sum([L[i,k] * L[j,k] * D[k] for k in range(j)])) / D[j]
123 
124  L = [[ 1., 0., 0., 0., 0., 0.],
125  [L[1,0], 1., 0., 0., 0., 0.],
126  [L[2,0], L[2,1], 1., 0., 0., 0.],
127  [L[3,0], L[3,1], L[3,2], 1., 0., 0.],
128  [L[4,0], L[4,1], L[4,2], L[4,1], 1., 0.],
129  [L[5,0], L[5,1], L[5,2], L[5,1], L[5,0], 1.]]
130 
131  Dsqrt = [[sqrt(D[0]), 0., 0., 0., 0., 0.],
132  [ 0., sqrt(D[1]), 0., 0., 0., 0.],
133  [ 0., 0., sqrt(D[2]), 0., 0., 0.],
134  [ 0., 0., 0., sqrt(D[3]), 0., 0.],
135  [ 0., 0., 0., 0., sqrt(D[4]), 0.],
136  [ 0., 0., 0., 0., 0., sqrt(D[5])]]
137 
138  return mmult(L, Dsqrt)
139 
140 matrix = [[ xx, xy, xz, xphix, xphiy, xphiz],
141  [ xy, yy, yz, yphix, yphiy, yphiz],
142  [ xz, yz, zz, zphix, zphiy, zphiz],
143  [xphix, yphix, zphix, phixphix, phixphiy, phixphiz],
144  [xphiy, yphiy, zphiy, phixphiy, phiyphiy, phiyphiz],
145  [xphiz, yphiz, zphiz, phixphiz, phiyphiz, phizphiz]]
146 
147 chomat = cholesky(matrix)
148 
149 ### Generate correlated random misalignments for all chambers
150 
152  randomunit = [gauss(0., 1.), gauss(0., 1.), gauss(0., 1.), gauss(0., 1.), gauss(0., 1.), gauss(0., 1.)]
153  return mvdot(chomat, randomunit)
154 
155 misal = {}
156 
157 for wheel in -2, -1, 0, 1, 2:
158  for station in 1, 2, 3, 4:
159  for sector in range(1, 14+1):
160  if station != 4 and sector > 12: continue
161 
162  misal["DT", wheel, station, 0, sector] = random6dof()
163 
164 for endcap in 1, 2:
165  for station in 1, 2, 3, 4:
166  for ring in 1, 2, 3:
167  if station > 1 and ring == 3: continue
168  for sector in range(1, 36+1):
169  if station > 1 and ring == 1 and sector > 18: continue
170 
171  misal["CSC", endcap, station, ring, sector] = random6dof()
172 
173 ### More diagnostics
174 
175 sum_x = 0.
176 sum_y = 0.
177 sum_z = 0.
178 sum_phix = 0.
179 sum_phiy = 0.
180 sum_phiz = 0.
181 
182 sum_xx = 0.
183 sum_xy = 0.
184 sum_xz = 0.
185 sum_xphix = 0.
186 sum_xphiy = 0.
187 sum_xphiz = 0.
188 sum_yy = 0.
189 sum_yz = 0.
190 sum_yphix = 0.
191 sum_yphiy = 0.
192 sum_yphiz = 0.
193 sum_zz = 0.
194 sum_zphix = 0.
195 sum_zphiy = 0.
196 sum_zphiz = 0.
197 sum_phixphix = 0.
198 sum_phixphiy = 0.
199 sum_phixphiz = 0.
200 sum_phiyphiy = 0.
201 sum_phiyphiz = 0.
202 sum_phizphiz = 0.
203 
204 for xi, yi, zi, phixi, phiyi, phizi in misal.values():
205  sum_x += xi
206  sum_y += yi
207  sum_z += zi
208  sum_phix += phixi
209  sum_phiy += phiyi
210  sum_phiz += phizi
211 
212  sum_xx += xi*xi
213  sum_xy += xi*yi
214  sum_xz += xi*zi
215  sum_xphix += xi*phixi
216  sum_xphiy += xi*phiyi
217  sum_xphiz += xi*phizi
218  sum_yy += yi*yi
219  sum_yz += yi*zi
220  sum_yphix += yi*phixi
221  sum_yphiy += yi*phiyi
222  sum_yphiz += yi*phizi
223  sum_zz += zi*zi
224  sum_zphix += zi*phixi
225  sum_zphiy += zi*phiyi
226  sum_zphiz += zi*phizi
227  sum_phixphix += phixi*phixi
228  sum_phixphiy += phixi*phiyi
229  sum_phixphiz += phixi*phizi
230  sum_phiyphiy += phiyi*phiyi
231  sum_phiyphiz += phiyi*phizi
232  sum_phizphiz += phizi*phizi
233 
234 ave_x = sum_x/float(len(misal))
235 ave_y = sum_y/float(len(misal))
236 ave_z = sum_z/float(len(misal))
237 ave_phix = sum_phix/float(len(misal))
238 ave_phiy = sum_phiy/float(len(misal))
239 ave_phiz = sum_phiz/float(len(misal))
240 
241 ave_xx = sum_xx/float(len(misal))
242 ave_xy = sum_xy/float(len(misal))
243 ave_xz = sum_xz/float(len(misal))
244 ave_xphix = sum_xphix/float(len(misal))
245 ave_xphiy = sum_xphiy/float(len(misal))
246 ave_xphiz = sum_xphiz/float(len(misal))
247 ave_yy = sum_yy/float(len(misal))
248 ave_yz = sum_yz/float(len(misal))
249 ave_yphix = sum_yphix/float(len(misal))
250 ave_yphiy = sum_yphiy/float(len(misal))
251 ave_yphiz = sum_yphiz/float(len(misal))
252 ave_zz = sum_zz/float(len(misal))
253 ave_zphix = sum_zphix/float(len(misal))
254 ave_zphiy = sum_zphiy/float(len(misal))
255 ave_zphiz = sum_zphiz/float(len(misal))
256 ave_phixphix = sum_phixphix/float(len(misal))
257 ave_phixphiy = sum_phixphiy/float(len(misal))
258 ave_phixphiz = sum_phixphiz/float(len(misal))
259 ave_phiyphiy = sum_phiyphiy/float(len(misal))
260 ave_phiyphiz = sum_phiyphiz/float(len(misal))
261 ave_phizphiz = sum_phizphiz/float(len(misal))
262 
263 print("Estimated covariance matrix from %d chambers (x, y, z, phix, phiy, phiz):" % len(misal))
264 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xx, ave_xy, ave_xz, ave_xphix, ave_xphiy, ave_xphiz))
265 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xy, ave_yy, ave_yz, ave_yphix, ave_yphiy, ave_yphiz))
266 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xz, ave_yz, ave_zz, ave_zphix, ave_zphiy, ave_zphiz))
267 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xphix, ave_yphix, ave_zphix, ave_phixphix, ave_phixphiy, ave_phixphiz))
268 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xphiy, ave_yphiy, ave_zphiy, ave_phixphiy, ave_phiyphiy, ave_phiyphiz))
269 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xphiz, ave_yphiz, ave_zphiz, ave_phixphiz, ave_phiyphiz, ave_phizphiz))
270 print()
271 
272 print("Estimated correlation from %d chambers (x, y, z, phix, phiy, phiz):" % len(misal))
273 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xx/sqrt(ave_xx)/sqrt(ave_xx), ave_xy/sqrt(ave_xx)/sqrt(ave_yy), ave_xz/sqrt(ave_xx)/sqrt(ave_zz), ave_xphix/sqrt(ave_xx)/sqrt(ave_phixphix), ave_xphiy/sqrt(ave_xx)/sqrt(ave_phiyphiy), ave_xphiz/sqrt(ave_xx)/sqrt(ave_phizphiz)))
274 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xy/sqrt(ave_yy)/sqrt(ave_xx), ave_yy/sqrt(ave_yy)/sqrt(ave_yy), ave_yz/sqrt(ave_yy)/sqrt(ave_zz), ave_yphix/sqrt(ave_yy)/sqrt(ave_phixphix), ave_yphiy/sqrt(ave_yy)/sqrt(ave_phiyphiy), ave_yphiz/sqrt(ave_yy)/sqrt(ave_phizphiz)))
275 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xz/sqrt(ave_zz)/sqrt(ave_xx), ave_yz/sqrt(ave_zz)/sqrt(ave_yy), ave_zz/sqrt(ave_zz)/sqrt(ave_zz), ave_zphix/sqrt(ave_zz)/sqrt(ave_phixphix), ave_zphiy/sqrt(ave_zz)/sqrt(ave_phiyphiy), ave_zphiz/sqrt(ave_zz)/sqrt(ave_phizphiz)))
276 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xphix/sqrt(ave_phixphix)/sqrt(ave_xx), ave_yphix/sqrt(ave_phixphix)/sqrt(ave_yy), ave_zphix/sqrt(ave_phixphix)/sqrt(ave_zz), ave_phixphix/sqrt(ave_phixphix)/sqrt(ave_phixphix), ave_phixphiy/sqrt(ave_phixphix)/sqrt(ave_phiyphiy), ave_phixphiz/sqrt(ave_phixphix)/sqrt(ave_phizphiz)))
277 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xphiy/sqrt(ave_phiyphiy)/sqrt(ave_xx), ave_yphiy/sqrt(ave_phiyphiy)/sqrt(ave_yy), ave_zphiy/sqrt(ave_phiyphiy)/sqrt(ave_zz), ave_phixphiy/sqrt(ave_phiyphiy)/sqrt(ave_phixphix), ave_phiyphiy/sqrt(ave_phiyphiy)/sqrt(ave_phiyphiy), ave_phiyphiz/sqrt(ave_phiyphiy)/sqrt(ave_phizphiz)))
278 print("%11.8f %11.8f %11.8f %11.8f %11.8f %11.8f" % (ave_xphiz/sqrt(ave_phizphiz)/sqrt(ave_xx), ave_yphiz/sqrt(ave_phizphiz)/sqrt(ave_yy), ave_zphiz/sqrt(ave_phizphiz)/sqrt(ave_zz), ave_phixphiz/sqrt(ave_phizphiz)/sqrt(ave_phixphix), ave_phiyphiz/sqrt(ave_phizphiz)/sqrt(ave_phiyphiy), ave_phizphiz/sqrt(ave_phizphiz)/sqrt(ave_phizphiz)))
279 print()
280 
281 ### Delete all three files at once to make sure the user never sees
282 ### stale data (e.g. from a stopped process due to failed conversion)
283 
284 if os.path.exists(outputName + ".xml"):
285  os.unlink(outputName + ".xml")
286 if os.path.exists(outputName + "_convert_cfg.py"):
287  os.unlink(outputName + "_convert_cfg.py")
288 if os.path.exists(outputName + ".db"):
289  os.unlink(outputName + ".db")
290 if os.path.exists(outputName + "_correlations.txt"):
291  os.unlink(outputName + "_correlations.txt")
292 
293 ### Print out the list of correlations
294 
295 txtfile = file(outputName + "_correlations.txt", "w")
296 for wheel in -2, -1, 0, 1, 2:
297  for station in 1, 2, 3, 4:
298  for sector in range(1, 14+1):
299  if station != 4 and sector > 12: continue
300  txtfile.write("DT %(wheel)d %(station)d %(sector)d %(xx)g %(xy)g %(xz)g %(xphix)g %(xphiy)g %(xphiz)g %(yy)g %(yz)g %(yphix)g %(yphiy)g %(yphiz)g %(zz)g %(zphix)g %(zphiy)g %(zphiz)g %(phixphix)g %(phixphiy)g %(phixphiz)g %(phiyphiy)g %(phiyphiz)g %(phizphiz)g\n" % vars())
301 
302 for endcap in 1, 2:
303  for station in 1, 2, 3, 4:
304  for ring in 1, 2, 3:
305  if station > 1 and ring == 3: continue
306  for sector in range(1, 36+1):
307  if station > 1 and ring == 1 and sector > 18: continue
308  txtfile.write("CSC %(endcap)d %(station)d %(ring)d %(sector)d %(xx)g %(xy)g %(xz)g %(xphix)g %(xphiy)g %(xphiz)g %(yy)g %(yz)g %(yphix)g %(yphiy)g %(yphiz)g %(zz)g %(zphix)g %(zphiy)g %(zphiz)g %(phixphix)g %(phixphiy)g %(phixphiz)g %(phiyphiy)g %(phiyphiz)g %(phizphiz)g\n" % vars())
309 
310 ### Make an XML representation of the misalignment
311 
312 xmlfile = file(outputName + ".xml", "w")
313 xmlfile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
314 xmlfile.write("<?xml-stylesheet type=\"text/xml\" href=\"MuonAlignment.xsl\"?>\n")
315 xmlfile.write("<MuonAlignment>\n\n")
316 
317 for (system, whendcap, station, ring, sector), (xi, yi, zi, phixi, phiyi, phizi) in misal.items():
318  if system == "DT": wheel = whendcap
319  if system == "CSC": endcap = whendcap
320 
321  rot = rotation[system, whendcap, station, ring, sector]
322  localape = [[xx, xy, xz], [xy, yy, yz], [xz, yz, zz]]
323  globalape = mmult(rot, mmult(localape, mtrans(rot)))
324  globalxx = globalape[0][0]
325  globalxy = globalape[0][1]
326  globalxz = globalape[0][2]
327  globalyy = globalape[1][1]
328  globalyz = globalape[1][2]
329  globalzz = globalape[2][2]
330 
331  xmlfile.write("<operation>\n")
332 
333  if system == "DT":
334  xmlfile.write(" <DTChamber wheel=\"%(wheel)d\" station=\"%(station)d\" sector=\"%(sector)d\" />\n" % vars())
335  if system == "CSC":
336  xmlfile.write(" <CSCChamber endcap=\"%(endcap)d\" station=\"%(station)d\" ring=\"%(ring)d\" chamber=\"%(sector)d\" />\n" % vars())
337 
338  # ME1/1a is called "ring 4", but it should always get exactly the same alignment constants as the corresponding ME1/1b ("ring 1")
339  if (station, ring) == (1, 1):
340  xmlfile.write(" <CSCChamber endcap=\"%(endcap)d\" station=\"%(station)d\" ring=\"4\" chamber=\"%(sector)d\" />\n" % vars())
341 
342  xmlfile.write(" <setposition relativeto=\"ideal\" x=\"%(xi)g\" y=\"%(yi)g\" z=\"%(zi)g\" phix=\"%(phixi)g\" phiy=\"%(phiyi)g\" phiz=\"%(phizi)g\" />\n" % vars())
343  xmlfile.write(" <setape xx=\"%(globalxx)g\" xy=\"%(globalxy)g\" xz=\"%(globalxz)g\" yy=\"%(globalyy)g\" yz=\"%(globalyz)g\" zz=\"%(globalzz)g\" />\n" % vars())
344  xmlfile.write("</operation>\n\n")
345 
346 xmlfile.write("</MuonAlignment>\n")
347 xmlfile.close()
348 
349 ### Convert it to an SQLite file with CMSSW
350 
351 cfgfile = file(outputName + "_convert_cfg.py", "w")
352 
353 cfgfile.write("""import FWCore.ParameterSet.Config as cms
354 
355 process = cms.Process("CONVERT")
356 process.source = cms.Source("EmptySource")
357 process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))
358 
359 process.load("Configuration.StandardSequences.GeometryDB_cff")
360 process.load("Geometry.MuonNumbering.muonNumberingInitialization_cfi")
361 
362 process.MuonGeometryDBConverter = cms.EDAnalyzer("MuonGeometryDBConverter",
363  input = cms.string("xml"),
364  fileName = cms.string("%(outputName)s.xml"),
365  shiftErr = cms.double(1000.),
366  angleErr = cms.double(6.28),
367 
368  output = cms.string("db")
369  )
370 
371 process.load("CondCore.DBCommon.CondDBSetup_cfi")
372 process.PoolDBOutputService = cms.Service("PoolDBOutputService",
373  process.CondDBSetup,
374  connect = cms.string("sqlite_file:%(outputName)s.db"),
375  toPut = cms.VPSet(cms.PSet(record = cms.string("DTAlignmentRcd"), tag = cms.string("DTAlignmentRcd")),
376  cms.PSet(record = cms.string("DTAlignmentErrorExtendedRcd"), tag = cms.string("DTAlignmentErrorExtendedRcd")),
377  cms.PSet(record = cms.string("CSCAlignmentRcd"), tag = cms.string("CSCAlignmentRcd")),
378  cms.PSet(record = cms.string("CSCAlignmentErrorExtendedRcd"), tag = cms.string("CSCAlignmentErrorExtendedRcd"))))
379 
380 process.Path = cms.Path(process.MuonGeometryDBConverter)
381 """ % vars())
382 
383 print("To create an SQLite file for this geometry (%(outputName)s.db), run the following:" % vars())
384 print()
385 os.system("echo cmsRun %s_convert_cfg.py" % outputName)
386 
def random6dof()
Generate correlated random misalignments for all chambers.
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def mmult(a, b)
Print out user&#39;s choices as diagnostics.