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