-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathahist.py
70 lines (60 loc) · 2.08 KB
/
ahist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from __future__ import print_function
import sys
import numpy as np
import matplotlib.pyplot as plt
from H5file import H5file
MIN = 1200
MAX = 3000
SCALE = 5
class Display:
strip = 64
strip_max = 512
pedestal = False
h5file = None
def __init__(self, h5file):
self.figure, self.axes = plt.subplots(1)
self.figure.canvas.mpl_connect('key_press_event', self.keyEvent)
self.h5file = h5file
self.showStrip()
plt.show()
def showStrip(self):
plt.cla()
if self.pedestal:
cut = self.h5file.pedestal['cut'][self.strip/256][self.strip%256]
else:
cut = MIN
self.figure.canvas.set_window_title(str(self.strip).zfill(3))
bins = np.arange(cut,MAX,SCALE)
mymax = MAX+(cut-MAX)%SCALE
print (cut,mymax)
hist = self.h5file.aggregate['hist'][self.strip][cut:mymax]
hist = hist.reshape(len(hist)/SCALE,SCALE)
hist = np.sum(hist,axis=1)
self.axes.bar(bins, hist, width=SCALE, color="blue", log=True)
plt.draw()
def keyEvent(self, event):
if event.key == 'right':
self.strip = (self.strip + 1) % self.strip_max
if event.key == 'left':
self.strip = (self.strip - 1) % self.strip_max
if event.key == 'up':
self.strip = (self.strip + 10) % self.strip_max
if event.key == 'down':
self.strip = (self.strip - 10) % self.strip_max
if event.key == 'pageup':
self.strip = (self.strip + 100) % self.strip_max
if event.key == 'pagedown':
self.strip = (self.strip - 100) % self.strip_max
if event.key == 'p':
self.pedestal = not self.pedestal
self.showStrip()
if __name__ == '__main__':
plt.rcParams['keymap.xscale'] = ''
plt.rcParams['keymap.yscale'] = ''
plt.rcParams['keymap.pan'] = ''
plt.rcParams['keymap.save'] = ''
plt.rcParams['keymap.fullscreen'] = ''
h5file = H5file(sys.argv[1])
h5file.readPedestal()
h5file.readAggregate()
display = Display(h5file)