source: fact/tools/pyscripts/sandbox/vogler/CalFitsPerformanceWeave_6.py@ 17548

Last change on this file since 17548 was 14173, checked in by vogler, 13 years ago
inital filling of my sandbox
  • Property svn:executable set to *
File size: 7.9 KB
Line 
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# ################################
13from ROOT import gSystem
14gSystem.Load("calfactfits_h.so") # according to new naming scheme
15from ROOT import *
16
17
18
19
20
21
22
23#define filenames
24
25# 2012 04 17
26#calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal
27calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal
28
29#datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext
30#datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext
31#datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext
32#datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext
33
34datafilename = '/fact/raw/2012/04/17/20120417_046.fits.gz' # NROI 300, 5 minutes physics data with
35 # interleaved LP_ext
36
37import numpy as np
38from scipy import weave
39from scipy.weave import converters
40
41from plotters import Plotter # ADC display
42from plotters import CamPlotter # event display
43#from drs_spikes import DRSSpikes
44
45
46print "Testing object creation: "
47caltest = CalFactFits(datafilename, calibfilename)
48npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
49caltest.SetNpcaldataPtr(npcalevent)
50
51
52numroi = np.int64(caltest.nroi)
53numpix = np.int64(caltest.npix)
54numevents = np.int64(caltest.nevents)
55
56num_LP_ev = 0 # number of ext Lightpulser events
57num_ped = 0 # number of pedestal events
58
59
60print "Common variables run information: "
61print "ROI: ", numroi
62print "#Pix: ", numpix
63print "Number of events: ", numevents
64print
65
66
67event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
68print "Array event created"
69run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
70print "Array run_average created"
71extracted_average = np.zeros(numpix)
72print "Array extracted_average created "
73data_average_run = np.zeros(numroi)
74print "Arrays created "
75
76
77
78pedestal = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
79print "Array pedestal created"
80pedestal_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
81print "Array pedestal_average created"
82ped_extracted_average = np.zeros(numpix)
83print "Array ped_extracted_average created "
84ped_data_average_run = np.zeros(numroi)
85print "Arrays created "
86
87
88
89
90#####################################################################################################################
91#print "creating plotters ..."
92
93#make a Plotter class ... this is an easy way for plotting ... but there are
94# many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
95#myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
96
97#myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
98
99# make a CamPlotter class
100#mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
101#mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=-1.2, vmax=1.2) # for pedestal data
102
103#print "Plotters created "
104###################################################################################################################
105
106print "... looping..."
107
108while caltest.GetCalEvent(): # Loop ueber alle events
109 # print npcalevent ## Daten, Array 1 dim Laenge caltest.npix * caltest.nroi 1 Event
110
111
112 if ((caltest.event_triggertype > 256) and (caltest.event_triggertype < 512)): #ext LP event
113
114 print 'event id:', caltest.event_id, ' Trigger Type:', caltest.event_triggertype
115
116 num_LP_ev = num_LP_ev + 1
117
118 event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
119
120 run_average += event
121
122 # A first test of Adrians idea of primitive signal extractor
123 # signal and background
124 extracted_signal = np.zeros(numpix)
125 for signalslice in range(90, 100):
126 extracted_signal += event[0:(numpix), signalslice]
127 # background subtraction
128 for backgroundslice in range(15, 25):
129 extracted_signal -= event[0:(numpix), backgroundslice]
130 extracted_average += extracted_signal
131
132
133 elif (caltest.event_triggertype == 1024): # Pedestal event
134 num_ped = num_ped +1
135 print 'pedestal events, event id:', caltest.event_id
136
137 pedestal = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
138
139 pedestal_average += pedestal
140
141 # A first test of Adrians idea of primitive signal extractor
142 # signal and background
143 extracted_pedestal = np.zeros(numpix)
144 for signalslice in range(90, 100):
145 extracted_pedestal += event[0:(numpix), signalslice]
146 # background subtraction
147 for backgroundslice in range(15, 25):
148 extracted_pedestal -= event[0:(numpix), backgroundslice]
149 ped_extracted_average += extracted_pedestal
150
151
152
153print "Looped ... "
154
155for i in range (0, (numpix - 1) ):
156 data_average_run += run_average[i]
157 ped_data_average_run += pedestal_average[i]
158
159print "Looped second loop "
160
161
162del caltest
163print "caltest deleted "
164
165
166
167print "Common variables run information: "
168print "ROI: ", numroi
169print "#Pix: ", numpix
170print "Number of events: ", numevents
171print "Number of external Lightpulser events: ", num_LP_ev
172print "Number of pedestal: ", num_ped
173print
174
175
176
177#####################################################################################################################
178print "creating plotters ..."
179
180#make a Plotter class ... this is an easy way for plotting ... but there are
181# many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
182#myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
183
184myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
185myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
186
187# make a CamPlotter class
188mycamplotter = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
189
190#mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=0, vmax=350) # for Lightpulser data
191
192mycamplotter2 = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=-1.2, vmax=1.2) # for pedestal data
193
194#mycamplotter = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=-2, vmax=2) # for pedestal data
195
196
197print "Plotters created "
198###################################################################################################################
199
200
201#myplotter((run_average[22]) / numevents, 'pix 22, average' )
202
203myplotter2( data_average_run / (numpix * num_LP_ev) , 'average signal (all pixel) over the whole run' )
204
205myplotter( ped_data_average_run / (numpix * num_ped) , 'average pedestal (all pixel) over the whole run' )
206
207
208#mycamplotter( data[0:1443, 100] ) # plot slice 100 of all pixel
209mycamplotter( extracted_average / (10 * num_LP_ev) ) # plot the extracted signal of all pixel
210
211mycamplotter2( ped_extracted_average / (10 * num_ped) ) # plot the extracted pedestal of all pixel
212
213
214
215answer = raw_input('type "quit" to quit ')
216while not 'quit' in answer:
217 answer = raw_input('type "quit" to quit ')
218
219
220
221
222# del caltest
223# print "caltest deleted "
Note: See TracBrowser for help on using the repository browser.