1 | #!/usr/bin/python -tt
|
---|
2 | # ********************************
|
---|
3 | # Test script for the CalFits class
|
---|
4 | #
|
---|
5 | # written by Thomas Kraehenbuehl, ETH Zurich
|
---|
6 | # tpk@phys.ethz.ch, +41 44 633 3973
|
---|
7 | # April 2012
|
---|
8 | # ********************************
|
---|
9 | #
|
---|
10 | # modified and adapted py Patrick Vogler
|
---|
11 | #
|
---|
12 | # ################################
|
---|
13 | from ROOT import gSystem
|
---|
14 | gSystem.Load("calfactfits_h.so") # according to new naming scheme
|
---|
15 | from ROOT import *
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | #define filenames
|
---|
24 |
|
---|
25 | # 2012 04 17
|
---|
26 | #calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal
|
---|
27 | calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal
|
---|
28 |
|
---|
29 | #datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext
|
---|
30 | #datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext
|
---|
31 | #datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext
|
---|
32 | #datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext
|
---|
33 |
|
---|
34 | datafilename = '/fact/raw/2012/04/17/20120417_046.fits.gz' # NROI 300, 5 minutes physics data with
|
---|
35 | # interleaved LP_ext
|
---|
36 |
|
---|
37 | import numpy as np
|
---|
38 | from scipy import weave
|
---|
39 | from scipy.weave import converters
|
---|
40 |
|
---|
41 | from plotters import Plotter # ADC display
|
---|
42 | from plotters import CamPlotter # event display
|
---|
43 | #from drs_spikes import DRSSpikes
|
---|
44 |
|
---|
45 |
|
---|
46 | print "Testing object creation: "
|
---|
47 | caltest = CalFactFits(datafilename, calibfilename)
|
---|
48 | npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
|
---|
49 | caltest.SetNpcaldataPtr(npcalevent)
|
---|
50 |
|
---|
51 |
|
---|
52 | numroi = np.int64(caltest.nroi)
|
---|
53 | numpix = np.int64(caltest.npix)
|
---|
54 | numevents = np.int64(caltest.nevents)
|
---|
55 |
|
---|
56 | num_LP_ev = 0 # number of ext Lightpulser events
|
---|
57 | num_ped = 0 # number of pedestal events
|
---|
58 |
|
---|
59 |
|
---|
60 | print "Common variables run information: "
|
---|
61 | print "ROI: ", numroi
|
---|
62 | print "#Pix: ", numpix
|
---|
63 | print "Number of events: ", numevents
|
---|
64 | print
|
---|
65 |
|
---|
66 |
|
---|
67 | event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
|
---|
68 | print "Array event created"
|
---|
69 | run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
|
---|
70 | print "Array run_average created"
|
---|
71 | extracted_average = np.zeros(numpix)
|
---|
72 | print "Array extracted_average created "
|
---|
73 | data_average_run = np.zeros(numroi)
|
---|
74 | print "Arrays created "
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 | pedestal = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
|
---|
79 | print "Array pedestal created"
|
---|
80 | pedestal_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
|
---|
81 | print "Array pedestal_average created"
|
---|
82 | ped_extracted_average = np.zeros(numpix)
|
---|
83 | print "Array ped_extracted_average created "
|
---|
84 | ped_data_average_run = np.zeros(numroi)
|
---|
85 | print "Arrays created "
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | #####################################################################################################################
|
---|
91 | #print "creating plotters ..."
|
---|
92 |
|
---|
93 | #make a Plotter class ... this is an easy way for plotting ... but there are
|
---|
94 | # many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
|
---|
95 | #myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
96 |
|
---|
97 | #myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
98 |
|
---|
99 | # make a CamPlotter class
|
---|
100 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
|
---|
101 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=-1.2, vmax=1.2) # for pedestal data
|
---|
102 |
|
---|
103 | #print "Plotters created "
|
---|
104 | ###################################################################################################################
|
---|
105 |
|
---|
106 | print "... looping..."
|
---|
107 |
|
---|
108 | while caltest.GetCalEvent(): # Loop ueber alle events
|
---|
109 | # print npcalevent ## Daten, Array 1 dim Laenge caltest.npix * caltest.nroi 1 Event
|
---|
110 |
|
---|
111 |
|
---|
112 | if ((caltest.event_triggertype > 256) and (caltest.event_triggertype < 512)): #ext LP event
|
---|
113 |
|
---|
114 | print 'event id:', caltest.event_id, ' Trigger Type:', caltest.event_triggertype
|
---|
115 |
|
---|
116 | num_LP_ev = num_LP_ev + 1
|
---|
117 |
|
---|
118 | event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
|
---|
119 |
|
---|
120 | run_average += event
|
---|
121 |
|
---|
122 | # A first test of Adrians idea of primitive signal extractor
|
---|
123 | # signal and background
|
---|
124 | extracted_signal = np.zeros(numpix)
|
---|
125 | for signalslice in range(90, 100):
|
---|
126 | extracted_signal += event[0:(numpix), signalslice]
|
---|
127 | # background subtraction
|
---|
128 | for backgroundslice in range(15, 25):
|
---|
129 | extracted_signal -= event[0:(numpix), backgroundslice]
|
---|
130 | extracted_average += extracted_signal
|
---|
131 |
|
---|
132 |
|
---|
133 | elif (caltest.event_triggertype == 1024): # Pedestal event
|
---|
134 | num_ped = num_ped +1
|
---|
135 | print 'pedestal events, event id:', caltest.event_id
|
---|
136 |
|
---|
137 | pedestal = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
|
---|
138 |
|
---|
139 | pedestal_average += pedestal
|
---|
140 |
|
---|
141 | # A first test of Adrians idea of primitive signal extractor
|
---|
142 | # signal and background
|
---|
143 | extracted_pedestal = np.zeros(numpix)
|
---|
144 | for signalslice in range(90, 100):
|
---|
145 | extracted_pedestal += event[0:(numpix), signalslice]
|
---|
146 | # background subtraction
|
---|
147 | for backgroundslice in range(15, 25):
|
---|
148 | extracted_pedestal -= event[0:(numpix), backgroundslice]
|
---|
149 | ped_extracted_average += extracted_pedestal
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | print "Looped ... "
|
---|
154 |
|
---|
155 | for i in range (0, (numpix - 1) ):
|
---|
156 | data_average_run += run_average[i]
|
---|
157 | ped_data_average_run += pedestal_average[i]
|
---|
158 |
|
---|
159 | print "Looped second loop "
|
---|
160 |
|
---|
161 |
|
---|
162 | del caltest
|
---|
163 | print "caltest deleted "
|
---|
164 |
|
---|
165 |
|
---|
166 |
|
---|
167 | print "Common variables run information: "
|
---|
168 | print "ROI: ", numroi
|
---|
169 | print "#Pix: ", numpix
|
---|
170 | print "Number of events: ", numevents
|
---|
171 | print "Number of external Lightpulser events: ", num_LP_ev
|
---|
172 | print "Number of pedestal: ", num_ped
|
---|
173 | print
|
---|
174 |
|
---|
175 |
|
---|
176 |
|
---|
177 | #####################################################################################################################
|
---|
178 | print "creating plotters ..."
|
---|
179 |
|
---|
180 | #make a Plotter class ... this is an easy way for plotting ... but there are
|
---|
181 | # many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
|
---|
182 | #myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
183 |
|
---|
184 | myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
185 | myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
186 |
|
---|
187 | # make a CamPlotter class
|
---|
188 | mycamplotter = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
|
---|
189 |
|
---|
190 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
|
---|
191 |
|
---|
192 | mycamplotter2 = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=-1.2, vmax=1.2) # for pedestal data
|
---|
193 |
|
---|
194 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=-2, vmax=2) # for pedestal data
|
---|
195 |
|
---|
196 |
|
---|
197 | print "Plotters created "
|
---|
198 | ###################################################################################################################
|
---|
199 |
|
---|
200 |
|
---|
201 | #myplotter((run_average[22]) / numevents, 'pix 22, average' )
|
---|
202 |
|
---|
203 | myplotter2( data_average_run / (numpix * num_LP_ev) , 'average signal (all pixel) over the whole run' )
|
---|
204 |
|
---|
205 | myplotter( ped_data_average_run / (numpix * num_ped) , 'average pedestal (all pixel) over the whole run' )
|
---|
206 |
|
---|
207 |
|
---|
208 | #mycamplotter( data[0:1443, 100] ) # plot slice 100 of all pixel
|
---|
209 | mycamplotter( extracted_average / (10 * num_LP_ev) ) # plot the extracted signal of all pixel
|
---|
210 |
|
---|
211 | mycamplotter2( ped_extracted_average / (10 * num_ped) ) # plot the extracted pedestal of all pixel
|
---|
212 |
|
---|
213 |
|
---|
214 |
|
---|
215 | answer = raw_input('type "quit" to quit ')
|
---|
216 | while not 'quit' in answer:
|
---|
217 | answer = raw_input('type "quit" to quit ')
|
---|
218 |
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 | # del caltest
|
---|
223 | # print "caltest deleted "
|
---|