addpath('/Users/alexastaley/Documents/MATLAB/alm');
% green path on ISCTEX
lambda = 532e-9;
% unit conversion
inch_to_meter = 0.0254;

%% OAT configuration
% data collected with OAT configuration w/ ROC=-100mm removed
OAT=beamPath;
ModeMaster_2W0 = 1.527e-3;
M11_to_ModeMaster = 28.5 * inch_to_meter; % zero position is M11
ModeMasterZ0 = -1.348;
OAT.seedWaist(ModeMaster_2W0/2, M11_to_ModeMaster + ModeMasterZ0, lambda);

% Mirror locations
z_M11 = 0;
z_M10 = -.36;
z_M9 = z_M10 - 1.47;
OAT.addComponent(component.flatMirror(z_M9, 'ALS M9'));
OAT.addComponent(component.flatMirror(z_M11, 'ALS M11'));
OAT.addComponent(component.flatMirror(z_M10, 'ALS M10'));
OAT.addComponent(component.flatMirror(M11_to_ModeMaster, 'MM'));

% index of refraction for Fused Silica
n = 1.46071;
% ALS L7
ROC_L7 = 500e-3;
f_L7 = ROC_L7/(n-1);
z_L7 = -32 * inch_to_meter; % from M11
OAT.addComponent(component.lens(f_L7, z_L7, 'ALS L7'));

%% Nominal Configuration
ISCEX=OAT.branchPath(-5);
z_L7 = z_M10 - 7*inch_to_meter;
ISCEX.moveComponent('ALS L7', z_L7, 'absolute');


% ALS L6
ROC_L6 = -100e-3;
f_L6 = ROC_L6/(n-1);
z_L6 = z_L7 - 37 * inch_to_meter; 
ISCEX.addComponent(component.lens(f_L6, z_L6, 'ALS L6'));

% target waist
z_target = 184.6 * inch_to_meter;
waist_target = 2.2e-3;
ISCEX.targetWaist(waist_target, z_target, lambda);

ISCEX.targetOverlap

zz=-3:0.01:1;
figure(1)
clf;
hold on;
OAT.plotSummary(zz)
OAT.plotComponents(zz, '*');

figure(2)
clf;
hold on;
ISCEX.plotSummary(zz)
ISCEX.plotComponents(zz, '*');