def OrderStat(x,A,n,mu,s): return (n/s)*fu.gauss1(x,A,mu,s)*((1./2)*((1 + sps.erf((x-mu)/s)))**(n-1))
PedFitComplete = True GoodPedFit = False FitComplete = True GoodFit = False continue pl.PlotPedestal(pedxdata,pedydata,fu.gauss1,pedxdata,pedopt,"GaussPlusExpo") above_ped = 0 past_ped = np.where(pedxdata > (pedopt[1] + 3*pedopt[2]))[0] if FIT_TAIL: plt.plot(pedxdata[past_ped],pedydata[past_ped]) plt.plot(pedxdata[past_ped],fu.expo(pedxdata[past_ped],pedopt[3], pedopt[4],pedopt[5])) above_ped = np.sum(pedydata[past_ped] - fu.expo(pedxdata[past_ped],pedopt[3], pedopt[4],pedopt[5])) else: above_ped = np.sum(pedydata[past_ped] - fu.gauss1(pedxdata[past_ped],pedopt[0], pedopt[1],pedopt[2])) plt.show() print("4SIGMA PAST PED, EXP. SUBTRACTED: " + str(above_ped)) if (above_ped < 300): print("Low statistics beyond pedestal! May just be fitting on fluctuations.") skip_fit = str(raw_input("Skip this fit?")) if skip_fit in ["y","Y","yes","Yes","YES"]: PedFitComplete = True GoodPedFit = False FitComplete = True GoodFit = False continue ped_good = str(raw_input("Happy with pedestal fit? [y/N]:")) if ped_good in ["y","Y","yes","Yes","YES"]: PedFitComplete = True
import matplotlib.pyplot as plt import numpy as np import scipy as scp import scipy.optimize as sco import scipy.stats as sts import scipy.special as sps import lib.Functions as fu def OrderStat(x,A,n,mu,s): return (n/s)*fu.gauss1(x,A,mu,s)*((1./2)*((1 + sps.erf((x-mu)/s)))**(n-1)) maxes = [] for i in range(10000): maxes.append(np.max(scp.randn(30))) bin_height, bin_edges = np.histogram(maxes,bins=100) bin_width = bin_edges[1]-bin_edges[0] bin_edges_t = bin_edges[0:len(bin_edges) -1] bin_centers = np.array(bin_edges_t) - (bin_width/2) popt,pcov = sco.curve_fit(fu.gauss1,bin_centers,bin_height,p0=[1000,2,2]) yfit = fu.gauss1(bin_centers,popt[0],popt[1],popt[2]) plt.hist(maxes,bins=100) plt.plot(bin_centers,yfit) plt.show() popt,pcov = sco.curve_fit(OrderStat,bin_centers,bin_height,p0=[300,30,1,2],maxfev=10000) yfit = OrderStat(bin_centers,popt[0],popt[1],popt[2],popt[3]) plt.hist(maxes,bins=100) plt.plot(bin_centers,yfit) plt.show()
GoodPedFit = False FitComplete = True GoodFit = False continue pl.PlotPedestal(ped_xdata, ped_ydata, fn.gauss1, ped_xdata, ped_opt, "GaussPlusExpo") above_ped = 0 past_ped = np.where(ped_xdata > (ped_opt[1] + 3.*ped_opt[2]))[0] if FIT_TAIL: plt.plot(ped_xdata[past_ped], ped_ydata[past_ped]) plt.plot(ped_xdata[past_ped], fn.expo(ped_xdata[past_ped], ped_opt[3], ped_opt[4], ped_opt[5])) above_ped = np.sum(ped_ydata[past_ped] - fn.expo(ped_xdata[past_ped], ped_opt[3], ped_opt[4], ped_opt[5])) else: above_ped = np.sum(ped_ydata[past_ped] - fn.gauss1(ped_xdata[past_ped], ped_opt[0], ped_opt[1], ped_opt[2])) plt.show() print(" > 4SIGMA PAST PED, EXP. SUBTRACTED: " + str(above_ped)) if (above_ped < 300): print("Low statistics beyond pedestal! May just be fitting on fluctuations.") skip_fit = str(input("Skip this fit?")) if (skip_fit in ["y", "Y", "yes", "Yes", "YES", "yEs"]): PedFitComplete = True GoodPedFit = False FitComplete = True GoodFit = False continue keep_ped = str(input("Keep pedestal fit? [y/N]: ")) if (keep_ped in ["y", "Y", "yes", "Yes", "YES", "yEs"]): ped_good = str(input("Happy with pedestal fit? [y/N]: "))