source: fact/tools/pyscripts/sandbox/vogler/LP_hist_1.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.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# from ROOT import TCanvas, TH1F
18
19
20c1 = TCanvas( 'c1', 'Example', 200, 10, 700, 500 )
21hpx = TH1F( 'hpx', 'px', 500,-50, 450 )
22
23
24
25#define filenames
26
27# 2012 04 17
28#calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal
29#calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal
30calibfilename = '/fact/raw/2012/06/01/20120601_013.drs.fits.gz' # NROI 300, pedestal
31
32#datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext
33#datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext
34#datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext
35#datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext
36
37datafilename = '/fact/raw/2012/06/01/20120601_017.fits.gz' # NROI 300, 5 minutes physics data with
38 # interleaved LP_ext
39
40import numpy as np
41from scipy import weave
42from scipy.weave import converters
43
44from plotters import Plotter # ADC display
45from plotters import CamPlotter # event display
46#from drs_spikes import DRSSpikes
47
48
49print "Testing object creation: "
50caltest = CalFactFits(datafilename, calibfilename)
51npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
52caltest.SetNpcaldataPtr(npcalevent)
53
54
55numroi = np.int64(caltest.nroi)
56numpix = np.int64(caltest.npix)
57numevents = np.int64(caltest.nevents)
58
59num_LP_ev = 0 # number of ext Lightpulser events
60num_ped = 0 # number of pedestal events
61
62
63print "Common variables run information: "
64print "ROI: ", numroi
65print "#Pix: ", numpix
66print "Number of events: ", numevents
67print
68
69
70event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
71print "Array event created"
72run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
73print "Array run_average created"
74extracted_average = np.zeros(numpix)
75print "Array extracted_average created "
76data_average_run = np.zeros(numroi)
77print "Arrays created "
78
79
80
81
82print "... looping..."
83
84while caltest.GetCalEvent(): # Loop ueber alle events
85 # print npcalevent ## Daten, Array 1 dim Laenge caltest.npix * caltest.nroi 1 Event
86
87
88 if ((caltest.event_triggertype > 256) and (caltest.event_triggertype < 512)): #ext LP event
89
90 print 'event id:', caltest.event_id, ' Trigger Type:', caltest.event_triggertype
91
92 num_LP_ev = num_LP_ev + 1
93
94 event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array)
95
96 run_average += event
97
98 # A first test of Adrians idea of primitive signal extractor
99 # signal and background
100 extracted_signal = np.zeros(numpix)
101 for signalslice in range(90, 100):
102 extracted_signal += event[0:(numpix), signalslice]
103 # background subtraction
104 for backgroundslice in range(15, 25):
105 extracted_signal -= event[0:(numpix), backgroundslice]
106 extracted_average += extracted_signal
107
108
109
110print "Looped ... "
111
112for i in range (0, (numpix - 1) ):
113 data_average_run += run_average[i]
114
115
116print "Looped second loop "
117
118
119del caltest
120print "caltest deleted "
121
122
123
124print "Common variables run information: "
125print "ROI: ", numroi
126print "#Pix: ", numpix
127print "Number of events: ", numevents
128print "Number of external Lightpulser events: ", num_LP_ev
129print
130
131
132
133
134for k in range (0, (numpix) ):
135 px = gRandom.Gaus()
136 hpx.Fill((extracted_average[k] / (10 * num_LP_ev)) )
137
138hpx.Draw()
139c1.Update()
140
141
142#####################################################################################################################
143print "creating plotters ..."
144
145#make a Plotter class ... this is an easy way for plotting ... but there are
146# many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it...
147#myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
148
149myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
150
151# make a CamPlotter class
152mycamplotter2 = CamPlotter('titel of the plot', map_file_path = 'map_dn.txt', vmin=0, vmax=400) # for pedestal data
153
154print "Plotters created "
155###################################################################################################################
156
157
158#myplotter((run_average[22]) / numevents, 'pix 22, average' )
159
160myplotter2( data_average_run / (numpix * num_LP_ev) , 'average signal (all pixel) over the whole run' )
161
162
163#mycamplotter( data[0:1443, 100] ) # plot slice 100 of all pixel
164
165
166mycamplotter2( extracted_average / (10 * num_LP_ev) ) # plot the extracted pedestal of all pixel
167
168
169
170answer = raw_input('type "quit" to quit ')
171while not 'quit' in answer:
172 answer = raw_input('type "quit" to quit ')
Note: See TracBrowser for help on using the repository browser.