% Optickle input file for Advanced Virgo
%
% Optical parameters tuned based on Bench 
% configuration of 26.06.2008
%
% Schnupp asymmetry optimized for SB2
%
% output ports powers tuned to have <~100 mW
% output mode cleaner simulated 
%      (single 10cm-long cavity, finesse=223)

function opt = adVirgo1_sd_hp

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % PARAMETERS
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  % input power 
  Pin = 125;
  
  % modulation frequencies
  fMod1 =  6270339.2;
  fMod2 = 81515709.5;
  fMod3 =  8360585.6;
  
  % Lengths
  Lcav  = 3000.0821;
  Lprc  =   11.953;
  Delta =    0.037;
  Lsrc  =   11.033;
  Lprbs =    5.980;
  
  % Mechanics
  w = 2 * pi * 0.6;      % pendulum resonance frequency
  mI = 40;               % mass of input mirror
  mE = 40;               % mass of end mirror
  mPRM = 30;
  mSRM = 30;
  mBS  = 35;
  dampRes = [0.001 + 1i, 0.001 - 1i];
  
  % mirror parameters
  tIMX = 0.007;
  tEMX = 5e-6;
  tIMY = 0.007;
  tEMY = 5e-6;
  tPRM = 0.06;
  tSRM = 0.11;
  tBS  = 0.5;
  
  rarBS  = 100e-6;
  rarIMX = 100e-6;
  rarIMY = 100e-6;
  
  lIMX = 40e-6;
  lEMX = 40e-6;
  lIMY = 40e-6;
  lEMY = 40e-6;
  lPRM = 40e-6;
  lSRM = 40e-6;
  lBS  = 40e-6;
  
  % Operating point
  offs_DARM  = 1e-11;       % DARM offset in meters
  tuning_SRC = 0.15;        % SRC tuning in radians
  
  % Demodulation phases
  ASYp_SB1_PHASE = 0;
  ASYp_SB2_PHASE = 0;
  ASYp_SB3_PHASE = 0;
  SYM_SB1_PHASE = 0;
  SYM_SB2_PHASE = 0;
  SYM_SB3_PHASE = 0;
  POBS_SB1_PHASE = 0;
  POBS_SB2_PHASE = 0;
  POBS_SB3_PHASE = 0;
  XP_SB1_PHASE = 0;
  XP_SB2_PHASE = 0;
  XP_SB3_PHASE = 0;
  YP_SB1_PHASE = 0;
  YP_SB2_PHASE = 0;
  YP_SB3_PHASE = 0;
  POX_SB1_PHASE = 0;
  POX_SB2_PHASE = 0;
  POX_SB3_PHASE = 0;
  POY_SB1_PHASE = 0;
  POY_SB2_PHASE = 0;
  POY_SB3_PHASE = 0;

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % create model
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  vFrf = [-fMod2, -fMod3, -fMod1, 0, fMod1, fMod3, fMod2];
  opt = Optickle(vFrf);
  
  % laser source (no IMC)
  opt = addSource(opt, 'Laser', sqrt(Pin) * (vFrf == 0));
  
  % Modulators
  gamma = 0.1;
  opt = addRFmodulator(opt, 'Mod1', fMod1, i * gamma);
  opt = addRFmodulator(opt, 'Mod2', fMod2, i * gamma);
  opt = addRFmodulator(opt, 'Mod3', fMod3, i * gamma);
  
  opt = addLink(opt, 'Laser', 'out', 'Mod1', 'in', 0.1);
  opt = addLink(opt, 'Mod1',  'out', 'Mod2', 'in', 0.1);
  opt = addLink(opt, 'Mod2',  'out', 'Mod3', 'in', 0.1);
  
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%% X cavity
  
  % input mirror with pick-off port
  opt = addBeamSplitter(opt, 'IMX_AR', 1, 0, 1-rarIMX, 0, 0);
  %                          angle, 1/Rcurv, THR,  LHR
  opt = addMirror(opt, 'IMX', 0,    1/1910, tIMX, lIMX);
  %                          angle, 1/Rcurv, THR,  LHR
  opt = addMirror(opt, 'EMX', 0,    1/1910, tEMX, lEMX);

  opt = addLink(opt, 'IMX_AR', 'bkA', 'IMX', 'bk', 0);
  opt = addLink(opt, 'IMX', 'bk', 'IMX_AR', 'bkB', 0);
  
  opt = addLink(opt, 'IMX', 'fr', 'EMX', 'fr', Lcav);
  opt = addLink(opt, 'EMX', 'fr', 'IMX', 'fr', Lcav);
  opt = setCavityBasis(opt, 'IMX', 'EMX');
  
  
  opt = setMechTF(opt, 'IMX', zpk([], -w * dampRes, 1 / mI));
  opt = setMechTF(opt, 'EMX', zpk([], -w * dampRes, 1 / mE));

  %%%%%%%%%%%%%%%%%%%%%%%%%%% Y cavity
  % input mirror with pick-off port
  opt = addBeamSplitter(opt, 'IMY_AR', 1, 0, 1-rarIMY, 0, 0);
  %                          angle, 1/Rcurv, THR,  LHR
  opt = addMirror(opt, 'IMY', 0,    1/1910, tIMY, lIMY);
  %                          angle, 1/Rcurv, THR,  LHR
  opt = addMirror(opt, 'EMY', 0,    1/1910, tEMY, lEMY);

  opt = addLink(opt, 'IMY_AR', 'bkA', 'IMY', 'bk', 0);
  opt = addLink(opt, 'IMY', 'bk', 'IMY_AR', 'bkB', 0);
  
  opt = addLink(opt, 'IMY', 'fr', 'EMY', 'fr', Lcav);
  opt = addLink(opt, 'EMY', 'fr', 'IMY', 'fr', Lcav);
  opt = setCavityBasis(opt, 'IMY', 'EMY');
  
  opt = setMechTF(opt, 'IMY', zpk([], -w * dampRes, 1 / mI));
  opt = setMechTF(opt, 'EMY', zpk([], -w * dampRes, 1 / mE));
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%% Recycling cavities
  % power recycling
  opt = addMirror(opt, 'PRM', 0, 0, tPRM, lPRM);
  % signal recycling
  opt = addMirror(opt, 'SRM', 0, 0, tSRM, lSRM);
  
  % beam splitter
  opt = addBeamSplitter(opt, 'BS', 45, 0, tBS, lBS, rarBS);
  
  opt = setMechTF(opt, 'PRM', zpk([], -w * dampRes, 1 / mPRM));
  opt = setMechTF(opt, 'SRM', zpk([], -w * dampRes, 1 / mSRM));
  opt = setMechTF(opt, 'BS',  zpk([], -w * dampRes, 1 / mBS));
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%% Links

  opt = addLink(opt, 'Mod3',  'out', 'PRM', 'bk', 1);
  
  opt = addLink(opt, 'PRM',  'fr',  'BS',  'frA', Lprbs);
  opt = addLink(opt, 'BS',   'frB', 'PRM', 'fr', Lprbs);
  
  opt = addLink(opt, 'SRM',  'fr',  'BS', 'bkA', Lsrc - (Lprc - Lprbs));
  opt = addLink(opt, 'BS',   'bkB', 'SRM', 'fr', Lsrc - (Lprc - Lprbs));
  
  opt = addLink(opt, 'BS',  'frA', 'IMY_AR', 'frA', (Lprc - Lprbs) - Delta/2);
  opt = addLink(opt, 'IMY_AR', 'frB',  'BS', 'frB', (Lprc - Lprbs) - Delta/2);
  
  opt = addLink(opt, 'BS',  'bkA', 'IMX_AR', 'frA', (Lprc - Lprbs) + Delta/2);
  opt = addLink(opt, 'IMX_AR', 'frB',  'BS', 'bkB', (Lprc - Lprbs) + Delta/2);
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%% Read-out optics (to reduce power)
  
  opt = addMirror(opt, 'XP_BS', 0, 0, 0.02);
  opt = addSink(opt, 'XP');
  opt = addLink(opt, 'EMX', 'bk', 'XP_BS', 'fr', 2);
  opt = addLink(opt, 'XP_BS', 'bk', 'XP', 'in', 2);
  
  opt = addMirror(opt, 'YP_BS', 0, 0, 0.02);
  opt = addSink(opt, 'YP');
  opt = addLink(opt, 'EMY', 'bk', 'YP_BS', 'fr', 2);
  opt = addLink(opt, 'YP_BS', 'bk', 'YP', 'in', 2);
  
  opt = addMirror(opt, 'SYM_BS', 0, 0, 0.03);
  opt = addSink(opt, 'SYM');
  opt = addLink(opt, 'PRM', 'bk', 'SYM_BS', 'fr', 2);
  opt = addLink(opt, 'SYM_BS', 'bk', 'SYM', 'in', 2);
  
  opt = addMirror(opt, 'POBS_BS', 0, 0, 0.75);
  opt = addSink(opt, 'POBS');
  opt = addLink(opt, 'BS', 'piB', 'POBS_BS', 'fr', 2);
  opt = addLink(opt, 'POBS_BS', 'bk', 'POBS', 'in', 2);
    
  opt = addMirror(opt, 'POX_BS', 0, 0, 0.7);
  opt = addSink(opt, 'POX');
  opt = addLink(opt, 'IMX_AR', 'frA', 'POX_BS', 'fr', 2);
  opt = addLink(opt, 'POX_BS', 'bk', 'POX', 'in', 2);
  
  opt = addMirror(opt, 'POY_BS', 0, 0, 0.7);
  opt = addSink(opt, 'POY');
  opt = addLink(opt, 'IMY_AR', 'frA', 'POY_BS', 'fr', 2);
  opt = addLink(opt, 'POY_BS', 'bk', 'POY', 'in', 2);
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%% ASY optics and OMC
  
  opt = addSink(opt, 'ASY');
  opt = addSink(opt, 'ASYs');
  opt = addSink(opt, 'ASYp');
  opt = addMirror(opt, 'ASY_BS', 0, 0, 0.99);
  opt = addLink(opt, 'SRM', 'bk', 'ASY_BS', 'fr', 2);
  opt = addLink(opt, 'ASY_BS', 'fr', 'ASYp', 'in', 2);
  
  opt = addMirror(opt, 'OMCin',  0, 0, 0.014);
  opt = addMirror(opt, 'OMCout', 0, 0, 0.014);
  opt = addMirror(opt, 'OMCend', 0, 0, 0);
  
  opt = addLink(opt, 'ASY_BS', 'bk', 'OMCin', 'bk', 1);
  opt = addLink(opt, 'OMCin', 'fr', 'OMCout', 'fr', 1e-3);
  opt = addLink(opt, 'OMCout', 'fr', 'OMCend', 'fr', 0.1);
  opt = addLink(opt, 'OMCend', 'fr', 'OMCin', 'fr', 0.1);
  
  opt = addLink(opt, 'OMCout', 'bk', 'ASY', 'in', 1);
  
  nOMC = getDriveIndex(opt, 'OMCend');
  opt = setDriveOffset(opt, nOMC, 1.064e-6 / 4);
  
  opt = addMirror(opt, 'ASYs_BS', 0, 0, 0.3);
  opt = addLink(opt, 'OMCin', 'bk', 'ASYs_BS', 'fr', 1);
  opt = addLink(opt, 'ASYs_BS', 'bk', 'ASYs', 'in', 1);
  
  
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%% Detectors
  opt = addProbeAt(opt, 'XP_DC', 'XP', 'in',  0, 0);
  opt = addProbeAt(opt, 'XP_SB1_P', 'XP', 'in',  fMod1, XP_SB1_PHASE); 
  opt = addProbeAt(opt, 'XP_SB1_Q', 'XP', 'in',  fMod1, XP_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'XP_SB2_P', 'XP', 'in',  fMod2, XP_SB2_PHASE); 
  opt = addProbeAt(opt, 'XP_SB2_Q', 'XP', 'in',  fMod2, XP_SB2_PHASE + 90); 
  opt = addProbeAt(opt, 'XP_SB3_P', 'XP', 'in',  fMod3, XP_SB3_PHASE); 
  opt = addProbeAt(opt, 'XP_SB3_Q', 'XP', 'in',  fMod3, XP_SB3_PHASE + 90); 
  
  opt = addProbeAt(opt, 'YP_DC',    'YP', 'in',  0, 0);
  opt = addProbeAt(opt, 'YP_SB1_P', 'YP', 'in',  fMod1, YP_SB1_PHASE); 
  opt = addProbeAt(opt, 'YP_SB1_Q', 'YP', 'in',  fMod1, YP_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'YP_SB2_P', 'YP', 'in',  fMod2, YP_SB2_PHASE); 
  opt = addProbeAt(opt, 'YP_SB2_Q', 'YP', 'in',  fMod2, YP_SB2_PHASE + 90); 
  opt = addProbeAt(opt, 'YP_SB3_P', 'YP', 'in',  fMod3, YP_SB3_PHASE); 
  opt = addProbeAt(opt, 'YP_SB3_Q', 'YP', 'in',  fMod3, YP_SB3_PHASE + 90); 
  
  opt = addProbeAt(opt, 'SYM_DC',    'SYM', 'in',  0, 0);
  opt = addProbeAt(opt, 'SYM_SB1_P', 'SYM', 'in',  fMod1, SYM_SB1_PHASE); 
  opt = addProbeAt(opt, 'SYM_SB1_Q', 'SYM', 'in',  fMod1, SYM_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'SYM_SB2_P', 'SYM', 'in',  fMod2, SYM_SB1_PHASE); 
  opt = addProbeAt(opt, 'SYM_SB2_Q', 'SYM', 'in',  fMod2, SYM_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'SYM_SB3_P', 'SYM', 'in',  fMod3, SYM_SB1_PHASE); 
  opt = addProbeAt(opt, 'SYM_SB3_Q', 'SYM', 'in',  fMod3, SYM_SB1_PHASE + 90); 
  
  opt = addProbeAt(opt, 'ASY_DC',    'ASY',  'in',  0, 0);
  opt = addProbeAt(opt, 'ASYs_DC',   'ASYs', 'in',  0, 0);
  
  opt = addProbeAt(opt, 'ASYp_DC',    'ASYp', 'in',  0, 0);
  opt = addProbeAt(opt, 'ASYp_SB1_P', 'ASYp', 'in',  fMod1, ASYp_SB1_PHASE); 
  opt = addProbeAt(opt, 'ASYp_SB1_Q', 'ASYp', 'in',  fMod1, ASYp_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'ASYp_SB2_P', 'ASYp', 'in',  fMod2, ASYp_SB1_PHASE); 
  opt = addProbeAt(opt, 'ASYp_SB2_Q', 'ASYp', 'in',  fMod2, ASYp_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'ASYp_SB3_P', 'ASYp', 'in',  fMod3, ASYp_SB1_PHASE); 
  opt = addProbeAt(opt, 'ASYp_SB3_Q', 'ASYp', 'in',  fMod3, ASYp_SB1_PHASE + 90); 
  
  opt = addProbeAt(opt, 'POBS_DC',    'POBS', 'in',  0, 0);
  opt = addProbeAt(opt, 'POBS_SB1_P', 'POBS', 'in',  fMod1, POBS_SB1_PHASE); 
  opt = addProbeAt(opt, 'POBS_SB1_Q', 'POBS', 'in',  fMod1, POBS_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'POBS_SB2_P', 'POBS', 'in',  fMod2, POBS_SB1_PHASE); 
  opt = addProbeAt(opt, 'POBS_SB2_Q', 'POBS', 'in',  fMod2, POBS_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'POBS_SB3_P', 'POBS', 'in',  fMod3, POBS_SB1_PHASE); 
  opt = addProbeAt(opt, 'POBS_SB3_Q', 'POBS', 'in',  fMod3, POBS_SB1_PHASE + 90); 
  
  opt = addProbeAt(opt, 'POX_DC',    'POX', 'in',  0, 0);
  opt = addProbeAt(opt, 'POX_SB1_P', 'POX', 'in',  fMod1, POX_SB1_PHASE); 
  opt = addProbeAt(opt, 'POX_SB1_Q', 'POX', 'in',  fMod1, POX_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'POX_SB2_P', 'POX', 'in',  fMod2, POX_SB1_PHASE); 
  opt = addProbeAt(opt, 'POX_SB2_Q', 'POX', 'in',  fMod2, POX_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'POX_SB3_P', 'POX', 'in',  fMod3, POX_SB1_PHASE); 
  opt = addProbeAt(opt, 'POX_SB3_Q', 'POX', 'in',  fMod3, POX_SB1_PHASE + 90); 
  
  opt = addProbeAt(opt, 'POY_DC',    'POY', 'in',  0, 0);
  opt = addProbeAt(opt, 'POY_SB1_P', 'POY', 'in',  fMod1, POY_SB1_PHASE); 
  opt = addProbeAt(opt, 'POY_SB1_Q', 'POY', 'in',  fMod1, POY_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'POY_SB2_P', 'POY', 'in',  fMod2, POY_SB1_PHASE); 
  opt = addProbeAt(opt, 'POY_SB2_Q', 'POY', 'in',  fMod2, POY_SB1_PHASE + 90); 
  opt = addProbeAt(opt, 'POY_SB3_P', 'POY', 'in',  fMod3, POY_SB1_PHASE); 
  opt = addProbeAt(opt, 'POY_SB3_Q', 'POY', 'in',  fMod3, POY_SB1_PHASE + 90); 
  
  % Set operating points
  nSRM = getDriveIndex(opt, 'SRM');
  nEMX = getDriveIndex(opt, 'EMX');
  nEMY = getDriveIndex(opt, 'EMY');
  opt = setDriveOffset(opt, nSRM, 1.064e-6 * (1 / 4 + tuning_SRC/(4*pi)));
  opt = setDriveOffset(opt, nEMX,  offs_DARM / 2);
  opt = setDriveOffset(opt, nEMY, -offs_DARM / 2);





