;+
; PROJECT:
;	HESSI
; NAME:
;	HSI_ANNSEC_PSF
;
; PURPOSE:
;
;
; CATEGORY:
;
;
; CALLING SEQUENCE:
;
;
; CALLS:
;	HSI_ANNSEC_BPROJ, HSI_ANNSEC_PROFILE
;
; INPUTS:
;       Pixel
;	Modul_pattern_obj - object containing modulation patterns
;
; OPTIONAL INPUTS:
;	MAP_PTR - keyword only to be used in testing.  Normally modulation pattern maps are carried
;	in the hsi_modul_pattern object, but for testing purposes (see hsi_annsec_test.pro) they
;	are passed around through this keyword.
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	SUM - If set, sum the map over the detectors.
;	WEIGHT - If set, use the weighting function in the back projection.
;	THIS_DET_INDEX- detector index for single collimator/harmonic pair.
;	THIS_HARMONIC- harmonic index for single collimator/harmonic pair.
;	DET_INDEX_MASK - Specify array of collimators and harmonics. See hsi_calib_eventlist.
;
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	HSI_ANNSEC_PROFILE is used to generate count rates fed into HSI_ANNSEC_BPROJ for polar_map
;	pixels to obtain the point spread function.
;
; MODIFICATION HISTORY:
;	Version 1, richard.schwartz@gsfc.nasa.gov
;		31-mar-2000.
;
;-
function hsi_annsec_psf,  pixel, modul_pattern_obj,  $
	this_det_index=this_det_index, this_harmonic=this_harmonic, $
	map_ptr=map_ptr,  sum=sum, det_index_mask=det_index_mask, weight=weight

rmap_dim = -1
if size(/tname, modul_pattern_obj) eq 'OBJREF' then rmap_dim=modul_pattern_obj->get(/rmap_dim)

if total(rmap_dim) eq 0 then begin
	if size(/tname,map_ptr) ne 'POINTER' then $
	map_ptr = modul_pattern_obj->getdata(class_name='hsi_modul_pattern', $
	this_det_index=this_det_index, this_harmonic=this_harmonic, det_index_mask=det_index_mask)


	this_map_ptr = map_ptr
	if n_elements(this_map_ptr) gt 1 then begin
		case 1 of
	n_elements(det_index_mask) ge 1 : this_map_ptr=this_map_ptr( (where(det_index_mask))[0])
	else: begin
	id =0
	while size(/tname, * this_map_ptr[id]  ) ne 'STRUCT'   do  id=id+1
	this_map_ptr = this_map_ptr[id]


	end
	endcase
   endif
	rmap_dim = (*this_map_ptr).rmap_dim
	endif

if n_elements(pixel) eq 1 then ipix = pixel[0] else ipix = rmap_dim[0]*pixel[1]+ pixel[0]

inpsf = fltarr(rmap_dim[0], rmap_dim[1])
inpsf[ipix]=1.

psf9 = hsi_annsec_profile(inpsf, modul_pattern_obj,$
	this_det_index=this_det_index, this_harmonic=this_harmonic, $
	map_ptr=map_ptr,det_index_mask=det_index_mask)

return, hsi_annsec_bproj( data_ptr=psf9, modul_pattern_obj,$
	this_det_index=this_det_index, this_harmonic=this_harmonic, $
	map_ptr=map_ptr,sum=sum,$
	det_index_mask=det_index_mask, weight=weight)
end