def plot_sciencepark_cluster(): stations = range(501, 507) cluster = clusters.ScienceParkCluster(stations) figure() x_list, y_list = [], [] x_stations, y_stations = [], [] for station in cluster.stations: x_detectors, y_detectors = [], [] for detector in station.detectors: x, y = detector.get_xy_coordinates() x_detectors.append(x) y_detectors.append(y) scatter(x, y, c='black', s=3) x_list.extend(x_detectors) y_list.extend(y_detectors) x_stations.append(mean(x_detectors)) y_stations.append(mean(y_detectors)) axis('equal') cluster = clusters.ScienceParkCluster([501, 503, 506]) pos = [] for station in cluster.stations: x, y, alpha = station.get_xyalpha_coordinates() pos.append((x, y)) for (x0, y0), (x1, y1) in itertools.combinations(pos, 2): plot([x0, x1], [y0, y1], 'gray') utils.savedata([x_list, y_list]) utils.saveplot() artist.utils.save_data([x_list, y_list], suffix='detectors', dirname='plots') artist.utils.save_data([stations, x_stations, y_stations], suffix='stations', dirname='plots')
def plot_phi_reconstruction_results_for_MIP(table, N): THETA = deg2rad(22.5) DTHETA = deg2rad(5.) events = table.read_where('(min_n134 >= N) & (abs(reference_theta - THETA) <= DTHETA)') sim_phi = events['reference_phi'] r_phi = events['reconstructed_phi'] figure() plot_2d_histogram(rad2deg(sim_phi), rad2deg(r_phi), 180) xlabel(r"$\phi_K$ [deg]") ylabel(r"$\phi_H$ [deg]") title(r"$N_{MIP} \geq %d, \quad \theta = 22.5^\circ \pm %d^\circ$" % (N, rad2deg(DTHETA))) utils.saveplot(N) graph = artist.GraphArtist() bins = linspace(-180, 180, 73) H, x_edges, y_edges = histogram2d(rad2deg(sim_phi), rad2deg(r_phi), bins=bins) graph.histogram2d(H, x_edges, y_edges, type='reverse_bw') graph.set_xlabel(r'$\phi_K$ [\si{\degree}]') graph.set_ylabel(r'$\phi_H$ [\si{\degree}]') graph.set_xticks(range(-180, 181, 90)) graph.set_yticks(range(-180, 181, 90)) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_phi_reconstruction_results_for_MIP(group, N): table = group.E_1PeV.zenith_22_5 events = table.read_where('min_n134 >= %d' % N) sim_phi = events['reference_phi'] r_phi = events['reconstructed_phi'] figure() plot_2d_histogram(rad2deg(sim_phi), rad2deg(r_phi), 180) xlabel(r"$\phi_{simulated}$ [deg]") ylabel(r"$\phi_{reconstructed}$ [deg]") #title(r"$N_{MIP} \geq %d, \quad \theta = 22.5^\circ$" % N) utils.saveplot(N) graph = artist.GraphArtist() bins = linspace(-180, 180, 73) H, x_edges, y_edges = histogram2d(rad2deg(sim_phi), rad2deg(r_phi), bins=bins) graph.histogram2d(H, x_edges, y_edges, type='reverse_bw') graph.set_xlabel(r'$\phi_\mathrm{sim}$ [\si{\degree}]') graph.set_ylabel(r'$\phi_\mathrm{rec}$ [\si{\degree}]') graph.set_xticks(range(-180, 181, 90)) graph.set_yticks(range(-180, 181, 90)) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_phi_reconstruction_results_for_MIP(table, N): THETA = deg2rad(22.5) DTHETA = deg2rad(5.) events = table.read_where('(min_n134 >= N) & (abs(reference_theta - THETA) <= DTHETA)') sim_phi = events['reference_phi'] r_phi = events['reconstructed_phi'] figure() plot_2d_histogram(rad2deg(sim_phi), rad2deg(r_phi), 180) xlabel(r"$\phi_K$ [deg]") ylabel(r"$\phi_H$ [deg]") title(r"$N_{MIP} \geq %d, \quad \theta = 22.5^\circ \pm %d^\circ$" % (N, rad2deg(DTHETA))) utils.saveplot(N) graph = artist.GraphArtist() bins = linspace(-180, 180, 73) H, x_edges, y_edges = histogram2d(rad2deg(sim_phi), rad2deg(r_phi), bins=bins) graph.histogram2d(H, x_edges, y_edges, type='reverse_bw') graph.set_xlabel(r'$\phi_K$ [\si{\degree}]') graph.set_ylabel(r'$\phi_H$ [\si{\degree}]') graph.set_xticks(range(-180, 181, 90)) graph.set_yticks(range(-180, 181, 90)) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_uncertainty_core_distance(table): N = 2 THETA = deg2rad(22.5) DTHETA = deg2rad(5.) DN = .5 DR = 10 LOGENERGY = 15 DLOGENERGY = .5 figure() x, y, y2 = [], [], [] for R in range(0, 81, 20): x.append(R) events = table.read_where('(abs(min_n134 - N) <= DN) & (abs(reference_theta - THETA) <= DTHETA) & (abs(r - R) <= DR) & (abs(log10(k_energy) - LOGENERGY) <= DLOGENERGY)') print(len(events),) errors = events['reference_theta'] - events['reconstructed_theta'] # Make sure -pi < errors < pi errors = (errors + pi) % (2 * pi) - pi errors2 = events['reference_phi'] - events['reconstructed_phi'] # Make sure -pi < errors2 < pi errors2 = (errors2 + pi) % (2 * pi) - pi #y.append(std(errors)) #y2.append(std(errors2)) y.append((scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) y2.append((scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) print() print("R: theta_std, phi_std") for u, v, w in zip(x, y, y2): print(u, v, w) print() # # Simulation data sx, sy, sy2 = loadtxt(os.path.join(DATADIR, 'DIR-plot_uncertainty_core_distance.txt')) graph = GraphArtist() # Plots plot(x, rad2deg(y), '^-', label="Theta") graph.plot(x[:-1], rad2deg(y[:-1]), mark='o') plot(sx, rad2deg(sy), '^-', label="Theta (sim)") graph.plot(sx[:-1], rad2deg(sy[:-1]), mark='square') plot(x, rad2deg(y2), 'v-', label="Phi") graph.plot(x[:-1], rad2deg(y2[:-1]), mark='*') plot(sx, rad2deg(sy2), 'v-', label="Phi (sim)") graph.plot(sx[:-1], rad2deg(sy2[:-1]), mark='square*') # Labels etc. xlabel("Core distance [m] $\pm %d$" % DR) graph.set_xlabel(r"Core distance [\si{\meter}] $\pm \SI{%d}{\meter}$" % DR) ylabel("Angle reconstruction uncertainty [deg]") graph.set_ylabel(r"Angle reconstruction uncertainty [\si{\degree}]") title(r"$N_{MIP} = %d \pm %.1f, \theta = 22.5^\circ \pm %d^\circ, %.1f \leq \log(E) \leq %.1f$" % (N, DN, rad2deg(DTHETA), LOGENERGY - DLOGENERGY, LOGENERGY + DLOGENERGY)) ylim(ymin=0) graph.set_ylimits(min=0) xlim(-2, 62) legend(numpoints=1, loc='best') utils.saveplot() artist.utils.save_graph(graph, dirname='plots') print
def plot_uncertainty_core_distance(table): N = 2 THETA = deg2rad(22.5) DTHETA = deg2rad(5.) DN = .5 DR = 10 LOGENERGY = 15 DLOGENERGY = .5 figure() x, y, y2 = [], [], [] for R in range(0, 81, 20): x.append(R) events = table.read_where('(abs(min_n134 - N) <= DN) & (abs(reference_theta - THETA) <= DTHETA) & (abs(r - R) <= DR) & (abs(log10(k_energy) - LOGENERGY) <= DLOGENERGY)') print len(events), errors = events['reference_theta'] - events['reconstructed_theta'] # Make sure -pi < errors < pi errors = (errors + pi) % (2 * pi) - pi errors2 = events['reference_phi'] - events['reconstructed_phi'] # Make sure -pi < errors2 < pi errors2 = (errors2 + pi) % (2 * pi) - pi #y.append(std(errors)) #y2.append(std(errors2)) y.append((scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) y2.append((scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) print print "R: theta_std, phi_std" for u, v, w in zip(x, y, y2): print u, v, w print # # Simulation data sx, sy, sy2 = loadtxt(os.path.join(DATADIR, 'DIR-plot_uncertainty_core_distance.txt')) graph = GraphArtist() # Plots plot(x, rad2deg(y), '^-', label="Theta") graph.plot(x[:-1], rad2deg(y[:-1]), mark='o') plot(sx, rad2deg(sy), '^-', label="Theta (sim)") graph.plot(sx[:-1], rad2deg(sy[:-1]), mark='square') plot(x, rad2deg(y2), 'v-', label="Phi") graph.plot(x[:-1], rad2deg(y2[:-1]), mark='*') plot(sx, rad2deg(sy2), 'v-', label="Phi (sim)") graph.plot(sx[:-1], rad2deg(sy2[:-1]), mark='square*') # Labels etc. xlabel("Core distance [m] $\pm %d$" % DR) graph.set_xlabel(r"Core distance [\si{\meter}] $\pm \SI{%d}{\meter}$" % DR) ylabel("Angle reconstruction uncertainty [deg]") graph.set_ylabel(r"Angle reconstruction uncertainty [\si{\degree}]") title(r"$N_{MIP} = %d \pm %.1f, \theta = 22.5^\circ \pm %d^\circ, %.1f \leq \log(E) \leq %.1f$" % (N, DN, rad2deg(DTHETA), LOGENERGY - DLOGENERGY, LOGENERGY + DLOGENERGY)) ylim(ymin=0) graph.set_ylimits(min=0) xlim(-2, 62) legend(numpoints=1, loc='best') utils.saveplot() artist.utils.save_graph(graph, dirname='plots') print
def plot_fsot_vs_lint_for_zenith(fsot, lint): bins = linspace(0, 35, 21) min_N = 1 x, f_y, f_y2, l_y, l_y2 = [], [], [], [], [] for low, high in zip(bins[:-1], bins[1:]): rad_low = deg2rad(low) rad_high = deg2rad(high) query = '(min_n134 >= min_N) & (rad_low <= reference_theta) & (reference_theta < rad_high)' f_sel = fsot.read_where(query) l_sel = lint.read_where(query) errors = f_sel['reconstructed_phi'] - f_sel['reference_phi'] errors2 = f_sel['reconstructed_theta'] - f_sel['reference_theta'] #f_y.append(std(errors)) #f_y2.append(std(errors2)) f_y.append( (scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) f_y2.append( (scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) errors = l_sel['reconstructed_phi'] - l_sel['reference_phi'] errors2 = l_sel['reconstructed_theta'] - l_sel['reference_theta'] #l_y.append(std(errors)) #l_y2.append(std(errors2)) l_y.append( (scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) l_y2.append( (scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) x.append((low + high) / 2) print(x[-1], len(f_sel), len(l_sel)) clf() plot(x, rad2deg(f_y), label="FSOT phi") plot(x, rad2deg(f_y2), label="FSOT theta") plot(x, rad2deg(l_y), label="LINT phi") plot(x, rad2deg(l_y2), label="LINT theta") legend() xlabel("Shower zenith angle [deg]") ylabel("Angle reconstruction uncertainty [deg]") title(r"$N_{MIP} \geq %d$" % min_N) utils.saveplot() graph = GraphArtist() graph.plot(x, rad2deg(f_y), mark=None) graph.plot(x, rad2deg(l_y), mark=None, linestyle='dashed') graph.plot(x, rad2deg(f_y2), mark=None) graph.plot(x, rad2deg(l_y2), mark=None, linestyle='dashed') graph.set_xlabel(r"Shower zenith angle [\si{\degree}]") graph.set_ylabel(r"Angle reconstruction uncertainty [\si{\degree}]") artist.utils.save_graph(graph, dirname='plots')
def plot_spectrum_fit_chisq(self): global integrals if 'integrals' not in globals(): events = self.data.root.hisparc.cluster_kascade.station_601.events integrals = events.col('integrals')[:, 0] bins = np.linspace(0, RANGE_MAX, N_BINS + 1) n, bins = np.histogram(integrals, bins=bins) x = (bins[:-1] + bins[1:]) / 2 p_gamma, p_landau = self.full_spectrum_fit( x, n, (1., 1.), (5e3 / .32, 3.38 / 5000, 1.)) print "FULL FIT" print p_gamma, p_landau print "charged fraction:", self.calc_charged_fraction( x, n, p_gamma, p_landau) landaus = scintillator.conv_landau_for_x(x, *p_landau) gammas = self.gamma_func(x, *p_gamma) fit = landaus + gammas x_trunc = x.compress((LOW <= x) & (x < HIGH)) n_trunc = n.compress((LOW <= x) & (x < HIGH)) fit_trunc = fit.compress((LOW <= x) & (x < HIGH)) chisq, pvalue = stats.chisquare(n_trunc, fit_trunc, ddof=5) chisq /= (len(n_trunc) - 1 - 5) print "Chi-square statistic:", chisq, pvalue plt.figure() plt.plot(x * VNS, n) self.plot_landau_and_gamma(x, p_gamma, p_landau) #plt.plot(x_trunc * VNS, fit_trunc, linewidth=4) plt.axvline(LOW * VNS) plt.axvline(HIGH * VNS) plt.xlabel("Pulse integral [V ns]") plt.ylabel("Count") plt.yscale('log') plt.xlim(0, 20) plt.ylim(1e2, 1e5) plt.title(r"$\chi^2_{red}$: %.2f, p-value: %.2e" % (chisq, pvalue)) utils.saveplot() plt.figure() plt.plot(x_trunc * VNS, n_trunc - fit_trunc) plt.axhline(0) plt.xlabel("Pulse integral [V ns]") plt.ylabel("Data - Fit") plt.title(r"$\chi^2_{red}$: %.2f, p-value: %.2e" % (chisq, pvalue)) utils.saveplot(suffix='residuals')
def plot_fsot_vs_lint_for_zenith(fsot, lint): bins = linspace(0, 35, 21) min_N = 1 x, f_y, f_y2, l_y, l_y2 = [], [], [], [], [] for low, high in zip(bins[:-1], bins[1:]): rad_low = deg2rad(low) rad_high = deg2rad(high) query = '(min_n134 >= min_N) & (rad_low <= reference_theta) & (reference_theta < rad_high)' f_sel = fsot.read_where(query) l_sel = lint.read_where(query) errors = f_sel['reconstructed_phi'] - f_sel['reference_phi'] errors2 = f_sel['reconstructed_theta'] - f_sel['reference_theta'] #f_y.append(std(errors)) #f_y2.append(std(errors2)) f_y.append((scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) f_y2.append((scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) errors = l_sel['reconstructed_phi'] - l_sel['reference_phi'] errors2 = l_sel['reconstructed_theta'] - l_sel['reference_theta'] #l_y.append(std(errors)) #l_y2.append(std(errors2)) l_y.append((scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) l_y2.append((scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) x.append((low + high) / 2) print(x[-1], len(f_sel), len(l_sel)) clf() plot(x, rad2deg(f_y), label="FSOT phi") plot(x, rad2deg(f_y2), label="FSOT theta") plot(x, rad2deg(l_y), label="LINT phi") plot(x, rad2deg(l_y2), label="LINT theta") legend() xlabel("Shower zenith angle [deg]") ylabel("Angle reconstruction uncertainty [deg]") title(r"$N_{MIP} \geq %d$" % min_N) utils.saveplot() graph = GraphArtist() graph.plot(x, rad2deg(f_y), mark=None) graph.plot(x, rad2deg(l_y), mark=None, linestyle='dashed') graph.plot(x, rad2deg(f_y2), mark=None) graph.plot(x, rad2deg(l_y2), mark=None, linestyle='dashed') graph.set_xlabel(r"Shower zenith angle [\si{\degree}]") graph.set_ylabel(r"Angle reconstruction uncertainty [\si{\degree}]") artist.utils.save_graph(graph, dirname='plots')
def hist_theta_single_stations(data): reconstructions = data.root.reconstructions.reconstructions figure() for n, station in enumerate(range(501, 507), 1): subplot(2, 3, n) query = '(N == 1) & s%d' % station theta = reconstructions.read_where(query, field='reconstructed_theta') hist(rad2deg(theta), bins=linspace(0, 45, 21), histtype='step') xlabel(r"$\theta$") legend([station]) locator_params(tight=True, nbins=4) utils.saveplot()
def boxplot_arrival_times(group, N): table = group.E_1PeV.zenith_0 sel = table.read_where('min_n134 >= N') t1 = sel[:]['t1'] t3 = sel[:]['t3'] t4 = sel[:]['t4'] ts = concatenate([t1, t3, t4]) print "Median arrival time delay over all detected events", median(ts) figure() bin_edges = linspace(0, 100, 11) x, arrival_times = [], [] t25, t50, t75 = [], [], [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): query = '(min_n134 >= N) & (low <= r) & (r < high)' sel = table.read_where(query) t1 = sel[:]['t1'] t2 = sel[:]['t2'] ct1 = t1.compress((t1 > -999) & (t2 > -999)) ct2 = t2.compress((t1 > -999) & (t2 > -999)) ts = abs(ct2 - ct1) t25.append(scoreatpercentile(ts, 25)) t50.append(scoreatpercentile(ts, 50)) t75.append(scoreatpercentile(ts, 75)) x.append((low + high) / 2) fill_between(x, t25, t75, color='0.75') plot(x, t50, 'o-', color='black') xlabel("Core distance [m]") ylabel("Arrival time delay [ns]") #title(r"$N_{MIP} \geq %d, \quad \theta = 0^\circ$" % N) xticks(arange(0, 100.5, 10)) utils.savedata((x, t25, t50, t75), N) utils.saveplot(N) graph = GraphArtist() graph.shade_region(x, t25, t75) graph.plot(x, t50, linestyle=None) graph.set_xlabel(r"Core distance [\si{\meter}]") graph.set_ylabel( r"Arrival time difference $|t_2 - t_1|$ [\si{\nano\second}]") graph.set_xlimits(0, 100) graph.set_ylimits(min=0) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def hist_theta_single_stations(data): reconstructions = data.root.reconstructions.reconstructions figure() for n, station in enumerate(range(501, 507), 1): subplot(2, 3, n) query = '(N == 1) & s%d' % station theta = reconstructions.read_where(query, field='reconstructed_theta') hist(rad2deg(theta), bins=linspace(0, 45, 21), histtype='step') xlabel(r"$\theta$") legend([station]) locator_params(tight=True, nbins=4) utils.saveplot()
def boxplot_arrival_times(group, N): table = group.E_1PeV.zenith_0 sel = table.read_where('min_n134 >= N') t1 = sel[:]['t1'] t3 = sel[:]['t3'] t4 = sel[:]['t4'] ts = concatenate([t1, t3, t4]) print "Median arrival time delay over all detected events", median(ts) figure() bin_edges = linspace(0, 100, 11) x, arrival_times = [], [] t25, t50, t75 = [], [], [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): query = '(min_n134 >= N) & (low <= r) & (r < high)' sel = table.read_where(query) t1 = sel[:]['t1'] t2 = sel[:]['t2'] ct1 = t1.compress((t1 > -999) & (t2 > -999)) ct2 = t2.compress((t1 > -999) & (t2 > -999)) ts = abs(ct2 - ct1) t25.append(scoreatpercentile(ts, 25)) t50.append(scoreatpercentile(ts, 50)) t75.append(scoreatpercentile(ts, 75)) x.append((low + high) / 2) fill_between(x, t25, t75, color='0.75') plot(x, t50, 'o-', color='black') xlabel("Core distance [m]") ylabel("Arrival time delay [ns]") #title(r"$N_{MIP} \geq %d, \quad \theta = 0^\circ$" % N) xticks(arange(0, 100.5, 10)) utils.savedata((x, t25, t50, t75), N) utils.saveplot(N) graph = GraphArtist() graph.shade_region(x, t25, t75) graph.plot(x, t50, linestyle=None) graph.set_xlabel(r"Core distance [\si{\meter}]") graph.set_ylabel(r"Arrival time difference $|t_2 - t_1|$ [\si{\nano\second}]") graph.set_xlimits(0, 100) graph.set_ylimits(min=0) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_uncertainty_zenith_angular_distance(group): group = group.E_1PeV rec = DirectionReconstruction N = 2 # constants for uncertainty estimation # BEWARE: stations must be the same over all reconstruction tables used station = group.zenith_0.attrs.cluster.stations[0] r1, phi1 = station.calc_r_and_phi_for_detectors(1, 3) r2, phi2 = station.calc_r_and_phi_for_detectors(1, 4) figure() graph = GraphArtist() # Uncertainty estimate x = linspace(0, deg2rad(45), 50) #x = array([pi / 8]) phis = linspace(-pi, pi, 50) y, y2 = [], [] for t in x: y.append(mean(rec.rel_phi_errorsq(t, phis, phi1, phi2, r1, r2))) y2.append(mean(rec.rel_theta1_errorsq(t, phis, phi1, phi2, r1, r2))) y = TIMING_ERROR * sqrt(array(y)) y2 = TIMING_ERROR * sqrt(array(y2)) ang_dist = sqrt((y * sin(x)) ** 2 + y2 ** 2) #plot(rad2deg(x), rad2deg(y), label="Estimate Phi") #plot(rad2deg(x), rad2deg(y2), label="Estimate Theta") plot(rad2deg(x), rad2deg(ang_dist), label="Angular distance") graph.plot(rad2deg(x), rad2deg(ang_dist), mark=None) print rad2deg(x) print rad2deg(y) print rad2deg(y2) print rad2deg(y * sin(x)) print rad2deg(ang_dist) # Labels etc. xlabel("Shower zenith angle [deg]") ylabel("Angular distance [deg]") graph.set_xlabel(r"Shower zenith angle [\si{\degree}]") graph.set_ylabel(r"Angular distance [\si{\degree}]") graph.set_ylimits(min=6) #title(r"$N_{MIP} \geq %d$" % N) #ylim(0, 100) #legend(numpoints=1) utils.saveplot() artist.utils.save_graph(graph, dirname='plots') print
def boxplot_phi_reconstruction_results_for_MIP(table, N): figure() THETA = deg2rad(22.5) DTHETA = deg2rad(5.) bin_edges = linspace(-180, 180, 18) x, r_dphi = [], [] d25, d50, d75 = [], [], [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): rad_low = deg2rad(low) rad_high = deg2rad(high) query = '(min_n134 >= N) & (rad_low < reference_phi) & (reference_phi < rad_high) & (abs(reference_theta - THETA) <= DTHETA)' sel = table.read_where(query) dphi = sel[:]['reconstructed_phi'] - sel[:]['reference_phi'] dphi = (dphi + pi) % (2 * pi) - pi r_dphi.append(rad2deg(dphi)) d25.append(scoreatpercentile(rad2deg(dphi), 25)) d50.append(scoreatpercentile(rad2deg(dphi), 50)) d75.append(scoreatpercentile(rad2deg(dphi), 75)) x.append((low + high) / 2) #boxplot(r_dphi, positions=x, widths=1 * (high - low), sym='') fill_between(x, d25, d75, color='0.75') plot(x, d50, 'o-', color='black') xlabel(r"$\phi_K$ [deg]") ylabel(r"$\phi_H - \phi_K$ [deg]") title(r"$N_{MIP} \geq %d, \quad \theta = 22.5^\circ \pm %d^\circ$" % (N, rad2deg(DTHETA))) xticks(linspace(-180, 180, 9)) axhline(0, color='black') utils.saveplot(N) graph = GraphArtist() graph.draw_horizontal_line(0, linestyle='gray') graph.shade_region(x, d25, d75) graph.plot(x, d50, linestyle=None) graph.set_xlabel(r"$\phi_K$ [\si{\degree}]") graph.set_ylabel(r"$\phi_H - \phi_K$ [\si{\degree}]") graph.set_xticks([-180, -90, '...', 180]) graph.set_xlimits(-180, 180) graph.set_ylimits(-23, 23) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_uncertainty_zenith_angular_distance(group): group = group.E_1PeV rec = DirectionReconstruction N = 2 # constants for uncertainty estimation # BEWARE: stations must be the same over all reconstruction tables used station = group.zenith_0.attrs.cluster.stations[0] r1, phi1 = station.calc_r_and_phi_for_detectors(1, 3) r2, phi2 = station.calc_r_and_phi_for_detectors(1, 4) figure() graph = GraphArtist() # Uncertainty estimate x = linspace(0, deg2rad(45), 50) #x = array([pi / 8]) phis = linspace(-pi, pi, 50) y, y2 = [], [] for t in x: y.append(mean(rec.rel_phi_errorsq(t, phis, phi1, phi2, r1, r2))) y2.append(mean(rec.rel_theta1_errorsq(t, phis, phi1, phi2, r1, r2))) y = TIMING_ERROR * sqrt(array(y)) y2 = TIMING_ERROR * sqrt(array(y2)) ang_dist = sqrt((y * sin(x))**2 + y2**2) #plot(rad2deg(x), rad2deg(y), label="Estimate Phi") #plot(rad2deg(x), rad2deg(y2), label="Estimate Theta") plot(rad2deg(x), rad2deg(ang_dist), label="Angular distance") graph.plot(rad2deg(x), rad2deg(ang_dist), mark=None) print rad2deg(x) print rad2deg(y) print rad2deg(y2) print rad2deg(y * sin(x)) print rad2deg(ang_dist) # Labels etc. xlabel("Shower zenith angle [deg]") ylabel("Angular distance [deg]") graph.set_xlabel(r"Shower zenith angle [\si{\degree}]") graph.set_ylabel(r"Angular distance [\si{\degree}]") graph.set_ylimits(min=6) #title(r"$N_{MIP} \geq %d$" % N) #ylim(0, 100) #legend(numpoints=1) utils.saveplot() artist.utils.save_graph(graph, dirname='plots') print
def plot_detection_efficiency_vs_R_for_angles(N): figure() graph = GraphArtist() locations = iter(['right', 'left', 'below left']) positions = iter([.18, .14, .15]) bin_edges = linspace(0, 100, 20) x = (bin_edges[:-1] + bin_edges[1:]) / 2. for angle in [0, 22.5, 35]: angle_str = str(angle).replace('.', '_') shower_group = '/simulations/E_1PeV/zenith_%s' % angle_str efficiencies = [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): shower_results = [] for shower in data.list_nodes(shower_group): sel_query = '(low <= r) & (r < high)' coinc_sel = shower.coincidences.read_where(sel_query) ids = coinc_sel['id'] obs_sel = shower.observables.read_coordinates(ids) assert (obs_sel['id'] == ids).all() o = obs_sel sel = obs_sel.compress((o['n1'] >= N) & (o['n3'] >= N) & (o['n4'] >= N)) shower_results.append(len(sel) / len(obs_sel)) efficiencies.append(mean(shower_results)) plot(x, efficiencies, label=r'$\theta = %s^\circ$' % angle) graph.plot(x, efficiencies, mark=None) graph.add_pin(r'\SI{%s}{\degree}' % angle, location=locations.next(), use_arrow=True, relative_position=positions.next()) xlabel("Core distance [m]") graph.set_xlabel(r"Core distance [\si{\meter}]") ylabel("Detection efficiency") graph.set_ylabel("Detection efficiency") #title(r"$N_{MIP} \geq %d$" % N) legend() graph.set_xlimits(0, 100) graph.set_ylimits(0, 1) utils.saveplot(N) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_uncertainty_core_distance(group): table = group.E_1PeV.zenith_22_5 N = 2 DR = 10 figure() x, y, y2 = [], [], [] for R in range(0, 81, 20): x.append(R) events = table.read_where('(min_n134 == N) & (abs(r - R) <= DR)') print len(events), errors = events['reference_theta'] - events['reconstructed_theta'] # Make sure -pi < errors < pi errors = (errors + pi) % (2 * pi) - pi errors2 = events['reference_phi'] - events['reconstructed_phi'] # Make sure -pi < errors2 < pi errors2 = (errors2 + pi) % (2 * pi) - pi #y.append(std(errors)) #y2.append(std(errors2)) y.append( (scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) y2.append( (scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) print print "R: theta_std, phi_std" for u, v, w in zip(x, y, y2): print u, v, w print utils.savedata((x, y, y2)) # Plots plot(x, rad2deg(y), '^-', label="Theta") plot(x, rad2deg(y2), 'v-', label="Phi") # Labels etc. xlabel("Core distance [m] $\pm %d$" % DR) ylabel("Angle reconstruction uncertainty [deg]") #title(r"$N_{MIP} = %d, \theta = 22.5^\circ$" % N) ylim(ymin=0) legend(numpoints=1, loc='best') utils.saveplot() print
def plot_detection_efficiency(self): integrals, dens = self.get_integrals_and_densities() popt = self.full_fit_on_data(integrals, (1., 1., 5e3 / .32, 3.38 / 5000, 1.)) x, y, yerr = [], [], [] dens_bins = np.linspace(0, 10, 51) for low, high in zip(dens_bins[:-1], dens_bins[1:]): sel = integrals.compress((low <= dens) & (dens < high)) x.append((low + high) / 2) frac = self.determine_charged_fraction(sel, popt) y.append(frac) yerr.append(np.sqrt(frac * len(sel)) / len(sel)) print(low + high) / 2, len(sel) self.plot_full_spectrum_fit_in_density_range(sel, popt, low, high) print plt.figure() plt.errorbar(x, y, yerr, fmt='o', label='data', markersize=3.) popt, pcov = optimize.curve_fit(self.conv_p_detection, x, y, p0=(1., )) print "Sigma Gauss:", popt x2 = plt.linspace(0, 10, 101) plt.plot(x2, self.p_detection(x2), label='poisson') plt.plot(x2, self.conv_p_detection(x2, *popt), label='poisson/gauss') plt.xlabel("Charged particle density [$m^{-2}$]") plt.ylabel("Detection probability") plt.ylim(0, 1.) plt.legend(loc='best') utils.saveplot() graph = GraphArtist() graph.plot(x2, self.p_detection(x2), mark=None) graph.plot(x2, self.conv_p_detection(x2, *popt), mark=None, linestyle='dashed') graph.plot(x, y, yerr=yerr, linestyle=None) graph.set_xlabel(r"Charged particle density [\si{\per\square\meter}]") graph.set_ylabel("Detection probability") graph.set_xlimits(min=0) graph.set_ylimits(min=0) artist.utils.save_graph(graph, dirname='plots')
def boxplot_phi_reconstruction_results_for_MIP(group, N): table = group.E_1PeV.zenith_22_5 figure() bin_edges = linspace(-180, 180, 18) x, r_dphi = [], [] d25, d50, d75 = [], [], [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): rad_low = deg2rad(low) rad_high = deg2rad(high) query = '(min_n134 >= N) & (rad_low < reference_phi) & (reference_phi < rad_high)' sel = table.read_where(query) dphi = sel[:]['reconstructed_phi'] - sel[:]['reference_phi'] dphi = (dphi + pi) % (2 * pi) - pi r_dphi.append(rad2deg(dphi)) d25.append(scoreatpercentile(rad2deg(dphi), 25)) d50.append(scoreatpercentile(rad2deg(dphi), 50)) d75.append(scoreatpercentile(rad2deg(dphi), 75)) x.append((low + high) / 2) fill_between(x, d25, d75, color='0.75') plot(x, d50, 'o-', color='black') xlabel(r"$\phi_{simulated}$ [deg]") ylabel(r"$\phi_{reconstructed} - \phi_{simulated}$ [deg]") #title(r"$N_{MIP} \geq %d, \quad \theta = 22.5^\circ$" % N) xticks(linspace(-180, 180, 9)) axhline(0, color='black') ylim(-15, 15) utils.saveplot(N) graph = GraphArtist() graph.draw_horizontal_line(0, linestyle='gray') graph.shade_region(x, d25, d75) graph.plot(x, d50, linestyle=None) graph.set_xlabel(r"$\phi_\mathrm{sim}$ [\si{\degree}]") graph.set_ylabel(r"$\phi_\mathrm{rec} - \phi_\mathrm{sim}$ [\si{\degree}]") graph.set_title(r"$N_\mathrm{MIP} \geq %d$" % N) graph.set_xticks([-180, -90, '...', 180]) graph.set_xlimits(-180, 180) graph.set_ylimits(-17, 17) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_detection_efficiency_vs_R_for_angles(N): figure() graph = GraphArtist() locations = iter(['right', 'left', 'below left']) positions = iter([.18, .14, .15]) bin_edges = linspace(0, 100, 20) x = (bin_edges[:-1] + bin_edges[1:]) / 2. for angle in [0, 22.5, 35]: angle_str = str(angle).replace('.', '_') shower_group = '/simulations/E_1PeV/zenith_%s' % angle_str efficiencies = [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): shower_results = [] for shower in data.list_nodes(shower_group): sel_query = '(low <= r) & (r < high)' coinc_sel = shower.coincidences.read_where(sel_query) ids = coinc_sel['id'] obs_sel = shower.observables.read_coordinates(ids) assert (obs_sel['id'] == ids).all() o = obs_sel sel = obs_sel.compress((o['n1'] >= N) & (o['n3'] >= N) & (o['n4'] >= N)) shower_results.append(len(sel) / len(obs_sel)) efficiencies.append(mean(shower_results)) plot(x, efficiencies, label=r'$\theta = %s^\circ$' % angle) graph.plot(x, efficiencies, mark=None) graph.add_pin(r'\SI{%s}{\degree}' % angle, location=locations.next(), use_arrow=True, relative_position=positions.next()) xlabel("Core distance [m]") graph.set_xlabel(r"Core distance [\si{\meter}]") ylabel("Detection efficiency") graph.set_ylabel("Detection efficiency") #title(r"$N_{MIP} \geq %d$" % N) legend() graph.set_xlimits(0, 100) graph.set_ylimits(0, 1) utils.saveplot(N) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def boxplot_phi_reconstruction_results_for_MIP(group, N): table = group.E_1PeV.zenith_22_5 figure() bin_edges = linspace(-180, 180, 18) x, r_dphi = [], [] d25, d50, d75 = [], [], [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): rad_low = deg2rad(low) rad_high = deg2rad(high) query = '(min_n134 >= N) & (rad_low < reference_phi) & (reference_phi < rad_high)' sel = table.read_where(query) dphi = sel[:]['reconstructed_phi'] - sel[:]['reference_phi'] dphi = (dphi + pi) % (2 * pi) - pi r_dphi.append(rad2deg(dphi)) d25.append(scoreatpercentile(rad2deg(dphi), 25)) d50.append(scoreatpercentile(rad2deg(dphi), 50)) d75.append(scoreatpercentile(rad2deg(dphi), 75)) x.append((low + high) / 2) fill_between(x, d25, d75, color='0.75') plot(x, d50, 'o-', color='black') xlabel(r"$\phi_{simulated}$ [deg]") ylabel(r"$\phi_{reconstructed} - \phi_{simulated}$ [deg]") #title(r"$N_{MIP} \geq %d, \quad \theta = 22.5^\circ$" % N) xticks(linspace(-180, 180, 9)) axhline(0, color='black') ylim(-15, 15) utils.saveplot(N) graph = GraphArtist() graph.draw_horizontal_line(0, linestyle='gray') graph.shade_region(x, d25, d75) graph.plot(x, d50, linestyle=None) graph.set_xlabel(r"$\phi_\mathrm{sim}$ [\si{\degree}]") graph.set_ylabel(r"$\phi_\mathrm{rec} - \phi_\mathrm{sim}$ [\si{\degree}]") graph.set_title(r"$N_\mathrm{MIP} \geq %d$" % N) graph.set_xticks([-180, -90, '...', 180]) graph.set_xlimits(-180, 180) graph.set_ylimits(-17, 17) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def boxplot_phi_reconstruction_results_for_MIP(table, N): figure() THETA = deg2rad(22.5) DTHETA = deg2rad(5.) bin_edges = linspace(-180, 180, 18) x, r_dphi = [], [] d25, d50, d75 = [], [], [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): rad_low = deg2rad(low) rad_high = deg2rad(high) query = '(min_n134 >= N) & (rad_low < reference_phi) & (reference_phi < rad_high) & (abs(reference_theta - THETA) <= DTHETA)' sel = table.read_where(query) dphi = sel[:]['reconstructed_phi'] - sel[:]['reference_phi'] dphi = (dphi + pi) % (2 * pi) - pi r_dphi.append(rad2deg(dphi)) d25.append(scoreatpercentile(rad2deg(dphi), 25)) d50.append(scoreatpercentile(rad2deg(dphi), 50)) d75.append(scoreatpercentile(rad2deg(dphi), 75)) x.append((low + high) / 2) #boxplot(r_dphi, positions=x, widths=1 * (high - low), sym='') fill_between(x, d25, d75, color='0.75') plot(x, d50, 'o-', color='black') xlabel(r"$\phi_K$ [deg]") ylabel(r"$\phi_H - \phi_K$ [deg]") title(r"$N_{MIP} \geq %d, \quad \theta = 22.5^\circ \pm %d^\circ$" % (N, rad2deg(DTHETA))) xticks(linspace(-180, 180, 9)) axhline(0, color='black') utils.saveplot(N) graph = GraphArtist() graph.draw_horizontal_line(0, linestyle='gray') graph.shade_region(x, d25, d75) graph.plot(x, d50, linestyle=None) graph.set_xlabel(r"$\phi_K$ [\si{\degree}]") graph.set_ylabel(r"$\phi_H - \phi_K$ [\si{\degree}]") graph.set_xticks([-180, -90, '...', 180]) graph.set_xlimits(-180, 180) graph.set_ylimits(-23, 23) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def boxplot_theta_reconstruction_results_for_MIP(table, N): figure() DTHETA = deg2rad(1.) angles = [0, 5, 10, 15, 22.5, 35] r_dtheta = [] x = [] d25, d50, d75 = [], [], [] for angle in angles: theta = deg2rad(angle) sel = table.read_where( '(min_n134 >= N) & (abs(reference_theta - theta) <= DTHETA)') dtheta = rad2deg(sel[:]['reconstructed_theta'] - sel[:]['reference_theta']) r_dtheta.append(dtheta) d25.append(scoreatpercentile(dtheta, 25)) d50.append(scoreatpercentile(dtheta, 50)) d75.append(scoreatpercentile(dtheta, 75)) x.append(angle) #boxplot(r_dtheta, sym='', positions=angles, widths=2.) fill_between(x, d25, d75, color='0.75') plot(x, d50, 'o-', color='black') xlabel(r"$\theta_K$ [deg]") ylabel(r"$\theta_H - \theta_K$ [deg]") title(r"$N_{MIP} \geq %d$" % N) axhline(0, color='black') ylim(-20, 25) xlim(0, 35) utils.saveplot(N) graph = GraphArtist() graph.draw_horizontal_line(0, linestyle='gray') graph.shade_region(angles, d25, d75) graph.plot(angles, d50, linestyle=None) graph.set_xlabel(r"$\theta_K$ [\si{\degree}]") graph.set_ylabel(r"$\theta_H - \theta_K$ [\si{\degree}]") graph.set_ylimits(-5, 15) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_reconstruction_efficiency_vs_R_for_angles(N): group = data.root.reconstructions.E_1PeV figure() bin_edges = linspace(0, 100, 10) x = (bin_edges[:-1] + bin_edges[1:]) / 2. all_data = [] for angle in [0, 22.5, 35]: angle_str = str(angle).replace('.', '_') shower_group = '/simulations/E_1PeV/zenith_%s' % angle_str reconstructions = group._f_get_child('zenith_%s' % angle_str) efficiencies = [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): shower_results = [] for shower in data.list_nodes(shower_group): sel_query = '(low <= r) & (r < high)' coinc_sel = shower.coincidences.read_where(sel_query) ids = coinc_sel['id'] obs_sel = shower.observables.read_coordinates(ids) assert (obs_sel['id'] == ids).all() o = obs_sel sel = obs_sel.compress((o['n1'] >= N) & (o['n3'] >= N) & (o['n4'] >= N)) shower_results.append(len(sel)) ssel = reconstructions.read_where( '(min_n134 >= N) & (low <= r) & (r < high)') efficiencies.append(len(ssel) / sum(shower_results)) all_data.append(efficiencies) plot(x, efficiencies, label=r'$\theta = %s^\circ$' % angle) xlabel("Core distance [m]") ylabel("Reconstruction efficiency") #title(r"$N_{MIP} \geq %d$" % N) legend() utils.saveplot(N) utils.savedata(array([x] + all_data).T, suffix=N)
def plot_uncertainty_core_distance(group): table = group.E_1PeV.zenith_22_5 N = 2 DR = 10 figure() x, y, y2 = [], [], [] for R in range(0, 81, 20): x.append(R) events = table.read_where('(min_n134 == N) & (abs(r - R) <= DR)') print len(events), errors = events['reference_theta'] - events['reconstructed_theta'] # Make sure -pi < errors < pi errors = (errors + pi) % (2 * pi) - pi errors2 = events['reference_phi'] - events['reconstructed_phi'] # Make sure -pi < errors2 < pi errors2 = (errors2 + pi) % (2 * pi) - pi #y.append(std(errors)) #y2.append(std(errors2)) y.append((scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) y2.append((scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) print print "R: theta_std, phi_std" for u, v, w in zip(x, y, y2): print u, v, w print utils.savedata((x, y, y2)) # Plots plot(x, rad2deg(y), '^-', label="Theta") plot(x, rad2deg(y2), 'v-', label="Phi") # Labels etc. xlabel("Core distance [m] $\pm %d$" % DR) ylabel("Angle reconstruction uncertainty [deg]") #title(r"$N_{MIP} = %d, \theta = 22.5^\circ$" % N) ylim(ymin=0) legend(numpoints=1, loc='best') utils.saveplot() print
def plot_reconstruction_efficiency_vs_R_for_angles(N): group = data.root.reconstructions.E_1PeV figure() bin_edges = linspace(0, 100, 10) x = (bin_edges[:-1] + bin_edges[1:]) / 2. all_data = [] for angle in [0, 22.5, 35]: angle_str = str(angle).replace('.', '_') shower_group = '/simulations/E_1PeV/zenith_%s' % angle_str reconstructions = group._f_get_child('zenith_%s' % angle_str) efficiencies = [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): shower_results = [] for shower in data.list_nodes(shower_group): sel_query = '(low <= r) & (r < high)' coinc_sel = shower.coincidences.read_where(sel_query) ids = coinc_sel['id'] obs_sel = shower.observables.read_coordinates(ids) assert (obs_sel['id'] == ids).all() o = obs_sel sel = obs_sel.compress((o['n1'] >= N) & (o['n3'] >= N) & (o['n4'] >= N)) shower_results.append(len(sel)) ssel = reconstructions.read_where('(min_n134 >= N) & (low <= r) & (r < high)') efficiencies.append(len(ssel) / sum(shower_results)) all_data.append(efficiencies) plot(x, efficiencies, label=r'$\theta = %s^\circ$' % angle) xlabel("Core distance [m]") ylabel("Reconstruction efficiency") #title(r"$N_{MIP} \geq %d$" % N) legend() utils.saveplot(N) utils.savedata(array([x] + all_data).T, suffix=N)
def boxplot_theta_reconstruction_results_for_MIP(table, N): figure() DTHETA = deg2rad(1.) angles = [0, 5, 10, 15, 22.5, 35] r_dtheta = [] x = [] d25, d50, d75 = [], [], [] for angle in angles: theta = deg2rad(angle) sel = table.read_where('(min_n134 >= N) & (abs(reference_theta - theta) <= DTHETA)') dtheta = rad2deg(sel[:]['reconstructed_theta'] - sel[:]['reference_theta']) r_dtheta.append(dtheta) d25.append(scoreatpercentile(dtheta, 25)) d50.append(scoreatpercentile(dtheta, 50)) d75.append(scoreatpercentile(dtheta, 75)) x.append(angle) #boxplot(r_dtheta, sym='', positions=angles, widths=2.) fill_between(x, d25, d75, color='0.75') plot(x, d50, 'o-', color='black') xlabel(r"$\theta_K$ [deg]") ylabel(r"$\theta_H - \theta_K$ [deg]") title(r"$N_{MIP} \geq %d$" % N) axhline(0, color='black') ylim(-20, 25) xlim(0, 35) utils.saveplot(N) graph = GraphArtist() graph.draw_horizontal_line(0, linestyle='gray') graph.shade_region(angles, d25, d75) graph.plot(angles, d50, linestyle=None) graph.set_xlabel(r"$\theta_K$ [\si{\degree}]") graph.set_ylabel(r"$\theta_H - \theta_K$ [\si{\degree}]") graph.set_ylimits(-5, 15) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_gamma_landau_fit(self): events = self.data.root.hisparc.cluster_kascade.station_601.events ph0 = events.col('integrals')[:, 0] bins = np.linspace(0, RANGE_MAX, N_BINS + 1) n, bins = np.histogram(ph0, bins=bins) x = (bins[:-1] + bins[1:]) / 2 p_gamma, p_landau = self.full_spectrum_fit( x, n, (1., 1.), (5e3 / .32, 3.38 / 5000, 1.)) print "FULL FIT" print p_gamma, p_landau n /= 10 p_gamma, p_landau = self.constrained_full_spectrum_fit( x, n, p_gamma, p_landau) print "CONSTRAINED FIT" print p_gamma, p_landau plt.figure() print self.calc_charged_fraction(x, n, p_gamma, p_landau) plt.plot(x * VNS, n) self.plot_landau_and_gamma(x, p_gamma, p_landau) #plt.plot(x, n - self.gamma_func(x, *p_gamma)) plt.xlabel("Pulse integral [V ns]") plt.ylabel("Count") plt.yscale('log') plt.xlim(0, 30) plt.ylim(1e1, 1e4) plt.legend() utils.saveplot() graph = GraphArtist('semilogy') graph.histogram(n, bins * VNS, linestyle='gray') self.artistplot_landau_and_gamma(graph, x, p_gamma, p_landau) graph.set_xlabel(r"Pulse integral [\si{\volt\nano\second}]") graph.set_ylabel("Count") graph.set_xlimits(0, 30) graph.set_ylimits(1e1, 1e4) artist.utils.save_graph(graph, dirname='plots')
def plot_reconstruction_efficiency_vs_R_for_mips(): reconstructions = data.root.reconstructions.E_1PeV.zenith_22_5 figure() bin_edges = linspace(0, 100, 10) x = (bin_edges[:-1] + bin_edges[1:]) / 2. for N in range(1, 5): shower_group = '/simulations/E_1PeV/zenith_22_5' efficiencies = [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): shower_results = [] for shower in data.list_nodes(shower_group): sel_query = '(low <= r) & (r < high)' coinc_sel = shower.coincidences.read_where(sel_query) ids = coinc_sel['id'] obs_sel = shower.observables.read_coordinates(ids) assert (obs_sel['id'] == ids).all() o = obs_sel sel = o.compress( amin(array([o['n1'], o['n3'], o['n4']]), 0) == N) shower_results.append(len(sel)) ssel = reconstructions.read_where( '(min_n134 == N) & (low <= r) & (r < high)') print sum(shower_results), len( ssel), len(ssel) / sum(shower_results) efficiencies.append(len(ssel) / sum(shower_results)) plot(x, efficiencies, label=r'$N_{MIP} = %d$' % N) xlabel("Core distance [m]") ylabel("Reconstruction efficiency") #title(r"$\theta = 22.5^\circ$") legend() utils.saveplot()
def plot_full_spectrum_fit_in_density_range(self, sel, popt, low, high): bins = np.linspace(0, RANGE_MAX, N_BINS + 1) n, bins = np.histogram(sel, bins=bins) x = (bins[:-1] + bins[1:]) / 2 p_gamma, p_landau = self.constrained_full_spectrum_fit( x, n, popt[:2], popt[2:]) plt.figure() plt.plot(x * VNS, n, label='data') self.plot_landau_and_gamma(x, p_gamma, p_landau) y_charged = self.calc_charged_spectrum(x, n, p_gamma, p_landau) plt.plot(x * VNS, y_charged, label='charged particles') plt.yscale('log') plt.xlim(0, 50) plt.ylim(ymin=1) plt.xlabel("Pulse integral [V ns]") plt.ylabel("Count") plt.legend() suffix = '%.1f-%.1f' % (low, high) suffix = suffix.replace('.', '_') utils.saveplot(suffix) n = np.where(n > 0, n, 1e-99) y_charged = np.where(y_charged > 0, y_charged, 1e-99) graph = GraphArtist('semilogy') graph.histogram(n, bins * VNS, linestyle='gray') self.artistplot_alt_landau_and_gamma(graph, x, p_gamma, p_landau) graph.histogram(y_charged, bins * VNS) graph.set_xlabel(r"Pulse integral [\si{\volt\nano\second}]") graph.set_ylabel("Count") graph.set_title( r"$\SI{%.1f}{\per\square\meter} \leq \rho_\mathrm{charged}$ < $\SI{%.1f}{\per\square\meter}$" % (low, high)) graph.set_xlimits(0, 30) graph.set_ylimits(1e0, 1e4) artist.utils.save_graph(graph, suffix, dirname='plots')
def boxplot_theta_reconstruction_results_for_MIP(group, N): group = group.E_1PeV figure() angles = [0, 5, 10, 15, 22.5, 30, 35, 45] r_dtheta = [] d25, d50, d75 = [], [], [] for angle in angles: table = group._f_get_child('zenith_%s' % str(angle).replace('.', '_')) sel = table.read_where('min_n134 >= %d' % N) dtheta = sel[:]['reconstructed_theta'] - sel[:]['reference_theta'] r_dtheta.append(rad2deg(dtheta)) d25.append(scoreatpercentile(rad2deg(dtheta), 25)) d50.append(scoreatpercentile(rad2deg(dtheta), 50)) d75.append(scoreatpercentile(rad2deg(dtheta), 75)) fill_between(angles, d25, d75, color='0.75') plot(angles, d50, 'o-', color='black') xlabel(r"$\theta_{simulated}$ [deg]") ylabel(r"$\theta_{reconstructed} - \theta_{simulated}$ [deg]") #title(r"$N_{MIP} \geq %d$" % N) axhline(0, color='black') ylim(-10, 25) utils.saveplot(N) graph = GraphArtist() graph.draw_horizontal_line(0, linestyle='gray') graph.shade_region(angles, d25, d75) graph.plot(angles, d50, linestyle=None) graph.set_xlabel(r"$\theta_\mathrm{sim}$ [\si{\degree}]") graph.set_ylabel( r"$\theta_\mathrm{rec} - \theta_\mathrm{sim}$ [\si{\degree}]") graph.set_title(r"$N_\mathrm{MIP} \geq %d$" % N) graph.set_ylimits(-8, 22) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_failed_and_successful_scatter_plots(): figure(figsize=(20., 11.5)) subplot(231) plot(gdt1, rad2deg(gphis_sim), ',', c='green') plot(dt1, rad2deg(phis_sim), ',', c='red') xlabel(r"$t_1 - t_3$ [ns]") ylabel(r"$\phi_{sim}$") xlim(-200, 200) subplot(232) plot(gdt2, rad2deg(gphis_sim), ',', c='green') plot(dt2, rad2deg(phis_sim), ',', c='red') xlabel(r"$t_1 - t_4$ [ns]") ylabel(r"$\phi_{sim}$") xlim(-200, 200) subplot(234) plot(gdt1, rad2deg(gphis_rec), ',', c='green') plot(dt1, rad2deg(phis_rec), ',', c='red') xlabel(r"$t_1 - t_3$ [ns]") ylabel(r"$\phi_{rec}$") xlim(-200, 200) subplot(235) plot(gdt2, rad2deg(gphis_rec), ',', c='green') plot(dt2, rad2deg(phis_rec), ',', c='red') xlabel(r"$t_1 - t_4$ [ns]") ylabel(r"$\phi_{rec}$") xlim(-200, 200) subplot(233) plot(gdt1, gdt2, ',', c='green') plot(dt1, dt2, ',', c='red') xlabel(r"$t_1 - t_3$ [ns]") ylabel(r"$t_1 - t_4$ [ns]") xlim(-200, 200) ylim(-200, 200) utils.saveplot()
def plot_failed_and_successful_scatter_plots(): figure(figsize=(20., 11.5)) subplot(231) plot(gdt1, rad2deg(gphis_sim), ',', c='green') plot(dt1, rad2deg(phis_sim), ',', c='red') xlabel(r"$t_1 - t_3$ [ns]") ylabel(r"$\phi_{sim}$") xlim(-200, 200) subplot(232) plot(gdt2, rad2deg(gphis_sim), ',', c='green') plot(dt2, rad2deg(phis_sim), ',', c='red') xlabel(r"$t_1 - t_4$ [ns]") ylabel(r"$\phi_{sim}$") xlim(-200, 200) subplot(234) plot(gdt1, rad2deg(gphis_rec), ',', c='green') plot(dt1, rad2deg(phis_rec), ',', c='red') xlabel(r"$t_1 - t_3$ [ns]") ylabel(r"$\phi_{rec}$") xlim(-200, 200) subplot(235) plot(gdt2, rad2deg(gphis_rec), ',', c='green') plot(dt2, rad2deg(phis_rec), ',', c='red') xlabel(r"$t_1 - t_4$ [ns]") ylabel(r"$\phi_{rec}$") xlim(-200, 200) subplot(233) plot(gdt1, gdt2, ',', c='green') plot(dt1, dt2, ',', c='red') xlabel(r"$t_1 - t_3$ [ns]") ylabel(r"$t_1 - t_4$ [ns]") xlim(-200, 200) ylim(-200, 200) utils.saveplot()
def boxplot_theta_reconstruction_results_for_MIP(group, N): group = group.E_1PeV figure() angles = [0, 5, 10, 15, 22.5, 30, 35, 45] r_dtheta = [] d25, d50, d75 = [], [], [] for angle in angles: table = group._f_get_child('zenith_%s' % str(angle).replace('.', '_')) sel = table.read_where('min_n134 >= %d' % N) dtheta = sel[:]['reconstructed_theta'] - sel[:]['reference_theta'] r_dtheta.append(rad2deg(dtheta)) d25.append(scoreatpercentile(rad2deg(dtheta), 25)) d50.append(scoreatpercentile(rad2deg(dtheta), 50)) d75.append(scoreatpercentile(rad2deg(dtheta), 75)) fill_between(angles, d25, d75, color='0.75') plot(angles, d50, 'o-', color='black') xlabel(r"$\theta_{simulated}$ [deg]") ylabel(r"$\theta_{reconstructed} - \theta_{simulated}$ [deg]") #title(r"$N_{MIP} \geq %d$" % N) axhline(0, color='black') ylim(-10, 25) utils.saveplot(N) graph = GraphArtist() graph.draw_horizontal_line(0, linestyle='gray') graph.shade_region(angles, d25, d75) graph.plot(angles, d50, linestyle=None) graph.set_xlabel(r"$\theta_\mathrm{sim}$ [\si{\degree}]") graph.set_ylabel(r"$\theta_\mathrm{rec} - \theta_\mathrm{sim}$ [\si{\degree}]") graph.set_title(r"$N_\mathrm{MIP} \geq %d$" % N) graph.set_ylimits(-8, 22) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_failed_histograms(): figure() global dt1, dt2, phis c = 3e8 * 1e-9 phi1 = calc_phi(1, 3) phi2 = calc_phi(1, 4) dt1 = array(dt1) dt2 = array(dt2) phis = array(phis) subplot(121) hist(c * dt1 / (10 * cos(phis - phi1)), bins=linspace(-20, 20, 100)) xlabel(r"$c \, \Delta t_1 / (r_1 \cos(\phi - \phi_1))$") subplot(122) hist(c * dt2 / (10 * cos(phis - phi2)), bins=linspace(-20, 20, 100)) xlabel(r"$c \, \Delta t_2 / (r_2 \cos(\phi - \phi_2))$") utils.saveplot()
def plot_failed_histograms(): figure() global dt1, dt2, phis c = 3e8 * 1e-9 phi1 = calc_phi(1, 3) phi2 = calc_phi(1, 4) dt1 = array(dt1) dt2 = array(dt2) phis = array(phis) subplot(121) hist(c * dt1 / (10 * cos(phis - phi1)), bins=linspace(-20, 20, 100)) xlabel(r"$c \, \Delta t_1 / (r_1 \cos(\phi - \phi_1))$") subplot(122) hist(c * dt2 / (10 * cos(phis - phi2)), bins=linspace(-20, 20, 100)) xlabel(r"$c \, \Delta t_2 / (r_2 \cos(\phi - \phi_2))$") utils.saveplot()
def plot_theta_reconstruction_results_for_MIP(table, N): events = table.read_where('min_n134 >= N') sim_theta = events['reference_theta'] r_theta = events['reconstructed_theta'] figure() x_edges = linspace(0, 40, 81) y_edges = linspace(0, 40, 81) plot_2d_histogram(rad2deg(sim_theta), rad2deg(r_theta), (x_edges, y_edges)) xlabel(r"$\theta_K$ [deg]") ylabel(r"$\theta_H$ [deg]") title(r"$N_{MIP} \geq %d$" % N) utils.saveplot(N) graph = artist.GraphArtist() bins = linspace(0, 40, 41) H, x_edges, y_edges = histogram2d(rad2deg(sim_theta), rad2deg(r_theta), bins=bins) graph.histogram2d(H, x_edges, y_edges, type='reverse_bw') graph.set_xlabel(r'$\theta_K$ [\si{\degree}]') graph.set_ylabel(r'$\theta_H$ [\si{\degree}]') artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_theta_reconstruction_results_for_MIP(table, N): events = table.read_where('min_n134 >= N') sim_theta = events['reference_theta'] r_theta = events['reconstructed_theta'] figure() x_edges = linspace(0, 40, 81) y_edges = linspace(0, 40, 81) plot_2d_histogram(rad2deg(sim_theta), rad2deg(r_theta), (x_edges, y_edges)) xlabel(r"$\theta_K$ [deg]") ylabel(r"$\theta_H$ [deg]") title(r"$N_{MIP} \geq %d$" % N) utils.saveplot(N) graph = artist.GraphArtist() bins = linspace(0, 40, 41) H, x_edges, y_edges = histogram2d(rad2deg(sim_theta), rad2deg(r_theta), bins=bins) graph.histogram2d(H, x_edges, y_edges, type='reverse_bw') graph.set_xlabel(r'$\theta_K$ [\si{\degree}]') graph.set_ylabel(r'$\theta_H$ [\si{\degree}]') artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_reconstruction_efficiency_vs_R_for_mips(): reconstructions = data.root.reconstructions.E_1PeV.zenith_22_5 figure() bin_edges = linspace(0, 100, 10) x = (bin_edges[:-1] + bin_edges[1:]) / 2. for N in range(1, 5): shower_group = '/simulations/E_1PeV/zenith_22_5' efficiencies = [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): shower_results = [] for shower in data.list_nodes(shower_group): sel_query = '(low <= r) & (r < high)' coinc_sel = shower.coincidences.read_where(sel_query) ids = coinc_sel['id'] obs_sel = shower.observables.read_coordinates(ids) assert (obs_sel['id'] == ids).all() o = obs_sel sel = o.compress(amin(array([o['n1'], o['n3'], o['n4']]), 0) == N) shower_results.append(len(sel)) ssel = reconstructions.read_where('(min_n134 == N) & (low <= r) & (r < high)') print sum(shower_results), len(ssel), len(ssel) / sum(shower_results) efficiencies.append(len(ssel) / sum(shower_results)) plot(x, efficiencies, label=r'$N_{MIP} = %d$' % N) xlabel("Core distance [m]") ylabel("Reconstruction efficiency") #title(r"$\theta = 22.5^\circ$") legend() utils.saveplot()
def plot_sciencepark_cluster(): stations = range(501, 507) cluster = clusters.ScienceParkCluster(stations) figure() x_list, y_list = [], [] x_stations, y_stations = [], [] for station in cluster.stations: x_detectors, y_detectors = [], [] for detector in station.detectors: x, y = detector.get_xy_coordinates() x_detectors.append(x) y_detectors.append(y) scatter(x, y, c='black', s=3) x_list.extend(x_detectors) y_list.extend(y_detectors) x_stations.append(mean(x_detectors)) y_stations.append(mean(y_detectors)) axis('equal') cluster = clusters.ScienceParkCluster([501, 503, 506]) pos = [] for station in cluster.stations: x, y, alpha = station.get_xyalpha_coordinates() pos.append((x, y)) for (x0, y0), (x1, y1) in itertools.combinations(pos, 2): plot([x0, x1], [y0, y1], 'gray') utils.savedata([x_list, y_list]) utils.saveplot() artist.utils.save_data([x_list, y_list], suffix='detectors', dirname='plots') artist.utils.save_data([stations, x_stations, y_stations], suffix='stations', dirname='plots')
def boxplot_core_distances_for_mips(group): table = group.E_1PeV.zenith_22_5 figure() r_list = [] r25, r50, r75 = [], [], [] x = [] for N in range(1, 5): sel = table.read_where('min_n134 >= N') r = sel[:]['r'] r_list.append(r) x.append(N) r25.append(scoreatpercentile(r, 25)) r50.append(scoreatpercentile(r, 50)) r75.append(scoreatpercentile(r, 75)) fill_between(x, r25, r75, color='0.75') plot(x, r50, 'o-', color='black') xticks(range(1, 5)) xlabel("Minimum number of particles") ylabel("Core distance [m]") #title(r"$\theta = 22.5^\circ$") utils.saveplot() graph = GraphArtist() graph.shade_region(x, r25, r75) graph.plot(x, r50, linestyle=None) graph.set_xlabel("Minimum number of particles") graph.set_ylabel(r"Core distance [\si{\meter}]") graph.set_ylimits(min=0) graph.set_xticks(range(5)) artist.utils.save_graph(graph, dirname='plots')
def boxplot_core_distances_for_mips(group): table = group.E_1PeV.zenith_22_5 figure() r_list = [] r25, r50, r75 = [], [], [] x = [] for N in range(1, 5): sel = table.read_where('min_n134 >= N') r = sel[:]['r'] r_list.append(r) x.append(N) r25.append(scoreatpercentile(r, 25)) r50.append(scoreatpercentile(r, 50)) r75.append(scoreatpercentile(r, 75)) fill_between(x, r25, r75, color='0.75') plot(x, r50, 'o-', color='black') xticks(range(1, 5)) xlabel("Minimum number of particles") ylabel("Core distance [m]") #title(r"$\theta = 22.5^\circ$") utils.saveplot() graph = GraphArtist() graph.shade_region(x, r25, r75) graph.plot(x, r50, linestyle=None) graph.set_xlabel("Minimum number of particles") graph.set_ylabel(r"Core distance [\si{\meter}]") graph.set_ylimits(min=0) graph.set_xticks(range(5)) artist.utils.save_graph(graph, dirname='plots')
def plot_phi_reconstruction_results_for_MIP(group, N): table = group.E_1PeV.zenith_22_5 events = table.read_where('min_n134 >= %d' % N) sim_phi = events['reference_phi'] r_phi = events['reconstructed_phi'] figure() plot_2d_histogram(rad2deg(sim_phi), rad2deg(r_phi), 180) xlabel(r"$\phi_{simulated}$ [deg]") ylabel(r"$\phi_{reconstructed}$ [deg]") #title(r"$N_{MIP} \geq %d, \quad \theta = 22.5^\circ$" % N) utils.saveplot(N) graph = artist.GraphArtist() bins = linspace(-180, 180, 73) H, x_edges, y_edges = histogram2d(rad2deg(sim_phi), rad2deg(r_phi), bins=bins) graph.histogram2d(H, x_edges, y_edges, type='reverse_bw') graph.set_xlabel(r'$\phi_\mathrm{sim}$ [\si{\degree}]') graph.set_ylabel(r'$\phi_\mathrm{rec}$ [\si{\degree}]') graph.set_xticks(range(-180, 181, 90)) graph.set_yticks(range(-180, 181, 90)) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_direction_single_vs_cluster(data, station, cluster): cluster_str = [str(u) for u in cluster] theta_station, phi_station, theta_cluster, phi_cluster = \ calc_direction_single_vs_cluster(data, station, cluster) figsize = list(rcParams['figure.figsize']) figsize[1] = figsize[0] / 2 figure(figsize=figsize) subplot(121) plot(theta_station, theta_cluster, ',') xlabel(r"$\theta_{%d}$" % station) ylabel(r"$\theta_{\{%s\}}$" % ','.join(cluster_str)) xlim(0, pi / 2) ylim(0, pi / 2) subplot(122) plot(phi_station, phi_cluster, ',') xlabel(r"$\phi_{%d}$" % station) ylabel(r"$\phi_{\{%s\}}$" % ','.join(cluster_str)) xlim(-pi, pi) ylim(-pi, pi) utils.saveplot('%d-%s' % (station, '_'.join(cluster_str)))
def plot_direction_single_vs_cluster(data, station, cluster): cluster_str = [str(u) for u in cluster] theta_station, phi_station, theta_cluster, phi_cluster = \ calc_direction_single_vs_cluster(data, station, cluster) figsize = list(rcParams['figure.figsize']) figsize[1] = figsize[0] / 2 figure(figsize=figsize) subplot(121) plot(theta_station, theta_cluster, ',') xlabel(r"$\theta_{%d}$" % station) ylabel(r"$\theta_{\{%s\}}$" % ','.join(cluster_str)) xlim(0, pi / 2) ylim(0, pi / 2) subplot(122) plot(phi_station, phi_cluster, ',') xlabel(r"$\phi_{%d}$" % station) ylabel(r"$\phi_{\{%s\}}$" % ','.join(cluster_str)) xlim(-pi, pi) ylim(-pi, pi) utils.saveplot('%d-%s' % (station, '_'.join(cluster_str)))
def plot_uncertainty_mip(table): rec = DirectionReconstruction # constants for uncertainty estimation station = table.attrs.cluster.stations[0] r1, phi1 = station.calc_r_and_phi_for_detectors(1, 3) r2, phi2 = station.calc_r_and_phi_for_detectors(1, 4) THETA = deg2rad(22.5) DTHETA = deg2rad(5.) DN = .1 LOGENERGY = 15 DLOGENERGY = .5 figure() x, y, y2 = [], [], [] for N in range(1, 6): x.append(N) events = table.read_where('(abs(min_n134 - N) <= DN) & (abs(reference_theta - THETA) <= DTHETA) & (abs(log10(k_energy) - LOGENERGY) <= DLOGENERGY)') print(len(events),) errors = events['reference_theta'] - events['reconstructed_theta'] # Make sure -pi < errors < pi errors = (errors + pi) % (2 * pi) - pi errors2 = events['reference_phi'] - events['reconstructed_phi'] # Make sure -pi < errors2 < pi errors2 = (errors2 + pi) % (2 * pi) - pi #y.append(std(errors)) #y2.append(std(errors2)) y.append((scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) y2.append((scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) print() print("mip: min_n134, theta_std, phi_std") for u, v, w in zip(x, y, y2): print(u, v, w) print() # Simulation data sx, sy, sy2 = loadtxt(os.path.join(DATADIR, 'DIR-plot_uncertainty_mip.txt')) # Uncertainty estimate ex = linspace(1, 5, 50) phis = linspace(-pi, pi, 50) phi_errsq = mean(rec.rel_phi_errorsq(pi / 8, phis, phi1, phi2, r1, r2)) theta_errsq = mean(rec.rel_theta1_errorsq(pi / 8, phis, phi1, phi2, r1, r2)) #ey = TIMING_ERROR * std_t(ex) * sqrt(phi_errsq) #ey2 = TIMING_ERROR * std_t(ex) * sqrt(theta_errsq) R_list = [30, 20, 16, 14, 12] with tables.open_file('master-ch4v2.h5') as data2: mc = my_std_t_for_R(data2, x, R_list) mc = sqrt(mc ** 2 + 1.2 ** 2 + 2.5 ** 2) print(mc) ey = mc * sqrt(phi_errsq) ey2 = mc * sqrt(theta_errsq) nx = linspace(1, 4, 100) ey = spline(x, ey, nx) ey2 = spline(x, ey2, nx) # Plots plot(x, rad2deg(y), '^', label="Theta") plot(sx, rad2deg(sy), '^', label="Theta (sim)") plot(nx, rad2deg(ey2))#, label="Estimate Theta") plot(x, rad2deg(y2), 'v', label="Phi") plot(sx, rad2deg(sy2), 'v', label="Phi (sim)") plot(nx, rad2deg(ey))#, label="Estimate Phi") # Labels etc. xlabel("$N_{MIP} \pm %.1f$" % DN) ylabel("Angle reconstruction uncertainty [deg]") title(r"$\theta = 22.5^\circ \pm %d^\circ \quad %.1f \leq \log(E) \leq %.1f$" % (rad2deg(DTHETA), LOGENERGY - DLOGENERGY, LOGENERGY + DLOGENERGY)) legend(numpoints=1) xlim(0.5, 4.5) utils.saveplot() print graph = GraphArtist() graph.plot(x, rad2deg(y), mark='o', linestyle=None) graph.plot(sx, rad2deg(sy), mark='square', linestyle=None) graph.plot(nx, rad2deg(ey2), mark=None) graph.plot(x, rad2deg(y2), mark='*', linestyle=None) graph.plot(sx, rad2deg(sy2), mark='square*', linestyle=None) graph.plot(nx, rad2deg(ey), mark=None) graph.set_xlabel(r"$N_\mathrm{MIP} \pm %.1f$" % DN) graph.set_ylabel(r"Angle reconstruction uncertainty [\si{\degree}]") graph.set_xlimits(max=4.5) graph.set_ylimits(0, 40) graph.set_xticks(range(5)) artist.utils.save_graph(graph, dirname='plots')
def boxplot_core_distances_for_mips(table): THETA = deg2rad(22.5) DTHETA = deg2rad(1.) DN = .5 ENERGY = 1e15 DENERGY = 2e14 MAX_R = 80 r25_list = [] r50_list = [] r75_list = [] x = [] for N in range(1, 5): sel = table.read_where('(abs(min_n134 - N) <= DN) & (abs(reference_theta - THETA) <= DTHETA) & (abs(k_energy - ENERGY) <= DENERGY) & (r <= MAX_R)') r = sel[:]['r'] r25_list.append(scoreatpercentile(r, 25)) r50_list.append(scoreatpercentile(r, 50)) r75_list.append(scoreatpercentile(r, 75)) x.append(N) print(len(r)) sx, sr25, sr50, sr75 = loadtxt(os.path.join(DATADIR, 'DIR-save_for_kascade_boxplot_core_distances_for_mips.txt')) fig = figure() ax1 = subplot(131) fill_between(sx, sr25, sr75, color='0.75') plot(sx, sr50, 'o-', color='black', markerfacecolor='none') ax2 = subplot(132, sharex=ax1, sharey=ax1) fill_between(x, r25_list, r75_list, color='0.75') plot(x, r50_list, 'o-', color='black') ax3 = subplot(133, sharex=ax1, sharey=ax1) plot(x, sr50, 'o-', color='black', markerfacecolor='none') plot(x, r50_list, 'o-', color='black') ax2.xaxis.set_label_text("Minimum number of particles $\pm %.1f$" % DN) ax1.yaxis.set_label_text("Core distance [m]") fig.suptitle(r"$\theta = 22.5^\circ \pm %d^\circ, \quad %.1f \leq \log(E) \leq %.1f$" % (rad2deg(DTHETA), log10(ENERGY - DENERGY), log10(ENERGY + DENERGY))) ax1.xaxis.set_ticks([1, 2, 3, 4]) fig.subplots_adjust(left=.1, right=.95) ylim(ymin=0) xlim(.8, 4.2) fig.set_size_inches(5, 2.67) utils.saveplot() graph = MultiPlot(1, 3, width=r'.3\linewidth', height=r'.4\linewidth') graph.shade_region(0, 0, sx, sr25, sr75) graph.plot(0, 0, sx, sr50, linestyle=None) graph.plot(0, 2, sx, sr50) graph.set_label(0, 0, 'simulation') graph.shade_region(0, 1, x, r25_list, r75_list) graph.plot(0, 1, x, r50_list, linestyle=None, mark='*') graph.plot(0, 2, x, r50_list, mark='*') graph.set_label(0, 1, 'experiment') graph.set_label(0, 2, 'sim + exp') graph.set_ylimits(0, 50) graph.set_xlabel("Minimum number of particles $\pm %.1f$" % DN) graph.set_ylabel("Core distance [\si{\meter}]") graph.show_xticklabels_for_all([(0, 0), (0, 1), (0, 2)]) graph.show_yticklabels(0, 0) artist.utils.save_graph(graph, dirname='plots')
def plot_fav_single_vs_cluster(data): cluster = [501, 503, 506] cluster_str = [str(u) for u in cluster] width = r'.35\linewidth' graph1 = artist.MultiPlot(1, 3, width=width, height=width) graph2 = artist.MultiPlot(1, 3, width=width, height=width) figure() for n, station in enumerate(cluster, 1): theta_station, phi_station, theta_cluster, phi_cluster = \ calc_direction_single_vs_cluster(data, station, cluster, 2000) subplot(2, 3, n) plot(rad2deg(phi_station), rad2deg(phi_cluster), ',') xlabel(r"$\phi_{%d}$" % station) xlim(-180, 180) ylim(-180, 180) locator_params(tight=True, nbins=4) if n == 1: ylabel(r"$\phi_{\{%s\}}$" % ','.join(cluster_str)) bins = linspace(-180, 180, 37) H, x_edges, y_edges = histogram2d(rad2deg(phi_station), rad2deg(phi_cluster), bins=bins) graph1.histogram2d(0, n - 1, H, x_edges, y_edges, 'reverse_bw') graph1.set_label(0, n - 1, station, 'upper left', style='fill=white') subplot(2, 3, n + 3) plot(rad2deg(theta_station), rad2deg(theta_cluster), ',') xlabel(r"$\theta_{%d}$" % station) xlim(0, 45) ylim(0, 45) locator_params(tight=True, nbins=4) if n == 1: ylabel(r"$\theta_{\{%s\}}$" % ','.join(cluster_str)) bins = linspace(0, 45, 46) H, x_edges, y_edges = histogram2d(rad2deg(theta_station), rad2deg(theta_cluster), bins=bins) graph2.histogram2d(0, n - 1, H, x_edges, y_edges, 'reverse_bw') graph2.set_label(0, n - 1, station, 'upper left', style='fill=white') subplots_adjust(wspace=.4, hspace=.4) utils.saveplot() graph1.set_xticks_for_all(None, range(-180, 181, 90)) graph1.set_yticks_for_all(None, range(-180, 181, 90)) graph1.show_xticklabels_for_all(None) graph1.show_yticklabels(0, 0) graph1.set_xticklabels_position(0, 1, 'right') graph1.set_xlabel(r"Azimuthal angle (station) [\si{\degree}]") graph1.set_ylabel(r"Azimuthal angle (cluster) [\si{\degree}]") graph2.show_xticklabels_for_all(None) graph2.show_yticklabels(0, 0) graph2.set_xticklabels_position(0, 1, 'right') graph2.set_xlabel(r"Zenith angle (station) [\si{\degree}]") graph2.set_ylabel(r"Zenith angle (cluster) [\si{\degree}]") artist.utils.save_graph(graph1, suffix='phi', dirname='plots') artist.utils.save_graph(graph2, suffix='theta', dirname='plots')
def plot_fav_single_vs_single(data): cluster = [501, 503, 506] cluster_str = [str(u) for u in cluster] width = r'.35\linewidth' graph = artist.MultiPlot(3, 3, width=width, height=width) figure() for i in range(len(cluster)): for j in range(len(cluster)): station1 = cluster[i] station2 = cluster[j] theta_station1, phi_station1, theta_station2, phi_station2 = \ calc_direction_single_vs_single(data, station1, station2) subplot(3, 3, j * 3 + i + 1) if i > j: plot(rad2deg(phi_station1), rad2deg(phi_station2), ',') xlim(-180, 180) ylim(-180, 180) bins = linspace(-180, 180, 37) H, x_edges, y_edges = histogram2d(rad2deg(phi_station1), rad2deg(phi_station2), bins=bins) graph.histogram2d(j, i, H, x_edges, y_edges, 'reverse_bw') graph.set_label(j, i, r'$\phi$', 'upper left', style='fill=white') elif i < j: plot(rad2deg(theta_station1), rad2deg(theta_station2), ',') xlim(0, 45) ylim(0, 45) bins = linspace(0, 45, 46) H, x_edges, y_edges = histogram2d(rad2deg(theta_station1), rad2deg(theta_station2), bins=bins) graph.histogram2d(j, i, H, x_edges, y_edges, 'reverse_bw') graph.set_label(j, i, r'$\theta$', 'upper left', style='fill=white') if j == 2: xlabel(station1) if i == 0: ylabel(station2) locator_params(tight=True, nbins=4) #subplot(3, 3, n + 3) #plot(rad2deg(theta_station1), rad2deg(theta_station2), ',') #xlabel(r"$\theta_{%d}$" % station1) #ylabel(r"$\theta_{\{%s\}}$" % ','.join(station2_str)) #xlim(0, 45) #ylim(0, 45) #locator_params(tight=True, nbins=4) utils.saveplot() graph.set_empty_for_all([(0, 0), (1, 1), (2, 2)]) graph.show_xticklabels_for_all([(0, 1), (0, 2), (2, 0), (2, 1)]) graph.set_xticks(0, 1, range(-180, 181, 90)) graph.set_xticks(0, 2, range(-90, 181, 90)) graph.show_yticklabels_for_all([(0, 2), (1, 2), (1, 0), (2, 0)]) graph.set_yticks(1, 2, range(-180, 181, 90)) graph.set_yticks(0, 2, range(-90, 181, 90)) graph.set_xlabel(r"Shower angle [\si{\degree}]") graph.set_ylabel(r"Shower angle [\si{\degree}]") for i, station in enumerate(cluster): graph.set_label(i, i, cluster[i], 'center') artist.utils.save_graph(graph, dirname='plots')
def boxplot_arrival_times(table, N): THETA = deg2rad(0) DTHETA = deg2rad(10.) LOGENERGY = 15 DLOGENERGY = .5 bin_edges = linspace(0, 80, 5) x = [] t25, t50, t75 = [], [], [] for low, high in zip(bin_edges[:-1], bin_edges[1:]): query = '(min_n134 >= N) & (low <= r) & (r < high) & (abs(reference_theta - THETA) <= DTHETA) & (abs(log10(k_energy) - LOGENERGY) <= DLOGENERGY)' sel = table.read_where(query) t2 = sel[:]['t2'] t1 = sel[:]['t1'] ct1 = t1.compress((t1 > -999) & (t2 > -999)) ct2 = t2.compress((t1 > -999) & (t2 > -999)) print(len(t1), len(t2), len(ct1), len(ct2)) t25.append(scoreatpercentile(abs(ct2 - ct1), 25)) t50.append(scoreatpercentile(abs(ct2 - ct1), 50)) t75.append(scoreatpercentile(abs(ct2 - ct1), 75)) x.append((low + high) / 2) sx, st25, st50, st75 = loadtxt(os.path.join(DATADIR, 'DIR-boxplot_arrival_times-1.txt')) fig = figure() ax1 = subplot(131) fill_between(sx, st25, st75, color='0.75') plot(sx, st50, 'o-', color='black', markerfacecolor='none') ax2 = subplot(132, sharex=ax1, sharey=ax1) fill_between(x, t25, t75, color='0.75') plot(x, t50, 'o-', color='black') ax3 = subplot(133, sharex=ax1, sharey=ax1) plot(sx, st50, 'o-', color='black', markerfacecolor='none') plot(x, t50, 'o-', color='black') ax2.xaxis.set_label_text("Core distance [m]") ax1.yaxis.set_label_text("Arrival time difference $|t_2 - t_1|$ [ns]") fig.suptitle(r"$N_{MIP} \geq %d, \quad \theta = 0^\circ \pm %d^\circ, \quad %.1f \leq \log(E) \leq %.1f$" % (N, rad2deg(DTHETA), LOGENERGY - DLOGENERGY, LOGENERGY + DLOGENERGY)) ylim(ymax=15) xlim(xmax=80) locator_params(tight=True, nbins=4) fig.subplots_adjust(left=.1, right=.95) fig.set_size_inches(5, 2.67) utils.saveplot(N) sx = sx.compress(sx < 80) st25 = st25[:len(sx)] st50 = st50[:len(sx)] st75 = st75[:len(sx)] graph = MultiPlot(1, 3, width=r'.3\linewidth', height=r'.4\linewidth') graph.shade_region(0, 0, sx, st25, st75) graph.plot(0, 0, sx, st50, linestyle=None) graph.plot(0, 2, sx, st50) graph.set_label(0, 0, 'simulation', 'upper left') graph.shade_region(0, 1, x, t25, t75) graph.plot(0, 1, x, t50, linestyle=None, mark='*') graph.plot(0, 2, x, t50, mark='*') graph.set_label(0, 1, 'experiment', 'upper left') graph.set_label(0, 2, 'sim + exp', 'upper left') graph.set_ylimits(0, 15) graph.set_xlimits(0, 80) graph.set_xlabel("Core distance [\si{\meter}]") graph.set_ylabel(r"Arrival time difference $|t_2 - t_1|$ [\si{\nano\second}]") graph.show_xticklabels_for_all([(0, 0), (0, 1), (0, 2)]) graph.set_xticklabels_position(0, 1, 'right') graph.show_yticklabels(0, 0) artist.utils.save_graph(graph, suffix=N, dirname='plots')
def plot_fav_uncertainty_single_vs_single(data): cluster = [501, 503, 506] cluster_str = [str(u) for u in cluster] width = r'.35\linewidth' graph = artist.MultiPlot(3, 3, width=width, height=width) figure() for i in range(len(cluster)): for j in range(len(cluster)): station1 = cluster[i] station2 = cluster[j] theta_station1, phi_station1, theta_station2, phi_station2 = \ calc_direction_single_vs_single(data, station1, station2) bins = linspace(0, deg2rad(45), 11) x, y, y2 = [], [], [] for low, high in zip(bins[:-1], bins[1:]): sel_phi_c = phi_station2.compress((low <= theta_station1) & (theta_station1 < high)) sel_phi_s = phi_station1.compress((low <= theta_station1) & (theta_station1 < high)) sel_theta_c = theta_station2.compress((low <= theta_station1) & (theta_station1 < high)) sel_theta_s = theta_station1.compress((low <= theta_station1) & (theta_station1 < high)) dphi = sel_phi_s - sel_phi_c dtheta = sel_theta_s - sel_theta_c # make sure phi, theta are between -pi and pi dphi = (dphi + pi) % (2 * pi) - pi dtheta = (dtheta + pi) % (2 * pi) - pi print rad2deg((low + high) / 2), len(dphi), len(dtheta) x.append((low + high) / 2) #y.append(std(dphi)) #y2.append(std(dtheta)) y.append( (scoreatpercentile(dphi, 83) - scoreatpercentile(dphi, 17)) / 2) y2.append((scoreatpercentile(dtheta, 83) - scoreatpercentile(dtheta, 17)) / 2) ex = linspace(0, deg2rad(45), 50) ephi, etheta = [], [] for theta in ex: ephi.append(calc_phi_error_for_station_station(theta, i, j)) etheta.append(calc_theta_error_for_station_station( theta, i, j)) subplot(3, 3, j * 3 + i + 1) if i > j: plot(rad2deg(x), rad2deg(y), 'o') plot(rad2deg(ex), rad2deg(ephi)) ylim(0, 100) graph.plot(j, i, rad2deg(x), rad2deg(y), linestyle=None) graph.plot(j, i, rad2deg(ex), rad2deg(ephi), mark=None) elif i < j: plot(rad2deg(x), rad2deg(y2), 'o') plot(rad2deg(ex), rad2deg(etheta)) ylim(0, 15) graph.plot(j, i, rad2deg(x), rad2deg(y2), linestyle=None) graph.plot(j, i, rad2deg(ex), rad2deg(etheta), mark=None) xlim(0, 45) if j == 2: xlabel(station1) if i == 0: ylabel(station2) locator_params(tight=True, nbins=4) utils.saveplot() graph.set_empty_for_all([(0, 0), (1, 1), (2, 2)]) graph.set_ylimits_for_all([(0, 1), (0, 2), (1, 2)], 0, 100) graph.set_ylimits_for_all([(1, 0), (2, 0), (2, 1)], 0, 15) graph.set_xlimits_for_all(None, 0, 45) graph.show_xticklabels_for_all([(2, 0), (2, 1), (0, 2)]) graph.show_yticklabels_for_all([(0, 2), (1, 2), (1, 0), (2, 0)]) graph.set_yticks(1, 0, [5, 10, 15]) graph.set_yticks(0, 2, range(20, 101, 20)) for i, station in enumerate(cluster): graph.set_label(i, i, station, 'center') graph.set_xlabel(r'Shower zenith angle [\si{\degree}]') graph.set_ylabel(r'Angle reconstruction uncertainty [\si{\degree}]') graph.set_label(0, 1, r'$\phi$') graph.set_label(0, 2, r'$\phi$') graph.set_label(1, 2, r'$\phi$') graph.set_label(1, 0, r'$\theta$', 'upper left') graph.set_label(2, 0, r'$\theta$', 'upper left') graph.set_label(2, 1, r'$\theta$', 'upper left') artist.utils.save_graph(graph, dirname='plots')
def plot_fav_uncertainty_single_vs_cluster(data): cluster = [501, 503, 506] cluster_str = [str(u) for u in cluster] cluster_ids = [0, 2, 5] width = r'.35\linewidth' graph = artist.MultiPlot(2, 3, width=width, height=width) figure() for n, station in enumerate(cluster, 1): theta_station, phi_station, theta_cluster, phi_cluster = \ calc_direction_single_vs_cluster(data, station, cluster) bins = linspace(0, deg2rad(45), 11) x, y, y2 = [], [], [] for low, high in zip(bins[:-1], bins[1:]): sel_phi_c = phi_cluster.compress((low <= theta_station) & (theta_station < high)) sel_phi_s = phi_station.compress((low <= theta_station) & (theta_station < high)) sel_theta_c = theta_cluster.compress((low <= theta_station) & (theta_station < high)) sel_theta_s = theta_station.compress((low <= theta_station) & (theta_station < high)) dphi = sel_phi_s - sel_phi_c dtheta = sel_theta_s - sel_theta_c # make sure phi, theta are between -pi and pi dphi = (dphi + pi) % (2 * pi) - pi dtheta = (dtheta + pi) % (2 * pi) - pi print rad2deg((low + high) / 2), len(dphi), len(dtheta) x.append((low + high) / 2) #y.append(std(dphi)) #y2.append(std(dtheta)) y.append( (scoreatpercentile(dphi, 83) - scoreatpercentile(dphi, 17)) / 2) y2.append( (scoreatpercentile(dtheta, 83) - scoreatpercentile(dtheta, 17)) / 2) ex = linspace(0, deg2rad(45), 50) ephi, etheta = [], [] for theta in ex: ephi.append( calc_phi_error_for_station_cluster(theta, n, cluster_ids)) etheta.append( calc_theta_error_for_station_cluster(theta, n, cluster_ids)) subplot(2, 3, n) plot(rad2deg(x), rad2deg(y), 'o') plot(rad2deg(ex), rad2deg(ephi)) xlabel(r"$\theta_{%d}$ [deg]" % station) if n == 1: ylabel(r"$\phi$ uncertainty [deg]") ylim(0, 100) locator_params(tight=True, nbins=4) graph.plot(0, n - 1, rad2deg(x), rad2deg(y), linestyle=None) graph.plot(0, n - 1, rad2deg(ex), rad2deg(ephi), mark=None) graph.set_label(0, n - 1, r'$\phi$, %d' % station) subplot(2, 3, n + 3) plot(rad2deg(x), rad2deg(y2), 'o') plot(rad2deg(ex), rad2deg(etheta)) xlabel(r"$\theta_{%d}$ [deg]" % station) if n == 1: ylabel(r"$\theta$ uncertainty [deg]") #ylabel(r"$\theta_{\{%s\}}$" % ','.join(cluster_str)) ylim(0, 15) locator_params(tight=True, nbins=4) graph.plot(1, n - 1, rad2deg(x), rad2deg(y2), linestyle=None) graph.plot(1, n - 1, rad2deg(ex), rad2deg(etheta), mark=None) graph.set_label(1, n - 1, r'$\theta$, %d' % station) subplots_adjust(wspace=.3, hspace=.3) utils.saveplot() graph.set_xlimits_for_all(None, 0, 45) graph.set_ylimits_for_all([(0, 0), (0, 1), (0, 2)], 0, 100) graph.set_ylimits_for_all([(1, 0), (1, 1), (1, 2)], 0, 15) graph.show_xticklabels_for_all([(1, 0), (0, 1), (1, 2)]) graph.show_yticklabels_for_all([(0, 2), (1, 0)]) graph.set_xlabel(r"Shower zenith angle [\si{\degree}]") graph.set_ylabel(r"Angle reconstruction uncertainty [\si{\degree}]") artist.utils.save_graph(graph, dirname='plots')
def plot_fav_single_vs_cluster(data): cluster = [501, 503, 506] cluster_str = [str(u) for u in cluster] width = r'.35\linewidth' graph1 = artist.MultiPlot(1, 3, width=width, height=width) graph2 = artist.MultiPlot(1, 3, width=width, height=width) figure() for n, station in enumerate(cluster, 1): theta_station, phi_station, theta_cluster, phi_cluster = \ calc_direction_single_vs_cluster(data, station, cluster, 2000) subplot(2, 3, n) plot(rad2deg(phi_station), rad2deg(phi_cluster), ',') xlabel(r"$\phi_{%d}$" % station) xlim(-180, 180) ylim(-180, 180) locator_params(tight=True, nbins=4) if n == 1: ylabel(r"$\phi_{\{%s\}}$" % ','.join(cluster_str)) bins = linspace(-180, 180, 37) H, x_edges, y_edges = histogram2d(rad2deg(phi_station), rad2deg(phi_cluster), bins=bins) graph1.histogram2d(0, n - 1, H, x_edges, y_edges, 'reverse_bw') graph1.set_label(0, n - 1, station, 'upper left', style='fill=white') subplot(2, 3, n + 3) plot(rad2deg(theta_station), rad2deg(theta_cluster), ',') xlabel(r"$\theta_{%d}$" % station) xlim(0, 45) ylim(0, 45) locator_params(tight=True, nbins=4) if n == 1: ylabel(r"$\theta_{\{%s\}}$" % ','.join(cluster_str)) bins = linspace(0, 45, 46) H, x_edges, y_edges = histogram2d(rad2deg(theta_station), rad2deg(theta_cluster), bins=bins) graph2.histogram2d(0, n - 1, H, x_edges, y_edges, 'reverse_bw') graph2.set_label(0, n - 1, station, 'upper left', style='fill=white') subplots_adjust(wspace=.4, hspace=.4) utils.saveplot() graph1.set_xticks_for_all(None, range(-180, 181, 90)) graph1.set_yticks_for_all(None, range(-180, 181, 90)) graph1.show_xticklabels_for_all(None) graph1.show_yticklabels(0, 0) graph1.set_xticklabels_position(0, 1, 'right') graph1.set_xlabel(r"Azimuthal angle (station) [\si{\degree}]") graph1.set_ylabel(r"Azimuthal angle (cluster) [\si{\degree}]") graph2.show_xticklabels_for_all(None) graph2.show_yticklabels(0, 0) graph2.set_xticklabels_position(0, 1, 'right') graph2.set_xlabel(r"Zenith angle (station) [\si{\degree}]") graph2.set_ylabel(r"Zenith angle (cluster) [\si{\degree}]") artist.utils.save_graph(graph1, suffix='phi', dirname='plots') artist.utils.save_graph(graph2, suffix='theta', dirname='plots')
def hist_fav_single_stations(data): reconstructions = data.root.reconstructions.reconstructions width = r'.35\linewidth' graph1 = artist.MultiPlot(1, 3, width=width, height=width) graph2 = artist.MultiPlot(1, 3, width=width, height=width) figure() for n, station in enumerate([501, 503, 506], 1): query = '(N == 1) & s%d' % station phi = reconstructions.read_where(query, field='reconstructed_phi') theta = reconstructions.read_where(query, field='reconstructed_theta') subplot(2, 3, n) N, bins, patches = hist(rad2deg(phi), bins=linspace(-180, 180, 21), histtype='step') x = (bins[:-1] + bins[1:]) / 2 f = lambda x, a: a popt, pcov = curve_fit(f, x, N, sigma=sqrt(N)) chi2 = chisquare(N, popt[0], ddof=0) print station, popt, pcov, chi2 axhline(popt[0]) xlabel(r"$\phi$") legend([station], loc='lower right') locator_params(tight=True, nbins=4) axis('auto') graph1.histogram(0, n - 1, N, bins) graph1.set_label(0, n - 1, station) subplot(2, 3, n + 3) N, bins, patches = hist(rad2deg(theta), bins=linspace(0, 45, 21), histtype='step') xlabel(r"$\theta$") legend([station], loc='lower right') locator_params(tight=True, nbins=4) axis('auto') graph2.histogram(0, n - 1, N, bins) graph2.set_label(0, n - 1, station) subplots_adjust(wspace=.4) utils.saveplot() graph1.set_ylimits_for_all(None, 0, 1500) graph1.set_xlimits_for_all(None, -180, 180) graph1.show_yticklabels(0, 0) graph1.show_xticklabels_for_all() graph1.set_xticklabels_position(0, 1, 'right') graph1.set_xticks_for_all(None, range(-180, 181, 90)) graph1.set_xlabel(r'Shower azimuthal angle [\si{\degree}]') graph1.set_ylabel('Count') artist.utils.save_graph(graph1, suffix='phi', dirname='plots') graph2.set_ylimits_for_all(None, 0, 2000) graph2.set_xlimits_for_all(None, 0, 45) graph2.show_yticklabels(0, 0) graph2.show_xticklabels_for_all() graph2.set_xticklabels_position(0, 1, 'right') graph2.set_xlabel(r'Shower zenith angle [\si{\degree}]') graph2.set_ylabel('Count') artist.utils.save_graph(graph2, suffix='theta', dirname='plots')
def plot_uncertainty_zenith(table): rec = DirectionReconstruction # constants for uncertainty estimation station = table.attrs.cluster.stations[0] r1, phi1 = station.calc_r_and_phi_for_detectors(1, 3) r2, phi2 = station.calc_r_and_phi_for_detectors(1, 4) N = 2 DTHETA = deg2rad(1.) DN = .1 LOGENERGY = 15 DLOGENERGY = .5 figure() rcParams['text.usetex'] = False x, y, y2 = [], [], [] for theta in 5, 10, 15, 22.5, 30, 35: x.append(theta) THETA = deg2rad(theta) events = table.read_where('(min_n134 >= N) & (abs(reference_theta - THETA) <= DTHETA) & (abs(log10(k_energy) - LOGENERGY) <= DLOGENERGY)') print(theta, len(events),) errors = events['reference_theta'] - events['reconstructed_theta'] # Make sure -pi < errors < pi errors = (errors + pi) % (2 * pi) - pi errors2 = events['reference_phi'] - events['reconstructed_phi'] # Make sure -pi < errors2 < pi errors2 = (errors2 + pi) % (2 * pi) - pi #y.append(std(errors)) #y2.append(std(errors2)) y.append((scoreatpercentile(errors, 83) - scoreatpercentile(errors, 17)) / 2) y2.append((scoreatpercentile(errors2, 83) - scoreatpercentile(errors2, 17)) / 2) print() print("zenith: theta, theta_std, phi_std") for u, v, w in zip(x, y, y2): print(u, v, w) print() # Simulation data sx, sy, sy2 = loadtxt(os.path.join(DATADIR, 'DIR-plot_uncertainty_zenith.txt')) # Uncertainty estimate ex = linspace(0, deg2rad(35), 50) phis = linspace(-pi, pi, 50) ey, ey2, ey3 = [], [], [] for t in ex: ey.append(mean(rec.rel_phi_errorsq(t, phis, phi1, phi2, r1, r2))) ey3.append(mean(rec.rel_phi_errorsq(t, phis, phi1, phi2, r1, r2)) * sin(t) ** 2) ey2.append(mean(rec.rel_theta1_errorsq(t, phis, phi1, phi2, r1, r2))) ey = TIMING_ERROR * sqrt(array(ey)) ey3 = TIMING_ERROR * sqrt(array(ey3)) ey2 = TIMING_ERROR * sqrt(array(ey2)) graph = GraphArtist() # Plots plot(x, rad2deg(y), '^', label="Theta") graph.plot(x, rad2deg(y), mark='o', linestyle=None) #plot(sx, rad2deg(sy), '^', label="Theta (sim)") plot(rad2deg(ex), rad2deg(ey2))#, label="Estimate Theta") graph.plot(rad2deg(ex), rad2deg(ey2), mark=None) # Azimuthal angle undefined for zenith = 0 plot(x[1:], rad2deg(y2[1:]), 'v', label="Phi") graph.plot(x[1:], rad2deg(y2[1:]), mark='*', linestyle=None) #plot(sx[1:], rad2deg(sy2[1:]), 'v', label="Phi (sim)") plot(rad2deg(ex), rad2deg(ey))#, label="Estimate Phi") graph.plot(rad2deg(ex), rad2deg(ey), mark=None) #plot(rad2deg(ex), rad2deg(ey3), label="Estimate Phi * sin(Theta)") # Labels etc. xlabel(r"Shower zenith angle [deg $\pm %d^\circ$]" % rad2deg(DTHETA)) graph.set_xlabel(r"Shower zenith angle [\si{\degree}] $\pm \SI{%d}{\degree}$" % rad2deg(DTHETA)) ylabel("Angle reconstruction uncertainty [deg]") graph.set_ylabel(r"Angle reconstruction uncertainty [\si{\degree}]") title(r"$N_{MIP} \geq %d, \quad %.1f \leq \log(E) \leq %.1f$" % (N, LOGENERGY - DLOGENERGY, LOGENERGY + DLOGENERGY)) ylim(0, 60) graph.set_ylimits(0, 60) xlim(-.5, 37) legend(numpoints=1) if USE_TEX: rcParams['text.usetex'] = True utils.saveplot() artist.utils.save_graph(graph, dirname='plots') print
def plot_fav_single_vs_single(data): cluster = [501, 503, 506] cluster_str = [str(u) for u in cluster] width = r'.35\linewidth' graph = artist.MultiPlot(3, 3, width=width, height=width) figure() for i in range(len(cluster)): for j in range(len(cluster)): station1 = cluster[i] station2 = cluster[j] theta_station1, phi_station1, theta_station2, phi_station2 = \ calc_direction_single_vs_single(data, station1, station2) subplot(3, 3, j * 3 + i + 1) if i > j: plot(rad2deg(phi_station1), rad2deg(phi_station2), ',') xlim(-180, 180) ylim(-180, 180) bins = linspace(-180, 180, 37) H, x_edges, y_edges = histogram2d(rad2deg(phi_station1), rad2deg(phi_station2), bins=bins) graph.histogram2d(j, i, H, x_edges, y_edges, 'reverse_bw') graph.set_label(j, i, r'$\phi$', 'upper left', style='fill=white') elif i < j: plot(rad2deg(theta_station1), rad2deg(theta_station2), ',') xlim(0, 45) ylim(0, 45) bins = linspace(0, 45, 46) H, x_edges, y_edges = histogram2d(rad2deg(theta_station1), rad2deg(theta_station2), bins=bins) graph.histogram2d(j, i, H, x_edges, y_edges, 'reverse_bw') graph.set_label(j, i, r'$\theta$', 'upper left', style='fill=white') if j == 2: xlabel(station1) if i == 0: ylabel(station2) locator_params(tight=True, nbins=4) #subplot(3, 3, n + 3) #plot(rad2deg(theta_station1), rad2deg(theta_station2), ',') #xlabel(r"$\theta_{%d}$" % station1) #ylabel(r"$\theta_{\{%s\}}$" % ','.join(station2_str)) #xlim(0, 45) #ylim(0, 45) #locator_params(tight=True, nbins=4) utils.saveplot() graph.set_empty_for_all([(0, 0), (1, 1), (2, 2)]) graph.show_xticklabels_for_all([(0, 1), (0, 2), (2, 0), (2, 1)]) graph.set_xticks(0, 1, range(-180, 181, 90)) graph.set_xticks(0, 2, range(-90, 181, 90)) graph.show_yticklabels_for_all([(0, 2), (1, 2), (1, 0), (2, 0)]) graph.set_yticks(1, 2, range(-180, 181, 90)) graph.set_yticks(0, 2, range(-90, 181, 90)) graph.set_xlabel(r"Shower angle [\si{\degree}]") graph.set_ylabel(r"Shower angle [\si{\degree}]") for i, station in enumerate(cluster): graph.set_label(i, i, cluster[i], 'center') artist.utils.save_graph(graph, dirname='plots')
def plot_fav_uncertainty_single_vs_cluster(data): cluster = [501, 503, 506] cluster_str = [str(u) for u in cluster] cluster_ids = [0, 2, 5] width = r'.35\linewidth' graph = artist.MultiPlot(2, 3, width=width, height=width) figure() for n, station in enumerate(cluster, 1): theta_station, phi_station, theta_cluster, phi_cluster = \ calc_direction_single_vs_cluster(data, station, cluster) bins = linspace(0, deg2rad(45), 11) x, y, y2 = [], [], [] for low, high in zip(bins[:-1], bins[1:]): sel_phi_c = phi_cluster.compress((low <= theta_station) & (theta_station < high)) sel_phi_s = phi_station.compress((low <= theta_station) & (theta_station < high)) sel_theta_c = theta_cluster.compress((low <= theta_station) & (theta_station < high)) sel_theta_s = theta_station.compress((low <= theta_station) & (theta_station < high)) dphi = sel_phi_s - sel_phi_c dtheta = sel_theta_s - sel_theta_c # make sure phi, theta are between -pi and pi dphi = (dphi + pi) % (2 * pi) - pi dtheta = (dtheta + pi) % (2 * pi) - pi print rad2deg((low + high) / 2), len(dphi), len(dtheta) x.append((low + high) / 2) #y.append(std(dphi)) #y2.append(std(dtheta)) y.append((scoreatpercentile(dphi, 83) - scoreatpercentile(dphi, 17)) / 2) y2.append((scoreatpercentile(dtheta, 83) - scoreatpercentile(dtheta, 17)) / 2) ex = linspace(0, deg2rad(45), 50) ephi, etheta = [], [] for theta in ex: ephi.append(calc_phi_error_for_station_cluster(theta, n, cluster_ids)) etheta.append(calc_theta_error_for_station_cluster(theta, n, cluster_ids)) subplot(2, 3, n) plot(rad2deg(x), rad2deg(y), 'o') plot(rad2deg(ex), rad2deg(ephi)) xlabel(r"$\theta_{%d}$ [deg]" % station) if n == 1: ylabel(r"$\phi$ uncertainty [deg]") ylim(0, 100) locator_params(tight=True, nbins=4) graph.plot(0, n - 1, rad2deg(x), rad2deg(y), linestyle=None) graph.plot(0, n - 1, rad2deg(ex), rad2deg(ephi), mark=None) graph.set_label(0, n - 1, r'$\phi$, %d' % station) subplot(2, 3, n + 3) plot(rad2deg(x), rad2deg(y2), 'o') plot(rad2deg(ex), rad2deg(etheta)) xlabel(r"$\theta_{%d}$ [deg]" % station) if n == 1: ylabel(r"$\theta$ uncertainty [deg]") #ylabel(r"$\theta_{\{%s\}}$" % ','.join(cluster_str)) ylim(0, 15) locator_params(tight=True, nbins=4) graph.plot(1, n - 1, rad2deg(x), rad2deg(y2), linestyle=None) graph.plot(1, n - 1, rad2deg(ex), rad2deg(etheta), mark=None) graph.set_label(1, n - 1, r'$\theta$, %d' % station) subplots_adjust(wspace=.3, hspace=.3) utils.saveplot() graph.set_xlimits_for_all(None, 0, 45) graph.set_ylimits_for_all([(0, 0), (0, 1), (0, 2)], 0, 100) graph.set_ylimits_for_all([(1, 0), (1, 1), (1, 2)], 0, 15) graph.show_xticklabels_for_all([(1, 0), (0, 1), (1, 2)]) graph.show_yticklabels_for_all([(0, 2), (1, 0)]) graph.set_xlabel(r"Shower zenith angle [\si{\degree}]") graph.set_ylabel(r"Angle reconstruction uncertainty [\si{\degree}]") artist.utils.save_graph(graph, dirname='plots')
def plot_fav_uncertainty_single_vs_single(data): cluster = [501, 503, 506] cluster_str = [str(u) for u in cluster] width = r'.35\linewidth' graph = artist.MultiPlot(3, 3, width=width, height=width) figure() for i in range(len(cluster)): for j in range(len(cluster)): station1 = cluster[i] station2 = cluster[j] theta_station1, phi_station1, theta_station2, phi_station2 = \ calc_direction_single_vs_single(data, station1, station2) bins = linspace(0, deg2rad(45), 11) x, y, y2 = [], [], [] for low, high in zip(bins[:-1], bins[1:]): sel_phi_c = phi_station2.compress((low <= theta_station1) & (theta_station1 < high)) sel_phi_s = phi_station1.compress((low <= theta_station1) & (theta_station1 < high)) sel_theta_c = theta_station2.compress((low <= theta_station1) & (theta_station1 < high)) sel_theta_s = theta_station1.compress((low <= theta_station1) & (theta_station1 < high)) dphi = sel_phi_s - sel_phi_c dtheta = sel_theta_s - sel_theta_c # make sure phi, theta are between -pi and pi dphi = (dphi + pi) % (2 * pi) - pi dtheta = (dtheta + pi) % (2 * pi) - pi print rad2deg((low + high) / 2), len(dphi), len(dtheta) x.append((low + high) / 2) #y.append(std(dphi)) #y2.append(std(dtheta)) y.append((scoreatpercentile(dphi, 83) - scoreatpercentile(dphi, 17)) / 2) y2.append((scoreatpercentile(dtheta, 83) - scoreatpercentile(dtheta, 17)) / 2) ex = linspace(0, deg2rad(45), 50) ephi, etheta = [], [] for theta in ex: ephi.append(calc_phi_error_for_station_station(theta, i, j)) etheta.append(calc_theta_error_for_station_station(theta, i, j)) subplot(3, 3, j * 3 + i + 1) if i > j: plot(rad2deg(x), rad2deg(y), 'o') plot(rad2deg(ex), rad2deg(ephi)) ylim(0, 100) graph.plot(j, i, rad2deg(x), rad2deg(y), linestyle=None) graph.plot(j, i, rad2deg(ex), rad2deg(ephi), mark=None) elif i < j: plot(rad2deg(x), rad2deg(y2), 'o') plot(rad2deg(ex), rad2deg(etheta)) ylim(0, 15) graph.plot(j, i, rad2deg(x), rad2deg(y2), linestyle=None) graph.plot(j, i, rad2deg(ex), rad2deg(etheta), mark=None) xlim(0, 45) if j == 2: xlabel(station1) if i == 0: ylabel(station2) locator_params(tight=True, nbins=4) utils.saveplot() graph.set_empty_for_all([(0, 0), (1, 1), (2, 2)]) graph.set_ylimits_for_all([(0, 1), (0, 2), (1, 2)], 0, 100) graph.set_ylimits_for_all([(1, 0), (2, 0), (2, 1)], 0, 15) graph.set_xlimits_for_all(None, 0, 45) graph.show_xticklabels_for_all([(2, 0), (2, 1), (0, 2)]) graph.show_yticklabels_for_all([(0, 2), (1, 2), (1, 0), (2, 0)]) graph.set_yticks(1, 0, [5, 10, 15]) graph.set_yticks(0, 2, range(20, 101, 20)) for i, station in enumerate(cluster): graph.set_label(i, i, station, 'center') graph.set_xlabel(r'Shower zenith angle [\si{\degree}]') graph.set_ylabel(r'Angle reconstruction uncertainty [\si{\degree}]') graph.set_label(0, 1, r'$\phi$') graph.set_label(0, 2, r'$\phi$') graph.set_label(1, 2, r'$\phi$') graph.set_label(1, 0, r'$\theta$', 'upper left') graph.set_label(2, 0, r'$\theta$', 'upper left') graph.set_label(2, 1, r'$\theta$', 'upper left') artist.utils.save_graph(graph, dirname='plots')
def hist_fav_single_stations(data): reconstructions = data.root.reconstructions.reconstructions width = r'.35\linewidth' graph1 = artist.MultiPlot(1, 3, width=width, height=width) graph2 = artist.MultiPlot(1, 3, width=width, height=width) figure() for n, station in enumerate([501, 503, 506], 1): query = '(N == 1) & s%d' % station phi = reconstructions.read_where(query, field='reconstructed_phi') theta = reconstructions.read_where(query, field='reconstructed_theta') subplot(2, 3, n) N, bins, patches = hist(rad2deg(phi), bins=linspace(-180, 180, 21), histtype='step') x = (bins[:-1] + bins[1:]) / 2 f = lambda x, a: a popt, pcov = curve_fit(f, x, N, sigma=sqrt(N)) chi2 = chisquare(N, popt[0], ddof=0) print station, popt, pcov, chi2 axhline(popt[0]) xlabel(r"$\phi$") legend([station], loc='lower right') locator_params(tight=True, nbins=4) axis('auto') graph1.histogram(0, n - 1, N, bins) graph1.set_label(0, n - 1, station) subplot(2, 3, n + 3) N, bins, patches = hist(rad2deg(theta), bins=linspace(0, 45, 21), histtype='step') xlabel(r"$\theta$") legend([station], loc='lower right') locator_params(tight=True, nbins=4) axis('auto') graph2.histogram(0, n - 1, N, bins) graph2.set_label(0, n - 1, station) subplots_adjust(wspace=.4) utils.saveplot() graph1.set_ylimits_for_all(None, 0, 1500) graph1.set_xlimits_for_all(None, -180, 180) graph1.show_yticklabels(0, 0) graph1.show_xticklabels_for_all() graph1.set_xticklabels_position(0, 1, 'right') graph1.set_xticks_for_all(None, range(-180, 181, 90)) graph1.set_xlabel(r'Shower azimuthal angle [\si{\degree}]') graph1.set_ylabel('Count') artist.utils.save_graph(graph1, suffix='phi', dirname='plots') graph2.set_ylimits_for_all(None, 0, 2000) graph2.set_xlimits_for_all(None, 0, 45) graph2.show_yticklabels(0, 0) graph2.show_xticklabels_for_all() graph2.set_xticklabels_position(0, 1, 'right') graph2.set_xlabel(r'Shower zenith angle [\si{\degree}]') graph2.set_ylabel('Count') artist.utils.save_graph(graph2, suffix='theta', dirname='plots')