3 Functions to provide information about wires 5 from wirecell
import units
10 return dict(x=p.x, y=p.y, z=p.z)
14 Convert the store to a dict-based representation. This will 15 inflate any duplicate references 18 for anode
in store.anodes:
19 d_anode = dict(ident = anode.ident, faces = list())
20 for iface
in anode.faces:
21 face = store.faces[iface]
22 d_face = dict(ident = face.ident, planes = list())
23 for iplane
in face.planes:
24 plane = store.planes[iplane]
25 d_plane = dict(ident = plane.ident, wires = list())
29 for wind
in plane.wires:
30 wire = store.wires[wind]
31 d_wire = dict(ident = wire.ident,
32 channel = wire.channel,
33 segment = wire.segment,
34 head =
p2p(store.points[wire.head]),
35 tail =
p2p(store.points[wire.tail]))
36 d_plane[
"wires"].append(d_wire)
37 d_face[
"planes"].append(d_plane)
38 d_anode[
"faces"].append(d_face)
39 d_anodes.append(d_anode)
42 return [dict(ident=0, anodes=d_anodes)]
56 for c,v
in self.minp.items():
60 for c,v
in self.maxp.items():
65 return {c:0.5*(self.
minp[c]+self.
maxp[c])
for c
in "xyz"}
69 self.
head = numpy.asarray([wire[
'head'][c]
for c
in "xyz"])
70 self.
tail = numpy.asarray([wire[
'tail'][c]
for c
in "xyz"])
81 Return [mean,rms] of pitch 83 eks = numpy.asarray([1.0,0.0,0.0])
84 zero = numpy.asarray([0.0, 0.0, 0.0])
87 pdir = numpy.cross(eks, r0.ray)
88 pdir = pdir/numpy.linalg.norm(pdir)
95 p = numpy.dot(pdir, r.center)
98 rays = [pr[1]
for pr
in prays]
100 for r1,r2
in zip(rays[:-1], rays[1:]):
101 p = numpy.dot(pdir,r2.center - r1.center)
112 pvar = (pmean*pmean - psum2/n)/(n-1)
113 return pmean, math.sqrt(
abs(pvar)), pmin, pmax
116 pmm = tuple([pp/units.mm
for pp
in p])
117 return "(%.3f +/- %.3f [%.3f<%.3f]) " % pmm
121 Return a summary data structure about the wire store. 125 for anode
in det[
'anodes']:
126 for face
in anode[
'faces']:
129 for plane
in face[
'planes']:
131 for wire
in plane[
'wires']:
142 lines.append(
"anode:%d face:%d X=[%.2f,%.2f]mm Y=[%.2f,%.2f]mm Z=[%.2f,%.2f]mm" % \
143 (anode[
'ident'], face[
'ident'],
144 bb.minp[
'x']/units.mm, bb.maxp[
'x']/units.mm,
145 bb.minp[
'y']/units.mm, bb.maxp[
'y']/units.mm,
146 bb.minp[
'z']/units.mm, bb.maxp[
'z']/units.mm))
147 for pind, plane
in enumerate(face[
'planes']):
148 lines.append(
'\t%d: x=%.2fmm dx=%.4fmm n=%d pitch=%s' % \
150 plane[
'wires'][0][
'head'][
'x']/units.mm,
151 (plane[
'wires'][0][
'head'][
'x']-face[
'planes'][2][
'wires'][0][
'head'][
'x'])/units.mm,
152 len(plane[
'wires']), pitches[pind]))
156 danode=0.0, dresponse=10*units.cm, dcathode=1*units.m, volpat=
None):
158 Return a Jsonnet string suitable for copying to set 159 params.det.volumes found in the pgrapher configuration. 161 The "namepat" should be a string with format markers "{variable}" 162 and will be formated with "detector", "anode" set to their 165 The "d" arguments give the distance measured from the collection 166 plane to each of these logical planes. 170 volpat = volpat
or ''' 175 facepat =
"anode:{anodex}*wc.cm, cathode:{cathodex}*wc.cm, response:{responsex}*wc.cm" 178 for anode
in det[
'anodes']:
179 faces = anode[
'faces']
180 assert (len(faces) <= 2)
181 facetexts = [
"null",
"null"]
184 for plane
in face[
'planes']:
186 for wire
in plane[
'wires']:
191 uvw_x = [bb.minp[
'x']
for bb
in face_bbs]
194 if uvw_x[0] < uvw_x[2]:
199 facetexts[find] =
"\n {" + facepat.format(
200 anodex = (xorigin + sign*danode)/units.cm,
201 responsex = (xorigin + sign*dresponse)/units.cm,
202 cathodex = (xorigin + sign*dcathode)/units.cm) +
"}" 205 facetext =
','.join(facetexts)
206 voltext =
" {" + volpat.format(anode=anode[
"ident"], faces=facetext) +
" }" 207 voltexts.append(voltext)
211 argstext =
" local volumeargs = { danode:%f*wc.cm, dresponse:%f*wc.cm, dcathode:%f*wc.cm },\n" \
212 % (danode/units.cm, dresponse/units.cm, dcathode/units.cm)
213 volumetext =
" volumes: [\n" +
',\n'.join(voltexts) +
"\n ],\n";
214 return argstext+volumetext;
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def pitch_mean_rms(wires)
def jsonnet_volumes(store, danode=0.0, dresponse=10 *units.cm, dcathode=1 *units.m, volpat=None)
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.