function [ P, num_of_spikes, tot_com_id ] = find_P( spike_train, tiles )
%FIND_P estimates the fraction of firing events of spike_train occuring within a defined 
% interval Ät of firing events of another neuron  (tiles)


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

% Indexes of spikes in spike_train 
ids_data = find(spike_train == 1);

% Indexes of marked moments in tiles
ids_tiles = find(tiles ==1);

% Indexes of spikes that lies within dt of any spike from the marked
% frames in tile
tot_com_id = intersect(ids_data, ids_tiles);

num_of_spikes = length(tot_com_id);

% Fraction P
if(sum(spike_train) == 0)
    P = 0;
else
    P = length(tot_com_id) / sum(spike_train);
end


end

