123 Plot each plane of wires on a page of a PDF file. 127 from matplotlib.backends.backend_pdf
import PdfPages
134 all_wire_anode = list()
136 plane_colors=[
"blue",
"red",
"black"]
138 with PdfPages(pdffile)
as pdf:
140 for anode
in store.anodes:
146 for iface
in anode.faces:
147 face = store.faces[iface]
149 for iplane
in face.planes:
150 plane = store.planes[iplane]
151 wires_in_plane = [store.wires[wind]
for wind
in plane.wires]
152 wires = [w
for w
in wires_in_plane
if w.segment == 0]
153 def pt(w):
return store.points[w.head]
154 wires.sort(key=
lambda a: pt(a).z)
158 edge_z.append(p.z/units.m)
159 edge_x.append(p.x/units.m)
160 edge_n.append(w.channel)
161 edge_s.append(
'f%d p%d c%d wid%d' % (face.ident, plane.ident, w.channel, w.ident))
165 fig, ax = plt.subplots(nrows=1, ncols=1)
166 ax.scatter(edge_z, edge_x, s=1, c=
'red', marker=
'.')
167 for i,(z,x,s)
in enumerate(
zip(edge_z, edge_x, edge_s)):
168 hal = [
"left",
"right"][i%2]
169 ax.text(z, x, s, horizontalalignment=hal,
170 bbox=dict(facecolor=
'yellow', alpha=0.5, pad=1))
171 for i
in range(len(edge_n)//2):
172 z = 0.5*(edge_z[2*i]+edge_z[2*i+1])
173 n = 1+
abs(edge_n[2*i] - edge_n[2*i+1])
175 ax.text(z, x,
str(n), horizontalalignment=
'center',
176 bbox=dict(facecolor=
'yellow', alpha=0.5, pad=1))
179 ax.set_title(
"Edge Channels AnodeID: %d" % (anode.ident))
180 ax.set_xlabel(
"Z [meter]")
181 ax.set_ylabel(
"X [meter]")
185 for anode
in store.anodes:
186 seg_x1 = [list(),list(),list()]
187 seg_x2 = [list(),list(),list()]
188 seg_z1 = [list(),list(),list()]
189 seg_z2 = [list(),list(),list()]
190 seg_col = [list(),list(),list()]
191 for iface
in anode.faces:
192 face = store.faces[iface]
193 for iplane
in face.planes:
194 plane = store.planes[iplane]
195 for wind
in plane.wires:
196 wire = store.wires[wind]
197 p1 = store.points[wire.tail]
198 p2 = store.points[wire.head]
200 seg_x1[seg].append(p1.x/units.meter)
201 seg_x2[seg].append(p2.x/units.meter)
202 seg_z1[seg].append(p1.z/units.meter)
203 seg_z2[seg].append(p2.z/units.meter)
204 seg_col[seg].append(plane_colors[iplane%(len(plane_colors))])
209 fig, axes = plt.subplots(nrows=3, ncols=1)
212 ax.scatter(seg_z2[seg], seg_x2[seg], c=seg_col[seg], s=1, marker=
'.')
213 ax.set_title(
"AnodeID %d wires, seg %d, head (%d wires)" %
214 (anode.ident, seg, len(seg_col[seg])))
219 fig, axes = plt.subplots(nrows=3, ncols=1)
222 ax.scatter(seg_z1[seg], seg_x1[seg], c=seg_col[seg], s=1, marker=
'.')
223 ax.set_title(
"AnodeID %d wires, seg %d, tail (%d wires)" %
224 (anode.ident, seg, len(seg_col[seg])))
230 for anode
in store.anodes:
238 for iface
in anode.faces:
239 face = store.faces[iface]
243 for iplane
in face.planes:
244 plane = store.planes[iplane]
246 print (
"anodeID:%d faceID:%d planeID:%d" %
247 (anode.ident, face.ident, plane.ident))
249 first_wires.append(plane.wires[:2])
251 fig, ax = plt.subplots(nrows=1, ncols=1)
252 ax.set_aspect(
'equal',
'box')
253 for wind
in plane.wires[::wire_step]:
254 wire = store.wires[wind]
255 p1 = store.points[wire.tail]
256 p2 = store.points[wire.head]
257 width = wire.segment + .1
258 ax.plot((p1.z/units.meter, p2.z/units.meter),
259 (p1.y/units.meter, p2.y/units.meter), linewidth = width)
260 wire_x1.append(p1.x/units.meter)
261 wire_z1.append(p1.z/units.meter)
262 wire_x2.append(p2.x/units.meter)
263 wire_z2.append(p2.z/units.meter)
264 wire_anode.append(anode.ident)
267 for wcount, wind
in enumerate([plane.wires[0], plane.wires[-1]]):
268 wire = store.wires[wind]
269 print (
"\twcount:%d wind:%d wident:%d chan:%d" % (wcount,wind,wire.ident,wire.channel))
270 p1 = store.points[wire.tail]
271 p2 = store.points[wire.head]
274 wirex = p2.x/units.meter
279 t=
'%s wid:%d ch:%d' %([
"beg",
"end"][wcount], wire.ident, wire.channel)
281 horizontalalignment=hal,
282 bbox=dict(facecolor=
'yellow', alpha=0.5, pad=10))
297 ax.set_xlabel(
"Z [meter]")
298 ax.set_ylabel(
"Y [meter]")
299 ax.set_title(
"AnodeID %d, FaceID %d, PlaneID %d every %dth wire, x=%.3fm" % \
300 (anode.ident, face.ident, plane.ident, wire_step, wirex))
306 fig, axes = plt.subplots(nrows=2, ncols=2)
307 for iplane,winds
in enumerate(first_wires):
308 plane_color =
"red green blue".
split()[iplane]
309 w0 = store.wires[winds[0]]
310 h0 = numpy.asarray(store.points[w0.head])
311 t0 = numpy.asarray(store.points[w0.tail])
312 w1 = store.wires[winds[1]]
313 h1 = numpy.asarray(store.points[w1.head])
314 t1 = numpy.asarray(store.points[w1.tail])
325 w = w/math.sqrt(numpy.sum(w*w))
328 r = r/math.sqrt(numpy.sum(r*r))
331 x = x/math.sqrt(numpy.sum(x*x))
335 axes[0,0].arrow(0,0, pt[2], pt[1], color=plane_color, linewidth=ipt+1)
336 axes[0,1].arrow(0,0, pt[2], pt[0], color=plane_color, linewidth=ipt+1)
337 axes[1,0].arrow(0,0, pt[0], pt[1], color=plane_color, linewidth=ipt+1)
339 for a,t
in zip(axes.flatten(),[
"Z vs Y",
"X vs Y",
"Z vs X",
"none"]):
340 a.set_aspect(
'equal')
341 a.set_title(
"%s anode: %d, face: %d" % (t, anode.ident, face.ident))
353 fig, ax = plt.subplots(nrows=1, ncols=1)
354 ax.scatter(wire_z1, wire_x1,s=1, c=wire_anode, marker=
'.')
355 ax.set_title(
"AnodeID %d wires, tail" % anode.ident)
358 fig, ax = plt.subplots(nrows=1, ncols=1)
359 ax.scatter(wire_z2, wire_x2,s=1, c=wire_anode, marker=
'.')
360 ax.set_title(
"AnodeID %d wires, head" % anode.ident)
363 all_wire_x1 += wire_x1
364 all_wire_z1 += wire_z1
365 all_wire_x2 += wire_x2
366 all_wire_z2 += wire_z2
367 all_wire_anode += wire_anode
370 fig, ax = plt.subplots(nrows=1, ncols=1)
371 ax.scatter(all_wire_z1, all_wire_x1,s=1, c=all_wire_anode,marker=
'.')
372 ax.set_title(
"All wires, tail")
375 fig, ax = plt.subplots(nrows=1, ncols=1)
376 ax.scatter(all_wire_z2, all_wire_x2,s=1, c=all_wire_anode,marker=
'.')
377 ax.set_title(
"All wires, head")
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def allplanes(store, pdffile)
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
void split(std::string const &s, char c, OutIter dest)