source: fact/tools/pyscripts/sandbox/vogler/LP_template_1_time.py@ 17548

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