source: fact/tools/pyscripts/sandbox/dneise/trigger_studies/ftu.py@ 17893

Last change on this file since 17893 was 13146, checked in by neise, 13 years ago
enabled tab checking and excahnged python_rename with python
  • Property svn:executable set to *
File size: 4.0 KB
Line 
1#!/usr/bin/python -itt
2#
3# Dominik Neise
4#
5from pyfact import RawData
6import os.path
7import matplotlib.pyplot as plt
8import numpy as np
9from fir_filter import *
10from extractor import *
11from drs_spikes import *
12from plotters import *
13import sys
14confirm_next_step = True # this is for user interaction
15
16
17data_file_name = '/media/daten_platte/FACT/data/20120305_021.fits.gz'
18calib_file_name = '/media/daten_platte/FACT/data/20120305_005.drs.fits.gz'
19if not os.path.isfile(data_file_name):
20 print 'not able to find file:', data_file_name
21 sys.exit(-1)
22if not os.path.isfile(calib_file_name ):
23 print 'not able to find file:', calib_file_name
24 sys.exit(-1)
25
26run = RawData(data_file_name, calib_file_name)
27despike = DRSSpikes()
28
29# according to Ulf Roeser, the clipping cable is about 5ns long and damps reflection by about 0.9
30clipping = CFD( length=20, ratio=0.9)
31
32thresholds = range(200, 1001, 100)
33plotter =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
37tots = []
38for 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
111tots = np.array(tots)
112tots_over_1ns = (tots > 2).sum(axis=0)
113plotter(tots_over_1ns)
Note: See TracBrowser for help on using the repository browser.