Exemplo n.º 1
0
def local_fit(x, y, errors, mu, sigma):
    func = lambda x, mu, sigma, A, a0, a1: GAUSS(x, mu, sigma, A) + a0 + a1 * x

    fit = Fit(func)
    fit.mu = _simple_peak(y, mu, sigma)
    fit.sigma = sigma
    fit.A = y[fit.mu]
    fit.a0 = 0
    fit.a1 = 0

    for i in range(5):
        lower = max(fit.mu - 5 * fit.sigma, 0)
        upper = min(fit.mu + 5 * fit.sigma, len(x))
        lx = x[lower:upper]
        ly = y[lower:upper]
        lerrors = errors[lower:upper]
        if i <= 2:
            fit.fit(lx, ly, lerrors, solver="curve_fit")
        else:
            fit.fit(lx, ly, lerrors, solver="minuit", method="migrad")

    return fit
Exemplo n.º 2
0
def plot_coincidence_co():
    angle, count = np.loadtxt("data/winkel_cobalt3.txt", unpack=True)

    error_angle = 0.3
    error_count = np.sqrt(count + 1)

    plt.clf()
    plt.errorbar(angle,
                 count,
                 xerr=error_angle,
                 yerr=error_count,
                 fmt='s',
                 color="black")

    W = lambda theta, A, a2, a4: A * (1 + a2 * np.power(
        np.cos(np.radians(theta)), 2) + a4 * np.power(
            np.cos(np.radians(theta)), 4))

    fit = Fit(W)
    fit.A = count.mean()
    fit.a2 = 0
    fit.a4 = 0
    for i in range(5):
        errors = fit.combine_errors(angle, error_angle, error_count)
        fit.fit(angle, count, errors)
    fit.plot(-90, 90, box="br", color="red")
    plt.xlim(-90, 90)
    plt.xlabel("Winkel / Grad")
    plt.ylabel("Count")
    plt.savefig("out/coincidence_co_fit." + SAVETYPE)

    plt.clf()
    fit.plot_residual(angle, count, errors, fmt="s", box="br", color="black")
    plt.xlabel("Winkel / Grad")
    plt.ylabel("Count")
    plt.savefig("out/coincidence_co_residual." + SAVETYPE)

    plt.clf()
    plt.errorbar(angle,
                 count,
                 xerr=error_angle,
                 yerr=error_count,
                 fmt='s',
                 color="black")

    fit = Fit(CONSTANT)
    fit.c = count.mean()
    for i in range(5):
        errors = fit.combine_errors(angle, error_angle, error_count)
        fit.fit(angle, count, errors)
    fit.plot(-90, 90, box="br", color="red")
    plt.xlim(-90, 90)
    plt.xlabel("Winkel / Grad")
    plt.ylabel("Count")
    plt.savefig("out/coincidence_co_fitc." + SAVETYPE)

    plt.clf()
    fit.plot_residual(angle, count, errors, fmt="s", box="br", color="black")
    plt.xlabel("Winkel / Grad")
    plt.ylabel("Count")
    plt.savefig("out/coincidence_co_residualc." + SAVETYPE)