-
Notifications
You must be signed in to change notification settings - Fork 1
/
fdrallplot.py
56 lines (43 loc) · 1.53 KB
/
fdrallplot.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
import sys
import os
from matplotlib import pyplot as plt
import numpy as np
files = list(sorted(sys.argv[1:]))
fig, ax = plt.subplots(num='fdrallplot', clear=True)
ax.set_xlabel('Threshold [Filter output sdev]')
ax.set_ylabel('Rate [cps]')
for ifile, file in enumerate(files):
with np.load(file) as arch:
thr = arch['thr']
thrcounts = arch['thrcounts']
thr_theory = arch['thr_theory']
thrcounts_theory = arch['thrcounts_theory']
effnsamples = arch['effnsamples']
nevents = arch['nevents']
freq = arch['freq']
sdev = arch['sdev']
nz = np.flatnonzero(thrcounts)
start = max(0, nz[0] - 1)
end = min(len(thr), nz[-1] + 2)
s = slice(start, end)
ratefactor = freq / (nevents * effnsamples)
cond = thr_theory >= np.min(thr)
cond &= thr_theory <= np.max(thr)
cond &= thrcounts_theory >= np.min(thrcounts[thrcounts > 0])
label = os.path.split(file)[1].replace('.npz', '')
kw = dict(color=f'C{ifile}')
ax.plot(thr_theory[cond] / sdev, ratefactor * thrcounts_theory[cond], '-', **kw)
ax.plot(thr[s] / sdev, ratefactor * thrcounts[s], '.--', label=label, **kw)
if len(files) <= 6:
fontsize = 'medium'
elif len(files) <= 10:
fontsize = 'small'
else:
fontsize = 'x-small'
ax.legend(fontsize=fontsize)
ax.set_yscale('log')
ax.minorticks_on()
ax.grid(True, 'major', linestyle='--')
ax.grid(True, 'minor', linestyle=':')
fig.tight_layout()
fig.show()