addpath  /ligo/home/sheila.dwyer/PSL/mode_matching/alm-master

%% a la mode demonstration
% mode matching and beam propagation solutions in MATLAB.
%
% a la mode is a stimple library of gaussian ABCD matrix tools intended to 
% optimize and visualize optical systems.

%% simple beam path
%
% In this example, we will design a simple beam path and then define a target
% beam for modematchin, and choose an optimum configuration from a list of possible
% lens choices.

% here we design an initial simple beam path
lambda = 1064e-9;
goo = beamPath;
%SRM_ROC= -5.69;
goo.seedq = beamq.beamWidthAndR(2.1e-3,-3.88,lambda);%from table 1 T1200410
goo.seedz = 0;
%n=1.45;
%SRMf= -1*SRM_ROC/(n-1);

%focal length of SRM subtrate lens
%goo.addComponent(component.lens(SRMf,0,'SRMlens'));  %focal length, location, label

goo.addComponent(component.curvedMirror(4.6,3.571,'OM1'));%T1200410 table 1+2
goo.addComponent(component.curvedMirror(1.7,4.966,'OM2'));%T1200410 table 1+2
%from T1000317 the designed distance from SRM to OMC was 5.69meters
SRM_to_OMC = 3.646+1.395+0.708+0.268;  %Keita's distances in T1000317 table 3 are distances between optics
%SRM to OM1
goo.targetWaist(5.09e-4, 5.936); %wasit size, position, lambda
goo.targetOverlap
% plot the results
zplot = -1:.01:6.5;
goo.components
goo.plotSummary(zplot);

%% repeat for as built distances
% here we design an initial simple beam path
lambda = 1064e-9;
gooasBuilt = beamPath;
%SRM_ROC= -5.69;
gooasBuilt.seedq = beamq.beamWidthAndR(2.1e-3,-3.88,lambda);%from table 1 T1200410
gooasBuilt.seedz = 0;
%n=1.45;
%SRMf= -1*SRM_ROC/(n-1);

%focal length of SRM subtrate lens
%goo.addComponent(component.lens(SRMf,0,'SRMlens'));  %focal length, location, label

gooasBuilt.addComponent(component.curvedMirror(4.6,3.442,'OM1'));%T1200410 table 1+2
gooasBuilt.addComponent(component.curvedMirror(1.7,4.888,'OM2'));%T1200410 table 1+2
%from T1000317 the designed distance from SRM to OMC was 5.69meters
SRM_to_OMC = 3.646+1.395+0.708+0.268;  %Keita's distances in T1000317 table 3 are distances between optics
%SRM to OM1
gooasBuilt.targetWaist(5.09e-4, 5.858+0.14); %wasit size, position, lambda
gooasBuilt.targetOverlap
% plot the results
zplot = -1:.01:6.5;
gooasBuilt.components
gooasBuilt.plotSummary(zplot);




%% other features and limitations
% 
% Features:
%
% * lives inside MATLAB% * built-in beam width measurement fitting
% * define beams as eigenmodes
% * angular, lateral, and positional motion sensitivity calculations
% * calculate gouy phase seperations of optical elements
% * comprehensive, cross referenced help documentation
% 
% Limitations:
%
% * Totally 1-D
% * all components are 'thin'