Commit 8f22759b authored by Simone Liuzzo's avatar Simone Liuzzo
Browse files

merge

parents b81f3937 f0358734
function [ErrorsH, ErrorsV] = CheckPolArrayQuads(obj,indexes)
%CHECKPOLARRAYQuads Check the polarity of many quadrupoles
%
%
% see also: CheckPolarityOneQuad
ErrorsH=nan(size(indexes));
ErrorsV=nan(size(indexes));
for ii=1:length(indexes)
pause(2);
ErrorsH(ii)=obj.CheckPolOneQuad(indexes(ii),'H');
pause(2);
ErrorsV(ii)=obj.CheckPolOneQuad(indexes(ii),'V');
disp(['~~~~~~~~~~~ Quadrupole ' num2str(indexes(ii)) ': '])
disp(['H error = ' num2str(ErrorsH(ii)*100) '%, V error = ' num2str(ErrorsV(ii)*100) '%']);
disp('~~~~~~~~~~~')
end
figure;
plot(indexes,ErrorsH*100,'-*','DisplayName','Horizontal')
hold on; grid on;
plot(indexes,ErrorsV*100,'-*','DisplayName','Vertical')
xlabel('steerer number');
ylabel('Focusing error (%)')
legend('Location','NorthEast')
end
function Error = CheckPolOneQuad(obj,index,plane)
%CHECKPOLONEQUAD Checks polarity of a single quadrupole
% Detailed explanation goes here
% see also: CheckPolArrayQuads
sQuad=obj.sQuad(index);
indbpmafter=find(obj.sBPM>(sQuad+0),1,'first');
indHstbefore=find(obj.sHst<(sQuad-0),1,'last');
indVstbefore=find(obj.sVst<(sQuad-0),1,'last');
kicks= linspace(-obj.kickmax,obj.kickmax,obj.numkicksperquad);
x1=zeros(size(kicks));
x2=zeros(size(kicks));
% y1=zeros(size(kicks));
% y2=zeros(size(kicks));
% Simulation
for ii=1:length(kicks)
if plane=='H'
traj=obj.SimulateTrajectoryKick(indHstbefore,kicks(ii),plane);
else
traj=obj.SimulateTrajectoryKick(indVstbefore,kicks(ii),plane);
end
if plane=='H'
x1(ii)=traj(1,indbpmafter);
x2(ii)=traj(1,indbpmafter+1);
else
x1(ii)=traj(2,indbpmafter);
x2(ii)=traj(2,indbpmafter+1);
end
end
% Measurement
if plane=='H'
v_zero=obj.getHSteerersValues();
else
v_zero=obj.getVSteerersValues();
end
% v=v_zero;
traj0=obj.measuretrajectory();
for ii=1:length(kicks)
v=v_zero;
if plane=='H'
v(indHstbefore)=v(indHstbefore)+kicks(ii);
obj.setHSteerersValues(v);
else
v(indVstbefore)=v(indVstbefore)+kicks(ii);
obj.setVSteerersValues(v);
end
pause(2)
traj=obj.measuretrajectory()-traj0;
if plane == 'H'
x1_m(ii)=traj(1,indbpmafter);
x2_m(ii)=traj(1,indbpmafter+1);
else
x1_m(ii)=traj(2,indbpmafter);
x2_m(ii)=traj(2,indbpmafter+1);
end
end
if plane=='H'
obj.setHSteerersValues(v_zero);
else
obj.setVSteerersValues(v_zero);
end
[fit_s1,gf_s1]=fit(kicks',x1','poly1');
[fit_s2,gf_s2]=fit(kicks',x2','poly1');
[fit_m1,gf_m1]=fit(kicks',x1_m','poly1');
[fit_m2,gf_m2]=fit(kicks',x2_m','poly1');
if obj.plot
figure;
hold on; grid on;
p1=plot(kicks,x1,'.','MarkerSize',10,'DisplayName','Simu first BPM');
pf1=plot(fit_s1);pf1.Color=p1.Color;
p2=plot(kicks,x2,'.','MarkerSize',10,'DisplayName','Simu second BPM');
pf2=plot(fit_s2);pf2.Color=p2.Color;
p3=plot(kicks,x1_m,'.','MarkerSize',10,'DisplayName','Meas first BPM');
pf3=plot(fit_m1);pf3.Color=p3.Color;
p4=plot(kicks,x2_m,'.','MarkerSize',10,'DisplayName','Meas second BPM');
pf4=plot(fit_m2);pf4.Color=p4.Color;
legend([p1 p2 p3 p4],'Location','NorthEast');
xlabel(['Kick at ' plane ' steerer before Quad number ' num2str(index)])
ylabel([plane ' position BPMs'])
end
Error=sqrt(((fit_m1.p1-fit_s1.p1)/fit_s1.p1)^2 + ((fit_m2.p1-fit_s2.p1)/fit_s2.p1)^2);
disp(['Focalization error for quad n. ' num2str(index) ' in ' plane ' plane is: ' num2str(100*Error) ' %']);
end
classdef QuadPolarity < RingControl
%QuadPolarity is a Class to check if the quads have the good polarity.
%
% The class can be used in the esrf-sr, esrf-sy or ebs-simu
%
% Example on how to use it:
% ...
%
% see also: RingControl, SteerersPolarity
properties
plot;
sBPM;
sHst;
sVst;
sQuad;
kickmax;
numkicksperquad;
end
methods
function obj = QuadPolarity(machine)
%QUADPOLARITY Construct an instance of the class
%QuadPolarity
%
% QP=QuadPolarity(machine)
% machine can be: 'ebs-simu', 'esrf-sr', 'esrf-sy'
%
% see also: RingControl
% call the construct of RingControl
obj@RingControl(machine);
% put the default values in the properties
obj.plot=true;
%obj.kick_rad=1e-4;
%obj.nbpm_after=4;
% find s positions of BPMs and steerers
obj.sBPM=findspos(obj.rmodel,obj.indBPM);
obj.sHst=findspos(obj.rmodel,obj.indHst);
obj.sVst=findspos(obj.rmodel,obj.indVst);
obj.sQuad=findspos(obj.rmodel,obj.indQuad);
obj.kickmax=5e-5; %rad
obj.numkicksperquad=4;
end
%this function checks the polarity a single quadrupole
Error=CheckPolOneQuad(obj,index,plane);
%this function checks the polarity of an array of quadrupoles
Errors=CheckPolArrayQuads(obj,indexes);
end
end
......@@ -9,16 +9,14 @@ classdef SteerersPolarity < RingControl
% 2. create a "SteerersPolarity" object
% SP=SteerersPolarity('ebs-simu') or
% SP=SteerersPolarity('esrf-sr')
% 3. decide the plane of steerers you want to check
% SP.ChangePlane('H') for horizontal (default) or
% SP.ChangePlane('V') for vertical
% 4. check the polarity of a single steerer
% error=SP.CheckPolOneSteerer(number), where number is the
% 3. check the polarity of a single steerer
% error=SP.CheckPolOneSteerer(number,'H') or
% error=SP.CheckPolOneSteerer(number,'V'), where number is the
% steerer number and error is the error in trajectory on the next
% 'obj.nbpm_after' bpms after a kick of 'obj.kick_rad' radians
% if |error|<~0.5 then you don't have sign problems
% A sign error in a steerer should give error~-2
% 5. check the polarity of many steerers
% 4. check the polarity of many steerers
% errors=SP.CheckPolArraySteerers([10 12 15 25 30]) checks the
% polarity of the steerers of the list you pass
%
......
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