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