Functions
wirecell.sigproc.response.plots Namespace Reference

Functions

def get_plane (fr, planeid, reflect=True)
 
def plot_planes (fr, filename=None)
 

Function Documentation

def wirecell.sigproc.response.plots.get_plane (   fr,
  planeid,
  reflect = True 
)

Definition at line 10 of file plots.py.

10 def get_plane(fr, planeid, reflect=True):
11  pr = fr.planes[planeid]
12 
13  period = fr.period
14 
15  ntbins = pr.paths[0].current.size
16  tmin = fr.tstart
17  tmax = tmin + ntbins*period
18  tdelta = (tmax-tmin)/ntbins
19  print 'TBINS:', ntbins, tmin, tmax, tdelta, period
20 
21  pitches = [path.pitchpos for path in pr.paths]
22  pdelta = pitches[1] - pitches[0]
23  pmax = max(map(abs, pitches)) + 0.5*pdelta # bin centered
24  pmin = -pmax
25  npbins = int(round((pmax-pmin)/pdelta))
26  print 'PBINS:', npbins, pmin, pmax, pdelta, (pmax-pmin)/pdelta
27 
28  tlin = numpy.linspace(tmin, tmax, ntbins+1)
29  plin = numpy.linspace(pmin, pmax, npbins+1)
30 
31  # print 'T:', tlin
32  # print 'P:', plin
33 
34  times, pitches = numpy.meshgrid(tlin, plin)
35  currents = numpy.zeros((npbins, ntbins))
36 
37  for path in pr.paths:
38  pitch = path.pitchpos
39  pind = int(round((pitch - pmin)/pdelta))
40  pind = max(0, pind)
41  pind = min(npbins, pind)
42 
43  pind_ref = int(round((-pitch - pmin)/pdelta))
44  pind_ref = max(0, pind_ref)
45  pind_ref = min(npbins, pind_ref)
46 
47  assert path.current.size == ntbins
48  for tind, cur in enumerate(path.current):
49 
50  time = tmin + tind*tdelta
51  terr = time - times[pind, tind]
52 
53  # sanity check on indexing:
54  center_line = pitches[pind, tind] + 0.5*pdelta
55  perr = pitch - center_line
56  if abs(terr) >= 0.001*tdelta:
57  print 'time:', tind, time, times[pind, tind], terr
58  if abs(perr) >= 0.001*pdelta:
59  print 'pitch:', pind, pitch, pitches[pind, tind], perr
60  assert abs(terr) < 0.001*tdelta
61  assert abs(perr) < 0.001*pdelta
62  if pind >= npbins:
63  print 'pitch:', pind, pitch, pitches[pind, tind], perr
64 
65  currents[pind, tind] = cur
66 
67  if reflect:
68  currents[pind_ref, tind] = cur
69 
70  return (times, pitches, currents)
71 
72 
def get_plane(fr, planeid, reflect=True)
Definition: plots.py:10
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
T abs(T value)
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
def wirecell.sigproc.response.plots.plot_planes (   fr,
  filename = None 
)
Plot field response as time vs impact positions.

>>> import wirecell.sigproc.response.persist as per
>>> fr = per.load("garfield-1d-3planes-21wires-6impacts.json.bz2")
>>> plot_planes(fr)

Definition at line 73 of file plots.py.

73 def plot_planes(fr, filename=None):
74  '''
75  Plot field response as time vs impact positions.
76 
77  >>> import wirecell.sigproc.response.persist as per
78  >>> fr = per.load("garfield-1d-3planes-21wires-6impacts.json.bz2")
79  >>> plot_planes(fr)
80 
81  '''
82 
83  fig, axes = plt.subplots(3, 1, sharex=True, figsize=(8.0, 10.5))
84 
85  fig.subplots_adjust(left=0.05, right=1.0, top=0.95, bottom=0.05)
86 
87  vlims = [0.1, 0.1, 0.1]
88 
89  for planeid in range(3):
90  vlim = vlims[planeid]
91  t, p, c = get_plane(fr, planeid)
92  print t.shape, p.shape, c.shape
93  ax = axes[planeid]
94  ax.axis([65, 90, -20, 20])
95  ax.set_title('Induced Current %s-plane' % 'UVW'[planeid])
96  ax.set_ylabel('Pitch [mm]')
97  ax.set_xlabel('Time [us]')
98  im = ax.pcolormesh(t/units.us, p/units.mm, c/units.picoampere,
99  vmin=-vlim, vmax=vlim,
100  cmap='seismic')
101  fig.colorbar(im, ax=[ax], shrink=0.9, pad=0.05)
102 
103  for iwire in range(10):
104  ax.axhline(-iwire*3*units.mm, linewidth=1, color='black')
105  ax.axhline(+iwire*3*units.mm, linewidth=1, color='black')
106  ax.axhline(-(iwire+0.5)*3*units.mm, linewidth=1, color='gray',
107  linestyle='dashed')
108  ax.axhline(+(iwire+0.5)*3*units.mm, linewidth=1, color='gray',
109  linestyle='dashed')
110 
111  if filename:
112  print ("Saving to %s" % filename)
113  if filename.endswith(".pdf"):
114  print ("warning: saving to PDF takes an awfully long time. Try PNG.")
115 
116  fig.savefig(filename)
117 
def get_plane(fr, planeid, reflect=True)
Definition: plots.py:10
def plot_planes(fr, filename=None)
Definition: plots.py:73