addpath C:\Users\sheila.dwyer\Documents\MATLAB\alm-master
% 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

goo = beamPath;
%goo.seedq.lambda = 532e-9;

%we think this is green light in class B fiber in green coupler
%this gives us a 52um waist
% zScan = 0.173+[0 2 4 6 8 10 12 14]*25.4e-3; % hole spacing is 2 inches
% hWidth = [432 775 1100 1435 1766 2088 2408 2734] * 1e-6/2;
% vWidth = [440 786 1113 1462 1794 2111 2419 2704] * 1e-6/2;
% goo.seedWaist(350e-6,0.33, 532e-9)


%green light in red coupler
%this gives us 210/255 um waist 0.22/0.33 meters after the coupler
zScan = 0.255-0.0508+[2 4 6 8 18]*25.4e-3; % hole spacing is 2 inches
hWidth = [472 432 442 495 842] * 1e-6/2;
vWidth = [505 480 490 550 838] * 1e-6/2;
goo.seedWaist(350e-6,0.33, 532e-9)

% %red light in what we think is the red coupler
% %gives a waist of 155 um 0.22 meters behind coupler
% zScan = 0.255-0.0508+[2 4 6 8 14]*25.4e-3; % hole spacing is 2 inches
% hWidth = [2108 2339 2581 2804 3435] * 1e-6/2;
% vWidth = [2125 2353 2587 2802 3442] * 1e-6/2;
% goo.seedWaist(370e-6,0, 1064e-9)

% %red light in what we think is the green coupler (coupler was 200 mm from
% %the 2 inch place)  %this gives us a wiast of 255 um after the fiber 0.3 m
% zScan = 0.200-0.0508+[2 4 6 8 12 16]*25.4e-3; % hole spacing is 2 inches
% hWidth = [568 525 513 546 711 945] * 1e-6/2;
% vWidth = [557 514 511 544 708 936] * 1e-6/2;
% goo.seedWaist(370e-6,0, 1064e-9)

gooh = goo.fitBeamWidth(zScan,hWidth);
goov = goo.fitBeamWidth(zScan,vWidth);

zdomain = 0:.001:1;%linspace(min(zScan),max(zScan),100);
figure(1)
clf
hold on
plot(zScan,hWidth,'bo')
gooh.plotBeamWidth(zdomain,'b')
gooh.plotBeams(zdomain,.5e-3,'b')
plot(zScan,vWidth,'ro')
goov.plotBeamWidth(zdomain,'r')
goov.plotBeams(zdomain,-.5e-3,'r')
hold off

goo.plotBeamWidth(zdomain,'k')
gooh.qPropagate(0).waistSize
gooh.qPropagate(0).waistZ

goov.qPropagate(0).waistSize
goov.qPropagate(0).waistZ

