#!/usr/bin/python -tt # ******************************** # Test script for the CalFits class # # written by Thomas Kraehenbuehl, ETH Zurich # tpk@phys.ethz.ch, +41 44 633 3973 # April 2012 # ******************************** # # modified and adapted py Patrick Vogler # # ################################ from ROOT import gSystem gSystem.Load("calfactfits_h.so") # according to new naming scheme from ROOT import * outfile = open(r'LP_template.txt','w') # file where the template is written to infile = open(r'FACTmapV6a.txt','r') # read in the FACT mapping file ############################################## # Test: read from a file def file_read(): # open file test1.txt infile = open('/home/pavogler/Python/test1.txt','r') # read lines from the file line1 = infile.readline() line2 = infile.readline() line3 = infile.readline() # strip the \n from each string line1 = line1.rstrip('\n') line2 = line2.rstrip('\n') line3 = line3.rstrip('\n') # close the file infile.close text = 'base sample test' text.split()[0][0] >>> b ############################################ #define filenames # 2012 04 17 #calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz' # NROI 300, pedestal #calibfilename = '/fact/raw/2012/04/17/20120417_033.drs.fits.gz' # NROI 300, pedestal calibfilename = '/fact/raw/2012/06/01/20120601_013.drs.fits.gz' # NROI 300, pedestal #datafilename = '/fact/raw/2012/04/17/20120417_015.fits.gz' # NROI 300, LP_ext #datafilename = '/fact/raw/2012/04/17/20120417_021.fits.gz' # NROI 300, LP_ext #datafilename = '/fact/raw/2012/04/17/20120417_036.fits.gz' # NROI 300, LP_ext #datafilename = '/fact/raw/2012/04/17/20120417_042.fits.gz' # NROI 300, LP_ext datafilename = '/fact/raw/2012/06/01/20120601_017.fits.gz' # NROI 300, 5 minutes physics data with # interleaved LP_ext import numpy as np from scipy import weave from scipy.weave import converters from plotters import Plotter # ADC display #from plotters import CamPlotter # event display #from drs_spikes import DRSSpikes print "Testing object creation: " caltest = CalFactFits(datafilename, calibfilename) npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi) caltest.SetNpcaldataPtr(npcalevent) numroi = np.int64(caltest.nroi) numpix = np.int64(caltest.npix) numevents = np.int64(caltest.nevents) num_LP_ev = 0 # number of ext Lightpulser events num_ped = 0 # number of pedestal events print "Common variables run information: " print "ROI: ", numroi print "#Pix: ", numpix print "Number of events: ", numevents print event = np.zeros((numpix, numroi)) # create an array to store an event in the format numpix * numroi (2-dim array) run_average = np.zeros((numpix, numroi)) # create an array to store the "average event" of a run data_average_run = np.zeros(numroi) print "... looping..." while caltest.GetCalEvent(): # Loop ueber alle events # print npcalevent ## Daten, Array 1 dim Laenge caltest.npix * caltest.nroi 1 Event if ((caltest.event_triggertype > 256) and (caltest.event_triggertype < 512)): #ext LP event print 'event id:', caltest.event_id, ' Trigger Type:', caltest.event_triggertype num_LP_ev = num_LP_ev + 1 event = np.reshape(npcalevent, (numpix, -1)) # bring the event the shape numpix * numroi (2-dim array) run_average += event if(num_LP_ev==10): # just for testing, not to read the whole file break headerline = infile.readline() while not '#' in headerline: headerline = infile.readline() for i in range (0, (numpix - 1) ): # if (()and()and()and()and()and()) data_average_run += run_average[i] del caltest print "caltest deleted " print "Common variables run information: " print "ROI: ", numroi print "#Pix: ", numpix print "Number of events: ", numevents print "Number of external Lightpulser events: ", num_LP_ev print ##################################################################################################################### #make a Plotter class ... this is an easy way for plotting ... but there are # many was to plot data ... without this class ... it was written for convenience, but there is no strong reason to use it... #myplotter = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV') myplotter2 = Plotter('titel of the plot', xlabel='time in slices', ylabel='amplitude calibrated data ... in mV') ################################################################################################################### myplotter2( data_average_run / (numpix * num_LP_ev) , 'average signal (all pixel) over the whole run' ) outfile.write('This file contains a template of the Lightpulser pulse, i.e. an average of one file. \n') outfile.write('data file: ' + str(datafilename) + '\n') outfile.write('DRS calib file: ' + str(calibfilename) + '\n') outfile.write('Number of Lightpulser events in this run: ' + str(num_LP_ev) + '\n') outfile.write('ROI: ' + str(numroi) + '\n') outfile.write('\n') outfile.write('slice signal [mV] \n') outfile.write('\n') for k in range(0,(numroi)): outfile.write( str(k) + ' ' + str((data_average_run[k])/(10 * num_LP_ev)) + '\n') outfile.close answer = raw_input('type "quit" to quit ') while not 'quit' in answer: answer = raw_input('type "quit" to quit ')