function [Ps,Ms,Ss]=detection_accuracy_by_sizebin(spd,pw)
%takes the spd data from simulated_psc_in_noise and a two-element vector providing the upper and lower limits of the 'proximal window'
%for all events whose true size lies within a bin, determines how many have delta times within the proximal window (i.e., low enough delta time value)
%and of those within the proximal window, finds the mean and SD of the *magnitude* of the delta time

DTs=spd(3,:)-spd(1,:);
trueamps=-1*spd(2,:);
Ps=[];Ms=[];Ss=[];
for bin=1:ceil(max(trueamps))
    liveamps=find(trueamps>=bin-1 & trueamps<bin);
    liveDTs=DTs(liveamps);
    %z=max(liveDTs),zz=min(liveDTs) %the range of possible DT values can be used to find likelihood of being within pw by chance 
    proximalliveDTs=liveDTs(find(liveDTs<=pw(1) & liveDTs>=pw(2)));
    P=length(proximalliveDTs)/length(liveDTs);
    Ps=[Ps P];
    M=mean(abs(proximalliveDTs));
    Ms=[Ms M];
    S=std(abs(proximalliveDTs));
    Ss=[Ss S];
end