def hist_ecalib(calib, dataToPredict):
    """
    Histogram of ecalib and etrue
    """
    h = dataToPredict.hcal[np.logical_and(
        dataToPredict.ecal == 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]
    t = dataToPredict.true[np.logical_and(
        dataToPredict.ecal == 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]
    e = np.zeros(len(h))
    h2 = dataToPredict.hcal[np.logical_and(
        dataToPredict.ecal != 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]
    t2 = dataToPredict.true[np.logical_and(
        dataToPredict.ecal != 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]
    e2 = dataToPredict.ecal[np.logical_and(
        dataToPredict.ecal != 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]

    c = calib.predict(e, h)
    c2 = calib.predict(e2, h2)

    plt.subplot(2, 2, 1)
    plt.hist(c, binwidth_array(c, 2))
    plt.xlabel(r"$e_{calib}$", fontsize=15)
    plt.title(r"$e_{cal} = 0$", fontsize=15)
    plt.subplot(2, 2, 2)
    c2 = c2[np.invert(np.isnan(c2))]
    plt.hist(c2, binwidth_array(c2, 2))
    plt.xlabel(r"$e_{calib}$", fontsize=15)
    plt.title(r"$e_{cal} \neq 0$", fontsize=15)
    plt.subplot(2, 2, 3)
    t = t[np.invert(np.isnan(t))]
    plt.hist(t, binwidth_array(t, 2))
    plt.xlabel(r"$e_{true}$", fontsize=15)
    plt.title(r"$e_{cal} = 0$", fontsize=15)
    plt.subplot(2, 2, 4)
    t2 = t2[np.invert(np.isnan(t2))]
    plt.hist(t2, binwidth_array(t2, 2))
    plt.xlabel(r"$e_{true}$", fontsize=15)
    plt.title(r"$e_{cal} \neq 0$", fontsize=15)
    plt.tight_layout()
rchi2_ecal_neq_0 = KNNGF.evaluatedPoint_reducedchi2[1:]
rrchi2_ecal_neq_0 = np.resize(rchi2_ecal_neq_0,
                              (len(hcal_ecal_neq_0), len(ecal_ecal_neq_0)))
rrchi2_ecal_neq_0[eecal_ecal_neq_0 + hhcal_ecal_neq_0 > lim] = math.nan
x = np.array(KNNGF.evaluatedPoint_reducedchi2)
x = x[np.array(KNNGF.evaluatedPoint_hcal) +
      np.array(KNNGF.evaluatedPoint_ecal) < lim]

fig = plt.figure(figsize=(10, 8))
plt.subplot(2, 2, 1)
plt.plot(hcal_ecal_eq_0, KNNGF.evaluatedPoint_reducedchi2_ecal_eq_0)
plt.xlabel(r"$h_{cal}$", fontsize=12)
plt.ylabel(r"$\chi^2/df$", fontsize=12)
plt.title(r"$\chi^2/df$ for $e_{cal} = 0$", fontsize=12)
plt.subplot(2, 2, 2)
plt.hist(rchi2_ecal_eq_0, binwidth_array(rchi2_ecal_eq_0, 0.25))
plt.xlabel(r"$\chi^2/df$", fontsize=12)
plt.title(r"$\chi^2/df$ for $e_{cal} = 0$", fontsize=12)
plt.subplot(2, 2, 3)
xmin = min(ecal_ecal_neq_0)
xmax = max(ecal_ecal_neq_0)
ymin = min(hcal_ecal_neq_0)
ymax = max(hcal_ecal_neq_0)
vmin = 0.5
vmax = 1.5
im = plt.imshow(rrchi2_ecal_neq_0,
                cmap=plt.cm.seismic,
                extent=(xmin, xmax, ymin, ymax),
                origin='lower',
                vmin=vmin,
                vmax=vmax,
def plot_gaussianfitcurve_ecalib_over_etrue_functionof_ecal_hcal(
        calib, dataToPredict):
    """
    plot the gaussian fit curve of ecalib/etrue = f(etrue)
    """
    h = dataToPredict.hcal[np.logical_and(
        dataToPredict.ecal == 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]
    t = dataToPredict.true[np.logical_and(
        dataToPredict.ecal == 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]
    e = np.zeros(len(h))
    h2 = dataToPredict.hcal[np.logical_and(
        dataToPredict.ecal != 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]
    t2 = dataToPredict.true[np.logical_and(
        dataToPredict.ecal != 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]
    e2 = dataToPredict.ecal[np.logical_and(
        dataToPredict.ecal != 0,
        dataToPredict.ecal + dataToPredict.hcal < calib.lim)]

    c = calib.predict(e, h)
    r = c / t
    c2 = calib.predict(e2, h2)
    r2 = c2 / t2

    energy, means, mean_gaussianfit, sigma_gaussianfit, reducedChi2 = getMeans(
        t, r)
    energy2, means2, mean_gaussianfit2, sigma_gaussianfit2, reducedChi22 = getMeans(
        t2, r2)
    #mean
    ax = plt.subplot(4, 1, 1)
    plt.plot(energy, mean_gaussianfit, lw=3, label=r"$e_{cal} = 0$")
    plt.plot(energy2, mean_gaussianfit2, lw=3, label=r"$e_{cal} \neq 0$")
    plt.xlabel(r"$e_{true}$", fontsize=15)
    plt.title(r"$e_{calib}/e_{true}$", fontsize=15)
    plt.ylabel(r"$<e_{calib}/e_{true}>$", fontsize=15)
    plt.legend(loc='upper right')
    major_ticks = np.arange(0, 200, 50)
    minor_ticks = np.arange(0, 200, 10)
    ax.set_xticks(major_ticks)
    ax.set_xticks(minor_ticks, minor=True)
    # and a corresponding grid
    ax.grid(which='both')
    # or if you want differnet settings for the grids:
    ax.grid(which='minor', alpha=0.2)
    ax.grid(which='major', alpha=1)
    #sigma
    ax = plt.subplot(4, 1, 2)
    plt.plot(energy, sigma_gaussianfit, lw=3, label=r"$e_{cal} = 0$")
    plt.plot(energy2, sigma_gaussianfit2, lw=3, label=r"$e_{cal} \neq 0$")
    plt.xlabel(r"$e_{true}$", fontsize=15)
    plt.ylabel(r"$\sigma (e_{calib}/e_{true})$", fontsize=15)
    plt.legend(loc='upper right')
    major_ticks = np.arange(0, 200, 50)
    minor_ticks = np.arange(0, 200, 10)
    ax.set_xticks(major_ticks)
    ax.set_xticks(minor_ticks, minor=True)
    # and a corresponding grid
    ax.grid(which='both')
    # or if you want differnet settings for the grids:
    ax.grid(which='minor', alpha=0.2)
    ax.grid(which='major', alpha=1)
    #chi2
    ax = plt.subplot(4, 1, 3)
    plt.plot(energy, reducedChi2, lw=3, label=r"$e_{cal} = 0$")
    plt.plot(energy2, reducedChi22, lw=3, label=r"$e_{cal} \neq 0$")
    plt.xlabel(r"$e_{true}$", fontsize=15)
    plt.ylabel(r"$\chi^2/df$", fontsize=15)
    plt.legend(loc='upper right')
    major_ticks = np.arange(0, 200, 50)
    minor_ticks = np.arange(0, 200, 10)
    ax.set_xticks(major_ticks)
    ax.set_xticks(minor_ticks, minor=True)
    # and a corresponding grid
    ax.grid(which='both')
    # or if you want differnet settings for the grids:
    ax.grid(which='minor', alpha=0.2)
    ax.grid(which='major', alpha=1)
    #hist chi2/df for ecal == 0
    ax = plt.subplot(4, 2, 7)
    x = np.array(reducedChi2)
    x = x[np.invert(np.isnan(x))]
    bins = binwidth_array(x, binwidth=0.5)
    plt.hist(x, bins, label=r"$e_{cal} = 0$")
    plt.xlabel(r"$\chi^2/df$", fontsize=15)
    plt.legend(loc='upper right')
    #hist chi2/df for ecal != 0
    ax = plt.subplot(4, 2, 8)
    x = np.array(reducedChi22)
    x = x[np.invert(np.isnan(x))]
    bins = binwidth_array(x, binwidth=0.5)
    plt.hist(x, bins, label=r"$e_{cal} \neq 0$")
    plt.xlabel(r"$\chi^2/df$", fontsize=15)
    plt.legend(loc='upper right')
    plt.tight_layout()
Beispiel #4
0
c = KNNGF.predict(e,h)
r = c/t

energy, means, mean_gaussianfit, sigma_gaussianfit, reducedChi2 = getMeans(t,r)
fig = plt.figure(figsize=(10,5))
plt.plot(t,r,'.',markersize=1)
plt.axis([0,200,0,2])
plt.plot(energy,mean_gaussianfit,lw=3)
plt.xlabel(r"$e_{true}$",fontsize=15)
plt.ylabel(r"$e_{calib}/e_{true}$",fontsize=15)
plt.title(r"$e_{calib}/e_{true}$ for $e_{cal} = 0$",fontsize=15)
savefig(fig,directory,"ecalib_over_etrue.png")

#histogram of hcal
fig = plt.figure(figsize=(10,5))
bw = binwidth_array(h)
entries, bins, other = plt.hist(h,bw)
plt.xlabel(r"$h_{cal}$",fontsize=15)
plt.title(r"$h_{cal}$ for $e_{cal} = 0$",fontsize=15)
plt.show()
savefig(fig,directory,"histograms_hcal.png")

#histogram of ecalib
fig = plt.figure(figsize=(10,5))
#bw = binwidth_array(c)
bw = binwidth_array(c,0.01)
entries, bins, other = plt.hist(c,bw)
plt.xlabel(r"$e_{calib}$",fontsize=15)
plt.title(r"$e_{calib}$ for $e_{cal} = 0$",fontsize=15)
plt.show()
savefig(fig,directory,"histograms_ecalib.png")
Beispiel #5
0
plt.title(r"$e_{true}$ for $e_{cal} = 0$", fontsize=15)
plt.axis([0, lim, 0, max(calib)])
plt.legend(loc="lower right")
plt.subplot(1, 2, 2)
plt.plot(hcal_train, true_train, '.', markersize=1, label=r"training data")
plt.plot(hcal_calib, calib, lw=3, label="calibration")
plt.xlabel(r"$h_{cal}$", fontsize=15)
plt.ylabel(r"$e_{true}$", fontsize=15)
plt.title(r"$e_{true}$ for $e_{cal} = 0$", fontsize=15)
plt.axis([0, 15, 0, 15])
plt.legend(loc="lower right")
savefig(fig, directory, "calibration.png")

#histogram of hcal
fig = plt.figure(figsize=(10, 5))
bw = binwidth_array(h)
entries, bins, other = plt.hist(h, bw)
plt.xlabel(r"$h_{cal}$", fontsize=15)
plt.title(r"$h_{cal}$ for $e_{cal} = 0$", fontsize=15)
plt.show()
savefig(fig, directory, "histograms_hcal.png")

#histogram of etrue
fig = plt.figure(figsize=(10, 5))
bw = binwidth_array(t)
entries, bins, other = plt.hist(h, bw)
plt.xlabel(r"$e_{true}$", fontsize=15)
plt.title(r"$e_{true}$ for $e_{cal} = 0$", fontsize=15)
plt.show()
savefig(fig, directory, "histograms_etrue.png")