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