clear all;
% transmissivity of BS, including 2nd beam from AR, is T0.
% reflectivity of BS, including 2nd beam from AR, is R0.
% Thorlabs PD sensitivity is A volt/W with 50dB gain, A/10 with 30dB gain.
% Power meter sensitivity (of analog out) is B volt/W with 300uW "range",
% 10B with 30uW "range".

% 1st measurement, PD in transmission with 50dB gain, PM in refl with 300uW
% range.
bT1=3.76; %bright Trans measured by Thorlabs
bR1=0.794; % bright Refl measured by power meter
dT1=51.3e-3; % dark Trans
dR1=59.3e-6; % dark Refl

T11=bT1-dT1; % If the total power impinging BS is P1, this is A*T0*P1.
R11=bR1-dR1; % and this is B*R0*P1.
TRRatioRaw1=T11/R11; % this is A*T0/B/R0.

% 2nd measurement, PD in REFL with 30dB gain, PM in trans with 30uW
% range.
bT2=.904; %bright Trans measured by power meter
bR2=3.51; % bright Refl measured by Thorlabs
dT2=.463e-3; % dark Trans
dR2=27e-3; % dark Refl

T22=bT2-dT2; % If the total power impinging BS is P2, this is 10B*T0*P2.
R22=bR2-dR2; % and this is A/10*R0*P2.
TRRatioRaw2=T22/R22; % This is 100*B*T0/A/R0.

T0R0Ratio=sqrt(TRRatioRaw1*TRRatioRaw2/100); %This is T0/R0.
% Assuming no loss, R0=1-T0, T0/(1-T0)=T0R0Ratio,
% T0=T0R0Ratio/(1+T0R0Ratio).
T0=T0R0Ratio/(1+T0R0Ratio); % T0=.0992
R0=1-T0; % R0=.9008

BARatio= sqrt(TRRatioRaw2/TRRatioRaw1/100); % this is B/A.

% Let's ignore 3rd beam due to AR of AR.
% R0=R1+T1^2*R2. where R1 is the reflectivity of the 1st surface etc.
% R1~R0=.9008
% T1~T0=.0992
% R2 is AR, let's assume it's less than 1% i.e. R2<1e-2.
% The 2nd beam term T1^2*R2 ~<T0^2*1e-2 = 9.8e-5 ~ 1e-4.
% This is totally negligible.

%%
% now, let's see how the above can be used to measure SFI1 back propagation
% throughput.
tpPM=(680e-3-(-154e-6)); 
% voltage out of the power meter placed right after TFP, 300uW range setting.
% this is equal to P*R1^2*tp*B volt where P is the power impinging BS and tp is
% the throughput, assuming that the retroreflector loss is negligible.

BSTrans=(3.77-50.1e-3);
% voltage out of the Thorlabs diode looking at BS transmission, 50dB gain.
% this is equal to P*T0*A.

% tpPM/BSTrans = R1^2*tp*B/T0/A, therefore
% tp = tpPM/BSTrans *T0/R1^2 *A/B
% but R1~R0.
tp_SFI1_retro = tpPM/BSTrans *T0/R0^2/BARatio;