%% This script is used for mode matching of the telescope of ISCTEY
% refer to DCC T1200200-v1 (only using nominal values)

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


%% Mode Master 
%(see snap shots of MM in /Users/alexastaley/Desktop/LIGO/ISCTEY Results/TelescopeMM/)
for i = 1:length(names)
    MM(i) = beamPath;
end
 
z_MM = 0;
% waist size given by MM (2Wo,Zo in meters) -- these results were
% reproducible
% Configuration: L6 is 13.5inch from M9, and L7 is 6inch from M10
MM_WO(1) = 3.237e-3/2;
MM_WO(2) = 3.935e-3/2;
MM_ZO(1) = 11.819;
MM_ZO(2) = 0.517;
for i = 1:length(names)
    MM(i).seedWaist(MM_WO(i), z_MM + MM_ZO(i), lambda);
    MM(i).addComponent(component.flatMirror(z_MM, 'MM'));
end


% Target waist is 3.5m from M11, 3.6m from M10
% M10 to MM is 1.356m
% Target waist is 2.254m from MM

% target waist
z_target = 2.254; % relative to zero of MM
waist_target = 2.2e-3;
for i = 1:length(names)
    MM(i).targetWaist(waist_target, z_target, lambda);
end

for i = 1:length(names)
    MM(i).targetOverlap
end


zz2=-1:0.01:5;
figure(3)
clf;
hold on;
x_MM = MM(1).plotBeamWidth(zz2, 'r');
y_MM = MM(2).plotBeamWidth(zz2, 'b');
MM(1).plotComponents(zz2, 'r*');
legend([x_MM y_MM], 'x MM', 'y MM');
ylabel('Beam width (m)')
grid on
xlabel('distance along the path (m)')