close all 
clear all
clc

set(0,'DefaultLineLineWidth',2)
set(0,'DefaultAxesFontSize',16)
set(0,'DefaultAxesXGrid','on')
set(0,'DefaultAxesYGrid','on')
set(0,'DefaultAxesZGrid','on')

%%
printFigs = true;

dccNum = 'T0900450';
verNum = 'v5';

svnDir = '/ligo/svncommon/SeiSVN/seismic/';
ssnPath = [svnDir 'Common/MatlabTools/'];
figDir = [svnDir 'Common/Documents/T0900450_Sensor_Noise_estimates/'];

freq = logspace(-2,4,100);

figTag = [figDir dccNum '-' verNum '_sensor_noise_estimates'];

%%
sensorlist_disp = {'ADE_1mm','Kaman_IPSmeas','ADE_p25mm','Fine_Hugh'};

sensorlist_inert = {'L4C','T240meas','T360','T120H','T120C','GS13meas','Guralp_40T_spec'};

sensorlist_acc = {'PCB_356M132_spec','Wilcoxon_797L_spec'};

sensorlist_ifo = {'SPI_L','PICO','SmarAct','HoQI'};

sensorlist_rot = {'BRS','cBRS','CRS','SPI_PY'};

%%
addpath(ssnPath)

%%
dispASDs = [];
inertASDs = [];
accASDs = [];
ifoASDs = [];
rotASDs = [];

for iSensor = 1:length(sensorlist_disp)
    disp(iSensor).m_rtHz = SEI_sensor_noise(sensorlist_disp{iSensor},freq);
    dispASDs = [dispASDs disp(iSensor).m_rtHz(:)];
end

for jSensor = 1:length(sensorlist_inert)
    inert(jSensor).m_rtHz = SEI_sensor_noise(sensorlist_inert{jSensor},freq);
    inertASDs = [inertASDs inert(jSensor).m_rtHz(:)];
end

for kSensor = 1:length(sensorlist_acc)
    acc(kSensor).m_rtHz = SEI_sensor_noise(sensorlist_acc{kSensor},freq);
    accASDs = [accASDs acc(kSensor).m_rtHz(:)];
end

for lSensor = 1:length(sensorlist_ifo)
    ifo(lSensor).m_rtHz = SEI_sensor_noise(sensorlist_ifo{lSensor},freq);
    ifoASDs = [ifoASDs ifo(lSensor).m_rtHz(:)];
end

for mSensor = 1:length(sensorlist_rot)
    rot(mSensor).rad_rtHz = SEI_sensor_noise(sensorlist_rot{mSensor},freq);
    rotASDs = [rotASDs rot(mSensor).rad_rtHz(:)];
end

%%
figNum = 1;

figure(figNum)
figNames{figNum} = [figTag '_dispsensors.pdf'];
figNum = figNum+1;
ll = loglog(freq(:),dispASDs);
xlabel('Frequency [Hz]')
ylabel('Displacement [m/rtHz]')
axis([1e-2 1e2 1e-14 1e-7])
set(gca,'XTick',10.^(-2:2),'YTick',10.^(-14:-7))
legend('1mm gap MicroSense CPS',...
       '1mm gap Kaman IPS',...
       '0.25mm gap MicroSense CPS, aLIGO era',...
       '0.25mm gap MicroSense CPS, A+ era',...
       'Location','NorthEast')
title(['Noise Estimates for LIGO Displacement Sensors, ' dccNum '-' verNum])

%%
figure(figNum)
figNames{figNum} = [figTag '_inertsensors.pdf'];
figNum = figNum+1;
ll = loglog(freq(:),inertASDs);
xlabel('Frequency [Hz]')
ylabel('Displacement [m/rtHz]')
axis([1e-2 1e2 1e-14 1e-7])
set(gca,'XTick',10.^(-2:2),'YTick',10.^(-14:-7))
legend('Sercel L4C',...
       'Nanometrics T240',...
       'Nanometrics T360',...
       'Nanometrics T120H',...
       'Nanometrics T120C',...
       'GeoTech GS13',...
       'Guralp 40T',...
       'Location','NorthEast')
title(['Noise Estimates for LIGO Inertial Sensors, ' dccNum '-' verNum])


%%
figure(figNum)
figNames{figNum} = [figTag '_ifosensors.pdf'];
figNum = figNum+1;
ll = loglog(freq(:),ifoASDs);
xlabel('Frequency [Hz]')
ylabel('Displacement [m/rtHz]')
axis([1e-2 1e2 1e-14 1e-7])
set(gca,'XTick',10.^(-2:2),'YTick',10.^(-14:-7))
legend('MachZender IFO, AEI SPI (P2200259)',...
       'Michelson IFO, SmarAct PICOScale',...
       'Deep Frequency Modulation IFO, UBirmingham (P2200019)',...
       'Homodyne IFO, HoQI (P1700133)',...
       'Location','NorthEast')
title(['Noise Estimates for LIGO Interferometric Sensors, ' dccNum '-' verNum])

%%
figure(figNum)
figNames{figNum} = [figTag '_rotationsensors.pdf'];
figNum = figNum+1;
ll = loglog(freq(:),rotASDs);
xlabel('Frequency [Hz]')
ylabel('Displacement [rad/rtHz]')
axis([1e-2 1e2 1e-12 1e-7])
set(gca,'XTick',10.^(-2:2),'YTick',10.^(-12:-7))
legend('UWash Beam Rotation Sensor (BRS)',...
       'UWash Compact BRS (cBRS)',...
       'UWash Cylindrical Rotation Sensor, HoQI readout (CRS)',...
       'AEI Optical Lever Yaw (10m lever arm)',...
       'Location','NorthEast')
title(['Noise Estimates for LIGO Rotation Sensors, ' dccNum '-' verNum])



%%
figure(figNum)
figNames{figNum} = [figTag '_accsensors.pdf'];
figNum = figNum+1;
ll = loglog(freq(:),accASDs);
xlabel('Frequency [Hz]')
ylabel('Displacement [m/rtHz]')
axis([1e0 1e3 1e-14 1e-6])
set(gca,'XTick',10.^(-2:2),'YTick',10.^(-14:-6))
legend('PCB Piezotronics 356M132',...
       'Wilcoxon 797L',...
       'Location','NorthEast')
title(['Noise Estimates for LIGO Accelerometers, ' dccNum '-' verNum])

%%
if printFigs
    mergeCommand = ['pdfmerge ' figTag '.pdf'];
    
    for iFig = 1:length(figNames)
        figure(iFig)
        FillPage('w')
        IDfig
        saveas(gcf,figNames{iFig})
        
        mergeCommand = [mergeCommand ' ' figNames{iFig}];
    end
    
    system(mergeCommand);
end