% Back propagate q value measurement for mode before ZM4

profiler_to_steering_mirror = 1.774 + 0.574 +84.5*25.4e-3 + 0.150+.395;


ZM4_location_to_profiler = profiler_to_steering_mirror;

% Waist data for ZM2 = 3.15 strain gauge (nominal settings for ZM4/ZM5 PSAM
% sweeps.  from Jun30_2026.yaml

%ZM4 = 2
z0_x_2 = -1*(6452.67e-3 - ZM4_location_to_profiler); %Position of x waist, Z=0 is ZM4 location
z0_y_2 = -1*(6577.46e-3 - ZM4_location_to_profiler);%Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_x_2 = sqrt(1867.76e-3*wl/pi);
w0_y_2 = sqrt(2098.87e-3*wl/pi);

xBeam_2 = beamPath;
xBeam_2.seedWaist(w0_x_2,z0_x_2);

yBeam_2 = beamPath;
yBeam_2.seedWaist(w0_y_2,z0_y_2)

%ZM4 = 4
z0_x_4 = -1*(6524.84e-3 - ZM4_location_to_profiler); %Position of x waist, Z=0 is ZM4 location
z0_y_4 = -1*(6588.3e-3 - ZM4_location_to_profiler);%Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_x_4 = sqrt(1751.63e-3*wl/pi);
w0_y_4 = sqrt(1908.88e-3*wl/pi);

xBeam_4 = beamPath;
xBeam_4.seedWaist(w0_x_4,z0_x_4);

yBeam_4 = beamPath;
yBeam_4.seedWaist(w0_y_4,z0_y_4)

%ZM4 = 6

z0_x_6 = -1*(6502.85e-3 - ZM4_location_to_profiler); %Position of x waist, Z=0 is ZM4 location
z0_y_6 = -1*(6552.8e-3 - ZM4_location_to_profiler);%Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_x_6 = sqrt(1659.59e-3*wl/pi);
w0_y_6 = sqrt(1754.19e-3*wl/pi);

xBeam_6 = beamPath;
xBeam_6.seedWaist(w0_x_6,z0_x_6);

yBeam_6 = beamPath;
yBeam_6.seedWaist(w0_y_6,z0_y_6)

%ZM4 = 8

z0_x_8 = -1*(6497.65e-3 - ZM4_location_to_profiler); %Position of x waist, Z=0 is ZM4 location
z0_y_8 = -1*(6561.93e-3 - ZM4_location_to_profiler);%Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_x_8 = sqrt(1560.52e-3*wl/pi);
w0_y_8 = sqrt(1682.03e-3*wl/pi);

xBeam_8 = beamPath;
xBeam_8.seedWaist(w0_x_8,z0_x_8);

yBeam_8 = beamPath;
yBeam_8.seedWaist(w0_y_8,z0_y_8)

%Use values for ZM5 ROC determined by alog 90845 analysis

R_n4p5_zm5 = 4.0;
R_n2_zm5 = 4.3;
R_2_zm5 = 4.9;
R_0_zm5 = 4.7;

cosT_5 = cos(5*pi/180);
d45 = 1.618;  

R_8_zm4 = -12;
R_6_zm4 = -11;
R_4_zm4 = -10;
R_2_zm4 = -9;


%% First Datapoint ZM4 = 6, ZM5 = -4.5
xBeam_6_n4p5 = beamPath;
yBeam_6_n4p5 = beamPath;
xBeam_6_n4p5.seedWaist(w0_x_6,z0_x_6);
yBeam_6_n4p5.seedWaist(w0_y_6,z0_y_6);




%Build Path
xBeam_6_n4p5.addComponent(component.curvedMirror(R_n4p5_zm5*cosT_5,d45,'ZM5'))

yBeam_6_n4p5.addComponent(component.curvedMirror(R_n4p5_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 6.0  ZM5 = -4.5
z0_6n4p5_x = -1*(2433.75e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_6n4p5_y = -1*(2496.61e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_6n4p5_x = sqrt(1235.29e-3*wl/pi);
w0_6n4p5_y = sqrt(1402.20e-3*wl/pi);

xBeam_6_n4p5.targetWaist(w0_6n4p5_x,z0_6n4p5_x);
yBeam_6_n4p5.targetWaist(w0_6n4p5_y,z0_6n4p5_y);

fprintf("X overlap for ZM4 = 6.0, ZM5 = -4.5: %f\n", xBeam_6_n4p5.targetOverlap())
fprintf("Y overlap for ZM4 = 6.0, ZM5 = -4.5: %f\n",yBeam_6_n4p5.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_6_zm4)
fprintf("ROC for ZM5 = %f\n", R_n4p5_zm5)

%%  ZM4 = 6,  ZM5 = 2.0

xBeam_6_2 = beamPath;
yBeam_6_2 = beamPath;
xBeam_6_2.seedWaist(w0_x_6,z0_x_6);
yBeam_6_2.seedWaist(w0_y_6,z0_y_6);


%Build Path
xBeam_6_2.addComponent(component.curvedMirror(R_2_zm5*cosT_5,d45,'ZM5'))

yBeam_6_2.addComponent(component.curvedMirror(R_2_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 6.0  ZM5 = 2
z0_6_2_x = -1*(992.0e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_6_2_y = -1*(1231.02e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_6_2_x = sqrt(2235.31e-3*wl/pi);
w0_6_2_y = sqrt(2549.02e-3*wl/pi);

xBeam_6_2.targetWaist(w0_6_2_x,z0_6_2_x);
yBeam_6_2.targetWaist(w0_6_2_y,z0_6_2_y);

fprintf("X overlap for ZM4 = 6.0, ZM5 = 2.0: %f\n", xBeam_6_2.targetOverlap())
fprintf("Y overlap for ZM4 = 6.0, ZM5 = 2.0: %f\n",yBeam_6_2.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_6_zm4)
fprintf("ROC for ZM5 = %f\n", R_2_zm5)

%%  ZM4 = 6,  ZM5 = -2.0

xBeam_6_n2 = beamPath;
yBeam_6_n2 = beamPath;
xBeam_6_n2.seedWaist(w0_x_6,z0_x_6);
yBeam_6_n2.seedWaist(w0_y_6,z0_y_6);


%Build Path
xBeam_6_n2.addComponent(component.curvedMirror(R_n2_zm5*cosT_5,d45,'ZM5'))

yBeam_6_n2.addComponent(component.curvedMirror(R_n2_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 6.0  ZM5 = -2
z0_6_n2_x = -1*(1897.43e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_6_n2_y = -1*(2017.06e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_6_n2_x = sqrt(1544.56e-3*wl/pi);
w0_6_n2_y = sqrt(1734.56e-3*wl/pi);

xBeam_6_n2.targetWaist(w0_6_n2_x,z0_6_n2_x);
yBeam_6_n2.targetWaist(w0_6_n2_y,z0_6_n2_y);

fprintf("X overlap for ZM4 = 6.0, ZM5 = -2.0: %f\n", xBeam_6_n2.targetOverlap())
fprintf("Y overlap for ZM4 = 6.0, ZM5 = -2.0: %f\n",yBeam_6_n2.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_6_zm4)
fprintf("ROC for ZM5 = %f\n", R_n2_zm5)

%%  ZM4 = 6,  ZM5 = 0.0

xBeam_6_0 = beamPath;
yBeam_6_0 = beamPath;
xBeam_6_0.seedWaist(w0_x_6,z0_x_6);
yBeam_6_0.seedWaist(w0_y_6,z0_y_6);



%Build Path
xBeam_6_0.addComponent(component.curvedMirror(R_0_zm5*cosT_5,d45,'ZM5'))

yBeam_6_0.addComponent(component.curvedMirror(R_0_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 6.0  ZM5 = 0
z0_6_0_x = -1*(1194.78e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_6_0_y = -1*(1427.07e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_6_0_x = sqrt(2076.3e-3*wl/pi);
w0_6_0_y = sqrt(2386.48e-3*wl/pi);

xBeam_6_0.targetWaist(w0_6_0_x,z0_6_0_x);
yBeam_6_0.targetWaist(w0_6_0_y,z0_6_0_y);

fprintf("X overlap for ZM4 = 6.0, ZM5 = 0: %f\n", xBeam_6_0.targetOverlap())
fprintf("Y overlap for ZM4 = 6.0, ZM5 = 0: %f\n",yBeam_6_0.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_6_zm4)
fprintf("ROC for ZM5 = %f\n", R_0_zm5)

%%  ZM4 = 8,  ZM5 = -4.5

xBeam_8_n4p5 = beamPath;
yBeam_8_n4p5 = beamPath;
xBeam_8_n4p5.seedWaist(w0_x_8,z0_x_8);
yBeam_8_n4p5.seedWaist(w0_y_8,z0_y_8);


%Build Path
xBeam_8_n4p5.addComponent(component.curvedMirror(R_n4p5_zm5*cosT_5,d45,'ZM5'))

yBeam_8_n4p5.addComponent(component.curvedMirror(R_n4p5_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 8.0  ZM5 = -4.5
z0_8_n4p5_x = -1*(2352.96e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_8_n4p5_y = -1*(2411.9e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_8_n4p5_x = sqrt(1219.16e-3*wl/pi);
w0_8_n4p5_y = sqrt(1386.05e-3*wl/pi);

xBeam_8_n4p5.targetWaist(w0_8_n4p5_x,z0_8_n4p5_x);
yBeam_8_n4p5.targetWaist(w0_8_n4p5_y,z0_8_n4p5_y);

fprintf("X overlap for ZM4 = 8.0, ZM5 = -4.5: %f\n", xBeam_8_n4p5.targetOverlap())
fprintf("Y overlap for ZM4 = 8.0, ZM5 = -4.5: %f\n",yBeam_8_n4p5.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_8_zm4)
fprintf("ROC for ZM5 = %f\n", R_n4p5_zm5)

%%  ZM4 = 8,  ZM5 = 0p0

xBeam_8_0 = beamPath;
yBeam_8_0 = beamPath;
xBeam_8_0.seedWaist(w0_x_8,z0_x_8);
yBeam_8_0.seedWaist(w0_y_8,z0_y_8);


%Build Path
xBeam_8_0.addComponent(component.curvedMirror(R_0_zm5*cosT_5,d45,'ZM5'))

yBeam_8_0.addComponent(component.curvedMirror(R_0_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 8.0  ZM5 = 0
z0_8_0_x = -1*(976.59e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_8_0_y = -1*(1171.08e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_8_0_x = sqrt(2125.69e-3*wl/pi);
w0_8_0_y = sqrt(2434.82e-3*wl/pi);

xBeam_8_0.targetWaist(w0_8_0_x,z0_8_0_x);
yBeam_8_0.targetWaist(w0_8_0_y,z0_8_0_y);

fprintf("X overlap for ZM4 = 8.0, ZM5 = 0: %f\n", xBeam_8_0.targetOverlap())
fprintf("Y overlap for ZM4 = 8.0, ZM5 = 0: %f\n",yBeam_8_0.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_8_zm4)
fprintf("ROC for ZM5 = %f\n", R_0_zm5)

%%  ZM4 = 8,  ZM5 = 2

xBeam_8_2 = beamPath;
yBeam_8_2 = beamPath;
xBeam_8_2.seedWaist(w0_x_8,z0_x_8);
yBeam_8_2.seedWaist(w0_y_8,z0_y_8);



%Build Path
xBeam_8_2.addComponent(component.curvedMirror(R_2_zm5*cosT_5,d45,'ZM5'))

yBeam_8_2.addComponent(component.curvedMirror(R_2_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 8.0  ZM5 = 2
z0_8_2_x = -1*(773.59e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_8_2_y = -1*(982.81e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_8_2_x = sqrt(2276.88e-3*wl/pi);
w0_8_2_y = sqrt(2575.5e-3*wl/pi);

xBeam_8_2.targetWaist(w0_8_2_x,z0_8_2_x);
yBeam_8_2.targetWaist(w0_8_2_y,z0_8_2_y);

fprintf("X overlap for ZM4 = 8.0, ZM5 = 2: %f\n", xBeam_8_2.targetOverlap())
fprintf("Y overlap for ZM4 = 8.0, ZM5 = 2: %f\n",yBeam_8_2.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_8_zm4)
fprintf("ROC for ZM5 = %f\n", R_2_zm5)

%%  ZM4 = 8,  ZM5 = -2

xBeam_8_n2 = beamPath;
yBeam_8_n2 = beamPath;
xBeam_8_n2.seedWaist(w0_x_8,z0_x_8);
yBeam_8_n2.seedWaist(w0_y_8,z0_y_8);



%Build Path
xBeam_8_n2.addComponent(component.curvedMirror(R_n2_zm5*cosT_5,d45,'ZM5'))

yBeam_8_n2.addComponent(component.curvedMirror(R_n2_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 8.0  ZM5 = -2
z0_8_n2_x = -1*(1775.74e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_8_n2_y = -1*(1895.54e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_8_n2_x = sqrt(1526.73e-3*wl/pi);
w0_8_n2_y = sqrt(1740.47e-3*wl/pi);

xBeam_8_n2.targetWaist(w0_8_n2_x,z0_8_n2_x);
yBeam_8_n2.targetWaist(w0_8_n2_y,z0_8_n2_y);

fprintf("X overlap for ZM4 = 8.0, ZM5 = -2: %f\n", xBeam_8_n2.targetOverlap())
fprintf("Y overlap for ZM4 = 8.0, ZM5 = -2: %f\n",yBeam_8_n2.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_8_zm4)
fprintf("ROC for ZM5 = %f\n", R_n2_zm5)

%%  ZM4 = 2,  ZM5 = 0

xBeam_2_0 = beamPath;
yBeam_2_0 = beamPath;
xBeam_2_0.seedWaist(w0_x_2,z0_x_2);
yBeam_2_0.seedWaist(w0_y_2,z0_y_2);


%Build Path
xBeam_2_0.addComponent(component.curvedMirror(R_0_zm5*cosT_5,d45,'ZM5'))

yBeam_2_0.addComponent(component.curvedMirror(R_0_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 2  ZM5 = 0
z0_2_0_x = -1*(1550.19e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_2_0_y = -1*(1806.37e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_2_0_x = sqrt(2029.78e-3*wl/pi);
w0_2_0_y = sqrt(2381.95e-3*wl/pi);

xBeam_2_0.targetWaist(w0_2_0_x,z0_2_0_x);
yBeam_2_0.targetWaist(w0_2_0_y,z0_2_0_y);

fprintf("X overlap for ZM4 = 2.0, ZM5 = 0: %f\n", xBeam_2_0.targetOverlap())
fprintf("Y overlap for ZM4 = 2.0, ZM5 = 0: %f\n",yBeam_2_0.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_2_zm4)
fprintf("ROC for ZM5 = %f\n", R_0_zm5)

%%  ZM4 = 2,  ZM5 = -4.5

xBeam_2_n4p5 = beamPath;
yBeam_2_n4p5 = beamPath;
xBeam_2_n4p5.seedWaist(w0_x_2,z0_x_2);
yBeam_2_n4p5.seedWaist(w0_y_2,z0_y_2);


%Build Path
xBeam_2_n4p5.addComponent(component.curvedMirror(R_n4p5_zm5*cosT_5,d45,'ZM5'))

yBeam_2_n4p5.addComponent(component.curvedMirror(R_n4p5_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 2  ZM5 = -4.5
z0_2_n4p5_x = -1*(2622.56e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_2_n4p5_y = -1*(2708.54e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_2_n4p5_x = sqrt(1207.73e-3*wl/pi);
w0_2_n4p5_y = sqrt(1366.0e-3*wl/pi);

xBeam_2_n4p5.targetWaist(w0_2_n4p5_x,z0_2_n4p5_x);
yBeam_2_n4p5.targetWaist(w0_2_n4p5_y,z0_2_n4p5_y);

fprintf("X overlap for ZM4 = 2.0, ZM5 = -4.5: %f\n", xBeam_2_n4p5.targetOverlap())
fprintf("Y overlap for ZM4 = 2.0, ZM5 = -4.5: %f\n",yBeam_2_n4p5.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_2_zm4)
fprintf("ROC for ZM5 = %f\n", R_n4p5_zm5)

%%  ZM4 = 2,  ZM5 = -2

xBeam_2_n2 = beamPath;
yBeam_2_n2 = beamPath;
xBeam_2_n2.seedWaist(w0_x_2,z0_x_2);
yBeam_2_n2.seedWaist(w0_y_2,z0_y_2);


%Build Path
xBeam_2_n2.addComponent(component.curvedMirror(R_n2_zm5*cosT_5,d45,'ZM5'))

yBeam_2_n2.addComponent(component.curvedMirror(R_n2_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 2  ZM5 = -2
z0_2_n2_x = -1*(2126.73e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_2_n2_y = -1*(2309.187e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_2_n2_x = sqrt(1665.56e-3*wl/pi);
w0_2_n2_y = sqrt(1750.27e-3*wl/pi);

xBeam_2_n2.targetWaist(w0_2_n2_x,z0_2_n2_x);
yBeam_2_n2.targetWaist(w0_2_n2_y,z0_2_n2_y);

fprintf("X overlap for ZM4 = 2.0, ZM5 = -2.0: %f\n", xBeam_2_n2.targetOverlap())
fprintf("Y overlap for ZM4 = 2.0, ZM5 = -2.0: %f\n",yBeam_2_n2.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_2_zm4)
fprintf("ROC for ZM5 = %f\n", R_n2_zm5)

%%  ZM4 = 2,  ZM5 = 2

xBeam_2_2 = beamPath;
yBeam_2_2 = beamPath;
xBeam_2_2.seedWaist(w0_x_2,z0_x_2);
yBeam_2_2.seedWaist(w0_y_2,z0_y_2);


%Build Path
xBeam_2_2.addComponent(component.curvedMirror(R_2_zm5*cosT_5,d45,'ZM5'))

yBeam_2_2.addComponent(component.curvedMirror(R_2_zm5/cosT_5,d45,'ZM5'))

%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 2.0  ZM5 = 2
z0_2_2_x = -1*(1409.2e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_2_2_y = -1*(1667.0e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_2_2_x = sqrt(2167.9e-3*wl/pi);
w0_2_2_y = sqrt(2541.56e-3*wl/pi);

xBeam_2_2.targetWaist(w0_2_2_x,z0_2_2_x);
yBeam_2_2.targetWaist(w0_2_2_y,z0_2_2_y);

fprintf("X overlap for ZM4 = 2.0, ZM5 = 2: %f\n", xBeam_2_2.targetOverlap())
fprintf("Y overlap for ZM4 = 2.0, ZM5 = 2: %f\n",yBeam_2_2.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_2_zm4)
fprintf("ROC for ZM5 = %f\n", R_2_zm5)

%%  ZM4 = 4,  ZM5 = -4.5

xBeam_4_n4p5 = beamPath;
yBeam_4_n4p5 = beamPath;
xBeam_4_n4p5.seedWaist(w0_x_4,z0_x_4);
yBeam_4_n4p5.seedWaist(w0_y_4,z0_y_4);

%Build Path
xBeam_4_n4p5.addComponent(component.curvedMirror(R_n4p5_zm5*cosT_5,d45,'ZM5'))
yBeam_4_n4p5.addComponent(component.curvedMirror(R_n4p5_zm5/cosT_5,d45,'ZM5'))


%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 4.0  ZM5 = -4.5
z0_4_n4p5_x = -1*(2519.61e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_4_n4p5_y = -1*(2573.67e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_4_n4p5_x = sqrt(1243.95e-3*wl/pi);
w0_4_n4p5_y = sqrt(1395.06e-3*wl/pi);

xBeam_4_n4p5.targetWaist(w0_4_n4p5_x,z0_4_n4p5_x);
yBeam_4_n4p5.targetWaist(w0_4_n4p5_y,z0_4_n4p5_y);

fprintf("X overlap for ZM4 = 4.0, ZM5 = -4.5: %f\n", xBeam_4_n4p5.targetOverlap())
fprintf("Y overlap for ZM4 = 4.0, ZM5 = -4.5: %f\n",yBeam_4_n4p5.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_4_zm4)
fprintf("ROC for ZM5 = %f\n", R_n4p5_zm5)

%%  ZM4 = 4,  ZM5 = -2

xBeam_4_n2 = beamPath;
yBeam_4_n2 = beamPath;
xBeam_4_n2.seedWaist(w0_x_4,z0_x_4);
yBeam_4_n2.seedWaist(w0_y_4,z0_y_4);


%Build Path
xBeam_4_n2.addComponent(component.curvedMirror(R_n2_zm5*cosT_5,d45,'ZM5'))
yBeam_4_n2.addComponent(component.curvedMirror(R_n2_zm5/cosT_5,d45,'ZM5'))


%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 4.0  ZM5 = -2
z0_4_n2_x = -1*(2005.73e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_4_n2_y = -1*(2141.09e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_4_n2_x = sqrt(1575.6e-3*wl/pi);
w0_4_n2_y = sqrt(1718.94e-3*wl/pi);

xBeam_4_n2.targetWaist(w0_4_n2_x,z0_4_n2_x);
yBeam_4_n2.targetWaist(w0_4_n2_y,z0_4_n2_y);

fprintf("X overlap for ZM4 = 4.0, ZM5 = -2: %f\n", xBeam_4_n2.targetOverlap())
fprintf("Y overlap for ZM4 = 4.0, ZM5 = -2: %f\n",yBeam_4_n2.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_4_zm4)
fprintf("ROC for ZM5 = %f\n", R_n2_zm5)

%%  ZM4 = 4,  ZM5 = 0

xBeam_4_0 = beamPath;
yBeam_4_0 = beamPath;
xBeam_4_0.seedWaist(w0_x_4,z0_x_4);
yBeam_4_0.seedWaist(w0_y_4,z0_y_4);



%Build Path
xBeam_4_0.addComponent(component.curvedMirror(R_0_zm5*cosT_5,d45,'ZM5'))
yBeam_4_0.addComponent(component.curvedMirror(R_0_zm5/cosT_5,d45,'ZM5'))


%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 4.0  ZM5 = 0
z0_4_0_x = -1*(1378.65e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_4_0_y = -1*(1640.27e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_4_0_x = sqrt(2054.1e-3*wl/pi);
w0_4_0_y = sqrt(2354.9e-3*wl/pi);

xBeam_4_0.targetWaist(w0_4_0_x,z0_4_0_x);
yBeam_4_0.targetWaist(w0_4_0_y,z0_4_0_y);

fprintf("X overlap for ZM4 = 4.0, ZM5 = 0: %f\n", xBeam_4_0.targetOverlap())
fprintf("Y overlap for ZM4 = 4.0, ZM5 = 0: %f\n",yBeam_4_0.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_4_zm4)
fprintf("ROC for ZM5 = %f\n", R_0_zm5)


%%  ZM4 = 4,  ZM5 = 2

xBeam_4_2 = beamPath;
yBeam_4_2 = beamPath;
xBeam_4_2.seedWaist(w0_x_4,z0_x_4);
yBeam_4_2.seedWaist(w0_y_4,z0_y_4);


%Build Path
xBeam_4_2.addComponent(component.curvedMirror(R_2_zm5*cosT_5,d45,'ZM5'))
yBeam_4_2.addComponent(component.curvedMirror(R_2_zm5/cosT_5,d45,'ZM5'))


%Figure out target q by back propagating from the beam profiler for Jun26th
%data

%ZM4 = 4.0  ZM5 = 2
z0_4_2_x = -1*(1200.63e-3 - 5.678)+d45; %Position of x waist, Z=0 is ZM4 location
z0_4_2_y = -1*(1492.9e-3 - 5.678)+d45; %Position of y waist, Z=0 is ZM4

wl = 1064e-9;
w0_4_2_x = sqrt(2196.53e-3*wl/pi);
w0_4_2_y = sqrt(2530.27e-3*wl/pi);

xBeam_4_2.targetWaist(w0_4_2_x,z0_4_2_x);
yBeam_4_2.targetWaist(w0_4_2_y,z0_4_2_y);

fprintf("X overlap for ZM4 = 4.0, ZM5 = 2: %f\n", xBeam_4_2.targetOverlap())
fprintf("Y overlap for ZM4 = 4.0, ZM5 = 2: %f\n",yBeam_4_2.targetOverlap())
fprintf("ROC for ZM4 = %f\n", R_4_zm4)
fprintf("ROC for ZM5 = %f\n", R_2_zm5)