noise.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 '''
3 
4 $ PYTHONPATH=`pwd`/sigproc/python python sigproc/python/wirecell/sigproc/paper/noise.py
5 
6 '''
7 
8 from wirecell import units
9 from .. import garfield, response, plots
10 import numpy
11 
12 garfield_tarball = "/home/bviren/projects/wire-cell/garfield-data/ub_10.tar.gz"
13 garfield_tarball = "/opt/bviren/wct-dev/data/ub_10.tar.gz"
14 
15 def filter_response_functions(dat, regions=None):
16  if regions is None:
17  return dat
18  return [d for d in dat if abs(d.region) in regions]
19 
20 
21 def figure_adc(dat, regions=None, outname='paper-noise-figure-adc-%dwires'):
22  dat = filter_response_functions(dat, regions)
23  nwires = 10
24  if regions is not None:
25  nwires = max(regions)
26 
27  norm = 16000*units.eplus # was 13700
28  uvw = response.line(dat, norm)
29 
30  gain = 1.2 # was 1.1 for a while
31  adc_bin_range = 4096.0
32  adc_volt_range = 2000.0
33  adc_per_mv = gain*adc_bin_range/adc_volt_range
34 
35  fig,data = plots.plot_digitized_line(uvw, 14.0, 2.0*units.us,
36  adc_per_mv = adc_per_mv)
37 
38  if "%d" in outname:
39  outname = outname % nwires
40  fig.savefig(outname + ".pdf")
41 
42  with open(outname + ".txt", 'w') as fp:
43  for t,u,v,w in data:
44  fp.write('%f %e %e %e\n' % (t,u,v,w))
45 
46  return outname
47 
48 
49 if '__main__' == __name__:
50  import sys
51 
52  try:
53  gt = sys.argv[1]
54  except IndexError:
55  gt = garfield_tarball
56 
57  try:
58  outname = sys.argv[2]
59  except IndexError:
60  outname = None
61 
62  nwires = 10
63  print ("Using %d wires of Garfield data: %s" % (nwires, gt))
64  dat = garfield.load(gt)
65 
66  if "%d" in outname:
67  for nwires in range(1, nwires + 2):
68  fname = figure_adc(dat, regions = range(nwires), outname=outname)
69  print ("\t%s" % fname)
70  else:
71  fname = figure_adc(dat, outname=outname)
72  print ("\t%s" % fname)
73 
74 
75 
int open(const char *, int)
Opens a file descriptor.
def filter_response_functions(dat, regions=None)
Definition: noise.py:15
T abs(T value)
static int max(int a, int b)
def figure_adc(dat, regions=None, outname='paper-noise-figure-adc-%dwires')
Definition: noise.py:21