# Presentation: 177359

## BB-Diagnostics: Computer Class (Matlab/AT)

-  Monday: Intro to the Middle Layer and AT
-                   Orbit errors
-  Tuesday: Gradient errors, beta function, phase advance
-  Wednesday: Gradient errors, LOCO
-  Thursday: Detuning with amplitude, decoherence, resonances
-                     (Christoph Steier)
-  Friday: no computer class

**Greg Portmann, Christoph Steier, and James Safranek **

**Using Accelerator Tracking Code AT, **
**Middle Layer Software, and **
**Response Matrix Fitting**

- USPAS, Phoenix

- January 16-20, 2006

**Notes:**
The goal of the superbend project is to create sources of high brightness high energy x-ray beams using superconducting magnets. I will talk about the superbend accelerator physics issues. My talk is structured in the following way.
I will give a brief introduction to the superbend project where I will present the motivation for the superbends and compare the superbends  to other high energy x-ray sources. Next I will discuss the modifications to the ring and how that will change the beam  parameters and particularly how it will impact the  other users. I will discuss the possible operational concerns in particular the impact on injection, momentum acceptance and ramping. Finally I will conclude with some summary statements.

## Starting Matlab 

- % Start Matlab 6.5 (AT and LOCO require at least Matlab version 6.0)
- % Matlab 7.1 is the latest version.
- % Set the matlab path for AT, MiddleLayer, and LOCO
-      cd c:\bbdiag\acceleratorcontrol
-      setpathals
- %          or
- %     setpathspear3
- %     setpathxray
- %     setpathvuv
- % Change to the class examples directory
-      cd docs
- % Note: When in doubt, setpathals will also restore the default lattice.

- USPAS, Phoenix

- January 16-20, 2006

## Monday: AT Lattice Model & Orbits

- %  Plot lattice (AT):
- 	intlat
- %  Edit the AT lattice file:
- 	edit alslat
- %  Plot the orbit with plotfamily (Middle Layer):
- 	plotfamily
- 	% Menu: Graph #1 -> Add to plot -> Draw Lattice
- %  Switch synchrotron radiation and RF cavity on & off (Middle Layer):
- 	setcavity on;
- 	setradiation on;
- 	% Update plotfamily
- 	setcavity off;
- 	setradiation off;
- 	% Update plotfamily
- %  Change the first corrector magnet in sector 6 by 1 amp   (Middle Layer):
- 	setsp('HCM', 1, [6 1]) ;
- 	setsp('VCM', 1, [6 1]);
- 	% Update plotfamily

- USPAS, Phoenix

- January 16-20, 2006

## Monday: Closed Orbits

- %  Get the orbit, beta, and phase at all elements in the AT model (Middle Layer):
- 	[x, y, BPMs] = modeltwiss('ClosedOrbit');
- 	[BetaX, BetaY, BPMs] = modeltwiss('Beta');
- 	[MuX, MuY] = modeltwiss('Phase');
- %  Plot the orbit vs. s-position:
- 	figure;
- 	subplot(2,1,1);
- 	plot(BPMs, x);
- 	subplot(2,1,2);
- 	plot(BPMs, y);
- %  Plot the orbit vs. phase
- 	figure;
- 	subplot(2,1,1);
- 	plot(MuX, x);
- 	subplot(2,1,2);
- 	plot(MuY, y);
- %  Plot nomalized orbit vs. phase
- 	figure;
- 	subplot(2,1,1);
- 	plot(MuX, x ./ sqrt(BetaX));
- 	subplot(2,1,2);
- 	plot(MuY, y ./ sqrt(BetaY));

- USPAS, Phoenix

- January 16-20, 2006

## Monday: Closed Orbits

- % Try these commands
- modelbeta;
- modelbeta('BPMx');
- modelbeta('QF');
- modeldisp;
- modeldisp('BEND');
- [FractionalTune, IntegerTune] = modeltune
- %  Get closed orbit directly from AT:
- 	help findorbit4
- 	global THERING
- 	x = findorbit4(THERING, 0.0, 1:length(THERING));
-          s = findspos(THERING, 1:length(THERING));
- %  Plot the orbit vs. s-position:
- 	subplot(2,1,1);
- 	plot(s, x(1,:));
-        ylabel('x [meters]');
- 	subplot(2,1,2);
- 	plot(s, x(2,:));
-        ylabel('x-prime');
- %  Get closed orbit at BPMs (AT):
- 	BPMindex = findcells(THERING, 'FamName', 'BPM');
- 	BPM = findorbit4(THERING, 0.0, BPMindex);

