-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmonte_carlo_plots.py
428 lines (345 loc) · 21.1 KB
/
monte_carlo_plots.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/usr/bin/env python
import io
import pickle
import sys
import os
import random
import time
from functools import partial
from urllib import parse, request
import numpy as np
import scipy.stats as spstat
from collections import namedtuple
from astropy.time import Time
from astropy.coordinates import Distance
import astropy.table as at
import astropy.units as u, astropy.constants as c
import argparse
import matplotlib.pyplot as plt
from astropy.visualization import hist
import schwimmbad
from scipy.linalg import cholesky
import scipy.integrate as scinteg
from sklearn.preprocessing import MinMaxScaler
from sed_to_lc import SEDDerviedLC
from dns_mass_distribution import Galaudage21, Farrow19
import inspiral_range
import ligo.em_bright
import ligo.em_bright.computeDiskMass
from ligo.em_bright.computeDiskMass import computeCompactness, computeDiskMass
import lalsimulation as lalsim
from gwemlightcurves.EjectaFits import DiUj2017, KrFo2019
from kilopop.kilonovae import bns_kilonovae_population_distribution as s22p
def get_options(argv=None):
'''
Get commandline options
'''
parser = argparse.ArgumentParser()
parser.add_argument('--trials_dir', required=True, help='Directory to store simulation results')
parser.add_argument('--obs_run', required=True, choices=['O4','O5'], help='Observing run')
args = parser.parse_args(args=argv)
return args
if __name__=='__main__':
argv = sys.argv[1:]
args = get_options(argv=argv)
trials_dir = args.trials_dir
obs_run = args.obs_run
with open(f'{trials_dir}/plotting_data.pickle', 'rb') as f:
values = pickle.load(f)
for key,val in values.items():
exec(key + '=val')
if obs_run == 'O4':
h_range = np.arange(15, 23, 0.1)
dist_range = np.arange(0, 260., 0.1)
elif obs_run == 'O5':
h_range = np.arange(15, 24, 0.1)
dist_range = np.arange(0, 460., 0.1)
n_detect1 = np.array(n_detect1)
n_detect2 = np.array(n_detect2)
n_detect3 = np.array(n_detect3)
n_detect4 = np.array(n_detect4)
n_all = n_detect1 + n_detect2 + n_detect3 + n_detect4
#print(f"2 det: {n_detect2};\n3 det: {n_detect3};\n4 det: {n_detect4}")
#print(f"2 det mean: {np.mean(n_detect2)};\n3 det mean: {np.mean(n_detect3)};\n4 det mean: {np.mean(n_detect4)}")
fig_kw = {'figsize':(9.5/0.7, 4)}
fig, axes = plt.subplots(nrows=1, ncols=3, **fig_kw)
ebins = np.arange(-0.5, 1 + max(max(n_detect1), max(n_detect2), max(n_detect3), max(n_detect4)))
norm = np.sum(n_detect3)/np.sum(n_detect2)
mean_nevents = np.mean(n_detect1)
#vals*=norm
#test = dict(zip(ebins, vals))
#print(ebins, vals)
#print("Test")
#print(test)
axes[0].hist(n_detect1, density=True, histtype='stepfilled', color='C4', alpha=0.5, bins=ebins, zorder=1)
axes[0].hist(n_detect1, density=True, histtype='step', color='C4', lw=1, bins=ebins, zorder=2)
#axes[0].hist(list(test.keys()), weights=list(test.values()), histtype='stepfilled', color='C1', alpha=0.5, bins=ebins, zorder=1)
#axes[0].hist(list(test.keys()), weights=list(test.values()), histtype='step', color='C1', lw=3, bins=ebins, zorder=2)
five_percent, ninetyfive_percent = np.percentile(n_detect1, 5), np.percentile(n_detect1, 95)
axes[0].axvline(mean_nevents, color='C4', linestyle='--', lw=1,
label=r'$\langle N\rangle = %.1f ;~ N_{95} = %.0f$' % (mean_nevents, ninetyfive_percent))
#axes[0].axvline(ninetyfive_percent, color='C4',linestyle='dotted', lw=1)
#ebins = np.logspace(0, 1.53, 10)
#ebins = np.insert(ebins, 0, 0)
vals, _, _ = axes[0].hist(n_detect2, histtype='stepfilled', bins=ebins, color='C0', alpha=0.3, density=True, zorder=0)
axes[0].hist(n_detect2, histtype='step', \
bins=ebins, color='C0', lw=1, density=True, zorder=3)
bin_centers = (ebins[0:-1] + ebins[1:])/2.
mean_nevents = np.mean(n_detect2)
five_percent, ninetyfive_percent = np.percentile(n_detect2, 5), np.percentile(n_detect2, 95)
axes[0].axvline(mean_nevents, color='C0', linestyle='--', lw=1,
label=r'$\langle N\rangle = %.1f ;~ N_{95} = %.0f$' % (mean_nevents, ninetyfive_percent))
#axes[0].axvline(ninetyfive_percent, color='C0',linestyle='dotted', lw=1)
#vals, bins = np.histogram(n_detect3, bins=ebins, density=True)
#vals, bins = np.histogram(n_detect3, bins=ebins, density=True)
mean_nevents = np.mean(n_detect3)
#vals*=norm
#test = dict(zip(ebins, vals))
#print(ebins, vals)
#print("Test")
#print(test)
axes[0].hist(n_detect3, density=True, histtype='stepfilled', color='C1', alpha=0.5, bins=ebins, zorder=1)
#axes[0].hist(n_detect3, density=True, histtype='step', color='C1', lw=1, bins=ebins, zorder=2)
#axes[0].hist(list(test.keys()), weights=list(test.values()), histtype='stepfilled', color='C1', alpha=0.5, bins=ebins, zorder=1)
#axes[0].hist(list(test.keys()), weights=list(test.values()), histtype='step', color='C1', lw=3, bins=ebins, zorder=2)
five_percent, ninetyfive_percent = np.percentile(n_detect3, 5), np.percentile(n_detect3, 95)
axes[0].axvline(mean_nevents, color='C1', linestyle='--', lw=1,
label=r'$\langle N\rangle = %.1f ;~ N_{95} = %.0f$' % (mean_nevents, ninetyfive_percent))
#axes[0].axvline(ninetyfive_percent, color='C1', linestyle='dotted', lw=1)
if obs_run == 'O5':
mean_nevents = np.mean(n_detect4)
# #vals*=nor
# #test = dict(zip(ebins, vals))
axes[0].hist(n_detect4, density=True, histtype='stepfilled', color='C2', alpha=0.5, bins=ebins, zorder=1)
axes[0].hist(n_detect4, density=True, histtype='step', color='C2', lw=1, bins=ebins, zorder=2)
five_percent, ninetyfive_percent = np.percentile(n_detect4, 5), np.percentile(n_detect4, 95)
axes[0].axvline(round(mean_nevents), color='C2', linestyle='--', lw=1,
label=r'$\langle N\rangle = %.1f ;~ N_{95} = %.0f$' % (mean_nevents, ninetyfive_percent))
#axes[0].axvline(ninetyfive_percent, color='C2',linestyle='dotted', lw=1)
axes[0].hist(n_all, color = 'black', histtype='step', density=True, bins = ebins, lw=2, label=r'$\langle N\rangle = %.1f ;~ N_{95} = %.0f$' % (np.mean(n_all), np.percentile(n_all, 95)))
axes[0].legend(frameon=False, fontsize='medium', loc='upper right')
#axes[0].set_xscale('log')
axes[0].set_yscale('log')
#axes[0].set_ylim((1e-2, 1))
#######################################################
### print out probabilities of greater than 1 event ###
#######################################################
# print("P(N > 1 event detected)")
# print("For two detector", np.sum(n_detect2 > 1)/len(n_detect2))
# print("For three detector", np.sum(n_detect3 > 1)/len(n_detect2))
# print("For four detector", np.sum(n_detect4 > 1)/len(n_detect2))
# print("Number of trials with less than 1 KN",np.sum((n_detect2 + n_detect3 + n_detect4) < 1)*100/len(n_detect2))
print("Percentiles of events")
print(f"one detector | 5th {np.percentile(n_detect1, 5)} | median {np.median(n_detect1)} | 95th {np.percentile(n_detect1, 95)}")
print(f"two detector | 5th {np.percentile(n_detect2, 5)} | median {np.median(n_detect2)} | 95th {np.percentile(n_detect2, 95)}")
print(f"three detector | 5th {np.percentile(n_detect3, 5)} | median {np.median(n_detect3)} | 95th {np.percentile(n_detect3, 95)}")
print(f"four detector | 5th {np.percentile(n_detect4, 5)} | median {np.median(n_detect4)} | 95th {np.percentile(n_detect4, 95)}")
print(f"Total | 5th {np.percentile(n_all, 5)} | mean {np.mean(n_all)} | 95th {np.percentile(n_all, 95)}")
print("one detector ${", np.median(n_detect1), "}_{-", np.median(n_detect1) - np.percentile(n_detect1, 5) ,"}^{+", np.percentile(n_detect1, 95) - np.median(n_detect1), "}$")
print("two detector ${", np.median(n_detect2), "}_{-", np.median(n_detect2) - np.percentile(n_detect2, 5) ,"}^{+", np.percentile(n_detect2, 95) - np.median(n_detect2), "}$")
print("three detector ${", np.median(n_detect3), "}_{-", np.median(n_detect3) - np.percentile(n_detect3, 5) ,"}^{+", np.percentile(n_detect3, 95) - np.median(n_detect3), "}$")
print("four detector ${", np.median(n_detect4), "}_{-", np.median(n_detect4) - np.percentile(n_detect4, 5) ,"}^{+", np.percentile(n_detect4, 95) - np.median(n_detect4), "}$")
print("total ${", np.median(n_all), "}_{-", np.median(n_all) - np.percentile(n_all, 5) ,"}^{+", np.percentile(n_all, 95) - np.median(n_all), "}$")
patches = list()
legend_text = list()
try:
kde = spstat.gaussian_kde(dist_detect1, bw_method='scott')
pdist = kde(dist_range)
axes[1].plot(dist_range, pdist, color='C4', linestyle='-', lw=3, zorder=4)
patch1 = axes[1].fill_between(dist_range, np.zeros(len(dist_range)), pdist, color='C4', alpha=0.3, zorder=0)
patches.append(patch1)
legend_text.append('1 Detector Events')
mean_dist = np.mean(dist_detect1)
axes[1].axvline(mean_dist, color='C4', linestyle='--', lw=1.5, zorder=6, label=r'$\langle D \rangle = {:.0f}$ Mpc'.format(mean_dist))
# ind0_40 = dist_range <= 40.
# ind40_80 = (dist_range <= 100.) & (dist_range > 40.)
# ind80_160 = (dist_range <= 160.) & (dist_range > 100.)
# p0_40 = scinteg.trapz(pdist[ind0_40], dist_range[ind0_40])
# p40_80 = scinteg.trapz(pdist[ind40_80], dist_range[ind40_80])
# p80_160 = scinteg.trapz(pdist[ind80_160], dist_range[ind80_160])
# print(p0_40*5, p40_80*5, p80_160*5)
except ValueError:
print("Could not create KDE since no 1-det detection")
try:
kde = spstat.gaussian_kde(dist_detect2, bw_method='scott')
pdist = kde(dist_range)
axes[1].plot(dist_range, pdist, color='C0', linestyle='-', lw=3, zorder=4)
patch1 = axes[1].fill_between(dist_range, np.zeros(len(dist_range)), pdist, color='C0', alpha=0.3, zorder=0)
patches.append(patch1)
legend_text.append('2 Detector Events')
mean_dist = np.mean(dist_detect2)
axes[1].axvline(mean_dist, color='C0', linestyle='--', lw=1.5, zorder=6, label=r'$\langle D \rangle = {:.0f}$ Mpc'.format(mean_dist))
# ind0_40 = dist_range <= 40.
# ind40_80 = (dist_range <= 100.) & (dist_range > 40.)
# ind80_160 = (dist_range <= 160.) & (dist_range > 100.)
# p0_40 = scinteg.trapz(pdist[ind0_40], dist_range[ind0_40])
# p40_80 = scinteg.trapz(pdist[ind40_80], dist_range[ind40_80])
# p80_160 = scinteg.trapz(pdist[ind80_160], dist_range[ind80_160])
# print(p0_40*5, p40_80*5, p80_160*5)
except ValueError:
print("Could not create KDE since no 2-det detection")
try:
kde = spstat.gaussian_kde(dist_detect3, bw_method='scott')
pdist = kde(dist_range)
axes[1].plot(dist_range, pdist, color='C1', linestyle='-', lw=3, zorder=2)
patch2 = axes[1].fill_between(dist_range, np.zeros(len(dist_range)), pdist, color='C1', alpha=0.5, zorder=1)
patches.append(patch2)
legend_text.append('3 Detector Events')
mean_dist = np.mean(dist_detect3)
axes[1].axvline(mean_dist, color='C1', linestyle='--', lw=1.5, zorder=6, label=r'$\langle D \rangle = {:.0f}$ Mpc'.format(mean_dist))
axes[1].legend(frameon=False, fontsize='medium')
except ValueError:
print("Could not create KDE since no 3-det detection")
try:
kde = spstat.gaussian_kde(dist_detect4, bw_method='scott')
pdist = kde(dist_range)
mean_dist = np.mean(dist_detect4)
axes[1].plot(dist_range, pdist, color='C2', linestyle='-', lw=3, zorder=2)
axes[1].axvline(mean_dist, color='C2', linestyle='--', lw=1.5, zorder=6, label=r'$\langle D \rangle = {:.0f}$ Mpc'.format(mean_dist))
patch3 = axes[1].fill_between(dist_range, np.zeros(len(dist_range)), pdist, color='C2', alpha=0.5, zorder=1)
patches.append(patch3)
legend_text.append('4 Detector Events')
axes[1].legend(frameon=False, fontsize='medium')
except ValueError:
print("Could not create KDE since no 4-det detection")
kde = spstat.gaussian_kde(mag_detect1, bw_method='scott')
kde_peak = spstat.gaussian_kde(mag_peak1, bw_method='scott')
ph = kde(h_range)
peak_ph = kde_peak(h_range)
axes[2].plot(h_range, ph, color='C4', linestyle='dotted', lw=3, zorder=4)
axes[2].plot(h_range, peak_ph, color='C4', linestyle='-', lw=3, zorder=4)
axes[2].fill_between(h_range, np.zeros(len(h_range)), peak_ph, color='C4', alpha=0.3, zorder=0)
mean_h = np.mean(mag_peak1)
axes[2].axvline(mean_h, color='C4', linestyle='--', lw=1.5, zorder=6, label=r'$\langle r \rangle_{{peak}} = {:.1f}$ mag'.format(mean_h))
kde = spstat.gaussian_kde(mag_detect2, bw_method='scott')
kde_peak = spstat.gaussian_kde(mag_peak2, bw_method='scott')
ph = kde(h_range)
peak_ph = kde_peak(h_range)
axes[2].plot(h_range, ph, color='C0', linestyle='dotted', lw=3, zorder=4)
axes[2].plot(h_range, peak_ph, color='C0', linestyle='-', lw=3, zorder=4)
axes[2].fill_between(h_range, np.zeros(len(h_range)), peak_ph, color='C0', alpha=0.3, zorder=0)
mean_h = np.mean(mag_peak2)
axes[2].axvline(mean_h, color='C0', linestyle='--', lw=1.5, zorder=6, label=r'$\langle r \rangle_{{peak}} = {:.1f}$ mag'.format(mean_h))
kde = spstat.gaussian_kde(mag_detect3, bw_method='scott')
kde_peak = spstat.gaussian_kde(mag_peak3, bw_method='scott')
ph = kde(h_range)
peak_ph = kde_peak(h_range)
axes[2].plot(h_range, ph, color='C1', linestyle='dotted', lw=3, zorder=2)
axes[2].plot(h_range, peak_ph, color='C1', linestyle='-', lw=3, zorder=2)
axes[2].fill_between(h_range, np.zeros(len(h_range)), peak_ph, color='C1', alpha=0.5, zorder=1)
mean_h = np.mean(mag_peak3)
axes[2].axvline(mean_h, color='C1', linestyle='--', lw=1.5, zorder=6, label=r'$\langle r \rangle_{{peak}} = {:.1f}$ mag'.format(mean_h))
axes[2].legend(frameon=False, fontsize='medium')
try:
kde = spstat.gaussian_kde(mag_detect4, bw_method='scott')
kde_peak = spstat.gaussian_kde(mag_peak4, bw_method='scott')
ph = kde(h_range)
peak_ph = kde_peak(h_range)
axes[2].plot(h_range, ph, color='C2', linestyle='dotted', lw=3, zorder=2)
axes[2].plot(h_range, peak_ph, color='C2', linestyle='-', lw=3, zorder=2)
axes[2].fill_between(h_range, np.zeros(len(h_range)), peak_ph, color='C2', alpha=0.5, zorder=1)
mean_h = np.mean(mag_detect4)
axes[2].axvline(mean_h, color='C2', linestyle='--', lw=1.5, zorder=6, label=r'$\langle r \rangle_{{peak}} = {:.1f}$ mag'.format(mean_h))
axes[2].legend(frameon=False, fontsize='medium')
except ValueError:
print("Could not create KDE for h-mag since no 4 detector events found")
axes[1].set_xlabel('Distance ($D$, Mpc)', fontsize='x-large')
axes[1].set_ylabel('$P(D)$', fontsize='x-large')
#if args.mass_distrib != 'msp':
# axes[0].set_title(f"Masses {args.mass_distrib}; {args.masskey1} -- {args.masskey2}")
#else:
# axes[0].set_title("MSP bimodal mass @ 1.393 / 1.807 $M_{\odot}$")
axes[0].set_xlabel('Number of Events ($N$)', fontsize='x-large')
axes[0].set_ylabel('$P(N)$', fontsize='x-large')
axes[2].set_xlabel('Apparent ($r$, AB mag)', fontsize='x-large')
axes[2].set_ylabel('$P(r)$', fontsize='x-large')
ymin, ymax = axes[1].get_ylim()
axes[1].set_ylim(0, ymax)
if obs_run == 'O4':
axes[1].set_xlim(0, 260)
elif obs_run == 'O5':
axes[1].set_xlim(0, 460)
axes[0].set_xlim(-1, 1 + max(max(n_detect1), max(n_detect2), max(n_detect3), max(n_detect4), max(n_all)))
ymin, ymax = axes[2].get_ylim()
axes[2].set_ylim(0, ymax)
if obs_run == 'O4':
axes[2].set_xlim(16.5, 23)
elif obs_run == 'O5':
axes[2].set_xlim(16.5, 24)
fig.legend(patches, legend_text,
'upper center', frameon=False, ncol=4, fontsize='medium')
fig.tight_layout(rect=[0, 0, 1, 0.97], pad=1.05)
fig.savefig(f'{trials_dir}/{obs_run}-sims.pdf')
plt.show()
# # Figure for losses
# gw_mean = np.mean(gw_recovered) * 100
# em_mean = np.mean(em_recovered) * 100
# single_gw_detection_mean = np.mean(single_gw_detection) * 100
# plt.hist(np.array(gw_recovered) * 100, density=True, label=r"$F_{GW}$", histtype=u'step', linewidth=3, color='C0')
# plt.hist(np.array(em_recovered) * 100, density=True, label=r"$F_{EM}$", histtype=u'step', linewidth=3, color='C1')
# plt.hist(np.array(single_gw_detection) * 100, density=True, label=r"$F_{1GW+EM}$", histtype=u'step', linewidth=3, color='C2')
# plt.axvline(gw_mean, linestyle='dotted', label=r"$\langle F_{{GW}} \rangle = {:.1f}$".format(gw_mean), color='C0')
# plt.axvline(em_mean, linestyle='dotted', label=r"$\langle F_{{EM}} \rangle = {:.1f}$".format(em_mean), color='C1')
# plt.axvline(single_gw_detection_mean, linestyle='dotted', label=r"$\langle F_{{1GW+EM}} \rangle = {:.1f}$".format(single_gw_detection_mean), color='C2')
# plt.xlabel('Percent of events')
# plt.ylabel('Relative Number of trials')
# plt.legend()
# plt.savefig(f'{trials_dir}/loss_fractions.pdf')
# plt.show()
# # Figure for discovery window
discovery_window1_mean = np.mean(discovery_window1)
discovery_window2_mean = np.mean(discovery_window2)
discovery_window3_mean = np.mean(discovery_window3)
discovery_window4_mean = np.mean(discovery_window4)
discovery_window2_std = np.std(discovery_window2)
discovery_window3_std = np.std(discovery_window3)
discovery_window4_std = np.std(discovery_window4)
discovery_window2_median = np.median(discovery_window2)
discovery_window3_median = np.median(discovery_window3)
discovery_window4_median = np.median(discovery_window4)
discovery_window1_95 = np.percentile(discovery_window1, 95)
discovery_window2_95 = np.percentile(discovery_window2, 95)
discovery_window3_95 = np.percentile(discovery_window3, 95)
#discovery_window4_95 = np.percentile(discovery_window4, 95)
discovery_window1_5 = np.percentile(discovery_window1, 5)
discovery_window2_5 = np.percentile(discovery_window2, 5)
discovery_window3_5 = np.percentile(discovery_window3, 5)
#discovery_window4_5 = np.percentile(discovery_window4, 5)
print("Discovery windows")
print(f"one detector | 5th {np.percentile(discovery_window1, 5)} | mean {np.mean(discovery_window1)} | 95th {np.percentile(discovery_window1, 95)} | median {np.median(discovery_window1)}")
print(f"two detector | 5th {np.percentile(discovery_window2, 5)} | mean {np.mean(discovery_window2)} | 95th {np.percentile(discovery_window2, 95)} | median {np.median(discovery_window2)}")
print(f"three detector | 5th {np.percentile(discovery_window3, 5)} | mean {np.mean(discovery_window3)} | 95th {np.percentile(discovery_window3, 95)} | median {np.median(discovery_window3)}")
# plt.hist(discovery_window2, density=True, histtype=u'step', linewidth=3, color='C0', label='2 detector')
# plt.hist(discovery_window3, density=True, histtype=u'step', linewidth=3, color='C1', label='3 detector')
# plt.hist(discovery_window4, density=True, histtype=u'step', linewidth=3, color='C2', label='4 detector')
# plt.axvline(discovery_window2_mean, linestyle='dotted', color='C0')
# plt.axvline(discovery_window3_mean, linestyle='dotted', color='C1')
# plt.xlabel('Discovery window (days)')
# plt.ylabel('Relative number of events')
# # plt.savefig(f'{trials_dir}/discovery_windows.pdf')
# plt.show()
# print(f"Discovery windows:\n2 det mean: {discovery_window2_mean} std: {discovery_window2_std}\n3 det: {discovery_window3_mean} std: {discovery_window3_std}\n4 det: {discovery_window4_mean} std: {discovery_window4_std}")
# print(f"Discovery windows:\n2 det 5th: {discovery_window2_5} median: {discovery_window2_median} 95th: {discovery_window2_95}\n3 det 5th: {discovery_window3_5} median: {discovery_window3_median} 95th: {discovery_window3_95}") # \n4 det 5th: {discovery_window4_5} median: {discovery_window4_median} 95th: {discovery_window4_95}\n")
# n_iterations = np.arange(1, len(n_detect2) + 1)
# cumulative_averages2 = np.cumsum(n_detect2) / n_iterations
# cumulative_averages3 = np.cumsum(n_detect3) / n_iterations
# cumulative_averages4 = np.cumsum(n_detect4) / n_iterations
# iteration_start = 10
# plt.plot(n_iterations[iteration_start:], cumulative_averages2[iteration_start:])
# plt.xlabel('Number of iterations')
# plt.ylabel('Cumulative average of 2 detector events')
# plt.axhline(y = np.mean(n_detect2), color='red')
# plt.savefig(f'{trials_dir}/cumulative_avg_2.png')
# plt.show()
# plt.plot(n_iterations[iteration_start:], cumulative_averages3[iteration_start:])
# plt.xlabel('Number of iterations')
# plt.ylabel('Cumulative average of 3 detector events')
# plt.axhline(y = np.mean(n_detect3), color='red')
# plt.savefig(f'{trials_dir}/cumulative_avg_3.png')
# plt.show()
# plt.plot(n_iterations[iteration_start:], cumulative_averages4[iteration_start:])
# plt.xlabel('Number of iterations')
# plt.ylabel('Cumulative average of 4 detector events')
# plt.axhline(y = np.mean(n_detect4), color='red')
# plt.savefig(f'{trials_dir}/cumulative_avg_4.png')
# plt.show()