PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/utils/get_DR_corrs.m

http://slac-lucretia.googlecode.com/
MATLAB | 165 lines | 69 code | 23 blank | 73 comment | 15 complexity | ff6f5100e9c28ed7dec61509b5a03623 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. function varargout=get_DR_corrs(opCode,energy,varargin)
  2. %
  3. % KL=get_DR_corrs(1,energy,Icorr,fflag);
  4. %
  5. % Compute DR corrector kicks (KL=BL/brho) from currents
  6. %
  7. % Icorr=get_DR_corrs(2,energy,KL,fflag);
  8. %
  9. % Compute DR corrector currents (KL=BL/brho) from kicks
  10. %
  11. % INPUTs (opCode=1):
  12. %
  13. % opCode = 1 (I to KL conversion)
  14. % energy = DR energy (GeV) [scalar]
  15. % Icorr = DR corrector currents (amps) [101 element array]
  16. % fflag = (optional) if present and nonzero, fudge factors will be used
  17. %
  18. % INPUTs (opCode=2):
  19. %
  20. % opCode = 2 (KL to I conversion)
  21. % energy = DR energy (GeV) [scalar]
  22. % KL = corrector kicks (radians) [101 element array]
  23. % fflag = (optional) if present and nonzero, fudge factors will be used
  24. %
  25. % The order of correctorss in the Icorr or KL arrays must be:
  26. %
  27. % ZH1R,...,ZH14R,ZH16R,...,ZH48R (ZH15R is missing)
  28. % ZV1R,...,ZV15R,ZV17R,...,ZV51R (ZV16R is missing)
  29. % ZH100R,ZH101R,ZH102R,ZV100R (specials)
  30. %
  31. % OUTPUT (opCode=1):
  32. %
  33. % KL = DR corrector kicks (radians; same signs as Icorr)
  34. % [101 element array, same order as Icorr]
  35. %
  36. % OUTPUT (opCode=2):
  37. %
  38. % Icorr = DR corrector currents (amps; same signs as KL)
  39. % [101 element array, same order as KL]
  40. % ==============================================================================
  41. % 22-FEB-2009, M. Woodley
  42. % Do either I-to-KL and KL-to-I conversion
  43. % ==============================================================================
  44. Ncorr=101;
  45. % check input args
  46. if (~exist('opCode','var'))
  47. error('opCode argument not supplied')
  48. end
  49. if (~exist('energy','var'))
  50. error('energy argument not supplied')
  51. else
  52. if (energy<=0)
  53. error('Bad energy value')
  54. end
  55. end
  56. if (opCode==1)
  57. if (nargin<3)
  58. error('At least 3 input arguments required for opCode=1')
  59. end
  60. Icorr=varargin{1};
  61. if (length(Icorr)~=Ncorr)
  62. error('Incorrect Icorr length')
  63. end
  64. elseif (opCode==2)
  65. if (nargin<3)
  66. error('At least 3 input arguments required for opCode=2')
  67. end
  68. KL=varargin{1};
  69. if (length(KL)~=Ncorr)
  70. error('Incorrect KL length')
  71. end
  72. else
  73. error('Invalid opCode')
  74. end
  75. if (nargin>3)
  76. fflag=varargin{2};
  77. else
  78. fflag=0;
  79. end
  80. fudge=(fflag~=0);
  81. % ==============================================================================
  82. % DR CORRECTOR MAGNET DATA
  83. % ==============================================================================
  84. % there are 6 types of DR corrector:
  85. % 1 = NKK type CH (horizontal)
  86. % 2 = Tecno model 58283 (horizontal)
  87. % 3 = NKK type CV (vertical)
  88. % 4 = Tecno model 58928 (vertical)
  89. % 5 = Tecno model 58284 (vertical)
  90. % 6 = Tecno model 82982 (horizontal)
  91. % 7 = Tecno model 82983 (horizontal)
  92. % 8 = ZV100R (vertical; modified)
  93. % B vs I slopes and effective lengths
  94. % (from: ATF$MAG:MAG_KI_Z_NKK_CH.FOR
  95. % ATF$MAG:MAG_KI_Z_TECNO_H58283.FOR
  96. % ATF$MAG:MAG_KI_Z_NKK_CV.FOR
  97. % ATF$MAG:MAG_KI_Z_TECNO_V58928.FOR
  98. % ATF$MAG:MAG_KI_Z_TECNO_V58284.FOR
  99. % ATF$MAG:MAG_KI_Z_TECNO_ZH82982.FOR
  100. % ATF$MAG:MAG_KI_Z_TECNO_ZH82983.FOR
  101. % ATF$MAG:MAG_KI_ZV100R.FOR)
  102. cbvi=[108.0e-4;102.8e-4;112.0e-4;111.5e-4;102.0e-4;12.5e-3;5.9e-3;8.5e-3]; % T/amp
  103. cleff=[0.11921;0.11455;0.1248;0.128141;0.172;0.24955;0.1679;0.13874]; % m
  104. % corrector types
  105. % (from: ATF$MAG:MAG_KI_MAIN.FOR)
  106. ctype=[ ...
  107. 1;1;1;1;1;1;1;1;1;2;2;2;2;2; 1;1;1;1;1;1;1;1;1;1; ... %ZH1-25
  108. 1;1;1;1;1;1;1;1;2;2;2;2;2;2;1;1;1;1;1;1;1;1;1; ... %ZH26-48
  109. 3;3;3;3;3;3;3;3;3;4;4;4;4;4;5; 3;3;3;3;3;3;3;3;3; ... %ZV1-25
  110. 3;3;3;3;3;3;3;3;5;5;5;4;4;4;4;4;5;3;3;3;3;3;3;3;3; ... %ZV26-50
  111. 3; ... %ZV51
  112. 6;7;3;8]; %ZH100-102,ZV100
  113. % "Kubo" fudge factors
  114. % (none available)
  115. cfudge=zeros(Ncorr,1);
  116. % ==============================================================================
  117. % compute rigidity
  118. Cb=1e10/2.99792458e8; % kG-m/GeV
  119. brho=Cb*energy;
  120. % perform requested conversion
  121. if (opCode==1)
  122. % convert current to KL
  123. KL=zeros(Ncorr,1);
  124. for n=1:Ncorr
  125. t=ctype(n);
  126. B=Icorr(n)*cbvi(t); % T
  127. KL(n)=(10*B)*cleff(t)/brho; % radian
  128. if (fudge),KL(n)=KL(n)/(1+cfudge(t));end
  129. end
  130. varargout{1}=KL;
  131. else
  132. % convert current to KL
  133. Icorr=zeros(Ncorr,1);
  134. for n=1:Ncorr
  135. t=ctype(n);
  136. B=0.1*brho*KL(n)/cleff(t); % T
  137. if (fudge),B=B*(1+cfudge(t));end
  138. Icorr(n)=B/cbvi(t); % amps
  139. end
  140. varargout{1}=Icorr;
  141. end
  142. end