PRO df_showfit,x,y,a,rms, $ sig,yfit, CHISQ = chisq @df_common ; 11/30/94 dd Modified for rms being scalar OR vector ; 11/30/94 dd Modified for fitting histogram: Gaussian area in counts ; 5/30/96 dd modified (?) for ghost line ; 6/17/98 dd add CHISQ as a keyword to return chisquared value IF (n_params() NE 6) THEN BEGIN print, ' showfit,x,y,a,rms,sig,yfit' print, ' x = x-vector' print, ' y = y-vector' print, ' a = parameters = height,ctr,disp,...,cont' print, ' sig = output array of parameter uncertainties' print, ' yfit = output fit y-vector' return ENDIF area=0.0 sigarea=0.0 ; Scale factor to go from Gaussian height/width to Number of counts ; assuming fitting a histogram ; assumes X is equally spaced. XperBin = x(1)-x(0) scale=sqrt(2.*!pi)/XperBin fmt='(i3,f10.3,f8.4,(f10.2,f10.3),(f10.4,f9.4),(f10.2,f10.3))' hfmt='(a3,a10,a8,(a10,a10),(a10,a9),(a10,a10))' print, ' ' print, ' Fitting results' print, ' ' print,'i','ctr','dctr','hght','dhght','sig','dsig','area','darea',format=hfmt for i=0,n_elements(a)-2,3 do begin areac = a(i)*a(i+2)*scale area = area + areac sigc = areac * sqrt( (sig(i)/a(i))^2 + (sig(i+2)/a(i+2))^2 ) sigarea= sigarea + areac^2 * (sig(i)^2/a(i)^2 + sig(i+2)^2/a(i+2)^2) print,i/3+1,a(i+1),sig(i+1),a(i),sig(i),a(i+2),sig(i+2),areac,sigc,format=fmt endfor print, ' ' ; Correct chi-square: chisq = total( (y-yfit)^2/(rms^2) ) / FLOAT(n_elements(yfit)-n_elements(a)) print, 'Cont=',a(n_elements(a)-1), 'dCont=',sig(n_elements(a)-1), $ 'Chisq=',chisq, format='(a7,F10.2, a10, F10.2,a14,F10.2)' print,'' if(n_elements(df_title) EQ 0) then df_title = 'Fitting with Gaussian(s) and Continuum' if(n_elements(df_xtitle) EQ 0) then df_xtitle = 'x' if(n_elements(df_ytitle) EQ 0) then df_ytitle = 'y' ; Setup character size for plots plt_c_size = 1.0 if(n_elements(!P.MULTI) EQ 5) then begin ; Scale size by square root of number of plots plt_c_size = 1.0/SQRT(1 > !P.MULTI(1)*!P.MULTI(2) ) end plot,x,y,PSYM=10, YRANGE = [-max(y)/3., max(y)], $ TITLE = df_title, XTITLE=df_xtitle, YTITLE=df_ytitle, $ CHARSIZE = plt_c_size oplot,x,yfit oplot,x,(y-yfit)-max(y)/6.,linestyle=3 oplot,x, 0.*x-max(y)/6.,linestyle=3 ; Spacing for plot labels ; These values work well for xyouts with /NORMAL specified ; but to do multiple plots convert to actual X,Y values. xledg = 0.65 x_space = 0.01 y_line = 0.90 y_space = 0.03 ; X conversion: xledg = xledg * (max(x)-min(x)) + min(x) x_space = x_space * (max(x)-min(x)) ; Y conversion y_line = y_line * (max(y) + max(y)/3.) - max(y)/3. y_space = y_space * (max(y) + max(y)/3.) xyouts, xledg, y_line, ' Total counts ='+ $ STRING(TOTAL(y),FORMAT='(F10.0)'), SIZE= plt_c_size y_line = y_line - (4./3.)*y_space xyouts, xledg-x_space, y_line, $ ' Peak FWHM Counts Error', SIZE= plt_c_size for i=0,n_elements(a)-2,3 do begin areac = a(i)*a(i+2)*scale sigc = areac * sqrt( (sig(i)/a(i))^2 + (sig(i+2)/a(i+2))^2 ) y_line = y_line - y_space xyouts, xledg-0.01, y_line, STRING(a(i+1),FORMAT='(F8.3)') + $ STRING(2.35*a(i+2),FORMAT='(F7.3)') + $ STRING(areac,FORMAT='(F10.0)') + STRING(sigc,FORMAT='(F9.0)'), $ SIZE= plt_c_size endfor y_line = y_line - 1.3*y_space xyouts, xledg+2.5*x_space, y_line, ' Continuum ='+ $ STRING(a(n_elements(a)-1),FORMAT='(F8.2)'), SIZE= plt_c_size y_line = y_line - 1.3*y_space xyouts, xledg+5.*x_space, y_line, ' Chi^2/v =' + $ STRING(chisq,FORMAT='(F6.2)'), SIZE= plt_c_size for i=0,n_elements(a)-3,3 do begin lgauss,x,a(i:i+2),g oplot,x,g,linestyle=3 endfor oplot,x,a(n_elements(a)-1)*df_continuum,linestyle=2 return end