pro histoplot,a,amean,asig,title=maintitle,chi=deg

	index=where(finite(a) eq 1)
	z=moment(a(index))
	Na=N_elements(a(index))
	print,z
	b=histogram(a(index),binsize=sqrt(z(1))/5.)

	print,Na

	
	mean=strreal(z(0))


	sig=strreal(sqrt(z(1)))


	
	
	Nb=N_elements(b)
	xx=findgen(Nb)*(max(a(index))-min(a(index)))/(Nb-1)+min(a(index))

	if (N_elements(deg) ne 0) then begin
	if (deg eq 2) then begin
		yy=exp(-xx)
	endif else begin
		yy=xx^(deg/2.-1)*exp(-xx*deg/2.)/gamma(deg/2.)/sqrt(2./deg)^deg
	endelse
	endif

	If (n_elements(maintitle) gt 0) then begin

		
		plot,xx,b,title=maintitle+', mean='+mean+', sigma='+sig,xtitle='Data',ytitle='Number of points'
		if (N_elements(deg) ne 0) then begin
			plot,xx,b,title=maintitle,xtitle='Data',ytitle='Number of points'
			print,'chi 2 dof=',deg
			yy=yy*total(b)/total(yy)
			oplot,xx,yy,linestyle=2
			zcumul=fltarr(Nb)
			for i=1,Nb-1 do begin
				zcumul(i)=int_tabulated(findgen(i+1),yy(0:i))
			endfor
			zcumul=zcumul/zcumul(Nb-1)
			print,'Kolmogorov test=',kolmo(a,zcumul,Nb,0)
		endif else begin
			oplot,xx,exp(-(xx-z(0))^2/2./z(1))*Na/sqrt(2*3.141592654)/5.,linestyle=2
		endelse

	
	endif else begin
		
		if (N_elements(deg) ne 0) then begin
			print,'chi 2 dof=',deg
			plot,xx,b,title='Histogram'+', mean='+mean+', sigma='+sig+', chi 2 dof='+strtrim(deg,1),xtitle='Data',ytitle='Number of points'
			yy=yy*total(b)/total(yy)
			oplot,xx,yy,linestyle=2
			Nx=N_elements(xx)
			zcumul=fltarr(Nb)
			for i=1,Nx-1 do begin
				zcumul(i)=int_tabulated(findgen(i+1),yy(0:i))
			endfor
			zcumul=zcumul/zcumul(Nb-1)
			print,'Kolmogorov test=',kolmo(a,zcumul,Nb,0)

		endif else begin
			plot,xx,b,title='Histogram'+', mean='+mean+', sigma='+sig,xtitle='Data',ytitle='Number of points'
			oplot,xx,exp(-(xx-z(0))^2/2./z(1))*Na/sqrt(2*3.141592654)/5.,linestyle=2
		endelse
	endelse
	amean=z(0)
	asig=sqrt(z(1))
end
