Changeset 13096


Ignore:
Timestamp:
03/14/12 09:08:24 (13 years ago)
Author:
lusterma
Message:
modified working version - not finished
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/tools/spike_ana.py

    r13020 r13096  
    44# ETH Zurich
    55#
     6from ROOT import TFile
    67import numpy as np
    78from pyfact_rename import RawData
     
    910from drs_spikes import DRSSpikes
    1011
    11 from hist import histogramList, SaveHistograms
     12from hist import hist, histogramList, SaveHistograms
    1213
    1314import matplotlib.pyplot as plt
    1415
    15 
    16 spike_histo = histogramList('spike_ana')
    17 spike_histo.h1d('N_candidates', 'N candidates',
     16spike_histo = {}
     17spike_histo['cand'] = hist('N_candidates', 'N candidates', 
    1818                10000, 0., 10000., 'number of spike candidates', 'N / 1')
    19 spike_histo.h1d('N_singles', 'N doubles',
     19spike_histo['sing']= hist('N_singles', 'N singles',
    2020                10000, 0., 10000., 'number of signel spikes', 'N / 1')
    21 spike_histo.h1d('N_doubles', 'N singles',
     21spike_histo['doub'] = hist('N_doubles', 'N doubles',
    2222                10000, 0., 10000., 'number of double spikes', 'N / 1')
    2323
    24 spike_histo.h1d('ind_ampl_single', 'indicator amplitude singles',
    25                 500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV')
    26 spike_histo.h1d('ind_ampl_double', 'indicator amplitude singles',
    27                 500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV')
     24
     25spike_histo['all_ampl'] = hist('all_ampl', 'indicator all amplitude',                 1000, -1000., 1000., 'indicator amplitude in mV', 'N / 2 mV')
     26spike_histo['cand_ampl'] = hist('cand_ampl', 'candidate amplitudes',                 500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV')
     27spike_histo['sing_ampl'] = hist('cand_ampl_single', 'amplitude singles',                500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV')
     28spike_histo['doub_ampl'] = hist('cand_ampl_double', 'amplitude doubles',                 500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV')
    2829
    2930spikes = {}
     
    3132spikes['sing'] = []
    3233spikes['doub'] = []
     34spikes['cand_ampl'] = []
     35spikes['sing_ampl'] = []
     36spikes['doub_ampl'] = []
     37#spikes['ind'] = []
    3338
    3439def spike_ana(candidates, singles, doubles, data, ind):
    3540    """ call back function for DRSSpikes class """
    36    
     41
    3742    #number of spikes
    3843    #print len(candidates), len(singles), len(doubles)
     
    4045    spikes['sing'].append(len(singles))
    4146    spikes['doub'].append(len(doubles))
     47    spike_histo['cand'](len(candidates))
     48    spike_histo['sing'](len(singles))
     49    spike_histo['doub'](len(doubles))
    4250
    43     #print 'spikes[cand]', spikes['cand']
    44     #spike_histo('N_candidates', len(candidates))
    45     #spike_histo('N_singles', len(singles))
    46     #spike_histo('N_doubles', len(doubles))
     51    spike_histo['all_ampl'](ind)
     52    spike_histo['cand_ampl'](ind[ np.array(candidates)+1])
     53    spike_histo['sing_ampl'](ind[ np.array(singles)+1])
     54    spike_histo['doub_ampl']( (ind[ np.array(doubles)+1] + ind[ np.array(doubles)+2]) / 2.)
    4755
    48     #indicator
    49     print [ind[singles[0]+i] for i in range(4)], '\n'
    50     spikes['sing_ampl'].append(ind[singles+1])
     56    spikes['cand_ampl'].extend( list(ind[ np.array(candidates)+1]) )
     57    spikes['sing_ampl'].extend( list(ind[ np.array(singles)+1]) )
     58    spikes['doub_ampl'].extend( list(
     59            (ind[ np.array(doubles)+1] + ind[ np.array(doubles)+2]) / 2.) )
     60    print 'len() ', len( spikes['sing_ampl'] )
     61    #print spikes['sing_ampl']
     62
    5163    #spike_histo('ind_ampl_single', ind[single]
    5264    #amplitudes
     
    5769    #print singles[0], a, b, data[a,b-1], data[a,b], data[1,b+1]
    5870
    59 data_file_name = '/data00/fact-construction/raw/2011/11/24/20111124_111.fits.gz'
     71data_file_name = '/data00/fact-construction/raw/2011/11/24/20111124_117.fits.gz'
    6072calib_file_name = '/data00/fact-construction/raw/2011/11/24/20111124_111.drs.fits.gz'
    6173run = RawData( data_file_name, calib_file_name )
    6274
    63 remove_spikes = DRSSpikes(7., user_action=spike_ana, debug=False)
     75remove_spikes = DRSSpikes(5., user_action=spike_ana, debug=False)
    6476
    65 for event in range(10):
    66     data, scell, tt = run.next()
     77#for event in range(1000):
     78ev = 0
     79for data, scell, tt in run:
     80    print 'event ', ev
     81    ev += 1
     82    if ev == 10:
     83        break
    6784    remove_spikes(data)
    68  
     85   
     86
     87root_file = TFile( 'spike_histo.root', 'RECREATE')
     88   
     89root_file.mkdir( 'spike_histo' )
     90root_file.cd( 'spike_histo' )
     91for key in spike_histo:
     92    spike_histo[key].mkroot()
     93    spike_histo[key].rh.Write()
     94
     95root_file.Close()
     96
     97plt.figure()
     98plt.semilogy(spike_histo['all_ampl'].y, 'b', label = 'all')
     99plt.semilogy(spike_histo['cand_ampl'].y, 'r', label='candidates')
     100plt.title('Estimator values')
     101plt.xlabel('estimator value')
     102plt.ylabel('N / 1')
     103plt.legend()
     104plt.savefig('spike_histo.jpg')
     105
    69106x = range(len(spikes['cand']))
    70 #print 'x: ', x
     107
    71108plt.figure()
    72109plt.plot(x, np.array(spikes['cand']), 'b.', label='candidates')
    73110plt.plot(x, np.array(spikes['sing']), 'g.', label='singles')
    74111plt.plot(x, np.array(spikes['doub']), 'r.', label='doubles')
     112plt.savefig('t.jpg')
    75113
    76114plt.title('Number of spikes')
     
    94132
    95133plt.figure()
     134plt.hist(np.array(spikes['cand_ampl']), 100, color='blue',
     135         label='candidates', histtype='step', log=True)
     136plt.hist(np.array(spikes['sing_ampl']), 100, color='green',
     137         label='singles', histtype='step', log=True)
     138plt.hist(np.array(spikes['doub_ampl']), 100, color='red',
     139         label='doubles', histtype='step', log=True)
     140plt.grid(True)
     141plt.title('Amplitude of spikes spike indicator')
     142plt.legend()
     143plt.savefig('spikes_ampl_hist.jpg')
    96144
    97145plt.show()
    98 
    99 
    100 #SaveHistograms( [spike_histo] ,'spike_histo.root')
    101 
Note: See TracChangeset for help on using the changeset viewer.