1 | #!/usr/bin/python
|
---|
2 | #
|
---|
3 | # Dominik Neise, Werner Lustermann
|
---|
4 | # TU Dortmund, ETH Zurich
|
---|
5 | #
|
---|
6 | import numpy as np
|
---|
7 | import matplotlib.pyplot as plt
|
---|
8 | #import * from fir_filter
|
---|
9 |
|
---|
10 | class GlobalMaxFinder(object):
|
---|
11 | """ Pulse Extractor
|
---|
12 | Finds the global maximum in the given window.
|
---|
13 | (Best used with filtered data)
|
---|
14 | """
|
---|
15 |
|
---|
16 | def __init__(self, min=30, max=250 , name = 'GlobalMaxFinder'):
|
---|
17 | """ initialize search Window
|
---|
18 |
|
---|
19 | """
|
---|
20 | self.min = min
|
---|
21 | self.max = max
|
---|
22 | self.name = name
|
---|
23 |
|
---|
24 | def __call__(self, data):
|
---|
25 | time = np.argmax( data[ : , self.min:self.max ], 1)
|
---|
26 | amplitude = np.max( data[ : , self.min:self.max], 1)
|
---|
27 | return amplitude, time
|
---|
28 |
|
---|
29 | def __str__(self):
|
---|
30 | s = self.name + '\n'
|
---|
31 | s += 'window:\n'
|
---|
32 | s += '(min,max) = (' + str(self.min) + ',' + str(self.max) + ')\n'
|
---|
33 | return s
|
---|
34 |
|
---|
35 |
|
---|
36 | class FixedWindowIntegrator(object):
|
---|
37 | """ Integrates in a given intergration window
|
---|
38 | """
|
---|
39 |
|
---|
40 | def __init__(self, min=55, max=105 , name = 'FixedWindowIntegrator'):
|
---|
41 | """ initialize integration Window
|
---|
42 | """
|
---|
43 | self.min = min
|
---|
44 | self.max = max
|
---|
45 | self.name = name
|
---|
46 |
|
---|
47 | def __call__(self, data):
|
---|
48 | integral = np.empty( data.shape[0] )
|
---|
49 | for pixel in range( data.shape[0] ):
|
---|
50 | integral[pixel] = data[pixel, self.min:self.max].sum()
|
---|
51 | return integtral
|
---|
52 |
|
---|
53 | def __str__(self):
|
---|
54 | s = self.name + '\n'
|
---|
55 | s += 'window:\n'
|
---|
56 | s += '(min,max) = (' + str(self.min) + ',' + str(self.max) + ')\n'
|
---|
57 | return s
|
---|
58 |
|
---|
59 | class ZeroXing(object):
|
---|
60 | """ Finds zero crossings in given data
|
---|
61 | (should be used on CFD output for peak finding)
|
---|
62 | returns list of lists of time_of_zero_crossing
|
---|
63 | """
|
---|
64 | def __init__(self, slope=1, name = 'ZeroXing'):
|
---|
65 | if (slope >= 0):
|
---|
66 | self.slope = 1 # search for rising edge crossing
|
---|
67 | elif (slope < 0):
|
---|
68 | self.slope = -1 # search for falling edge crossing
|
---|
69 | self.name = name
|
---|
70 |
|
---|
71 |
|
---|
72 | def __call__(self, data):
|
---|
73 | all_hits = []
|
---|
74 | for pix_data in data:
|
---|
75 | hits = []
|
---|
76 | for i in range( data.shape[1] ):
|
---|
77 | if ( slope > 0 ):
|
---|
78 | if ( pix_data[i] > 0 ):
|
---|
79 | continue
|
---|
80 | else:
|
---|
81 | if ( pix_data[i] < 0):
|
---|
82 | continue
|
---|
83 | if ( pix_data[i] * pix_data[i+1] <= 0 ):
|
---|
84 | # interpolate time of zero crossing with
|
---|
85 | # linear polynomial: y = ax + b
|
---|
86 | a = (pix_data[i+1] - pix_data[i]) / ((i+1) - i)
|
---|
87 | time = -1.0/a * pix_data[i] + i
|
---|
88 | hits.append(time)
|
---|
89 | all_hits.append(hits)
|
---|
90 | return all_hits
|
---|
91 |
|
---|
92 | def __str__(self):
|
---|
93 | s = self.name + '\n'
|
---|
94 | if (self.slope == 1):
|
---|
95 | s += 'search for rising edge crossing.\n'
|
---|
96 | else:
|
---|
97 | s += 'search for falling edge crossing.\n'
|
---|
98 | return s
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 | if __name__ == '__main__':
|
---|
103 | """ test the extractors """
|
---|
104 |
|
---|
105 | gmf = GlobalMaxFinder((12,40))
|
---|
106 | print gmf
|
---|
107 | fwi = FixedWindowIntegrator(1,3)
|
---|
108 | print fwi
|
---|
109 | zx = ZeroXing()
|
---|
110 | print zx |
---|