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 | outfile = open(r'LP_template.txt','w') # file where the template is written to
|
---|
20 |
|
---|
21 | infile = open(r'FACTmapV6a.txt','r') # read in the FACT mapping file
|
---|
22 |
|
---|
23 |
|
---|
24 | ##############################################
|
---|
25 |
|
---|
26 | # Test: read from a file
|
---|
27 | def file_read():
|
---|
28 | # open file test1.txt
|
---|
29 | infile = open('/home/pavogler/Python/test1.txt','r')
|
---|
30 |
|
---|
31 | # read lines from the file
|
---|
32 | line1 = infile.readline()
|
---|
33 | line2 = infile.readline()
|
---|
34 | line3 = infile.readline()
|
---|
35 |
|
---|
36 | # strip the \n from each string
|
---|
37 | line1 = line1.rstrip('\n')
|
---|
38 | line2 = line2.rstrip('\n')
|
---|
39 | line3 = line3.rstrip('\n')
|
---|
40 |
|
---|
41 | # close the file
|
---|
42 | infile.close
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 | text = 'base sample test'
|
---|
48 | text.split()[0][0]
|
---|
49 | >>> b
|
---|
50 |
|
---|
51 |
|
---|
52 | ############################################
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | #define filenames
|
---|
58 |
|
---|
59 | # 2012 04 17
|
---|
60 | #calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal
|
---|
61 | #calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal
|
---|
62 | calibfilename = '/fact/raw/2012/06/01/20120601_013.drs.fits.gz' # NROI 300, pedestal
|
---|
63 |
|
---|
64 | #datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext
|
---|
65 | #datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext
|
---|
66 | #datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext
|
---|
67 | #datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext
|
---|
68 |
|
---|
69 | datafilename = '/fact/raw/2012/06/01/20120601_017.fits.gz' # NROI 300, 5 minutes physics data with
|
---|
70 | # interleaved LP_ext
|
---|
71 |
|
---|
72 | import numpy as np
|
---|
73 | from scipy import weave
|
---|
74 | from scipy.weave import converters
|
---|
75 |
|
---|
76 | from plotters import Plotter # ADC display
|
---|
77 | #from plotters import CamPlotter # event display
|
---|
78 | #from drs_spikes import DRSSpikes
|
---|
79 |
|
---|
80 |
|
---|
81 | print "Testing object creation: "
|
---|
82 | caltest = CalFactFits(datafilename, calibfilename)
|
---|
83 | npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
|
---|
84 | caltest.SetNpcaldataPtr(npcalevent)
|
---|
85 |
|
---|
86 |
|
---|
87 | numroi = np.int64(caltest.nroi)
|
---|
88 | numpix = np.int64(caltest.npix)
|
---|
89 | numevents = np.int64(caltest.nevents)
|
---|
90 |
|
---|
91 | num_LP_ev = 0 # number of ext Lightpulser events
|
---|
92 | num_ped = 0 # number of pedestal events
|
---|
93 |
|
---|
94 |
|
---|
95 | print "Common variables run information: "
|
---|
96 | print "ROI: ", numroi
|
---|
97 | print "#Pix: ", numpix
|
---|
98 | print "Number of events: ", numevents
|
---|
99 | print
|
---|
100 |
|
---|
101 |
|
---|
102 | event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
|
---|
103 |
|
---|
104 | run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
|
---|
105 |
|
---|
106 | data_average_run = np.zeros(numroi)
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 | print "... looping..."
|
---|
113 |
|
---|
114 | while caltest.GetCalEvent(): # Loop ueber alle events
|
---|
115 | # print npcalevent ## Daten, Array 1 dim Laenge caltest.npix * caltest.nroi 1 Event
|
---|
116 |
|
---|
117 |
|
---|
118 | if ((caltest.event_triggertype > 256) and (caltest.event_triggertype < 512)): #ext LP event
|
---|
119 | print 'event id:', caltest.event_id, ' Trigger Type:', caltest.event_triggertype
|
---|
120 | num_LP_ev = num_LP_ev + 1
|
---|
121 | event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
|
---|
122 | run_average += event
|
---|
123 |
|
---|
124 | if(num_LP_ev==10): # just for testing, not to read the whole file
|
---|
125 | break
|
---|
126 |
|
---|
127 |
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 | headerline = infile.readline()
|
---|
136 | while not '#' in headerline:
|
---|
137 | headerline = infile.readline()
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 | for i in range (0, (numpix - 1) ):
|
---|
152 | # if (()and()and()and()and()and())
|
---|
153 | data_average_run += run_average[i]
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 |
|
---|
159 | del caltest
|
---|
160 | print "caltest deleted "
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 | print "Common variables run information: "
|
---|
165 | print "ROI: ", numroi
|
---|
166 | print "#Pix: ", numpix
|
---|
167 | print "Number of events: ", numevents
|
---|
168 | print "Number of external Lightpulser events: ", num_LP_ev
|
---|
169 | print
|
---|
170 |
|
---|
171 |
|
---|
172 | #####################################################################################################################
|
---|
173 | #make a Plotter class ... this is an easy way for plotting ... but there are
|
---|
174 | # many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
|
---|
175 | #myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
176 |
|
---|
177 | myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
178 |
|
---|
179 | ###################################################################################################################
|
---|
180 |
|
---|
181 | myplotter2( data_average_run / (numpix * num_LP_ev) , 'average signal (all pixel) over the whole run' )
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 | outfile.write('This file contains a template of the Lightpulser pulse, i.e. an average of one file. \n')
|
---|
186 | outfile.write('data file: ' + str(datafilename) + '\n')
|
---|
187 | outfile.write('DRS calib file: ' + str(calibfilename) + '\n')
|
---|
188 | outfile.write('Number of Lightpulser events in this run: ' + str(num_LP_ev) + '\n')
|
---|
189 | outfile.write('ROI: ' + str(numroi) + '\n')
|
---|
190 | outfile.write('\n')
|
---|
191 | outfile.write('slice signal [mV] \n')
|
---|
192 | outfile.write('\n')
|
---|
193 |
|
---|
194 |
|
---|
195 | for k in range(0,(numroi)):
|
---|
196 | outfile.write( str(k) + ' ' + str((data_average_run[k])/(10 * num_LP_ev)) + '\n')
|
---|
197 |
|
---|
198 | outfile.close
|
---|
199 |
|
---|
200 |
|
---|
201 |
|
---|
202 | answer = raw_input('type "quit" to quit ')
|
---|
203 | while not 'quit' in answer:
|
---|
204 | answer = raw_input('type "quit" to quit ')
|
---|