Commit 91572776 authored by Thomas Perron's avatar Thomas Perron

updated name of magnets for tune fit

parent 6c66356f
function res=fittune_traj(x,bpm,mach,or)
qd6=findcells(mach,'FamName','QD6');
qf7=findcells(mach,'FamName','QF7');
cini=[x(1:4)';0;0]
mach=setcellstruct(mach,'PolynomB',qd6,[x(5)],1,2);
mach=setcellstruct(mach,'PolynomB',qf7,[x(6)],1,2);
function res=fittune_traj(x,bpm,mach,or,co4)
Qstrength=x
QD2=findcells(mach,'FamName','QD2\w*');
QF1=findcells(mach,'FamName','QF1\w*');
if nargin>4
cini=[co4';0;0];
mach=setcellstruct(mach,'PolynomB',QD2,[x(1)],1,2);
mach=setcellstruct(mach,'PolynomB',QF1,[x(2)],1,2);
else
cini=[x(1:4)';0;0];
mach=setcellstruct(mach,'PolynomB',QD2,[x(5)],1,2);
mach=setcellstruct(mach,'PolynomB',QF1,[x(6)],1,2);
end
orb=linepass(mach,cini,bpm);
orb=orb(1:2,:)';
orb=orb(1:2,1:numel(bpm))';
res=sum(std2(orb-or));
\ No newline at end of file
res=sum(std2(orb-or(1:numel(bpm),:)))
\ No newline at end of file
function [tunes,cur,posm]=ftcheck_sr(flagtune,average,numbpm)
%This function is making the actual measurement of the first turn
% [tunes,cur,posm]=ftcheck_sr(flagtune,average,numbpm)
%This function is making the actual measurement of the first turn
%trajectory. If asked for (FLAGTUNE==1) then it will also compute the
%tune on the trajectory measured ion the NUMBPM first BPM's (max=1000). The tune is
%measured on the horizontal injection oscillation and on the oscillation
......@@ -7,26 +8,33 @@ function [tunes,cur,posm]=ftcheck_sr(flagtune,average,numbpm)
%the outputs are the TUNES, CURRENT and POSITIONS measured on the first
%turn.
%%
ithresh=0.5E7
incs3=25
inccv9=0.4
ithresh=0
incs3=5
inccv9=0.02
%opens conection to the gun, and KE
%%%%Ke=tango.Device('sy/ps-ke/1');
gun=tango.Device('elin/beam/run');
%%%%%%gun=tango.Device('elin/beam/run');
srall=tango.Device('srdiag/beam-position/all');
disable=srall.All_Status();
if srall.TBT_Enable.read==false
fprintf('error bpms are not in TBT mode, switch to TBT or go home')
end
%%%ramp=tango.Device('sy/ps-rips/manager');
%reads faulty BPM.
bpmok=~bitand(disable.read,2);
bpmok(80)=0;
%%%bpmok(80)=0;
bpmok=[bpmok bpmok bpmok bpmok bpmok];
tunes=[0 0];
%%%ramp.StartRamping();
pause(2);
%starts a loop to measure turn by turn data AVERAGE times
res=gun.On();
%%%%%%%%res=gun.On();
for i=1:average
%res=Ke.On();
......@@ -68,22 +76,22 @@ traj=posm;
CV=tango.Attribute('tl2/ps-c1/cv9/current');
cvini=CV.set;
CV.set=cvini(1)+inccv9;
for i=1:average
res=Ke.On();
pause(3)
[xx3,zz3,intens3]=loadposlib(20);
%%%%%% CV=tango.Attribute('tl2/ps-c1/cv9/current');
%%%% cvini=CV.set;
%%%%% CV.set=cvini(1)+inccv9;
for i=1:average
%%%%% res=Ke.On();
%%%%% pause(3)
[xx3,zz3,intens3]=loadposlib(20);
zz3=zz3';
intens3=intens3';
posz(i,:)=zz3(1:numbpm);
posz(i,:)=zz3(1:numbpm);
intensv(i,:)=intens3(1:numbpm);
end
poszp=mean2(posz,1)';
% sets back CV9 to initial value
CV.set=cvini;
%%%%% CV.set=cvini;
%prepares for Horizontal data sets measurements (again averaged
%AVERAGE times)
......@@ -93,7 +101,7 @@ traj=posm;
%Data taking
for i=1:average
res=Ke.On();
%%%%%%res=Ke.On();
pause(2)
[xx2,zz2,intens2]=loadposlib(20);
xx2=xx2';
......@@ -117,8 +125,8 @@ traj=posm;
%computes h and v trajectory by substracting initial data in order to
%extract betatron oscillations.
traj=([posxp-posm(:,1) poszp-posm(:,2)]);
%%%%%%traj=([posxp-posm(:,1) poszp-posm(:,2)]);
traj=([posxp poszp]);
bpmok(bpmnok)=0;
......@@ -126,30 +134,35 @@ traj=posm;
% extracts the tunes via fft
tunes=findtunetom2(traj(:,:),200,1);
tunes=tunes*(224);
tunes=tunes*319;
%extract the tunes via fit of model
m=sr.model;
m=ebs.model;
mach=m.ring;
bpm=findcells(mach,'FamName','BPM');
x0=[-0.8211 0.6820];
co4=[0 -incs3*3E-6 (0.5E-3/0.8)*inccv9 +inccv9*161E-6];
re=fittune(x0,bpm,mach,traj(1:224,:),co4)
[xr,res]=fminsearch(@(x) fittune(x,bpm,mach,traj(1:224,:),co4),x0);
mach=setcellstruct(mach,'PolynomB',qd6,[xr(1)],1,2);
mach=setcellstruct(mach,'PolynomB',qf7,[xr(2)],1,2);
%%%bpm=findcells(mach,'FamName','BPM');
bpm=m.get(0,'BPM');
x0=[-2.704 4.459];
co4=[-0.22E-3 -0.11E-3 -0.45E-3 0.06E-3];
re=fittune_traj(x0,bpm(1:numbpm),mach,traj(1:numbpm,:),co4);
[xr,res]=fminsearch(@(x) fittune_traj(x,bpm(1:numbpm),mach,traj(1:numbpm,:),co4),x0);
QF1=findcells(mach,'FamName','QF1\w*');
QD2=findcells(mach,'FamName','QD2\w*');
mach=setcellstruct(mach,'PolynomB',QD2,[xr(1)],1,2);
mach=setcellstruct(mach,'PolynomB',QF1,[xr(2)],1,2);
orb=linepass(mach,[co4 0 0]',bpm);
figure(3)
plot([traj(1:224,:) 1E3*orb(1:2:3,:)']);
plot([traj(1:numbpm,:) orb(1:2:3,1:numbpm)']);
grid on;
legend('meas or h','meas or v','fit or h','fit or v');
figure(4);
atplot(mach);
pause(2)
atplot(mach);
end
ramp.StopRamping();
gun.Off();
%%%%ramp.StopRamping();
%%%%%gun.Off();
%Ploting result
figure(1)
subplot(3,1,1);
......@@ -179,7 +192,7 @@ subplot(2,1,2)
plot(abs(fft(t3(:,2))));
legend('vfft');
grid on;
tunes=tunes;
......@@ -206,25 +219,25 @@ intens=intens(7:end,:);
%[oscill(:,:),aver]=mtclean(vx0(:,:),mean2(vx0(:,:)),[]);
end
function res=fittune(y,bpm,mach,traj,co4)
y=y
qd6=findcells(mach,'FamName','QD6');
qf7=findcells(mach,'FamName','QF7');
%%% function res=fittune(y,bpm,mach,traj,co4)
%%% QD5D=findcells(mach,'FamName','QD5D');
%%% QF6D=findcells(mach,'FamName','QF6D');
cini=[co4';0;0]
mach=setcellstruct(mach,'PolynomB',qd6,[y(1)],1,2);
mach=setcellstruct(mach,'PolynomB',qf7,[y(2)],1,2);
orb=linepass(mach,cini,bpm);
orb=orb(1:2:3,:)';
%%%cini=[co4';0;0]
%%%mach=setcellstruct(mach,'PolynomB',QD5D,[y(1)],1,2);
%%%mach=setcellstruct(mach,'PolynomB',QF6D,[y(2)],1,2);
%%%orb=linepass(mach,cini,bpm);
%%%orb=orb(1:2:3,:)';
res=sum(std2(orb-traj*1E-3,1))
end
%%%res=sum(std2(orb-traj*1E-3,1))
%%%end
%
%% function res=fittune(x,bpm,mach,plane,or)
%%cini=[x(1:4)';0;0]
%%mach=atfittune([x(5) x(6)],'QD6','QF7');
%%mach=atfittune([x(5) x(6)],'QD5D','QF6D');
%%orb=linepass(mach,orini,bpm);
%%orb=orb(1:2,:)';
%%res=std2(orb-or);
......
......@@ -36,7 +36,7 @@ classdef search_obs
addpathtom;
cd(curdir);
obj.CUR=tango.Attribute('sr/d-ct/1/current');
obj.BLM=tango.Device('srdiag/beam-position/all');
%obj.BLM=tango.Device('srdiag/beam-position/all');
obj.ORBITH=tango.Attribute('srdiag/beam-position/all/SA_HPositions');
obj.ORBITV=tango.Attribute('srdiag/beam-position/all/SA_VPositions');
obj.LT=tango.Attribute('srdiag/beam-position/all/SA_HPositions_Peak');
......@@ -65,7 +65,7 @@ classdef search_obs
obj.INITSTRENGTH.v=obj.VSTRENGTH.set;
obj.HSTNAME=tango.Attribute('srmag/hst/all/CorrectorNames');
obj.VSTNAME=tango.Attribute('srmag/vst/all/CorrectorNames');
obj.BLM.read=1+mod([3:0.25:34.75],32);
end
......@@ -116,7 +116,7 @@ classdef search_obs
end
%converts bump name to BPM name
bump_name=bump_name([1 2 3 4 6 7]);
bpm_name=bump_name([1 2 3 4 6 7]);
......@@ -124,7 +124,7 @@ classdef search_obs
% finds in the lattice structure lists of bpm and corrector
%to be considered for the given bump.
ibpms=obj.MODEL.get(0,'BPM');
ibpm=findcells(obj.MODEL.ring,'Device',['srdiag/beam-position/' bump_name]);
ibpm=findcells(obj.MODEL.ring,'Device',['srdiag/beam-position/' bpm_name]);
numbpm=find(ibpm<=ibpms,1)
numcor=find(ibpm<icors,1);
% if numcor>numel(icors); numcor=1; end
......@@ -132,7 +132,8 @@ classdef search_obs
orb=zeros(numel(ibpms),1);
orb(numbpm)=amplitude;
bpmok=true(1,320);
bpmok([numbpm-3 numbpm-2 numbpm-1 numbpm+3 numbpm+2 numbpm+1])=false;
bpmok([numbpm-1 numbpm+1])=false;
%%%bpmok([numbpm-3 numbpm-2 numbpm-1 numbpm+3 numbpm+2 numbpm+1])=false;
orb(~bpmok)=nan;
numcor=mod(numcor-1,288)+1;
......@@ -140,7 +141,7 @@ classdef search_obs
%calculates the steerer strengths to be applied
[or_fit,err_exec]=calc_correction(numvect,resp(:,numcor),orb,0);
% checks if the steerer strength is resonable and if yes aplies it.
%checks if the steerer strength is resonable and if yes aplies it.
stit=zeros(288,1);
stit(numcor)=err_exec;
......@@ -151,12 +152,12 @@ classdef search_obs
size(st_strength.set(obj.s_ok))
stfin(obj.s_ok)=stit'+st_strength.set(obj.s_ok);
stfin(~obj.s_ok)=st_strength.set(~obj.s_ok);
stfin(obj.s_ok)
end
if sum(stfin>4.42E-4)>0
%fprintf('too strong steerers');
steernok=find(stfin>4.42E-4);
steernok=find(stfin>6E-4);
for i=1:numel(steernok)
error=['Strength send to corrector ' stname.read{steernok(i)} ' out of range (' num2str(1000*stfin(steernok(i))) 'mrad)']
......@@ -164,7 +165,9 @@ classdef search_obs
else
st_strength.set=stfin;
end
plot(stfin-st_strength.set);
end
......@@ -258,8 +261,7 @@ classdef search_obs
if numel(mark_shift)==64
mark_shift=mark_shift(2:2:end);
end
cells=mach(1:mark_shift(mod(cend-cini,32)));
iblm=sort([findcells(cells,'FamName','ID\w*') findcells(cells,'FamName','QF7') findcells(cells,'FamName','B1H') findcells(cells,'FamName','DL\w*A\w*_2') findcells(cells,'FamName','DL\w*E\w*_2')...
findcells(cells,'FamName','JL\w*_2') findcells(cells,'FamName','DL\w*D\w*_2')]);
......@@ -282,28 +284,92 @@ classdef search_obs
end
end
function res=obs_search(obj,cell,plane,amplitude)
for i=1:9
if numel(num2str(cell))==1;
cell_str=[num2str(0) num2str(cell)];
else
cell_str=[num2str(cell)];
end
figure(i);
if plane==1
bump_name=['c' cell_str 'h0' num2str(i)];
end
if plane==2
bump_name=['c' cell_str 'v0' num2str(i)];
end
end
[bumpini,bump_name]=mkbump(obj,bump_name,amplitude)
obj.plot_blm_cells(cell-1,cell+2);
hold on
obj.plot_orb_cells(cell-1,cell+2);
function [or_sh,or_sv,blmh,blmv]=resp_blm(obj,amplitude)
% [or_sh,or_sv,blmh,blmv]=resp_blm(obj,amplitude)
%measures the response of all BLMs to a steerer excitation. All
%third steerers of each cell are used in horizontal and vertical
%plane.
%AMPLITUDE is the strength to be aplied to the steerer
%OR_SH is the orbit response to horizontal steerers. 2d matrix of size numsteer*(2*numbpm).
%horizontal and vertical orbits resulting from one steerer are
%recorded in one single column.
%first 320 lines are the Horbit and following 320 lines are the
%vertical one.
%OR_SV same as OR_SH but reponse to a vertical steerer.
%BLMH reponse: steererh on BLM
%BLMV response: steererv on BLM
Iini=obj.CUR.read;
ref_blm=[obj.BLM.read']./Iini;
for i=1:8
I=obj.CUR.read;
fprintf(['cell' num2str(i) ', current=' num2str(I) 'mA.\n']);
if I<0.75*Iini
obj.reset_steer;
fprintf(['error, too much current lost, please reinject up to' num2str(Iini*1.1) 'mA']);
res=input('have you reinjected (y/n)','s');
if res~='y'
fprintf('error: current missing, measurement faled');
end
end
ncorv=(i-1)*36+3;
ncorh=(i-1)*48+3;
ic_ini=obj.VSTRENGTH.read(ncorv);
obj.VSTRENGTH.set(ncorv)=ic_ini+amplitude;
pause(5)
or_sv(:,i)=[obj.ORBITH.read';obj.ORBITV.read'];
blmv(:,i)=(([obj.BLM.read']./obj.CUR.read));
%%%%%-ref_blm);
obj.VSTRENGTH.set(ncorv)=ic_ini;
pause(5)
ic_ini=obj.HSTRENGTH.read(ncorh);
obj.HSTRENGTH.set(ncorh)=ic_ini+amplitude;
pause(5)
or_sh(:,i)=[obj.ORBITH.read';obj.ORBITV.read'];
blmh(:,i)=obj.BLM.read'./obj.CUR.read;
%%%%%ref_blm;
obj.HSTRENGTH.set(ncorh)=ic_ini;
pause(5)
end
bpmstatus=tango.Attribute('srdiag/beam-position/all/All_Status');
bpmok=~bitand(bpmstatus.read,128) | bitand(bpmstatus.read,2);
or_sv([~bpmok(:);~bpmok(:)],:)=nan;
or_sh([~bpmok(:);~bpmok(:)],:)=nan;
end
function [corelh,corelv]=blm_resp_corel(obj,or_sh,or_sv,blmh,blmv)
cells=obj.MODEL.ring;
iblm=sort([findcells(cells,'FamName','ID\w*') findcells(cells,'FamName','QF7') findcells(cells,'FamName','B1H') findcells(cells,'FamName','DL\w*A\w*_2') findcells(cells,'FamName','DL\w*E\w*_2')...
findcells(cells,'FamName','JL\w*_2') findcells(cells,'FamName','DL\w*D\w*_2')]);
ibpm=[findcells(cells,'Class','Monitor') findcells(cells,'FamName','BPM')];
whos
for i=1:320
iblm_loc=find(iblm>ibpm(i),4);
if numel(iblm_loc)<4
iblm_loc=sort([iblm_loc 1:4-numel(iblm_loc)]);
end
blmh_loc=blmh(iblm_loc,:);
blmv_loc=blmv(iblm_loc,:);
corelh(i)=mean2((or_sh(i,:)).*mean2(blmh_loc(1:4),2));
corelv(i)=mean2((or_sv(320+i,:)).*mean2(blmv_loc(1:4),2));
end
figure(5);
plot([corelh(:) corelv(:)]);
legend('hcorelation','vcorelation');
grid('on');
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment