f.add(x,y) f.dump() spline = SplineCH() spline.compile(f) spline.dump() print "================" n = 100 step = 0.8*(f.getMaxX() - f.getMinX())/(n-1) y_dev_max = 0. yp_dev_max = 0. for j in range(n): x = f.getMinX() + j*step y = FF(x) yp = FFP(x) ys = math.fabs(spline.getY(x) - y) yps = math.fabs(spline.getYP(x) - yp) if(y_dev_max < ys): #print "debug x=",x," dev y=",ys," y=",y y_dev_max = ys if(yp_dev_max < yps): #print "debug x=",x," dev yp=",yps," yp=",yp yp_dev_max = yps print " deviation y max =",y_dev_max print " deviation yp max =",yp_dev_max
def makeTransitTimeTables(self,beta_min,beta_max,n_table_points,rf_freq): """ It will calculate transit time factor tables for all RF gaps TTFs (T,S,Tp,Sp) are funcftions of the cappa variable = 2*pi*f/(c*beta) """ self.rf_freq = rf_freq c_light = 2.99792458e+8 self.beta_arr = [] self.cappa_arr = [] for i_beta in range(n_table_points): beta = beta_min + i_beta*(beta_max-beta_min)/(n_table_points-1) cappa = 2*math.pi*rf_freq/(c_light*beta) self.beta_arr.append(beta) self.cappa_arr.append(cappa) self.beta_arr.reverse() self.cappa_arr.reverse() #--calculate realtive gap amplitudes integral = GaussLegendreIntegrator(500) e0l_arr = [] e0l_sum = 0. for i in range(len(self.gap_slpline_arr)): [gap_length,x_center,splineGap] = self.gap_slpline_arr[i] n = splineGap.getSize() x_min = splineGap.x(0) x_max = splineGap.x(n-1) integral.setLimits(x_min,x_max) e0l = integral.integral(splineGap) e0l_sum += e0l e0l_arr.append(e0l) self.e0_normalized_arr = [] self.e0l_normalized_arr = [] e0_norm = e0l_arr[0]/self.gap_slpline_arr[0][0] e0l_norm = e0l_arr[0] for i in range(len(e0l_arr)): self.e0_normalized_arr.append((e0l_arr[i]/self.gap_slpline_arr[i][0])/e0_norm) self.e0l_normalized_arr.append((e0l_arr[i]/e0l_norm)) #--- calculate transit time factors self.ttp_ssp_gap_arr = [] for i in range(len(self.gap_slpline_arr)): func_T = Function() func_TP = Function() func_S = Function() func_SP = Function() self.ttp_ssp_gap_arr.append([func_T,func_TP,func_S,func_SP]) for i_gap in range(len(self.gap_slpline_arr)): [func_T,func_TP,func_S,func_SP] = self.ttp_ssp_gap_arr[i_gap] [gap_length,x0,spline] = self.gap_slpline_arr[i_gap] x_min = spline.x(0) x_max = spline.x(spline.getSize()-1) integral.setLimits(x_min,x_max) for i_beta in range(n_table_points): beta = self.beta_arr[i_beta] cappa = self.cappa_arr[i_beta] f_cos = Function() f_sin = Function() for isp in range(spline.getSize()): x = spline.x(isp) y = spline.y(isp) phase = cappa*x s = math.sin(phase) c = math.cos(phase) f_cos.add(x,c*y) f_sin.add(x,s*y) f_sp_cos = SplineCH() f_sp_sin = SplineCH() f_sp_cos.compile(f_cos) f_sp_sin.compile(f_sin) T = integral.integral(f_sp_cos) S = integral.integral(f_sp_sin) func_T.add(cappa,T/e0l_arr[i_gap]) func_S.add(cappa,S/e0l_arr[i_gap]) spline_T = SplineCH() spline_S = SplineCH() spline_T.compile(func_T) spline_S.compile(func_S) for i_beta in range(spline_T.getSize()): cappa = spline_T.x(i_beta) TP = spline_T.getYP(cappa) SP = spline_S.getYP(cappa) func_TP.add(cappa,TP) func_SP.add(cappa,SP) return self.ttp_ssp_gap_arr