source: fact/tools/pyscripts/tools/trigger_studies/ftu_comparator_out.py@ 13146

Last change on this file since 13146 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 -tt
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_022.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(100, 1001, 20)
33plotter =Plotter('time_over_thr', x=thresholds, xlabel='FTU threshold [DAC units]', ylabel='Board time over threshold[slices]')
34
35# add up 9 pixels
36for data, scell, tt in run:
37 data = despike(data)
38 event_id = run.event_id.value
39 #print 'event# : ' , run.event_id.value
40# print 'data.shape', data.shape
41 #prepare placeholder for the input of the comparator
42 ftu_comp_in = np.empty( (data.shape[0]/9, data.shape[1]-20), dtype='float64' )
43# print 'ftu_comp_in.shape', ftu_comp_in.shape
44
45 #prepare space for the compartor output for all thresholds under test
46 ftu_comp_out_shape = (len(thresholds), ftu_comp_in.shape[0]/4 , ftu_comp_in.shape[1])
47 ftu_comp_out = np.empty( ftu_comp_out_shape, dtype=bool)
48# print 'ftu_comp_out.shape', ftu_comp_out.shape
49
50 time_over_thr = np.empty( (len(thresholds), ftu_comp_in.shape[0]/4),dtype=int)
51# print 'time_over_thr.shape', time_over_thr.shape
52
53
54
55 for begin in range(0,data.shape[0],9):
56 patch_sig = np.sum(data[begin:begin+9,10:-10],axis=0)
57
58 # scaling signal as it should be in front of the comparator
59 # factors are according to poster of Olli
60 # EPS_HEP-Electronics.pdf ... I did not check the numbers again
61 # factor between DRS and U1A
62 patch_sig /=-2
63 # from U1A to comparator
64 patch_sig *= 1./5.4 * 4.5 * -1. * 0.5 * 4.5 * 0.9
65
66 # in order to understand the FTU treschold a little better
67 # I scale the voltages to FTU DAC counts: 12bits @ 2.5Volts
68 patch_sig *= 1./2500 * 2**12
69 #now clipping is applied.
70 patch_sig = -1*clipping(patch_sig)
71
72 #store patch signal
73 ftu_comp_in[begin/9] = patch_sig
74
75# print 'checking for thresholds'
76
77
78 for thr_id,thr in enumerate(thresholds):
79
80 for board_id in range(len(ftu_comp_in)/4):
81 patch_comp_out = np.zeros( ftu_comp_out.shape[2], dtype=bool )
82 for patch_id in range(4):
83 # OR the 4 patch outs together
84 patch_comp_out += ftu_comp_in[4*board_id+patch_id] > thr
85# print 'thr_id', thr_id
86# print 'board_id', board_id
87# print 'ftu_comp_out[thr_id][board_id].shape', ftu_comp_out[thr_id][board_id].shape
88# print 'patch_comp_out.shape', patch_comp_out.shape
89 ftu_comp_out[thr_id][board_id]=patch_comp_out
90 time_over_thr[thr_id][board_id]=patch_comp_out.sum()
91
92 # really bad coding here:
93 # the path is hardcoded,
94 # and if the path does no exist, it is not created automatically
95 # both is very bad
96 #
97 # anyway if you want to save the plots to file ... just comment this in
98 # and give some nice filename ...
99 #plotter.fname='./20120305_022/_'+str(event_id) + '.png'
100
101 plotter.name='time over thr, for all boards | Evt ID = ' + str(event_id)
102 plotter(np.transpose(time_over_thr))
103
104 print 'event# : ' , event_id,
105
106 if confirm_next_step:
107 user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
108 if user_input.find('q') != -1:
109 sys.exit(0)
110 elif user_input.find('r') != -1:
111 confirm_next_step = False
112
Note: See TracBrowser for help on using the repository browser.