Home > pubtools > LatticeTuningFunctions > correction > RFcavity > atsetRFCavityErr.m

atsetRFCavityErr

PURPOSE ^

ATSETRFCAVITY sets the RF Cavity with the passmethod RFCavityPass.

SYNOPSIS ^

function [newring, inCOD]= atsetRFCavityErr( ring, rfv, radflag, HarmNumber, inCOD, DeltaFreq )

DESCRIPTION ^

  ATSETRFCAVITY sets the RF Cavity with the passmethod RFCavityPass.
  RFCavityPass allows to change the energy of the beam changing the
  frequency of the cavity.

   newring = atSetRFCavity(ring, rfv, radflag, HarmNumber, DeltaFreq)
   sets the synchronous phase of the cavity, the voltage, the harmonic
   number and the PassMethod. All the N cavities will have a voltage rfv/N
   radflag says whether or not we want radiation on, which affects
   synchronous phase. If radflag is 0, the function calls atradoff, if it
   is 1, it calls atradon.
   Cavities in the ring must have the Class RFCavity.
   Normally DeltaFreq should be 0, it's different from 0 when you want to
   simulate a change of energy changing the RF frequency. DeltaFreq is in
   Hz.

   normal use:
   newring = atsetRFCavity( ring, 6e6, 1, 992, 0 )
   for off-energy simulations:
   newring = atsetRFCavity( ring, 6e6, 1, 992, 100 )

   modified : defaulted DeltaFreq
              removed U0 set timelag to 6th coordinate of findorbit6


   see also: atsetcavity

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [newring, inCOD]= atsetRFCavityErr( ring, rfv, radflag, HarmNumber, inCOD, DeltaFreq )
0002 %  ATSETRFCAVITY sets the RF Cavity with the passmethod RFCavityPass.
0003 %  RFCavityPass allows to change the energy of the beam changing the
0004 %  frequency of the cavity.
0005 %
0006 %   newring = atSetRFCavity(ring, rfv, radflag, HarmNumber, DeltaFreq)
0007 %   sets the synchronous phase of the cavity, the voltage, the harmonic
0008 %   number and the PassMethod. All the N cavities will have a voltage rfv/N
0009 %   radflag says whether or not we want radiation on, which affects
0010 %   synchronous phase. If radflag is 0, the function calls atradoff, if it
0011 %   is 1, it calls atradon.
0012 %   Cavities in the ring must have the Class RFCavity.
0013 %   Normally DeltaFreq should be 0, it's different from 0 when you want to
0014 %   simulate a change of energy changing the RF frequency. DeltaFreq is in
0015 %   Hz.
0016 %
0017 %   normal use:
0018 %   newring = atsetRFCavity( ring, 6e6, 1, 992, 0 )
0019 %   for off-energy simulations:
0020 %   newring = atsetRFCavity( ring, 6e6, 1, 992, 100 )
0021 %
0022 %   modified : defaulted DeltaFreq
0023 %              removed U0 set timelag to 6th coordinate of findorbit6
0024 %
0025 %
0026 %   see also: atsetcavity
0027 
0028 clight=299792458 ;
0029 
0030 newring = ring;
0031 indrfc=findcells(ring,'Class','RFCavity');
0032 
0033 beta0=1;
0034 
0035 % circumference + trajectory length modification introduced by orbit in
0036 % dipoles
0037 
0038 % DLL=LatticeLengtheningCODDipole(ring,inCOD);
0039 DLL=0;
0040 circumference=findspos(ring,length(ring)+1)*(1+DLL);
0041 
0042 newring=setcellstruct(newring,'PassMethod',indrfc,'RFCavityPass');
0043 
0044 freq0=(clight*beta0/circumference)*HarmNumber;
0045 
0046 %now set intial guess for cavity frequencies,
0047 % set Harmonic Number and RF Voltage
0048 for j=indrfc
0049     newring{j}.Frequency=freq0;
0050     newring{j}.HarmNumber=HarmNumber;
0051     newring{j}.Voltage=rfv/length(indrfc);
0052 end
0053 
0054 % set radiation pass methods ('auto' sets radiation on also in quadrupoles)
0055 if radflag
0056     newring=atradon(newring,'RFCavityPass','auto','auto');
0057 else
0058     newring=atradoff(newring,'RFCavityPass','auto','auto');
0059 end
0060 
0061 % default DeltaFreq to cancel energy deviation after one turn
0062 if nargin<6
0063     disp('DeltaFreq not provided. Setting DeltaFreq to cancel energy variation after one turn');
0064     
0065     for i=1:5
0066         freq=atgetfieldvalues(newring,indrfc,'Frequency');
0067         tlag=atgetfieldvalues(newring,indrfc,'TimeLag');
0068         
0069         %alpha=mcfErr(newring,indrfc,inCOD,DLL);
0070         alpha=mcf(newring);
0071         orb = findorbit6(newring,indrfc,inCOD);
0072         if ~isnan(orb(1))
0073             df = alpha*orb(5,:)'.*freq;
0074         else
0075             df=zeros(size(freq));
0076             warning('findorbit6 failed.')
0077         end
0078         
0079         newring=atsetfieldvalues(newring,indrfc,'Frequency',freq+df);
0080         
0081         orb = findorbit6(newring,indrfc,inCOD);
0082         newring=atsetfieldvalues(newring,indrfc,'TimeLag',tlag-orb(6,:)');
0083     
0084         
0085     end
0086     
0087     freqct=atgetfieldvalues(newring(indrfc),'Frequency');
0088     DeltaFreq=freqct(1)-freq0;
0089     
0090     
0091     disp(['DeltaFreq: ' num2str(DeltaFreq) ' Hz']);
0092     
0093 end
0094 
0095 freq=freq0+DeltaFreq;
0096 
0097 % set frequency
0098 newring(indrfc)=atsetfieldvalues(newring(indrfc),'Frequency',freq);
0099 
0100 % set timelag
0101 orb = findorbit6(newring,indrfc,inCOD);
0102 tlag=atgetfieldvalues(newring,indrfc,'TimeLag');
0103 ntlag=tlag-orb(6,:)';
0104 
0105 newring(indrfc)=atsetfieldvalues(newring(indrfc),'TimeLag',ntlag);
0106 
0107 inCOD = findorbit6(newring,1,inCOD);
0108 
0109 if nargin<7
0110     verbose=false;
0111 end
0112 
0113 if verbose
0114     disp(['DLL: ' num2str(circumference*DLL) ' m']);
0115     disp(['Delta RF frequency: ' num2str(DeltaFreq) ' Hz']);
0116     disp(['Time Lag: ' num2str(ntlag) ' m']);
0117 end
0118 
0119 end

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005