10 import matplotlib.pyplot
as plt
13 electron_charge = -1.6021766199999996e-19
14 def checkit(field_rf, charge = electron_charge):
19 t0, t1 = field_rf.times[0:2]
21 tf = dt*field_rf.nbins
23 print "dt=%f us, time range: %f (%f us)" % (dt/units.us, tf, tf/units.us)
26 nbins_native = field_rf.nbins
27 nbins_tick =
int(dt*nbins_native / (0.5*units.us))
28 n_downsample = nbins_hirez//nbins_tick
30 print 'nbins:', nbins_tick, nbins_native, nbins_hirez
32 tbin_hirez = tf/nbins_hirez
33 tbin_native = tf/nbins_native
34 tbin_tick = tf/nbins_tick
36 print 'tbins (us):', tbin_tick/units.us, tbin_native/units.us, tbin_hirez/units.us
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)
42 elect_hirez = response.electronics(times_hirez, gain, shaping)
43 elect_tick = response.electronics(times_tick, gain, shaping)
45 field_hirez_rf = field_rf.resample(nbins_hirez)
46 field_tick_rf = field_rf.resample(nbins_tick)
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)
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)
56 charge_tots = map(numpy.sum, [charge_native, charge_hirez, charge_tick])
57 print 'total charge', charge_tots
60 elect_hirez_spec = numpy.fft.fft(elect_hirez)
61 charge_hirez_spec = numpy.fft.fft(charge_hirez)
64 convo_hirez = numpy.fft.ifft(elect_hirez_spec * charge_hirez_spec)
65 convo_downsample = convo_hirez[::n_downsample]
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
78 charge_delta = numpy.zeros_like(elect_hirez)
79 charge_delta[100] = 1.0
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)
86 fig, axes = plt.subplots(3,4)
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')
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')
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')
112 ax.plot(times_hirez/units.us, elect_hirez)
113 ax.set_autoscalex_on(
False)
115 ax.set_title(
'elect respon')
119 ax.semilogy(numpy.absolute(charge_hirez_spec[:nbins_tick]))
120 ax.set_title(
"mag(fft(field))")
123 ax.plot(numpy.angle(charge_hirez_spec[:nbins_tick]))
124 ax.set_title(
"phase(fft(field))")
127 ax.semilogy(numpy.absolute(elect_hirez_spec[:nbins_tick]))
128 ax.set_title(
"mag(fft(elect))")
131 ax.plot(numpy.angle(elect_hirez_spec[:nbins_tick]))
132 ax.set_title(
"phase(fft(elect))")
136 ax.plot(times_hirez/units.us, convo_hirez/1e-6)
137 ax.set_xlim(time_range)
138 ax.set_title(
'convo hirez [uV]')
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]')
155 ax.plot(times_hirez/units.us, charge_delta)
159 ax.plot(times_hirez/units.us, convo_delta)
160 ax.plot(times_hirez/units.us, convo_delta2[:5000])
def checkit(field_rf, charge=electron_charge)