-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDREAMHR_calculate_voxels.py
More file actions
411 lines (304 loc) · 15.2 KB
/
DREAMHR_calculate_voxels.py
File metadata and controls
411 lines (304 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wednesday May 11 10:45:32 2022
@author: irinastefanescu
"""
import numpy as np
np.set_printoptions(precision=4)
"""
*******The HR for DREAM ******
Uses the engineering specifications from the company CDT and
generates the centers and dimensions of the voxels for the
DREAM HR module.
First version of this script written by Irina Stefanescu, ESS DG.
May 2022.
data is in mm
"""
"""**************User parameters *****************"""
nHR = 8 # no of segments per module
no_modulesHR = 9 # no of modules in the frame
no_sectorsHR = 4 # no of sectors
"""***********************************************"""
hHR = 170 # segment height front, sample side
sensHR = 313 # segment depth
wHR = 20 # segment width front, sample side
margin = 10 # empty space inside the segment front-back and left-right
marginb = 1.5 # empty space inside the segment top-bottom
shieldz = 25 # length of the shielding block at the back of the segment
mod_dist = 2 # distance between neighboring segments in order to avoid overlap
AlthickH = 0.3 # thickness Al cathode material and housing
BthickHR = 0.0013 # thickness Boron coating
# start position for placing the modules in the frame, integer number
# to multiply with 12*deg
init_angleHR = 0 # init angle in deg
tilt_theta = -10 # tilt_angle in deg
tilt_thetaHR = -1 # tilt_angle in deg
tilt_phiHR = -1 # inclination angle module in deg
n_wiresHR = 16 # no of wires
n_stripsHR = 32 # no of strips
dist_detHR = 2500 # distance from the sample in mm
# start calculations
# Al housing (box)
AlyHR = (hHR + 1) / 2 # 1/2 height Al housing at entrance window HR
AlzHR = (sensHR + margin) / 2 # depth housing HR
AlxHR = wHR / 2 # 1/2 width segment front in HR
"""
the next lines are for calculating the dimensions of
the inner volume that will be filled with gas voxels
the principle is similar to the Russian Matryoschka
dolls (nested dolls)
From the Al box representing the segment
housing subtract the box
representing the Boron coating on the side walls
and the remaining volume is the gas volume,
therefore the "G" letter used to name
the variables relevant to the gas voxels
"""
# Boron box
ByHR = AlyHR - AlthickH
BzHR = AlzHR - AlthickH
BxHR = AlxHR - AlthickH
# Gas volume available to the gas voxels
GyHR = ByHR
GzHR = BzHR - BthickHR
GxHR = BxHR - BthickHR
CathSubstrYHR = GyHR - marginb / 2
CathSubstrZHR = BzHR - margin / 2
CathConvYHR = CathSubstrYHR
CathConvZHR = CathSubstrZHR
CathConvXHR = BthickHR / 2
CathSubstrX1 = AlthickH / 2
# calculate the dimensions of the gas voxels
xxHR = GxHR - (2*CathConvXHR + AlthickH)
izzHR = sensHR / n_stripsHR # strip pitch HR in mm, all equal
GLzHR = izzHR / 2
GLyHR = hHR / 2 / n_wiresHR
GLxHR = xxHR / 2
# calculate the centers of the voxels
shp = (n_wiresHR, n_stripsHR)
voxelXXhr = np.zeros(shp)
voxelXXchr = np.zeros(shp)
voxelYYhr = np.zeros(shp)
voxelZZhr = np.zeros(shp)
for strip in range(n_stripsHR):
for wire in range(n_wiresHR):
# fill the voxels from the top to bottom and from front to back
voxelYYhr[wire, strip] = (n_wiresHR - 2 * wire - 1) * GLyHR
voxelZZhr[wire, strip] = (n_stripsHR//2 - strip - 1) * izzHR + margin/2
voxelXXhr[wire, strip] = AlthickH
voxelXXchr[wire, strip] = GLxHR + 2 * CathConvXHR + CathSubstrX1
# calculate the segment positions in the detector frame
segY = np.zeros(nHR)
segZ = - dist_detHR - AlzHR
segX = 0
for seg_no in range(nHR):
segY[seg_no] = 80 + (2 * AlxHR + 0.4) * (seg_no + 1)
# calculate the module positions in the detector frame
pos_mod = hHR + mod_dist # allow for 2 mm space between the modules
# Edit June 2024: modification back to initial definition to match the design of the installed HR detector.
m_hrx = np.array([0, 0, 0, pos_mod, pos_mod, pos_mod, 2*pos_mod, 2*pos_mod, 3*pos_mod])
m_hry = np.array([0, pos_mod, 2*pos_mod, 0, pos_mod, 2*pos_mod, 0, pos_mod, 0])
m_hrz = 0
shr_angle = np.array([0, -90, 180, 90])
""" calculate the lookup table """
shp = (no_sectorsHR, 100 * no_modulesHR + nHR, n_wiresHR, n_stripsHR)
# voxel positions after placing the segment in the frame
sxhr_z = np.zeros(shp)
syhr_z = np.zeros(shp)
szhr_z = np.zeros(shp)
sxhr_zx = np.zeros(shp)
syhr_zx = np.zeros(shp)
szhr_zx = np.zeros(shp)
sxhr_zxy = np.zeros(shp)
syhr_zxy = np.zeros(shp)
szhr_zxy = np.zeros(shp)
# voxel positions after placing the module in the frame
mhrx = np.zeros(shp)
mhry = np.zeros(shp)
mhrz = np.zeros(shp)
secx = np.zeros(shp)
secy = np.zeros(shp)
secz = np.zeros(shp)
with open('HR_temp.txt', "a") as f:
# voxels in the 'top counter'
for sec in range(no_sectorsHR):
secZ_s = np.sin(np.deg2rad(shr_angle[sec]))
secZ_c = np.cos(np.deg2rad(shr_angle[sec]))
for md in range(no_modulesHR):
for segment in range(nHR):
angZ = 90
angX = tilt_thetaHR
angY = tilt_phiHR
segZ_s = np.sin(np.deg2rad(angZ))
segZ_c = np.cos(np.deg2rad(angZ))
segY_s = np.sin(np.deg2rad(angY))
segY_c = np.cos(np.deg2rad(angY))
segX_s = np.sin(np.deg2rad(angX))
segX_c = np.cos(np.deg2rad(angX))
md_segt_id = 100 * md + segment
for strip in range(n_stripsHR):
for wire in range(n_wiresHR):
# rotation of each segment of the module by angZ
# around the Z-axis
sxhr_z[sec, md_segt_id, wire, strip] = -voxelYYhr[wire, strip] * segZ_s + \
(voxelXXhr[wire, strip] +
voxelXXchr[wire, strip]) * segZ_c
syhr_z[sec, md_segt_id, wire, strip] = \
voxelYYhr[wire, strip] * segZ_c + (voxelXXhr[wire, strip] +
voxelXXchr[wire, strip]) * segZ_s
szhr_z[sec, md_segt_id, wire, strip] = voxelZZhr[wire, strip]
# rotation of the segment around the X axis
sxhr_zx[sec, md_segt_id, wire, strip] = \
sxhr_z[sec, md_segt_id, wire, strip] * segX_c + \
szhr_z[sec, md_segt_id, wire, strip] * segX_s
syhr_zx[sec, md_segt_id, wire, strip] = syhr_z[sec, md_segt_id, wire, strip]
szhr_zx[sec, md_segt_id, wire, strip] = \
-sxhr_z[sec, md_segt_id, wire, strip] * segX_s + \
szhr_z[sec, md_segt_id, wire, strip] * segX_c
# rotation of the segment around the Y axis + translation
sxhr_zxy[sec, md_segt_id, wire, strip] = \
sxhr_zx[sec, md_segt_id, wire, strip] + segX
syhr_zxy[sec, md_segt_id, wire, strip] = \
syhr_zx[sec, md_segt_id, wire, strip] * segY_c - \
szhr_zx[sec, md_segt_id, wire, strip] * segY_s + segY[segment]
szhr_zxy[sec, md_segt_id, wire, strip] = \
syhr_zx[sec, md_segt_id, wire, strip] * segY_s + \
szhr_zx[sec, md_segt_id, wire, strip] * segY_c + segZ
# translation module
mhrx[sec, md_segt_id, wire, strip] = \
sxhr_zxy[sec, md_segt_id, wire, strip] + m_hrx[md]
mhry[sec, md_segt_id, wire, strip] = \
syhr_zxy[sec, md_segt_id, wire, strip] + m_hry[md]
mhrz[sec, md_segt_id, wire, strip] = \
szhr_zxy[sec, md_segt_id, wire, strip] + m_hrz
# rotation of the module around the Z-axis
secx[sec, md_segt_id, wire, strip] = \
-mhry[sec, md_segt_id, wire, strip] * secZ_s + \
mhrx[sec, md_segt_id, wire, strip] * secZ_c
secy[sec, md_segt_id, wire, strip] = \
mhry[sec, md_segt_id, wire, strip] * secZ_c + \
mhrx[sec, md_segt_id, wire, strip] * secZ_s
secz[sec, md_segt_id, wire, strip] = \
mhrz[sec, md_segt_id, wire, strip]
# Legend:
# 8 = 'HR'
# sector no, module no, segment no, wire no, strip no, counter no
temp = '%d\t%d\t%d\t%d\t%d\t%d\t%d' % (
8, sec + 1, md + 1, segment + 1, wire + 1, strip + 1, 1
)
# Legend: x,y,z voxel centers
temp1 = '%.2f\t%.2f\t%.2f' % (
secx[sec, md_segt_id, wire, strip],
secy[sec, md_segt_id, wire, strip],
secz[sec, md_segt_id, wire, strip]
)
# Legend:
# voxel dimensions to be used to generate Nexus
temp2 = '%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f' % (
0,
2 * GLxHR,
2 * GLxHR,
2 * GLyHR,
2 * GLyHR,
2 * GLzHR)
temp3 = '%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n' % (
angZ, -angX, -angY, shr_angle[sec], 0, 0, 0, 0, 0
)
stringa = temp + '\t' + temp1 + '\t' + temp2 + '\t' + temp3
if sec ==2 and md<=2:
pass
else:
f.writelines(stringa)
# voxels in the 'bottom counter'
for sec in range(no_sectorsHR):
secZ_s = np.sin(np.deg2rad(shr_angle[sec]))
secZ_c = np.cos(np.deg2rad(shr_angle[sec]))
for md in range(no_modulesHR):
for segment in range(nHR):
angZ = 90
angX = tilt_thetaHR
angY = tilt_phiHR
segZ_s = np.sin(np.deg2rad(angZ))
segZ_c = np.cos(np.deg2rad(angZ))
segY_s = np.sin(np.deg2rad(angY))
segY_c = np.cos(np.deg2rad(angY))
segX_s = np.sin(np.deg2rad(angX))
segX_c = np.cos(np.deg2rad(angX))
md_segt_id = 100 * md + segment
for strip in range(n_stripsHR):
for wire in range(n_wiresHR):
# rotation of each segment of the module by angZ
# around the Z-axis
sxhr_z[sec, md_segt_id, wire, strip] = \
-voxelYYhr[wire, strip] * segZ_s - \
(voxelXXhr[wire, strip] +
voxelXXchr[wire, strip]) * segZ_c
syhr_z[sec, md_segt_id, wire, strip] = \
voxelYYhr[wire, strip] * segZ_c - \
(voxelXXhr[wire, strip] +
voxelXXchr[wire, strip]) * segZ_s
szhr_z[sec, md_segt_id, wire, strip] = voxelZZhr[wire, strip]
# rotation of the segment around the X axis
sxhr_zx[sec, md_segt_id, wire, strip] = \
sxhr_z[sec, md_segt_id, wire, strip] * segX_c + \
szhr_z[sec, md_segt_id, wire, strip] * segX_s
syhr_zx[sec, md_segt_id, wire, strip] = \
syhr_z[sec, md_segt_id, wire, strip]
szhr_zx[sec, md_segt_id, wire, strip] = \
-sxhr_z[sec, md_segt_id, wire, strip] * segX_s + \
szhr_z[sec, md_segt_id, wire, strip] * segX_c
# rotation of the segment around the Y axis + translation
sxhr_zxy[sec, md_segt_id, wire, strip] = \
sxhr_zx[sec, md_segt_id, wire, strip] + segX
syhr_zxy[sec, md_segt_id, wire, strip] = \
syhr_zx[sec, md_segt_id, wire, strip] * segY_c - \
szhr_zx[sec, md_segt_id, wire, strip] * segY_s + segY[segment]
szhr_zxy[sec, md_segt_id, wire, strip] = \
syhr_zx[sec, md_segt_id, wire, strip] * segY_s + \
szhr_zx[sec, md_segt_id, wire, strip] * segY_c + segZ
# translation module
mhrx[sec, md_segt_id, wire, strip] = \
sxhr_zxy[sec, md_segt_id, wire, strip] + m_hrx[md]
mhry[sec, md_segt_id, wire, strip] = \
syhr_zxy[sec, md_segt_id, wire, strip] + m_hry[md]
mhrz[sec, md_segt_id, wire, strip] = \
szhr_zxy[sec, md_segt_id, wire, strip] + m_hrz
# rotation of the module around the Z-axis
secx[sec, md_segt_id, wire, strip] = \
-mhry[sec, md_segt_id, wire, strip] * secZ_s + \
mhrx[sec, md_segt_id, wire, strip] * secZ_c
secy[sec, md_segt_id, wire, strip] = \
mhry[sec, md_segt_id, wire, strip] * secZ_c + \
mhrx[sec, md_segt_id, wire, strip] * secZ_s
secz[sec, md_segt_id, wire, strip] = mhrz[sec, md_segt_id, wire, strip]
# Legend:
# 8 = 'HR'
# sector no, module no, segment no, wire no, strip no, counter no
temp = '%d\t%d\t%d\t%d\t%d\t%d\t%d' % (
8, sec + 1, md + 1, segment + 1,
wire + 1, strip + 1, 2
)
# Legend: x,y,z voxel centers
temp1 = '%.2f\t%.2f\t%.2f' % (
secx[sec, md_segt_id, wire, strip],
secy[sec, md_segt_id, wire, strip],
secz[sec, md_segt_id, wire, strip]
)
# Legend:
# voxel dimensions to be used to generate Nexus
temp2 = '%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f' % (
0,
2 * GLxHR,
2 * GLxHR,
2 * GLyHR,
2 * GLyHR,
2 * GLzHR)
temp3 = '%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n' % (
angZ, -angX, -angY, shr_angle[sec], 0, 0, 0, 0, 0
)
stringa = temp + '\t' + temp1 + '\t' + temp2 + '\t' + temp3
if sec == 2 and md <= 2:
pass
else:
f.writelines(stringa)