% beam width fitting

% data from kate's elog:

%             diameter (um)
% hole       x             y
% ----     ------        ------
%   3     3550 ± 30     3480 ± 10
%  19     3490 ± 20     3360 ± 10
%  35     3460 ± 20     3310 ± 10

close all
clear classes

lambda = 1064e-9;

z_BD = 5.96; %I'm guessing this from looking at Lee's plots, I don't know the distance of the beam diverter from ZM5

zScan = z_BD + [0, 4, 8] * 1e-2; %second Beam profile taken by Varun and I alog 61698
xWidth = [1518, 1497, 1470] * 1e-6/2;
yWidth = [1636, 1618, 1578] * 1e-6/2;

goo = beamPath;

goo.seedWaist(1197e-6/2, 6.855); %nominal beam labelled on Lee's last plot in alog 61593
goo.targetWaist(1197e-6/2, 6.855);

goox = goo.fitBeamWidth(zScan,xWidth);
gooy = goo.fitBeamWidth(zScan,yWidth);

%% Make a beam path with the nominal beam parameter
Apath = beamPath;  %
%translate Z, Zr from last plot of alog 61593
designZr= 1.057; 
waist_size = sqrt(designZr*lambda/pi);
designZ = 3.81+3.045 
Apath.seedWaist(waist_size, designZ, lambda);

%%
zdomain = 5:.0001:7.1;%linspace(min(zScan),max(zScan),100);
figure(1)
clf
hold on
plot(zScan,xWidth,'bo')
goox.plotBeamWidth(zdomain,'b')
goox.plotBeams(zdomain,.7e-3,'b')
plot(zScan,yWidth,'ro')
gooy.plotBeamWidth(zdomain,'r')
gooy.plotBeams(zdomain,-.7e-3,'r')
Apath.plotBeamWidth(zdomain, 'k')
xlabel('Distance from SFI TFP')
ylabel('Beam radius [m]')
title('ALM fit: blue is x (yaw), red is y (pit)')
grid on
axis tight
hold off