Beispiel #1
0
def histogram_spike_duration(file):
    fills = fills_from_file(file, "OML")
    outliers = []
    durations = []
    for nbr in fills:
        fill = Fill(nbr)

        start, end = fill.OML_period()
        d = fill.blm_ir7().x[end] - fill.blm_ir7().x[start]
        if d < 70 or d > 300:
            outliers.append(nbr)
        durations.append(d)

    draw_histogram('Spike duration for {}'.format(file), durations, 10,
                   'Seconds', 'Count')
    return outliers
Beispiel #2
0
def histogram_intensity_lost_during_OML(fills, beam):
    agg_fill = aggregate_fill(beam=beam, from_cache=True)
    t_agg = agg_fill.blm_ir3().x[agg_fill.OML_period()]

    lost_agg_period = np.empty(len(fills))
    lost_fill_period = np.empty(len(fills))
    total_lost_during_ramp = np.empty(len(fills))

    for i, nbr in enumerate(fills):
        fill = Fill(nbr)

        a_index = fill.intensity().index_for_time(t_agg)
        int_agg = fill.intensity().y[a_index]
        lost_agg_period[i] = int_agg[0] - int_agg[1]

        f_index = fill.intensity().index_for_time(
            fill.blm_ir3().x[fill.OML_period()])
        int_fill = fill.intensity().y[f_index]
        lost_fill_period[i] = int_fill[0] - int_fill[1]

        total_lost_during_ramp[i] = fill.intensity().y[0] - fill.intensity(
        ).y[-1]

    fig, ax = plt.subplots()
    ax.hist((lost_agg_period, lost_fill_period),
            label=("Aggregate OML period", "Fill OML period"),
            edgecolor='white')
    # ax.hist((lost_agg_period,), label=("Aggregate OML period",) , edgecolor='white')
    ax.legend(loc='upper right')
    ax.xaxis.set_major_formatter(
        FuncFormatter(lambda x, pos: "{0:.2f}".format(x * 100.0)))
    ax.set_xlabel("Intensity lost (%)")
    ax.set_ylabel("# fills")
    plt.title(
        "Intensity during off-momentum loss peak at start of ramp (beam {})".
        format(beam))
    # ax.hist(lost_fill_period, edgecolor='white')

    fig2, ax2 = plt.subplots()
    ax2.hist(total_lost_during_ramp, edgecolor='white')
    ax2.xaxis.set_major_formatter(
        FuncFormatter(lambda x, pos: "{0:.2f}".format(x * 100.0)))
    ax2.set_xlabel("Intensity lost (%)")
    ax2.set_ylabel("# fills")
    plt.title("Total intensity lost during whole ramp (beam {})".format(beam))

    plt.show()
Beispiel #3
0
def comp_blm_ir3_vs_intensity(file):
    fills = fills_from_file(file, "OML")
    intensity = []
    mean_loss = []
    max_loss = []
    discarded = 0
    for nbr in fills:
        fill = Fill(nbr, False)
        fill.fetch()
        smin, smax = fill.OML_period()
        ssubset = fill.blm_ir3().y[smin:smax]

        maxint = max(fill.intensity().y)
        if maxint < 1.8e14:
            discarded += 1
            continue

        mean_loss.append(np.mean(ssubset))
        max_loss.append(max(ssubset))
        intensity.append(maxint)

    fig = plt.figure()
    ax1 = fig.add_subplot(121)
    ax2 = fig.add_subplot(122, sharey=ax1)

    ax1.set_xlabel("Mean momentum (IR3) TCP")
    ax1.set_ylabel("Intensity")
    ax1.scatter(mean_loss, intensity, color='b', label='mean')
    ax1.set_xlim([0, 1.1 * max(mean_loss)])
    ax1.set_ylim([1.5e14, 1.1 * max(intensity)])
    ax1.legend(loc="lower right")

    ax2.set_xlabel("Max momentum (IR3) TCP")
    ax2.set_ylabel("Intensity")
    ax2.scatter(max_loss, intensity, color='r', label='max')
    ax2.set_xlim([0, 1.1 * max(max_loss)])
    ax2.legend(loc="lower right")

    percent_used = int(
        round(float(len(intensity)) / (len(intensity) + discarded) * 100))
    fig.suptitle(
        "Intensity vs OML for {} (only intenities > 1.8e14, {}% of total)\n".
        format(file, percent_used))

    plt.show()
Beispiel #4
0
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()
Beispiel #5
0
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()
Beispiel #6
0
def comp_blm_ir3_vs_ir7(file):
    fills = fills_from_file(file, "OML")
    ok = 0
    notok = 0
    sdata = {
        'max': [],
        'mean': [],
    }
    bdata = {'max': [], 'mean': []}
    for nbr in fills:
        fill = Fill(nbr)
        fill.beta_coll_merge()

        smin, smax = fill.OML_period()
        tmin, tmax = fill.blm_ir3().x[[smin, smax]]
        bmin = fill.blm_ir7().index_for_time(tmin)
        bmax = fill.blm_ir7().index_for_time(tmax)

        bsubset = fill.blm_ir7().y[bmin:bmax]
        ssubset = fill.blm_ir3().y[smin:smax]

        sdata['max'].append(max(ssubset))
        sdata['mean'].append(np.mean(ssubset))
        bdata['max'].append(max(bsubset))
        bdata['mean'].append(np.mean(bsubset))

    fig, ax = plt.subplots()
    ax.set_xlabel("Synchrotron (IR3) TCP")
    ax.set_ylabel("Betatron (IR7) TCPs")

    ax.scatter(sdata['max'], bdata['max'], color='r')
    slope, intercept, r_value, p_value, std_err = stats.linregress(
        sdata['max'], bdata['max'])
    # print(slope, intercept, r_value, p_value, std_err)
    xval = [0, 1]
    max_yval = [slope * x + intercept for x in xval]
    ax.plot(xval, max_yval, color='r', label='max')

    ax.scatter(sdata['mean'], bdata['mean'], color='b')
    slope, intercept, r_value, p_value, std_err = stats.linregress(
        sdata['mean'], bdata['mean'])
    # print(slope, intercept, r_value, p_value, std_err)
    mean_yval = [slope * x + intercept for x in xval]
    ax.plot(xval, mean_yval, color='b', label='mean')

    ax.plot([0, 1], [0, 1], color='black', label='delimiter')

    for v in ['max', 'mean']:
        count = 0
        for i, sd in enumerate(sdata[v]):
            if bdata[v][i] > sd:
                count += 1
        print(v, "over: ", count,
              "({}%)".format(int(float(count) / len(sdata[v]) * 100)))

    plt.title(
        'Losses due to synchrotron vs betatron oscillations\n for {}'.format(
            file))
    ax.legend(loc='upper right')
    ax.set_ylim([0, 0.5])
    ax.set_xlim([0, 0.5])
    plt.show()