forked from ThorstenHellert/SC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCgetCOD.m
103 lines (88 loc) · 2.35 KB
/
SCgetCOD.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function COD = SCgetCOD(SC,varargin)
% SCgetCOD
% ========
%
% NAME
% ----
% SCgetCOD - Calculates closed orbit deviations with respect to magnet centers.
%
% SYNOPSIS
% --------
% `COD = SCgetCOD(SC [, options])`
%
% DESCRIPTION
% -----------
% This function calculates the closed orbit deviation from the magnetic centers.
%
% INPUTS
% ------
%
% `SC`::
% SC base structure
%
% OPTIONS
% -------
% The following options can be given as name/value-pairs:
%
% `'ords'` (`SC.ORD.Magnet`)::
% List of magnet ordinates at which the orbit deviation should be evaluated.
% `'plot'` (`0`)::
% Flag indicating if closed orbit deviation should be plotted.
%
% RETURN VALUES
% -------------
% `COD`::
% Orbit deviation w.r.t. magnet centers
%
% EXAMPLES
% --------
% Calculate closed orbit deviation in magnets named 'SF' and 'SD' and plot results.
% ------------------------------------------------------------------
% COD = SCgetCOD(SC,'ords',SCgetOrds(SC.RING,'SF|SD'),'plot',1);
% ------------------------------------------------------------------
% Parse input
p = inputParser;
addOptional(p,'ords',SC.ORD.Magnet);
addOptional(p,'plot',0);
parse(p,varargin{:});
par = p.Results;
% Calculate orbit
T = findorbit6(SC.RING,par.ords);
if any(isnan(T))
warning('Closed orbit could not be found.')
COD = nan(2,length(par.ords));
return
end
% Get magnet offsets
magOffset=zeros(2,length(par.ords));i=1;
for ord=par.ords
magOffset(:,i) = SC.RING{ord}.T2([1 3]);
i=i+1;
end
% Calculate orbit deviation in magnets
COD = T([1,3],:) - magOffset;
% Plot results?
if par.plot
% Get s-positions
sPos = findspos(SC.RING,par.ords);
ylabelStr = {'$\Delta x$ [mm]','$\Delta y$ [mm]'};
figure(784);clf
for nDim=1:2
ax(nDim) = subplot(2,1,nDim);hold on
plot(sPos,1E3*COD(nDim,:),'LineWidth',2)
plot(sPos,1E3*magOffset(nDim,:),'LineWidth',2)
plot(sPos,1E3*T(2*nDim-1,:),'LineWidth',2)
legend({'COD in magnets','Magnet offset','Orbit'})
xlabel('s [m]');
ylabel(ylabelStr{nDim});
set(gca,'box','on','xlim',[min(sPos),max(sPos)])
end
set(findall(gcf,'-property','FontSize'),'FontSize',18);
set(findall(gcf,'-property','Interpreter'),'Interpreter','latex');
set(findall(gcf,'-property','TickLabelInterpreter'),'TickLabelInterpreter','latex');
set(gcf,'color','w');
drawnow
% Link x-axis
linkaxes([ax(1) ax(2)],'x')
end
end