source: MML/trunk/machine/SOLEIL/StorageRing/PSB/PSB_tempogui.m @ 17

Last change on this file since 17 was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

  • Property svn:executable set to *
File size: 15.5 KB
Line 
1function varargout = PSB_tempogui(varargin)
2% PSB_TEMPOGUI M-file for PSB_tempogui.fig
3%      PSB_TEMPOGUI, by itself, creates a new PSB_TEMPOGUI or raises the existing
4%      singleton*.
5%
6%      H = PSB_TEMPOGUI returns the handle to a new PSB_TEMPOGUI or the handle to
7%      the existing singleton*.
8%
9%      PSB_TEMPOGUI('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in PSB_TEMPOGUI.M with the given input arguments.
11%
12%      PSB_TEMPOGUI('Property','Value',...) creates a new PSB_TEMPOGUI or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before PSB_tempogui_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to PSB_tempogui_OpeningFcn via varargin.
17%
18%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
19%      instance to run (singleton)".
20%
21% See also: GUIDE, GUIDATA, GUIHANDLES
22
23% Edit the above text to modify the response to help PSB_tempogui
24
25% Last Modified by GUIDE v2.5 13-Dec-2010 11:49:59
26
27% Begin initialization code - DO NOT EDIT
28gui_Singleton = 1;
29gui_State = struct('gui_Name',       mfilename, ...
30                   'gui_Singleton',  gui_Singleton, ...
31                   'gui_OpeningFcn', @PSB_tempogui_OpeningFcn, ...
32                   'gui_OutputFcn',  @PSB_tempogui_OutputFcn, ...
33                   'gui_LayoutFcn',  [] , ...
34                   'gui_Callback',   []);
35if nargin && ischar(varargin{1})
36    gui_State.gui_Callback = str2func(varargin{1});
37end
38
39if nargout
40    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41else
42    gui_mainfcn(gui_State, varargin{:});
43end
44% End initialization code - DO NOT EDIT
45
46
47% --- Executes just before PSB_tempogui is made visible.
48function PSB_tempogui_OpeningFcn(hObject, eventdata, handles, varargin)
49% This function has no output args, see OutputFcn.
50% hObject    handle to figure
51% eventdata  reserved - to be defined in a future version of MATLAB
52% handles    structure with handles and user data (see GUIDATA)
53% varargin   command line arguments to PSB_tempogui (see VARARGIN)
54
55% Choose default command line output for PSB_tempogui
56handles.output = hObject;
57
58% Update handles structure
59guidata(hObject, handles);
60
61% UIWAIT makes PSB_tempogui wait for user response (see UIRESUME)
62% uiwait(handles.figure1);
63lat_2020_3170_pseudo1
64updateatindex;
65handles.ATIndexList = atindex;
66handles.thetax = 0;
67handles.thetaz = 0;
68handles.Turns = 1;
69
70[betax betaz]   = modelbeta('all');
71[alphax alphaz] = modeltwiss('alpha', 'all');
72
73handles.alphaT = alphax(handles.ATIndexList.TEMPO);
74handles.betaT = betax(handles.ATIndexList.TEMPO);
75handles.gammaT=(1+handles.alphaT*handles.alphaT)/handles.betaT;
76
77handles.HCOR = getsp('HCOR', 'Model');
78
79% Update handles structure
80guidata(hObject, handles);
81
82
83% --- Outputs from this function are returned to the command line.
84function varargout = PSB_tempogui_OutputFcn(hObject, eventdata, handles)
85% varargout  cell array for returning output args (see VARARGOUT);
86% hObject    handle to figure
87% eventdata  reserved - to be defined in a future version of MATLAB
88% handles    structure with handles and user data (see GUIDATA)
89
90% Get default command line output from handles structure
91varargout{1} = handles.output;
92
93
94
95function edit_KEMV_Callback(hObject, eventdata, handles)
96% hObject    handle to edit_KEMV (see GCBO)
97% eventdata  reserved - to be defined in a future version of MATLAB
98% handles    structure with handles and user data (see GUIDATA)
99
100% Hints: get(hObject,'String') returns contents of edit_KEMV as text
101%        str2double(get(hObject,'String')) returns contents of edit_KEMV as a double
102handles.thetaz = str2double(get(hObject,'String'))*1e-6; % rad
103% Update handles structure
104guidata(hObject, handles);
105pushbutton_plot_Callback(handles.pushbutton_plot, eventdata, handles)
106
107
108% --- Executes during object creation, after setting all properties.
109function edit_KEMV_CreateFcn(hObject, eventdata, handles)
110% hObject    handle to edit_KEMV (see GCBO)
111% eventdata  reserved - to be defined in a future version of MATLAB
112% handles    empty - handles not created until after all CreateFcns called
113
114% Hint: edit controls usually have a white background on Windows.
115%       See ISPC and COMPUTER.
116if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
117    set(hObject,'BackgroundColor','white');
118end
119
120
121
122function edit_KEMH_Callback(hObject, eventdata, handles)
123% hObject    handle to edit_KEMH (see GCBO)
124% eventdata  reserved - to be defined in a future version of MATLAB
125% handles    structure with handles and user data (see GUIDATA)
126
127% Hints: get(hObject,'String') returns contents of edit_KEMH as text
128%        str2double(get(hObject,'String')) returns contents of edit_KEMH as a double
129
130handles.thetax = str2double(get(hObject,'String'))*1e-6; % rad
131% Update handles structure
132guidata(hObject, handles);
133pushbutton_plot_Callback(handles.pushbutton_plot, eventdata, handles)
134
135% --- Executes during object creation, after setting all properties.
136function edit_KEMH_CreateFcn(hObject, eventdata, handles)
137% hObject    handle to edit_KEMH (see GCBO)
138% eventdata  reserved - to be defined in a future version of MATLAB
139% handles    empty - handles not created until after all CreateFcns called
140
141% Hint: edit controls usually have a white background on Windows.
142%       See ISPC and COMPUTER.
143if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
144    set(hObject,'BackgroundColor','white');
145end
146
147
148% --- Executes on button press in pushbutton_init.
149function pushbutton_init_Callback(hObject, eventdata, handles)
150% hObject    handle to pushbutton_init (see GCBO)
151% eventdata  reserved - to be defined in a future version of MATLAB
152% handles    structure with handles and user data (see GUIDATA)
153lat_2020_3170_pseudo1
154
155
156% --- Executes on button press in pushbutton_plot.
157function pushbutton_plot_Callback(hObject, eventdata, handles)
158% hObject    handle to pushbutton_plot (see GCBO)
159% eventdata  reserved - to be defined in a future version of MATLAB
160% handles    structure with handles and user data (see GUIDATA)
161
162global THERING
163handles.Turns = get(handles.popupmenu_Nturn ,'Value');
164L = 13.4165; %m Position for point source on diaphragme
165
166if strcmp(get(get(handles.uipanel_plane, 'SelectedObject'), 'Tag'), 'radiobutton_Hplane')
167    hplane = 1;
168else
169    hplane = 0;
170end
171
172if hplane % if KEMH
173    % construct Line for transport from KEMH to end of the ring
174    REFPTS= (handles.ATIndexList.KEMH:length(THERING));
175    LINE = THERING(REFPTS);
176    % transport
177    Rin = [0; handles.thetax; 0; 0; 0; 0];
178    Rout = linepass(LINE,Rin,1:(length(LINE)+1));
179    % now make n turns
180    [x, ATIndex, LostBeam] = getturns(Rout(:,end), handles.Turns, 'All');
181    % construct turn 1
182    htour1 =  [zeros(6,handles.ATIndexList.KEMH-1), Rout(:,:)]*1e3;
183    % purpose ?
184    vtour0 =  [zeros(6,handles.ATIndexList.KEMH-1), Rout(:,:)]*1e3;
185    vtour1(:,:) =  x(:,1,:)*1e3;vtour1 = vtour1';
186    z = x;
187else % KEMV activated
188    Rin = [0;0;0;handles.thetaz;0; 0];
189    LINE = THERING(handles.ATIndexList.KEMV:end);
190    % transport the beam from KEMV to end of RING
191    Rout = LINEPASS(LINE,Rin,1:(length(LINE)+1));
192    % now make n turn by transporting the beam
193    [z, ATIndex, LostBeam] = getturns(Rout(:,end), handles.Turns, 'All');
194    vtour0 =  [zeros(6,handles.ATIndexList.KEMV-1), Rout(:,:)]*1e3;
195    vtour1(:,:) =  z(:,1,:)*1e3;vtour1 = vtour1';
196    htour1(:,:) =  z(:,1,:)*1e3;htour1 = htour1';
197    x = z;
198end
199
200%select low axes
201axes(handles.axes1);cla;
202
203% get position for all points
204spos = findspos(THERING, 1:(length(THERING)+1));
205sposBPM = getspos('BPMx');
206
207if hplane
208    plot(spos, htour1(1,:),'b-'); hold on
209    % SOURCE POINT
210    xTEMPO = htour1(1,handles.ATIndexList.TEMPO);
211    xpTEMPO = htour1(2,handles.ATIndexList.TEMPO);
212    LxTEMPO = xTEMPO+L*xpTEMPO; % at L meters
213else
214    plot(spos, vtour0(1,:),'b-'); hold on
215end
216slegend={'#1'};
217if handles.Turns > 1
218    plot(spos, x(:,1,1)*1e3,'r');
219    xTEMPO  = x(handles.ATIndexList.TEMPO,handles.Turns-1, 1)*1e3;
220    xpTEMPO = x(handles.ATIndexList.TEMPO,handles.Turns-1, 2)*1e3;
221    LxTEMPO  = xTEMPO+L*xpTEMPO;
222    slegend=[slegend, {'#2'}];
223    if handles.Turns > 2
224        plot(spos, x(:,2,1)*1e3,'g');
225        slegend=[slegend, {'#3'}];
226        if handles.Turns > 3
227            plot(spos, x(:,3,1)*1e3,'c');
228            slegend=[slegend, {'#4'}];
229            if handles.Turns > 4
230                plot(spos, x(:,4,1)*1e3,'k');
231                slegend=[slegend, {'#5'}];
232            end
233        end
234    end
235end
236legend(slegend)
237% Replot BPM position for turn 1
238plot(sposBPM, htour1(1,family2atindex('BPMx')),'b.');
239
240% plot positions of kickers
241plot(spos(handles.ATIndexList.KEMH), 0, 'ks'); hold on;
242plot(spos(handles.ATIndexList.KEMV), 0, 'rs');
243
244xlabel('s-position (m)')
245ylabel('x-position (mm)')
246xlim([0 getcircumference])
247% Show position of point TEMPO source
248plot(repmat(findspos(THERING, handles.ATIndexList.TEMPO), 2,1), ...
249    1.1*[-1 1]*max(x(:,1,1)*1e3),'k');
250
251% compute position at BPM and point sources
252%BPMspos = getspos('BPMx', [8 1; 8 2]);
253%diff(BPMspos)
254%xTempo = x(:,1,1);
255
256% Position first time the beam cross TEMPO BL
257fprintf('Turn %d Center SDM08 x = %.3f mm x'' = %.3f mrad  x @ 10m = %.3f mm\n', ...
258    handles.Turns, xTEMPO,xpTEMPO, LxTEMPO);
259fprintf('Center SDM08 z = %.3f mm z'' = %.3f mrad z @ 10m = %.3f mm\n',...
260    htour1(3,handles.ATIndexList.TEMPO),htour1(4,handles.ATIndexList.TEMPO), ...
261    htour1(3,handles.ATIndexList.TEMPO)+L*htour1(4,handles.ATIndexList.TEMPO));
262
263%ylim([-2 2])
264
265% second axis
266axes(handles.axes2);cla;
267plot(spos, vtour0(3,:)); hold on
268if handles.Turns > 1
269    plot(spos, z(:,1,3)*1e3,'r');
270    if handles.Turns > 2
271        plot(spos, z(:,2,3)*1e3,'g');
272        if handles.Turns > 3
273            plot(spos, z(:,3,3)*1e3,'c');
274            if handles.Turns > 4
275                plot(spos, z(:,4,3)*1e3,'k');
276            end
277        end
278    end
279end
280
281% Compute position at BPM and poitn source first time the beam cross TEMPO
282fprintf('Center SDM08 x = %.3f mm x'' = %.3f mrad\n  x @ 10m = %.3f mm\n', ...
283    htour1(1,handles.ATIndexList.TEMPO),htour1(2,handles.ATIndexList.TEMPO), ...
284    htour1(1,handles.ATIndexList.TEMPO)+L*htour1(2,handles.ATIndexList.TEMPO));
285set(handles.text_xTEMPO10m, 'String',...
286    num2str(LxTEMPO));
287
288fprintf('Center SDM08 z = %.3f mm z'' = %.3f mrad\n z @ 10m = %.3f mm\n',...
289    htour1(3,handles.ATIndexList.TEMPO),htour1(4,handles.ATIndexList.TEMPO), ...
290    htour1(3,handles.ATIndexList.TEMPO)+L*htour1(4,handles.ATIndexList.TEMPO));
291legend(slegend)
292xlabel('s-position (m)')
293ylabel('z-position (mm)')
294xlim([0 getcircumference])
295% plot if 2 turn at least
296if size(z,2) > 1
297    plot(repmat(findspos(THERING, handles.ATIndexList.TEMPO), 2,1), ...
298    1.1*[-1 1]*max(z(:,2,3)*1e3),'k');
299end
300%ylim([-2 2])
301
302BPMid = dev2elem('BPMx', [8 1; 8 2]);
303
304set(handles.text_BPM8_1_hposition,'String',num2str(htour1(1,handles.ATIndexList.BPM(BPMid(1)))))
305set(handles.text_BPM8_1_vposition,'String',num2str(vtour1(3,handles.ATIndexList.BPM(BPMid(1)))))
306set(handles.text_BPM8_2_hposition,'String',num2str(htour1(1,handles.ATIndexList.BPM(BPMid(2)))))
307set(handles.text_BPM8_2_vposition,'String',num2str(vtour1(3,handles.ATIndexList.BPM(BPMid(2)))))
308
309set(handles.text_BPM8_1_hangle,'String',num2str(htour1(2,handles.ATIndexList.BPM(BPMid(1)))))
310set(handles.text_BPM8_1_vangle,'String',num2str(vtour1(4,handles.ATIndexList.BPM(BPMid(1)))))
311set(handles.text_BPM8_2_hangle,'String',num2str(htour1(2,handles.ATIndexList.BPM(BPMid(2)))))
312set(handles.text_BPM8_2_vangle,'String',num2str(vtour1(4,handles.ATIndexList.BPM(BPMid(2)))))
313
314% Source point
315set(handles.text_TEMPO_hposition,'String',num2str(htour1(1,handles.ATIndexList.TEMPO)))
316set(handles.text_TEMPO_vposition,'String',num2str(vtour1(3,handles.ATIndexList.TEMPO)))
317set(handles.text_TEMPO_hangle,'String',num2str(htour1(2,handles.ATIndexList.TEMPO)))
318set(handles.text_TEMPO_vangle,'String',num2str(vtour1(4,handles.ATIndexList.TEMPO)))
319
320% Invariant
321x  = htour1(1,handles.ATIndexList.TEMPO) *1e-3;
322xp = htour1(2,handles.ATIndexList.TEMPO) *1e-3;
323A = handles.gammaT*x*x+2*handles.alphaT*x*xp+handles.betaT*xp*xp;
324set(handles.text_TEMPO_xmax,'String',num2str(sqrt(A/handles.gammaT)*1e3));
325
326% --- Executes on selection change in popupmenu_Nturn.
327function popupmenu_Nturn_Callback(hObject, eventdata, handles)
328% hObject    handle to popupmenu_Nturn (see GCBO)
329% eventdata  reserved - to be defined in a future version of MATLAB
330% handles    structure with handles and user data (see GUIDATA)
331
332% Hints: contents = get(hObject,'String') returns popupmenu_Nturn contents as cell array
333%        contents{get(hObject,'Value')} returns selected item from popupmenu_Nturn
334pushbutton_plot_Callback(handles.pushbutton_plot, eventdata, handles)
335
336
337% --- Executes during object creation, after setting all properties.
338function popupmenu_Nturn_CreateFcn(hObject, eventdata, handles)
339% hObject    handle to popupmenu_Nturn (see GCBO)
340% eventdata  reserved - to be defined in a future version of MATLAB
341% handles    empty - handles not created until after all CreateFcns called
342
343% Hint: popupmenu controls usually have a white background on Windows.
344%       See ISPC and COMPUTER.
345if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
346    set(hObject,'BackgroundColor','white');
347end
348
349
350% --- Executes on button press in radiobutton_zoom1.
351function radiobutton_zoom1_Callback(hObject, eventdata, handles)
352% hObject    handle to radiobutton_zoom1 (see GCBO)
353% eventdata  reserved - to be defined in a future version of MATLAB
354% handles    structure with handles and user data (see GUIDATA)
355
356% Hint: get(hObject,'Value') returns toggle state of radiobutton_zoom1
357if get(hObject,'Value')
358    dragzoom(handles.axes1)
359else
360    dragzoom(handles.axes1)
361end
362
363% --- Executes on button press in radiobutton_zoom2.
364function radiobutton_zoom2_Callback(hObject, eventdata, handles)
365% hObject    handle to radiobutton_zoom2 (see GCBO)
366% eventdata  reserved - to be defined in a future version of MATLAB
367% handles    structure with handles and user data (see GUIDATA)
368
369% Hint: get(hObject,'Value') returns toggle state of radiobutton_zoom2
370
371if get(hObject,'Value')
372    dragzoom(handles.axes2)
373else
374    dragzoom(handles.axes2)
375end
376
377
378% --- Executes on button press in pushbutton_SaveHCOR.
379function pushbutton_SaveHCOR_Callback(hObject, eventdata, handles)
380% hObject    handle to pushbutton_SaveHCOR (see GCBO)
381% eventdata  reserved - to be defined in a future version of MATLAB
382% handles    structure with handles and user data (see GUIDATA)
383
384handles.HCOR = getsp('HCOR', 'Model');
385
386% Update handles structure
387guidata(hObject, handles);
388
389% --- Executes on button press in pushbutton_Restore.
390function pushbutton_Restore_Callback(hObject, eventdata, handles)
391% hObject    handle to pushbutton_Restore (see GCBO)
392% eventdata  reserved - to be defined in a future version of MATLAB
393% handles    structure with handles and user data (see GUIDATA)
394
395setsp('HCOR', handles.HCOR, 'Model');
396pushbutton_plot_Callback(handles.pushbutton_plot, eventdata, handles)
397
398function edit_angle_Callback(hObject, eventdata, handles)
399% hObject    handle to edit_angle (see GCBO)
400% eventdata  reserved - to be defined in a future version of MATLAB
401% handles    structure with handles and user data (see GUIDATA)
402
403% Hints: get(hObject,'String') returns contents of edit_angle as text
404%        str2double(get(hObject,'String')) returns contents of edit_angle as a double
405angle = str2double(get(hObject,'String'));
406
407% 2 BPMs for TEMPO BL
408BPMspos = getspos('BPMx', [8 1; 8 2]);
409
410setorbitbump('BPMx', [8 1; 8 2], [0 diff(BPMspos)*angle],'HCOR', [-2 -1 1 2], 'Model')
411pushbutton_plot_Callback(handles.pushbutton_plot, eventdata, handles)
Note: See TracBrowser for help on using the repository browser.