spectro.py 3.74 KB
 Matheus Muller committed Aug 15, 2011 1 ``````from pylab import * `````` Matheus Müller committed Aug 22, 2011 2 3 ``````from scipy.special import i1 from Edict import * `````` Matheus Muller committed Aug 15, 2011 4 5 6 `````` PI=math.pi `````` Matheus Müller committed Sep 09, 2011 7 8 9 10 11 12 ``````def CSRf(Z1, Z2, Ein, M1, M2, Theta): if M1 < M2: return ((Z1*Z2*4.8e-20*1e8)/(4*Ein))**2 * sin(Theta)**-4 * (sqrt(1-((M1/M2)*sin(Theta))**2)+cos(Theta))**2 / sqrt(1-((M1/M2)*sin(Theta))**2) else: return 0 `````` Matheus Müller committed Aug 22, 2011 13 ``````## funcoes usadas pela classe spectro `````` Matheus Muller committed Aug 15, 2011 14 15 16 17 ``````def gaussian(e, Em, sigma): # Funcao que retorna uma gaussiana centrada em Em e largura sigma return exp((-(e-Em)**2)/(2.*sigma))/sqrt(2.*PI*sigma) `````` Matheus Müller committed Sep 23, 2011 18 ``````#def modbessel(e, alpha, m, x, k, E0): `````` Matheus Muller committed Aug 15, 2011 19 20 `````` # Funcao que retorna a perda de energia de acordo com a funcao # modificada de bessel do primeiro tipo de ordem 1 `````` Matheus Müller committed Sep 09, 2011 21 `````` # N FUNCIONA! `````` Matheus Muller committed Aug 15, 2011 22 23 24 25 26 `````` ## Definindo classe referente a objetos de espectro de espalhamento class spectro_espalhamento: def __init__(self, Emin, Emax, EPasso): # Inicia o spectro no limite dado, com o passo EPasso `````` Matheus Müller committed Sep 23, 2011 27 28 `````` self.e = arange(Emin, Emax, EPasso) self.Y = e*0. `````` Matheus Muller committed Aug 15, 2011 29 `````` `````` Matheus Müller committed Sep 23, 2011 30 `````` def addbessel(self, peso, alpha, m, x, k, E0): `````` Matheus Muller committed Aug 15, 2011 31 32 `````` # Adiciona uma funcao modificada de bessel do primeiro tipo: # energia media Em, com variancia sigma com o peso dado `````` Matheus Müller committed Sep 23, 2011 33 34 35 36 `````` lbd=m*x*alpha bessel = lbd*exp(-m*x-alpha*(k*E0-e))*i1(2.*sqrt(lbd*(k*E0-e)))/(sqrt(lbd*(k*E0-e))) self.Y = self.Y + peso*bessel #modbessel(self.e, alpha, m, x, k, E0) print len(self.Y), len(self.e) `````` Matheus Muller committed Aug 15, 2011 37 38 39 40 `````` def addgauss(self,Em,sigma,peso): # Adiciona uma gaussiana ao spectro: # centrada em Em, com variancia sigma com o peso dado `````` Matheus Müller committed Sep 23, 2011 41 `````` self.Y = self.Y+peso*gaussian(self.e, Em, sigma) `````` Matheus Muller committed Aug 15, 2011 42 43 44 `````` def plot(self): # Plota o spectro `````` Matheus Müller committed Sep 09, 2011 45 `````` plt.plot(self.e,self.Y) `````` Matheus Müller committed Aug 22, 2011 46 47 48 `````` suptitle('Signal received', fontsize=12) xlabel("Enegy (eV)") ylabel("Yield") `````` Matheus Muller committed Aug 15, 2011 49 50 51 `````` show() def setparam (self, parametros): `````` Matheus Müller committed Aug 22, 2011 52 `````` # Define os parametros fixos do spectro `````` Matheus Muller committed Aug 15, 2011 53 54 55 56 57 `````` self.E0 = parametros['E0'] self.dedx = parametros['dedx'] self.dW2dx = parametros['dW2dx'] self.Theta_in = parametros['Theta_in'] self.Theta_out = parametros['Theta_out'] `````` Matheus Müller committed Aug 22, 2011 58 59 60 61 62 63 64 65 `````` self.FWHM0 = parametros['FWHM0'] self.sigma0 = pow(self.FWHM0/2.35,2.) def sweepelements(self, param, modelo, ion): for ATOM in SLOT: if SLOT[ATOM]['control']==0: pass else: `````` Matheus Müller committed Sep 23, 2011 66 `````` xstep = 0.01 `````` Matheus Müller committed Aug 22, 2011 67 `````` c = SLOT[ATOM]['dist'] `````` Matheus Müller committed Sep 23, 2011 68 `````` x = arange(0.1,20,xstep) `````` Matheus Müller committed Aug 22, 2011 69 70 71 72 73 `````` self.setparam(param) Theta_s = PI - (self.Theta_in + self.Theta_out)*PI/180 mt = SLOT[ATOM]['mass'] mi = ion['mass'] `````` Matheus Müller committed Sep 09, 2011 74 75 `````` k = ( (sqrt (mt**2+mi**2*(sin(Theta_s)**2)) + mi*cos(Theta_s) ) / (mi+mt) )**2 `````` Matheus Müller committed Sep 23, 2011 76 77 `````` for i in x: `````` Matheus Müller committed Aug 22, 2011 78 `````` if modelo == 'gaussiana': `````` Matheus Müller committed Sep 23, 2011 79 80 81 82 83 `````` sigma=i*self.dW2dx*(k**2./cos(self.Theta_in*PI/180.)+1./cos(self.Theta_out*PI/180.))+self.sigma0 Em = k*self.E0 - i*self.dedx*(k/cos(self.Theta_in*PI/180.) + 1/cos(self.Theta_out*PI/180.)) CS = CSRf(ion['Z'], SLOT[ATOM]['Z'], Em, ion['mass'], SLOT[ATOM]['mass'], Theta_s) self.addgauss(Em, sigma, c[int(i/xstep)]*k*CS) `````` Matheus Müller committed Sep 09, 2011 84 `````` elif modelo == 'bessel': `````` Matheus Müller committed Sep 23, 2011 85 86 87 88 89 90 91 `````` dedxef = self.dedx*(k/cos(self.Theta_in*PI/180.) + 1/cos(self.Theta_out*PI/180.)) dw2dxef = self.dW2dx*(k**2./cos(self.Theta_in*PI/180.)+1./cos(self.Theta_out*PI/180.)) alpha = dedxef*(2./dw2dxef) m = alpha*dedxef Em = k*self.E0-dedxef*x CS = CSRf(ion['Z'], SLOT[ATOM]['Z'], Em , ion['mass'], SLOT[ATOM]['mass'], Theta_s) self.addbessel(c[int(i/xstep)]*k*CS*xstep, alpha, m, i, k, self.E0) `````` Matheus Müller committed Sep 09, 2011 92 `````` `````` Matheus Muller committed Aug 15, 2011 93