Commit 63417cad authored by perron's avatar perron

change in fun_tom

parent 7f761187
function [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. The tune is
%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
%created by CV9 for the vertical plane.
%the outputs are the TUNES, CURRENT and POSITIONS measured on the first
%turn.
%%
ithresh=1E5;
ithresh=0.5E7
incs3=25
inccv9=0.4
%opens conection to the gun, and KE
Ke=tango.Device('sy/ps-ke/1');
gun=tango.Device('elin/tw-gun/0');
srall=tango.Device('sr/d-bpmlibera/all');
%%%%Ke=tango.Device('sy/ps-ke/1');
gun=tango.Device('elin/beam/run');
srall=tango.Device('srdiag/beam-position/all');
disable=srall.All_Status();
ramp=tango.Device('sy/ps-rips/manager')
bpmok=~bitand(disable.read,2);
bpmok=[bpmok bpmok bpmok bpmok bpmok];
%%%ramp=tango.Device('sy/ps-rips/manager');
%reads faulty BPM.
ramp.StartRamping()
bpmok=~bitand(disable.read,2);
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();
for i=1:average
res=gun.on();
res=Ke.On();
%res=Ke.On();
pause(2)
......@@ -30,38 +37,48 @@ pause(2);
xx=xx';
zz=zz';
intens=intens';
figure(4)
plot(intens(:));
posxtest(i,:)=xx(:);
posztest(i,:)=zz(:);
whos
curtest(i,:)=intens(:);
end
pause(3);
%adapts BPMOK mask to cope with beam presence.
bpmok=bpmok(1:numbpm)&intens(1:numbpm)>ithresh;
bpmok
%averages the tbt data sets to extract h,v postion and intensity
posm(:,1)=mean2(posxtest(:,1:numbpm),1)';
posm(:,2)=mean2(posztest(:,1:numbpm),1)';
cur=mean2(curtest(:,1:numbpm))';
traj=posm;
traj(:,~bpmok(1:numbpm))=nan;
%if tune flag is turned on takes dataw ith increases TL2/CV9 and S3
posm(:,1)=mean2(posxtest(:,1:numbpm),1)';
posm(:,2)=mean2(posztest(:,1:numbpm),1)';
cur=mean2(curtest(:,1:numbpm),1)';
traj=posm;
traj(~bpmok(1:numbpm),:)=nan;
cur(~bpmok(1:numbpm))=nan;
%if tune flag is turned on takes data with increases TL2/CV9 and S3
%data recording for vetical analysis increasing CV9 averaged over AVERAGE samples
if flagtune==1
CV=tango.Attribute('tl2/ps-c1/cv9/current');
cvini=CV.read
CV.set=cvini(1)+0.3;
CV=tango.Attribute('tl2/ps-c1/cv9/current');
cvini=CV.set;
CV.set=cvini(1)+inccv9;
for i=1:average
res=Ke.On();
pause(2)
[xx,zz,intens(i)]=loadposlib(20);
zz=zz';
intens=intens';
posz(i,:)=zz(1:numbpm);
intensv(i,:)=zz(1:numbpm);
pause(3)
[xx3,zz3,intens3]=loadposlib(20);
zz3=zz3';
intens3=intens3';
posz(i,:)=zz3(1:numbpm);
intensv(i,:)=intens3(1:numbpm);
end
poszp=mean2(posz,1)';
......@@ -70,61 +87,99 @@ pause(2);
%prepares for Horizontal data sets measurements (again averaged
%AVERAGE times)
S3=tango.Attribute('sr/ps-si/3/Current')
S3ini=S3.read;
S3.set=S3ini+10;
%%%S3=tango.Attribute('sr/ps-si/3/Current')
%%%S3ini=S3.set;
%%% S3.set=S3ini+incs3;
%Data taking
for i=1:average
res=Ke.On();
pause(2)
[xx,zz,intens]=loadposlib(20);
xx=xx';
intens=intens';
posx(i,:)=xx(1:numbpm);
intensh(i,:)=intens(1:numbpm);
[xx2,zz2,intens2]=loadposlib(20);
xx2=xx2';
intens2=intens2';
posx(i,:)=xx2(1:numbpm);
intensh(i,:)=intens2(1:numbpm);
end
posxp(:,1)=mean2(posx,1)';
bpmnok=isnull(sum([intensh>itresh;intensv>itresh;curtest>itresh],2)==(3*size(intensh,2)));
bpmnok=0==(sum([intensh>ithresh;intensv>ithresh;bpmok(1:numbpm)],1)==((2*average+1)*ones(1,size(intensh,2))));
%Stops the gun and reloads S3 inital value
S3.set=S3ini;
pause(2);
%%%S3.set=S3ini;
%computes h and v trajectory by substracting initial data in order to
%extract betatron oscillations.
whos
traj=([posxp-posm(:,1) poszp-posm(:,2)]);
%computes h and v trajectory by substracting initial data in order to
%extract betatron oscillations.
traj=([posxp-posm(:,1) poszp-posm(:,2)]);
bpmok(bpmnok)=0
traj(~bpmok,:)=nan;
% extracts the tunes
bpmok(bpmnok)=0;
traj(~bpmok,:)=nan;
% extracts the tunes via fft
tunes=findtunetom2(traj(:,:),200,1);
tunes=tunes*(224);
%extract the tunes via fit of model
m=sr.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);
orb=linepass(mach,[co4 0 0]',bpm);
figure(3)
plot([traj(1:224,:) 1E3*orb(1:2:3,:)']);
grid on;
legend('meas or h','meas or v','fit or h','fit or v');
figure(4);
atplot(mach);
end
ramp.StopRamping();
pause(2);
gun.off();
gun.Off();
%Ploting result
figure(1)
subplot(3,1,1);
plot(cur);
ylabel('intensity');
grid on;
subplot(3,1,2);
plot(traj(:,1));
ylabel('H trajectory (microm)');
grid on;
subplot(3,1,3);
plot(traj(:,2));
ylabel('V trajectory (microm)');
xlabel('bpm');
grid on;
figure(2)
t2=~isfinite(traj);
t3=traj;
t3(t2)=0;
subplot(2,1,1)
plot(abs(fft(t3(:,1))));
legend('hfft');
grid on;
subplot(2,1,2)
plot(abs(fft(t3(:,2))));
legend('vfft');
grid on;
tunes=tunes;
......@@ -140,12 +195,40 @@ xlabel('bpm');
intens=load_sumdd();
vx0=cat(3,vx0h,vx0v);
[xx]=preparevvtom(vx0(18:nbturns+18-1,:,1));
[zz]=preparevvtom(vx0(18:nbturns+18-1,:,2));
intens=intens(18:end,:);
[xx]=preparevvtom(vx0(7:nbturns+7-1,:,1));
[zz]=preparevvtom(vx0(7:nbturns+7-1,:,2));
intens=intens(7:end,:);
end
function [oscill]=preparevvtom(vx0)
oscill=vx0
oscill=vx0;
aver=mean2(vx0(:,:));
%oscill=NaN(size(vx0));
%[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');
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,:)';
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');
%%orb=linepass(mach,orini,bpm);
%%orb=orb(1:2,:)';
%%res=std2(orb-or);
%% end
end
......@@ -25,8 +25,11 @@ syall.TDP_AMPL_Enable=true;
disable=syall.GetBPMStatus();
syall.SignalProcessing=int16(0);
gun=tango.Device('elin/beam/run');
res=gun.On();
ramp=tango.Device('sy/ps-rips/manager');
ramp.On();
res=gun.On();
for i=1:numel(disable);
dis(i)=size(disable{i},2)>10;
......@@ -103,5 +106,6 @@ syall.TDP_QSUM_Enable=false;
clock.ClockDelay=delayini.read;
res=gun.Off();
ramp.Off();
gun.dvclose;
syall.dvclose;
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