forked from ThorstenHellert/SC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCplotBPMreading.m
More file actions
148 lines (125 loc) · 3.94 KB
/
SCplotBPMreading.m
File metadata and controls
148 lines (125 loc) · 3.94 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
function SCplotBPMreading(SC,B,T)
% SCplotBPMreading
% ================
%
% NAME
% ----
% SCplotBPMreading - plots BPM readings and particle trajectories
%
% SYNOPSIS
% --------
% `SCplotBPMreading(SC, B, T)`
%
%
% DESCRIPTION
% -----------
% `SCplotBPMreading` is a plotting function used by *SCgetBPMreading* and plots the BPM readings and
% particle trajectories including the aperture model. Note that the BPM readings must include all
% registered BPMs and the trajectories must be evaluated at all lattice elements.
%
%
% INPUTS
% ------
% `SC`:: SC base structure
% `B`:: BPM readings
% `T`:: Trajectories
%
% SEE ALSO
% --------
% *SCgetBPMreading*
ApertureForPLotting = getRingAperture(SC);
% Check if orbit mode
if strcmp(SC.INJ.trackMode,'ORB')
SC.INJ.nTurns = 1;
SC.INJ.nParticles = 1;
end
figure(23);clf; tmpCol = get(gca, 'ColorOrder');
% Labels and legend
ylabelStr = {'$\Delta x$ [mm]','$\Delta y$ [mm]'};
legStr = {'Particle trajectories','BPM reading','Aperture'};
% s positions of all lattice elements
sPos = findspos(SC.RING,1:length(SC.RING))';
sMax = findspos(SC.RING,length(SC.RING)+1);
% Loop over dimensions
for nDim=1:2
ax(nDim)=subplot(2,1,nDim);hold on
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Trajectories
x = reshape([0:SC.INJ.nTurns-1]*sMax+sPos,1,[]);
x = repmat(x',1,SC.INJ.nParticles);
for nS=1:SC.INJ.nShots
M = SCparticlesIn3D(T(:,:,nS),SC.INJ.nParticles);
y = 1E3*squeeze(M(2*nDim-1,:,:));
legVec=plot(x,y,'k');
end
% Use one line for legend handle
legVec=legVec(1);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BPMs
x = reshape([0:SC.INJ.nTurns-1]*sMax+findspos(SC.RING,SC.ORD.BPM)',1,[]);
y = 1E3*(B(nDim,:));
legVec(2) = plot(x,y,'rO');
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Aperture
if ~isempty(ApertureForPLotting)
apS = sPos(ApertureForPLotting.apOrds);
x = reshape([0:SC.INJ.nTurns-1]*sMax+apS,1,[]);
y = 1E3*repmat(ApertureForPLotting.apVals{nDim},1,SC.INJ.nTurns);
legVec(3)=stairs(x,y(1,:),'Color',tmpCol(1,:),'LineWidth',4);
stairs(x,y(2,:),'Color',tmpCol(1,:),'LineWidth',4)
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ring ending
x = reshape([0:SC.INJ.nTurns-1]*sMax,1,[]);
for nT=1:SC.INJ.nTurns
plot(x(nT)*[1 1],10*[-1 1],'k:')
end
% Set axes properties
set(gca,...
'XLim',[0 SC.INJ.nTurns*sPos(end)],...
'box','on',...
'Position',get(gca,'Position')+[0 .07*(nDim-1) 0 0])
set(gca,'ylim',.5*[-1 1])
% Label and legend
ylabel(ylabelStr{nDim});
legend(legVec,legStr{1:length(legVec)});
end
% Label, white background, font size and latex
xlabel('$s$ [m]');
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')
% % (needed for making movies)
% global figFrame
% tmp = getframe(gcf);
% figFrame(end+1).cdata = tmp.cdata;
% figFrame(end).colormap = tmp.colormap;
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Auxiliary functions
% Get aperture
function ApertureForPLotting = getRingAperture(SC)
apOrds=[];apVals={[],[]};
for ord=1:length(SC.RING)
if isfield(SC.RING{ord},'EApertures') || isfield(SC.RING{ord},'RApertures')
apOrds(end+1) = ord;
for nDim=1:2
if isfield(SC.RING{ord},'EApertures')
apVals{nDim}(:,end+1) = SC.RING{ord}.EApertures(nDim) * [-1 1];
else
apVals{nDim}(:,end+1) = SC.RING{ord}.RApertures(2*(nDim-1) + [1 2] );
end
end
end
end
if isempty(apOrds)
ApertureForPLotting = [];
else
ApertureForPLotting.apOrds = apOrds;
ApertureForPLotting.apVals = apVals;
end
end