Index: fact/tools/pyscripts/tools/spike_ana.py
===================================================================
--- fact/tools/pyscripts/tools/spike_ana.py	(revision 13020)
+++ fact/tools/pyscripts/tools/spike_ana.py	(revision 13020)
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+#
+# Werner Lustermann
+# ETH Zurich
+#
+import numpy as np
+from pyfact_rename import RawData
+from plotter import Plotter
+from drs_spikes import DRSSpikes
+
+from hist import histogramList, SaveHistograms
+
+import matplotlib.pyplot as plt
+
+
+spike_histo = histogramList('spike_ana')
+spike_histo.h1d('N_candidates', 'N candidates', 
+                10000, 0., 10000., 'number of spike candidates', 'N / 1')
+spike_histo.h1d('N_singles', 'N doubles', 
+                10000, 0., 10000., 'number of signel spikes', 'N / 1')
+spike_histo.h1d('N_doubles', 'N singles', 
+                10000, 0., 10000., 'number of double spikes', 'N / 1')
+
+spike_histo.h1d('ind_ampl_single', 'indicator amplitude singles', 
+                500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV')
+spike_histo.h1d('ind_ampl_double', 'indicator amplitude singles', 
+                500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV')
+
+spikes = {}
+spikes['cand'] = []
+spikes['sing'] = []
+spikes['doub'] = []
+
+def spike_ana(candidates, singles, doubles, data, ind):
+    """ call back function for DRSSpikes class """
+    
+    #number of spikes
+    #print len(candidates), len(singles), len(doubles)
+    spikes['cand'].append(len(candidates))
+    spikes['sing'].append(len(singles))
+    spikes['doub'].append(len(doubles))
+
+    #print 'spikes[cand]', spikes['cand']
+    #spike_histo('N_candidates', len(candidates))
+    #spike_histo('N_singles', len(singles))
+    #spike_histo('N_doubles', len(doubles))
+
+    #indicator
+    print [ind[singles[0]+i] for i in range(4)], '\n'
+    spikes['sing_ampl'].append(ind[singles+1])
+    #spike_histo('ind_ampl_single', ind[single]
+    #amplitudes
+    #print 'ampl'
+    #row, col = data.shape
+    # print 'row, col: ', row, col
+    #a,b = divmod(singles[0], col)
+    #print singles[0], a, b, data[a,b-1], data[a,b], data[1,b+1]
+
+data_file_name = '/data00/fact-construction/raw/2011/11/24/20111124_111.fits.gz'
+calib_file_name = '/data00/fact-construction/raw/2011/11/24/20111124_111.drs.fits.gz'
+run = RawData( data_file_name, calib_file_name )
+
+remove_spikes = DRSSpikes(7., user_action=spike_ana, debug=False)
+
+for event in range(10):
+    data, scell, tt = run.next()
+    remove_spikes(data)
+ 
+x = range(len(spikes['cand']))
+#print 'x: ', x
+plt.figure()
+plt.plot(x, np.array(spikes['cand']), 'b.', label='candidates')
+plt.plot(x, np.array(spikes['sing']), 'g.', label='singles')
+plt.plot(x, np.array(spikes['doub']), 'r.', label='doubles')
+
+plt.title('Number of spikes')
+plt.grid(True)
+plt.legend()
+plt.xlabel('event')
+plt.ylabel('N spikes')
+plt.savefig('n_spikes.jpg')
+
+plt.figure()
+plt.hist(np.array(spikes['cand']), 100, color='blue', 
+         label='candidates', histtype='step')
+plt.hist(np.array(spikes['sing']), 100, color='green',
+         label='singles', histtype='step')
+plt.hist(np.array(spikes['doub']), 100, color='red',
+         label='doubles', histtype='step')
+plt.grid(True)
+plt.title('Number of spike candidates')
+plt.legend()
+plt.savefig('spikes_hist.jpg')
+
+plt.figure()
+
+plt.show()
+
+
+#SaveHistograms( [spike_histo] ,'spike_histo.root')
+
