def histogram_max_abort_gap_before_OML(fills): max_ag = {1: [], 2: []} for nbr in fills: for beam in (1, 2): fill = Fill(nbr, beam=beam) OML_start = fill.OML_period()[0] max_ag[beam].append(fill.abort_gap().y[:OML_start].max()) bins = np.arange(0, 2e10, 2e9) fig, ax = plt.subplots() ax.hist([max_ag[1], max_ag[2]], bins=bins, label=["Beam 1", "Beam 2"]) ax.legend(loc="upper right") ax.set_ylabel("Fill count") ax.set_xlabel("Abort gap intensity [$ 10^9 $]") ax.xaxis.set_major_formatter( FuncFormatter(lambda x, pos: "{0:.1f}".format(x / 1e9))) plt.title("Max abort gap intensity before start of ramp") plt.show()
def comp_blm_ir3_vs_abort_gap(file): fills = fills_from_file(file, "OML") abort_gap = [] average_loss = [] max_loss = [] for nbr in fills: fill = Fill(nbr, False) fill.fetch() smin, smax = fill.OML_period() # Only looking until t_co instead -- will not affect max smax = fill.crossover_point()['i'] tmax = fill.blm_ir3().x[smax] tmin = fill.blm_ir3().x[smin] # tmax = find_crossover_point(fill)['t'] ag_average = moving_average(fill.abort_gap().y, 5) agmin = fill.abort_gap().index_for_time(tmin) agmax = fill.abort_gap().index_for_time(tmax) ssubset = fill.blm_ir3().y[smin:smax] average_loss.append(np.average(ssubset)) max_loss.append(max(ssubset)) abort_gap.append(ag_average[agmin] - ag_average[agmax]) fig = plt.figure() ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122, sharey=ax1) # fig1, ax1 = plt.subplots() ax1.set_xlabel("Average BLM") ax1.set_ylabel("∆ abort gap intensity") ax1.scatter(average_loss, abort_gap, color='b', label='average') ax1.set_xlim([0, 1.1 * max(average_loss)]) ax1.set_ylim([0, 1.1 * max(abort_gap)]) xval = [0, 1] slope, intercept, r_value, p_value, std_err = stats.linregress( average_loss, abort_gap) print("Average fit") print( "\tk ={:>10.3E}\n\tm ={:>10.3E}\n\tr ={:>10.7f}\n\tp ={:>10.3E}\n\te^2={:>10.3E}" .format(slope, intercept, r_value, p_value, std_err)) yfit = [slope * x + intercept for x in xval] ax1.plot(xval, yfit, color='gray') ax1.legend(loc="lower right") # fig2, ax2 = plt.subplots() ax2.set_xlabel("Max BLM") ax2.scatter(max_loss, abort_gap, color='r', label='max') ax2.set_xlim([0, 1.1 * max(max_loss)]) ax2.legend(loc="lower right") slope, intercept, r_value, p_value, std_err = stats.linregress( max_loss, abort_gap) print("Max fit") print( "\tk ={:>10.3E}\n\tm ={:>10.3E}\n\tr ={:>10.7f}\n\tp ={:>10.3E}\n\te^2={:>10.3E}" .format(slope, intercept, r_value, p_value, std_err)) yfit = [slope * x + intercept for x in xval] ax2.plot(xval, yfit, color='gray') fig.suptitle( "Correlation between abort gap intensity and BLM signal for TCP in IR3" ) plt.show()