-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemps1series0213plot.py
144 lines (117 loc) · 4.67 KB
/
temps1series0213plot.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import numpy as np
from matplotlib import pyplot as plt
from scipy import interpolate
import textbox
inphotons = 2 # in [3, 7, 10, 15, 20, 30, 40]
idcr = 1 # in [25, 250] cps/pdm
rate = 100 # cps
table = np.load('temps1series0213.npy')
figkw = dict(clear=True, sharex=True, figsize=[9, 7])
figs = []
axs = []
for wname in ['efficiency', 'fakerate', 'effvsrate', 'effvssigma']:
figkw['sharey'] = 'col' if wname == 'effvsrate' else True
fig, ax = plt.subplots(2, 2, num=f'temps1series0213plot-{wname}', **figkw)
figs.append(fig)
axs.append(ax)
axs = np.array(axs)
for ax in axs[0].reshape(-1):
if ax.is_first_col():
ax.set_ylabel('S1 detection efficiency')
if ax.is_last_row():
ax.set_xlabel('Threshold on filter output')
for ax in axs[1].reshape(-1):
if ax.is_first_col():
ax.set_ylabel('Fake rate [cps]')
if ax.is_last_row():
ax.set_xlabel('Threshold on filter output')
for ax in axs[2].reshape(-1):
if ax.is_first_col():
ax.set_ylabel('S1 detection efficiency')
if ax.is_last_row():
ax.set_xlabel('Fake rate [cps]')
for ax in axs[3].reshape(-1):
if ax.is_first_col():
ax.set_ylabel(f'Efficiency at fake rate {rate} cps')
if ax.is_last_row():
ax.set_xlabel('Template $\\sigma$ [ns]')
# the shape of table is over (DCR, VL, nphotons, sigma)
for ivl in range(table.shape[1]):
entries = table[idcr, ivl]
if np.count_nonzero(entries['done']) == 0:
continue
for ifilter, fname in enumerate(['ER', 'NR']):
qax = axs[:, ifilter, ivl]
for ifig, ax in enumerate(qax):
for inph, entry in enumerate(entries):
if not np.any(entry['done']) or ifig != 3:
continue
entry = entry[entry['done']]
nph = entry[0]['parameters']['nphotons']
plotkw = dict(
alpha=(inph + 1) / len(entries),
color='#600',
label=f'{nph}',
linestyle=['-', '--', '-.', ':'][inph % 4],
)
x = entry['parameters']['sigma']
interpkw = dict(assume_sorted=True, copy=False)
y = [
interpolate.interp1d(subent['rate'], subent[fname]['efficiency'], **interpkw)(rate)
for subent in entry
]
ax.plot(x, y, **plotkw)
for isigma, entry in enumerate(entries[inphotons]):
if not entry['done'] or ifig == 3:
continue
sigma = entry['parameters']['sigma']
plotkw = dict(
alpha=(isigma + 1) / len(entries[inphotons]),
color='#600',
label=f'{sigma:.3g}',
linestyle=['-', '--', '-.', ':'][isigma % 4],
)
if ifig == 0:
x = entry['threshold']
y = entry[fname]['effthr']
elif ifig == 1:
x = entry['threshold']
y = entry[fname]['ratethr']
elif ifig == 2:
x = entry['rate']
y = entry[fname]['efficiency']
changepoint = np.flatnonzero(np.diff(y))
start = max(0 , changepoint[ 0] - 1)
end = min(len(y), changepoint[-1] + 3)
sel = slice(start, end)
x = x[sel]
y = y[sel]
ax.plot(x, y, **plotkw)
for ax in qax:
s1type = 'ER' if entries[0, 0]['parameters']['VL'] < 1 else 'NR'
ax.set_title(f'{s1type} S1, {fname} filter')
ax.minorticks_on()
ax.grid(True, which='major', linestyle='--')
ax.grid(True, which='minor', linestyle=':')
for ifig, fax in enumerate(axs):
if ifig == 3:
legendtitle = 'Nphotons'
else:
legendtitle = 'Template $\\sigma$ [ns]'
fax[0, 0].legend(loc='best', fontsize='small', ncol=2, title=legendtitle)
params = table[idcr, 0, inphotons, 0]['parameters']
info = f"""\
DCR = {params['DCR'] * 1e9:.3g} cps/pdm
tres = 10 ns
nevents = 1000"""
if ifig != 3:
info = f"nphotons = {params['nphotons']}\n" + info
infoheight = 'lower' if ifig in [2, 3] else 'upper'
textbox.textbox(fax[0, 1], info, loc=f'{infoheight} right', fontsize='small')
if ifig == 1:
fax[0, 0].set_yscale('log')
if ifig == 2:
fax[0, 0].set_xscale('log')
for fig in figs:
fig.tight_layout()
fig.show()