1 | #!/usr/bin/python -tti
|
---|
2 | #
|
---|
3 | # Lightpulser Analysis Test Script
|
---|
4 | # Written by DN but
|
---|
5 | # but based on an idea from PV
|
---|
6 | # This script is intended for testing purposes,
|
---|
7 | # and has no real purpose so far....
|
---|
8 | #
|
---|
9 | print 'importing libraries ... takes a sec .. sorry'
|
---|
10 |
|
---|
11 | # 2012 04 17
|
---|
12 | #calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal
|
---|
13 | calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal
|
---|
14 |
|
---|
15 | #datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext
|
---|
16 | #datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext
|
---|
17 | #datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext
|
---|
18 | datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext
|
---|
19 |
|
---|
20 | # 2012 01 25
|
---|
21 | #datafilename = '/fact/raw/2012/01/25/20120125_042.fits.gz' # light-pulser-ext
|
---|
22 | # = '/fact/raw/2012/01/25/20120125_095.fits.gz' # pedestal
|
---|
23 | # = '/fact/raw/2012/01/25/20120125_094.fits.gz' # pedestal
|
---|
24 | # = '/fact/raw/2012/01/25/20120125_093.fits.gz' # pedestal
|
---|
25 | #datafilename = '/fact/raw/2012/01/25/20120125_075.fits.gz'
|
---|
26 | #calibfilename = '/fact/raw/2012/01/25/20120125_088.drs.fits.gz'
|
---|
27 |
|
---|
28 |
|
---|
29 | from pyfact import RawData
|
---|
30 | import numpy as np
|
---|
31 | import sys
|
---|
32 | from plotters import Plotter
|
---|
33 | from plotters import CamPlotter
|
---|
34 |
|
---|
35 | print 'creating RawData object...'
|
---|
36 | run = RawData(datafilename, calibfilename, return_dict=True)
|
---|
37 |
|
---|
38 | print "... looping..."
|
---|
39 | print ' over ', run.nevents, 'events ... please wait and stay calm :-)'
|
---|
40 |
|
---|
41 | # create variables as 'None' so inside the loop the variables can be created
|
---|
42 | # with the right shape
|
---|
43 | data_average = None
|
---|
44 | extracted_average = None
|
---|
45 |
|
---|
46 | for event in run:
|
---|
47 | data = event['acal_data'] # this data is already in the shape number_of_pixel x ROI
|
---|
48 |
|
---|
49 | # create an array to store the 'average event', the shape derived from the shape of the data
|
---|
50 | if data_average == None:
|
---|
51 | data_average = np.zeros( data.shape )
|
---|
52 | data_average += data
|
---|
53 |
|
---|
54 |
|
---|
55 | # A first test of Adrians idea of primitive signal extractor
|
---|
56 | # signal and background
|
---|
57 |
|
---|
58 | # axis=1 means, do not sum over all, but only over the slices, the output is a numpy array with len=numpix
|
---|
59 | extracted_signal = data[ : , 90:100 ].sum( axis=1 )
|
---|
60 |
|
---|
61 | # background subtraction
|
---|
62 | extracted_signal -= data[ : , 15:25 ].sum( axis=1 )
|
---|
63 |
|
---|
64 | if extracted_average == None:
|
---|
65 | extracted_average = np.zeros( extracted_signal.shape )
|
---|
66 | extracted_average += extracted_signal
|
---|
67 |
|
---|
68 | print "Looped ... "
|
---|
69 |
|
---|
70 | # After the loop we should divide
|
---|
71 | # the data_average and
|
---|
72 | # the extracted_average
|
---|
73 | # by the number of events
|
---|
74 | data_average /= run.nevents
|
---|
75 | extracted_average /= 10 * run.nevents # the 10 is hardcoded here ... this is bad coding ... but it works :-)
|
---|
76 |
|
---|
77 | # I guess data_average_run was intended to contain the mean over all pixel
|
---|
78 | # the name is a bit strange ...
|
---|
79 | # axis=0 means, to calculate the mean over all pixel.
|
---|
80 | # so outcome is a 1D array of length = ROI
|
---|
81 | data_average_run = data_average.mean( axis=0 )
|
---|
82 |
|
---|
83 | myplotter = Plotter('this is myplotter', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
---|
84 | mycamplotter = CamPlotter('this is mycamplotter', vmax=350) # for Lightpulser data
|
---|
85 | #mycamplotter = CamPlotter('titel of the plot', map_file_path = '../map_dn.txt', vmin=-1.2, vmax=1.2) # for pedestal data
|
---|
86 |
|
---|
87 | myplotter( data_average[22], 'pix 22, average' )
|
---|
88 | mycamplotter( extracted_average )
|
---|
89 |
|
---|
90 | print
|
---|
91 | print 'the script was started in "interactive mode" by using the cmdline option -tti in the first line of the script'
|
---|
92 | print 'you have still all the variables from the script available here and can go on testing interactively....'
|
---|
93 | print
|
---|
94 | print 'eg type:'
|
---|
95 | print " p = Plotter('test')"
|
---|
96 | print " p(data_average_run) "
|
---|
97 | print
|
---|
98 | print ' the RawData instance called run, was not yet deleted, since in interactive mode this makes no sense ... you might still need it :-)'
|
---|