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

%script used for switch to diamond fiber for CLF pre O4 June vent
lambda = 1064e-9;
goo = beamPath;
%waist of OPO
%from T1900649 fig 23   M2 is at 12.48inches
difference_design_to_built_path_length = 12.48*25.4e-3-0.307
goo.seedWaist(379.7e-6/2, 10.697*25.4e-3-difference_design_to_built_path_length); %from T1900649 fig 23  %This is the ideal waist, at 10.697 inches in Lee's coordinates, where M2 is at 12.48 inches
%distaces noted in alog 57960, using 0 as collimator position for now
goo.addComponent(component.lens(0.334,44e-3,'F:L1+150mm ROC')); 
%collimator to M2 of OPO is 205+102mm
goo.addComponent(component.flatMirror(0.205+0.102, 'M2'));  %in out layout M2 is at 0.307mm

%fit data taken by Camilla and Austin
zScan = [210, 337, 464, 591, 718, 845, 972, 1099]*1e-3;
hWidth = [573.8, 476.4, 632.5, 981.8, 1355.2, 1708.5, 2097.9, 2535.1]*1e-6/2;
vWidth = [554.2, 457.4, 633.1, 1006.3, 1375, 1751.1, 2157.6, 2573.1]*1e-6/2;

meas = beamPath;
meas.seedWaist(500e-6, 0.3, lambda);
meas_h = meas.fitBeamWidth(zScan, hWidth);
meas_v = meas.fitBeamWidth(zScan, vWidth);

zdomain = -0.1:.01:1;
figure(1)
goo;
hold on
goo.plotBeamWidth(zdomain,'k')
meas_h.plotBeamWidth(zdomain, 'b')
meas_v.plotBeamWidth(zdomain, 'r')
plot(zScan,hWidth,'bo')
plot(zScan,vWidth,'rx')
legend('target beam', ' ', 'measured beam from collimator horizontal', ' ',...
    'measured beam from collimator vertical', 'Location', 'SouthEast')
xlabel('distance from collimator [m]')
ylabel('Beam radius [m]')
saveas(gcf, 'CLF_new_collimator.png')