1 | function BeamLossgui()
|
---|
2 | %BeamLossgui: user interface for beam losses when RF is switched off
|
---|
3 | %
|
---|
4 | % BeamLossgui() used the GUILayout toolbox.
|
---|
5 | %
|
---|
6 | % NOTES:
|
---|
7 | % Works only with thick sextupoles
|
---|
8 | % Warning otherwise divergence in sextupoles !!!
|
---|
9 |
|
---|
10 | %
|
---|
11 | %% Written by Laurent S. Nadolski
|
---|
12 |
|
---|
13 | % Data is shared between all child functions by declaring the variables
|
---|
14 | % here (they become global to the function). We keep things tidy by putting
|
---|
15 | % all GUI stuff in one structure and all data stuff in another. As the app
|
---|
16 | % grows, we might consider making these objects rather than structures.
|
---|
17 | global THERING;
|
---|
18 |
|
---|
19 | data = createData();
|
---|
20 | gui = createInterface();
|
---|
21 |
|
---|
22 | % Now update the GUI with the current data
|
---|
23 | %redrawData();
|
---|
24 | setradiation('on');
|
---|
25 | setcavity('off');
|
---|
26 | onCompute();
|
---|
27 |
|
---|
28 | %-------------------------------------------------------------------------%
|
---|
29 | function data = createData()
|
---|
30 | % Create the shared data-structure for this applicdata.ATion
|
---|
31 | data.Nturn = 100;
|
---|
32 | data.ATi = atindex;
|
---|
33 | data.spos = findspos(THERING,1:length(THERING)+1);
|
---|
34 |
|
---|
35 | end % createData
|
---|
36 |
|
---|
37 | %-------------------------------------------------------------------------%
|
---|
38 | function gui = createInterface
|
---|
39 | % Create the user interface for the applicdata.ATion and return a
|
---|
40 | % structure of handles for global use.
|
---|
41 |
|
---|
42 | orbfig = findobj(allchild(0),'Name','Beam Loss GUI');
|
---|
43 |
|
---|
44 | % if already open, then close it
|
---|
45 | if ~isempty(orbfig)
|
---|
46 | close(orbfig); % IHM already exists
|
---|
47 | end
|
---|
48 |
|
---|
49 | gui = struct();
|
---|
50 | % Open a window and add some menus
|
---|
51 | gui.Window = figure( ...
|
---|
52 | 'Name', 'Beam Loss GUI', ...
|
---|
53 | 'NumberTitle', 'off', ...
|
---|
54 | 'MenuBar', 'none', ...
|
---|
55 | 'Toolbar', 'none', ...
|
---|
56 | 'Toolbar', 'Figure', ...
|
---|
57 | 'HandleVisibility', 'off' );
|
---|
58 |
|
---|
59 | % Set default panel color
|
---|
60 | uiextras.set( gui.Window, 'DefaultBoxPanelTitleColor', [0.7 1.0 0.7] );
|
---|
61 |
|
---|
62 | % + Help menu
|
---|
63 | helpMenu = uimenu( gui.Window, 'Label', 'Help' );
|
---|
64 | uimenu( helpMenu, 'Label', 'documentation', 'Callback', @onDemoHelp );
|
---|
65 |
|
---|
66 |
|
---|
67 | % Arrange the main interface
|
---|
68 | mainLayout = uiextras.HBoxFlex( 'Parent', gui.Window, 'Spacing', 3 );
|
---|
69 |
|
---|
70 | % + Create the panels
|
---|
71 |
|
---|
72 | controlPanel = uiextras.BoxPanel( ...
|
---|
73 | 'Parent', mainLayout, ...
|
---|
74 | 'Title', 'Select options:' );
|
---|
75 |
|
---|
76 | gui.ViewPanel{1} = uiextras.BoxPanel( ...
|
---|
77 | 'Parent', mainLayout, ...
|
---|
78 | 'Title', 'Tracking data', ...
|
---|
79 | 'HelpFcn', @onDemoHelp );
|
---|
80 |
|
---|
81 | % + Adjust the main layout
|
---|
82 | set( mainLayout, 'Sizes', [-1,-3] );
|
---|
83 |
|
---|
84 | % + Create the controls
|
---|
85 | controlLayout = uiextras.VBox( 'Parent', controlPanel, ...
|
---|
86 | 'Padding', 3, 'Spacing', 3 );
|
---|
87 |
|
---|
88 | % + Create panel
|
---|
89 | TurnPanel = uiextras.BoxPanel( 'Title', 'Number of turns:', 'Parent', controlLayout );
|
---|
90 | gui.TurnEdit = uicontrol( 'Style', 'edit', ...
|
---|
91 | 'BackgroundColor', 'w', ...
|
---|
92 | 'Parent', TurnPanel, ...
|
---|
93 | 'String', '100', ...
|
---|
94 | 'Callback', @onTurnEdit);
|
---|
95 |
|
---|
96 | % + Create panel
|
---|
97 | CoordPanel = uiextras.BoxPanel( 'Title', 'Coordinates @ end', 'Parent', controlLayout );
|
---|
98 | gui.CoordPanel = uicontrol( 'Style', 'text', ...
|
---|
99 | 'BackgroundColor', 'w', ...
|
---|
100 | 'Parent', CoordPanel, ...
|
---|
101 | 'Max', 6, ...
|
---|
102 | 'FontName', 'FixedWidth', ...
|
---|
103 | 'String', {'x =0','px =0','y =0','py =0','delta=0','ctau =0'}, ...
|
---|
104 | 'Callback', []);
|
---|
105 |
|
---|
106 | % + Radiation button
|
---|
107 | gui.RadiationCheckBox = uicontrol( 'Style', 'checkbox', ...
|
---|
108 | 'BackgroundColor', 'w', ...
|
---|
109 | 'Parent', controlLayout, ...
|
---|
110 | 'String', 'Radiation', ...
|
---|
111 | 'Value', 1, ...
|
---|
112 | 'Callback', @onRadiation);
|
---|
113 |
|
---|
114 | % + Cavity button
|
---|
115 | gui.CavityCheckBox = uicontrol( 'Style', 'checkbox', ...
|
---|
116 | 'BackgroundColor', 'w', ...
|
---|
117 | 'Parent', controlLayout, ...
|
---|
118 | 'String', 'Cavity', ...
|
---|
119 | 'Value', 0, ...
|
---|
120 | 'Callback', @onCavity);
|
---|
121 |
|
---|
122 | % + Reload Button
|
---|
123 | gui.ReloadButton = uicontrol( 'Style', 'PushButton', ...
|
---|
124 | 'Parent', controlLayout, ...
|
---|
125 | 'String', 'Reload lattice', ...
|
---|
126 | 'Callback', @onReload );
|
---|
127 |
|
---|
128 | % + Compute Button
|
---|
129 | gui.ComputeButton = uicontrol( 'Style', 'PushButton', ...
|
---|
130 | 'Parent', controlLayout, ...
|
---|
131 | 'String', 'Compute', ...
|
---|
132 | 'Callback', @onCompute );
|
---|
133 |
|
---|
134 | % + Help Button
|
---|
135 | gui.HelpButton = uicontrol( 'Style', 'PushButton', ...
|
---|
136 | 'Parent', controlLayout, ...
|
---|
137 | 'String', 'Help', ...
|
---|
138 | 'Callback', @onDemoHelp );
|
---|
139 | set( controlLayout, 'Sizes', [50 3.5*28 28 28 28 28 28] ); % Make the list fill the space
|
---|
140 |
|
---|
141 | %%%%%%%%%%%
|
---|
142 | PanelLayout = uiextras.TabPanel( 'Parent', gui.ViewPanel{1});
|
---|
143 |
|
---|
144 | for k=1:3,
|
---|
145 | % + Create the view
|
---|
146 | AxesTabPanel{k} = uiextras.VBox( 'Parent', PanelLayout, ...
|
---|
147 | 'Padding', 40, 'Spacing', 10 );
|
---|
148 |
|
---|
149 | % + Main axes for draw data
|
---|
150 | gui.ViewAxes{k} = axes( 'Parent', AxesTabPanel{k}, ...
|
---|
151 | 'ActivePositionProperty', 'Position', ...
|
---|
152 | 'xticklabel', []);
|
---|
153 |
|
---|
154 | % + drawlattice
|
---|
155 | gui.LatticeAxes{k} = axes( 'Parent', AxesTabPanel{k}, ...
|
---|
156 | 'ActivePositionProperty', 'Position');
|
---|
157 |
|
---|
158 | % + Drawlattice Axes
|
---|
159 |
|
---|
160 | drawlattice(0,1,gui.LatticeAxes{k});
|
---|
161 | xlabel(gui.LatticeAxes{k}, 's-position (m)');
|
---|
162 | set(gui.LatticeAxes{k},'yticklabel', []);
|
---|
163 | %set(gui.LatticeAxes, 'Position', [0.142 0.122 0.751 1])
|
---|
164 | xlim(gui.ViewAxes{k}, [0 getcircumference]);
|
---|
165 | set(AxesTabPanel{k}, 'Sizes', [-4 -1])
|
---|
166 | end
|
---|
167 | linkaxes([gui.ViewAxes{:} gui.LatticeAxes{:}],'x')
|
---|
168 | set(PanelLayout, 'TabNames', {'x (m)', 'px (rad)', 'delta'}, ...
|
---|
169 | 'SelectedChild', 1);
|
---|
170 | end % createInterface
|
---|
171 |
|
---|
172 | %-------------------------------------------------------------------------%
|
---|
173 | function updateInterface()
|
---|
174 | % Update various parts of the interface in response to the demo
|
---|
175 | % being changed.
|
---|
176 |
|
---|
177 | % Update the help button label
|
---|
178 | demoName = data.DemoNames{ data.SelectedDemo };
|
---|
179 | set( gui.HelpButton, 'String', ['Help for ',demoName] );
|
---|
180 | end % updateInterface
|
---|
181 |
|
---|
182 | %-------------------------------------------------------------------------%
|
---|
183 | function redrawData()
|
---|
184 | % Draw a demo into the axes provided
|
---|
185 | coord = [1 2 5];
|
---|
186 | for k=1:3,
|
---|
187 | cla(gui.ViewAxes{k});
|
---|
188 | len = size(data.xAllBPMs,2);
|
---|
189 |
|
---|
190 | % Sampling
|
---|
191 | ivect = [(1:10:len) len-1];
|
---|
192 |
|
---|
193 | % plot data
|
---|
194 | plot(gui.ViewAxes{k}, data.spos, data.xAllBPMs(:,ivect,coord(k)),'k');
|
---|
195 | hold(gui.ViewAxes{k},'on');
|
---|
196 | ylimits = [-0.040 0.005];
|
---|
197 |
|
---|
198 | %plot scrapers and mSDC15 if defined
|
---|
199 |
|
---|
200 | plot(gui.ViewAxes{k},[data.spos(data.ATi.HSCRAP(1)) data.spos(data.ATi.HSCRAP(1))], [0.0 ylimits(1)], 'r-.')
|
---|
201 |
|
---|
202 | if isfield(data.ATi, 'mSDC15')
|
---|
203 | plot(gui.ViewAxes{k},[data.spos(data.ATi.mSDC15) data.spos(data.ATi.mSDC15)], [0.0 ylimits(1)], 'r-.')
|
---|
204 | else
|
---|
205 | fprintf('mSDC15 marker not defined \n');
|
---|
206 | end
|
---|
207 |
|
---|
208 | ylim(gui.ViewAxes{k}, ylimits);
|
---|
209 | set(gui.ViewAxes{k},'xticklabel', []);
|
---|
210 | end
|
---|
211 |
|
---|
212 | if isfield(data.ATi, 'mSDC15')
|
---|
213 | xstrTitle = sprintf('Particle lost at turn #%d H-scraper: %.3f mm SDC15: %.3f mm', ...
|
---|
214 | size(data.xAllBPMs,2), data.xAllBPMs(data.ATi.HSCRAP(1), end,1), ...
|
---|
215 | data.xAllBPMs(data.ATi.mSDC15, end,1));
|
---|
216 | else
|
---|
217 | xstrTitle = '';
|
---|
218 | end
|
---|
219 |
|
---|
220 | title(gui.ViewAxes{1}, xstrTitle)
|
---|
221 |
|
---|
222 | set(gui.CoordPanel, 'String', {...
|
---|
223 | sprintf('x = % .6f', data.xAllBPMs(1,end,1)), ...
|
---|
224 | sprintf('px = % .6f', data.xAllBPMs(1,end,2)), ...
|
---|
225 | sprintf('y = % .6f', data.xAllBPMs(1,end,3)), ...
|
---|
226 | sprintf('py = % .6f', data.xAllBPMs(1,end,4)), ...
|
---|
227 | sprintf('delta = % .6f', data.xAllBPMs(1,end,5)), ...
|
---|
228 | sprintf('ctau = % .6f', data.xAllBPMs(1,end,6))});
|
---|
229 | end % redrawData
|
---|
230 |
|
---|
231 | %-------------------------------------------------------------------------%
|
---|
232 | function onTurnEdit(hObj,~)
|
---|
233 | % User selected a demo from the list - update "data" and refresh
|
---|
234 | data.Nturn = str2double(get( hObj, 'String' ));
|
---|
235 | set(hObj, 'BackGroundColor', 'w');
|
---|
236 | onCompute();
|
---|
237 | end % onTurnEdit
|
---|
238 |
|
---|
239 | %-------------------------------------------------------------------------%
|
---|
240 | function onRadiation( hObj, ~ )
|
---|
241 | % User has asked for the documentation
|
---|
242 | val = get( hObj, 'Value' );
|
---|
243 | if val
|
---|
244 | setradiation('on');
|
---|
245 | else
|
---|
246 | setradiation('off');
|
---|
247 | end
|
---|
248 | end % onRadiation
|
---|
249 |
|
---|
250 | %-------------------------------------------------------------------------%
|
---|
251 | function onCavity( hObj, ~ )
|
---|
252 | % User has asked for the documentation
|
---|
253 | val = get( hObj, 'Value' );
|
---|
254 | if val
|
---|
255 | setcavity('on');
|
---|
256 | else
|
---|
257 | setcavity('off');
|
---|
258 | end
|
---|
259 | end % onCavity
|
---|
260 |
|
---|
261 | %-------------------------------------------------------------------------%
|
---|
262 | function onCompute( ~, ~ )
|
---|
263 | % Do the tracking
|
---|
264 | [data.xAllBPMs, ATindex, data.LostBeam] = getturns([0.0 0 0 0 0.0 0]', data.Nturn, 'All');
|
---|
265 | if ~isempty(data.xAllBPMs)
|
---|
266 | redrawData();
|
---|
267 | else
|
---|
268 | set(gui.TurnEdit, 'BackGroundColor', 'red');
|
---|
269 | end
|
---|
270 | end % onCompute
|
---|
271 |
|
---|
272 | %-------------------------------------------------------------------------%
|
---|
273 | function onReload( ~, ~ )
|
---|
274 | data.ATi = atindex;
|
---|
275 | data.spos = findspos(THERING,1:length(THERING)+1);
|
---|
276 | setradiation('on');
|
---|
277 | setcavity('off');
|
---|
278 | end % onReload
|
---|
279 |
|
---|
280 |
|
---|
281 | %-------------------------------------------------------------------------%
|
---|
282 | function onDemoHelp( ~, ~ )
|
---|
283 | % User wants documentation for the current demo
|
---|
284 | help BeamLossgui;
|
---|
285 | end % onDemoHelp
|
---|
286 |
|
---|
287 | %-------------------------------------------------------------------------%
|
---|
288 | function onExit( ~, ~ )
|
---|
289 | % User wants to quit out of the applicdata.ATion
|
---|
290 | delete( gui.Window );
|
---|
291 | end % onExit
|
---|
292 |
|
---|
293 | end % EOF |
---|