regions.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 '''
3 Functions to process descriptions of wire regions
4 '''
5 
6 from wirecell import units
7 from collections import namedtuple, defaultdict
8 
9 Point = namedtuple("Point","x y z")
10 Border = namedtuple("Border","plane wire ch tail head") # a wire
11 Region = namedtuple("Region","beg end") # pair of borders
12 WCLS = namedtuple("WCLS", "wc ls")
13 
14 def wcborder(vals):
15  '''
16  convert array of
17  Plane,Channel,Start X,Start Y,Start Z,End X,End Y,End Z,
18  to Border object
19  '''
20  nums = [int(v) for v in vals[:2]]
21  coords = [round(1000*float(v)*units.cm)/1000.0 for v in vals[2:]]
22 
23  return Border(nums[0], nums[1], nums[1],
24  Point(*coords[0:3]), Point(*coords[3:6]))
25 def lsborder(vals):
26  '''
27  convert array of
28  # Channel,Plane,Wire,Start X,Start Y,Start Z,End X,End Y,End Z,
29  to Border object
30  '''
31  nums = [int(v) for v in vals[:3]]
32  coords = [round(1000*float(v)*units.cm)/1000.0 for v in vals[3:]]
33 
34  return Border(nums[1], nums[2], nums[0],
35  Point(*coords[0:3]), Point(*coords[3:6]))
36 
37 
38 def uboone_shorted(store, filename):
39  '''
40  Load in the CSV file holding description of shorted wires in
41  microboone. Confirm data is consistent with given
42  wires.schema.Store object.
43 
44  Example file is the CSV saved from MicroBooNE_ShortedWireList.xlsx.
45 
46  Return data structure describing the shorted wires.
47  '''
48 
49  #### wirecell numbers:
50  # Plane,Channel,Start X,Start Y,Start Z,End X,End Y,End Z,
51  # Plane,Channel,Start X,Start Y,Start Z,End X,End Y,End Z,
52  #### then larsoft numbers
53  # Channel,Plane,Wire,Start X,Start Y,Start Z,End X,End Y,End Z,
54  # Channel,Plane,Wire,Start X,Start Y,Start Z,End X,End Y,End Z
55 
56 
57  # return a dictionary indexed by shorted plane number and with
58  # values which are lists of triples of (plane,wire1,wire2)
59 
60  ret = defaultdict(list)
61  last_triple = list()
62  shorted_plane = None
63  for lineno, line in enumerate(open(filename).readlines()):
64  line=line.strip()
65 
66  if not line:
67  continue
68  vals = line.split(',')
69  if not vals[0]:
70  continue
71 
72  maybe = vals[0].lower();
73  if "shorted region" in maybe:
74  letter = maybe[maybe.find("shorted region")-2]
75  #print 'Starting plane "%s"' % letter
76  shorted_plane = "uvy".index(letter)
77  continue
78 
79  if vals[0].lower() == "plane":
80  continue # column names
81 
82  plane = int(vals[17])
83 
84  ch1 = int(vals[16])
85  w1 = int(vals[18])
86  ch2 = int(vals[25])
87  w2 = int(vals[27])
88 
89  chw1 = [w.ident for w in store.wires if w.channel == ch1]
90  chw2 = [w.ident for w in store.wires if w.channel == ch2]
91  assert w1 in chw1, "w1 %s %s"%(w1,chw1)
92  assert w2 in chw2, "w2 %s %s"%(w2,chw2)
93  one = dict(plane=plane,ch1=ch1,wire1=w1,ch2=ch2,wire2=w2)
94  if plane == shorted_plane:
95  print "[ {plane:%d, min:%d, max:%d} ]," % (plane,w1,w2)
96  last_triple.append(one)
97 
98  if plane == 2:
99  if last_triple:
100  ret[shorted_plane].append(last_triple)
101  last_triple = list()
102 
103  return ret
104 
105 
106 
107 
int open(const char *, int)
Opens a file descriptor.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
def uboone_shorted(store, filename)
Definition: regions.py:38