TALK
0001 %TALK 0002 0003 % keeping notes and comments in lattice files 0004 help spear2 0005 help spear2rad 0006 help sp3v81loco 0007 0008 % STUDY 1: load a file 0009 spear2 0010 whos 0011 0012 THERING{1:10} 0013 FAMLIST{1:10} 0014 0015 % Read MAD output 0016 clear all 0017 THERING = readmad('spear3_mad_structure.out'); 0018 0019 0020 0021 % STUDY 2 0022 % LATTICE MANIPULATION 0023 % start over by clearing the workspace and loading spear2 0024 clear all 0025 spear2; 0026 0027 % You may access/modify parameters of individual elements 0028 % in several ways 0029 % 1. Text mode is very useful to write your own scripts: 0030 % for example 0031 THERING{3} % notice curly {} braces for cell access 0032 % displays the data from the first Q3 quadrupole 0033 % THERING{i} is actually a MATLAB structure so you can 0034 % access individual fields using "." 0035 THERING{3}.R1 0036 % displays only the 6x6 entrance tilt matrix R1 for the same quadrupole 0037 % You may even access individual elements in that matrix 0038 THERING{3}.R1(1,1) 0039 % Try 0040 getfield(THERING{3},'PassMethod') % WATCH OUT - you will get 0041 % MATLAB warnings if the field does not exist for that element 0042 % or if you misspell it. MATLAB is case sensitive 0043 0044 % SEE ALSO MATLAB help on SETFIELD, GETFIELD, FIELDNAMES funtions 0045 % useful for structure access / manipulation 0046 fieldnames(THERING{3}) 0047 % returns the list of fields in for THERING{3} 0048 % In fact this list is common for all Q3 0049 0050 0051 0052 % GUI Lattice manipulation 0053 0054 clear all 0055 spear2 0056 % Draw the ring - select and edit elements 0057 intlat 0058 0059 % GUI editor of an elemet 0060 intelem(3) 0061 0062 % GUI (slider) control of a 'K' parameter in 0063 % all QF and QD simultaneously 0064 demoknob 0065 0066 0067 % STUDY3: TRACKING 0068 spear2 0069 % Use RINGPASS for tracking 0070 help ringpass 0071 % Input vectors must be Nx6 matrixes 0072 X0 = [0.01 0 0 0 0 0]' 0073 % Track 1 particle - 1 turn 0074 X = ringpass(THERING,X0); 0075 0076 % Track 1 particle - 10 turns 0077 X = ringpass(THERING,X0,10) 0078 0079 % Track 3 particles - 10 turns 0080 X0 = [X0 X0 X0] 0081 X = ringpass(THERING,X0,10) 0082 0083 0084 0085 % Using results of tracking for accelearator physics calculations in MATLAB 0086 X0 = [0.001 0 0 0 0 0]'; 0087 % Track 1 particle - 200 turns 0088 clear X 0089 X = ringpass(THERING,X0,200); 0090 plot(X(1,:),'.') 0091 xlabel('Turn Number'); 0092 ylabel('X [mm]'); 0093 figure 0094 plot(X(1,:),X(2,:),'.') 0095 title('Phase Space'); 0096 figure 0097 xspectrum = abs(fft(X(1,:))); 0098 plot(xspectrum) 0099 title('FFT'); 0100 0101 0102 % Plot phase-space near 1/3 integer resonance 0103 clear all; close all 0104 spear2 0105 fittune2([0.345 0.26],'QF','QD'); 0106 X0 = [0.001 0 0 0 0 0]'*(1:15); 0107 % Track 15 particles - 200 turns 0108 clear X 0109 X = ringpass(THERING,X0,200); 0110 figure 0111 plot(X(1,:),X(2,:),'.') 0112 title('Phase Space'); 0113 0114 0115 0116 % Low-level element pass method 0117 X0 = [0.001 0 0 0 0 0]'; 0118 X1 = QuadLinearPass(THERING{5},X0) 0119 X2 = DriftPass(THERING{6},X1) 0120 0121 0122 0123 % Many physics routines call RINGPASS, LINEPASS 0124 % or one of the element-level mex-functions 0125 0126 0127 % Example 1: CLOSED ORBIT CALCULATION 0128 clear all 0129 spear2 0130 0131 plotcod(THERING,0) 0132 % use intlat to set ByError in one of the bends 0133 0134 plotcod(THERING,0) 0135 % Behold horizontally distorted orbit 0136 0137 clear all 0138 clf 0139 spear2 0140 plotcod(THERING,0) 0141 % use intlat to set T1,T2 in one of the quads 0142 % to T1 = [0.001 0 0.001 0 0 0]; T2= -T1; 0143 plotcod(THERING,0) 0144 % Behold orbit distortion in both planes 0145 0146 0147 % Example 2: Make a script to calculate 0148 % Momentum Compaction Factor 0149 0150 % Lets calculate momentum compaction factor: 0151 % dL = alpha*L*dP/P 0152 0153 % Find off-energy fixed point 0154 dP = 0.001 0155 fp = findorbit(THERING,dP) 0156 format long 0157 0158 % Build initial condition vector that starts 0159 % on the fixed point 0160 X0 = fp; 0161 X0(5) = dP; 0162 X0(6) = 0; 0163 X0 0164 % Track X0 for 1 turn 0165 X1 = ringpass(THERING,X0) 0166 % Calculate momentum compaction factor 0167 alpha = X1(6)/(dP*234) 0168 0169 % EXAMPLE 3. Beta-functions and tunes 0170 clear all 0171 spear2 0172 plotbeta 0173 % Use demoknob to tweek quad values 0174 demoknob 0175 plotbeta 0176 0177