def main(self): global weights, densities, weighted_densities plt.figure() cluster = clusters.SingleStation() self.station = cluster.stations[0] R = np.linspace(0, 100, 100) densities = [] weights = [] for E in np.linspace(1e13, 1e17, 10000): relative_flux = E ** -2.7 Ne = 10 ** (np.log10(E) - 15 + 4.8) self.ldf = KascadeLdf(Ne) min_dens = self.calculate_minimum_density_for_station_at_R(R) weights.append(relative_flux) densities.append(min_dens) weights = np.array(weights) densities = np.array(densities).T weighted_densities = (np.sum(weights * densities, axis=1) / np.sum(weights)) plt.plot(R, weighted_densities) plt.yscale('log') plt.ylabel("Min. density [m^{-2}]") plt.xlabel("Core distance [m]") plt.axvline(5.77) plt.show()
def __init__(self): # Detectors stations = [501, 503, 506] self.cluster = ScienceParkCluster(stations=stations) # Conditions self.detection_probability = 0.5 self.min_detectors = 2 self.min_stations = 3 # Shower parameters self.ldf = KascadeLdf() self.grid_points = 2500 self.max_radius = 1000 self.min_energy = 1e12 self.max_energy = 1e21 self.start_energy = 1e17 self.bisections = 11 # Throw showers in a regular grid around center mass of the station xc, yc, _ = self.cluster.calc_center_of_mass_coordinates() self.xx = np.linspace(-self.max_radius + xc, self.max_radius + xc, np.sqrt(self.grid_points)) self.yy = np.linspace(-self.max_radius + yc, self.max_radius + yc, np.sqrt(self.grid_points))
def test_init_stores_Ne_and_s(self): Ne = sentinel.Ne s = sentinel.s with patch.object(KascadeLdf, '_cache_c_s_value') as mock_cache: ldf = KascadeLdf(Ne, s) self.assertIs(ldf._Ne, Ne) self.assertIs(ldf._s, s)
def test_init_calls_cache_c_s_value(self): with patch.object(KascadeLdf, '_cache_c_s_value') as mock_cache: sim = KascadeLdf() mock_cache.assert_called_once_with()
def setUp(self): self.ldf = KascadeLdf()
def plot_N_vs_R(data): stations = range(501, 507) station_ids = range(6) cluster = clusters.ScienceParkCluster(stations) c_index = data.root.coincidences.c_index observables = data.root.coincidences.observables figure() #clf() global c_x, c_y if 'c_x' in globals(): scatter(c_x, c_y) else: stations_in_coincidence = [] for coincidence_events in c_index: stations = [ observables[u]['station_id'] for u in coincidence_events ] stations_in_coincidence.append(stations) c_x = [] c_y = [] for station1, station2 in itertools.combinations(station_ids, 2): condition = [ station1 in u and station2 in u for u in stations_in_coincidence ] N = sum(condition) R, phi = cluster.calc_r_and_phi_for_stations(station1, station2) scatter(R, N) c_x.append(R) c_y.append(N) print R, N, station1, station2 ldf = KascadeLdf() R = linspace(100, 500) E = linspace(1e14, 1e19, 100) F = E**-2.7 N = [] for r in R: x = [] for f, e in zip(F, E): Ne = e / 1e15 * 10**4.8 density = ldf.get_ldf_value_for_size(r, Ne) prob = 1 - exp(-.5 * density) x.append(f * prob) N.append(mean(x)) N = array(N) f = lambda x, S: S * interp(x, R, N) c_x = array(c_x) c_y = array(c_y) # WTF wrong with point at slightly less than 100 m? 501 / 502?? sc_x = c_x.compress(c_x >= 100) sc_y = c_y.compress(c_x >= 100) popt, pcov = curve_fit(f, sc_x, sc_y, p0=(1e45)) plot(R, f(R, popt[0])) #ylim(0, 150000) ylim(0, 500000) xlim(0, 500) xlabel("Distance [m]") ylabel("Number of coincidences") utils.saveplot() utils.savedata([sc_x, sc_y], suffix='data') utils.savedata([R, f(R, popt[0])], suffix='fit')
prob_temp = [] for distance in core_distances: prob_temp.append(P_2(ldf, distance, size)) probabilities.append(prob_temp) probabilities = array(probabilities) plot = Plot('semilogx') low = [] mid = [] high = [] for p in probabilities: # Using `1 -` to ensure x (i.e. p) is increasing. low.append(interp(1 - 0.10, 1 - p, core_distances)) mid.append(interp(1 - 0.50, 1 - p, core_distances)) high.append(interp(1 - 0.90, 1 - p, core_distances)) plot.plot(low, energies, linestyle='densely dotted', mark=None) plot.plot(mid, energies, linestyle='densely dashed', mark=None) plot.plot(high, energies, mark=None) plot.set_ylimits(13, 20) plot.set_xlimits(1., 1e4) plot.set_xlabel(r'Core distance [\si{\meter}]') plot.set_ylabel(r'Energy [log10(E/\si{\eV})]') plot.save_as_pdf('efficiency_distance_energy_' + ldf.__class__.__name__) if __name__ == "__main__": for ldf in [NkgLdf(), KascadeLdf(), EllipsLdf()]: plot_E_d_P(ldf)