def fit_muon_selection_efficiency(efficiency, error, binedges, smoothing=1): from gen2_analysis.util import center def pad_knots(knots, order=2): """ Pad knots out for full support at the boundaries """ pre = knots[0] - (knots[1]-knots[0])*np.arange(order, 0, -1) post = knots[-1] + (knots[-1]-knots[-2])*np.arange(1, order+1) return np.concatenate((pre, knots, post)) z = efficiency w = 1./error**2 for i in range(z.shape[1]): # deweight empty declination bands if not (z[:,i] > 0).any(): w[:,i] = 0 continue # extrapolate efficiency with a constant last = np.where(z[:,i] > 0)[0][-1] zlast = z[last-10:last,i] mask = zlast != 0 w[last:,i] = 1./((error[last-10:last,i][mask]**2).mean()) z[last:,i] = zlast[mask].mean() first = np.where(z[:,i] > 0)[0][0] w[:first,i] = 1./((error[first:first+10,i]**2).mean()) w[~np.isfinite(w) | ~np.isfinite(z)] = 0 centers = [center(np.log10(binedges[0])), center(binedges[1])] knots = [pad_knots(np.log10(binedges[0]), 2), pad_knots(binedges[1], 2)] order = [2,2] z, w = photospline.ndsparse.from_data(z, w) spline = photospline.glam_fit(z, w, centers, knots, order, smoothing=[5*smoothing, 10*smoothing], penaltyOrder=[2,2]) return spline
args = parser.parse_args() the_geom = args.geom the_index = args.gamma L0 = 1e45 gamma_num = float(the_index) if 'Sunflower' not in the_geom: the_file = 'sensitivity_Sunflower_' + the_geom + '_' + the_index + '.json' fig = plt.gcf() ax = plt.gca() file = open(the_file, 'r') dataset = json.load(file) cos_theta = np.asarray(dataset['data']['cos_zenith']) xc = -util.center(cos_theta) for detector in dataset['data']['discovery_potential'].keys(): yc = np.full(xc.shape, np.nan) discovery_potential = [] for k in dataset['data']['discovery_potential'][detector].keys(): # items are flux, ns, nb the_dp = dataset['data']['discovery_potential'][detector][k]['flux'] discovery_potential.append(the_dp * 1e-12) yc[int(k)] = the_dp ax.semilogy(xc, yc * 1e-12, label=detector) discovery_potential = np.array(discovery_potential)[::-1] print("Min discovery potential for {} is {}".format( detector, np.min(discovery_potential / 1e-12))) volume = survey_volume(xc, discovery_potential, L0=L0, gamma=gamma_num) print("the volume for {} is {:.3f} Gpc^3".format(detector, volume))
@np.vectorize def median_opening_angle(psf, energy, cos_theta): def f(psi): return psf(psi, energy, cos_theta)-0.5 try: return bisect(f, 0, np.radians(5)) except: return np.radians(5) psf = angular_resolution.SplineKingPointSpreadFunction(spline_name) psf_ic = angular_resolution.get_angular_resolution('IceCube') aeff = effective_areas.MuonEffectiveArea(geo_name, 240) aeff_ic = effective_areas.MuonEffectiveArea('IceCube', 125) loge = np.arange(3.5, 8.5, 0.5) + 0.25 loge_centers = 10**util.center(loge) fig = plt.figure(figsize=(7, 2.5)) griddy = plt.GridSpec(1, 2) ax = plt.subplot(griddy[0]) ct = np.linspace(-1, 1, 101) for e in 1e4, 1e5, 1e6, 1e7: line = ax.plot(ct, aeff(e, ct)/1e6, label=plotting.format_energy('%d', e))[0] s = surfaces.get_fiducial_surface(geo_name, 240, padding=0) ax.plot(ct, s.azimuth_averaged_area(ct)/1e6, color='grey', ls=':') x = 0.7 y = s.azimuth_averaged_area(x)/1e6 ax.annotate(r'$A_{\rm{ geo,IceCube \operatorname{-} Gen2}}$', (x, y,), (-20, 0), textcoords='offset points',