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