Index: fact/tools/pyscripts/sandbox/dneise/spikes/ana.py
===================================================================
--- fact/tools/pyscripts/sandbox/dneise/spikes/ana.py	(revision 14157)
+++ fact/tools/pyscripts/sandbox/dneise/spikes/ana.py	(revision 14171)
@@ -5,4 +5,5 @@
 import sys
 import numpy as np
+from ctypes import *
 import os
 import os.path as path
@@ -12,94 +13,29 @@
 dfn = sys.argv[1]
 cfn = sys.argv[2]
+run = RawData( dfn, cfn) 
+
 
 file_base_name = path.splitext(path.basename(dfn))[0]
-root_filename = '/home_nfs/isdc/neise/' + file_base_name + time.strftime('%Y%m%d_%H%M%S') +'.root'
-
-run = RawData( dfn, cfn) 
+root_filename = '/home_nfs/isdc/neise/' + file_base_name + '_' + time.strftime('%Y%m%d_%H%M%S') +'_spikeana.root'
 
 rootfile = TFile(root_filename, "RECREATE")
 
-canv = TCanvas('canv', 'test canvas',10,10,400,400)
-canv.Divide(2,4)
+baum = TTree('spiketree', 'spike ana tree')
+
+# prepare some vars for the tree
+chid               =  c_int(0)
+startcell          =  c_int(0)
+number_of_singles  =  c_int(0)
+position_of_spikes_in_logical_pipeline   =  np.zeros(100, np.int32)
+position_of_spikes_in_physical_pipeline  =  np.zeros(100, np.int32)
+time_to_previous   =  c_long(0)
 
 
-
-hs_log_chid = TH2F("hs_log_chid",
-    "singles - logical pipe vs chid",
-    1440, -0.5, 1439.5, 
-    300, -0.5, 299.5)
-hd_log_chid = TH2F("hd_log_chid",
-    "doubles - logical pipe vs chid",
-    1440, -0.5, 1439.5, 
-    300, -0.5, 299.5)
-
-hs_phys_log = TH2F("hs_phys_log",
-    "singles logical pipe vs physical pipe",
-    1024, -0.5, 1023.5, 
-    300, -0.5, 299.5)
-
-hd_phys_log = TH2F("hd_phys_log",
-    "doubles logical pipe vs physical pipe",
-    1024, -0.5, 1023.5, 
-    300, -0.5, 299.5)
-
-hs_phys_sc = TH2F("hs_phys_sc",
-    "singles physical pipe vs startcell",
-    1024, -0.5, 1023.5, 
-    1024, -0.5, 1023.5)
-    
-hd_phys_sc = TH2F("hd_phys_sc",
-    "doubles physical pipe vs startcell",
-    1024, -0.5, 1023.5, 
-    1024, -0.5, 1023.5)
-    
-hs_log_sc = TH2F("hs_log_sc",
-    "singles logical pipe vs startcell",
-    1024, -0.5, 1023.5,
-    300, -0.5, 299.5 
-    )
-    
-hd_log_sc = TH2F("hd_log_sc",
-    "doubles logical pipe vs startcell",
-    1024, -0.5, 1023.5,
-    300, -0.5, 299.5, 
-    )
-
-rootfile.mkdir('per_chid')
-rootfile.cd('per_chid')
-
-hd_log_sc_pp = []
-for chid in range(1440):
-    hd_log_sc_pp.append(
-        TH2F("chid_"+str(chid),
-            "doubles - log pipe vs startcell - chid:" +str(chid),
-            1024, -0.5, 1023.5, 
-            300, -0.5, 299.5)
-        )
-        
-rootfile.cd('..')
-
-    
-singlebaum = TTree('singlebaum', 'spike ana tree')
-doublebaum = TTree('doublebaum', 'spike ana tree')
-
-
-# prepare some vars for the tree
-chid = 0
-startcell = 0
-number_of_singles = 0
-number_of_doubles = 0
-single_positions = np.zeros(10)
-double_positions = np.zeros(10)
-singlebaum.Branch('chid',chid,'chid/I')
-singlebaum.Branch('sc',startcell,'sc/I')
-singlebaum.Branch('n',number_of_singles,'n/I')
-singlebaum.Branch('spikes',single_positions,'spikes/I')
-
-doublebaum.Branch('chid',chid,'chid/I')
-doublebaum.Branch('sc',startcell,'sc/I')
-doublebaum.Branch('n',number_of_doubles,'n/I')
-doublebaum.Branch('spikes',double_positions,'spikes/I')
-
+baum.Branch('chid',chid,'chid/I')
+baum.Branch('sc',startcell,'sc/I')
+baum.Branch('n',number_of_singles,'n/I')
+baum.Branch('logpos',position_of_spikes_in_logical_pipeline,'logpos[n]/I')
+baum.Branch('physpos',position_of_spikes_in_physical_pipeline,'physpos[n]/I')
+baum.Branch('time',time_to_previous,'time/I')
 
 
@@ -116,4 +52,6 @@
             
     
+despike = DRSSpikes(user_action = spikecallback)
+
 def mars_spikes( data ):
     """
@@ -167,5 +105,10 @@
     return singles, doubles        
 
-despike = DRSSpikes(user_action = spikecallback)
+
+
+
+
+event = run.next()
+bt_old = event['board_times'].copy
 
 for event in run:
@@ -173,85 +116,21 @@
     s, d = mars_spikes(data)
     sc = event['start_cells']
+    bt = event['board_times'].copy()
+    
+    if len(s) >0 :
+        chid.value  = s[0][0]
+        startcell.value = sc[ chid.value ]
+        number_of_singles.value = len(s)
+        time.value = bt[s[0][0]/9]-bt_old[s[0][0]/9]
+        for i in s:
+            log = i[1]
+            phys  = (startcell.value+log)%1024
+            position_of_spikes_in_logical_pipeline[i] = log
+            position_of_spikes_in_physical_pipeline[i] = phys
+        baum.Fill()
+    
+    bt_old = event['board_times'].copy()
 
-    if len(s) >0 :
-        for i in s:
-            log   = i[1]
-            chid  = i[0]
-            stace = sc[ chid ]
-            phys  = (stace+log)%1024
-            
-            hs_log_chid.Fill( chid, log)
-            hs_phys_log.Fill( phys, log)
-            hs_phys_sc.Fill( stace, phys)
-            hs_log_sc.Fill( stace, log)
-            
-            
-    if len(d) >0 :
-        for i in d:
-            log   = i[1]
-            chid  = i[0]
-            stace = sc[ chid ]
-            phys  = (stace+log)%1024
+baum.Write()
 
-            hd_log_chid.Fill( chid, log)
-            hd_phys_log.Fill( phys, log)
-            hd_phys_sc.Fill( stace, phys)
-            hd_log_sc.Fill( stace, log)
-            hd_log_sc_pp[chid].Fill(stace, log)
-    
-    
-    
-    if event['event_id'] % 100 == 0:
-        print event['event_id']
-        canv.cd(1)
-        hs_log_chid.Draw("COLZ")
-        canv.cd(2)
-        hd_log_chid.Draw("COLZ")
-        canv.cd(3)
-        hs_phys_log.Draw("COLZ")
-        canv.cd(4)
-        hd_phys_log.Draw("COLZ")
-    
-        canv.cd(5)
-        hs_phys_sc.Draw("COLZ")
-        canv.cd(6)
-        hd_phys_sc.Draw("COLZ")
-        canv.cd(7)
-        hs_log_sc.Draw("COLZ")
-        canv.cd(8)
-        hd_log_sc.Draw("COLZ")
-        canv.Modified()
-        canv.Update()
-        
-        
-
-    if event['event_id'] % 1000 == 0:
-        print event['event_id']
-        hs_log_chid.Write('',TObject.kOverwrite)
-        hd_log_chid.Write('',TObject.kOverwrite)
-        hs_phys_log.Write('',TObject.kOverwrite)
-        hd_phys_log.Write('',TObject.kOverwrite)
-        hs_phys_sc.Write('',TObject.kOverwrite)
-        hd_phys_sc.Write('',TObject.kOverwrite)
-        hs_log_sc.Write('',TObject.kOverwrite)
-        hd_log_sc.Write('',TObject.kOverwrite)
-        
-        rootfile.cd('per_chid')
-        for h in hd_log_sc_pp:
-            h.Write('',TObject.kOverwrite)
-        rootfile.cd('..')
-    
-hs_log_chid.Write('',TObject.kOverwrite)
-hd_log_chid.Write('',TObject.kOverwrite)
-hs_phys_log.Write('',TObject.kOverwrite)
-hd_phys_log.Write('',TObject.kOverwrite)
-hs_phys_sc.Write('',TObject.kOverwrite)
-hd_phys_sc.Write('',TObject.kOverwrite)
-hs_log_sc.Write('',TObject.kOverwrite)
-hd_log_sc.Write('',TObject.kOverwrite)
-        
-rootfile.cd('per_chid')
-for h in hd_log_sc_pp:
-    h.Write()
-rootfile.cd('..')    
 rootfile.Close()
