source: MML/trunk/mml/doc_html/mml/findrf1.html @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 16.1 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2                "http://www.w3.org/TR/REC-html40/loose.dtd">
3<html>
4<head>
5  <title>Description of findrf1</title>
6  <meta name="keywords" content="findrf1">
7  <meta name="description" content="FINDRF1 - Finds the RF frequency that minimizes the horizonal dispersion">
8  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
9  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
10  <meta name="robots" content="index, follow">
11  <link type="text/css" rel="stylesheet" href="../m2html.css">
12</head>
13<body>
14<a name="_top"></a>
15<div><a href="../index.html">Home</a> &gt;  <a href="index.html">mml</a> &gt; findrf1.m</div>
16
17<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
18<td align="right"><a href="index.html">Index for mml&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->
19
20<h1>findrf1
21</h1>
22
23<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
24<div class="box"><strong>FINDRF1 - Finds the RF frequency that minimizes the horizonal dispersion</strong></div>
25
26<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
27<div class="box"><strong>function [DeltaRF, RFnew, frf] = findrf1(DeltaRF, BPMFamily, BPMList, FileName) </strong></div>
28
29<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
30<div class="fragment"><pre class="comment">FINDRF1 - Finds the RF frequency that minimizes the horizonal dispersion
31  [DeltaRF, RFnew, frf] = findrf1(DeltaRFvec, BPMFamily, BPMList, FileName)
32
33  INPUTS
34  1. DeltaRFvec - Vector of RF changes {Default or empty: [-.2% -.1% 0% .1% .2%] energy change}
35  2. BPMFamily - Family name {Default or empty: 'BPMx'}
36  3. BPMList - Device or element list of BPMs  {Default or empty: all}
37  4. FileName to save data (data in structure 'frf') {Default or empty: don't save data}
38
39  OUTPUTS
40  1. DeltaRF - Change in RF
41  2. RFnew - Zero crossing of the fit
42  3. frf - RF structure containing all the measurement data
43
44  NOTES
45  1. The RF frequency that minimized the dispersion maybe not be the
46     optimal RF frequency.  The ALS found that choosing an RF frequency which
47     minimizes the energy shift due to the horizontal corrector magnets
48     to be a more robust and repeatable solution.
49  2. This function measures the dispersion, hence changes the RF frequency!
50     rmdisp will basically do the same thing as findrf1 without changing the
51     RF frequency.  However, findrf1 gives more control over the fit range for
52     the RF change and allows for more noise reduction in the fit.  That said,
53     rmdisp is usually just fine to use.
54  3. Beware of the magnitude of DeltaRFvec for nonlinear accelerators.
55
56  See also <a href="findrf.html" class="code" title="function [DeltaRF, HCMEnergyChangeTotal, DeltaL] = findrf(varargin)">findrf</a> <a href="rmdisp.html" class="code" title="function [DeltaRF, BPM, c, DispOrbit] = rmdisp(varargin)">rmdisp</a> <a href="plotcm.html" class="code" title="function [DeltaRF, HCMEnergyChangeTotal, DeltaL] = plotcm(varargin)">plotcm</a>
57
58  Written by Greg Portmann</pre></div>
59
60<!-- crossreference -->
61<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
62This function calls:
63<ul style="list-style-image:url(../matlabicon.gif)">
64<li><a href="family2dev.html" class="code" title="function DeviceList = family2dev(Family, varargin);">family2dev</a>   FAMILY2DEV - Return the device list for a family</li><li><a href="getam.html" class="code" title="function [AM, tout, DataTime, ErrorFlag] = getam(varargin)">getam</a> GETAM - Gets monitor channels</li><li><a href="getfamilydata.html" class="code" title="function [Data, ErrorFlag] = getfamilydata(Family, Field1, Field2, DeviceList)">getfamilydata</a>        GETFAMILYDATA - Gets data associated with the accelerator control</li><li><a href="getgolden.html" class="code" title="function Data = getgolden(varargin)">getgolden</a>       GETGOLDEN - Returns the golden values for a family</li><li><a href="getmcf.html" class="code" title="function Alpha = getmcf(ModelString)">getmcf</a>   GETMCF - Returns the momentum compaction factor (MCF) stored in the AD or the model</li><li><a href="getoffset.html" class="code" title="function Data = getoffset(varargin)">getoffset</a>     GETOFFSET - Returns the offset values for a family</li><li><a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a>     GETRF - Gets the RF frequency</li><li><a href="measdisp.html" class="code" title="function [Dx, Dy, FileName] = measdisp(varargin);">measdisp</a>       MEASDISP - Measures the dispersion function</li><li><a href="setrf.html" class="code" title="function setrf(RF, varargin)">setrf</a>    SETRF - Sets the RF frequency</li><li><a href="steprf.html" class="code" title="function steprf(varargin)">steprf</a>   STEPRF - Increment change in the RF frequency</li></ul>
65This function is called by:
66<ul style="list-style-image:url(../matlabicon.gif)">
67</ul>
68<!-- crossreference -->
69
70
71<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
72<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [DeltaRF, RFnew, frf] = findrf1(DeltaRF, BPMFamily, BPMList, FileName)</a>
730002 <span class="comment">%FINDRF1 - Finds the RF frequency that minimizes the horizonal dispersion</span>
740003 <span class="comment">%  [DeltaRF, RFnew, frf] = findrf1(DeltaRFvec, BPMFamily, BPMList, FileName)</span>
750004 <span class="comment">%</span>
760005 <span class="comment">%  INPUTS</span>
770006 <span class="comment">%  1. DeltaRFvec - Vector of RF changes {Default or empty: [-.2% -.1% 0% .1% .2%] energy change}</span>
780007 <span class="comment">%  2. BPMFamily - Family name {Default or empty: 'BPMx'}</span>
790008 <span class="comment">%  3. BPMList - Device or element list of BPMs  {Default or empty: all}</span>
800009 <span class="comment">%  4. FileName to save data (data in structure 'frf') {Default or empty: don't save data}</span>
810010 <span class="comment">%</span>
820011 <span class="comment">%  OUTPUTS</span>
830012 <span class="comment">%  1. DeltaRF - Change in RF</span>
840013 <span class="comment">%  2. RFnew - Zero crossing of the fit</span>
850014 <span class="comment">%  3. frf - RF structure containing all the measurement data</span>
860015 <span class="comment">%</span>
870016 <span class="comment">%  NOTES</span>
880017 <span class="comment">%  1. The RF frequency that minimized the dispersion maybe not be the</span>
890018 <span class="comment">%     optimal RF frequency.  The ALS found that choosing an RF frequency which</span>
900019 <span class="comment">%     minimizes the energy shift due to the horizontal corrector magnets</span>
910020 <span class="comment">%     to be a more robust and repeatable solution.</span>
920021 <span class="comment">%  2. This function measures the dispersion, hence changes the RF frequency!</span>
930022 <span class="comment">%     rmdisp will basically do the same thing as findrf1 without changing the</span>
940023 <span class="comment">%     RF frequency.  However, findrf1 gives more control over the fit range for</span>
950024 <span class="comment">%     the RF change and allows for more noise reduction in the fit.  That said,</span>
960025 <span class="comment">%     rmdisp is usually just fine to use.</span>
970026 <span class="comment">%  3. Beware of the magnitude of DeltaRFvec for nonlinear accelerators.</span>
980027 <span class="comment">%</span>
990028 <span class="comment">%  See also findrf rmdisp plotcm</span>
1000029 <span class="comment">%</span>
1010030 <span class="comment">%  Written by Greg Portmann</span>
1020031
1030032
1040033 ChangeRFFlag = 1;
1050034 DisplayFlag = 1;
1060035
1070036
1080037 <span class="comment">% Starting Point</span>
1090038 RF0 = <a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a>(<span class="string">'Struct'</span>);
1100039
1110040
1120041 <span class="keyword">if</span> nargin &lt; 1
1130042     DeltaRF = [];
1140043 <span class="keyword">end</span>
1150044 <span class="keyword">if</span> isempty(DeltaRF)
1160045     <span class="comment">%DeltaRF = getfamilydata('DeltaRFChro');</span>
1170046     <span class="keyword">if</span> isempty(DeltaRF)
1180047         DeltaRF = <a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a> * <a href="getmcf.html" class="code" title="function Alpha = getmcf(ModelString)">getmcf</a> * [-.002 -.001 0 .001 .002];  <span class="comment">% .2% energy change</span>
1190048         <span class="comment">%DeltaRF = getrf * getmcf * [-.006 -.003 0 .003 .006];  % .6% energy change</span>
1200049         <span class="comment">%DeltaRF = [-400 -200 0 200 400];  % Hz</span>
1210050         <span class="comment">%if strcmpi(RF0.UnitsString, 'Hz')</span>
1220051         <span class="comment">%elseif strcmpi(RF0.UnitsString, 'MHz')</span>
1230052         <span class="comment">%    DeltaRF = DeltaRF * 1e-6;  % MHz</span>
1240053         <span class="comment">%else</span>
1250054         <span class="comment">%    error('RF units unknown, hence default input frequency cannot be choosen.');</span>
1260055         <span class="comment">%end</span>
1270056     <span class="keyword">end</span>
1280057 <span class="keyword">end</span>
1290058 <span class="keyword">if</span> nargin &lt; 2
1300059     BPMFamily = <span class="string">''</span>;
1310060 <span class="keyword">end</span>
1320061 <span class="keyword">if</span> isempty(BPMFamily)
1330062     BPMFamily = <span class="string">'BPMx'</span>;
1340063 <span class="keyword">end</span>
1350064 <span class="keyword">if</span> nargin &lt; 3
1360065     BPMList = <a href="family2dev.html" class="code" title="function DeviceList = family2dev(Family, varargin);">family2dev</a>(BPMFamily);
1370066 <span class="keyword">end</span>
1380067 <span class="keyword">if</span> isempty(BPMList)
1390068     BPMList = <a href="family2dev.html" class="code" title="function DeviceList = family2dev(Family, varargin);">family2dev</a>(BPMFamily);
1400069 <span class="keyword">end</span>
1410070 <span class="keyword">if</span> nargin &lt; 4
1420071     FileName = [];
1430072 <span class="keyword">end</span>
1440073
1450074
1460075 BPMDelay = <a href="getfamilydata.html" class="code" title="function [Data, ErrorFlag] = getfamilydata(Family, Field1, Field2, DeviceList)">getfamilydata</a>(<span class="string">'BPMDelay'</span>);
1470076 <span class="keyword">if</span> isempty(BPMDelay)
1480077     BPMDelay = 0;
1490078 <span class="keyword">end</span>
1500079
1510080
1520081 Xoffset = <a href="getoffset.html" class="code" title="function Data = getoffset(varargin)">getoffset</a>(BPMFamily, BPMList);
1530082 Xgolden = <a href="getgolden.html" class="code" title="function Data = getgolden(varargin)">getgolden</a>(BPMFamily, BPMList);
1540083
1550084
1560085 <span class="comment">% Get Dispersion</span>
1570086 Dx = <a href="measdisp.html" class="code" title="function [Dx, Dy, FileName] = measdisp(varargin);">measdisp</a>([], BPMFamily, BPMList);
1580087
1590088
1600089 <span class="keyword">for</span> i = 1:length(DeltaRF)
1610090     fprintf(<span class="string">'   %d. Setting RF to %f [%s] \n'</span>, i, RF0.Data + DeltaRF(i), RF0.UnitsString);
1620091     <a href="setrf.html" class="code" title="function setrf(RF, varargin)">setrf</a>(RF0.Data + DeltaRF(i));
1630092     sleep(BPMDelay);
1640093     x(:,i) = <a href="getam.html" class="code" title="function [AM, tout, DataTime, ErrorFlag] = getam(varargin)">getam</a>(BPMFamily, BPMList) - Xoffset;
1650094     rf(1,i) = <a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a>;
1660095 <span class="keyword">end</span>
1670096
1680097
1690098 <span class="comment">% Set RF back to starting point</span>
1700099 <a href="setrf.html" class="code" title="function setrf(RF, varargin)">setrf</a>(RF0);
1710100
1720101
1730102 <span class="comment">% Find LS fit to the line</span>
1740103 y = x' * Dx;           <span class="comment">% Dot product of Dx and the X orbit</span>
1750104 X = [ones(max(size(rf)),1) rf'];
1760105 <span class="comment">%b = inv(X'*X)*X'*y;</span>
1770106 b = X \ y;
1780107 RFnew = -b(1) / b(2);
1790108
1800109
1810110 rf1 = linspace(rf(1),rf(max(size(rf))),100);
1820111 yfit = b(1) + b(2)*rf1;
1830112
1840113 DeltaRF = RFnew - RF0.Data;
1850114
1860115
1870116 <span class="comment">%figure</span>
1880117 clf reset
1890118 plot(rf1,yfit, <span class="string">'b'</span>, rf,y,<span class="string">'og'</span>, RFnew,0,<span class="string">'xr'</span>);
1900119 grid on
1910120 xlabel(<span class="string">'RF Frequency [MHz]'</span>);
1920121 ylabel(<span class="string">'Dot product of Dx and Hor. Orbit'</span>);
1930122 title(sprintf(<span class="string">'FIT: %g + %g * RF,  \\DeltaRF = %g'</span>, b(1), b(2), DeltaRF));
1940123
1950124
1960125
1970126 <span class="comment">% Set the RF frequency</span>
1980127 <span class="keyword">if</span> ChangeRFFlag
1990128     <span class="comment">% fprintf('\n               Starting RF = %f [%s]\n', RF0.Data, RF0.UnitsString);</span>
2000129     <span class="comment">% fprintf('   Zero crossing of the RF = %f  Delta RF = %g [%s]\n', RFnew, DeltaRF, RF0.UnitsString);</span>
2010130     <span class="comment">% answer = input('   Do you want to set the RF frequence now (n/y)? ','s');</span>
2020131     <span class="comment">% if strcmp(answer, 'y') == 1</span>
2030132     <span class="comment">%     setrf(RFnew);</span>
2040133     <span class="comment">%     fprintf('   New RF frequency = %f [%s]\n', getrf, RF0.UnitsString);</span>
2050134     <span class="comment">%     fprintf('   Measurement complete.\n');</span>
2060135     <span class="comment">% else</span>
2070136     <span class="comment">%     fprintf('   Measurement complete.  No change to the RF frequency.\n');</span>
2080137     <span class="comment">% end</span>
2090138     <span class="keyword">if</span> ~isempty(DeltaRF)
2100139         <span class="keyword">if</span> DisplayFlag
2110140             answer = inputdlg({strvcat(strvcat(strvcat(sprintf(<span class="string">'Recommend new RF Freqenecy is %g %s'</span>, RFnew, RF0.UnitsString), sprintf(<span class="string">'Delta RF is %g %s'</span>, DeltaRF, RF0.UnitsString)), <span class="string">'  '</span>),<span class="string">'Change the RF frequency?'</span>)},<span class="string">'FINDFR1'</span>,1,{sprintf(<span class="string">'%g'</span>,DeltaRF)});
2120141             <span class="keyword">if</span> isempty(answer)
2130142                 fprintf(<span class="string">'   No change was made to the RF frequency.\n'</span>);
2140143                 <span class="keyword">return</span>
2150144             <span class="keyword">end</span>
2160145             DeltaRF = str2num(answer{1});
2170146         <span class="keyword">end</span>
2180147         <a href="steprf.html" class="code" title="function steprf(varargin)">steprf</a>(DeltaRF);
2190148         <span class="keyword">if</span> DisplayFlag
2200149             fprintf(<span class="string">'   RF frequency change by %f %s.\n'</span>, DeltaRF, RFUnitsString);
2210150         <span class="keyword">end</span>
2220151     <span class="keyword">else</span>
2230152         error(<span class="string">'RF frequency not changed because of a calculation problem.'</span>);
2240153     <span class="keyword">end</span>
2250154 <span class="keyword">end</span>
2260155
2270156
2280157 <span class="keyword">if</span> ~isempty(FileName)         <span class="comment">%save file</span>
2290158     frf.TimeStamp = clock;
2300159     frf.CreatedBy = <span class="string">'findrf'</span>;
2310160     frf.FileName  = FileName;
2320161     frf.x         = x;
2330162     frf.rf        = rf;
2340163     frf.Dx        = Dx;
2350164     frf.RF0       = RF0;
2360165     frf.RFnew     = RFnew;
2370166     frf.DeltaRF   = DeltaRF;
2380167     frf.BPMFamily = BPMFamily;
2390168     frf.BPMList   = BPMList;
2400169     frf.Xgolden   = Xgolden;
2410170     frf.Xoffset   = Xoffset;
2420171     save(FileName, <span class="string">'frf'</span>);
2430172     fprintf(<span class="string">'   Data saved to %s.mat in directory %s.\n'</span>, FileName, pwd);
2440173 <span class="keyword">end</span>
2450174
2460175
2470176</pre></div>
248<hr><address>Generated on Mon 21-May-2007 15:29:18 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
249</body>
250</html>
Note: See TracBrowser for help on using the repository browser.