Changeset 14171 for fact


Ignore:
Timestamp:
06/13/12 15:18:45 (12 years ago)
Author:
neise
Message:
working
Location:
fact/tools/pyscripts/sandbox/dneise/spikes
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/sandbox/dneise/spikes/ana.py

    r14157 r14171  
    55import sys
    66import numpy as np
     7from ctypes import *
    78import os
    89import os.path as path
     
    1213dfn = sys.argv[1]
    1314cfn = sys.argv[2]
     15run = RawData( dfn, cfn)
     16
    1417
    1518file_base_name = path.splitext(path.basename(dfn))[0]
    16 root_filename = '/home_nfs/isdc/neise/' + file_base_name + time.strftime('%Y%m%d_%H%M%S') +'.root'
    17 
    18 run = RawData( dfn, cfn)
     19root_filename = '/home_nfs/isdc/neise/' + file_base_name + '_' + time.strftime('%Y%m%d_%H%M%S') +'_spikeana.root'
    1920
    2021rootfile = TFile(root_filename, "RECREATE")
    2122
    22 canv = TCanvas('canv', 'test canvas',10,10,400,400)
    23 canv.Divide(2,4)
     23baum = TTree('spiketree', 'spike ana tree')
     24
     25# prepare some vars for the tree
     26chid               =  c_int(0)
     27startcell          =  c_int(0)
     28number_of_singles  =  c_int(0)
     29position_of_spikes_in_logical_pipeline   =  np.zeros(100, np.int32)
     30position_of_spikes_in_physical_pipeline  =  np.zeros(100, np.int32)
     31time_to_previous   =  c_long(0)
    2432
    2533
    26 
    27 hs_log_chid = TH2F("hs_log_chid",
    28     "singles - logical pipe vs chid",
    29     1440, -0.5, 1439.5,
    30     300, -0.5, 299.5)
    31 hd_log_chid = TH2F("hd_log_chid",
    32     "doubles - logical pipe vs chid",
    33     1440, -0.5, 1439.5,
    34     300, -0.5, 299.5)
    35 
    36 hs_phys_log = TH2F("hs_phys_log",
    37     "singles logical pipe vs physical pipe",
    38     1024, -0.5, 1023.5,
    39     300, -0.5, 299.5)
    40 
    41 hd_phys_log = TH2F("hd_phys_log",
    42     "doubles logical pipe vs physical pipe",
    43     1024, -0.5, 1023.5,
    44     300, -0.5, 299.5)
    45 
    46 hs_phys_sc = TH2F("hs_phys_sc",
    47     "singles physical pipe vs startcell",
    48     1024, -0.5, 1023.5,
    49     1024, -0.5, 1023.5)
    50    
    51 hd_phys_sc = TH2F("hd_phys_sc",
    52     "doubles physical pipe vs startcell",
    53     1024, -0.5, 1023.5,
    54     1024, -0.5, 1023.5)
    55    
    56 hs_log_sc = TH2F("hs_log_sc",
    57     "singles logical pipe vs startcell",
    58     1024, -0.5, 1023.5,
    59     300, -0.5, 299.5
    60     )
    61    
    62 hd_log_sc = TH2F("hd_log_sc",
    63     "doubles logical pipe vs startcell",
    64     1024, -0.5, 1023.5,
    65     300, -0.5, 299.5,
    66     )
    67 
    68 rootfile.mkdir('per_chid')
    69 rootfile.cd('per_chid')
    70 
    71 hd_log_sc_pp = []
    72 for chid in range(1440):
    73     hd_log_sc_pp.append(
    74         TH2F("chid_"+str(chid),
    75             "doubles - log pipe vs startcell - chid:" +str(chid),
    76             1024, -0.5, 1023.5,
    77             300, -0.5, 299.5)
    78         )
    79        
    80 rootfile.cd('..')
    81 
    82    
    83 singlebaum = TTree('singlebaum', 'spike ana tree')
    84 doublebaum = TTree('doublebaum', 'spike ana tree')
    85 
    86 
    87 # prepare some vars for the tree
    88 chid = 0
    89 startcell = 0
    90 number_of_singles = 0
    91 number_of_doubles = 0
    92 single_positions = np.zeros(10)
    93 double_positions = np.zeros(10)
    94 singlebaum.Branch('chid',chid,'chid/I')
    95 singlebaum.Branch('sc',startcell,'sc/I')
    96 singlebaum.Branch('n',number_of_singles,'n/I')
    97 singlebaum.Branch('spikes',single_positions,'spikes/I')
    98 
    99 doublebaum.Branch('chid',chid,'chid/I')
    100 doublebaum.Branch('sc',startcell,'sc/I')
    101 doublebaum.Branch('n',number_of_doubles,'n/I')
    102 doublebaum.Branch('spikes',double_positions,'spikes/I')
    103 
     34baum.Branch('chid',chid,'chid/I')
     35baum.Branch('sc',startcell,'sc/I')
     36baum.Branch('n',number_of_singles,'n/I')
     37baum.Branch('logpos',position_of_spikes_in_logical_pipeline,'logpos[n]/I')
     38baum.Branch('physpos',position_of_spikes_in_physical_pipeline,'physpos[n]/I')
     39baum.Branch('time',time_to_previous,'time/I')
    10440
    10541
     
    11652           
    11753   
     54despike = DRSSpikes(user_action = spikecallback)
     55
    11856def mars_spikes( data ):
    11957    """
     
    167105    return singles, doubles       
    168106
    169 despike = DRSSpikes(user_action = spikecallback)
     107
     108
     109
     110
     111event = run.next()
     112bt_old = event['board_times'].copy
    170113
    171114for event in run:
     
    173116    s, d = mars_spikes(data)
    174117    sc = event['start_cells']
     118    bt = event['board_times'].copy()
     119   
     120    if len(s) >0 :
     121        chid.value  = s[0][0]
     122        startcell.value = sc[ chid.value ]
     123        number_of_singles.value = len(s)
     124        time.value = bt[s[0][0]/9]-bt_old[s[0][0]/9]
     125        for i in s:
     126            log = i[1]
     127            phys  = (startcell.value+log)%1024
     128            position_of_spikes_in_logical_pipeline[i] = log
     129            position_of_spikes_in_physical_pipeline[i] = phys
     130        baum.Fill()
     131   
     132    bt_old = event['board_times'].copy()
    175133
    176     if len(s) >0 :
    177         for i in s:
    178             log   = i[1]
    179             chid  = i[0]
    180             stace = sc[ chid ]
    181             phys  = (stace+log)%1024
    182            
    183             hs_log_chid.Fill( chid, log)
    184             hs_phys_log.Fill( phys, log)
    185             hs_phys_sc.Fill( stace, phys)
    186             hs_log_sc.Fill( stace, log)
    187            
    188            
    189     if len(d) >0 :
    190         for i in d:
    191             log   = i[1]
    192             chid  = i[0]
    193             stace = sc[ chid ]
    194             phys  = (stace+log)%1024
     134baum.Write()
    195135
    196             hd_log_chid.Fill( chid, log)
    197             hd_phys_log.Fill( phys, log)
    198             hd_phys_sc.Fill( stace, phys)
    199             hd_log_sc.Fill( stace, log)
    200             hd_log_sc_pp[chid].Fill(stace, log)
    201    
    202    
    203    
    204     if event['event_id'] % 100 == 0:
    205         print event['event_id']
    206         canv.cd(1)
    207         hs_log_chid.Draw("COLZ")
    208         canv.cd(2)
    209         hd_log_chid.Draw("COLZ")
    210         canv.cd(3)
    211         hs_phys_log.Draw("COLZ")
    212         canv.cd(4)
    213         hd_phys_log.Draw("COLZ")
    214    
    215         canv.cd(5)
    216         hs_phys_sc.Draw("COLZ")
    217         canv.cd(6)
    218         hd_phys_sc.Draw("COLZ")
    219         canv.cd(7)
    220         hs_log_sc.Draw("COLZ")
    221         canv.cd(8)
    222         hd_log_sc.Draw("COLZ")
    223         canv.Modified()
    224         canv.Update()
    225        
    226        
    227 
    228     if event['event_id'] % 1000 == 0:
    229         print event['event_id']
    230         hs_log_chid.Write('',TObject.kOverwrite)
    231         hd_log_chid.Write('',TObject.kOverwrite)
    232         hs_phys_log.Write('',TObject.kOverwrite)
    233         hd_phys_log.Write('',TObject.kOverwrite)
    234         hs_phys_sc.Write('',TObject.kOverwrite)
    235         hd_phys_sc.Write('',TObject.kOverwrite)
    236         hs_log_sc.Write('',TObject.kOverwrite)
    237         hd_log_sc.Write('',TObject.kOverwrite)
    238        
    239         rootfile.cd('per_chid')
    240         for h in hd_log_sc_pp:
    241             h.Write('',TObject.kOverwrite)
    242         rootfile.cd('..')
    243    
    244 hs_log_chid.Write('',TObject.kOverwrite)
    245 hd_log_chid.Write('',TObject.kOverwrite)
    246 hs_phys_log.Write('',TObject.kOverwrite)
    247 hd_phys_log.Write('',TObject.kOverwrite)
    248 hs_phys_sc.Write('',TObject.kOverwrite)
    249 hd_phys_sc.Write('',TObject.kOverwrite)
    250 hs_log_sc.Write('',TObject.kOverwrite)
    251 hd_log_sc.Write('',TObject.kOverwrite)
    252        
    253 rootfile.cd('per_chid')
    254 for h in hd_log_sc_pp:
    255     h.Write()
    256 rootfile.cd('..')   
    257136rootfile.Close()
Note: See TracChangeset for help on using the changeset viewer.