% Offset DARM generates plots related to selecting the DARM
% offset for DC readout.  (This function has no arguments and
% no return values.)

function offsetDARM

  % prepare some variables
  sweepSetup

  nDC = nAS(1);
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % DARM sweep for AS power and signal as a function of DARM offset
  pos = zeros(opt.Noptic, 1);
  pos(nEX) = 5e-13;
  pos(nEY) = -5e-13;
  pos = pos * logspace(-1, 2, 200);
  
  [xPos, sigDC, fDC] = sweepDC(opt, pos);
  x = 2 * xPos(nEX, :);
  fDC = permute(fDC, [1 3 2]);
  
  %%%%%%%%%%%%%%%% Plot DARM signal

  % DARM signal, just a difference of DC values
  sd = [diff(sigDC(nDC, :)) ./ diff(x)];

  % shot noise, more or less, with some normalization
  ad = 5.92e10 * sqrt(sigDC(nDC, 2:end));

  % plot signal / noise ratio
  subplot('Position',[0.08,0.53,0.89,0.43]);
  semilogx(x(2:end) * 1e12, sd ./ ad)
  %xlabel('DARM offset [pm]')
  set(gca,'XTickLabel',[])
  title('DARM Shot Noise SNR (arbitrary units)')
  grid on
  axis([1e12*min(x) 1e12*max(x) 0 1])
  
  %%%%%%%%%%%%%%%% Plot AS port power
  subplot('Position',[0.08,0.06,0.89,0.43]);
  loglog(x * 1e12, sigDC(nDC, :),'b',...
         x * 1e12, sigDC(nPOX(1), :),'r')
  %loglog(x * 1e12, sigDC(nDC, :))
  title('AS DC (after OMC) and POX DC (100 ppm pick-off)')
  xlabel('DARM offset [pm]')
  ylabel('P_{AS} [W]')
  legend('AS DC', 'POX DC', 'Location', 'NorthWest');
  grid on
  grid minor
  axis([1e12*min(x) 1e12*max(x) min(sigDC(nDC,:)) max(sigDC(nDC,:))])
