close all
clear all
clc

%%
printFigs = true;

dataDir = '/Users/kissel/Desktop/scratch/2017LHOVent/BnK/TCSSteeringMirrors/';

fileNamesX = {'2017-11-30_H1TCSX_BSC2_SteeringMirror_Y_IFOY_Exc_Yresp.txt';...
              '2017-11-30_H1TCSY_BSC2_SteeringMirror_Y_IFOY_Exc_Yresp.txt'};
        
fileNamesY = {'2017-11-30_H1TCSX_BSC2_SteeringMirror_Z_IFOX_Exc_Zresp.txt';...
              '2017-11-30_H1TCSY_BSC2_SteeringMirror_Z_IFOX_Exc_Zresp.txt'};
          
X = 1;
Y = 2;

figTag = '2017-11-30_H1TCS_BSC2_SteeringMirrors_StructuralResonances_BandK';
          
%%
for iMirror = 1:2
    tcs(iMirror).IFO(1).rawData = load([dataDir fileNamesX{iMirror}]);
    tcs(iMirror).IFO(1).freq = tcs(iMirror).IFO(1).rawData(:,2);
    tcs(iMirror).IFO(1).tf   = tcs(iMirror).IFO(1).rawData(:,3) + 1i*tcs(iMirror).IFO(1).rawData(:,4);
    
    tcs(iMirror).IFO(2).rawData = load([dataDir fileNamesY{iMirror}]);
    tcs(iMirror).IFO(2).freq = tcs(iMirror).IFO(2).rawData(:,2);
    tcs(iMirror).IFO(2).tf   = tcs(iMirror).IFO(2).rawData(:,3) + 1i*tcs(iMirror).IFO(2).rawData(:,4);
end

%%
figure(1)
    subplot(211);
    loglog(tcs(X).IFO(Y).freq, abs(tcs(X).IFO(Y).tf),...
           tcs(Y).IFO(X).freq, abs(tcs(Y).IFO(X).tf));
xlim([10 400])   
ylim([1e-3 1e1])
legend('TCS X Mirror, IFO Y Direction',...
       'TCS Y Mirror, IFO X Direction',...
       'Location','NorthWest')
xlabel('Frequency / Hz') 
ylabel('Magnitude / (m.s^{-2}).N^{-2}')
title({'2017-11-30 H1 TCSX/TCSY Steering Mirror 2 (in BSC2) Structure Resonances';'Vibration Absorbers ON'})
set(gca,'YTick',10.^(-3:1),'XTick',10.^(1:3))
       
    subplot(212)
    loglog(tcs(X).IFO(X).freq, abs(tcs(X).IFO(X).tf),...
           tcs(Y).IFO(Y).freq, abs(tcs(Y).IFO(Y).tf))
legend('TCS X Mirror, IFO X Direction',...
       'TCS Y Mirror, IFO Y Direction',...
       'Location','NorthWest')
xlim([10 400])       
ylim([1e-3 1e1])
xlabel('Frequency / Hz') 
ylabel('Magnitude / (m.s^{-2}).N^{-2}')
set(gca,'YTick',10.^(-3:1),'XTick',10.^(1:3))

%%
figure(2)
    subplot(211);
    loglog(tcs(X).IFO(Y).freq, abs(tcs(X).IFO(Y).tf),...
           tcs(Y).IFO(X).freq, abs(tcs(Y).IFO(X).tf));
xlim([18 30])   
ylim([1e-3 1e1])
legend('TCS X Mirror, IFO Y Direction',...
       'TCS Y Mirror, IFO X Direction',...
       'Location','NorthWest')
xlabel('Frequency / Hz') 
ylabel('Magnitude / (m.s^{-2}).N^{-2}')
title({'2017-11-30 H1 TCSX/TCSY Steering Mirror 2 (in BSC2) Structure Resonances';'Vibration Absorbers ON, ZOOM'})
set(gca,'YTick',10.^(-3:1),'XTick',18:1:30)
       
    subplot(212)
    loglog(tcs(X).IFO(X).freq, abs(tcs(X).IFO(X).tf),...
           tcs(Y).IFO(Y).freq, abs(tcs(Y).IFO(Y).tf))
legend('TCS X Mirror, IFO X Direction',...
       'TCS Y Mirror, IFO Y Direction',...
       'Location','NorthWest')
xlim([18 30])       
ylim([1e-3 1e1])
xlabel('Frequency / Hz') 
ylabel('Magnitude / (m.s^{-2}).N^{-2}')
set(gca,'YTick',10.^(-3:1),'XTick',18:1:30)

%%
if printFigs
    figure(1)
    FillPage('w')
    IDfig(', J. Kissel')
    saveas(gcf,[dataDir figTag '.pdf'])
    
    figure(2)
    FillPage('w')
    IDfig(', J. Kissel')
    saveas(gcf,[dataDir figTag '_ZOOM.pdf'])
end