Index: fact/tools/pyscripts/sandbox/dneise/gain/gain.py
===================================================================
--- fact/tools/pyscripts/sandbox/dneise/gain/gain.py	(revision 13446)
+++ fact/tools/pyscripts/sandbox/dneise/gain/gain.py	(revision 13447)
@@ -1,21 +1,16 @@
-#!/usr/bin/python -tti
+#!/usr/bin/python -tt
 #
 # 
 
 from pyfact   import RawData
-from drs_spikes import DRSSpikes        
+from drs_spikes import DRSSpikes
 from fir_filter import CFD
 from fir_filter import SlidingAverage
 
-from plotters import Plotter
-
 import sys
-import cPickle
-import matplotlib.pyplot as plt
 import numpy as np
 
-data_filename = 'data/20111017_009.fits.gz'
+data_filename = 'data/20111017_010.fits.gz'
 calib_filename = 'data/20111017_006.drs.fits.gz'
-out_filename = 'test.pkl'
 
 run = RawData(data_filename, calib_filename, return_dict = True, do_calibration=True)
@@ -30,7 +25,7 @@
 sws = search_window_size
 
-plt.ion()
-fig = plt.figure()
-fig.hold(True)
+#plt.ion()
+#fig = plt.figure()
+#fig.hold(True)
 
 # we try to determine the:
@@ -47,5 +42,5 @@
 
 PEAKS_MAX = 10
-N_INFO = 3 # Position, Height of unfiltered peak, Height of Filtered peak
+
 
 # TODO: this operation might under certain circumstances need way to much mem.
@@ -55,11 +50,12 @@
 #       The user will then find a certain nuber of ndarray in the output npz file.
 #       But this should not be a major problem.
-peaks = np.ones( ( N_INFO, run.nevents, run.npix, PEAKS_MAX), dtype=np.float32)
-
+result_peak_positions         = np.ones( (run.nevents, run.npix,  PEAKS_MAX), dtype=np.int16) * -1
+result_peak_unfiltered_height = np.ones( (run.nevents, run.npix,  PEAKS_MAX), dtype=np.float32) * -np.inf
+result_peak_smoothed_height   = np.ones( (run.nevents, run.npix,  PEAKS_MAX), dtype=np.float32) * -np.inf
 
 
 for event in run:
     event_id = event['event_id'].value - 1
-    print 'event_id', event_id
+    
     
     data = event['acal_data']
@@ -77,6 +73,6 @@
     for dat, fil, orig in zip(data, filtered, data_orig):
         pixel_id += 1
-        print 'pixel id:', pixel_id
-        plt.cla()
+        print event_id, pixel_id
+#        plt.cla()
         prod = fil[:-1] * fil[1:]
         cand = np.where( prod <= 0)[0]
@@ -119,17 +115,24 @@
                 max_smoothed[i]  = dat[max_pos[i]]
                 max_orig[i]      = orig[max_pos[i]-filter_delay]
+        
+        result_peak_positions[event_id,pixel_id, :len(max_pos)]         = max_pos
+        result_peak_unfiltered_height[event_id,pixel_id, :len(max_pos)] =max_orig
+        result_peak_smoothed_height[event_id,pixel_id, :len(max_pos)]   = max_smoothed
 
-        plt.plot(max_pos, max_smoothed, 'ro')
-        plt.plot(max_pos, max_orig, 'bo')
-        plt.plot(np.arange(len(dat)), dat, 'k:')
+#        plt.plot(max_pos, max_smoothed, 'ro')
+#        plt.plot(max_pos, max_orig, 'bo')
+#        plt.plot(np.arange(len(dat)), dat, 'k:')
         
-        ret = raw_input('pixel-loop?')
-        if ret == 'q':
-            break
-    ret = raw_input('event-loop?')
-    if ret == 'q':
-        break
-        
+#        ret = raw_input('pixel-loop?')
+#        if ret == 'q':
+#            break
+#    ret = raw_input('event-loop?')
+#    if ret == 'q':
+#        break
 
+np.savez('20111017_010-006.npz', 
+    result_peak_positions = result_peak_positions,
+    result_peak_unfiltered_height = result_peak_unfiltered_height,
+    result_peak_smoothed_height = result_peak_smoothed_height )
 
 #output = open(out_filename, 'wb')
