def plot_data(channels): for i,ch in enumerate(channels):#file_array): #cdata = B.get_file(ctrl_dir + cf) # get time slices for analysis #f_name = "./Analysis_Results/"+str(29975)+"/Raw_Fitting/fit_results_4_"+ str(29975) + "_{0:5.3f}_{1:5.3f}_{2:d}.npz".format(0.000, 0.500, ch)#self.par['dtmin']/us, self.par['dtmax']/us, self.par['channel']) (dtmin,dtmax) = db.retrieve('dtmin, dtmax', 'Raw_Fitting', 'Shot = '+ str(shot) + ' AND Channel = '+ str(ch)) #cdata.par.get_value('input_result_file', str) pf_name = "../Analysis_Results/"+str(shot)+"/Rate_Plotting/rate_results_4_"+ str(shot) + "_{0:5.3f}_{1:5.3f}_{2:d}.npz".format(dtmin, dtmax, ch)#cdata.par.get_value('output_file', str) #f_name = res_dir + f_name #pf_name = res_dir + pf_name # shot = cdata.par.get_value('shot_number',str) try: d = np.load(pf_name) #pd = B.get_file(pf_name) except: print("cannot open : ", pf_name, " skipping") continue t = d['t']#B.get_data(pd, 't') Ap = d['Ap']#B.get_data(pd, 'Ap') dAp = d['dAp']#B.get_data(pd, 'dAp') # # At = B.get_data(pd, 'At') # dAt = B.get_data(pd, 'dAt') # # A = B.get_data(pd, 'A') # dA = B.get_data(pd, 'dA') # # Total signal B.plot_exp(t, Ap, dAp, color = colors[ channels[i] ], ecolor='grey', label = 'Ch {}'.format(channels[i]), capsize = 0.) # B.plot_line(t, A, color = colors[i]) # B.pl.xlabel('t [s]') B.pl.ylabel('Rate (p)') B.pl.title('Shot : '+ str(shot) ) #B.pl.ylim((A_min, A_max)) #B.pl.xlim((t_min, t_max)) B.pl.legend(loc = 'upper right') B.pl.show()
def plot_results(self): draw_p = self.par['draw_p'] draw_t = self.par['draw_t'] draw_sum = self.par['draw_sum'] #if pulser were added draw_pulser=self.par['draw_pul'] dt = self.par['time_slice_width']*us # proton sum signal if draw_p : B.plot_exp(self.slice_t/us, self.A_sp/dt*us, self.dA_sp/dt*us, linestyle = '-', marker = 'o', color = 'b', ecolor='grey', capsize = 0.) #,markeredgecolor='g', # triton sum signal if draw_t: B.plot_exp(self.slice_t/us, self.A_st/dt*us, self.dA_st/dt*us, color = 'g', ecolor='grey', capsize = 0.) # pulser sum signal if draw_pulser: B.plot_exp(self.slice_t/us, self.A_pul/dt*us, self.dA_pul/dt*us, color = 'm', ecolor='grey', capsize = 0.) # Total signal if draw_sum : B.plot_exp(self.slice_t/us, self.A_t/dt*us, self.dA_t/dt*us, linestyle = '-',ecolor='grey', marker = '.', capsize = 0., label='Ch %d'%self.par['channel']) o_file = self.var['of_name'] if not os.path.exists(os.path.dirname(o_file)): os.makedirs(os.path.dirname(o_file)) B.pl.xlabel('t [s]') B.pl.ylabel('Rate [Hz]') B.pl.title('Shot : '+ str(self.par['shot']) +'/ channel: '+str(self.par['channel'])) B.pl.xlim((self.par['dtmin']/us, self.par['dtmax']/us)) B.pl.show() """
C = h.bin_content dC = h.bin_error dM = M[1] - M[0] # get the bin width #dM = d.par.get_value('dx') # get the histogram data #M = d['xb'] #C = d['cont'] #dC = d['dcont'] #dC = np.sqrt(C) # plot the data B.plot_exp(M, C, dC) # setup # simple gaussian A = B.Parameter(C.max(), 'A') #x0 = B.Parameter(0.135, 'x0') #x0 = B.Parameter(0.135, 'x0') x0 = B.Parameter(0.956, 'x0') #x01 = B.Parameter(0.545, 'x01') sig = B.Parameter(.005, 'sigma') def gaus(x): return A() * np.exp(-(x - x0())**2 / (2. * sig()**2))
r4 = R0a[:, 3] r5 = R0a[:, 4] r6 = R0a[:, 5] dr1 = sig_R0a[:, 0] dr2 = sig_R0a[:, 1] dr3 = sig_R0a[:, 2] dr4 = sig_R0a[:, 3] dr5 = sig_R0a[:, 4] dr6 = sig_R0a[:, 5] # range in R covered (2 sigma) B.plot_exp(times, r1, dr1, color='r', label='view 1, ch {}'.format(channels[0][0])) B.plot_exp(times, r2, dr2, color='g', label='view 2, ch {}'.format(channels[0][1])) B.plot_exp(times, r3, dr3, color='b', label='view 3, ch {}'.format(channels[0][2])) B.plot_exp(times, r4, dr4,
# read the data mf = B.get_file('my_exp_1.data') # get the data into arrays t = B.get_data(mf, 'time') dexp = B.get_data(mf,'dist') derr = B.get_data(mf, 'd_err') # print the values in a for loop for i, D in enumerate(dexp): # indentation is important print 'time = ', t[i], 'distance = ', D, 'error = ', derr[i] # end of the loop = end of indentation # plot the data B.plot_exp(t, dexp, derr) # fit a line fit = B.linefit(t, dexp, derr) # draw the fit result B.plot_line(fit.xpl, fit.ypl) # add the labels B.pl.xlabel('t (sec)') B.pl.ylabel('Distance (m)') B.pl.title('Distance vs time exp.') # save the plot B.pl.savefig('my_plot.pdf')
sigma_strobe = 0.05 sigma_B = np.sqrt((((mu_naught / (2 * np.pi * R)) * df1['Sigmai(A)'])**2) + (((-mu_naught * 3.00) / (2 * np.pi * ((R)**2)) * sigma_R)**2)) sigma_ang_vel = np.sqrt(sigma_strobe) sigma_Imoment = (2 / 5) * np.sqrt(((((rBall)**2) * sigma_mBall)**2) + ((2 * (rBall * mBall * sigma_rBall))**2)) sigma_L = np.sqrt(((ang_vel * sigma_Imoment)**2) + ((moment_I * sigma_ang_vel)**2)) sigma_mu = np.sqrt((((1 / BoverL) * sigma_omega)**2) + (((-omega * L / ((0.002541)**2)) * sigma_B)**2) + (((omega / 0.002541) * sigma_L)**2)) errorbar = sigma_omega B.plot_exp(BoverL, omega, 0.008) B.pl.title("Precesional Frequency over B/L") B.pl.ylabel("Frequency (HZ)") B.pl.xlabel("B/L") fit2 = B.linefit(BoverL, omega) B.plot_line(fit2.xpl, fit2.ypl) B.pl.show()
#%% A_a, X_a, S_a, A0_a, A1_a, Q = fit_draw_histo(h2_etap_phi, Fit=True) #%% A_a, X_a, S_a, A0_a, A1_a, Q = fit_draw_histo(h2_etap_mant, Fit=True) #%% A_a, X_a, S_a, A0_a, A1_a, Q = fit_draw_histo(h2_etap_be, Fit=True) #%% phi_bin_center = h2_etap_phi.y_bin_center B.plot_exp(phi_bin_center, Q, marker='o') B.pl.hlines(Q.mean(), phi_bin_center.min(), phi_bin_center.max()) plt.xlabel('azimuthal angle $\phi_{GJ}$', fontsize=8) plt.ylabel('Q values', fontsize=8) #%% mant_bin_center = h2_etap_mant.y_bin_center B.plot_exp(mant_bin_center, Q, marker='o') B.pl.hlines(Q.mean(), mant_bin_center.min(), mant_bin_center.max()) plt.xlabel('momentum transfer t', fontsize=8) plt.ylabel('Q values', fontsize=8) #%% e_beam_bin_center = h2_etap_be.y_bin_center B.plot_exp(e_beam_bin_center, Q, marker='o')
R = (23.5 + 17.9) / 2 sigma_R = (0.05**2) / 2 R = R / 100 sigma_R = sigma_R / 100 # units of R in mn N = 195 Bfield = ((mu_naught * N * df['I']) / (R)) * ((4 / 5)**(3 / 2)) # Bfield = Bfield*10**6 #units in kg/As^2 Torque = df['r'] * m * g Torque = Torque / 100 #error propagation sigma_Torque = np.sqrt(((m * g * df['sigmar'])**2) + ((df['r'] * g * sigma_m)**2)) # print(sigma_Torque) B.plot_exp(Bfield, Torque, 0.00004) B.pl.title("Torque Vs Magentic Field") B.pl.ylabel("Torque [(kgm^2)/(s^2)]") B.pl.xlabel("Magnetic field *10^-6 [kg/(s^2)(A)]") fit2 = B.linefit(Bfield, Torque) B.plot_line(fit2.xpl, fit2.ypl) B.pl.show()
mBall = mBall / 1000 sigma_mBall = 0.05 sigma_mBall = sigma_mBall / 1000 # units in kg moment_I = (2 * mBall * (rBall**2)) / 5 Bfield = ((mu_naught * N * df['Current(A)']) / (R)) * ((4 / 5)**(3 / 2)) IoverB = moment_I / Bfield axis_X = 4 * (np.pi**2) * IoverB print(Bfield) B.plot_exp(Tsquared, axis_X, 0.15) B.pl.title("Harmonic Motion") B.pl.ylabel("4pi*I/B (T^-1)") B.pl.xlabel("period squared (s^2)") fit2 = B.linefit( Tsquared, axis_X, ) B.plot_line(fit2.xpl, fit2.ypl) B.pl.show() # plt.plot([list(axis_X)],[list(Tsquared)],'ro') # plt.ylabel('period squared (s^2)') # plt.xlabel('4pi*I/B (T^-1)')
A_fit.sigma_min.set(0.003) A_fit.sigma_max.set(0.03) A_fit.b0_min.set(0.5) A_fit.b0_max.set(0.9) A_fit.c0_min.set(45.) A_fit.c0_max.set(70.) A_fit.fit_gaussbt(pi0m, A_value, A_err) # fit gauss peak with linear bkg plt.figure() A_fit.plot_fit() B.plot_line(pi0m, A_fit.gauss(pi0m)) B.plot_line(pi0m, A_fit.bt_bkg(pi0m)) B.plot_exp(pi0m, A_value, A_err, plot_title='Fit the fit parameter A', x_label=' $M(\gamma\gamma)$') plt.figure() px0 = B.polyfit(pi0m, x0_value, x0_err, order=1) B.plot_exp(pi0m, x0_value, x0_err, plot_title='Fit the fit parameter $x0$', x_label='bin centers of y-axis in 2D plot $M(\pi^{0})$') B.plot_line(px0.xpl, px0.ypl) plt.figure() pS = B.polyfit(pi0m, S_value, S_err, order=2) B.plot_exp(pi0m,
# calculate averages # use only proton data t_mean_b, w_mean_b, sig_w_mean_b = get_mean(t, Ap, dAp, t_wb) t_mean_a, w_mean_a, sig_w_mean_a = get_mean(t, Ap, dAp, t_wa) # append information to an array R_b.append([[t_mean_b, w_mean_b, sig_w_mean_b], cf, j, nr_b]) #int(channel), j, nr_b] ) R_a.append([[t_mean_a, w_mean_a, sig_w_mean_a], cf, j, nr_a]) print('Channel : ', cf) #hannel print('Mean before : ', get_mean(t, Ap, dAp, t_wb)) print('Mean after : ', get_mean(t, Ap, dAp, t_wa)) # Total signal B.plot_exp(t, Ap, dAp, color=colors[cf], label='Ch {}'.format(channels[i]), capsize=0.) # B.plot_line(t, A, color = colors[i]) B.pl.xlabel('t [s]') B.pl.ylabel('Rate') B.pl.legend(loc='upper right') B.pl.title('Shot : ' + str(shot)) B.pl.ylim((A_min, A_max)) B.pl.xlim((t_min_pl, t_max_pl)) ymin, ymax = B.pl.ylim() # before B.pl.vlines(t_min_b, ymin, ymax, color='r') B.pl.vlines(t_max_b, ymin, ymax, color='r')
def plot_results(self): draw_p = self.par['draw_p'] draw_t = self.par['draw_t'] draw_sum = self.par['draw_sum'] # histogram setup h_min = self.par['h_min'] h_max = self.par['h_max'] h_bins = self.par['h_bins'] h_range = (h_min, h_max) #if pulser were added add_pulser = self.par['add_pulser'] # no histo fitting at this time fit_histos = False t_offset = self.par['t_offset'] #cdata.par.get_value('t_offset')*us # get directories f_name = self.var['f_name'] # load data (faster loading then from txt) d = np.load(f_name) tr = d['t'] + t_offset Vpr = d['V'] # raw PH Ar = d['A'] # fitted PH dAr = d['sig_A'] # chir = np.zeros_like(tr) # positive signals pa = Ar > 0. r = np.abs(dAr[pa] / Ar[pa]) # cut on error ratio r_cut_off = self.par['sig_ratio'] # this is for good events gr = r < r_cut_off # this is to study background #gr = r > r_cut_off tg = tr[pa][gr] A = Ar[pa][gr] # dA = dAr[pa][gr] # chi = chir[pa][gr] # simple pulse heights for testing ta = tr[pa] Ap = Vpr[pa] # raw data # time slice the data dt = self.par['time_slice_width'] * us # step width # bin numbers i_t = (tg / dt).astype('int') i_t_a = (ta / dt).astype('int') # time slicing for fitted peaks slice_t = [] slices = [] i_start = 0 i_bin = i_t[0] for i, ip in enumerate(i_t): if ip != i_bin or i == len(i_t) - 1: i_end = i # print "found slice from : ", i_start, i_end slice_t.append(i_bin * dt + 0.5 * dt) slices.append(slice(i_start, i_end)) i_bin = ip i_start = i # time slicing for all peaks slice_t_a = [] slices_a = [] i_start_a = 0 i_bin_a = 0 for i, ip in enumerate(i_t_a): if ip == i_bin_a: continue else: i_end = i # print "found slice from : ", i_start, i_end slice_t_a.append(i_bin_a * dt + 0.5 * dt) slices_a.append(slice(i_start_a, i_end)) i_bin_a = ip i_start_a = i # histogram h = [] hp = [] for i, s in enumerate(slices): hi = B.histo(A[s], range=h_range, bins=h_bins) h_time = "{0:6.4f} s".format(slice_t[i] / us) hi.title = h_time h.append(hi) for i, s in enumerate(slices_a): hip = B.histo(Ap[s], range=h_range, bins=h_bins) h_time = "{0:6.4f} s".format(slice_t_a[i] / us) hip.title = h_time hp.append(hip) self.h = h self.hp = hp print("created ", len(h), " histograms h") A_sp = [] dA_sp = [] A_st = [] dA_st = [] A_pul = [] dA_pul = [] # for protons p_min = self.par['p_min'] #cdata.par.get_value('p_min') p_max = self.par['p_max'] #cdata.par.get_value('p_max') # for tritons t_min = self.par['t_min'] t_max = self.par['t_max'] # fit histograms if add_pulser: pul_min = self.par['pulser_min'] pul_max = self.par['pulser_max'] # inital parameters A_init = self.par['A_init'] sigma_init = self.par['sig_init'] for i, hi in enumerate(h): # proton fit # hi.mean.set(p_mean) #check if necessary hi.A.set(A_init) hi.sigma.set(sigma_init) # fitting with limits if fit_histos: hi.fit(xmin=p_min, xmax=p_max) # sum histograms sp, dsp = hi.sum(xmin=p_min, xmax=p_max) st, dst = hi.sum(xmin=t_min, xmax=t_max) spul, dspul = hi.sum(xmin=pul_min, xmax=pul_max) A_sp.append(sp) dA_sp.append(dsp) A_st.append(st) dA_st.append(dst) A_pul.append(spul) dA_pul.append(dspul) # proton amplitudes A_sp = np.array(A_sp) dA_sp = np.array(dA_sp) # tritomn amplitudes A_st = np.array(A_st) dA_st = np.array(dA_st) # pulser amplitudes A_pul = np.array(A_pul) dA_pul = np.array(dA_pul) # total A_t = A_sp + A_st dA_t = np.sqrt(dA_sp**2 + dA_st**2) # fitting results if fit_histos: A_f = [] dA_f = [] chi_red = [] m_f = [] dm_f = [] fact = np.sqrt(2. * np.pi) for i, hi in enumerate(h): bw = hi.bin_width sig = np.abs(hi.sigma()) name, Am, dAm = hi.fit_par['A'].get() name, p, dp = hi.fit_par['mean'].get() A_f.append(Am * sig * fact / bw) dA_f.append(dAm * sig * fact / bw) m_f.append(p) dm_f.append(dp) chi_red.append(hi.F.chi2_red) A_f = np.array(A_f) dA_f = np.array(dA_f) m_f = np.array(m_f) dm_f = np.array(dm_f) chi_red = np.array(chi_red) # proton sum signal if draw_p == 'True': B.plot_exp(np.array(slice_t) / us, A_sp / dt * us, dA_sp / dt * us, linestyle='-', marker='o', color='b', ecolor='grey', capsize=0.) #,markeredgecolor='g', # triton sum signal if draw_t == 'True': B.plot_exp(np.array(slice_t) / us, A_st / dt * us, dA_st / dt * us, color='g', ecolor='grey', capsize=0.) # pulser sum signal if add_pulser == 'True': B.plot_exp(np.array(slice_t) / us, A_pul / dt * us, dA_pul / dt * us, color='m', ecolor='grey', capsize=0.) # Total signal if draw_sum == 'True': B.plot_exp(np.array(slice_t) / us, A_t / dt * us, dA_t / dt * us, linestyle='-', ecolor='grey', marker='.', capsize=0., label='Ch %d' % self.par['channel']) #color = 'r',ecolor='grey', # o_file = self.var['of_name'] if not os.path.exists(os.path.dirname(o_file)): os.makedirs(os.path.dirname(o_file)) B.pl.xlabel('t [s]') B.pl.ylabel('Rate [Hz]') B.pl.title('Shot : ' + str(self.par['shot']) + '/ channel: ' + str(self.par['channel'])) B.pl.xlim((self.par['dtmin'] / us, self.par['dtmax'] / us)) B.pl.show() B.pl.savefig('../Analysis_Results/%d/Rate_Plotting/Rate_%s.png' % (self.par['shot'], self.var['f_name'][-16:-6])) # write results # if os.path.isfile(o_file): # inp = raw_input("Do you want to overwrite the results file? (y)es or (n)o: ") # if inp == "yes" or inp == "y": # os.remove(o_file) # print 'Old file removed.' # elif inp == "no" or inp == "n": # return np.savez_compressed(o_file, t=np.asarray(slice_t) / us, Ap=np.asarray(A_sp) / dt * us, dAp=np.asarray(dA_sp) / dt * us, At=np.asarray(A_st) / dt * us, dAt=np.asarray(dA_st) / dt * us, A=np.asarray(A_t) / dt * us, dA=np.asarray(dA_t) / dt * us)
#alpha2r, err_alpha2 = round(alpha2[1], 5), alpha2[2] #beta2r, err_beta2 = round(beta2[1], 5), beta2[2] lambda1 = lambda1.get() lambda1r, err_lambda1 = round(lambda1[1], 5), lambda1[2] #Plot 1 - Single Exponential Fit fig = plt.figure() ax = fig.add_subplot(111) plt.xlim(0, max(timescale)) plt.ylim(0, max(normcounts)+0.0002) lt.plot_exp(timescale, normcounts, marker = '|', color = 'grey', x_label = 'Decay Time ($\mu s$)', y_label = 'Probability Density ($\%$ of total detected)', plot_title = 'Muon Decay - Single Exponential Fit'), lt.plot_line(L.xpl, L.ypl, linewidth = 1.5, # linestyle = '', color = 'b', label = r'Single Exponential: $\tau$ = {0}$\mu s$'.format(round(1/lambda1r, 5))) handles, labels = ax.get_legend_handles_labels() ax.legend(handles, labels) plt.savefig('graph_{0}_SnglExp.png'.format(filename))
import LT.box as B import numpy as np import pandas as pd import LT_Fit.parameters as P import LT_Fit.gen_fit as G df = pd.read_csv( 'C:\\Users\\iw2ba\\Desktop\\Senior Physics\\NMR\\T1A7.18B3.54.csv') DIF = df['Voltage(V)'] tao = df['tao(s)'] y = np.log(0.5 * (1 - (DIF / 4.055432285469148))) B.plot_exp(tao, y, 0.02) B.pl.title('Spin Echo VS Tau Linear') B.pl.ylabel('Spin Echo (v)') B.pl.xlabel('Tau(s)') fit1 = B.linefit(tao, y) B.plot_line(fit1.xpl, fit1.ypl) slope = fit1.par[1] T1 = -1 / slope print(T1) print(1 / 0.26248527624448215) # M0 = P.Parameter(4.055432285469148, 'M0') # T1 = P.Parameter(0.04900121822053086, 'T1') # c1= P.Parameter (0,'c1')
x_bpm = B.get_data(f, 'x_bpm') y_bpm = B.get_data(f, 'y_bpm') ptrig6_acc = B.get_data(f, 'ptrig6_accepted') ptrig6_acc_err = np.sqrt(ptrig6_acc) norm_cnts = ptrig6_acc / charge norm_cnts_err = ptrig6_acc_err / charge #with error #B.plot_exp(run[(run>=3291) & (run<=3305)], ptrk_eff[(run>=3291) & (run<=3305)], ptrk_eff_err[(run>=3291) & (run<=3305)], color='r', marker='o', label = 'Pm = 580 MeV: Set 1' ) #B.plot_exp(run[(run>=3341) & (run<=3356)], ptrk_eff[(run>=3341) & (run<=3356)], ptrk_eff_err[(run>=3341) & (run<=3356)], color='b', marker='s', label = 'Pm = 580 MeV: Set 2' ) ''' #no error B.plot_exp(run[(run>=3291) & (run<=3305)], charge[(run>=3291) & (run<=3305)], color='r', marker='o', label = 'Pm = 580 MeV: Set 1' ) B.plot_exp(run[(run>=3341) & (run<=3356)], charge[(run>=3341) & (run<=3356)], color='b', marker='s', label = 'Pm = 580 MeV: Set 2' ) B.plot_exp(run, h3of4_rate, color='r', marker='o', label = 'HMS 3/4 Rate: Pm = 580 MeV/c') B.plot_exp(run, p3of4_rate, color='r', marker='s', label = 'SHMS 3/4 Rate: Pm = 580 MeV/c') B.plot_exp(run, coin_rate, color='r', marker='^', label = 'Coin 3/4 Rate: Pm = 580 MeV/c') B.plot_exp(run, cpuLT, color='r', marker='o', label = 'Computer Live Time: Pm = 580 MeV/c') B.plot_exp(run, tLT, color='b', marker='s', label = 'Total Live Time: Pm = 580 MeV/c') ''' B.plot_exp(run, x_bpm, color='r', marker='o', label = 'X BPM: Pm = 580 MeV/c') B.plot_exp(run, y_bpm, color='b', marker='s', label = 'Y BPM: Pm = 580 MeV/c')
import LT.box as B import numpy as np import pandas as pd df = pd.read_csv('C:\\Users\\iw2ba\\Desktop\\Senior Physics\\NMR\\T22.csv') spinEcho = df['Voltage(V)'] tao = df['tao(s)'] y = np.log(spinEcho) # dy = np.sqrt(((1/spinEcho)*0.02)**2) dy = df['dy'] B.plot_exp(tao, y, 0.03) B.pl.title('FID VS Tao: Linear ') B.pl.xlabel('Tao(s)') B.pl.ylabel('FID (v)') fit1 = B.linefit(tao, y) B.plot_line(fit1.xpl, fit1.ypl) # fit1 = B.polyfit(tao,spinEcho) # B.plot_line(fit1.xpl, fit1.ypl) B.pl.show() slope = fit1.par[1] T2 = -1 / slope m0 = np.exp(1.4000572874265063)
Be = np.array(Be) Be_err = np.array(Be_err) Ga = np.array(Ga) Ga_err = np.array(Ga_err) De = np.array(De) De_err = np.array(De_err) return Aa, X0, S, Al, Be, Ga, De, Aa_err, X0_err, S_err, Al_err, Be_err, Ga_err, De_err #%% Aa, X0, S, Al, Be, Ga, De, Aa_err, X0_err, S_err, Al_err, Be_err, Ga_err, De_err = fit_histo( ) #%% '''pAl = B.polyfit(pi0m, Al, Al_err, order=4) pBe = B.polyfit(pi0m, Be, Be_err, order=4) pGa = B.polyfit(pi0m, Ga, Ga_err, order=4) pDe = B.polyfit(pi0m, De, De_err, order=3) pA = B.polyfit(pi0m, Aa, Aa_err, order=4) pS = B.polyfit(pi0m, S, S_err, order=1) pM = B.polyfit(pi0m, X0, X0_err, order=1) pAl = B.polyfit(pi0m, Al, Al_err, order=4) B.plot_exp(pi0m, Al, Al_err, plot_title = "Fit the fit parameter $\\alpha$", x_label = 'bin centers of y-axis in 2D plot $M(\pi^{0})$') B.plot_line(pAl.xpl, pAl.ypl) plt.figure() pBe = B.polyfit(pi0m, Be, Be_err, order=4)
Q5 = 8.69 Q6 = 3.374 Q7 = 7.10 Q8 = 1.80 print('q = 1.764e-19 C') print('Percent error =10.11%') data = {'Qs': [1.764, 12.278, 6.97, 8.26, 8.69, 3.374, 7.10, 1.80]} df1 = pd.DataFrame(data) q_int = df1['Qs'] / Q1 df1['Q_int'] = round(q_int) df1.dropna(inplace=True) df1.reset_index(inplace=True, drop=True) B.plot_exp(df1['Q_int'], df1['Qs'], .3) B.pl.title('Method of Smallest Value') B.pl.ylabel('Drop Charge (e^-19 Coulombs)') B.pl.xlabel('# of Electrons lost') fit2 = B.linefit( df1['Q_int'], df1['Qs'], ) B.plot_line(fit2.xpl, fit2.ypl) B.pl.show()
import LT.box as B #import numpy as np #import matplotlib as mpl #import mathplotlib.pyplot as plt # get file data_file = B.get_file('estimatepi.data') # get data no_dimension = B.get_data(data_file, 'dimension') pi_estimate = B.get_data(data_file, 'piestimate') error = B.get_data(data_file, 'error') # make a plot B.plot_exp(no_dimension, pi_estimate, error) # add the labels B.pl.xlabel('Number of dimensions') B.pl.ylabel('Estimator for pi') B.pl.title('Pi estimated') # save the plot B.pl.savefig('pi_plot.png')
delta = B.Parameter(1., 'delta') def tanh_bkg(x): return alpha() + beta()*np.tanh(gamma()*(x - delta())) def signal(x): return tanh_bkg(x) + gaus_peak(x) M = hep.bin_center C = hep.bin_content dC = hep.bin_error fit = B.genfit(signal, [ A, x0, s, alpha, beta, gamma, delta], x = M, y = C, y_err = dC ) plt.figure() B.plot_exp(M, C, dC, x_label = '$M(\pi^{+}\pi^{-}\eta)$', plot_title = 'Gaussian peak on Tanh bkg ') B.plot_line(fit.xpl, fit.ypl) fit.save_parameters() al = fit.parameters_sav[3].value be = fit.parameters_sav[4].value ga = fit.parameters_sav[5].value de = fit.parameters_sav[6].value def etap_bkg(x): return al + be*np.tanh(ga*(x - de))