function [ T , til] = find_T_plus( bin_data, dt )
%FIND_T_plus: estimates the fraction of total recording time covered by the
% tiles Ät after each spike of spike train
% Inputs: 
%        bin_data, vector (1 x length of frames): spiketrain of neuron
%        dt, integer: time window in order to estimate the tiles_vectores
% Outputs: 
%        T, double: fraction of total recording time covered by the
%        tiles Ät after each spike of spike train
%        til, vector (1 x length of frames): spiketrain with 0 & 1
%        (0 -> no events, 1 -> marked frame, tile)

% Length of total recording time
len_bin =  length(bin_data);

% Indexes of spikes in bin_data
spikes_ids = find(bin_data == 1);
tiles = zeros(1, len_bin);

% For the case dt = 0
if(dt == 0)
    %tiles = bin_data;
    til = bin_data;
    T = sum(til) / len_bin;
else

    % Mark the moments
    for i=1:length(spikes_ids)
       % Mark the moment of the spike
       tiles(spikes_ids(i)) = 1;
       for j=1:dt
          % Mark previous moments
%           if((spikes_ids(i) - j) > 0)
%              tiles((spikes_ids(i) - j)) = 1;
%           end

          % Mark next moments
          if((spikes_ids(i) + j) <= len_bin)
             tiles((spikes_ids(i) + j)) = 1;
          end
       end

    end

    til = tiles;
    % Fraction T
    T = sum(tiles) / len_bin;
end

end


