chans = {'H1:TCS-SIM_ITMX_SUB_DEFOCUS_SELF_OUTPUT.mean,m-trend', 'H1:TCS-SIM_ITMY_SUB_DEFOCUS_SELF_OUTPUT.mean,m-trend', ...
'H1:TCS-ITMX_HWS_PROBE_SPHERICAL_POWER.mean,m-trend', 'H1:TCS-ITMY_HWS_PROBE_SPHERICAL_POWER.mean,m-trend'};

t0 = 1141784000;
t1 = t0 + 6*3600;

filename = 'LVC_SIM_data.mat';
if exist(filename, 'file')
load(filename)
else
[data, t, ifno] = get_data(t0, t1, chans);
save(filename, 'data', 't', 'ifno');

end

% plot
close all
figure
subplot(2,1,1)
N0 = 150;
N1 = 180;
N2 = 320;
simX = data(N0:N2, 1) - mean(data(N0:N1, 1));
hwsX = data(N0:N2, 3) - mean(data(N0:N1, 3));
plot(hwsX*1E6, 'o')
hold all
%plot(simX*1E6*2)
plot(simX*1E6*2*0.475)
grid on
xlabel('Time (min)')
ylabel('Defocus (uD)')
title('Double-passed lens in H1:ITMX')
legend('HWS\_SPHERICAL\_POWER', 'SIM\_ITMX - DP - 250ppb');

subplot(2,1,2)
N0 = 150;
N1 = 180;
N2 = 320;
simY = data(N0:N2, 2) - mean(data(N0:N1, 2));
hwsY = data(N0:N2, 4) - mean(data(N0:N1, 4));
%plot(hwsY*1E6, 'o')
hold all
plot(smooth(hwsY*1E6,5), 'o')

hold all
plot(simY*1E6*2*0.7)
grid on
xlabel('Time (min)')
ylabel('Defocus (uD)')
title('Double-passed lens in H1:ITMY')
legend('HWS\_SPHERICAL\_POWER', 'SIM\_ITMY - DP - 280ppb');
%legend('HWS - smoothed', 'Simulation - 280ppb');

figure
subplot(2,1,1)
N0 = 150;
N1 = 180;
N2 = 320;
simX = data(N0:N2, 1) - mean(data(N0:N1, 1));
hwsX = data(N0:N2, 3) - mean(data(N0:N1, 3));
plot(hwsX*1E6, 'o')
hold all
plot(simX*1E6*2)
%plot(simX*1E6)
grid on
xlabel('Time (min)')
ylabel('Defocus (uD)')
title('Double-passed lens in H1:ITMX')
legend('HWS\_SPHERICAL\_POWER', 'SIM\_ITMX - DP');

subplot(2,1,2)
N0 = 150;
N1 = 180;
N2 = 320;
simY = data(N0:N2, 2) - mean(data(N0:N1, 2));
hwsY = data(N0:N2, 4) - mean(data(N0:N1, 4));
plot(hwsY*1E6, 'o')
hold all
%plot(smooth(hwsY*1E6,5), 'o')

hold all
plot(simY*1E6*2)
grid on
xlabel('Time (min)')
ylabel('Defocus (uD)')
title('Double-passed lens in H1:ITMY')
legend('HWS\_SPHERICAL\_POWER', 'SIM\_ITMY - DP');