% This function calculates the value of the total detected photon count
% (normalized to source-emitted photons - Detect_total), within the 
% first 3.1cm from the center (minus the first 1mm around the center).
function [Detect_total] = Energy_analysis(r, Detecttot)

r = r(:)';
rhalf = 0;
[nspect, nr] = size(Detecttot); %nspect is a historical 
                                %residue. Apologies :">

if length(r)~=nr, error('Invalid Detecttot'); end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%calculate Detect_total and vector Detect_cumulative(r) that contains% 
%the total detected photon count within radius r                     %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Detect_cumulative(1) = 0;%exclude first 1mm
Detect_total = 0;
for k = 2:nr;
    Detect_cumulative(k) = Detect_cumulative(k-1)+Detecttot(k);
    if (k<=31); %only count photons within first 3.1cm.
    Detect_total = Detect_total+Detecttot(k);
    end;
end;


return 

