-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDREAMSANS_calculate_voxels.py
More file actions
404 lines (299 loc) · 15.4 KB
/
DREAMSANS_calculate_voxels.py
File metadata and controls
404 lines (299 loc) · 15.4 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sunday, January 28, 2024
@author: celinedurniak
"""
import numpy as np
np.set_printoptions(precision=4)
"""
*******The SANS for DREAM ******
Code adapted from implementation for High-Resolution detector
data is in mm
"""
"""**************User parameters *****************"""
nSANS = 8 # no of segments per module
no_modulesSANS = 9 # no of modules in the frame
no_sectorsSANS = 4 # no of sectors
"""***********************************************"""
hSANS = 170 # segment height front, sample side
sensSANS = 313 # segment depth
wSANS = 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
BthickSANS = 0.0013 # thickness Boron coating
# start position for placing the modules in the frame, integer number
# to multiply with 12*deg
init_angleSANS = 0 # init angle in deg
tilt_theta = -10 # tilt_angle in deg
tilt_thetaSANS = -1 # tilt_angle in deg
tilt_phiSANS = -1 # inclination angle module in deg
n_wiresSANS = 16 # no of wires
n_stripsSANS = 32 # no of strips
dist_detSANS = 2500 # distance from the sample in mm
# start calculations
# Al housing (box)
AlySANS = (hSANS + 1) / 2 # 1/2 height Al housing at entrance window SANS
AlzSANS = (sensSANS + margin) / 2 # depth housing SANS
AlxSANS = wSANS / 2 # 1/2 width segment front in SANS
"""
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
BySANS = AlySANS - AlthickH
BzSANS = AlzSANS - AlthickH
BxSANS = AlxSANS - AlthickH
# Gas volume available to the gas voxels
GySANS = BySANS
GzSANS = BzSANS - BthickSANS
GxSANS = BxSANS - BthickSANS
CathSubstrYSANS = GySANS - marginb / 2
CathSubstrZSANS = BzSANS - margin / 2
CathConvYSANS = CathSubstrYSANS
CathConvZSANS = CathSubstrZSANS
CathConvXSANS = BthickSANS / 2
CathSubstrX1 = AlthickH / 2
# calculate the dimensions of the gas voxels
xxSANS = GxSANS - (2*CathConvXSANS + AlthickH)
izzSANS = sensSANS / n_stripsSANS # strip pitch SANS in mm, all equal
GLzSANS = izzSANS / 2
GLySANS = hSANS / 2 / n_wiresSANS
GLxSANS = xxSANS / 2
# calculate the centers of the voxels
shp = (n_wiresSANS, n_stripsSANS)
voxelXXhr = np.zeros(shp)
voxelXXchr = np.zeros(shp)
voxelYYhr = np.zeros(shp)
voxelZZhr = np.zeros(shp)
for strip in range(n_stripsSANS):
for wire in range(n_wiresSANS):
# fill the voxels from the top to bottom and from front to back
voxelYYhr[wire, strip] = (n_wiresSANS - 2 * wire - 1) * GLySANS
voxelZZhr[wire, strip] = (n_stripsSANS//2 - strip - 1) * izzSANS + margin/2
voxelXXhr[wire, strip] = AlthickH
voxelXXchr[wire, strip] = GLxSANS + 2 * CathConvXSANS + CathSubstrX1
# calculate the segment positions in the detector frame
segY = np.zeros(nSANS)
segZ = - dist_detSANS - AlzSANS
segX = 0
for seg_no in range(nSANS):
segY[seg_no] = 80 + (2 * AlxSANS + 0.4) * (seg_no + 1)
# calculate the module positions in the detector frame
pos_mod = hSANS + mod_dist # allow for 2 mm space between the modules
# Edit Feb 2024: to match the new design from CDT.
# The translation along the x-axis for Sector 1 has to be reversed
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_sectorsSANS, 100 * no_modulesSANS + nSANS, n_wiresSANS, n_stripsSANS)
# 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('SANS_temp.txt', "a") as f:
# voxels in the 'top counter'
for sec in range(no_sectorsSANS):
secZ_s = np.sin(np.deg2rad(shr_angle[sec]))
secZ_c = np.cos(np.deg2rad(shr_angle[sec]))
for md in range(no_modulesSANS):
for segment in range(nSANS):
angZ = 90
angX = tilt_thetaSANS
angY = tilt_phiSANS
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_stripsSANS):
for wire in range(n_wiresSANS):
# 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:
# 9 = 'SANS'
# 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' % (
9, sec + 1, md + 1, segment + 1, wire + 1, strip + 1, 1
)
# Legend: x,y,z voxel centers
# the positions are first calculated for the High Resolution
# A rotation of 180 deg around Y axis is applied below
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 * GLxSANS,
2 * GLxSANS,
2 * GLySANS,
2 * GLySANS,
2 * GLzSANS)
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
f.writelines(stringa)
# voxels in the 'bottom counter'
for sec in range(no_sectorsSANS):
secZ_s = np.sin(np.deg2rad(shr_angle[sec]))
secZ_c = np.cos(np.deg2rad(shr_angle[sec]))
for md in range(no_modulesSANS):
for segment in range(nSANS):
angZ = 90
angX = tilt_thetaSANS
angY = tilt_phiSANS
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_stripsSANS):
for wire in range(n_wiresSANS):
# 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:
# 9 = 'SANS'
# 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' % (
9, sec + 1, md + 1, segment + 1,
wire + 1, strip + 1, 2
)
# Legend: x,y,z voxel centers
# the positions are first calculated for the High Resolution
# A rotation of 180 deg around Y axis is applied below
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 * GLxSANS,
2 * GLxSANS,
2 * GLySANS,
2 * GLySANS,
2 * GLzSANS)
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
f.writelines(stringa)