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 | #define filenames
|
---|
19 |
|
---|
20 | # 2011 12 05
|
---|
21 | calibfilename = '/fact/raw/2011/12/05/20111205_011.drs.fits.gz' # NROI 300, pedestal
|
---|
22 |
|
---|
23 | datafilename = '/fact/raw/2011/12/05/20111205_022.fits.gz' # NROI 300, 5 minutes physics data with
|
---|
24 |
|
---|
25 |
|
---|
26 | import numpy as np
|
---|
27 | from scipy import weave
|
---|
28 | from scipy.weave import converters
|
---|
29 |
|
---|
30 | from plotters import Plotter # ADC display
|
---|
31 | # from plotters import CamPlotter # event display
|
---|
32 | #from drs_spikes import DRSSpikes
|
---|
33 |
|
---|
34 |
|
---|
35 | caltest = CalFactFits(datafilename, calibfilename)
|
---|
36 | npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
|
---|
37 | caltest.SetNpcaldataPtr(npcalevent)
|
---|
38 |
|
---|
39 |
|
---|
40 | numroi = np.int64(caltest.nroi)
|
---|
41 | numpix = np.int64(caltest.npix)
|
---|
42 | numevents = np.int64(caltest.nevents)
|
---|
43 |
|
---|
44 | num_LP_ev = 0 # number of ext Lightpulser events
|
---|
45 |
|
---|
46 |
|
---|
47 | print "Common variables run information: "
|
---|
48 | print "ROI: ", numroi
|
---|
49 | print "#Pix: ", numpix
|
---|
50 | print "Number of events: ", numevents
|
---|
51 | print
|
---|
52 |
|
---|
53 |
|
---|
54 | event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
|
---|
55 |
|
---|
56 | data_average_run = np.zeros(numroi)
|
---|
57 | over_thresh = np.zeros(numpix) # count for every pixel how many times first slice over 50mV
|
---|
58 |
|
---|
59 | run_rms = np.zeros((numpix, numroi)) # rms
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | print "... looping..."
|
---|
64 |
|
---|
65 | while caltest.GetCalEvent(): # Loop ueber alle events
|
---|
66 |
|
---|
67 |
|
---|
68 | if (caltest.event_triggertype == 4): #ext LP event
|
---|
69 | print 'event id:', caltest.event_id, ' Trigger Type:', caltest.event_triggertype
|
---|
70 | num_LP_ev = num_LP_ev + 1
|
---|
71 | event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
|
---|
72 |
|
---|
73 | for j in range (0, (numpix - 1)):
|
---|
74 | if ((event[j,0] >50)and((j!=863)and(j!=297)and(j!=868))): #exclude crazy pixel (hard ID)
|
---|
75 | over_thresh[j]=over_thresh[j]+1
|
---|
76 | run_rms[j, : ]=run_rms[j, : ] + (event[j, : ])**2
|
---|
77 |
|
---|
78 |
|
---|
79 | for k in range (0, (numpix - 1)):
|
---|
80 | run_rms[k, : ]=run_rms[k, : ]/over_thresh[k]
|
---|
81 | run_rms = np.sqrt(run_rms)
|
---|
82 |
|
---|
83 | for i in range (0, (numpix - 1) ):
|
---|
84 | data_average_run = data_average_run + run_rms[i]**2
|
---|
85 |
|
---|
86 | data_average_run = data_average_run/numpix
|
---|
87 | data_average_run = np.sqrt(data_average_run)
|
---|
88 |
|
---|
89 | maxindex = over_thresh.argmax()
|
---|
90 |
|
---|
91 | del caltest
|
---|
92 | print "caltest deleted "
|
---|
93 |
|
---|
94 | print "Common variables run information: "
|
---|
95 | print "ROI: ", numroi
|
---|
96 | print "#Pix: ", numpix
|
---|
97 | print "Number of events: ", numevents
|
---|
98 | print "Number of external Lightpulser events: ", num_LP_ev
|
---|
99 | print
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 | #####################################################################################################################
|
---|
104 | print "creating plotters ..."
|
---|
105 |
|
---|
106 | #make a Plotter class ... this is an easy way for plotting ... but there are
|
---|
107 | # many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
|
---|
108 | #myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
109 |
|
---|
110 | myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
111 | myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
112 | myplotter3 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
113 | myplotter4 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
114 |
|
---|
115 | over_th_plotter = Plotter('first slice ofer 50mv', xlabel='pixel number', ylabel='number of times first slice over 50mV')
|
---|
116 |
|
---|
117 | print "Plotters created "
|
---|
118 | ###################################################################################################################
|
---|
119 |
|
---|
120 | myplotter(run_rms[20], 'pix 20 rms' )
|
---|
121 | myplotter2(run_rms[21], 'pix 21 rms' )
|
---|
122 | myplotter3(run_rms[maxindex], 'rms: pixel most times over 50mV')
|
---|
123 |
|
---|
124 |
|
---|
125 | over_th_plotter(over_thresh, 'run 20111205_022')
|
---|
126 |
|
---|
127 |
|
---|
128 | myplotter4(data_average_run , 'RMS (all pixel) over the whole run' )
|
---|
129 |
|
---|
130 |
|
---|
131 | answer = raw_input('type "quit" to quit ')
|
---|
132 | while not 'quit' in answer:
|
---|
133 | answer = raw_input('type "quit" to quit ')
|
---|
134 |
|
---|