# Presentation: 004606

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

-  Monday: Intro to the Middle Layer and AT
-                   Orbit errors
-  Tuesday:
- Potentially real measurements using SPEAR 3
- Gradient errors, beta function, phase advance
-  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

## Monday: AT Lattice Model & Orbits

- %  Plot lattice (AT):
- 	intlat
- %  Edit the AT lattice file:
- 	edit alslat_loco_3sb_disp_nuy9_122bpms
- % Look at example element tracking file
- 	edit QuadLinearPass.c
- %  Plot the orbit with plotfamily (Middle Layer):
- 	plotfamily
- % Orbit will look somewhat strange since beam based alignment not possible for all BPMs – no consistent definition of golden orbit in simulator ...
- % -> Save current orbit -> Plot difference to saved orbit
- %  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,Annapolis

- June 16-20, 2008

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

- June 16-20, 2008

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

- June 16-20, 2008

## Monday: Closed Orbits

- % Play a little with plotfamily
- % Common Tasks -> Orbit Correction -> or ...
- % Common Tasks -> Measure -> ... has many options
- % Example from lecture
- Y0 = getam('BPMy'); BPMindex=getlist('BPMy');
- % Create an Orbit Error
- vcm = .25 * randn(73,1);     % 73 vertical correctors at the ALS
- setsp('VCM', vcm);
- % Get the vertical orbit
- Y = getam('BPMy');
- plot(Y-Y0);hold on;
- % Get the Vertical response matrix from the model
- Ry = getrespmat('BPMy', BPMindex, 'VCM');       % 122x73 matrix
- % Computes the SVD of the response matrix
- Ivec = 1:48;
- [U, S, V] = svd(Ry, 0);
- % Find the corrector changes use 48 singular values
- DeltaAmps = -V(:,Ivec) * S(Ivec,Ivec)^-1 * U(:,Ivec)' *  (Y-Y0);
- % Changes the corrector strengths
- stepsp('VCM', DeltaAmps);
- % Get the vertical orbit
- Y = getam('BPMy');
- plot(Y-Y0, 'r');			% can iterate

- USPAS,Annapolis

- June 16-20, 2008