# Presentation: 575462

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

-  Monday: Intro to the Middle Layer and AT
-                   Orbit errors
-  Tuesday:
- Beam measurements using SPEAR 3
- Beta function, phase advance, beam based alignment
-  Wednesday: Gradient errors, LOCO
-  Thursday: Detuning with amplitude, decoherence, resonances
-  Friday: TBD

**Christoph Steier with help from James Safranek **

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

- USPAS,Annapolis

- June 16-20, 2008

**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 2008a (7.6) (AT and LOCO require at least Matlab version 7.x) - Matlab 7.6 is the latest version.
- Matlab middle layer is installed on the computers in the first 3 rows in the computer room
- I already have preset c:\bbdiag\acceleratorcontrol\mml on the Matlab path, this directory contains many routines, including the ones that set up memory structures and Matlab path for different accelerators
-      setpathals
-      setpathspear3
-      setpathxray
-      setpathvuv
- And many others ...
- cd c:\bbdiag – here we will put all the examples of this class – you can get the example file for the day from http://als.lbl.gov/als_physics/csteier/uspas08/computerclass.html
- Note: When in doubt, setpathals (or spear3, ...) will also restore the default lattice.

- USPAS,Annapolis

- June 16-20, 2008

## Tuesday: Gradient Errors

- %  Plot the beta function and phase advance for the
- %  nominal model and a model with a gradient error
- setpv('BPMx','Status',1,[1 7;6 2]);
- setpv('BPMy','Status',1,[1 7;6 2]);
- %  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,2,1);
- 	plot(s, BetaX1./BetaX0);
- 	xlabel('s [m]');
- 	title('Beta Beat from the Nominal Model');
- 	subplot(2,2,2);
- 	plot(s, BetaY1./BetaY0);
- 	xlabel('s [m]');
- 	subplot(2,2,3);
- 	plot(MuX0, BetaX1./BetaX0);
- 	xlabel('\mu_x [2\pi]');
- 	subplot(2,2,4);
- 	plot(MuY0, BetaY1./BetaY0);
- 	xlabel('\mu_y [2\pi]');
- %  Restore the lattice
- 	setsp('QF', qf, [7 1]);

- USPAS,Annapolis

- June 16-20, 2008

## Tuesday: 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,Annapolis

- June 16-20, 2008

## Tuesday: 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,Annapolis

- June 16-20, 2008

## Tuessday: 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,Annapolis

- June 16-20, 2008

## Tuessday: FFT Analyze

- % Now put a quadrupole error in the lattice and repeat
- steppv('QF',1,[6 1]);
- %  Track for 1024 turns
- 	X1 = ringpass(THERING, X0, 1024);
- %  Track coordinates for every turn along the ring (to all BPMs)
- 	X2 = linepass(THERING, X1, BPMindex);
- %  Recover matrix structure (turns x BPM#):
- 	BPMx = reshape(X2(1,:), 1024, 122);
- 	BPMy = reshape(X2(3,:), 1024, 122);
- %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 previous results.
- DeltaMuX = MuXnoise(:)-MuX0/(2*pi);
- DeltaMuY = MuYnoise(:)-MuY0/(2*pi);
- figure(2);
- subplot(2,1,1); hold on;
- plot(MuX0, DeltaMuX-DeltaMuX(1),'.-g');
- subplot(2,1,2); hold on;
- plot(MuY0, DeltaMuY-DeltaMuY(1),'.-g');
- steppv('QF',-1,[6 1]);

- USPAS,Annapolis

- June 16-20, 2008

## Tuesday: Quadrupole Centers

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

- USPAS,Annapolis

- June 16-20, 2008