-
Notifications
You must be signed in to change notification settings - Fork 4
/
biosans_geometry.py
executable file
·154 lines (150 loc) · 7.7 KB
/
biosans_geometry.py
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
#!/usr/bin/python3
# local imports
from helper import MantidGeom
from SNS.SANS.utilities import (kw, ag, make_filename, add_basic_types, add_double_flat_panel_type,
add_double_flat_panel_component, add_double_curved_panel_type,
add_double_curved_panel_component, add_double_panel_idlist, add_comment_section,
insert_location_from_logs,insert_side_by_side_view)
# third party imports
# standard imports
from copy import deepcopy
import math
"""
Instrument requirements from meeting at HFIR on May 07, 2019
- One component for the front panel and one component for the back panel
- divide each bank into fourpacks
- Pixel ID's start at tube1 of bank1 and finish at last tube of the last bank
"""
"""
Explanation of some entries in iinfo dictionary
tube_separation distance between consecutive tube axis
fourpack_separation distance between front and back fourpacks
fourpack_slip slip vector between the two fourpacks along X-axis
number_eightpacks number of eight-packs in the detector array
side_view_xy X and Y coordinates for the rendering of the side-by-side view of the detector
"""
iinfo = dict(valid_from='2023-10-01 00:00:00',
valid_to='2100-12-31 23:59:59',
comment='Created by Jose Borregero, borreguerojm@ornl.gov',
instrument_name='BIOSANS',
source_sample_distance=1.0,
monitors=(dict(name='monitor1', z=-10.5),
dict(name='timer', z=-10.5)),
flat_array='detector1', # name of the detector array
flat_panel_types=dict(front='front-panel', back='back-panel'),
bank_name='bank',
tube_length=1.046,
tube_diameter=0.00805,
pixels_per_tube=256,
tube_separation=0.0112522,
fourpack_separation=0.008205216,
fourpack_slip=0.0055103014,
number_eightpacks=24,
side_view_xy=(0.0, 0.0))
# Instrument handle
det = MantidGeom(iinfo['instrument_name'], **kw(iinfo, 'comment', 'valid_from', 'valid_to'))
det.addSnsDefaults(default_view="3D", axis_view_3d="Z-")
fn = make_filename(*ag(iinfo, 'instrument_name', 'valid_from', 'valid_to'))
add_basic_types(det, iinfo) # source, sample, pixel, tube, and fourpack
#
# Monitor Section
#
add_comment_section(det, 'COMPONENT, TYPE, and IDLIST: MONITORS')
det.addMonitors(distance=[m['z'] for m in iinfo['monitors']],
names=[m['name'] for m in iinfo['monitors']])
det.addMonitorIds(ids=[-1, -2])
det.addDummyMonitor(0.01, 0.1)
#
# Insert the flat panel
#
double_panel = add_double_flat_panel_type(det, iinfo)
pixel_idlist = 'flat_panel_ids'
double_panel = add_double_flat_panel_component(double_panel, 'flat_panel_ids', det, iinfo['flat_array'])
insert_location_from_logs(double_panel, log_key=['detector_trans_Readback', 'sample_detector_distance'],
coord_name=['x', 'z'], equation=['-0.001*value', 'value'])
insert_side_by_side_view(double_panel, *iinfo['side_view_xy'])
add_double_panel_idlist(det, iinfo, pixel_idlist)
last_pixel_id = 8 * iinfo['number_eightpacks'] * iinfo['pixels_per_tube'] - 1
last_bank_number = 2 * iinfo['number_eightpacks']
#
# Insert the curved panel for the wing detector
#
"""
Explanation of some entries in the below jinfo dictionary
bank_radius distance between focal-point and anchor point
anchor_offset add this to bank_radius for distance between focal-point
and eightpack midline
eightpack_angle effective angle subtended by each eightpack, in degrees
side_view_xy X and Y coordinates for the rendering of the side-by-side view of the detector
"""
jinfo = dict(curved_array='wing_detector', # name of the wing detector
curved_panel_types=dict(front='front-wing-panel',
back='back-wing-panel',
double='double-wing-panel'),
number_eightpacks=20,
bank_radius=1.129538,
anchor_offset=0.0,
eightpack_angle=2.232094,
panel_translation_log_key='detectorZ',
side_view_xy=(0.96, 0.0))
panel_info = deepcopy(iinfo)
panel_info.update(jinfo)
r_eightpack = panel_info['bank_radius'] + panel_info['anchor_offset']
comment = f'Panel is positioned {r_eightpack} meters downstream'
kwargs = dict(comment=comment, to_origin=False, first_bank_number=1 + last_bank_number)
double_panel = add_double_curved_panel_type(det, panel_info, **kwargs)
pixel_idlist = 'curved_panel_ids'
double_panel = add_double_curved_panel_component(double_panel, pixel_idlist, det, panel_info['curved_array'])
# Rotate the double panel away from the path of the Z-axis
rot_y = - panel_info['eightpack_angle'] * panel_info['number_eightpacks'] / 2
rot_y += 0.5 * panel_info['fourpack_slip'] / panel_info['bank_radius'] * 180. / math.pi
det.addLocation(double_panel, 0., 0., 0, rot_y=f'{rot_y:.2f}')
insert_location_from_logs(double_panel, log_key=['ww_rot_Readback', 'ww_rot_Readback'],
coord_name=['t-position', 'roty'], equation=[f'{rot_y:.2f}-value', f'{rot_y:.2f}-value'])
insert_side_by_side_view(double_panel, *panel_info['side_view_xy'])
add_double_panel_idlist(det, panel_info, pixel_idlist, start=1 + last_pixel_id)
last_pixel_id += 8 * panel_info['number_eightpacks'] * panel_info['pixels_per_tube']
last_bank_number += 2 * panel_info['number_eightpacks']
#
# Insert the curved panel for the midrange detector
#
"""
Explanation of some entries in the below kinfo dictionary
bank_radius distance between focal-point and anchor point
anchor_offset add this to bank_radius for distance between focal-point
and eightpack midline
eightpack_angle effective angle subtended by each eightpack, in degrees
side_view_xy X and Y coordinates for the rendering of the side-by-side view of the detector
"""
kinfo = dict(curved_array='midrange_detector', # name of the midrange detector
curved_panel_types=dict(front='front-midrange-panel',
back='back-midrange-panel',
double='double-midrange-panel'),
number_eightpacks=8,
bank_radius=3.9662, # shift so that the arc between the front and back panels is 4m away
anchor_offset=0.0,
eightpack_angle=0.629663,
panel_translation_log_key='md_rot_Readback',
side_view_xy=(-0.71, 0.0))
panel_info = deepcopy(iinfo)
panel_info.update(kinfo)
r_eightpack = panel_info['bank_radius'] + panel_info['anchor_offset']
comment = f'Panel is positioned {r_eightpack} meters downstream'
kwargs = dict(comment=comment, to_origin=False, first_bank_number=1 + last_bank_number)
double_panel = add_double_curved_panel_type(det, panel_info, **kwargs)
pixel_idlist = 'midrange_panel_ids'
double_panel = add_double_curved_panel_component(double_panel, pixel_idlist, det, panel_info['curved_array'])
# Rotate the double panel away from the path of the Z-axis to the nominal angle
rot_y = panel_info['eightpack_angle'] * panel_info['number_eightpacks'] / 2
rot_y += - 0.5 * panel_info['fourpack_slip'] / panel_info['bank_radius'] * 180. / math.pi
det.addLocation(double_panel, 0., 0., 0, rot_y=f'{rot_y:.2f}')
insert_location_from_logs(double_panel,
log_key=[panel_info['panel_translation_log_key'], panel_info['panel_translation_log_key']],
coord_name=['t-position', 'roty'],
equation=[f'{rot_y:.2f}+value', f'{rot_y:.2f}+value'])
insert_side_by_side_view(double_panel, *panel_info['side_view_xy'])
add_double_panel_idlist(det, panel_info, pixel_idlist, start=1 + last_pixel_id)
#
# Write to file
#
det.writeGeom(fn)