# Note, obscurations come from private communication with Kawanomoto, Satoshi.
# These do *not* include filter exchange unit though, which instead come from
# Josh's estimates based on published drawings of the camera.
opticalSystem:
  type: CompoundOptic
  name: SubaruHSC
  inMedium: &air 1.0
  # implicit `outMedium: *air`, although nothings really gets through the Detector at the end
  # anyway
  medium: *air # subitems will use this as their default inMedium/outMedium
  # By not specifying a coordSys, the vertex/orientation of this CompoundOptic is implicitly
  # the global coordSys.
  backDist: 18.0  # distance from global vertex to use to start tracing rays
  sphereRadius: 10.0  # reference sphere radius to use for wavefront calculation
  pupilSize: 8.2  # Pupil fits inside a square with this side length
  pupilObscuration: 0.1  # Fractional pupil central obscuration
  stopSurface:
    type: Interface
    name: entrancePupil
    surface:
      type: Plane
    coordSys:
      z: 0.28015574385898623
  items:
    -
      type: Baffle
      name: POPT2
      surface:
        type: Plane
      coordSys:
        z: 16.5 # meters above primary mirror
      obscuration:
        type: ObscCircle
        radius: 0.96
    - type: Baffle # Josh's rough guess for the filter exchange unit
      name: FEU
      surface:
        type: Plane
      coordSys:
        z: 15.3
      obscuration:
        type: ObscRectangle
        width: 0.84
        height: 2.28
    -
      type: Baffle
      name: TopRing
      surface:
        type: Plane
      # We're going to place the vertex of the primary mirror at the global origin.
      # The top ring is ~14.5 meters above this
      coordSys:
        z: 14.55
      obscuration:
        type: ObscUnion
        items:
          -
            type: ClearAnnulus
            inner: 0.65
            outer: 4.3
          -
            type: ObscRay
            x: 0.45
            y: 0.45
            width: 0.18
            theta: 1.6880569547141775
          -
            type: ObscRay
            x: 0.45
            y: 0.45
            width: 0.18
            theta: -0.11726062791928082
          -
            type: ObscRay
            x: -0.45
            y: -0.45
            width: 0.18
            theta: 3.024332025670512
          -
            type: ObscRay
            x: -0.45
            y: -0.45
            width: 0.18
            theta: 4.829649608303971
    -
      type: Baffle
      name: BottomRing  # on the way down towards the PM
      surface:
        type: Plane
      coordSys:
        z: 13.55
      obscuration:
        type: ObscUnion
        items:
          -
            type: ObscCircle
            radius: 0.65
          -
            type: ObscRay
            x: 0.45
            y: 0.45
            width: 0.18
            theta: 1.6880569547141775
          -
            type: ObscRay
            x: 0.45
            y: 0.45
            width: 0.18
            theta: -0.11726062791928082
          -
            type: ObscRay
            x: -0.45
            y: -0.45
            width: 0.18
            theta: 3.024332025670512
          -
            type: ObscRay
            x: -0.45
            y: -0.45
            width: 0.18
            theta: 4.829649608303971
    -
      type: Baffle
      name: TertiarySpiderFirstPass  # on the way down towards the PM
      surface:
        type: Plane
      coordSys:
        z: 1.86
      obscuration:
        type: ObscUnion
        items:
          -
            type: ObscCircle
            radius: 0.65
          -
            type: ObscRay
            x: 0.45
            y: 0.45
            width: 0.18
            theta: 1.6880569547141775
          -
            type: ObscRay
            x: 0.45
            y: 0.45
            width: 0.18
            theta: -0.11726062791928082
          -
            type: ObscRay
            x: -0.45
            y: -0.45
            width: 0.18
            theta: 3.024332025670512
          -
            type: ObscRay
            x: -0.45
            y: -0.45
            width: 0.18
            theta: 4.829649608303971
    -
      type: Mirror
      name: PM
      surface:
        type: Quadric
        R: 30.0
        conic: -1.00835
      # We can omit coordSys here, since it defaults to be the same as the parent coordSys, which
      # is already what we want.
      # Naive outermost-allowed-radius parameterization
      obscuration:
        type: ClearAnnulus
        inner: 0.65
        outer: 4.1
    -
      type: Baffle
      name: TertiarySpiderSecondPass  # on the way back up towards camera
      surface:
        type: Plane
      coordSys:
        z: 1.86
      obscuration:
        type: ObscUnion
        items:
          -
            type: ObscCircle
            radius: 0.65
          -
            type: ObscRay
            x: 0.45
            y: 0.45
            width: 0.18
            theta: 1.6880569547141775
          -
            type: ObscRay
            x: 0.45
            y: 0.45
            width: 0.18
            theta: -0.11726062791928082
          -
            type: ObscRay
            x: -0.45
            y: -0.45
            width: 0.18
            theta: 3.024332025670512
          -
            type: ObscRay
            x: -0.45
            y: -0.45
            width: 0.18
            theta: 4.829649608303971
    -
      type: CompoundOptic
      name: HSC  # wide field corrector and camera considered together.
      coordSys:
        z: 13.4564
      # inherits medium from parent
      items:
        -
          type: CompoundOptic
          name: WFC  # wide field corrector
          items:
            -
              type: Lens
              name: G1
              # For a Lens, `medium` is the internal medium between the two refractive surfaces.  Note
              # that a Lens must have exactly two surfaces.
              medium: &silica
                type: TableMedium
                wavelengths: &waves [0.4e-6, 0.6e-6, 0.75e-6, 0.9e-6, 1.1e-6]
                ns: [1.47009272, 1.45801158, 1.45421013, 1.45172729, 1.44917721]
              items:
                -
                  type: RefractiveInterface
                  name: G1_entrance
                  surface:
                    type: Sphere
                    R: 0.76
                  obscuration:
                    type: ClearCircle
                    radius: 0.410
                -
                  type: RefractiveInterface
                  name: G1_exit
                  surface:
                    type: Asphere
                    R: 1.3755
                    conic: 0.0
                    coefs: [-0.14974887830730002, -0.07579068214673, -0.7705293869522001, 10.26626319251,
                      -70.78826218129001, 255.96006178059997, -376.1551480577999]
                  obscuration:
                    type: ClearCircle
                    radius: 0.410
                  coordSys:
                    z: 0.09718
            -
              type: Lens
              name: G2
              medium: &bsl7y
                type: TableMedium
                wavelengths: *waves
                ns: [1.53123287, 1.51671428, 1.51225242, 1.50939738, 1.50653251]
              # Note that this coordSys is wrt the parent.  I.e., not wrt the global coords, and also
              # not wrt the G1_exit coords given above, since those are at the same level in the
              # hierarchy.
              coordSys:
                z: 0.47003
              items:
                -
                  type: RefractiveInterface
                  name: G2_entrance
                  surface:
                    type: Asphere
                    R: -3.53
                    conic: 0.0
                    coefs: [0.06914718060975, 0.603728126364, -15.326231734619999, 361.8110894954,
                      -4741.677881169, 32173.090716919996, -88598.78091629999]
                  obscuration:
                    type: ClearCircle
                    radius: 0.320
                -
                  type: RefractiveInterface
                  name: G2_exit
                  coordSys:
                    z: 0.046
                  surface:
                    type: Sphere
                    R: 0.6562498974113357
                  obscuration:
                    type: ClearCircle
                    radius: 0.320
            -
              type: CompoundOptic
              name: ADC
              coordSys:
                z: 0.83403
              items:
              -
                type: Lens
                name: ADC1
                medium: *bsl7y
                items:
                  -
                    type: RefractiveInterface
                    name: ADC1_entrance
                    surface:
                      type: Plane
                    obscuration:
                      type: ClearCircle
                      radius: 0.310
                  -
                    type: RefractiveInterface
                    name: ADC1_exit
                    coordSys:
                      z: 0.04
                    surface:
                      type: Sphere
                      R: 1.058
                    obscuration:
                      type: ClearCircle
                      radius: 0.310
              -
                type: Lens
                name: ADC2
                coordSys:
                  z: 0.043
                medium: &pbl1y
                  type: TableMedium
                  wavelengths: *waves
                  ns: [1.57046066, 1.54784671, 1.54157395, 1.53789058, 1.53457169]
                items:
                  -
                    type: RefractiveInterface
                    name: ADC2_entrance
                    surface:
                      type: Sphere
                      R: 1.04
                    obscuration:
                      type: ClearCircle
                      radius: 0.310
                  -
                    type: RefractiveInterface
                    name: ADC2_exit
                    coordSys:
                      z: 0.082
                    surface:
                      type: Plane
                    obscuration:
                      type: ClearCircle
                      radius: 0.310
            -
              type: Lens
              name: G3
              coordSys:
                z: 1.23333
              medium: *pbl1y
              items:
                -
                  type: RefractiveInterface
                  name: G3_entrance
                  surface:
                    type: Asphere
                    R: -0.840000170144847
                    conic: 0.0
                    coefs: [2.768476102307, -48.556420092589995, 717.6113272765999, -10763.702614520002,
                      118744.32178099999, -798382.1197395, 2393556.961408]
                  obscuration:
                    type: ClearCircle
                    radius: 0.320
                -
                  type: RefractiveInterface
                  name: G3_exit
                  coordSys:
                    z: 0.04
                  surface:
                    type: Sphere
                    R: 9.8
                  obscuration:
                    type: ClearCircle
                    radius: 0.320
            -
              type: Lens
              name: G4
              coordSys:
                z: 1.36333
              medium: *bsl7y
              items:
                -
                  type: RefractiveInterface
                  name: G4_entrance
                  surface:
                    type: Asphere
                    R: 0.48
                    conic: 0.0
                    coefs: [-4.355533915492, 36.358679149130005, -595.1267151922, 7658.839741989, -71941.20343205,
                      394282.0924898, -954342.843455]
                  obscuration:
                    type: ClearCircle
                    radius: 0.314
                -
                  type: RefractiveInterface
                  name: G4_exit
                  coordSys:
                    z: 0.102
                  surface:
                    type: Sphere
                    R: 4.021759021137413
                  obscuration:
                    type: ClearCircle
                    radius: 0.314
            -
              type: Lens
              name: G5
              coordSys:
                z: 1.56553
              medium: *silica
              items:
                -
                  type: RefractiveInterface
                  name: G5_entrance
                  surface:
                    type: Sphere
                    R: 4.176748363640779
                  obscuration:
                    type: ClearCircle
                    radius: 0.308
                -
                  type: RefractiveInterface
                  name: G5_exit
                  coordSys:
                    z: 0.088
                  surface:
                    type: Asphere
                    R: -1.2728222984309576
                    conic: 0.0
                    coefs: [-1.064687616564, 3.377750239208, -110.26471335, 2282.368582236, -27430.39658171,
                      175577.1152898, -482194.9608578]
                  obscuration:
                    type: ClearCircle
                    radius: 0.308
        -
          type: CompoundOptic
          name: CAM  # wide field corrector
          coordSys:
            z: 1.7435712564515065
          items:
            -
              type: Lens
              name: F
              medium: *silica
              items:
                -
                  type: RefractiveInterface
                  name: F_entrance
                  surface:
                    type: Plane
                  obscuration:
                    type: ClearCircle
                    radius: 0.320
                -
                  type: RefractiveInterface
                  name: F_exit
                  coordSys:
                    z: 0.015
                  surface:
                    type: Plane
                  obscuration:
                    type: ClearCircle
                    radius: 0.320
            -
              type: Lens
              name: W
              coordSys:
                z: 0.0475
              medium: *silica
              items:
                -
                  type: RefractiveInterface
                  name: W_entrance
                  surface:
                    type: Plane
                  obscuration:
                    type: ClearCircle
                    radius: 0.310
                -
                  type: RefractiveInterface
                  name: W_exit
                  coordSys:
                    z: 0.037
                  surface:
                    type: Plane
                  obscuration:
                    type: ClearCircle
                    radius: 0.310
            -
              type: Detector
              name: D
              coordSys:
                z: 0.0995
              surface:
                type: Plane
              obscuration:
                type: ClearCircle
                radius: 0.310
