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 | #define filenames
|
---|
18 |
|
---|
19 | # 2012 04 17
|
---|
20 | #calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal
|
---|
21 | calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal
|
---|
22 |
|
---|
23 | #datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext
|
---|
24 | #datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext
|
---|
25 | #datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext
|
---|
26 | datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 |
|
---|
31 | # 2012 01 25
|
---|
32 | #datafilename = '/fact/raw/2012/01/25/20120125_042.fits.gz' # light-pulser-ext
|
---|
33 | # = '/fact/raw/2012/01/25/20120125_095.fits.gz' # pedestal
|
---|
34 | # = '/fact/raw/2012/01/25/20120125_094.fits.gz' # pedestal
|
---|
35 | # = '/fact/raw/2012/01/25/20120125_093.fits.gz' # pedestal
|
---|
36 | #datafilename = '/fact/raw/2012/01/25/20120125_075.fits.gz'
|
---|
37 | #calibfilename = '/fact/raw/2012/01/25/20120125_088.drs.fits.gz'
|
---|
38 |
|
---|
39 |
|
---|
40 | import numpy as np
|
---|
41 | from scipy import weave
|
---|
42 | from scipy.weave import converters
|
---|
43 |
|
---|
44 | from plotters import Plotter # ADC display
|
---|
45 | from plotters import CamPlotter # event display
|
---|
46 | #from drs_spikes import DRSSpikes
|
---|
47 |
|
---|
48 |
|
---|
49 | print "Testing object creation: "
|
---|
50 | caltest = CalFactFits(datafilename, calibfilename)
|
---|
51 | npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
|
---|
52 | caltest.SetNpcaldataPtr(npcalevent)
|
---|
53 |
|
---|
54 |
|
---|
55 | numroi = np.int64(caltest.nroi)
|
---|
56 | numpix = np.int64(caltest.npix)
|
---|
57 | numevents = np.int64(caltest.nevents)
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 | print "Common variables run information: "
|
---|
62 | print "ROI: ", numroi
|
---|
63 | print "#Pix: ", numpix
|
---|
64 | print "Number of events: ", numevents
|
---|
65 | print
|
---|
66 |
|
---|
67 |
|
---|
68 | event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
|
---|
69 | print "Array event created"
|
---|
70 | run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
|
---|
71 | print "Array run_average created"
|
---|
72 | extracted_average = np.zeros(numpix)
|
---|
73 | print "Array extracted_average created "
|
---|
74 | data_average_run = np.zeros(numroi)
|
---|
75 | print "Arrays created "
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | #####################################################################################################################
|
---|
80 | #print "creating plotters ..."
|
---|
81 |
|
---|
82 | #make a Plotter class ... this is an easy way for plotting ... but there are
|
---|
83 | # many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
|
---|
84 | #myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
85 |
|
---|
86 | #myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
87 |
|
---|
88 | # make a CamPlotter class
|
---|
89 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
|
---|
90 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=-1.2, vmax=1.2) # for pedestal data
|
---|
91 |
|
---|
92 | #print "Plotters created "
|
---|
93 | ###################################################################################################################
|
---|
94 |
|
---|
95 | print "... looping..."
|
---|
96 |
|
---|
97 | while caltest.GetCalEvent(): # Loop ueber alle events
|
---|
98 | #print npcalevent ## Daten, Array 1 dim Laenge caltest.npix * caltest.nroi 1 Event
|
---|
99 | event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
|
---|
100 |
|
---|
101 | run_average += event
|
---|
102 |
|
---|
103 | # A first test of Adrians idea of primitive signal extractor
|
---|
104 | # signal and background
|
---|
105 | extracted_signal = np.zeros(numpix)
|
---|
106 | for signalslice in range(90, 100):
|
---|
107 | extracted_signal += event[0:(numpix), signalslice]
|
---|
108 | # background subtraction
|
---|
109 | for backgroundslice in range(15, 25):
|
---|
110 | extracted_signal -= event[0:(numpix), backgroundslice]
|
---|
111 | extracted_average += extracted_signal
|
---|
112 |
|
---|
113 | print "Looped ... "
|
---|
114 |
|
---|
115 | for i in range (0, (numpix - 1) ):
|
---|
116 | data_average_run += run_average[i]
|
---|
117 |
|
---|
118 |
|
---|
119 | print "Looped second loop "
|
---|
120 |
|
---|
121 | del caltest
|
---|
122 | print "caltest deleted "
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 | print "Common variables run information: "
|
---|
127 | print "ROI: ", numroi
|
---|
128 | print "#Pix: ", numpix
|
---|
129 | print "Number of events: ", numevents
|
---|
130 | print
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | #####################################################################################################################
|
---|
135 | print "creating plotters ..."
|
---|
136 |
|
---|
137 | #make a Plotter class ... this is an easy way for plotting ... but there are
|
---|
138 | # many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
|
---|
139 | myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
140 |
|
---|
141 | myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
142 |
|
---|
143 | # make a CamPlotter class
|
---|
144 | mycamplotter = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
|
---|
145 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
|
---|
146 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=-1.2, vmax=1.2) # for pedestal data
|
---|
147 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=-2, vmax=2) # for pedestal data
|
---|
148 |
|
---|
149 |
|
---|
150 | print "Plotters created "
|
---|
151 | ###################################################################################################################
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 | myplotter((run_average[22]) / numevents, 'pix 22, average' )
|
---|
159 |
|
---|
160 | myplotter2( data_average_run / (numpix * numevents) , 'average signal (all pixel) over the whole run' )
|
---|
161 |
|
---|
162 |
|
---|
163 | #mycamplotter( data[0:1443, 100] ) # plot slice 100 of all pixel
|
---|
164 | mycamplotter( extracted_average / (10 * numevents) ) # plot the extracted signal of all pixel
|
---|
165 |
|
---|
166 | answer = raw_input('type "quit" to quit ')
|
---|
167 | while not 'quit' in answer:
|
---|
168 | answer = raw_input('type "quit" to quit ')
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 | del caltest
|
---|
174 | print "caltest deleted "
|
---|