#[h_bkg, spline_bkg, _] = get_draw_spline("../data/mca/bkg_4_1937_spectrum.mca", 0.002, 'g', 'g', "Background", ax, axins) # subtract backround and draw h_fe_new = subtract_bkg(h_fe, spline_fe, spline_bkg, "b", ax, axins) h_am_new = subtract_bkg(h_am, spline_am, spline_bkg, "r", ax, axins) # finished zoomed in sub-figure axins.set_xlim(0, 149) axins.set_ylim(0, 99) #axins.set_ylim(0, 1.5) mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5") # spice it up and show x = 0.05 ax.set_ylim(top=1.2 * ax.get_ylim()[1]) show_title(ax, x=x) show_text("Dashed lines: Bsplines of original histograms", ax, y=0.85, x=x) show_text("Full lines: Bsplined background subtracted", ax, y=0.80, x=x) ax.set_ylabel( "Counts for {:.0f} seconds per channel [1/s/bit]".format(time_fe)) #ax.set_ylabel("Counts per second per 4 channels [1/s/bit]") ax.set_xlabel("Channel [bit]") ax.legend(loc='best') fig.show() plt.savefig("../graphics/bkgsubtraction.pdf", format='pdf') # used later on for calculating the number of events in gauss binwidth = h_am_new.GetBinWidth(1) #%%##################################### # Fit spectra
# plot points and fit result ax.errorbar(y=Q, yerr=10 * Qerr, x=mean, xerr=5000 * mean_tot_unc, color='r', linestyle='None') x0 = mean[0] - 10 xlast = mean[-1] + 10 xx = np.linspace(x0, xlast, 1000) yy = [fit_Q.Eval(x) for x in xx] ax.plot(xx, yy, 'b-') # spice it up and show show_title(ax) show_text("Note: Channel uncertainties scaled by 5000", ax, y=0.85) show_text(" Charge uncertainties scaled by 10", ax, y=0.80) show_text("Fit: y = b + ax", ax, y=0.75) show_text("b = {:.5f} ± {:.5f} ({:3.1f}σ from 0)".format( fit_Q.GetParameter(0), fit_Q.GetParError(0), abs(fit_Q.GetParameter(0)) / fit_Q.GetParError(0)), ax, y=0.70) show_text("a = {:.7f} ± {:.7f}".format(fit_Q.GetParameter(1), fit_Q.GetParError(1)), ax, y=0.65) show_text("p( X², ndof ) = p( {:.1f}, {:d} ) = {:.1f}%".format( fit_Q.GetChisquare(), fit_Q.GetNDF(), fit_Q.GetProb() * 100),