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, range=(30,250) , name = 'GlobalMaxFinder'):
|
---|
17 | """ initialize search Window
|
---|
18 |
|
---|
19 | """
|
---|
20 | self.min = range[0]
|
---|
21 | self.max = range[1]
|
---|
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) = (' + self.min + ',' + 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, range=(55,105) , name = 'FixedWindowIntegrator'):
|
---|
41 | """ initialize integration Window
|
---|
42 | """
|
---|
43 | self.min = range[0]
|
---|
44 | self.max = range[1]
|
---|
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) = (' + self.min + ',' + 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 | else if (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 | time = (pix_data[i+1]*i-pix_data[i]*(i+1))
|
---|
85 | hits.append(time)
|
---|
86 | all_hits.append(hits)
|
---|
87 | return all_hits
|
---|
88 |
|
---|
89 | def __str__(self):
|
---|
90 | s = self.name + '\n'
|
---|
91 | if (self.slope == 1):
|
---|
92 | s += 'search for rising edge crossing.\n'
|
---|
93 | else:
|
---|
94 | s += 'search for falling edge crossing.\n'
|
---|
95 | return s
|
---|
96 |
|
---|