1 | #!/usr/bin/python -itt
|
---|
2 | #
|
---|
3 | # Dominik Neise
|
---|
4 | #
|
---|
5 | from pyfact import RawData
|
---|
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_021.fits.gz'
|
---|
18 | calib_file_name = '/media/daten_platte/FACT/data/20120305_005.drs.fits.gz'
|
---|
19 | if not os.path.isfile(data_file_name):
|
---|
20 | print 'not able to find file:', data_file_name
|
---|
21 | sys.exit(-1)
|
---|
22 | if not os.path.isfile(calib_file_name ):
|
---|
23 | print 'not able to find file:', calib_file_name
|
---|
24 | sys.exit(-1)
|
---|
25 |
|
---|
26 | run = RawData(data_file_name, calib_file_name)
|
---|
27 | despike = DRSSpikes()
|
---|
28 |
|
---|
29 | # according to Ulf Roeser, the clipping cable is about 5ns long and damps reflection by about 0.9
|
---|
30 | clipping = CFD( length=20, ratio=0.9)
|
---|
31 |
|
---|
32 | thresholds = range(200, 1001, 100)
|
---|
33 | plotter =Plotter('time_over_thr : 20120305_021', x=thresholds, xlabel='FTU threshold [DAC units]', ylabel='# events, which would have been triggered')
|
---|
34 |
|
---|
35 |
|
---|
36 | # add up 9 pixels
|
---|
37 | tots = []
|
---|
38 | for data, scell, tt in run:
|
---|
39 | data = despike(data)
|
---|
40 | event_id = run.event_id.value
|
---|
41 | #print 'event# : ' , run.event_id.value
|
---|
42 | # print 'data.shape', data.shape
|
---|
43 | #prepare placeholder for the input of the comparator
|
---|
44 | ftu_comp_in = np.empty( (data.shape[0]/9, data.shape[1]-20), dtype='float64' )
|
---|
45 | # print 'ftu_comp_in.shape', ftu_comp_in.shape
|
---|
46 |
|
---|
47 | #prepare space for the compartor output for all thresholds under test
|
---|
48 | ftu_comp_out_shape = (len(thresholds), ftu_comp_in.shape[0]/4 , ftu_comp_in.shape[1])
|
---|
49 | ftu_comp_out = np.empty( ftu_comp_out_shape, dtype=bool)
|
---|
50 | # print 'ftu_comp_out.shape', ftu_comp_out.shape
|
---|
51 |
|
---|
52 | time_over_thr = np.empty( (len(thresholds), ftu_comp_in.shape[0]/4),dtype=int)
|
---|
53 | # print 'time_over_thr.shape', time_over_thr.shape
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | for begin in range(0,data.shape[0],9):
|
---|
58 | patch_sig = np.sum(data[begin:begin+9,10:-10],axis=0)
|
---|
59 |
|
---|
60 | # scaling signal as it should be in front of the comparator
|
---|
61 | # factors are according to poster of Olli
|
---|
62 | # EPS_HEP-Electronics.pdf ... I did not check the numbers again
|
---|
63 | # factor between DRS and U1A
|
---|
64 | patch_sig /=-2
|
---|
65 | # from U1A to comparator
|
---|
66 | patch_sig *= 1./5.4 * 4.5 * -1. * 0.5 * 4.5 * 0.9
|
---|
67 |
|
---|
68 | # in order to understand the FTU treschold a little better
|
---|
69 | # I scale the voltages to FTU DAC counts: 12bits @ 2.5Volts
|
---|
70 | patch_sig *= 1./2500 * 2**12
|
---|
71 | #now clipping is applied.
|
---|
72 | patch_sig = -1*clipping(patch_sig)
|
---|
73 |
|
---|
74 | #store patch signal
|
---|
75 | ftu_comp_in[begin/9] = patch_sig
|
---|
76 |
|
---|
77 | # print 'checking for thresholds'
|
---|
78 |
|
---|
79 |
|
---|
80 | for thr_id,thr in enumerate(thresholds):
|
---|
81 |
|
---|
82 | for board_id in range(len(ftu_comp_in)/4):
|
---|
83 | patch_comp_out = np.zeros( ftu_comp_out.shape[2], dtype=bool )
|
---|
84 | for patch_id in range(4):
|
---|
85 | # OR the 4 patch outs together
|
---|
86 | patch_comp_out += ftu_comp_in[4*board_id+patch_id] > thr
|
---|
87 | # print 'thr_id', thr_id
|
---|
88 | # print 'board_id', board_id
|
---|
89 | # print 'ftu_comp_out[thr_id][board_id].shape', ftu_comp_out[thr_id][board_id].shape
|
---|
90 | # print 'patch_comp_out.shape', patch_comp_out.shape
|
---|
91 | ftu_comp_out[thr_id][board_id]=patch_comp_out
|
---|
92 |
|
---|
93 | # now we have the output of the comparator on each FTU.
|
---|
94 | # we need to AND these values, in order get the answer of FTM in case of
|
---|
95 | # coincidence 40/40 is requested.
|
---|
96 | tot = []
|
---|
97 | for at_certain_thr in ftu_comp_out:
|
---|
98 | tot.append(at_certain_thr.prod(axis=0).sum())
|
---|
99 | tots.append(tot)
|
---|
100 | print 'event# : ' , event_id
|
---|
101 |
|
---|
102 | if confirm_next_step:
|
---|
103 | user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
|
---|
104 | if user_input.find('q') != -1:
|
---|
105 | sys.exit(0)
|
---|
106 | elif user_input.find('r') != -1:
|
---|
107 | confirm_next_step = False
|
---|
108 | elif user_input.find('e') != -1:
|
---|
109 | sys.exit(0)
|
---|
110 |
|
---|
111 | tots = np.array(tots)
|
---|
112 | tots_over_1ns = (tots > 2).sum(axis=0)
|
---|
113 | plotter(tots_over_1ns)
|
---|