#NAME:						Lance Simms, LLNL 2011
#  CalculateBackgroundFlux.py
#
#PUPROSE:
#  To calculate the background flux of gammas expected from the measurements 
#  in Moretti et al., 2008.  The calculation is done between 10-100 keV.
#
#######
import os
execfile(os.path.expanduser('~')+'/Desktop/Software/Python/CZTCubeSat/CZTCubeSatSetup.py')

#Here are the estimates for each bin
NumBins   = 10
EInterval = 100/NumBins
EBins     = (arange(NumBins)+1)*EInterval     #Energy bins in keV
CountBins = zeros(NumBins, dtype=float32)     #Count bins

#FOV of Detector
ColOpeningAngle_Degrees = 18
FOV_InSteradians = 2*pi*(1-cos(pi*ColOpeningAngle_Degrees/180))

#Area of detector
DetectorArea = 2 #cm^2

#Background Flux
BackgroundFlux = 0  #Number of counts/s/sr/cm^2
BackgroundHits = 0  #Number of counts/s

#Measurements taken from Moretti et al. 2008
FluxMeasurements = [40., 50., 50, 45, 40, 35, 32, 30, 28, 28]

#Print out the columns
print "Energy\tHits\t\tFlux"

for i,EBin in zip(arange(NumBins),EBins):
  FluxPerBin = FluxMeasurements[i]/(float(EBin*EBin))*EInterval
  HitsPerBin = FluxMeasurements[i]*FOV_InSteradians*DetectorArea/(EBin*EBin)*EInterval
  BackgroundHits += HitsPerBin
  BackgroundFlux += FluxPerBin 
  print str(EBin) + '\t' + str(HitsPerBin) + '\t' + str(FluxPerBin)

#Print out the total amount of hits
print "\nTotal Hits per Second-----"
print BackgroundHits
print "\nTotal Flux -----"
print BackgroundFlux
#
