;plot_ellipticities
;
;PURPOSE:
;    This function will take an a 4x12xN array of filtered ellipticities and
;    elliptiticy angles, histogram them, and plot them.
;
;    
;INPUTS:
;    EllipticityArr:
;      EllipticityArr(0,k,*) = Ellipticities of High Pass Filtered at cutoff k
;      EllipticityArr(1,k,*) = Angles of High Pass Filtered at cutoff k
;      EllipticityArr(2,k,*) = Ellipticities of Low Pass Filtered at cutoff k
;      EllipticityArr(3,k,*) = Angles of Low Pass Filtered at cutoff k
;   
;    PlotStyle:
;      0 = Plot to X Windwow
;      1 = Plot a PNG file
;      
function plot_elliphistogram_ff,EHistFileName,SOARDataFileName,PlotStyle

readcol,EHistFileName,$
        LocE,EHist,LocTheta,ThetaHist,$
        format='f,f,f,f'
readcol,SOARDataFileName,$
        basename,uttime,date,frame_e,frame_e1,frame_e2,$
        frame_theta,phi_array,WSpeedArr,WDirArr,$
        PAltArr,PAzArr,xcenters,ycenters,xfcenters,yfcenters,$
        format='a,a,f,f,f,f,f,f,f,f,f,f,f,f,f,f'

ro=sort(uttime)
basename=basename(ro)
date=date(ro)
frame_e=frame_e(ro)
frame_e1=frame_e1(ro)
frame_e2=frame_e2(ro)
frame_theta=frame_theta(ro)
phi_array=phi_array(ro)
WSpeedArr=WSpeedArr(ro)
WDirArr=WDirArr(ro)
PAltArr=PAltArr(ro)
PAzArr=PAzArr(ro)
xcenter=xcenters(ro)
ycenters=ycenters(ro)
xfcenters=xfcenters(ro)
yfcenters=yfcenters(ro)


if PlotStyle eq 1 then begin
  set_plot,'z'
  erase
  device, set_font='Courier'
  device,set_resolution=[800,600]
  !p.charsize=1
  !p.charthick=1.2
  !x.thick=2
  !y.thick=2
  !p.thick=4
  !p.noerase=0
  loadct,39

  white='FFFFFF'x
  black='000000'x
  blue='FF0000'x
  red='0000FF'x
endif 

!p.multi=[0,1,1]

ThetaMin=-!pi/2
NoBins=20.
ThetaBinWidth=!pi/NoBins
ThetaMax=ThetaMin+(NoBins-1)*ThetaBinWidth
ThetaBinSize=(ThetaMax-ThetaMin)/(NoBins-1)

SOARThetaHist=histogram(Frame_Theta,Nbins=NoBins,locations=loc_theta,$
                 reverse_indices=theta_ind,$
                 max=thetamax,min=thetamin)

plot,LocTheta+ThetaBinSize/2,SOARThetaHist,psym=10,xtitle='Theta',$
     ytitle='Number of Events',xrange=[-1.6,1.6],$
     background=white,color=black
oplot,LocTheta+ThetaBinSize/2,ThetaHist,psym=10,linestyle=3,color=black

if PlotStyle eq 0 then stop
Emin=0                                     ;ELLIPTICITY
NoEBins=20.
EBinWidth=(1-Emin)/NoEBins
Emax=Emin+(NoEBins)*EBinWidth
Ebinsize=(Emax-Emin)/(NoEBins-1)

SOAREHist=histogram(Frame_E,Nbins=NoEbins,locations=loc_e,$
                 reverse_indices=e_ind,$
                 max=emax,min=emin)

plot,LocE,Ehist,psym=10,xtitle='e',$
     ytitle='Number of Events',$
     background=white,color=black,linestyle=3
oplot,LocE,SOAREHist,psym=10
if PlotStyle eq 0 then stop
return,1

end
