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 | # from ROOT import TCanvas, TH1F
|
---|
18 |
|
---|
19 |
|
---|
20 | c1 = TCanvas( 'c1', 'Example', 200, 10, 700, 500 )
|
---|
21 | hpx = TH1F( 'hpx', 'px', 500,-50, 450 )
|
---|
22 |
|
---|
23 |
|
---|
24 |
|
---|
25 | #define filenames
|
---|
26 |
|
---|
27 | # 2012 04 17
|
---|
28 | #calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal
|
---|
29 | #calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal
|
---|
30 | calibfilename = '/fact/raw/2012/06/01/20120601_013.drs.fits.gz' # NROI 300, pedestal
|
---|
31 |
|
---|
32 | #datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext
|
---|
33 | #datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext
|
---|
34 | #datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext
|
---|
35 | #datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext
|
---|
36 |
|
---|
37 | datafilename = '/fact/raw/2012/06/01/20120601_017.fits.gz' # NROI 300, 5 minutes physics data with
|
---|
38 | # interleaved LP_ext
|
---|
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 | num_LP_ev = 0 # number of ext Lightpulser events
|
---|
60 | num_ped = 0 # number of pedestal events
|
---|
61 |
|
---|
62 |
|
---|
63 | print "Common variables run information: "
|
---|
64 | print "ROI: ", numroi
|
---|
65 | print "#Pix: ", numpix
|
---|
66 | print "Number of events: ", numevents
|
---|
67 | print
|
---|
68 |
|
---|
69 |
|
---|
70 | event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
|
---|
71 | print "Array event created"
|
---|
72 | run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
|
---|
73 | print "Array run_average created"
|
---|
74 | extracted_average = np.zeros(numpix)
|
---|
75 | print "Array extracted_average created "
|
---|
76 | data_average_run = np.zeros(numroi)
|
---|
77 | print "Arrays created "
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | print "... looping..."
|
---|
83 |
|
---|
84 | while caltest.GetCalEvent(): # Loop ueber alle events
|
---|
85 | # print npcalevent ## Daten, Array 1 dim Laenge caltest.npix * caltest.nroi 1 Event
|
---|
86 |
|
---|
87 |
|
---|
88 | if ((caltest.event_triggertype > 256) and (caltest.event_triggertype < 512)): #ext LP event
|
---|
89 |
|
---|
90 | print 'event id:', caltest.event_id, ' Trigger Type:', caltest.event_triggertype
|
---|
91 |
|
---|
92 | num_LP_ev = num_LP_ev + 1
|
---|
93 |
|
---|
94 | event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
|
---|
95 |
|
---|
96 | run_average += event
|
---|
97 |
|
---|
98 | # A first test of Adrians idea of primitive signal extractor
|
---|
99 | # signal and background
|
---|
100 | extracted_signal = np.zeros(numpix)
|
---|
101 | for signalslice in range(90, 100):
|
---|
102 | extracted_signal += event[0:(numpix), signalslice]
|
---|
103 | # background subtraction
|
---|
104 | for backgroundslice in range(15, 25):
|
---|
105 | extracted_signal -= event[0:(numpix), backgroundslice]
|
---|
106 | extracted_average += extracted_signal
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | print "Looped ... "
|
---|
111 |
|
---|
112 | for i in range (0, (numpix - 1) ):
|
---|
113 | data_average_run += run_average[i]
|
---|
114 |
|
---|
115 |
|
---|
116 | print "Looped second loop "
|
---|
117 |
|
---|
118 |
|
---|
119 | del caltest
|
---|
120 | print "caltest deleted "
|
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 | print "Common variables run information: "
|
---|
125 | print "ROI: ", numroi
|
---|
126 | print "#Pix: ", numpix
|
---|
127 | print "Number of events: ", numevents
|
---|
128 | print "Number of external Lightpulser events: ", num_LP_ev
|
---|
129 | print
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | for k in range (0, (numpix) ):
|
---|
135 | px = gRandom.Gaus()
|
---|
136 | hpx.Fill((extracted_average[k] / (10 * num_LP_ev)) )
|
---|
137 |
|
---|
138 | hpx.Draw()
|
---|
139 | c1.Update()
|
---|
140 |
|
---|
141 |
|
---|
142 | #####################################################################################################################
|
---|
143 | print "creating plotters ..."
|
---|
144 |
|
---|
145 | #make a Plotter class ... this is an easy way for plotting ... but there are
|
---|
146 | # many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
|
---|
147 | #myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
148 |
|
---|
149 | myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
150 |
|
---|
151 | # make a CamPlotter class
|
---|
152 | mycamplotter2 = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=0, vmax=400) # for pedestal data
|
---|
153 |
|
---|
154 | print "Plotters created "
|
---|
155 | ###################################################################################################################
|
---|
156 |
|
---|
157 |
|
---|
158 | #myplotter((run_average[22]) / numevents, 'pix 22, average' )
|
---|
159 |
|
---|
160 | myplotter2( data_average_run / (numpix * num_LP_ev) , 'average signal (all pixel) over the whole run' )
|
---|
161 |
|
---|
162 |
|
---|
163 | #mycamplotter( data[0:1443, 100] ) # plot slice 100 of all pixel
|
---|
164 |
|
---|
165 |
|
---|
166 | mycamplotter2( extracted_average / (10 * num_LP_ev) ) # plot the extracted pedestal of all pixel
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 | answer = raw_input('type "quit" to quit ')
|
---|
171 | while not 'quit' in answer:
|
---|
172 | answer = raw_input('type "quit" to quit ')
|
---|