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