| 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 | # ################################
|
|---|
| 13 | from ROOT import gSystem
|
|---|
| 14 | gSystem.Load("calfactfits_h.so") # according to new naming scheme
|
|---|
| 15 | from ROOT import *
|
|---|
| 16 |
|
|---|
| 17 | import time
|
|---|
| 18 |
|
|---|
| 19 | # c1 = TCanvas( 'c1', 'Example', 200, 10, 700, 500 )
|
|---|
| 20 | # hpx = TH1F( 'hpx', 'px', 500,-50, 450 )
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | outfile = 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
|
|---|
| 54 | calibfilename = '/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 |
|
|---|
| 61 | datafilename = '/fact/raw/2012/06/01/20120601_017.fits.gz' # NROI 300, 5 minutes physics data with
|
|---|
| 62 | # interleaved LP_ext
|
|---|
| 63 |
|
|---|
| 64 | import numpy as np
|
|---|
| 65 | from scipy import weave
|
|---|
| 66 | from scipy.weave import converters
|
|---|
| 67 |
|
|---|
| 68 | from plotters import Plotter # ADC display
|
|---|
| 69 | #from plotters import CamPlotter # event display
|
|---|
| 70 | #from drs_spikes import DRSSpikes
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | print "Testing object creation: "
|
|---|
| 74 | caltest = CalFactFits(datafilename, calibfilename)
|
|---|
| 75 | npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
|
|---|
| 76 | caltest.SetNpcaldataPtr(npcalevent)
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | numroi = np.int64(caltest.nroi)
|
|---|
| 80 | numpix = np.int64(caltest.npix)
|
|---|
| 81 | numevents = np.int64(caltest.nevents)
|
|---|
| 82 |
|
|---|
| 83 | num_LP_ev = 0 # number of ext Lightpulser events
|
|---|
| 84 | num_ped = 0 # number of pedestal events
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | print "Common variables run information: "
|
|---|
| 88 | print "ROI: ", numroi
|
|---|
| 89 | print "#Pix: ", numpix
|
|---|
| 90 | print "Number of events: ", numevents
|
|---|
| 91 | print
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 | event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array)
|
|---|
| 95 |
|
|---|
| 96 | run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run
|
|---|
| 97 |
|
|---|
| 98 | data_average_run = np.zeros(numroi)
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | time_start = time.clock()
|
|---|
| 103 | print "start loop", time_start
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | while 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 |
|
|---|
| 119 | time_stop = time.clock()
|
|---|
| 120 | print "loop finished", time_stop
|
|---|
| 121 |
|
|---|
| 122 | print "Looped ... "
|
|---|
| 123 |
|
|---|
| 124 | for i in range (0, (numpix - 1) ):
|
|---|
| 125 |
|
|---|
| 126 | # if (()and()and()and()and()and())
|
|---|
| 127 |
|
|---|
| 128 | data_average_run += run_average[i]
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | print "Looped second loop "
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 | del caltest
|
|---|
| 135 | print "caltest deleted "
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 | print "Common variables run information: "
|
|---|
| 140 | print "ROI: ", numroi
|
|---|
| 141 | print "#Pix: ", numpix
|
|---|
| 142 | print "Number of events: ", numevents
|
|---|
| 143 | print "Number of external Lightpulser events: ", num_LP_ev
|
|---|
| 144 | print
|
|---|
| 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 |
|
|---|
| 152 | myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV')
|
|---|
| 153 |
|
|---|
| 154 | ###################################################################################################################
|
|---|
| 155 |
|
|---|
| 156 | myplotter2( data_average_run / (numpix * num_LP_ev) , 'average signal (all pixel) over the whole run' )
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | outfile.write('This file contains a template of the Lightpulser pulse, i.e. an average of one file. \n')
|
|---|
| 161 | outfile.write('data file: ' + str(datafilename) + '\n')
|
|---|
| 162 | outfile.write('DRS calib file: ' + str(calibfilename) + '\n')
|
|---|
| 163 | outfile.write('Number of Lightpulser events in this run: ' + str(num_LP_ev) + '\n')
|
|---|
| 164 | outfile.write('ROI: ' + str(numroi) + '\n')
|
|---|
| 165 | outfile.write('\n')
|
|---|
| 166 | outfile.write('slice signal [mV] \n')
|
|---|
| 167 | outfile.write('\n')
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 | for k in range(0,(numroi)):
|
|---|
| 171 | outfile.write( str(k) + ' ' + str((data_average_run[k])/(10 * num_LP_ev)) + '\n')
|
|---|
| 172 |
|
|---|
| 173 | outfile.close
|
|---|
| 174 |
|
|---|
| 175 | print
|
|---|
| 176 | print "The loop over the whole file took",(time_stop-time_start),"seconds to complete."
|
|---|
| 177 | print "processing rate: ",(numevents/(time_stop-time_start)),"events per second"
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 | answer = raw_input('type "quit" to quit ')
|
|---|
| 181 | while not 'quit' in answer:
|
|---|
| 182 | answer = raw_input('type "quit" to quit ')
|
|---|