source: fact/tools/pyscripts/sandbox/vogler/CalFitsPerformanceWeave_7.py@ 17689

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