forked from mantidproject/mantidgeometry
/
cncs_geometry.py
executable file
·110 lines (91 loc) · 3.43 KB
/
cncs_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
#!/usr/bin/python
NUM_PIXELS_PER_TUBE = 128
NUM_TUBES_PER_BANK = 8
TUBE_SIZE = 2.0 #meter
TUBE_WIDTH = 0.0254 #meter
AIR_GAP_WIDTH = 0.002032 #meter
PIXELS_PER_BANK = NUM_TUBES_PER_BANK * NUM_PIXELS_PER_TUBE
CONVERT_TO_METERS = 1.0 #x,y,z are in meters
# Detector Parameters
TUBE_PRESSURE = ("tube_pressure", 6.0, "atm")
TUBE_THICKNESS = ("tube_thickness", 0.0008, "metre")
TUBE_TEMPERATURE = ("tube_temperature", 290.0, "K")
def read_file(filename):
fh = open(filename)
lines = fh.readlines()
fh.close()
di = {}
di["name"] = []
di["id"] = []
di["X"] = []
di["Y"] = []
di["Z"] = []
di["RotX"] = []
di["RotY"] = []
di["RotZ"] = []
counter = 0
for line in lines[1:]:
values = line.split()
counter += 1
di["name"].append("bank%d" % counter)
di["id"].append(counter)
di["X"].append(str(float(values[2])/CONVERT_TO_METERS))
di["Y"].append(str(float(values[1])/CONVERT_TO_METERS))
di["Z"].append(str(float(values[0])/CONVERT_TO_METERS))
di["RotX"].append(None)
di["RotY"].append(str(float(values[3])+180.0))
di["RotZ"].append(None)
return di
if __name__ == "__main__":
import sys
from helper import MantidGeom
try:
geom_input_file = sys.argv[1]
except KeyError:
geom_input_file = inst_name+"_geom.txt"
# Set header information
comment = "Created by Michael Reuter"
# Time needs to be in UTC?
valid_from = "2013-08-14 18:30:00"
# Get geometry information file
inst_name = "CNCS"
detinfo = read_file(geom_input_file)
num_dets = len(detinfo.values()[0])
xml_outfile = inst_name+"_Definition.xml"
det = MantidGeom(inst_name, comment=comment, valid_from=valid_from)
det.addSnsDefaults()
det.addComment("SOURCE AND SAMPLE POSITION")
det.addModerator(-36.262)
det.addSamplePosition()
det.addComment("MONITORS")
det.addMonitors(names=["monitor1", "monitor2", "monitor3"],
distance=["-29.949", "-28.706", "-1.416"])
label = "detectors"
det.addComponent(label, label)
doc_handle = det.makeTypeElement(label)
for i in range(num_dets):
det.addComponent(detinfo["name"][i], root=doc_handle)
det.addDetector(detinfo["X"][i], detinfo["Y"][i],
detinfo["Z"][i], detinfo["RotX"][i],
detinfo["RotY"][i], detinfo["RotZ"][i],
detinfo["name"][i], "eightpack")
det.addComment("STANDARD 8-PACK")
det.addNPack("eightpack", NUM_TUBES_PER_BANK, TUBE_WIDTH, AIR_GAP_WIDTH)
det.addComment("STANDARD 2m 128 PIXEL TUBE")
det.addPixelatedTube("tube", NUM_PIXELS_PER_TUBE, TUBE_SIZE)
det.addComment("PIXEL FOR STANDARD 2m 128 PIXEL TUBE")
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("MONITOR SHAPE")
det.addComment("FIXME: Do something real here.")
det.addDummyMonitor(0.01, 0.03)
det.addComment("DETECTOR IDs")
det.addDetectorIds(label, [0, (num_dets * PIXELS_PER_BANK) - 1 , None])
det.addComment("MONITOR IDs")
det.addMonitorIds(["-1", "-2", "-3"])
det.addComment("DETECTOR PARAMETERS")
det.addDetectorParameters(label, TUBE_PRESSURE, TUBE_THICKNESS,
TUBE_TEMPERATURE)
#det.showGeom()
det.writeGeom(xml_outfile)