 addpath C:\Users\sheila.dwyer\Documents\MATLAB\alm-master
close all
clear classes

goo = beamPath;
goo.seedWaist(205e-6, -1.22, 1064e-9);  %mode out of F220FC-1064, measured in alog 57169
%PLCX-77.3 f = 154.7mm
goo.addComponent(component.lens(687.5e-3, 0.16, 'lens1'))  %309.1 

blah = goo.getWaists;
waist_from_collimator = blah(2)

opo = beamPath;
opo.seedWaist(215e-6, 0, 1064e-9)
lens_from_OPO = 0.16;
opo.addComponent(component.lens(111e-3, lens_from_OPO, 'lens1'))

%opo.qPropagate(1)
%disp('waist position from OPO waist')
blah = opo.getWaists;
%waist_pos_opo = blah(2)
%disp('waist position from 50mm lens')

%waist_from_ROC50 = waist_pos_opo - lens_from_OPO

%add ROC to collimator path
goo.addComponent(component.lens(111e-3, 1.4, 'lens2'))
%try out automated lens selection
goo.targetWaist(214e-6,1.566); 
% we create a list of possible lens choices
focalLengthList = [-56,-167, -222, 111,167,222,334,687.5,515.3,1030.9]*1e-3;
lensList = component.lens(focalLengthList);

tic;
[pathList,overlapList] = goo.chooseComponents(...
                'lens1',lensList,[0.1 1],...  % choose lens1 from the list,
                'lens2',lensList.duplicate,[1 2],... %duplicate the list, this allows
                ...                                    %  the same component to be chosen more than once
                'target',[1.4,3]... % we can also allow the target waist position to vary while optimizing the overlap
                ,'-vt',.25); % set the minimum initial overlap to 0.25, if a combination of components
                             % has an overlap less than this, it will be skipped without trying to optimize the lens positions
toc

pathList = pathList(overlapList >= 0.99);
sensitivityList = pathList.positionSensitivity;
[sensitivityList,sortIndex] = sort(sensitivityList);
pathList = pathList(sortIndex);
bestPath = pathList(1);
disp('Location of waists for best path:')
blah = bestPath.getWaists;
col_to_waist = blah(2)
% print the component list to the command window
disp(' ')
disp(' Optimized Path Component List:')
display(bestPath.components)
zdomain = 0:.003:2;
figure(3)
bestPath.plotSummary(zdomain);

blah = goo.getWaists;

%OPO_to_collimator = blah(3)

figure(1)
goo.plotSummary(zdomain)

figure(2)
opo.plotSummary(zdomain)


%can't find the focal length for PLCX-25.4-309.1 online anywhere.... seems
%to be discontinued
n_FS = 1.4496;  %index of refraction FS at 1064nm
R1 = 309.1e-3; %ROC
f = R1/(n_FS-1)

disp('off platform steering mirror to collimator')
col_to_waist - 0.845
