pks_00 = 0.628;
pks_20 = 0.036;
mode_matching = pks_00/(pks_00 + pks_20)
mode_mismatch = 1- mode_matching;

r_m1 = sqrt(0.93);  %from E2000155
r_m2 = sqrt(0.999);

refl_off_resonance = 1.01;
refl_dip_V = 1.01-0.056; %detla between off resonance and dip
refl_dips = refl_dip_V/refl_off_resonance;
P_mismatch = refl_off_resonance.* mode_mismatch;  %this is how much power is not matched to the 00 mode, so it needs to be subtracted from both on resonance and off resonance values
refl_dip_00 = (refl_dip_V-P_mismatch)./(refl_off_resonance-P_mismatch)  %this the reflection dip on resonance as % once mode mismatch is corrected for

%solve for the loss
syms rloss
s=solve((((r_m1-rloss)/(1-r_m1*rloss))/((r_m1+rloss)/(1+r_m1*rloss)))^2-refl_dip_00, rloss);

double(s).^2;
indx_high=find(double(s).^2<0.9999);  %solutions with R_loss >1 are not physical
indx=indx_high(find(double(s(indx_high)).^2>0.9));  %I think that the 0.88(or 0.03) solution is also probably not real

Rloss = double(s(indx).^2)
loss_not_M2 = (1-Rloss./r_m2.^2)*1e6

Tf = 1-r_m1^2;
Tloss = 1-Rloss.*r_m2^2;
eta_esc = log(r_m1^2)./log(r_m1^2.*Rloss)

