def plot_arrival_times(): graph = GraphArtist() figure() sim = data.root.showers.E_1PeV.zenith_22_5 t = get_front_arrival_time(sim, 20, 5, pi / 8) n, bins = histogram(t, bins=linspace(0, 50, 201)) mct = monte_carlo_timings(n, bins, 100000) n, bins, patches = hist(mct, bins=linspace(0, 20, 101), histtype='step') graph.histogram(n, bins, linestyle='black!50') mint = my_t_draw_something(data, 2, 100000) n, bins, patches = hist(mint, bins=linspace(0, 20, 101), histtype='step') graph.histogram(n, bins) xlabel("Arrival time [ns]") ylabel("Number of events") graph.set_xlabel(r"Arrival time [\si{\nano\second}]") graph.set_ylabel("Number of events") graph.set_xlimits(0, 20) graph.set_ylimits(min=0) graph.save('plots/SIM-T') print median(t), median(mct), median(mint)
def plot_arrival_times(): graph = GraphArtist() figure() sim = data.root.showers.E_1PeV.zenith_22_5 t = get_front_arrival_time(sim, 20, 5, pi / 8) n, bins = histogram(t, bins=linspace(0, 50, 201)) mct = monte_carlo_timings(n, bins, 100000) n, bins, patches = hist(mct, bins=linspace(0, 20, 101), histtype='step') graph.histogram(n, bins, linestyle='black!50') mint = my_t_draw_something(data, 2, 100000) n, bins, patches = hist(mint, bins=linspace(0, 20, 101), histtype='step') graph.histogram(n, bins) xlabel("Arrival time [ns]") ylabel("Number of events") graph.set_xlabel(r"Arrival time [\si{\nano\second}]") graph.set_ylabel("Number of events") graph.set_xlimits(0, 20) graph.set_ylimits(min=0) graph.save('plots/SIM-T') print(median(t), median(mct), median(mint))
def plot_R(): graph = GraphArtist(width=r'.45\linewidth') n, bins, patches = hist( data.root.simulations.E_1PeV.zenith_22_5.shower_0.coincidences.col( 'r'), bins=100, histtype='step') graph.histogram(n, bins, linestyle='black!50') shower = data.root.simulations.E_1PeV.zenith_22_5.shower_0 ids = shower.observables.get_where_list( '(n1 >= 1) & (n3 >= 1) & (n4 >= 1)') R = shower.coincidences.read_coordinates(ids, field='r') n, bins, patches = hist(R, bins=100, histtype='step') graph.histogram(n, bins) xlabel("Core distance [m]") ylabel("Number of events") print "mean", mean(R) print "median", median(R) graph.set_xlabel(r"Core distance [\si{\meter}]") graph.set_ylabel("Number of events") graph.set_xlimits(min=0) graph.set_ylimits(min=0) graph.save('plots/SIM-R')
def plot_pulseheight_histogram(data): events = data.root.hisparc.cluster_kascade.station_601.events ph = events.col('pulseheights') s = landau.Scintillator() mev_scale = 3.38 / 340 count_scale = 6e3 / .32 clf() n, bins, patches = hist(ph[:, 0], bins=arange(0, 1501, 10), histtype='step') x = linspace(0, 1500, 1500) plot(x, s.conv_landau_for_x(x, mev_scale=mev_scale, count_scale=count_scale)) plot(x, count_scale * s.landau_pdf(x * mev_scale)) ylim(ymax=25000) xlim(xmax=1500) # Remove one statistical fluctuation from data. It is not important # for the graph, but it detracts from the main message index = bins.searchsorted(370) n[index] = mean([n[index - 1], n[index + 1]]) graph = GraphArtist() n_trunc = where(n <= 100000, n, 100000) graph.histogram(n_trunc, bins, linestyle='gray') graph.add_pin('data', x=800, location='above right', use_arrow=True) graph.add_pin('$\gamma$', x=90, location='above right', use_arrow=True) graph.plot(x, s.conv_landau_for_x(x, mev_scale=mev_scale, count_scale=count_scale), mark=None) graph.add_pin('convolved Landau', x=450, location='above right', use_arrow=True) graph.plot(x, count_scale * s.landau_pdf(x * mev_scale), mark=None, linestyle='black') graph.add_pin('Landau', x=380, location='above right', use_arrow=True) graph.set_xlabel(r"Pulseheight [\adc{}]") graph.set_ylabel(r"Number of events") graph.set_xlimits(0, 1400) graph.set_ylimits(0, 21000) graph.save("plots/plot_pulseheight_histogram")
def plot_nearest_neighbors(data, limit=None): global coincidences hisparc_group = data.root.hisparc.cluster_kascade.station_601 kascade_group = data.root.kascade coincidences = KascadeCoincidences(data, hisparc_group, kascade_group, ignore_existing=True) #dt_opt = find_optimum_dt(coincidences, p0=-13, limit=1000) #print(dt_opt) graph = GraphArtist(axis='semilogy') styles = iter(['solid', 'dashed', 'dashdotted']) uncorrelated = None figure() #for shift in -12, -13, dt_opt, -14: for shift in -12, -13, -14: print("Shifting", shift) coincidences.search_coincidences(shift, dtlimit=1, limit=limit) print(".") dts = coincidences.coincidences['dt'] n, bins, p = hist(abs(dts) / 1e9, bins=linspace(0, 1, 101), histtype='step', label='%.3f s' % shift) n = [u if u else 1e-99 for u in n] graph.histogram(n, bins, linestyle=styles.next() + ',gray') if uncorrelated is None: uncorrelated = n, bins y, bins = uncorrelated x = (bins[:-1] + bins[1:]) / 2 f = lambda x, N, a: N * exp(-a * x) popt, pcov = curve_fit(f, x, y) plot(x, f(x, *popt), label=r"$\lambda = %.2f$ Hz" % popt[1]) graph.plot(x, f(x, *popt), mark=None) yscale('log') xlabel("Time difference [s]") graph.set_xlabel(r"Time difference [\si{\second}]") ylabel("Counts") graph.set_ylabel("Counts") legend() graph.set_ylimits(min=10) utils.saveplot() graph.save('plots/MAT-nearest-neighbors')
def plot_nearest_neighbors(data, limit=None): global coincidences hisparc_group = data.root.hisparc.cluster_kascade.station_601 kascade_group = data.root.kascade coincidences = KascadeCoincidences(data, hisparc_group, kascade_group, ignore_existing=True) #dt_opt = find_optimum_dt(coincidences, p0=-13, limit=1000) #print dt_opt graph = GraphArtist(axis='semilogy') styles = iter(['solid', 'dashed', 'dashdotted']) uncorrelated = None figure() #for shift in -12, -13, dt_opt, -14: for shift in -12, -13, -14: print "Shifting", shift coincidences.search_coincidences(shift, dtlimit=1, limit=limit) print "." dts = coincidences.coincidences['dt'] n, bins, p = hist(abs(dts) / 1e9, bins=linspace(0, 1, 101), histtype='step', label='%.3f s' % shift) n = [u if u else 1e-99 for u in n] graph.histogram(n, bins, linestyle=styles.next() + ',gray') if uncorrelated is None: uncorrelated = n, bins y, bins = uncorrelated x = (bins[:-1] + bins[1:]) / 2 f = lambda x, N, a: N * exp(-a * x) popt, pcov = curve_fit(f, x, y) plot(x, f(x, *popt), label=r"$\lambda = %.2f$ Hz" % popt[1]) graph.plot(x, f(x, *popt), mark=None) yscale('log') xlabel("Time difference [s]") graph.set_xlabel(r"Time difference [\si{\second}]") ylabel("Counts") graph.set_ylabel("Counts") legend() graph.set_ylimits(min=10) utils.saveplot() graph.save('plots/MAT-nearest-neighbors')
def plot_front_passage(): sim = data.root.showers.E_1PeV.zenith_0.shower_0 leptons = sim.leptons R = 40 dR = 2 low = R - dR high = R + dR global t t = leptons.read_where('(low < core_distance) & (core_distance <= high)', field='arrival_time') n, bins, patches = hist(t, bins=linspace(0, 30, 31), histtype='step') graph = GraphArtist() graph.histogram(n, bins) graph.set_xlabel(r"Arrival time [\si{\nano\second}]") graph.set_ylabel("Number of leptons") graph.set_ylimits(min=0) graph.set_xlimits(0, 30) graph.save('plots/front-passage')
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_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 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_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 plot_R(): graph = GraphArtist(width=r'.45\linewidth') n, bins, patches = hist(data.root.simulations.E_1PeV.zenith_22_5.shower_0.coincidences.col('r'), bins=100, histtype='step') graph.histogram(n, bins, linestyle='black!50') shower = data.root.simulations.E_1PeV.zenith_22_5.shower_0 ids = shower.observables.get_where_list('(n1 >= 1) & (n3 >= 1) & (n4 >= 1)') R = shower.coincidences.read_coordinates(ids, field='r') n, bins, patches = hist(R, bins=100, histtype='step') graph.histogram(n, bins) xlabel("Core distance [m]") ylabel("Number of events") print("mean", mean(R)) print("median", median(R)) graph.set_xlabel(r"Core distance [\si{\meter}]") graph.set_ylabel("Number of events") graph.set_xlimits(min=0) graph.set_ylimits(min=0) graph.save('plots/SIM-R')
def plot_pulseheight_histogram(data): events = data.root.hisparc.cluster_kascade.station_601.events ph = events.col("pulseheights") s = landau.Scintillator() mev_scale = 3.38 / 340 count_scale = 6e3 / 0.32 clf() n, bins, patches = hist(ph[:, 0], bins=arange(0, 1501, 10), histtype="step") x = linspace(0, 1500, 1500) plot(x, s.conv_landau_for_x(x, mev_scale=mev_scale, count_scale=count_scale)) plot(x, count_scale * s.landau_pdf(x * mev_scale)) ylim(ymax=25000) xlim(xmax=1500) # Remove one statistical fluctuation from data. It is not important # for the graph, but it detracts from the main message index = bins.searchsorted(370) n[index] = mean([n[index - 1], n[index + 1]]) graph = GraphArtist() n_trunc = where(n <= 100000, n, 100000) graph.histogram(n_trunc, bins, linestyle="gray") graph.add_pin("data", x=800, location="above right", use_arrow=True) graph.add_pin("$\gamma$", x=90, location="above right", use_arrow=True) graph.plot(x, s.conv_landau_for_x(x, mev_scale=mev_scale, count_scale=count_scale), mark=None) graph.add_pin("convolved Landau", x=450, location="above right", use_arrow=True) graph.plot(x, count_scale * s.landau_pdf(x * mev_scale), mark=None, linestyle="black") graph.add_pin("Landau", x=380, location="above right", use_arrow=True) graph.set_xlabel(r"Pulseheight [\adc{}]") graph.set_ylabel(r"Number of events") graph.set_xlimits(0, 1400) graph.set_ylimits(0, 21000) graph.save("plots/plot_pulseheight_histogram")