def load_od(): od = np.vstack( (rd.read_h5py_file(path, data_le), rd.read_h5py_file(path, data_he))) od_psd = rd.slice_selection(od, 21, 60, 90) od_all = rd.slice_selection(od_psd, 3, 70, 20000) od_all = rd.slice_selection(od_all, 1, 650, 30000) od_all = rd.slice_selection(od_all, 17, 4e-9, 7e-9) c = 2.998e8 m = 511 / c**2 od_all = od_all[abs(20 * np.pi / 180 - abs( np.arccos(1 - (od_all[:, 3] / od_all[:, 1] * m * c**2 / (od_all[:, 3] + od_all[:, 1])))) <= 16 * np.pi / 180)] od_all = od_all[od_all[:, 22] > 0] od_all = od_all[od_all[:, 23] > 0] return od, od_psd, od_all
def optimize_ToF_parameters(forward=True, num_bins=100, data=None): d = rd.read_h5py_file() d = data if not type(data) == type(None) else d d = rd.slice_selection(d, 17, 3.5e-9, 9e-9) if forward: df = rd.cut_selection(d, 9, 0) tf = rd.extract_parameter(df, 17) n, bins, patches = plt.hist(tf, num_bins) x = bins x_data = bins[:-1] + (bins[1] - bins[0]) / 2 y_data = n popt, pcov = curve_fit(forward_ToF, x_data, y_data, (0.4e-9, 150, 1e-13)) y = np.array([forward_ToF(i, popt[0], popt[1], popt[2]) for i in x]) plt.plot(x, y, lw=2.0) else: db = rd.cut_selection(d, 9, 0, False) tb = rd.extract_parameter(db, 17) n, bins, patches = plt.hist(tb, num_bins) x = bins x_data = bins[:-1] + (bins[1] - bins[0]) / 2 y_data = n popt, pcov = curve_fit(backward_ToF, x_data, y_data, (0.4e-9, 150, 1e-13)) y = np.array([backward_ToF(i, popt[0], popt[1], popt[2]) for i in x]) plt.plot(x, y, lw=2.0) # plt.xlabel("Time of Flight [s]") # plt.ylabel("Frequency [Counts/Bin]") return popt, pcov
def SAD_CROSS_GOOD(forward, num_bins=50): d = rd.read_h5py_file() d = rd.cut_selection(d, 9, 0, forward) # E_e=rd.extract_parameter(d, 3) # E_g=rd.extract_parameter(d, 1) c = 2.998e8 m = 511 / c**2 # a_E=np.arccos( 1 - (E_e/E_g*m*c**2/(E_e+E_g)) ) # a_P=rd.calculate_angles(d) # a=np.array([]) # for i in range(len(a_E)): # if abs(a_E[i]-a_P[i])<0.01: # a=np.append(a,a_P[i]) margin = 0.01 d = d[abs( np.arccos(1 - (d[:, 3] / d[:, 1] * m * c**2 / (d[:, 3] + d[:, 1]))) - np.arccos(-1 * (-d[:, 9] + d[:, 15]) / d[:, 24])) <= margin] a = rd.calculate_angles(d) n, bins, patches = plt.hist(a, num_bins) if forward: D = pd.NF x_min = at.fsad_min x_max = at.fsad_max else: D = pd.NB x_min = at.bsad_min x_max = at.bsad_max D = D * np.amax(n) / np.amax(D) rd.plot_points(D, x_min, x_max) plt.xlabel("Scattering Angle [rad]") plt.ylabel("Frequency [Counts/Bins]")
def calculate_data_rates(): data = np.array([ rd.cut_selection(rd.read_h5py_file(p_cra0, h5_cra0), 9, 0, True), rd.cut_selection(rd.read_h5py_file(p_cos, h5_cos), 9, 0, True), rd.cut_selection(rd.read_h5py_file(p_alb, h5_alb), 9, 0, True), rd.cut_selection(rd.read_h5py_file(p_act, h5_act), 9, 0, True), rd.cut_selection(rd.read_h5py_file(p_act, h5_act_f), 9, 0, True) ]) datat = np.array([ rd.read_h5py_file(p_cra0, h5_cra0), rd.read_h5py_file(p_cos, h5_cos), rd.read_h5py_file(p_alb, h5_alb), rd.read_h5py_file(p_act, h5_act), rd.read_h5py_file(p_act, h5_act_f) ]) for i in range(len(data)): E = data[i].shape[0] ET = datat[i].shape[0] print(E, E / ET, E / sim_times[i], sim_times[i])
def werner_cut_comparison(): fig=plt.figure(figsize=(10,10)) cut1_plot=mpimg.imread(p_werner_cuts+"Cut8.jpg") plt.imshow(cut1_plot) d=rd.read_h5py_file(p_data,"Thesis_Simulations\\Real_COMPTEL_data"+"\\h5_vp426_09-43") dc=rd.read_h5py_file(p_data,"Thesis_Simulations\\Real_COMPTEL_data"+"\\h5_vp426_09-43_c") E_e=dc[:,3] E_g=dc[:,1] c=2.998e8 m=511/c**2 phibar=np.arccos( 1 - (E_e/E_g*m*c**2/(E_e+E_g)) ) phigeo=np.arccos( -( -dc[:,9]+dc[:,15] ) / dc[:,24]) ARM=phibar-phigeo for i in range(20): print(i) print("Phibar:", phibar[i]*180/np.pi,d[i,5]) print("ARM:",ARM[i]*180/np.pi,d[i,14])
def plot_ang_dist(forward, num_bins=100, data_array=None): d = rd.read_h5py_file() d = rd.cut_selection(d, 9, 0, forward) a = rd.calculate_angles(d) a = data_array if not type(data_array) == type(None) else a n, bins, patches = plt.hist(a, num_bins) if forward: D = NF x_min = at.fsad_min x_max = at.fsad_max else: D = NB x_min = at.bsad_min x_max = at.bsad_max D = D * np.amax(n) / np.amax(D) rd.plot_points(D, x_min, x_max, 2.0)
def plot_E_all(): scale1 = 1.7 x_min = 0 x_max = 6000 d = rd.read_h5py_file() d = rd.cut_selection(d, 9, 0, True) E = rd.extract_parameter(d, 1) # + rd.extract_parameter(d, 3) n, bins, patches = plt.hist(E, 500) x = np.linspace(x_min, x_max, 200) y = np.array([at.energy_distribution(i) for i in x]) y = y * np.amax(n) / np.amax(y) * scale1 #plt.plot(x,y,label="A") plt.xlim(x_min, x_max) plt.xlabel("Detected Energy [keV]") plt.ylabel("Frequency [Counts/Bin]")
def SAD_E(forward, num_bins=100, data_array=None): d = rd.read_h5py_file() if type(data_array) == type(None) else data_array d = rd.cut_selection(d, 9, 0, forward) E_e = rd.extract_parameter(d, 3) E_g = rd.extract_parameter(d, 1) c = 2.998e8 m = 511 / c**2 a = np.arccos(1 - (E_e / E_g * m * c**2 / (E_e + E_g))) n, bins, patches = plt.hist(a, num_bins) if forward: D = pd.NF x_min = at.fsad_min x_max = at.fsad_max else: D = pd.NB x_min = at.bsad_min x_max = at.bsad_max D = D * np.amax(n) / np.amax(D) rd.plot_points(D, x_min, x_max, 2.0)
def events_per_cell(forward=True, D1=True, text=True): d = rd.read_h5py_file() if forward: d = rd.cut_selection(d, 9, 0) if D1: N = Nfor1 par1 = 5 par2 = 7 points = rd.D1_points else: N = Nfor2 par1 = 11 par2 = 13 points = rd.D2_points else: d = rd.cut_selection(d, 9, 0, False) if D1: N = Nba1 par1 = 11 par2 = 13 points = rd.D1_points else: N = Nba2 par1 = 5 par2 = 7 points = rd.D2_points rd.plot_histogram_2D(d, par1, par2) s = 0 for i in N: s += i N = N * len(d) / s if text: for i in range(len(points)): plt.text(points[i, 0], points[i, 1], "M=" + str(len(rd.select_cell(d, i, forward, D1))) + "\n E=" + str(int(N[i])), ha="center", va="center", bbox=dict(facecolor='white', edgecolor='none'))
def plot_histogram_and_optimized_distribution(num_bins=100, forward=True): d = rd.read_h5py_file() d = rd.cut_selection(d, 9, 0, forward) data_array = rd.calculate_angles(d) if forward: distribution_points, x_min, x_max = fsad, fsad_min, fsad_max else: distribution_points, x_min, x_max = bsad, bsad_min, bsad_max n, bins = plot_histogram_and_distribution(data_array, distribution_points, x_min, x_max, num_bins) x_data = bins[:-1] + (bins[1] - bins[0]) / 2 y_data = n if forward: popt, pcov = curve_fit(fsad_correction, x_data, y_data) #plt.plot(x_data,fsad_correction(x_data,*popt),color="C8",lw=3.0) else: popt, pcov = curve_fit(bsad_correction, x_data, y_data) #plt.plot(x_data,bsad_correction(x_data,*popt),color="C8",lw=3.0) #plt.xlabel("Scattering Angle [rad]") #plt.ylabel("Frequency [Counts/Bin]") return popt, pcov
def SAD_E_vs_Pos(forward, size=100, data_array=None): d = rd.read_h5py_file() if type(data_array) == None else data_array d = rd.cut_selection(d, 9, 0, forward) E_e = rd.extract_parameter(d, 3) E_g = rd.extract_parameter(d, 1) c = 2.998e8 m = 511 / c**2 a_E = np.arccos(1 - (E_e / E_g * m * c**2 / (E_e + E_g))) a_P = rd.calculate_angles(d) c = 0 while c < len(a_E): if np.isnan(a_E[c]): a_E = np.delete(a_E, c) a_P = np.delete(a_P, c) c += -1 c += 1 plt.hist2d(a_E, a_P, bins=(size, size)) if forward: x = np.linspace(at.fsad_min, at.fsad_max, size) plt.plot(x, x, color="C1") else: x = np.linspace(at.bsad_min, at.bsad_max, size) plt.plot(x, x, color="C1")
def plot_E_dist( forward, num_bins=300, ): x_min = 0000 x_max = 5000 y_min = 0 #y_max=140000 scale1 = 1.8 scale2 = 1 d = rd.read_h5py_file() d = rd.cut_selection(d, 9, 0, forward) E = rd.extract_parameter(d, 1) + rd.extract_parameter(d, 3) n, bins, patches = plt.hist(E, num_bins) x = np.linspace(x_min, x_max, 100) y = np.array([at.energy_distribution(i) for i in x]) y = y * np.amax(n) / np.amax(y) * scale1 plt.plot(x, y, label="A") if forward: t_min, t_max, sad = at.fsad_min, at.fsad_max, at.fsad else: t_min, t_max, sad = at.bsad_min, at.bsad_max, at.bsad y2 = np.array([ quad(integrand1, t_min, t_max, (i, forward, t_min, t_max, sad), 0, 10e-5, 10e-5)[0] for i in x ]) y2 = y2 * np.amax(n) / np.amax(y2) * scale2 plt.plot(x, y2, label="B") plt.xlabel("Total Detected Energy [keV]") plt.ylabel("Frequency [Counts/Bin]") plt.legend() plt.xlim(x_min, x_max) plt.ylim(0, 50000)
def E1_E2_2D_hist(): fig=plt.figure(figsize=(8,12)) grid=plt.GridSpec(4, 2,hspace=0.15,wspace=0.30) pa=fig.add_subplot(grid[:,:]) pa.spines['top'].set_color('none') pa.spines['bottom'].set_color('none') pa.spines['left'].set_color('none') pa.spines['right'].set_color('none') plt.tick_params(axis='both', which='both', bottom=False, top=False, labelbottom=False, right=False, left=False, labelleft=False) pa.set_xlabel("E1 [MeV]",labelpad=30) pa.set_ylabel("E2 [MeV]",labelpad=40) rows={0:"1500",1:"5000",2:"15000",3:"50000"} energies={0:"1.5",1:"5",2:"15",3:"50"} columns={0:True,1:False} letters=np.array([["a","b"], ["c","d"], ["e","f"], ["g","h"]]) num_bins=100 for row in range(len(rows)): for column in range(len(columns)): temp=fig.add_subplot(grid[row,column]) d=rd.read_h5py_file(p_data+"Thesis_Simulations/"+"Mono_"+rows[row]+"/","Mono_"+rows[row]+"_h5") d=rd.cut_selection(d,9,0,columns[column]) if columns[column]: E1=rd.extract_parameter(d, 3)/1000 E2=rd.extract_parameter(d, 1)/1000 else: E1=rd.extract_parameter(d, 1)/1000 E2=rd.extract_parameter(d, 3)/1000 logbins1 = np.geomspace(E1.min(), E1.max(), num_bins) logbins2 = np.geomspace(E2.min(), E2.max(), num_bins) counts, _, _ = np.histogram2d(E1, E2, bins=(logbins1, logbins2)) temp.pcolormesh(logbins1, logbins2, counts.T) temp.plot() temp.set_xscale('log') temp.set_yscale('log') temp.plot(logbins1,float(energies[row])-logbins1,color="C1",lw=1.0) plt.ylim(logbins2[0],logbins2[-1]) if column==1: if row==1: plt.ylim(1.5,logbins2[-1]) elif row==2: plt.ylim(5,logbins2[-1]) elif row==3: plt.ylim(10,logbins2[-1]) if row==0: if column==0: temp.set_xlabel("Forward Photons") temp.xaxis.set_label_position("top") elif column==1: temp.set_xlabel("Backward Photons") temp.xaxis.set_label_position("top") if column==1: temp.set_ylabel(energies[row]+"MeV") temp.yaxis.set_label_position("right") if column==0: angs=(1,10,20,30,40,50) ang_lines=np.zeros((len(angs),num_bins)) for ang in range(len(angs)): for b in range(num_bins): e_sca=logbins2[b] wl_sca=6.625e-34*3e8/(1.602e-19*float(e_sca)*1e6) wl_ini=wl_sca-2.426e-12*(1-np.cos(angs[ang]*np.pi/180)) e_ini=6.625e-34*3e8/(1.602e-19*wl_ini)*1e-6 ang_lines[ang,b]=e_ini-e_sca if e_ini-e_sca>0 else float("NaN") for ang in range(len(angs)): temp.plot(ang_lines[ang],logbins2,color="C6",lw=1) for b in range(num_bins): if ang_lines[ang,b]>E1.min(): plt.text(ang_lines[ang,b],logbins2[b],str(angs[ang])+"$^\circ$",color="bisque") break else: mult=10 logbinse=np.geomspace(E1.min(), E1.max(), num_bins*mult) angs=(180,140) ang_lines=np.zeros((len(angs),num_bins*mult)) for ang in range(len(angs)): for b in range(num_bins*mult): e_sca=logbinse[b] wl_sca=6.625e-34*3e8/(1.602e-19*float(e_sca)*1e6) wl_ini=wl_sca-2.426e-12*(1-np.cos(angs[ang]*np.pi/180)) e_ini=6.625e-34*3e8/(1.602e-19*wl_ini)*1e-6 ang_lines[ang,b]=e_ini-e_sca if e_ini-e_sca>0 else float("NaN") left_shift=((3/4,1), (2/3,1), (3/5,1), (1/2,1)) for ang in range(len(angs)): temp.plot(logbinse,ang_lines[ang],color="C6",lw=1) for b in range(num_bins*mult): if ang_lines[ang,b]>E2.min(): plt.text(logbinse[b]*left_shift[row][ang],ang_lines[ang,b],str(angs[ang])+"$^\circ$",color="bisque") break plt.xlim(E1.min(),np.amax(E1)) plt.ylim(E2.min(),np.amax(E2)) temp.text(-0.10,0.97,"("+letters[row,column]+")",transform=temp.transAxes,ha='left', va='center') plt.savefig(p_plots+'E1_E2_2D_hist.pdf',bbox_inches='tight')
def crab_outlier_distributions(): fig=plt.figure(figsize=(10,13)) grid1=plt.GridSpec(1, 3,hspace=0.2,wspace=0.25,bottom=0.73) grid2=plt.GridSpec(3,3,hspace=0.05,wspace=0.05,top=0.65) d=rd.read_h5py_file(p_data+"Thesis_Simulations/Simulation_Batch_3/","Simulation1") d=rd.cut_selection(d,9,0,True) c=2.998e8 m=511/c**2 rang=0.08 dc=d[np.abs( np.minimum( np.abs(np.arccos( -( -d[:,9]+d[:,15] ) / d[:,24])*np.sign(d[:,11]-d[:,5]) - np.arccos( 1 - (d[:,3]/d[:,1]*m*c**2/(d[:,3]+d[:,1])) ) ) , np.abs(np.arccos( -( -d[:,9]+d[:,15] ) / d[:,24])*np.sign(d[:,11]-d[:,5]) + np.arccos( 1 - (d[:,3]/d[:,1]*m*c**2/(d[:,3]+d[:,1])) ) ) ))>rang] temp=fig.add_subplot(grid1[0,0]) n1,bins1=pc.create_ARM_plot(dc,200,1,True) n2,bins2=pc.create_ARM_plot(d,200,1,False) temp.axhline(0,c="black",lw=0.8) plt.plot(bins1,n2,c="C2") plt.plot(bins1,n1-n2,c="C3") temp.set_xlabel("Angle of Incidence [rad]") temp.set_ylabel("Frequency [Counts/Bin]") temp.text(0.01,0.99,"(a)",transform=temp.transAxes,ha='left', va='top') temp=fig.add_subplot(grid1[0,1]) bins1,n1=pc.plot_flight_angle(dc,False,50) bins2,n2=pc.plot_flight_angle(d,True,50) n2=n2/np.sum(n2)*np.sum(n1) temp.axhline(0,c="black",lw=0.8) plt.plot(bins1,n2,c="C2") plt.plot(bins1,n1-n2,c="C3") temp.set_xlabel("Flight Angle [rad]") secax=temp.secondary_xaxis("top",functions=(lambda d:d*180/np.pi,lambda r:r*np.pi/180)) secax.set_xlabel("Flight Angle [degrees]") temp.text(0.01,0.99,"(b)",transform=temp.transAxes,ha='left', va='top') temp=fig.add_subplot(grid1[0,2]) dct=dc[np.logical_and(dc[:,17]>4e-9,dc[:,17]<7.5e-9)] dt=d[np.logical_and(d[:,17]>4e-9, d[:,17]<7.5e-9)] bins1,n1=pc.plot_ToF(dct,False,50) bins2,n2=pc.plot_ToF(dt,True,50) n2=n2/np.sum(n2)*np.sum(n1) temp.axhline(0,c="black",lw=0.8) plt.plot(bins1,n2,c="C2") plt.plot(bins1,n1-n2,c="C3") temp.set_xlabel("Time of Flight [ns]") temp.text(0.01,0.99,"(c)",transform=temp.transAxes,ha='left', va='top') emp=fig.add_subplot(grid2[2,0]) emp.spines['top'].set_color('none') emp.spines['bottom'].set_color('none') emp.spines['left'].set_color('none') emp.spines['right'].set_color('none') plt.tick_params(axis='both', which='both', bottom=False, top=False, labelbottom=False, right=False, left=False, labelleft=False) custom_lines = [Line2D([0], [0], color="C0", lw=10), Line2D([0], [0], color="C2", lw=1.5), Line2D([0], [0], color="C3", lw=1.5),] plt.legend(custom_lines, ['Crab after Cut', 'Crab before Cut' , 'Residual'],loc="lower left") E1_min=0.04 E2_min=0.4 E_max=20 temp=fig.add_subplot(grid2[0:2,0]) bins1,n1=pc.plot_E2_vert(dc,False,50) bins2,n2=pc.plot_E2_vert(d,True,50) n2=n2/np.sum(n2)*np.sum(n1) temp.axvline(0,c="black",lw=0.8) plt.plot(n2,bins1,c="C2") plt.plot(n1-n2,bins1,c="C3") plt.ylim(E2_min,E_max) temp.set_ylabel("E2 [MeV]") temp.set_xlabel("Frequency\n[Counts/Bins]") temp.text(0.01,0.99,"(d)",transform=temp.transAxes,ha='left', va='top') temp=fig.add_subplot(grid2[2,1:3]) bins1,n1=pc.plot_E1(dc,False,50) bins2,n2=pc.plot_E1(d,True,50) n2=n2/np.sum(n2)*np.sum(n1) temp.axhline(0,c="black",lw=0.8) plt.plot(bins1,n2,c="C2") plt.plot(bins1,n1-n2,c="C3") temp.set_xlabel("E1 [MeV]") temp.set_ylabel("Frequency\n[Counts/Bins]") temp.text(0.01,0.99,"(f)",transform=temp.transAxes,ha='left', va='top') plt.xlim(E1_min,E_max) temp=fig.add_subplot(grid2[0:2,1:3]) pcmap=pc.plot_E1_E2(d,temp,label_pos_left=False) plt.colorbar(pcmap,ax=emp,orientation="horizontal",).set_label("Frequency [Counts/Bin]") plt.xlim(E1_min,E_max) plt.ylim(E2_min,E_max) temp.xaxis.tick_top() temp.yaxis.tick_right() temp.xaxis.set_label_position("top") temp.yaxis.set_label_position("right") temp.set_xlabel("E1 [MeV]") temp.set_ylabel("E2 [MeV]") temp.text(0,1,"(e)",transform=temp.transAxes,ha='left', va='top',bbox=dict(facecolor='white', edgecolor='none')) plt.savefig(p_plots+'Crab_ARM_Cut.pdf',bbox_inches='tight')
def parameter_cut(num_bins=(1, 1, 1, 1, 1), soft=True, w_fast=False, fit=True): ranges = ((4e-9, 7e-9), (np.log(70), np.log(20000)), (np.log(650), np.log(30000)), (np.log(900), np.log(30000)), (0 * np.pi / 180, 40 * np.pi / 180)) od = load_od()[2] odc = cut_converter(od) sim_d, sim_t = (raw_sim_data, sim_times) if w_fast else (raw_sim_data[:-1], sim_times[:-1]) t_min = np.min(sim_t) S, bins = np.histogramdd(cut_converter(sim_d[0]), bins=num_bins, range=ranges) S = S / sim_t[0] * t_min if soft: B = np.zeros(S.shape) for i in range(1, len(sim_d)): B += np.histogramdd(cut_converter(sim_d[i]), bins=num_bins, range=ranges)[0] / sim_t[i] * t_min T = S / (S + B) T = np.nan_to_num(T) T = T / np.amax(T) output = np.empty(od.shape) output[:, :] = np.NaN for row in range(len(od)): if (odc[row, 0] < ranges[0][0] or odc[row, 0] >= ranges[0][1] or odc[row, 1] < ranges[1][0] or odc[row, 1] >= ranges[1][1] or odc[row, 2] < ranges[2][0] or odc[row, 2] >= ranges[2][1] or odc[row, 3] < ranges[3][0] or odc[row, 3] >= ranges[3][1] or odc[row, 4] < ranges[4][0] or odc[row, 4] >= ranges[4][1]): #print(odc[row,:]) continue for i in range(len(bins[0]) - 1): if odc[row, 0] >= bins[0][i] and odc[row, 0] < bins[0][i + 1]: p1 = i for i in range(len(bins[1]) - 1): if odc[row, 1] >= bins[1][i] and odc[row, 1] < bins[1][i + 1]: p2 = i for i in range(len(bins[2]) - 1): if odc[row, 2] >= bins[2][i] and odc[row, 2] < bins[2][i + 1]: p3 = i for i in range(len(bins[3]) - 1): if odc[row, 3] >= bins[3][i] and odc[row, 3] < bins[3][i + 1]: p4 = i for i in range(len(bins[4]) - 1): if odc[row, 4] >= bins[4][i] and odc[row, 4] < bins[4][i + 1]: p5 = i #print(row) if np.random.rand() <= T[p1, p2, p3, p4, p5]: output[row, :] = od[row, :] else: odm = np.histogramdd(odc, bins=num_bins, range=ranges)[0] S = S / np.amax(S) odm = odm / np.amax(odm) if fit: a = minimize(rd.fit_func, 1, (odm, S)).x print(a) T = S * a output = np.empty(od.shape) output[:, :] = np.NaN for row in range(len(od)): if (odc[row, 0] < ranges[0][0] or odc[row, 0] >= ranges[0][1] or odc[row, 1] < ranges[1][0] or odc[row, 1] >= ranges[1][1] or odc[row, 2] < ranges[2][0] or odc[row, 2] >= ranges[2][1] or odc[row, 3] < ranges[3][0] or odc[row, 3] >= ranges[3][1] or odc[row, 4] < ranges[4][0] or odc[row, 4] >= ranges[4][1]): #print(odc[row,:]) continue for i in range(len(bins[0]) - 1): if odc[row, 0] >= bins[0][i] and odc[row, 0] < bins[0][i + 1]: p1 = i for i in range(len(bins[1]) - 1): if odc[row, 1] >= bins[1][i] and odc[row, 1] < bins[1][i + 1]: p2 = i for i in range(len(bins[2]) - 1): if odc[row, 2] >= bins[2][i] and odc[row, 2] < bins[2][i + 1]: p3 = i for i in range(len(bins[3]) - 1): if odc[row, 3] >= bins[3][i] and odc[row, 3] < bins[3][i + 1]: p4 = i for i in range(len(bins[4]) - 1): if odc[row, 4] >= bins[4][i] and odc[row, 4] < bins[4][i + 1]: p5 = i #print(row) if T[p1, p2, p3, p4, p5] > odm[p1, p2, p3, p4, p5] or np.random.rand( ) <= T[p1, p2, p3, p4, p5] / odm[p1, p2, p3, p4, p5]: output[row, :] = od[row, :] else: a = np.min(odm / S) print(a) T = S * a output = np.empty(od.shape) output[:, :] = np.NaN for row in range(len(od)): if (odc[row, 0] < ranges[0][0] or odc[row, 0] >= ranges[0][1] or odc[row, 1] < ranges[1][0] or odc[row, 1] >= ranges[1][1] or odc[row, 2] < ranges[2][0] or odc[row, 2] >= ranges[2][1] or odc[row, 3] < ranges[3][0] or odc[row, 3] >= ranges[3][1] or odc[row, 4] < ranges[4][0] or odc[row, 4] >= ranges[4][1]): #print(odc[row,:]) continue for i in range(len(bins[0]) - 1): if odc[row, 0] >= bins[0][i] and odc[row, 0] < bins[0][i + 1]: p1 = i for i in range(len(bins[1]) - 1): if odc[row, 1] >= bins[1][i] and odc[row, 1] < bins[1][i + 1]: p2 = i for i in range(len(bins[2]) - 1): if odc[row, 2] >= bins[2][i] and odc[row, 2] < bins[2][i + 1]: p3 = i for i in range(len(bins[3]) - 1): if odc[row, 3] >= bins[3][i] and odc[row, 3] < bins[3][i + 1]: p4 = i for i in range(len(bins[4]) - 1): if odc[row, 4] >= bins[4][i] and odc[row, 4] < bins[4][i + 1]: p5 = i #print(row) if T[p1, p2, p3, p4, p5] > odm[p1, p2, p3, p4, p5] or np.random.rand( ) <= T[p1, p2, p3, p4, p5] / odm[p1, p2, p3, p4, p5]: output[row, :] = od[row, :] d = rd.read_h5py_file() d = rd.cut_selection(d, 9, 0, True) x1, n1 = plot_ARM(output) x2, n2 = plot_ARM(d, True) n2 = (n1[48] + n1[49] + n1[50] + n1[51]) / (n2[48] + n2[49] + n2[50] + n2[51]) * n2 plt.plot(x2, n2, label="Crab Simulation", lw=2.0) x3, n3 = plot_ARM(od, True) n3 = (n1[48] + n1[49] + n1[50] + n1[51]) / (n3[48] + n3[49] + n3[50] + n3[51]) * n3 plt.plot(x3, n3, label="Before Cuts", lw=2.0)
od_psd = rd.slice_selection(od, 21, 60, 90) od_all = rd.slice_selection(od_psd, 3, 70, 20000) od_all = rd.slice_selection(od_all, 1, 650, 30000) od_all = rd.slice_selection(od_all, 17, 4e-9, 7e-9) c = 2.998e8 m = 511 / c**2 od_all = od_all[abs(20 * np.pi / 180 - abs( np.arccos(1 - (od_all[:, 3] / od_all[:, 1] * m * c**2 / (od_all[:, 3] + od_all[:, 1])))) <= 16 * np.pi / 180)] od_all = od_all[od_all[:, 22] > 0] od_all = od_all[od_all[:, 23] > 0] return od, od_psd, od_all raw_sim_data = [ rd.cut_selection(rd.read_h5py_file(p_pre + p_cra0, h5_cra0), 9, 0, True), rd.cut_selection(rd.read_h5py_file(p_pre + p_cos, h5_cos), 9, 0, True), rd.cut_selection(rd.read_h5py_file(p_pre + p_alb, h5_alb), 9, 0, True), rd.cut_selection(rd.read_h5py_file(p_pre + p_act, h5_act), 9, 0, True), rd.cut_selection(rd.read_h5py_file(p_pre + p_act, h5_act_f), 9, 0, True) ] sim_times = np.array([t_cra0, t_cos, t_alb, t_act, t_act_f]) parameters = { 0: "Line", 1: "Time", 2: "E1", 3: "E2", 4: "E Total", 5: "Phibar",