1 | #!/usr/bin/python
|
---|
2 |
|
---|
3 | from pyfact import RawData
|
---|
4 | from pylab import *
|
---|
5 | import numpy as np
|
---|
6 | from scipy import *
|
---|
7 | import os.path
|
---|
8 | from coor import Coordinator
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 | class EventBrowser:
|
---|
13 |
|
---|
14 | def __init__(self, run, nevents = 100):
|
---|
15 | map_file_path = '../../map_dn.txt'
|
---|
16 | path = os.path.abspath(__file__)
|
---|
17 | path = os.path.dirname(path)
|
---|
18 | map_file_path = os.path.join(path, map_file_path)
|
---|
19 | if not os.path.isfile(map_file_path):
|
---|
20 | print 'not able to find file:', map_file_path
|
---|
21 | sys.exit(-2)
|
---|
22 |
|
---|
23 | chid, y,x,ye,xe,yh,xh,softid,hardid = np.loadtxt(map_file_path ,unpack=True)
|
---|
24 | self.xe = xe
|
---|
25 | self.ye = ye
|
---|
26 | self.H = (6,0,30./180.*3.1415926)
|
---|
27 | self.H = (6,0,0)
|
---|
28 |
|
---|
29 | self.coor = Coordinator()
|
---|
30 |
|
---|
31 | self.run = run
|
---|
32 |
|
---|
33 | self.event = run.next()
|
---|
34 | self.nevents = nevents
|
---|
35 |
|
---|
36 | self.fig = figure(figsize=(6, 8), dpi=80)
|
---|
37 | self.axup = self.fig.add_axes([0.1,0.3,0.8,0.6])
|
---|
38 |
|
---|
39 |
|
---|
40 | self.axdn = self.fig.add_axes([0.1,0.,0.8,0.25])
|
---|
41 | self.axup.grid(True)
|
---|
42 | data = np.zeros(1440)
|
---|
43 | result = self.axup.scatter(xe,ye,s=38,alpha=1,
|
---|
44 | c=data, marker=self.H, linewidths=1.)
|
---|
45 | self.axup.axis([-21,21,-21,21])
|
---|
46 |
|
---|
47 |
|
---|
48 | #qself.axdn = self.fig.add_subplot(212)
|
---|
49 |
|
---|
50 | self.fig.canvas.mpl_connect('key_press_event', self.onpress)
|
---|
51 | self.fig.canvas.mpl_connect('button_press_event', self.onclick)
|
---|
52 |
|
---|
53 |
|
---|
54 | self.axdn.set_axis_off()
|
---|
55 |
|
---|
56 | text = "Event Browser, press 'n' iterate over the events.\n"
|
---|
57 | text += "Event id: 0\n"
|
---|
58 | text += "Trigger type: 0"
|
---|
59 |
|
---|
60 | self.axdn.annotate(text, (0.01, 0.5),
|
---|
61 | xycoords="axes fraction", va="center", ha="left",
|
---|
62 | bbox=dict(boxstyle="round, pad=1", fc="w"))
|
---|
63 |
|
---|
64 | setp(self.axdn.get_xticklabels(), visible=False)
|
---|
65 | setp(self.axdn.get_yticklabels(), visible=False)
|
---|
66 |
|
---|
67 | def onclick(self, button_press_event):
|
---|
68 |
|
---|
69 | self.axdn.cla()
|
---|
70 | self.axdn.set_axis_off()
|
---|
71 |
|
---|
72 | euc2chid = self.coor.euc2chid
|
---|
73 | pixel_centers = euc2chid.keys()
|
---|
74 |
|
---|
75 | mouse = (button_press_event.xdata, button_press_event.ydata)
|
---|
76 |
|
---|
77 | diffs = np.zeros(len(pixel_centers))
|
---|
78 | for i,pixel in enumerate(pixel_centers):
|
---|
79 | diffs[i]= np.sqrt((mouse[0]-pixel[0])**2 + (mouse[1]-pixel[1])**2)
|
---|
80 |
|
---|
81 | chid = euc2chid[pixel_centers[np.argmin(diffs)]]
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | text = "Event Browser, press 'n' iterate over the events.\n"
|
---|
86 | text += "Event id: 0\n"
|
---|
87 | text += "Trigger type: 0"
|
---|
88 | text += '\nx' + str(button_press_event.xdata) + ' '
|
---|
89 | text += 'y' + str(button_press_event.ydata) + ' '
|
---|
90 | text += 'inaxes' + str(button_press_event.inaxes) + ' '
|
---|
91 | text += 'chid' + str(chid) + ' '
|
---|
92 |
|
---|
93 | text += 'button' + str(button_press_event.button)
|
---|
94 |
|
---|
95 |
|
---|
96 | print button_press_event
|
---|
97 |
|
---|
98 |
|
---|
99 | self.axdn.annotate(text, (0.01, 0.5),
|
---|
100 | xycoords="axes fraction", va="center", ha="left",
|
---|
101 | bbox=dict(boxstyle="round, pad=1", fc="w"))
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 | self.fig.canvas.draw()
|
---|
106 | show()
|
---|
107 |
|
---|
108 |
|
---|
109 | def onpress(self, event):
|
---|
110 | 'define some key press events'
|
---|
111 |
|
---|
112 | if self.event['event_id'] > self.nevents: return
|
---|
113 |
|
---|
114 | if event.key in ('q','Q'): sys.exit()
|
---|
115 |
|
---|
116 | if event.key not in ('n', 'p'): return
|
---|
117 | if event.key=='n':
|
---|
118 | self.event = self.run.next()
|
---|
119 | else:
|
---|
120 | print "Sorry I cannot go back!"
|
---|
121 | return
|
---|
122 |
|
---|
123 |
|
---|
124 | #self.ax.cla()
|
---|
125 | #self.ax.set_axis_off()
|
---|
126 |
|
---|
127 | text = "Event Browser, press 'n' in this window to iterate over the events.\nEvent id: "+str(self.event['event_id'])
|
---|
128 | text = text + "\nTrigger type: "+str(self.event['trigger_type'])
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 | #self.ax.annotate(text, (0.01, 0.5),
|
---|
133 | # xycoords="axes fraction", va="center", ha="left",
|
---|
134 | # bbox=dict(boxstyle="round, pad=1", fc="w"))
|
---|
135 |
|
---|
136 | self.update()
|
---|
137 |
|
---|
138 | def update(self):
|
---|
139 |
|
---|
140 | if self.event['event_id'] > self.nevents: return
|
---|
141 |
|
---|
142 | dataind = self.event['event_id']
|
---|
143 |
|
---|
144 | # put a user function in here!
|
---|
145 | self.userfunc(dataind)
|
---|
146 |
|
---|
147 | self.fig.canvas.draw()
|
---|
148 | show()
|
---|
149 |
|
---|
150 | def userfunc(self,dataind):
|
---|
151 | print 'No userfunc defined'
|
---|
152 | pass
|
---|
153 |
|
---|
154 |
|
---|
155 | #event = run.next()
|
---|
156 |
|
---|
157 | if __name__ == '__main__':
|
---|
158 | datafilepath = '/fact/raw/2012/06/05/20120605_016.fits.gz'
|
---|
159 | calibfilepath = '/fact/raw/2012/06/05/20120605_012.drs.fits.gz'
|
---|
160 | run = RawData(datafilepath, calibfilepath)
|
---|
161 |
|
---|
162 | if len(sys.argv) < 2:
|
---|
163 | print "Usage: testFFT.py pixelID neventsmax"
|
---|
164 | sys.exit()
|
---|
165 |
|
---|
166 | pixelID = int(sys.argv[1])
|
---|
167 | neventsmax = int(sys.argv[2])
|
---|
168 |
|
---|
169 | eb = EventBrowser(run, neventsmax)
|
---|
170 |
|
---|
171 |
|
---|
172 | def PlotFFT(dataind):
|
---|
173 |
|
---|
174 | fig2 = figure(2, figsize=(10, 8))
|
---|
175 |
|
---|
176 | ax1= fig2.add_subplot(311)
|
---|
177 | ax2 = fig2.add_subplot(312)
|
---|
178 | ax3 = fig2.add_subplot(313)
|
---|
179 |
|
---|
180 | ax1.cla()
|
---|
181 | ax2.cla()
|
---|
182 | ax3.cla()
|
---|
183 |
|
---|
184 | ax1.grid()
|
---|
185 | ax2.grid()
|
---|
186 | ax3.grid()
|
---|
187 |
|
---|
188 | x_drs = np.arange(0, 300, 1)
|
---|
189 | data = eb.event['data']
|
---|
190 | drsdata = data[pixelID]
|
---|
191 | ft = fft(drsdata)
|
---|
192 | ax1.plot(x_drs, data[0])
|
---|
193 |
|
---|
194 | ax2.plot(x_drs, ft)
|
---|
195 |
|
---|
196 | invdata = ifft(ft)
|
---|
197 |
|
---|
198 | ax3.plot(x_drs, invdata)
|
---|
199 | ax3.set_xlabel("DRS counts")
|
---|
200 |
|
---|
201 |
|
---|
202 |
|
---|
203 | fig2.canvas.draw()
|
---|
204 |
|
---|
205 |
|
---|
206 | eb.userfunc = PlotFFT
|
---|
207 |
|
---|
208 | show()
|
---|
209 |
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 |
|
---|
214 |
|
---|