- USPAS, Phoenix

- January 16-20, 2006

## Tuesday: Gradient Errors

- %  Plot the beta function and phase advance for the
- %  nominal model and a model with a gradient error
- %  Get beta & phase at all elements in the AT model (Middle Layer):
- 	Tune0 = gettune;
- 	[BetaX0, BetaY0, s] = modeltwiss('Beta');
- 	[MuX0, MuY0] = modeltwiss('Phase');
- %  Plot beta vs. position
- 	figure(1); clf;
- 	subplot(2,2,1); plot(MuX0, BetaX0, 'b'); ylabel('Beta X');
- 	subplot(2,2,3); plot(MuY0, BetaY0, 'b'); ylabel('Beta Y');
- 	subplot(2,2,2); plot(MuX0, MuX0/(2*pi) , 'b'); ylabel('Phase X');
- 	subplot(2,2,4); plot(MuY0, MuY0/(2*pi) , 'b'); ylabel('Phase Y');
- %  Perturb the lattice at 1 quadrupole, QF(7,1)
- 	qf = getsp('QF', [7 1]);
- 	setsp('QF', 1.05*qf, [7 1]);
- %  Get and plot beta for the perturbed lattice
- 	Tune1 = gettune;
- 	[x1, y1] = modeltwiss('ClosedOrbit');
- 	[BetaX1, BetaY1] = modeltwiss('Beta');
- 	[MuX1, MuY1] = modeltwiss('Phase');

- %  Add the perturbed beta to figure(1)
- 	figure(1);
- 	subplot(2,2,1); hold on;
- 	plot(MuX0, BetaX1, 'r');
- 	subplot(2,2,3); hold on;
- 	plot(MuY0, BetaY1, 'r');
- 	subplot(2,2,2); hold on;
- 	plot(MuX0, MuX1/(2*pi) , 'r');
- 	subplot(2,2,4); hold on;
- 	plot(MuY0, MuY1/(2*pi) , 'r');
- %  Plot beta beat
- 	figure(2);
- 	subplot(2,1,1);
- 	plot(s, BetaX1./BetaX0);
- 	title('Beta Beat from the Nominal Model');
- 	subplot(2,1,2);
- 	plot(s, BetaY1./BetaY0);
- %  Restore the lattice
- 	setsp('QF', qf, [7 1]);

- USPAS, Phoenix

- January 16-20, 2006

## Tuesday: Quadrupole Centers

- % Beam based measurement of quadrupole centers
- 	quadcenter
- %	 QF
- % 	 QF(7,1)
- %	 Vertical only
- %	Note: your data got put in c:\bbdiag\machine\alsdata\HighTune\QMS

- USPAS, Phoenix

- January 16-20, 2006

## Wednesday: FFT Analyze

