source: fact/tools/pyscripts/sandbox/vogler/LP_template_2.py@ 14962

Last change on this file since 14962 was 14173, checked in by vogler, 12 years ago
inital filling of my sandbox
  • Property svn:executable set to *
File size: 5.5 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
19outfile = open(r'LP_template.txt','w') # file where the template is written to
20
21infile = open(r'FACTmapV6a.txt','r') # read in the FACT mapping file
22
23
24##############################################
25
26# Test: read from a file
27def file_read():
28 # open file test1.txt
29 infile = open('/home/pavogler/Python/test1.txt','r')
30
31 # read lines from the file
32 line1 = infile.readline()
33 line2 = infile.readline()
34 line3 = infile.readline()
35
36 # strip the \n from each string
37 line1 = line1.rstrip('\n')
38 line2 = line2.rstrip('\n')
39 line3 = line3.rstrip('\n')
40
41 # close the file
42 infile.close
43
44
45
46
47 text = 'base sample test'
48 text.split()[0][0]
49 >>> b
50
51
52############################################
53
54
55
56
57#define filenames
58
59# 2012 04 17
60#calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal
61#calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal
62calibfilename = '/fact/raw/2012/06/01/20120601_013.drs.fits.gz' # NROI 300, pedestal
63
64#datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext
65#datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext
66#datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext
67#datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext
68
69datafilename = '/fact/raw/2012/06/01/20120601_017.fits.gz' # NROI 300, 5 minutes physics data with
70 # interleaved LP_ext
71
72import numpy as np
73from scipy import weave
74from scipy.weave import converters
75
76from plotters import Plotter # ADC display
77#from plotters import CamPlotter # event display
78#from drs_spikes import DRSSpikes
79
80
81print "Testing object creation: "
82caltest = CalFactFits(datafilename, calibfilename)
83npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
84caltest.SetNpcaldataPtr(npcalevent)
85
86
87numroi = np.int64(caltest.nroi)
88numpix = np.int64(caltest.npix)
89numevents = np.int64(caltest.nevents)
90
91num_LP_ev = 0 # number of ext Lightpulser events
92num_ped = 0 # number of pedestal events
93
94
95print "Common variables run information: "
96print "ROI: ", numroi
97print "#Pix: ", numpix
98print "Number of events: ", numevents
99print
100
101
102event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
103
104run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
105
106data_average_run = np.zeros(numroi)
107
108
109
110
111
112print "... looping..."
113
114while caltest.GetCalEvent(): # Loop ueber alle events
115 # print npcalevent ## Daten, Array 1 dim Laenge caltest.npix * caltest.nroi 1 Event
116
117
118 if ((caltest.event_triggertype > 256) and (caltest.event_triggertype < 512)): #ext LP event
119 print 'event id:', caltest.event_id, ' Trigger Type:', caltest.event_triggertype
120 num_LP_ev = num_LP_ev + 1
121 event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
122 run_average += event
123
124 if(num_LP_ev==10): # just for testing, not to read the whole file
125 break
126
127
128
129
130
131
132
133
134
135headerline = infile.readline()
136while not '#' in headerline:
137 headerline = infile.readline()
138
139
140
141
142
143
144
145
146
147
148
149
150
151for i in range (0, (numpix - 1) ):
152 # if (()and()and()and()and()and())
153 data_average_run += run_average[i]
154
155
156
157
158
159del caltest
160print "caltest deleted "
161
162
163
164print "Common variables run information: "
165print "ROI: ", numroi
166print "#Pix: ", numpix
167print "Number of events: ", numevents
168print "Number of external Lightpulser events: ", num_LP_ev
169print
170
171
172#####################################################################################################################
173#make a Plotter class ... this is an easy way for plotting ... but there are
174# many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
175#myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
176
177myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
178
179###################################################################################################################
180
181myplotter2( data_average_run / (numpix * num_LP_ev) , 'average signal (all pixel) over the whole run' )
182
183
184
185outfile.write('This file contains a template of the Lightpulser pulse, i.e. an average of one file. \n')
186outfile.write('data file: ' + str(datafilename) + '\n')
187outfile.write('DRS calib file: ' + str(calibfilename) + '\n')
188outfile.write('Number of Lightpulser events in this run: ' + str(num_LP_ev) + '\n')
189outfile.write('ROI: ' + str(numroi) + '\n')
190outfile.write('\n')
191outfile.write('slice signal [mV] \n')
192outfile.write('\n')
193
194
195for k in range(0,(numroi)):
196 outfile.write( str(k) + ' ' + str((data_average_run[k])/(10 * num_LP_ev)) + '\n')
197
198outfile.close
199
200
201
202answer = raw_input('type "quit" to quit ')
203while not 'quit' in answer:
204 answer = raw_input('type "quit" to quit ')
Note: See TracBrowser for help on using the repository browser.