coefdata
;CREATE THE INCIDENT SOLAR FLARE PHOTON FLUXES
;-------------------------------------------
;Read in Fluence file
file = loc_file(path=[curdir(),'SSWDB_HESSI','SSWDB_HESI')], 'hesi_spec.dat',count=file_count)
common hesi_spec, em, ftherm1, fbpow1, fnucl1, pi_not_en, pi_not_flux
em = 0
ftherm1 =0
fbpow1 = 0
fnucl1 = 0
pi_not_en = 0
pi_not_flux =0
ftherm3 = 0 ;ftherm3 is flux from Te=4. MK and EM=1e49cm-3, it is flux, not fluence
restore,/verbose,file(0) 
fcomp=ftherm1+fbpow1+fnucl1
fcomp_flux = fcomp/100. 	;divide by the time to get flux from fluence
fcomp_flux = fcomp_flux + interpol(pi_not_flux/100.,pi_not_en,em)
;-------------------------------------------
;-------------------------------------------
;Read in the HESSI background models and effective area curves for the Ge detectors
read_hesi_dat, evec, backs, effarea
;-------------------------------------------
;-------------------------------------------
;GE EFFECTIVE AREAS
hesi_grid_trans, etrans, trans, min_tran=min_trans
atrans = interpol(avg(trans,1), etrans, em)
atrans_min = interpol(avg(min_trans,1),etrans, em)
ge_tot_area = 12*!pi*3.55^2
min_area = 7./12.
ge_scale = ge_tot_area * atrans
;-------------------------------------------
;-------------------------------------------
;GE WINDOW ATTENUATION
read_seqfile,buff,loc_file(path=['SSWDB_HESI','SSWDB_HESSI'],'hesi_windows.dat')
ge_atten=fltarr(100,2)
iline=(where(strpos(buff,'100 attenuation') ne -1))(0)+1
reads, buff(iline:*), ge_atten
ge_atten=transpose(ge_atten)
ge_fil = interpol( (ge_atten(1,*))(*), (ge_atten(0,*))(*), em) < max(ge_atten(1,*))
;-------------------------------------------
;MAKE THE CUTOFFS BETWEEN THE SI, GE FRONT, AND GE BACK ENERGY RANGES
;lld cutoff
wlld = where( em le 10.)
w400 = where( em gt 400.)
;using array total peaks effective area (including escape and coincidence)
ge_front = interpol( effarea(0).(0)/ge_tot_area, evec*1000., em)
ge_total = interpol( effarea(8).(0)/ge_tot_area, evec*1000., em)
ge_rear = ge_total-ge_front
ge_front_effarea = ge_front*ge_scale*ge_fil
ge_rear_effarea  = ge_rear*ge_scale*ge_fil
ge_front_effarea_min = ge_front_effarea /atrans *atrans_min * min_area
ge_rear_effarea_min = ge_rear_effarea /atrans *atrans_min * min_area
ge_rear(wlld) = 0.0
ge_total(wlld) = 0.0
;Plot the front segment ge count rate
ge_front(wlld) = 0.0
ge_front(w400) = 0.0 
;SI DETECTORS
;-------------------------------------------
si_scale = 1/4.*12.
si_eff = 1-exp(-.2*xsec(em<999.,14,'pe'))
;Extract the attenuation coefficients for the Si detectors
iline=(where(strpos(buff,'Energies') ne -1))(0)+1
si_energ=fltarr(140)  
reads, buff(iline:*), si_energ
iline=(where(strpos(buff,'Effective area cm2') ne -1))(0)+2
si_eff_fil  =fltarr(140)  
reads, buff(iline:*), si_eff_fil
si_fil_energ =si_eff_fil/( 1-exp(-.2*xsec(si_energ,14,'pe')))
;take sharp edges out of filters here,  filter should really be applied inside
;comp_spec_calc.pro, but for the purposes of the proposal figure we can do it here.
em_smooth = findgen(200)*.25 +1.
si_fil = smooth( interpol( si_fil_energ, si_energ, em_smooth),8)
si_fil = interpol(si_fil, em_smooth, em)
w50 = where(em ge 50.)
si_eff(w50)=0.0
wlld_si = where( em lt 2.)
si_eff(wlld_si) = 0.0
si_eff_area = si_eff*si_scale*si_fil
si_eff_area_min = si_eff_area * min_area
if !d.name eq 'PS' then begin
	set_plot,'ps',/copy,file='effec-area-96.eps'
	device,/times,/bold,/portrait,/color,/encapsulated
	pfont=0
endif else pfont=-1
plot_oo, [1.,1e5],[9.9e-4,1e2],/nodata,/ysty,font=pfont,$
	charsize=1.5, xmargin=[12,4],$
	xtitle='Photon Energy', $
	ytitle='Total Effective Area (cm!u2!n)', $
	ytickname= ['10!u-3!n','10!u-2!n','10!u-1!n','10!u0!n ',$
           '10!u1!n ','10!u2!n '],$
        xtickname=['1','10','100 keV','1','10','100 MeV']
wfront = where( em gt 10. and ge_front_effarea gt 0.2)
oplot, em(wfront), ge_front_effarea(wfront), thick=10, color=9,/noclip
oplot, em(wfront), ge_front_effarea_min(wfront), thick=10, color=9, linestyle=2
oplot, em, thick=10, ge_rear_effarea,color=2
oplot, em, ge_rear_effarea_min,linestyle=2, color=2, thick=10
oplot, em, si_eff_area, thick=10, color=7 
oplot, em, si_eff_area_min, linestyle=2, thick=10, color=7 
        plots,[100.,300.],/data,10^(-1.+fltarr(2)),thick=8,color=9
        plots,[100.,300.],/data,10^(-1.5+fltarr(2)),thick=8,color=2
        plots,[100.,300.],/data,10^(-2.+fltarr(2)),thick=8,color=7
        plots,[100.,300.],/data,10^(-2.5+fltarr(2)),thick=8, linestyle=2
        xyouts,/data,400.,10^(-1.),'Ge Front Segments',chars=1.5,charth=1.5,font=pfont,$
         color=9
        xyouts,/data,400.,10^(-1.5), 'Ge Rear Segments',chars=1.5,charth=1.5,font=pfont,$
         color=2
        xyouts,/data,400.,10^(-2.0),'Silicon Detectors',chars=1.5,charth=1.5,font=pfont,$
         color=7
        xyouts,/data,400.,10^(-2.5), 'Minimum Science!cMission',chars=1.5,charth=1.5,font=pfont
end