source: fact/tools/pyscripts/sandbox/vogler/LP_template_1.py@ 14912

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