Changeset 490 in ETALON for CLIO


Ignore:
Timestamp:
Apr 18, 2016, 12:36:31 PM (8 years ago)
Author:
hodnevuc
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CLIO/CTR+gfw/GFWnew/GFWnew.m

    r471 r490  
    1   function  [nu_Hz,SP_spec_1,SP_spec_N,lam,E_total,sum_tr,thet]=GFWnew(var)
    2 
    3 %  single_elec
    4 % close all; clear all; clc
     1 %SP space charge model, spectrum calculation
     2 % close all; clear all; clc
     3 % var='PrSelect=1; P_file=''../p20.mat''; PlotFunc=[1 1 1 1 1]; ';
     4function  [nu_Hz,SP_spec_1,SP_spec_N,lam,E_total,sum_tr,thet]=GFWnew(var)
     5%% Output parameters
     6%nu_Hz -- frequency in Hz
     7%SP_spec_1 -- single electron yield from frequency, J/THz
     8%SP_spec_N -- whole spectrum from frequency, J/THz
     9%lam -- wavelength in mm
     10%E_total -- total energy emitted, J
     11%sum_tr -- spectrum from Theta,  J
     12%thet -- observation angle, Thetadegrees
    513%% Configuration of calculation
    614%PrSelect == what profile to use: 1 --from file; 2 - assymmetric gaussian
     
    1220%   4 -- Bunch profile
    1321%   5 -- dI(nu)/dnu (SP spetrum for signle elctron bunch)
    14 % var='PrSelect=1; P_file=''../p20.mat''; PlotFunc=[1 1 1 1 1]; ';
    1522PrSelect=2;
    1623PlotFunc=[0 0 0 0 0];
     
    4653ThetaDiv=10;%steps in theta
    4754phiDiv=3;%steps in phi
    48 
     55saveflag=0;%set to 1 if you want to save model parameters
    4956if (~isempty(var))
    50 strread(var,'%s','delimiter',' ')
     57strread(var,'%s','delimiter',';')
    5158eval(var);
    5259end %if
    5360
    5461%save all parameters
     62if (saveflag)
    5563name=regexprep(var,'.mat','');
    5664name=regexprep(name,'[../''[]]','');
    5765name=regexprep(name,'[; ]','_');
    58 % save([ name 'SP.mat'])
    59 %% Profile selection
    60 if PrSelect==1
    61     FFTspec=1;
    62   if  exist(P_file,'file')==2;
    63     load([P_file]);
    64   else
    65       disp('Set correct file name!')
    66   end
    67 else
    68     FFTspec=1;%how to calculate form factor: 1 -- FFT; 2 -- only fro assymetric gaussian
    69 %Gaussian
    70 sigma_t= pulse_len_ps/(sqrt(2*log(2))*(1+epsl))*1e-3;  %The sigma of the leading edge    ns
    71 
    72 nu=(1:1e+10:3e+13).*1e-9;%Ghz
    73 
    74 sigma_L= sigma_t*epsl;
    75 sigma_H= sigma_t;
    76 time=(1:(length(nu)*2))*(1/(length(nu)*2*(nu(2)-nu(1))));
    77 xc=mean(time);
    78 G1=exp(-(time-xc).^2./(2*sigma_L^2));
    79 G2=exp(-(time-xc).^2./(2*sigma_H^2));
    80 G1(time>xc)=0;
    81 G2(time<xc)=0;
    82 Profile=(G1+G2)./sum(G1+G2);
     66 save([ name 'SP.mat'])
    8367end
    8468
     
    10690disp([num2str(res1) ' of the beam above the grating'])
    10791n_e=n_e_t*res1;                                                 %Number of electrons above the grating
    108 % save([ name '_additional_SP.mat'])
     92numax=c/(el_mm*(1/beta-cos(ThetaStart))/m*1e-3);%max freq in Hz
     93
     94 if (saveflag)
     95save([ name '_additional_SP.mat'])
     96 end
     97 %% Profile selection
     98if PrSelect==1
     99    FFTspec=1;
     100  if  exist(P_file,'file')==2;
     101    load([P_file]);
     102  else
     103      error('Set correct file name!')
     104  end
     105else
     106    FFTspec=1;%how to calculate form factor: 1 -- FFT; 2 -- only fro assymetric gaussian
     107%Gaussian
     108sigma_t= pulse_len_ps/(sqrt(2*log(2))*(1+epsl))*1e-3;  %The sigma of the leading edge    ns
     109nu=(1:1e+10:(2*numax)).*1e-9;%Ghz
     110
     111sigma_L= sigma_t*epsl;
     112sigma_H= sigma_t;
     113time=(1:(length(nu)*2))*(1/(length(nu)*2*(nu(2)-nu(1))));
     114xc=mean(time);
     115G1=exp(-(time-xc).^2./(2*sigma_L^2));
     116G2=exp(-(time-xc).^2./(2*sigma_H^2));
     117G1(time>xc)=0;
     118G2(time<xc)=0;
     119Profile=(G1+G2)./sum(G1+G2);
     120end
     121if isnan(sum(Profile))
     122    error('Increase pulselength or decrease grating pitch')
     123end
     124%% Form factor
     125% form factor is calculated numericaly by FFT
     126SpectrumFFT=abs(fft(Profile)).^2;%Fourier transform
     127SpectrumHalf=SpectrumFFT(1:round(length(SpectrumFFT)/2));%only half of FT spectrum hold usefull information
     128Frequency=(0:(length(SpectrumFFT)-1))./(time(2)-time(1))/length(SpectrumFFT)*1e-3;%THz
     129FreqHalf=Frequency(1:round(length(Frequency)/2));%half of frequency range
     130SpectrumHalf=SpectrumHalf./max(SpectrumHalf);%normalization of Spectrum
     131Nmax=find(FreqHalf>=numax*1e-12,1);%xxx THz is more than enoght
     132% Interpolation is applyed to decrease error in calculation (freq step in FFT is to wide for this calculation )
     133FreqInter=FreqHalf(1):((FreqHalf(2)-FreqHalf(1))*1e-3):FreqHalf(Nmax);%interpolation diapason
     134SpecInter=pchip( FreqHalf(1:Nmax),SpectrumHalf(1:Nmax),FreqInter);%interpolation
     135if PlotFunc(1)==1
     136figure(1)
     137plot(FreqInter,SpecInter,'-k','linew',2)
     138hold on
     139grid on
     140set(gca,'fontsize',16)
     141ylabel('F(\nu)')
     142xlabel('\nu, [THz]')
     143legend('Form factor')
     144end
    109145%% Estimation grating factor R^2, coherent & incoherent integrals
    110146%%
     
    213249end%of phi
    214250end%of theta
    215 %% Form factor
    216 % form factor is calculated numericaly by FFT
    217 SpectrumFFT=abs(fft(Profile)).^2;%Fourier transform
    218 SpectrumHalf=SpectrumFFT(1:round(length(SpectrumFFT)/2));%only half of FT spectrum hold usefull information
    219 Frequency=(0:(length(SpectrumFFT)-1))./(time(2)-time(1))/length(SpectrumFFT)*1e-3;%THz
    220 FreqHalf=Frequency(1:round(length(Frequency)/2));%half of frequency range
    221 SpectrumHalf=SpectrumHalf./max(SpectrumHalf);%normalization of Spectrum
    222 Nmax=find(FreqHalf>=2.5,1);%2.5 THz is more than enoght
    223 % Interpolation is applyed to decrease error in calculation (freq step in FFT is to wide for this calculation )
    224 FreqInter=FreqHalf(1):((FreqHalf(2)-FreqHalf(1))*1e-3):FreqHalf(Nmax);%interpolation diapason
    225 SpecInter=pchip( FreqHalf(1:Nmax),SpectrumHalf(1:Nmax),FreqInter);%interpolation
    226 if PlotFunc(1)==1
    227 figure(1)
    228 plot(FreqInter,SpecInter,'-k','linew',2)
    229 hold on
    230 grid on
    231 set(gca,'fontsize',16)
    232 ylabel('F(\nu)')
    233 xlabel('\nu, [THz]')
    234 legend('Form factor')
    235 end
     251
    236252 %% I_N calculation
    237253f1=2*pi*qe*qe*1e-7;                                           % in Joules
Note: See TracChangeset for help on using the changeset viewer.