- Timestamp:
- 03/14/12 09:08:24 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/tools/spike_ana.py
r13020 r13096 4 4 # ETH Zurich 5 5 # 6 from ROOT import TFile 6 7 import numpy as np 7 8 from pyfact_rename import RawData … … 9 10 from drs_spikes import DRSSpikes 10 11 11 from hist import hist ogramList, SaveHistograms12 from hist import hist, histogramList, SaveHistograms 12 13 13 14 import matplotlib.pyplot as plt 14 15 15 16 spike_histo = histogramList('spike_ana') 17 spike_histo.h1d('N_candidates', 'N candidates', 16 spike_histo = {} 17 spike_histo['cand'] = hist('N_candidates', 'N candidates', 18 18 10000, 0., 10000., 'number of spike candidates', 'N / 1') 19 spike_histo .h1d('N_singles', 'N doubles',19 spike_histo['sing']= hist('N_singles', 'N singles', 20 20 10000, 0., 10000., 'number of signel spikes', 'N / 1') 21 spike_histo .h1d('N_doubles', 'N singles',21 spike_histo['doub'] = hist('N_doubles', 'N doubles', 22 22 10000, 0., 10000., 'number of double spikes', 'N / 1') 23 23 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 25 spike_histo['all_ampl'] = hist('all_ampl', 'indicator all amplitude', 1000, -1000., 1000., 'indicator amplitude in mV', 'N / 2 mV') 26 spike_histo['cand_ampl'] = hist('cand_ampl', 'candidate amplitudes', 500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV') 27 spike_histo['sing_ampl'] = hist('cand_ampl_single', 'amplitude singles', 500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV') 28 spike_histo['doub_ampl'] = hist('cand_ampl_double', 'amplitude doubles', 500, 0., 1000., 'indicator amplitude in mV', 'N / 2 mV') 28 29 29 30 spikes = {} … … 31 32 spikes['sing'] = [] 32 33 spikes['doub'] = [] 34 spikes['cand_ampl'] = [] 35 spikes['sing_ampl'] = [] 36 spikes['doub_ampl'] = [] 37 #spikes['ind'] = [] 33 38 34 39 def spike_ana(candidates, singles, doubles, data, ind): 35 40 """ call back function for DRSSpikes class """ 36 41 37 42 #number of spikes 38 43 #print len(candidates), len(singles), len(doubles) … … 40 45 spikes['sing'].append(len(singles)) 41 46 spikes['doub'].append(len(doubles)) 47 spike_histo['cand'](len(candidates)) 48 spike_histo['sing'](len(singles)) 49 spike_histo['doub'](len(doubles)) 42 50 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.) 47 55 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 51 63 #spike_histo('ind_ampl_single', ind[single] 52 64 #amplitudes … … 57 69 #print singles[0], a, b, data[a,b-1], data[a,b], data[1,b+1] 58 70 59 data_file_name = '/data00/fact-construction/raw/2011/11/24/20111124_11 1.fits.gz'71 data_file_name = '/data00/fact-construction/raw/2011/11/24/20111124_117.fits.gz' 60 72 calib_file_name = '/data00/fact-construction/raw/2011/11/24/20111124_111.drs.fits.gz' 61 73 run = RawData( data_file_name, calib_file_name ) 62 74 63 remove_spikes = DRSSpikes( 7., user_action=spike_ana, debug=False)75 remove_spikes = DRSSpikes(5., user_action=spike_ana, debug=False) 64 76 65 for event in range(10): 66 data, scell, tt = run.next() 77 #for event in range(1000): 78 ev = 0 79 for data, scell, tt in run: 80 print 'event ', ev 81 ev += 1 82 if ev == 10: 83 break 67 84 remove_spikes(data) 68 85 86 87 root_file = TFile( 'spike_histo.root', 'RECREATE') 88 89 root_file.mkdir( 'spike_histo' ) 90 root_file.cd( 'spike_histo' ) 91 for key in spike_histo: 92 spike_histo[key].mkroot() 93 spike_histo[key].rh.Write() 94 95 root_file.Close() 96 97 plt.figure() 98 plt.semilogy(spike_histo['all_ampl'].y, 'b', label = 'all') 99 plt.semilogy(spike_histo['cand_ampl'].y, 'r', label='candidates') 100 plt.title('Estimator values') 101 plt.xlabel('estimator value') 102 plt.ylabel('N / 1') 103 plt.legend() 104 plt.savefig('spike_histo.jpg') 105 69 106 x = range(len(spikes['cand'])) 70 #print 'x: ', x 107 71 108 plt.figure() 72 109 plt.plot(x, np.array(spikes['cand']), 'b.', label='candidates') 73 110 plt.plot(x, np.array(spikes['sing']), 'g.', label='singles') 74 111 plt.plot(x, np.array(spikes['doub']), 'r.', label='doubles') 112 plt.savefig('t.jpg') 75 113 76 114 plt.title('Number of spikes') … … 94 132 95 133 plt.figure() 134 plt.hist(np.array(spikes['cand_ampl']), 100, color='blue', 135 label='candidates', histtype='step', log=True) 136 plt.hist(np.array(spikes['sing_ampl']), 100, color='green', 137 label='singles', histtype='step', log=True) 138 plt.hist(np.array(spikes['doub_ampl']), 100, color='red', 139 label='doubles', histtype='step', log=True) 140 plt.grid(True) 141 plt.title('Amplitude of spikes spike indicator') 142 plt.legend() 143 plt.savefig('spikes_ampl_hist.jpg') 96 144 97 145 plt.show() 98 99 100 #SaveHistograms( [spike_histo] ,'spike_histo.root')101
Note:
See TracChangeset
for help on using the changeset viewer.