
%%
chan = {'H1:TCS-SIM_XARM_POWER.mean,s-trend',...
    'H1:TCS-SIM_YARM_POWER.mean,s-trend', ...
    'H1:TCS-SIM_ITMY_SUB_DEFOCUS_SELF_OUTPUT.mean,s-trend',...
    'H1:TCS-ITMY_HWS_PROBE_SPHERICAL_POWER.mean,s-trend'};
t0 = 1180224018 + 3600;
t1 = t0 + 5000;
[data,t,info] = get_data(t0, t1, chan, []);

close all
figure
subplot(1,1,1)
set(gca,'DefaultAxesFontSize', 16)
plot(data(:, 3)*1E6); hold all
HWS = data(:, 4)/2; % convert from double-pass measurement to single pass
HWS = HWS - mean(HWS(1700:1900));
plot(HWS*1E6);
grid on


diffL = [];
for scale1 = 1.0:0.05:5.0
    diff1 = HWS - data(:, 3)*scale1;
    rms1 = sqrt(sum(diff1(1700:end).^2));
    diffL = [diffL; scale1, rms1];
end
M0 = find(diffL(:, 2) == min(diffL(:, 2)));
scale0 = diffL(M0(1), 1)

plot(data(:,3)*scale0*1E6, '-k')

absorption = 2.8*scale0

xlabel('Time (s)')
ylabel('Defocus (uD)')
title('H1-HWSY single-pass measurement vs TCS SIM')
legend('TCS SIM - 280ppb (nominal)', ...
    'HWSY measurement - single-pass', ...
    ['TCS SIM - ', num2str(round(absorption*10)*10) ,'ppb (fit)'], ...
    'Location', 'NorthWest')
orient landscape
print('-dpdf', [mfilename(), '.pdf'])
