;plot_events
;
;PURPOSE:
;	This function takes in the Arr from return_events.pro to plot it in
;	postscript fashion

function plot_events,ReturnArr,TvFlag,Thickness,Pitch

;Different Color Schemes from X Window and .ps
White='FFFFFF'x
Black='000000'x
Red='0000FF'x
Green='00FF00'x
Blue='FF0000'x
Purple='FF00FF'x
Orange='0099FF'x

If TvFlag eq 1 then begin
   device,decompose=0		;Disable R+256*G+256^2*B
   loadct,39			;Load Rainbow+White Color Table
   ColorMultiplier=50.		
endif else begin
   ColorMultiplier=50.
endelse

Lambda1Arr=ReturnArr(0,*)
Lambda2Arr=ReturnArr(1,*)
EArr=ReturnArr(2,*)
FluxArr=ReturnArr(3,*)
TrackLength2DArr=ReturnArr(4,*)
TrackLength3DArr=ReturnArr(5,*)
PerpCountsArr=ReturnArr(6,*)
HitSizeArr=ReturnArr(7,*)
HitWidthArr=ReturnArr(8,*)
XExtentArr=ReturnArr(9,*)
YExtentArr=ReturnArr(10,*)
EventColor=ReturnArr(11,*)
Deltas=ReturnArr(12,*)
Worms=ReturnArr(13,*)

SpotIndices=where(ReturnArr(11,*) eq 0,NoSpots)
FakeStarIndices=where(ReturnArr(11,*) eq 1,NoFakeStars)
WormIndices=where(ReturnArr(11,*) eq 2,NoWorms)
DeltaIndices=where(ReturnArr(11,*) eq 3,NoDeltas)
StreakIndices=where(ReturnArr(11,*) eq 4,NoStreaks)
NoHits=N_elements(XExtentArr)
   
print,"Number of Spots     = ",NoSpots
print,"Number of Deltas    = ",NoDeltas
print,"Number of Muons     = ",NoStreaks
print,"Number of Worms     = ",NoWorms
print,"Number of FakeStars = ",NoFakeStars
print,"Total               = ",NoHits

;////////////////////////////////////////////////////////////////////////
;HISTOGRAMS AND SUCH
loadct,39
!p.multi=[0,1,1]
bar_plot,[NoSpots,NoFakeStars,NoDeltas,NoWorms,NoStreaks],$
         barnames=['Spots','Deltas','Worms','"Stars"','Muons','UnIdentified'],$
         title='Distribution of Events for Simulated Data',$
	 colors=[5*ColorMultiplier,1*ColorMultiplier,2*ColorMultiplier,$
		 3*ColorMultiplier,4*ColorMultiplier]
xyouts,0.5,0.90,'Thickness  ='+Strtrim(Thickness,2)+' Microns',/norm
xyouts,0.5,0.85,'Pitch      ='+Strtrim(Pitch,2)+' Microns',/norm

if TvFlag eq 1 then Stop
!p.multi=[0,2,2]
HitSizeHist=histogram(HitSizeArr,Nbins=25,locations=locHitSize)
plot,locHitSize,HitSizeHist,psym=10,title='Real Data Num pixels hit'
TrackLength3DHist=histogram(TrackLength3DArr,Nbins=10,$
                          locations=locTrack3DLength)
plot,locTrack3DLength,TrackLength3DHist,psym=10,title='TrackLength'
TrackLength2DHist=histogram(TrackLength2DArr,Nbins=15,$
                          locations=locTrack2DLength)
plot,locTrack2DLength,TrackLength2DHist,psym=10,title='TrackLength 2D'
HitWidthHist=histogram(HitWidthArr,Nbins=15,$
                          locations=locHitWidth)
plot,locHitWidth,HitWidthHist,psym=10,title='Track Width'
lambda1Hist=histogram(Lambda1Arr,Nbins=10,$
                      locations=locLambda1)
if TvFlag eq 1 then stop

plot,locLambda1,Lambda1Hist,psym=10,title='Real Data Lambda 1'
lambda2Hist=histogram(Lambda2Arr,Nbins=10,$
                      locations=locLambda2)
plot,locLambda2,Lambda2Hist,psym=10,title='Lambda 2'
lambda2Hist=histogram(Lambda2Arr,Nbins=10,$
                      locations=locLambda2)
plot,Lambda1Arr,Lambda2Arr,psym=2,xtitle='Lambda 1',ytitle='Lambda 2'
plot,lambda2arr,perpcountsarr*10^(-4.),psym=2,$
                      xtitle='Lambda 2',ytitle='Perp Counts'
If TvFlag eq 1 then stop
!p.multi=[0,1,1]

XVals=[0]
YVals=[0]
if SpotIndices(0) ne -1 then begin
  PerpCountsSpotHist=histogram(PerpCountsArr(SpotIndices)*10^(-4.),$
  NBins=20,locations=locPerpCountsSpots)
  XVals=[XVals,locPerpCountsspots]
  YVals=[YVals,max(PerpCountsSpotHist)]
endif
if StreakIndices(0) ne -1 then begin
 PerpCountsStreakHist=histogram(PerpCountsArr(StreakIndices)*10^(-4.),$
	Nbins=20,locations=locPerpCountsStreaks)
 XVals=[XVals,locPerpCountsStreaks]
 YVals=[YVals,max(PerpCountsStreakHist)]
endif
if WormIndices(0) ne -1 then begin
  PerpCountsWormHist=histogram(PerpCountsArr(WormIndices)*10^(-4.),$
        NBins=20,locations=locPerpCountsWorms)
  XVals=[XVals,locPerpCountsWorms]
  YVals=[YVals,max(PerpCountsWormHist)]
