Belle II Software  release-08-01-10
createThicknessDensity.py
1 #!/usr/bin/env python3
2 
3 
10 import xml.dom
11 import numpy as np
12 
13 """
14 Creating the xml file for tickness and density of each cell volume
15 for the service matirial.
16 
17 Two kinds of material can be selected:
18 
19 1. Defalut value:
20  The thickness and density calculated from the photo of actual
21  cable arrangement and density of each cable.
22 
23 2. vacuum:
24  No service matirial in the gap.
25 """
26 
27 dom1 = xml.dom.getDOMImplementation()
28 doc = dom1.createDocument(None, "TicknessDensity", None)
29 top_element = doc.documentElement
30 
31 # Select which kind of material you want to input. Defalut value: 1, vacuum: 0
32 DefalutValue = 0
33 
34 if DefalutValue == 0:
35  # Input the thickness of the matirial in the backward gap between CDC and ECL, unit is 'mm'
36  thickness_CDCback = (np.ones((16, 144)) * 1.0e-5).ravel()
37 
38  # Input the thickness of the matirial in the forward gap between CDC and ARICH
39  thickness_CDCfor = (np.ones((16, 144)) * 1.0e-5).ravel()
40 
41  # Input the thickness of the matirial in the forward gap between ARICH and TOP
42  thickness_ARICH = (np.ones((3, 144)) * 1.0e-5).ravel()
43 
44  # Input the thickness of the matirial in the backward gap between TOP and ECL
45  thickness_TOPback = (np.ones(144) * 1.0e-5).ravel()
46 
47  # Input the thickness of the matirial in the forward gap between TOP and ECL
48  thickness_TOPfor = (np.ones(144) * 1.0e-5).ravel()
49 
50  # Input the thickness of the matirial in the barrel gap between ECL and COIL
51  thickness_ECLCOIL = (np.ones((92, 144)) * 1.0e-5).ravel()
52 
53  # Input the thickness of the matirial in the backward gap between barrel and endcap of ECL
54  thickness_ECLback = (np.ones((3, 5, 144)) * 1.0e-5).ravel()
55 
56  # Input the thickness of the matirial in the forward gap between barrel and endcap of ECL
57  thickness_ECLfor = (np.ones((3, 5, 144)) * 1.0e-5).ravel()
58 
59 else:
60  # Input the thickness of the matirial in the backward gap between CDC and ECL
61  thickness_CDCback = (np.loadtxt(open("thickness_CDCback.csv", "rb"), delimiter=",")).ravel()
62  thickness_CDCback[thickness_CDCback < 1.0e-5] = 1.0e-5
63 
64  # You can change the thickness of backward cell(i,j) by:
65  # thickness_CDCback[i,j] = thickness
66 
67  # Input the thickness of the matirial in the forward gap between CDC and ARICH
68  thickness_CDCfor = (np.loadtxt(open("thickness_CDCfor.csv", "rb"), delimiter=",")).ravel()
69  thickness_CDCfor[thickness_CDCfor < 1.0e-5] = 1.0e-5
70 
71  # Input the thickness of the matirial in the forward gap between ARICH and TOP
72  thickness_ARICH = (np.loadtxt(open("thickness_ARICH.csv", "rb"), delimiter=",")).ravel()
73  thickness_ARICH[thickness_ARICH < 1.0e-5] = 1.0e-5
74 
75  # Input the thickness of the matirial in the backward gap between TOP and ECL
76  thickness_TOPback = (np.loadtxt(open("thickness_TOP_back.csv", "rb"), delimiter=",")).ravel()
77  thickness_TOPback[thickness_TOPback < 1.0e-5] = 1.0e-5
78 
79  # Input the thickness of the matirial in the forward gap between TOP and ECL
80  thickness_TOPfor = (np.loadtxt(open("thickness_TOP_for.csv", "rb"), delimiter=",")).ravel()
81  thickness_TOPfor[thickness_TOPfor < 1.0e-5] = 1.0e-5
82 
83  # Input the thickness of the matirial in the barrel gap between ECL and Coil
84  thickness_ECLCOIL = (np.loadtxt(open("thickness_ECLCOIL.csv", "rb"), delimiter=",")).ravel()
85  thickness_ECLCOIL[thickness_ECLCOIL < 1.0e-5] = 1.0e-5
86 
87  # Input the thickness of the matirial in the backward gap between barrel and endcap of ECL
88  thickness_ECLback = (np.loadtxt(open("thickness_ECLback.csv", "rb"), delimiter=",")).ravel()
89  thickness_ECLback[thickness_ECLback < 1.0e-5] = 1.0e-5
90 
91  # Input the thickness of the matirial in the forward gap between barrel and endcap of ECL
92  thickness_ECLfor = (np.loadtxt(open("thickness_ECLfor.csv", "rb"), delimiter=",")).ravel()
93  thickness_ECLfor[thickness_ECLfor < 1.0e-5] = 1.0e-5
94 
95 thickness_list = list(map(str, thickness_CDCback.tolist() +
96  thickness_CDCfor.tolist() +
97  thickness_ARICH.tolist() +
98  thickness_TOPback.tolist() +
99  thickness_TOPfor.tolist() +
100  thickness_ECLCOIL.tolist() +
101  thickness_ECLback.tolist() +
102  thickness_ECLfor.tolist()))
103 
104 
105 # Density of the servece material in each gap. Unity is 'g/cm3'
106 if DefalutValue == 0:
107  density_ARICH = (np.ones(3) * 1.29e-10).ravel()
108  density_TOPback = (np.ones(1) * 1.29e-10).ravel()
109  density_TOPfor = (np.ones(1) * 1.29e-10).ravel()
110  density_ECLCOIL = (np.ones(1) * 1.29e-10).ravel()
111  density_ECLback = (np.ones(5) * 1.29e-10).ravel()
112  density_ECLfor = (np.ones(5) * 1.29e-10).ravel()
113 else:
114  density_ARICH = (np.ones(3) * 8.96).ravel()
115  density_TOPback = (np.ones(1) * 8.96).ravel()
116  density_TOPfor = (np.ones(1) * 8.96).ravel()
117  density_ECLCOIL = (np.ones(1) * 8.96).ravel()
118  density_ECLback = (np.ones(5) * 8.96).ravel()
119  density_ECLfor = (np.ones(5) * 8.96).ravel()
120 
121 
122 density_list = list(map(str, density_ARICH.tolist() + density_TOPback.tolist() +
123  density_TOPfor.tolist() + density_ECLCOIL.tolist() +
124  density_ECLback.tolist() + density_ECLfor.tolist()))
125 
126 desc = {
127  'IRCDCBack': u'segmentation in R of backward',
128  'IPhiCDCBack': u'segmentation in Phi of backward',
129  'IRCDCFor': u'segmentation in R of forward',
130  'IPhiCDCFor': u'segmentation in Phi of forward',
131  'thicknesses': u'thicknesses',
132  'IZARICHFor': u'segmentation in Z of forward',
133  'IPhiARICHFor': u'segmentation in Phi of forward',
134  'IPhiTOPBack': u'segmentation in Phi of backward',
135  'IPhiTOPFor': u'segmentation in Phi of forward',
136  'IZECLCOILBar': u'segmentation in Z of barrel',
137  'IPhiECLCOILBar': u'segmentation in Phi of barrel',
138  'IRECLBack': u'segmentation in R of backward',
139  'IZECLBack': u'segmentation in Z of backward',
140  'IPhiECLBack': u'segmentation in Phi of backward',
141  'IRECLFor': u'segmentation in R of forward',
142  'IZECLFor': u'segmentation in Z of forward',
143  'IPhiECLFor': u'segmentation in Phi of forward'}
144 
145 # The segmentation in R, Z and Phi. And thickness.
146 value = {
147  'IRCDCBack': 16,
148  'IPhiCDCBack': 144,
149  'IRCDCFor': 16,
150  'IPhiCDCFor': 144,
151  'thicknesses': thickness_list,
152  'IZARICHFor': 3,
153  'IPhiARICHFor': 144,
154  'IPhiTOPBack': 144,
155  'IPhiTOPFor': 144,
156  'IZECLCOILBar': 92,
157  'IPhiECLCOILBar': 144,
158  'IRECLBack': 3,
159  'IZECLBack': 5,
160  'IPhiECLBack': 144,
161  'IRECLFor': 3,
162  'IZECLFor': 5,
163  'IPhiECLFor': 144}
164 
165 elements = [
166  'IRCDCBack',
167  'IPhiCDCBack',
168  'IRCDCFor',
169  'IPhiCDCFor',
170  'thicknesses',
171  'IZARICHFor',
172  'IPhiARICHFor',
173  'IPhiTOPBack',
174  'IPhiTOPFor',
175  'IZECLCOILBar',
176  'IPhiECLCOILBar',
177  'IRECLBack',
178  'IZECLBack',
179  'IPhiECLBack',
180  'IRECLFor',
181  'IZECLFor',
182  'IPhiECLFor']
183 
184 unit = {'thicknesses': 'mm'}
185 
186 for element in elements:
187  sNode = doc.createElement(element)
188  sNode.setAttribute('desc', desc[element])
189  if element in unit.keys():
190  sNode.setAttribute('unit', unit[element])
191  if isinstance(value[element], list):
192  textNode = doc.createTextNode(" ".join(value[element]))
193  else:
194  textNode = doc.createTextNode(str(value[element]))
195  sNode.appendChild(textNode)
196  top_element.appendChild(sNode)
197 
198 xmlfile = open('GAPS-thickness-density.xml', 'w')
199 doc.writexml(xmlfile, addindent=' ' * 4, newl='\n', encoding='utf-8')
200 xmlfile.close()