source: fact/tools/pyscripts/sandbox/vogler/LP_analysis_from_Patrick__example.py@ 17409

Last change on this file since 17409 was 14173, checked in by vogler, 12 years ago
inital filling of my sandbox
  • Property svn:executable set to *
File size: 3.8 KB
Line 
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#
9print '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
13calibfilename = '/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
18datafilename = '/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
29from pyfact import RawData
30import numpy as np
31import sys
32from plotters import Plotter
33from plotters import CamPlotter
34
35print 'creating RawData object...'
36run = RawData(datafilename, calibfilename, return_dict=True)
37
38print "... looping..."
39print ' 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
43data_average = None
44extracted_average = None
45
46for 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
68print "Looped ... "
69
70# After the loop we should divide
71# the data_average and
72# the extracted_average
73# by the number of events
74data_average /= run.nevents
75extracted_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
81data_average_run = data_average.mean( axis=0 )
82
83myplotter = Plotter('this is myplotter', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
84mycamplotter = 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
87myplotter( data_average[22], 'pix 22, average' )
88mycamplotter( extracted_average )
89
90print
91print 'the script was started in "interactive mode" by using the cmdline option -tti in the first line of the script'
92print 'you have still all the variables from the script available here and can go on testing interactively....'
93print
94print 'eg type:'
95print " p = Plotter('test')"
96print " p(data_average_run) "
97print
98print ' the RawData instance called run, was not yet deleted, since in interactive mode this makes no sense ... you might still need it :-)'
Note: See TracBrowser for help on using the repository browser.