Commit af2ebf7a authored by Thomas Perron's avatar Thomas Perron

Reinitialisation of fun-tom folder with updated functions

parent f652e0da
function res=fittune(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);
orb=linepass(mach,cini,bpm);
orb=orb(1:2,:)';
res=sum(std2(orb-or));
\ No newline at end of file
classdef search_obs
%export TANGO_HOST=ebs-simu:10000
% Detailed explanation goes here
properties
CUR
BUMPH
BUMPV
BLM
ORBITH
ORBITV
LT
RING
ATSTRUCT
end
methods
function obj = search_obs(machine)
%UNTITLED Construct an instance of this class
% Detailed explanation goes here
f=pwd;
cd /machfs/perron/matlab/programs;
addpathtom;
cd(f);
if strcmp(machine,'ebs')
!export TANGO_HOST=ebs-simu:10000
res=('ebs selected');
obj.CUR=tango.Attribute('sr/d-ct/1/current');
obj.BUMPH=tango.Device('sr/beam-bump/all-h');
obj.BUMPV=tango.Device('sr/beam-bump/all-v');
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');
obj.RING='ebs';
obj.ATSTRUCT=ebs.model;
elseif strcmp(machine,'esrf')
!export TANGO_HOST=orion:10000,orion:11000
obj.CUR=tango.Attribute('sr/d-ct/1/current');
obj.BUMPH='sr/bump-';
obj.BLM=tango.Attribute('sr/d-blm/all/Losses');
obj.ORBITH=tango.Attribute('sr/d-bpmlibera/all/X_position_DD');
obj.ORBITV=tango.Attribute('sr/d-bpmlibera/all/Z_position_DD');
obj.LT=tango.Attribute('sr/d-bpmlibera/lifetime/Lifetime');
obj.RING='esrf';
obj.ATSTRUCT=sr.model;
end
end
function [bumpini,bump_name]=mkbump(obj,bump_name,bump_amplitude)
%sets the bumps defined by BUMP_NAME (eg c02-h09) with the
%amplitude given by BUMP_AMPLITUDE (m)
amp=bump_amplitude;
[obj.BUMPH bump_name '/Amplitude']
bump=tango.Attribute([obj.BUMPH bump_name '/Amplitude']);
if abs(amp)>7E-4
res=('error bump amplitude too large');
else
bump.set=amp;
end
end
function plot_or_cells(obj,cini,cend,plane)
%Plots the orbit and the lattice structure between cell CINI
%and CEND. PLANE=1 refers to horizontal, PLANE=2 refers to
%vertical.
mach=obj.ATSTRUCT.ring;
mark=[findcells(mach,'FamName','ID\w*') sort([findcells(mach,'FamName','SDH\w*') findcells(mach,'FamName','SDL\w*')])]
if numel(mark)==64
mark=mark(2:2:end);
end
res=mach{mark(5)}
if plane==1
orb=obj.ORBITH.read;
elseif plane==2
orb=obj.ORBITV.read;
end
mach=circshift(mach,-mark(mod(cini-4,32)+1));
orb=circshift(reshape(orb,[],32)',-mod(cini-2,32)+1)';
orb=orb(:,[1:mod(cend-cini,32)]);
orb=orb(:);
mark_shift=[findcells(mach,'FamName','ID\w*') sort([findcells(mach,'FamName','SDH\w*') findcells(mach,'FamName','SDL\w*')])]
%mark_shift=sort([findcells(mach,'FamName','ID\w*')+2 findcells(mach,'FamName','DL\w*A\w*_2') findcells(mach,'FamName','DL\w*E\w*_2')...
% findcells(mach,'FamName','JL\w*_2') findcells(mach,'FamName','DL\w*D\w*_2')]);
if numel(mark_shift)==64
mark_shift=mark_shift(2:2:end);
end
cells=mach(1:mark_shift(mod(cend-cini,32)));
bpm=[findcells(cells,'Class','Monitor') findcells(cells,'FamName','BPM')];
figure(1);
clf(1);
atbaseplot(cells);
whos
if(numel(orb)==numel(bpm))
spos=findspos(cells,bpm);
hold on
yyaxis right;
%ylim([-2 2]);
plot(spos,orb(:)*1000);
legend(['orbit(mm) in cells: ' num2str([cini cend])])
hold off;
else
error='orbit length different from BPM numbers'
end
end
function plot_blm_cells(obj,cini,cend)
%Plots the orbit and the lattice structure between cell CINI
%and CEND. PLANE=1 refers to horizontal, PLANE=2 refers to
%vertical.
mach=obj.ATSTRUCT.ring;
mark=[findcells(mach,'FamName','ID\w*') sort([findcells(mach,'FamName','SDH\w*') findcells(mach,'FamName','SDL\w*')])];
if numel(mark)==64
mark=mark(2:2:end);
end
%res=mach{mark(5)}
%blm=[obj.BLM.SA_Incoherencies()];
blm=[obj.BLM.read()];
%%if plane==2
%% orb=obj.ORBITV.read;
%%elseif plane==1
%% orb=obj.ORBITH.read;
%%end
mach=circshift(mach,-mark(mod(cini-4,32)+1));
blm=circshift(reshape(blm,[],32)',-mod(cini-2,32)+1)';
blm=blm(:,[1:mod(cend-cini,32)]);
blm=blm(:);
%mark_shift=sort([findcells(mach,'FamName','ID\w*')+2 findcells(mach,'FamName','DL\w*A\w*_2') findcells(mach,'FamName','DL\w*E\w*_2')...
% findcells(mach,'FamName','JL\w*_2') findcells(mach,'FamName','DL\w*D\w*_2')]);
mark_shift=[findcells(mach,'FamName','ID\w*') sort([findcells(mach,'FamName','SDH\w*') findcells(mach,'FamName','SDL\w*')])];
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')]);
figure(1);
clf(1);
iblm
atbaseplot(cells);
whos
if(numel(blm)==numel(iblm))
spos=findspos(cells,iblm);
hold on
yyaxis right;
%ylim([-2 2]);
plot(spos,blm(:)*1000);
legend(['blm reading in cells: ' num2str([cini cend])])
hold off;
else
error='blm vector length different from bmls numbers'
end
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