| 1 | #!/usr/bin/python
|
|---|
| 2 | #
|
|---|
| 3 | # Dominik Neise
|
|---|
| 4 | #
|
|---|
| 5 | from pyfact_rename import *
|
|---|
| 6 | import os.path
|
|---|
| 7 | import matplotlib.pyplot as plt
|
|---|
| 8 | import numpy as np
|
|---|
| 9 | from fir_filter import *
|
|---|
| 10 | from extractor import *
|
|---|
| 11 | from drs_spikes import *
|
|---|
| 12 | from plotters import *
|
|---|
| 13 | import sys
|
|---|
| 14 | confirm_next_step = True # this is for user interaction
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | data_file_name = '/media/daten_platte/FACT/data/20120305_022.fits.gz'
|
|---|
| 18 | calib_file_name = '/media/daten_platte/FACT/data/20120305_005.drs.fits.gz'
|
|---|
| 19 | run = RawData(data_file_name, calib_file_name)
|
|---|
| 20 | despike = DRSSpikes()
|
|---|
| 21 |
|
|---|
| 22 | # according to Ulf Roeser, the clipping cable is about 5ns long and damps reflection by about 0.9
|
|---|
| 23 | clipping = CFD( length=20, ratio=0.9)
|
|---|
| 24 |
|
|---|
| 25 | thresholds = range(100, 1001, 20)
|
|---|
| 26 | plotter =Plotter('time_over_thr', x=thresholds, xlabel='FTU threshold [DAC units]', ylabel='Board time over threshold[slices]')
|
|---|
| 27 |
|
|---|
| 28 | # addiere immer 9 pixel
|
|---|
| 29 | for data, scell, tt in run:
|
|---|
| 30 | data = despike(data)
|
|---|
| 31 | event_id = run.event_id.value
|
|---|
| 32 | #print 'event# : ' , run.event_id.value
|
|---|
| 33 | # print 'data.shape', data.shape
|
|---|
| 34 | #prepare placeholder for the input of the comparator
|
|---|
| 35 | ftu_comp_in = np.empty( (data.shape[0]/9, data.shape[1]-20), dtype='float64' )
|
|---|
| 36 | # print 'ftu_comp_in.shape', ftu_comp_in.shape
|
|---|
| 37 |
|
|---|
| 38 | #prepare space for the compartor output for all thresholds under test
|
|---|
| 39 | ftu_comp_out_shape = (len(thresholds), ftu_comp_in.shape[0]/4 , ftu_comp_in.shape[1])
|
|---|
| 40 | ftu_comp_out = np.empty( ftu_comp_out_shape, dtype=bool)
|
|---|
| 41 | # print 'ftu_comp_out.shape', ftu_comp_out.shape
|
|---|
| 42 |
|
|---|
| 43 | time_over_thr = np.empty( (len(thresholds), ftu_comp_in.shape[0]/4),dtype=int)
|
|---|
| 44 | # print 'time_over_thr.shape', time_over_thr.shape
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | for begin in range(0,data.shape[0],9):
|
|---|
| 49 | patch_sig = np.sum(data[begin:begin+9,10:-10],axis=0)
|
|---|
| 50 |
|
|---|
| 51 | # scaling signal as it should be in front of the comparator
|
|---|
| 52 | # factors are according to poster of Olli
|
|---|
| 53 | # EPS_HEP-Electronics.pdf ... I did not check the numbers again
|
|---|
| 54 | # factor between DRS and U1A
|
|---|
| 55 | patch_sig /=-2
|
|---|
| 56 | # from U1A to comparator
|
|---|
| 57 | patch_sig *= 1./5.4 * 4.5 * -1. * 0.5 * 4.5 * 0.9
|
|---|
| 58 |
|
|---|
| 59 | # in order to understand the FTU treschold a little better
|
|---|
| 60 | # I scale the voltages to FTU DAC counts: 12bits @ 2.5Volts
|
|---|
| 61 | patch_sig *= 1./2500 * 2**12
|
|---|
| 62 | #now clipping is applied.
|
|---|
| 63 | patch_sig = -1*clipping(patch_sig)
|
|---|
| 64 |
|
|---|
| 65 | #store patch signal
|
|---|
| 66 | ftu_comp_in[begin/9] = patch_sig
|
|---|
| 67 |
|
|---|
| 68 | # print 'checking for thresholds'
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | for thr_id,thr in enumerate(thresholds):
|
|---|
| 72 |
|
|---|
| 73 | for board_id in range(len(ftu_comp_in)/4):
|
|---|
| 74 | patch_comp_out = np.zeros( ftu_comp_out.shape[2], dtype=bool )
|
|---|
| 75 | for patch_id in range(4):
|
|---|
| 76 | # OR the 4 patch outs together
|
|---|
| 77 | patch_comp_out += ftu_comp_in[4*board_id+patch_id] > thr
|
|---|
| 78 | # print 'thr_id', thr_id
|
|---|
| 79 | # print 'board_id', board_id
|
|---|
| 80 | # print 'ftu_comp_out[thr_id][board_id].shape', ftu_comp_out[thr_id][board_id].shape
|
|---|
| 81 | # print 'patch_comp_out.shape', patch_comp_out.shape
|
|---|
| 82 | ftu_comp_out[thr_id][board_id]=patch_comp_out
|
|---|
| 83 | time_over_thr[thr_id][board_id]=patch_comp_out.sum()
|
|---|
| 84 |
|
|---|
| 85 | # really bad coding here:
|
|---|
| 86 | # the path is hardcoded,
|
|---|
| 87 | # and if the path does no exist, it is not created automatically
|
|---|
| 88 | # both is very bad
|
|---|
| 89 | #
|
|---|
| 90 | # anyway if you want to save the plots to file ... just comment this in
|
|---|
| 91 | # and give some nice filename ...
|
|---|
| 92 | #plotter.fname='./20120305_022/_'+str(event_id) + '.png'
|
|---|
| 93 |
|
|---|
| 94 | plotter.name='time over thr, for all boards | Evt ID = ' + str(event_id)
|
|---|
| 95 | plotter(np.transpose(time_over_thr))
|
|---|
| 96 |
|
|---|
| 97 | print 'event# : ' , event_id,
|
|---|
| 98 |
|
|---|
| 99 | if confirm_next_step:
|
|---|
| 100 | user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
|
|---|
| 101 | if user_input.find('q') != -1:
|
|---|
| 102 | sys.exit(0)
|
|---|
| 103 | elif user_input.find('r') != -1:
|
|---|
| 104 | confirm_next_step = False
|
|---|
| 105 |
|
|---|