- %  Simulate a phase advance measurement
- %  Get the orbit, beta, and phase at all elements in the AT model (Middle Layer):
- 	Tune0 = gettune;
- 	[BetaX0, BetaY0, s] = modeltwiss('Beta', 'BPMx');
- 	[MuX0, MuY0] = modeltwiss('Phase', 'BPMx');
- %  Starting condition or tracking (0.1mm)
- 	X0 = [0.0001; 0; 0.0001; 0; 0; 0];
- %  Track for 1024 turns
- 	global THERING
- 	X1 = ringpass(THERING, X0, 1024);
- 	size(X1)
- %  Track coordinates for every turn along the ring (to all BPMs)
- 	BPMindex = findcells(THERING, 'FamName', 'BPM');
- 	BPM = findorbit4(THERING, 0.0, BPMindex);
- 	X2 = linepass(THERING, X1, BPMindex);
- 	size(X2)
- %  Recover matrix structure (turns x BPM#):
- 	BPMx = reshape(X2(1,:), 1024, 122);
- 	size(BPMx)
- 	BPMy = reshape(X2(3,:), 1024, 122);
- %  Plot some results:
- 	figure(1);subplot(2,1,1); plot(BPMy(1,:)); subplot(2,1,2); plot(BPMy(:,1));

- USPAS, Phoenix

- January 16-20, 2006

## Wednesday: FFT Analyze

- %  Calculate fractional tunes (interpolating FFT, sine window)
- 	[nux, nuy, ax, ay] = findfreq(BPMx, BPMy)
- % Calculate phase at every BPM
- % (integral convolution with sine and cosine trajectories)
- [MuX, MuY] = calcphase(nux, nuy, BPMx, BPMy);
- %  Calcphase asks for a frequency, typically just accepting
- %   the precalculated result is fine.
- %  Compare the 'measured' phase advance with the computed nominal one.
- DeltaMuX = MuX(:)-MuX0/(2*pi);
- DeltaMuY = MuY(:)-MuY0/(2*pi);
- figure(2);
- subplot(2,1,1);
- plot(MuX0, DeltaMuX-DeltaMuX(1), '.-b') ;
- subplot(2,1,2);
- plot(MuY0, DeltaMuY-DeltaMuY(1), '.-b');

- USPAS, Phoenix

- January 16-20, 2006

## Wednesday: FFT Analyze

- % Add noise to the BPM data and recalculation the phase
- 	BPMxNoise = BPMx + 5e-6*randn(size(BPMx));
- 	BPMyNoise = BPMy + 5e-6*randn(size(BPMy));
- %  Calculate fractional tunes (interpolating FFT, sine window)
- 	[nux, nuy, ax, ay] = findfreq(BPMxNoise , BPMyNoise)
- % Calculate phase at every BPM
- % (integral convolution with sine and cosine trajectories)
- [MuXnoise, MuYnoise] = calcphase(nux, nuy, BPMxNoise, BPMyNoise)
- %  Calcphase asks for a frequency, typically just accepting
- %   the precalculated result is fine.
- %  Compare the 'measured' phase advance with the computed nominal one.
- DeltaMuX = MuXnoise(:)-MuX0/(2*pi);
- DeltaMuY = MuYnoise(:)-MuY0/(2*pi);
- figure(2);
- subplot(2,1,1); hold on;
- plot(MuX0, DeltaMuX-DeltaMuX(1), '.-r') ;
- subplot(2,1,2); hold on;
- plot(MuY0, DeltaMuY-DeltaMuY(1), '.-r');

- USPAS, Phoenix

- January 16-20, 2006

## Wednesday: LOCO Optics Analysis

- Calibrate/control optics using orbit response matrix
- Determine quadrupole gradients
- Correcte coupling
- Calibrate BPM gains, steering magnets
- Measure local chromaticity and transverse impedance

- New MATLAB version of code
-  rewritten from FORTRAN
-  linked to control system
-  linked to AT simulator

- USPAS, Phoenix

- January 16-20, 2006

**Notes:**
Integer tune
Coupling correction
Beta function / phase advanced correction

## Wednesday: LOCO - locogui

- %  Start the LOCO graphical user interface (GUI)
- %  Look at an ALS LOCO run
- 	locogui
- %	 open
- %	     c:\bbdiag\machine\alsdata\HighTune\LOCO\2005-10-16

- USPAS, Phoenix

- January 16-20, 2006

## Wednesday: LOCO – measure the input data

- % Use the ALS ring
- 	setpathals
- %  Perturb the lattice at 1 quadrupole, QF(1,1)
- 	qf = getsp('QF', [1 1]);
- 	qf_k0 = getsp('QF', [1 1], 'Physics')     % 2.2371
- 	setsp('QF', 1.05*qf, [1 1]);
- 	qf_k1 = getsp('QF', [1 1], 'Physics')     %  2.3432
- 	DeltaK = qf_k1 - qf_k0                         %  0.1060
- % Note: 1 micron of noise to the model BPMs
- % Get LOCO data
- 	measlocodata
- %	 Use the default model
- %	 Use the default directory
- %	 Dispersion
- %	 BPM response matrix
- %	 BPM sigma
- %	 Don’t correct the orbit

- USPAS, Phoenix

- January 16-20, 2006

## Wednesday: LOCO – Find a quadrupole error

- % Open the GUI & run
- 	locogui
- %	 Inputs
- %	      Turn off: BPM coupling
- % 	      Turn off: Correcor Magnet coupling
- % 	      Turn off: “Include off diagonal response matrix terms”
- %	Start
- %  Result: After 3 iterations
- %  FitValues = [	2.3433
- %			2.2370
- %			2.2372
- %			2.2370    ];

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Detuning with amplitude

- % Start Matlab 6.5 (newer versions 7.0 and 7.1 will work as well)
- 	cd c:\bbdiag\acceleratorcontrol
- 	setpathals
- 	global THERING
- % Starting condition for tracking (100 micron x, 100 micron y):
- X0=[0.0001;0;0.0001;0;0;0];
- %Track for 1024 turns:
- X1=ringpass(THERING,X0,1024);
- % Plot tracking results:
- figure;subplot(2,1,1);plot(X1(1,:));subplot(2,1,2);plot(X1(3,:))
- % Calculate FFT:
- fftx=abs(fft(X1(1,:))); ffty=abs(fft(X1(3,:)));
- % Frequency/Tune vector:
- nu=[0:1023]/1023;
- % Plot FFT (x/y) - tunes
- ff=figure;subplot(2,1,1);plot(nu,fftx/max(fftx));hold on
- subplot(2,1,2);plot(nu,ffty/max(ffty));hold on
- % Find tunes and print result to screen:
- [maxx,kx]=max(fftx(2:512));
- [maxy,ky]=max(ffty(2:512));
- nux(1)=nu(kx+1);nuy(1)=nu(ky+1);
- fprintf('nu_x = %g, nu_y = %g \n',nu(kx+1),nu(ky+1));

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Detuning with amplitude

- % Plot in tunespace:
- ff2 = figure;plot(nux,nuy,'o');axis([0 0.26 0 0.21]);hold on;
- % Repeat with larger amplitude (1 mm x, 100 micron y):
- X0=[0.001;0;0.0001;0;0;0];X1=ringpass(THERING,X0,1024);
- fftx=abs(fft(X1(1,:)));ffty=abs(fft(X1(3,:)));
- figure(ff);subplot(2,1,1);plot(nu,fftx/max(fftx),'r');
- subplot(2,1,2);plot(nu,ffty/max(ffty),'r')
- [maxx,kx]=max(fftx(2:512));[maxy,ky]=max(ffty(2:512));
- nux(2)=nu(kx+1);nuy(2)=nu(ky+1);
- fprintf('nu_x = %g, nu_y = %g \n',nu(kx+1),nu(ky+1));
- figure(ff2);plot(nux,nuy,'o');axis([0 0.26 0 0.21]);
- % Repeat again with larger amplitude (5 mm x, 100 micron y) – tuneshift with
- % amplitude in the simplest case scales like initial position^2:
- X0=[0.005;0;0.0001;0;0;0];
- X1=ringpass(THERING,X0,1024);
- fftx=abs(fft(X1(1,:)));ffty=abs(fft(X1(3,:)));
- figure(ff);subplot(2,1,1);plot(nu,fftx/max(fftx),'g');
- subplot(2,1,2);plot(nu,ffty/max(ffty),'g');
- [maxx,kx]=max(fftx(2:512));[maxy,ky]=max(ffty(2:512));
- nux(3)=nu(kx+1);nuy(3)=nu(ky+1);

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Detuning with amplitude

- fprintf('nu_x = %g, nu_y = %g \n',nu(kx+1),nu(ky+1));
- figure(ff2);plot(nux,nuy,'o');axis([0 0.26 0 0.21]);
- % Now with even larger horizontal amplitude (10 mm x, 100 mciron y):
- X0=[0.01;0;0.0001;0;0;0];
- X1=ringpass(THERING,X0,1024);
- fftx=abs(fft(X1(1,:)));ffty=abs(fft(X1(3,:)));
- figure(ff);subplot(2,1,1);plot(nu,fftx/max(fftx),'m');
- subplot(2,1,2);plot(nu,ffty/max(ffty),'m');
- [maxx,kx]=max(fftx(2:512));[maxy,ky]=max(ffty(2:512));
- nux(4)=nu(kx+1);nuy(4)=nu(ky+1);
- fprintf('nu_x = %g, nu_y = %g \n',nu(kx+1),nu(ky+1));
- figure(ff2);plot(nux,nuy,'o');axis([0 0.26 0 0.21]);
- % Note that the fundamental tune lines shift in frequency and change their
- % shape (the plot normalizes their amplitude to one, since otherwise you
- % would not see the small initial tunelines on the final plot). Also note that
- % with increasing amplitude more and more small resonance lines besides
- % the main tune lines show up (compare lecture on resonance driving
- % terms).

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Decoherence

- % To show how the tuneshift with amplitude together with the finite beamsize
- % will create decoherence of the coherent bunch oscillations, we track an
- % ensemble of particles (100 particles for 100 turns):
- % Initial conditions (100 random coordinates with 300 micron horizontal
- % beamsize, 20 micron vertical beamsize and corresponding divergences –
- % ALS, 1.9 GeV, insertion device straights, plus 1 mm x-offset)
- X0 = [300e-6*randn(1,100)+1.0e-3;300e-6/13.5*randn(1,100);
- 20e-6*randn(1,100)+1.0e-3;20e-6/3.65*randn(1,100);
- zeros(1,100);zeros(1,100)];
- % Track for 100 turns, use 'reuse' flag to speed up tracking (can be used if
- % lattice does not change, after every change of a lattice parameters, one
- % has to track at least once without the 'reuse' flag):
- X1=ringpass(THERING,X0,100,'reuse');
- % Bring matrices into the right shape (we are only interested in x-x‘
- % phasespace):
- x=reshape(X1(1,:),100,100);xp=reshape(X1(2,:),100,100);
- % Plot results (upper plot shows x-x' phasespace, lower plot beam center):
- f1=figure;figure(f1);subplot(2,1,1);plot(X0(1,:),X0(2,:),'.');
- axis([min(min(x)) max(max(x)) min(min(xp)) max(max(xp))]);

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Decoherence

- subplot(2,1,2);plot(0,mean(X0(1,:)),'.');
- axis([0 length(x) min(min(x)) max(max(x))]);hold on;
- % Now plot information turn-by-turn (movie):
- for loop=1:100
- figure(f1);subplot(2,1,1);plot(x(:,loop),xp(:,loop),'.');
- axis([min(min(x)) max(max(x)) min(min(xp)) max(max(xp))]);
- subplot(2,1,2);plot(loop,mean(x(:,loop)),'.');
- pause(1)
- end
- % At this amplitude (1 mm) one hardly sees any decoherence
- % Now we repeat this with another 100 random particles with the same
- % beamsize, but a 5 mm x-offset:
- X0 = [300e-6*randn(1,100)+5.0e-3;300e-6/13.5*randn(1,100);
- 20e-6*randn(1,100)+1.0e-3;20e-6/3.65*randn(1,100);
- zeros(1,100);zeros(1,100)];
- X1=ringpass(THERING,X0,100,'reuse');
- x=reshape(X1(1,:),100,100);xp=reshape(X1(2,:),100,100);
- f1=figure;figure(f1);subplot(2,1,1);plot(X0(1,:),X0(2,:),'.');
- axis([min(min(x)) max(max(x)) min(min(xp)) max(max(xp))]);

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Decoherence

- subplot(2,1,2);plot(0,mean(X0(1,:)),'.');
- axis([0 length(x) min(min(x)) max(max(x))]);hold on;
- for loop=1:100
- figure(f1);subplot(2,1,1);plot(x(:,loop),xp(:,loop),'.');
- axis([min(min(x)) max(max(x)) min(min(xp)) max(max(xp))]);
- subplot(2,1,2);plot(loop,mean(x(:,loop)),'.');
- pause(1)
- end
- % The decoherence is visible, the particles with small amplitudes complete
- % little over 1⁄2 additional rotation in phasespace, compared to the ones with
- % large amplitude.
- % Now we repeat this with another 100 random particles with the same
- % beamsize, but an 11 mm x-offset:
- X0 = [300e-6*randn(1,100)+11.0e-3;300e-6/13.5*randn(1,100);
- 20e-6*randn(1,100)+1.0e-3;20e-6/3.65*randn(1,100);
- zeros(1,100);zeros(1,100)];
- X1=ringpass(THERING,X0,100,'reuse');
- x=reshape(X1(1,:),100,100);xp=reshape(X1(2,:),100,100);

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Decoherence

- f1=figure;figure(f1);subplot(2,1,1);plot(X0(1,:),X0(2,:),'.');
- axis([min(min(x)) max(max(x)) min(min(xp)) max(max(xp))]);
- subplot(2,1,2);plot(0,mean(X0(1,:)),'.');
- axis([0 length(x) min(min(x)) max(max(x))]);hold on;
- for loop=1:100
- figure(f1);subplot(2,1,1);plot(x(:,loop),xp(:,loop),'.');
- axis([min(min(x)) max(max(x)) min(min(xp)) max(max(xp))]);
- subplot(2,1,2);plot(loop,mean(x(:,loop)),'.');
- pause(1);
- end
- % The decoherence is fairly strong, the particles with small amplitudes complete
- % more than one additional rotation in phasespace, compared to the ones with
- % large amplitude, the oscillation amplitude of the beam centroid got much
- % smaller. Even though there is no damping in the simulation, the particle seem
- % to follow a spiral, which is created by the fact that particles with smaller
- % amplitudes (in the ALS) have a higher tune.

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Decoherence/Resonances

- % Now to illustrate, how a single machine error can significantly change the
- % nonlinear dynamicd, we put one gradient and one skew gradient error into
- % our model machine:
- QFI = findcells(THERING,'FamName','QF');
- QF = getcellstruct(THERING,'PolynomB',QFI,2);
- THERING = setcellstruct(THERING,'PolynomB',QFI(9),QF(9)*1.01,2);
- THERING = setcellstruct(THERING,'PolynomA',QFI(9),QF(9)*0.002,2);
- % And we track again with the same particle distribution and 11 mm x-offset:
- X0 = [300e-6*randn(1,100)+11.0e-3;300e-6/13.5*randn(1,100);
- 20e-6*randn(1,100)+1.0e-3;20e-6/3.65*randn(1,100);
- zeros(1,100);zeros(1,100)];
- % Now one first has to track once (for one turn) without the 'reuse' flag (we
- % changed some magnet strengths:
- X1=ringpass(THERING,X0,1);
- X1=ringpass(THERING,X0,100,'reuse');
- x=reshape(X1(1,:),100,100);xp=reshape(X1(2,:),100,100);

- USPAS, Phoenix

- January 16-20, 2006

## Thursday: Decoherence/Resonances

- f1=figure;figure(f1);subplot(2,1,1);plot(X0(1,:),X0(2,:),'.');
- axis([min(min(x)) max(max(x)) min(min(xp)) max(max(xp))]);
- subplot(2,1,2);plot(0,mean(X0(1,:)),'.');
- axis([0 length(x) min(min(x)) max(max(x))]);hold on;
- for loop=1:100
- figure(f1);subplot(2,1,1);plot(x(:,loop),xp(:,loop),'.');
- axis([min(min(x)) max(max(x)) min(min(xp)) max(max(xp))]);
- subplot(2,1,2);plot(loop,mean(x(:,loop)),'.');
- pause(1);
- end
- % The machine errors created a resonance which actually captures
- % part of the particle distribution in a resonance island and therefore
- % slows down the decoherence compared to the case without errors.
- %Just in case you want to continue doing something else, remove the
- % error from the lattice:
- 	THERING = setcellstruct(THERING,'PolynomB',QFI(9),QF(9),2)
- 	THERING = setcellstruct(THERING,'PolynomA',QFI(9),0,2);

- USPAS, Phoenix

- January 16-20, 2006

## Computer Homework

- USPAS, Phoenix

- January 16-20, 2006

## Motivation for Homework Problems

- Dispersion:        ηx = Δx / (Δp/p)
- Chromaticity:     ζ = Δ ν / (Δp/p)
- Momentum compaction factor:
-                           α = (ΔL/L) / (Δp/p)

- Storage Ring Setup

- USPAS, Phoenix

- January 16-20, 2006

## Computer Homework #1

- Computer Homework #1: Dispersion & Chromaticity
- Given the following middle layer commands:
- 	x = getam('BPMx');  % Horizontal orbit at BPMs(122x1)
- 	RF = getrf;               %  Get the RF frequency (MHz)
- 	setrf(RF);                 %  Set the RF frequency (MHz)
- 	Tune = gettune;       %  Tune [NuX; NuY]
-      Alpha = getmcf;        %  Momentum compaction factor
- Write a Matlab script to:
- 	1. Plot the horizontal dispersion function: ηx = Δx / (Δp/p)
-          Note: (Δp/p) = - (1/α)(Δf/f)
-          Use: ±.1% energy change
- 	2. Plot the horizontal tune vs energy change
-          (compute at [-.4%  -.2%  0  .2%  .4%] energy changes)
-      3. Compute the horizontal chromaticity by using a numerical derivative.
- 	    (I.e., the slope of horizontal tune vs energy change at Δp/p=0)

- USPAS, Phoenix

- January 16-20, 2006

## Computer Homework #2: Tune Correction	

- Given the following middle layer commands:
- 	Tune = gettune;     %  Tune [NuX; NuY]
- 	qf = getsp(‘QF');     % Get all the QF setpoints
- 	setsp(‘QF', qf+.5);   % Change QF by .5 amp
- Write a Matlab script to:
-     1. Record the starting tunes
-     2. Measure the [2x2] tune response matrix.  I.e., the response
-         from QF & QD to horizontal and vertical tune.  There are
-         24 magnets in each of the families, however, treat the entire
-         quadrupole family as a single tune corrector.  Use a .5 amp
-         change in the quadrupole family to get the response matrix.
-     3. Change the tunes by [-.1; .05] using the QF & QD families.
-         How much change in the QF & QD families did it take?

- USPAS, Phoenix

- January 16-20, 2006

## Computer Homework #3

- Computer Homework #3:  Orbit Correction
- Given the following middle layer commands:
- 	x = getam('BPMx');     % Horizontal orbit at BPMs(122x1)
- 	R = getbpmresp;         % Get the coupled BPM response matrix
-      Rx = R(1:122,1:97);    % Just the horizontal part of the matrix
- 	hcm = getsp('HCM');   % Get the horizontal corrector setpoints (97x1)
- 	setsp('HCM', hcm);     % Set the horizontal correctors
- 1. Create a random orbit error with the following commands:
- 	hcm = .05 * randn(97,1);     % 97 horizontal correctors at the ALS
- 	setsp('HCM', hcm);
- 2. Write a Matlab script to correct the orbit:
-     a. Plot the singular values of the response matrix (semilogy)
-     b. Plot the remaining RMS orbit error vs. # of the singular values.
-         Ie., orbit error when 1 sv is used, 1:2 sv, 1:3 sv, 1:4 sv, etc.
-     c. Plot the total corrector strength change  (sum(abs(DeltaHCM))) vs.
-         # of the singular values used.
-     d. How many singular values would you recommend using?

- USPAS, Phoenix

- January 16-20, 2006

## Computer Homework #4: Local Bumps	

-      Use the equations from Problem Set #2 and the optics data below to compute the kicks for a 3-magnet bump.

- Electron Beam

- Corrector Magnets

- θ1

- θ2

- θ3

- s1

- s2

- s3

- USPAS, Phoenix

- January 16-20, 2006

## Computer Homework #4: Local Bumps (cont.)

- Matlab Help:
- % Get the horizontal orbit
- 	x = getam('BPMx');
- % Change HCM[6 1] by +.1 mrad  (‘Physcis’ units are radians for a corrector magnet)
- 	hcm = getsp('HCM', [6 1], 'Physics');
- 	setsp('HCM', hcm+.0001, [6 1], 'Physics');
- % Get the beta & phase [radian] advance of the model
- 	beta1 = modeltwiss('Beta', 'HCM', [6 1])
- 	phase1 = modeltwiss('Phase', 'HCM', [6 1])
- % Get & Set the RF frequency
- 	RF = getrf;
- 	setrf(RF);

- B. Put the 3 correction magnet changes in the model and plot the horizontal orbit.  The bump should look basically closed at this point.
- C. Since the dispersion function is not zero at the corrector magnets, the correctors changed the energy of the beam.  Can you change the RF frequency by the classic “knob turning” method (ie, trial-and-error) to make the bump more “local”?  How much RF change did it take?
- D. In matlab: [Energy, HCMEnergy] = getenergy will return the energy change due to the HCMs.  Compute the required RF change to counter the energy change due to the corrector magnet change.

- USPAS, Phoenix

- January 16-20, 2006