endif
if FakeStarIndices(0) ne -1 then begin
 PerpCountsStarHist=histogram(PerpCountsArr(FakeStarIndices)*10^(-4.),$
	NBins=20,locations=locPerpCountsStars)
  XVals=[XVals,locPerpCountsStars]
  YVals=[YVals,max(PerpCountsStarHist)]
endif

MaxX=max(XVals)
MaxY=max(YVals)
plot,[0,MaxX],[0,MaxY],/xstyle,/ystyle,/nodata,$
     xr=[0,MaxX],yr=[0,MaxY],ytitle='Perp Counts'
if SpotIndices(0) ne -1 then $
     oplot,locPerpCountsSpots,PerpCountsSpotHist,psym=10,$
     color=ColorMultiplier*0
if FakeStarIndices(0) ne -1 then $
     oplot,locPerpCountsStars,PerpCountsStarHist,psym=10,$
     color=ColorMultiplier*1
if StreakIndices(0) ne -1 then $
     oplot,locPerpCountsStreaks,PerpCountsStreakHist,psym=10,$
     color=ColorMultiplier*4
if WormIndices(0) ne -1 then $
     oplot,locPerpCountsWorms,PerpCountsWormHist,psym=10,$
     color=ColorMultiplier*2
xyouts,0.7,0.90,'Spot',color=0*ColorMultiplier,/normal
xyouts,0.7,0.85,'Fake Star',color=1*ColorMultiplier,/normal
xyouts,0.7,0.80,'Worm',color=2*ColorMultiplier,/normal
xyouts,0.7,0.75,'Delta',color=3*ColorMultiplier,/normal
xyouts,0.7,0.70,'Muon',color=4*ColorMultiplier,/normal

plot,lambda1arr,lambda2arr,psym=4,xrange=[0,50],yrange=[0,4],$
     Color=Black,Background=White,$
     xtitle='Lambda 1', ytitle='Lambda 2'

plots,lambda1arr,lambda2arr,psym=4,/data,color=ColorMultiplier*eventcolor
xyouts,0.7,0.90,'Spot',color=0*ColorMultiplier,/normal
xyouts,0.7,0.85,'Fake Star',color=1*ColorMultiplier,/normal
xyouts,0.7,0.80,'Worm',color=2*ColorMultiplier,/normal
xyouts,0.7,0.75,'Delta',color=3*ColorMultiplier,/normal
xyouts,0.7,0.70,'Muon',color=4*ColorMultiplier,/normal

If TvFlag eq 1 then stop
!p.multi=[0,1,1]
plot,lambda1arr,lambda2arr,psym=4,xrange=[0,500],yrange=[0,4],$
     Color=Black,Background=White,$
     xtitle='Lambda 1', ytitle='Lambda 2'

plots,lambda1arr,lambda2arr,psym=4,/data,color=ColorMultiplier*eventcolor
xyouts,0.7,0.90,'Spot',color=0*ColorMultiplier,/normal
xyouts,0.7,0.85,'Fake Star',color=1*ColorMultiplier,/normal
xyouts,0.7,0.80,'Worm',color=2*ColorMultiplier,/normal
xyouts,0.7,0.75,'Delta',color=3*ColorMultiplier,/normal
xyouts,0.7,0.70,'Muon',color=4*ColorMultiplier,/normal

If TvFlag eq 1 then stop
!p.multi=[0,1,1]
plot,lambda1arr,lambda2arr,psym=4,xrange=[0,5],yrange=[0,4],$
     Color=Black,Background=White,$
     xtitle='Lambda 1', ytitle='Lambda 2'
plots,lambda1arr,lambda2arr,psym=4,/data,color=ColorMultiplier*eventcolor
xyouts,0.7,0.90,'Spot',color=0*ColorMultiplier,/normal
xyouts,0.7,0.85,'Fake Star',color=1*ColorMultiplier,/normal
xyouts,0.7,0.80,'Worm',color=2*ColorMultiplier,/normal
xyouts,0.7,0.75,'Delta',color=3*ColorMultiplier,/normal
xyouts,0.7,0.70,'Muon',color=4*ColorMultiplier,/normal

If TvFlag eq 1 then stop
!p.multi=[0,1,1]
plot,XExtentArr,YExtentArr,psym=4,xrange=[0,5],yrange=[0,4],$
     Color=Black,Background=White,$
     xtitle='X Extent',ytitle='Y Extent'
plots,XExtentArr,YExtentArr,psym=4,/data,color=ColorMultiplier*eventcolor
xyouts,0.7,0.90,'Spot',color=0*ColorMultiplier,/normal
xyouts,0.7,0.85,'Fake Star',color=1*ColorMultiplier,/normal
xyouts,0.7,0.80,'Worm',color=2*ColorMultiplier,/normal
xyouts,0.7,0.75,'Delta',color=3*ColorMultiplier,/normal
xyouts,0.7,0.70,'Muon',color=4*ColorMultiplier,/normal

If TvFlag eq 1 then stop
!p.multi=[0,1,1]
plot,XExtentArr,YExtentArr,psym=4,xrange=[0,20],yrange=[0,20],$
     Color=Black,Background=White,$
     xtitle='X Extent',ytitle='Y Extent'
plots,XExtentArr,YExtentArr,psym=4,/data,color=ColorMultiplier*eventcolor
xyouts,0.7,0.90,'Spot',color=0*ColorMultiplier,/normal
xyouts,0.7,0.85,'Fake Star',color=1*ColorMultiplier,/normal
xyouts,0.7,0.80,'Worm',color=2*ColorMultiplier,/normal
xyouts,0.7,0.75,'Delta',color=3*ColorMultiplier,/normal
xyouts,0.7,0.70,'Muon',color=4*ColorMultiplier,/normal
if tvflag eq 2 then device,/close

set_plot,'x'
return,1

end

