-
Notifications
You must be signed in to change notification settings - Fork 4
/
wand_geometry.py
executable file
·104 lines (87 loc) · 3.64 KB
/
wand_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
#!/usr/bin/python
INST_NAME = "WAND"
NUM_PIXELS_PER_TUBE = 512
NUM_TUBES_PER_BANK = 480
TUBE_SIZE = 0.2 # meter
TUBE_WIDTH = 0.000397 # meter
AIR_GAP_WIDTH = 0.0 # meter
PIXELS_PER_BANK = NUM_TUBES_PER_BANK * NUM_PIXELS_PER_TUBE
CONVERT_TO_METERS = 1000.0 # x,y,z in millimeters
NUM_DETS = 8
RADIUS = 0.728
def convert(value):
return float(value) / CONVERT_TO_METERS
if __name__ == "__main__":
from lxml import etree as le
from helper import MantidGeom
import numpy as np
try:
np.set_printoptions(legacy='1.13')
except TypeError:
pass
# Set header information
comment = "Created by Ross Whitfield"
# Time needs to be in UTC?
valid_from = "2018-04-01 00:00:00"
# Get geometry information file
xml_outfile = INST_NAME+"_Definition.xml"
det = MantidGeom(INST_NAME, comment=comment, valid_from=valid_from)
det.addSnsDefaults(default_view="cylindrical_y")
det.addComment("SOURCE AND SAMPLE POSITION")
det.addModerator(-3.289, "monochromator")
det.addSamplePosition()
doc_handle = None
for i in range(NUM_DETS):
bank = det.addComponent("bank"+str(i+1),
idlist="bank"+str(i+1),
root=doc_handle)
log = le.SubElement(bank, "parameter", **{"name": "y"})
le.SubElement(log, "logfile",
**{"id": "HB2C:Mot:detz.RBV", # detz is in mm
"eq": "rint(value*100)/100000", # Round to 0.01mm and convert to metres
"extract-single-value-as": "mean"})
det_type = "panel"
angle = (i)*15+7.5 # Mantid
angle -= 0.03125*6 # Offset by six pixels
#angle = i*15+7.5 # Flipped
type_element = le.SubElement(det.getRoot(), "type",
name="bank"+str(i+1))
comp_element = le.SubElement(type_element, "component",
type=det_type)
location = le.SubElement(comp_element, "location")
log = le.SubElement(location, "parameter", **{"name": "r-position"})
le.SubElement(log, "value", **{"val": str(RADIUS)})
log = le.SubElement(location, "parameter", **{"name": "t-position"})
le.SubElement(log, "logfile",
**{"id": "HB2C:Mot:s2.RBV",
"eq": str(angle)+"+rint(value*1000)/1000", # Round to 1/1000 of a degree
"extract-single-value-as": "mean"})
log = le.SubElement(location, "parameter", **{"name": "roty"})
le.SubElement(log, "logfile",
**{"id": "HB2C:Mot:s2.RBV",
"eq": str(angle)+"+value",
"extract-single-value-as": "mean"})
det.addComment("DET PACK")
det.addWANDDetector("panel",
NUM_TUBES_PER_BANK,
TUBE_WIDTH,
AIR_GAP_WIDTH,
RADIUS,
type_name="wire")
det.addComment("20CM WIRE 512 PIXELS")
det.addPixelatedTube("wire", NUM_PIXELS_PER_TUBE, TUBE_SIZE)
det.addComment("PIXEL FOR WIRE")
det.addCylinderPixel("pixel", (0.0, 0.0, 0.0), (0.0, 1.0, 0.0),
(TUBE_WIDTH/2.0),
(TUBE_SIZE/NUM_PIXELS_PER_TUBE))
det.addComment("DETECTOR IDs")
offset = 0
for i in range(NUM_DETS):
id_list = []
id_list.append(i * PIXELS_PER_BANK)
id_list.append((i+1) * PIXELS_PER_BANK - 1)
id_list.append(None)
det.addDetectorIds('bank'+str(NUM_DETS-i), id_list)
det.addComment("MONITOR IDs")
det.addMonitorIds(["-1"])
det.writeGeom(xml_outfile)