17 @class TBasePadShapeClass
18 @brief Generate pad information
23 @brief initialze object
24 @param mapping label of axsis (0:x, 1:y, 2:z)
25 @param center center position in pad
26 @param polygon list of vertices
29 self.mapping = {
'x': 0,
'y': 1,
'z': 2}
30 self.center = [0, 0, 0]
33 def set_center(self, x, y, z):
35 @brief set center position
38 self.center = [x, y, z]
40 def add_polygon(self, position):
42 @brief add vertex positio to list(self.polygon)
45 self.polygon.append(position)
49 @brief return center position
54 def get_polygon(self):
56 @brief return vertices list
61 def get_center_polygon_distance(self):
63 @brief caculate and return center position from vertices list
64 @return three component list ([x, y, z])
68 for i
in range(len(self.polygon)):
69 dx = self.center[0] - self.polygon[i][0]
70 dy = self.center[1] - self.polygon[i][1]
71 dz = self.center[2] - self.polygon[i][2]
72 distances.append( np.sqrt(dx**2 + dy**2 + dz**2) )
76 def get_polygon_vertex_distance(self):
78 @brief caculate and return distance between each vertices
79 @return distance list ([01, 12, 23, ...])
82 for i
in range(len(self.polygon)):
83 for j
in range(i+1, len(self.polygon)):
84 dx = self.polygon[i][0] - self.polygon[j][0]
85 dy = self.polygon[i][1] - self.polygon[j][1]
86 dz = self.polygon[i][2] - self.polygon[j][2]
87 distances.append( np.sqrt(dx**2 + dy**2 + dz**2) )
90 def show_polygon(self, plane='xz'):
93 @param plane Select projection plane by str (e.g. 'xz')
96 index1 = self.mapping.get(plane[0], 0)
97 index2 = self.mapping.get(plane[1], 0)
99 xs = [vertex[index1]
for vertex
in self.polygon ]
100 ys = [vertex[index2]
for vertex
in self.polygon ]
102 fig=plt.figure(figsize=(6, 5))
103 ax = fig.add_subplot(111)
104 fig.patch.set_alpha(0.)
105 ax.fill(xs, ys, edgecolor=
'black', facecolor=
'#d3d3d3')
106 ax.set_aspect(
'equal')
108 plt.xlabel(str(plane[0])+
"position [mm]")
109 plt.ylabel(str(plane[1])+
"position [mm]")
114 @class TReadoutPadArray
115 @brief pad information array
120 @brief initialze object
121 @param mapping label of axsis (0:x, 1:y, 2:z)
122 @param basepadlist list of base pad information
123 @param pads list of vertices
124 @param ids list of id
125 @param centers list of center
126 @param charges list of charge
129 self.mapping = {
'x': 0,
'y': 1,
'z': 2}
130 self.basepadlist = []
136 def rotate_x(self, position, degree):
138 @brief rotate position with x axis
139 @param position origninal position
140 @degree rotation angle [deg]
141 @return converted position [x, y, z]
143 theta = 0.0174533*degree
145 y = position[1] * np.cos(theta) - position[2] * np.sin(theta)
146 z = position[1] * np.sin(theta) + position[2] * np.cos(theta)
149 def rotate_y(self, position, degree):
151 @brief rotate position with y axis
152 @param position origninal position
153 @degree rotation angle [deg]
154 @return converted position [x, y, z]
156 theta = 0.0174533*degree
157 x = position[0] * np.cos(theta) + position[2] * np.sin(theta)
159 z = -position[0] * np.sin(theta) + position[2] * np.cos(theta)
162 def rotate_z(self, position, degree):
164 @brief rotate position with z axis
165 @param position origninal position
166 @degree rotation angle [deg]
167 @return converted position [x, y, z]
169 theta = 0.0174533*degree
170 x = position[0] * np.cos(theta) - position[1] * np.sin(theta)
171 y = position[0] * np.sin(theta) + position[1] * np.cos(theta)
175 def add_basepad(self,baseinfo):
177 @brief add pad info (TBasePadShapeClass)
178 @param baseinfo objerct of TBasePadShapeClass
181 self.basepadlist.append(baseinfo)
183 def add_pads(self, center, baseid, degX=0, degY=0, degZ=0, id=0):
185 @brief set pad with position and id
186 @param center center new center postion for adding pad
187 @param center baseid id of base pad object
188 @param center degX rotation angle by X
189 @param center degY rotation angle by Y
190 @param center degZ rotation angle by Z
191 @param center label od each id
194 padshape = self.basepadlist[baseid]
195 polygon_origin = padshape.get_polygon()
199 for i
in range(len(polygon_origin)):
201 polygon_rot = self.rotate_x(polygon_origin[i], degX)
202 polygon_rot = self.rotate_y(polygon_rot, degY)
203 polygon_rot = self.rotate_z(polygon_rot, degZ)
205 for j
in range(len(polygon_rot)):
206 polygon_rot[j] = polygon_rot[j] + center[j]
208 polygon_new.append(polygon_rot)
210 self.pads.append(polygon_new)
212 self.centers.append(np.mean(polygon_new, axis=0))
213 self.charges.append(0)
215 def show_pads(self, plane='xz'):
217 # @brief plot polygon
218 # @param plane Select projection plane by str (e.g. 'xz')
221 index1 = self.mapping.get(plane[0], 0)
222 index2 = self.mapping.get(plane[1], 0)
224 fig=plt.figure(figsize=(6, 5))
225 ax = fig.add_subplot(111)
226 fig.patch.set_alpha(0.)
228 for i
in range(len(self.pads)):
229 xs = [vertex[index1]
for vertex
in self.pads[i] ]
230 ys = [vertex[index2]
for vertex
in self.pads[i] ]
231 ax.fill(xs, ys, edgecolor=
'black', facecolor=
'#d3d3d3',lw=0.5)
233 ax.set_aspect(
'equal')
235 plt.xlabel(str(plane[0])+
" position [mm]")
236 plt.ylabel(str(plane[1])+
" position [mm]")
241 @brief generate regular n polygon
242 @param n number of vertex
243 @param length length of daistance between each vertex
244 @param theta rotation angle
245 @param flag plot pad (default:True)
246 @return object of TBasePadShapeClass
251 print(
"n must be greater than 2")
253 radius = length / (2 * np.sin(np.pi / n))
254 angles = np.linspace(0, 2 * np.pi, n, endpoint=
False)
255 vertices = [(radius * np.cos(angle), radius * np.sin(angle))
for angle
in angles]
257 theta = np.radians(theta)
258 rotation_matrix = np.array([[np.cos(theta), -np.sin(theta)],[np.sin(theta), np.cos(theta)]])
259 rotated_vertices = [np.dot(rotation_matrix, vertex)
for vertex
in vertices]
261 for i
in range(len(vertices)):
262 base_padinfo.add_polygon([rotated_vertices[i][0], 0, rotated_vertices[i][1]])
265 base_padinfo.show_polygon(
'xz')
270 @brief oblong 4 polygon
271 @param longlength length of long side
272 @param shortlength length of short side
273 @param plane projection plane
274 @param flag plot pad (default:True)
275 @return object of TBasePadShapeClass
279 if plane==
'yz' or plane==
'zy':
280 base_padinfo.add_polygon([0, shortlength/2, longlength/2])
281 base_padinfo.add_polygon([0, shortlength/2, -longlength/2])
282 base_padinfo.add_polygon([0, -shortlength/2, -longlength/2])
283 base_padinfo.add_polygon([0, -shortlength/2, longlength/2])
285 elif plane==
'xy' or plane==
'xy':
286 base_padinfo.add_polygon([ longlength/2, shortlength/2, 0])
287 base_padinfo.add_polygon([ longlength/2, -shortlength/2, 0])
288 base_padinfo.add_polygon([-longlength/2, -shortlength/2, 0])
289 base_padinfo.add_polygon([-longlength/2, shortlength/2, 0])
291 elif plane==
'xz' or plane==
'xz':
292 base_padinfo.add_polygon([ longlength/2, 0, shortlength/2])
293 base_padinfo.add_polygon([ longlength/2, 0, -shortlength/2])
294 base_padinfo.add_polygon([-longlength/2, 0, -shortlength/2])
295 base_padinfo.add_polygon([-longlength/2, 0, shortlength/2])
298 base_padinfo.show_polygon(plane)