;% Time-stamp: <97/05/19 17:07:28 dph> 
;% MIT Directory: ~dph/h1/HETG/Aeff_calc
;% CfA Directory: /proj/asc/dph/Aeff_calc
;% File: aciss_geometry
;% Author: D. Huenemoerder
;% Original version: 1995?
;                    % WARNING: uses system variables, !HEG_angle!,MEG_angle.
;%=====================================================================
; dd 10/3/97 
;----------------------------------------------------------------------
pro aciss_geometry, aciss_rgaps, aciss_lgaps

   aciss_offset =  6.047        ; mm from aim-point to array geometric center (y,z)=0
   
;;;; empirically calculated from XRCF MC test:
;   d_aciss_offset =  -0.724     ; offset aim-point for one xrcf obs
   d_aciss_offset =  0.0     ;     offset aim-point
   aciss_offset = aciss_offset+d_aciss_offset

   aciss_segment =  1024.*0.024       ; mm length of ACIS-S array segment
   aciss_gap = 0.43             ; mm

;   aciss_segment = mm size of ccd side
;   aciss_gap = mm separation of ccds
;   aciss_offset = mm aimpoint from chip edge
;   theta_heg

; OUTPUTS:
;   aciss_rgaps = mm array right-side gap boundaries:
;     0=> left edge of first
;     1=> right edge of first
;     2=> left edge of second
;     3=> right edge of second
;     4=> right edge of array
;
;   aciss_lgaps = mm array left-side gap boundaries
;     0=> right edge of first
;     1=> left edge of first
;     2=> right edge of second
;     etc
;     6=> left edge of array

; gaps are positions are along dispersion direction; 
; coordinates are "folded" so always positive distance from zero-order.

; allocate storage
; 
aciss_rgaps = fltarr(5)
aciss_lgaps = fltarr(7)

for ii = 0,4 do begin
  aciss_rgaps(ii) = (ii/2+1)*aciss_segment + ( (ii+1)/2)*aciss_gap - aciss_offset
endfor

for ii = 0,6 do begin
  aciss_lgaps(ii) = (ii/2)*aciss_segment + ( (ii+1)/2 )*aciss_gap + aciss_offset
endfor

;; assume symmetric - not strictly correct!
message, 'Assumes clocking angles symmetric!', /info
message, 'Clocking angle used is average of HEG and MEG', /info
ave_angle = 0.5*( ABS(!HEG_angle) + ABS(!MEG_angle) )
aciss_rgaps = aciss_rgaps / cos(ave_angle) ; sysvar from startup.
aciss_lgaps = -aciss_lgaps / cos(ave_angle)

END 


