Functions | Variables
wirecell.sigproc.downsample Namespace Reference

Functions

def checkit (field_rf, charge=electron_charge)
 

Variables

float electron_charge = -1.6021766199999996e-19
 

Detailed Description

downsampling

Function Documentation

def wirecell.sigproc.downsample.checkit (   field_rf,
  charge = electron_charge 
)

Definition at line 14 of file downsample.py.

14 def checkit(field_rf, charge = electron_charge):
15 
16  gain=14*1e-3/1e-15 # 14e12 Volt/Coulomb
17  shaping=2*units.us
18 
19  t0, t1 = field_rf.times[0:2]
20  dt = t1-t0
21  tf = dt*field_rf.nbins
22 
23  print "dt=%f us, time range: %f (%f us)" % (dt/units.us, tf, tf/units.us)
24 
25  nbins_hirez = 5000
26  nbins_native = field_rf.nbins # 1000
27  nbins_tick = int(dt*nbins_native / (0.5*units.us)) # 200
28  n_downsample = nbins_hirez//nbins_tick # 25
29 
30  print 'nbins:', nbins_tick, nbins_native, nbins_hirez
31 
32  tbin_hirez = tf/nbins_hirez
33  tbin_native = tf/nbins_native
34  tbin_tick = tf/nbins_tick
35 
36  print 'tbins (us):', tbin_tick/units.us, tbin_native/units.us, tbin_hirez/units.us
37 
38  times_hirez = numpy.linspace(t0,tf,nbins_hirez)
39  times_native = numpy.linspace(t0,tf,nbins_native)
40  times_tick = numpy.linspace(t0,tf,nbins_tick)
41 
42  elect_hirez = response.electronics(times_hirez, gain, shaping)
43  elect_tick = response.electronics(times_tick, gain, shaping)
44 
45  field_hirez_rf = field_rf.resample(nbins_hirez)
46  field_tick_rf = field_rf.resample(nbins_tick)
47 
48  charge_native = field_rf.response*(tbin_native/units.s)
49  charge_hirez = field_hirez_rf.response*(tbin_hirez/units.s)
50  charge_tick = field_tick_rf.response*(tbin_tick/units.s)
51 
52  charge_native = charge_native*charge/numpy.sum(charge_native)
53  charge_hirez = charge_hirez*charge/numpy.sum(charge_hirez)
54  charge_tick = charge_tick*charge/numpy.sum(charge_tick)
55 
56  charge_tots = map(numpy.sum, [charge_native, charge_hirez, charge_tick])
57  print 'total charge', charge_tots
58 
59  # upsampled FFT
60  elect_hirez_spec = numpy.fft.fft(elect_hirez)
61  charge_hirez_spec = numpy.fft.fft(charge_hirez)
62 
63  # upsample, fft, mult, ifft, downsample
64  convo_hirez = numpy.fft.ifft(elect_hirez_spec * charge_hirez_spec)
65  convo_downsample = convo_hirez[::n_downsample]
66 
67  # upsample, fft, truncate, mult, ifft
68  nbins_tick_half = nbins_tick//2
69  elect_trunc_spec = numpy.hstack((elect_hirez_spec[:nbins_tick_half], elect_hirez_spec[-nbins_tick_half:]))
70  charge_trunc_spec = numpy.hstack((charge_hirez_spec[:nbins_tick_half], charge_hirez_spec[-nbins_tick_half:]))
71  convo_trunc = numpy.fft.ifft(elect_trunc_spec * charge_trunc_spec)
72  convo_trunc /= n_downsample
73 
74  #convo_numpy = numpy.convolve(elect_hirez, charge_hirez, "same")
75  #convo_scipy = scipy.signal.convolve(elect_hirez, charge_hirez, "same")
76 
77 
78  charge_delta = numpy.zeros_like(elect_hirez)
79  charge_delta[100] = 1.0
80 
81  print len(charge_delta), numpy.sum(numpy.abs(charge_delta))
82  charge_delta_spec = numpy.fft.fft(charge_delta)
83  convo_delta = numpy.fft.ifft(charge_delta_spec * elect_hirez_spec)
84  convo_delta2 = numpy.convolve(charge_delta, elect_hirez)
85 
86  fig, axes = plt.subplots(3,4)
87  time_range = (70,100)
88 
89  ax = axes[0,0]
90  ax.plot(times_native/units.us, field_rf.response)
91  ax.set_autoscalex_on(False)
92  ax.set_xlim(time_range)
93  ax.set_title('field resp')
94  #ax.set_ylabel('Current')
95 
96 
97  ax = axes[0,1]
98  ax.plot(times_native/units.us, charge_native)
99  ax.set_autoscalex_on(False)
100  ax.set_xlim(time_range)
101  ax.set_title('charge/.1us')
102  #ax.set_ylabel('Current')
103 
104  ax = axes[0,2]
105  ax.plot(times_hirez/units.us, charge_hirez)
106  ax.set_autoscalex_on(False)
107  ax.set_xlim(time_range)
108  ax.set_title('charge/.02us')
109  #ax.set_ylabel('Current')
110 
111  ax = axes[0,3]
112  ax.plot(times_hirez/units.us, elect_hirez)
113  ax.set_autoscalex_on(False)
114  ax.set_xlim((0,10))
115  ax.set_title('elect respon')
116  #ax.set_ylabel('mV/fC')
117 
118  ax = axes[1,0]
119  ax.semilogy(numpy.absolute(charge_hirez_spec[:nbins_tick]))
120  ax.set_title("mag(fft(field))")
121 
122  ax = axes[1,1]
123  ax.plot(numpy.angle(charge_hirez_spec[:nbins_tick]))
124  ax.set_title("phase(fft(field))")
125 
126  ax = axes[1,2]
127  ax.semilogy(numpy.absolute(elect_hirez_spec[:nbins_tick]))
128  ax.set_title("mag(fft(elect))")
129 
130  ax = axes[1,3]
131  ax.plot(numpy.angle(elect_hirez_spec[:nbins_tick]))
132  ax.set_title("phase(fft(elect))")
133 
134 
135  ax = axes[2,0]
136  ax.plot(times_hirez/units.us, convo_hirez/1e-6)
137  ax.set_xlim(time_range)
138  ax.set_title('convo hirez [uV]')
139  ax.set_ylabel('')
140 
141  ax = axes[2,1]
142  ax.plot(times_tick/units.us, convo_downsample/1e-6)
143  ax.plot(times_tick/units.us, convo_trunc/1e-6)
144  ax.set_xlim(time_range)
145  ax.set_title('convo ds&trunc [uV]')
146 
147  #ax = axes[2,2]
148  #ax.plot(times_hirez/units.us, convo_numpy)
149  #ax.plot(times_hirez/units.us, convo_scipy)
150  #ax.set_xlim(time_range)
151  #ax.set_title('convo (numpy)')
152 
153 
154  ax = axes[2,2]
155  ax.plot(times_hirez/units.us, charge_delta)
156  ax.set_xlim((0,10))
157 
158  ax = axes[2,3]
159  ax.plot(times_hirez/units.us, convo_delta)
160  ax.plot(times_hirez/units.us, convo_delta2[:5000])
161  ax.set_xlim((0,10))
162 
def checkit(field_rf, charge=electron_charge)
Definition: downsample.py:14

Variable Documentation

float wirecell.sigproc.downsample.electron_charge = -1.6021766199999996e-19

Definition at line 13 of file downsample.py.