function latency_summarizer(latencies_preinduc, latencies_postinduc, pscs_liveinterval_preinduc, pscs_liveinterval_postinduc, presentcase, figure_addon, latencies_by_epoch,...
    latencies_by_AP, latencies_by_contingency)
%description: used with the criteria measured from the start of the presyn I_Na measured in patchfile_analysis and stored as __criteria_for_latency
%called by: analyze_across_expts, analyze_across_sd_stdp_expts(deprecated)
%calls: cumulative_histogram, standard_err, rectangles_with_error_bars
%notes:
%code confirmed date:

%latencies=latencies/10; %converting from samples to ms
disp('Assuming sampling frequency of 10 kHz for latency plots')

epoch_clrz=['b' 'k'];
pulse_clrz=['r' 'g' 'b' 'k'];

meanlats_byepoch=[]; semlats_byepoch=[];
meanlats_bypulse=[]; semlats_bypulse=[];
rectangle_colors=[];

if latencies_by_epoch
    %plot latency of all the successful responses in the train, comparing before and after induction for each case
    figure(figure_addon+presentcase), hold on
    if ~isempty(latencies_preinduc)
        latspre=latencies_preinduc(:); latspre(~latspre)=[];   %zeroes in the latency matrices represent failures
        cumulative_histogram(latspre,epoch_clrz(1));set(gca,'ytick',[0 1])
        meanlats_byepoch(1)=mean(latspre); semlats_byepoch(1)=standard_err(latspre);
        rectangle_colors=[0;0;1];
    end
    if ~isempty(latencies_postinduc)
        latspost=latencies_postinduc(:); latspost(~latspost)=[];
        cumulative_histogram(latspost,epoch_clrz(2));set(gca,'ytick',[0 1])
        meanlats_byepoch(end+1)=mean(latspost); semlats_byepoch(end+1)=standard_err(latspost);
        rectangle_colors=[rectangle_colors [0;0;0]];
    end

    figure(figure_addon+presentcase+1000), hold on
    rectangles_with_error_bars(meanlats_byepoch,meanlats_byepoch+semlats_byepoch,meanlats_byepoch-semlats_byepoch,rectangle_colors,0,{})
    set(gca,'xtick',[])
end

if latencies_by_AP
    %plot latency of the first, second, third (and fourth if applicable) response each train for each case
    figure(figure_addon+presentcase+2000),hold on
    latencies=[latencies_preinduc latencies_postinduc]
    for presentpulse=1:size(latencies,1)
        latsbypulse=latencies(presentpulse,:);
        livelatsbypulse=latsbypulse(find(latsbypulse));
        cumulative_histogram(livelatsbypulse,pulse_clrz(presentpulse));set(gca,'ytick',[0 1])
        meanlats_bypulse(presentpulse)=mean(livelatsbypulse);
        semlats_bypulse(presentpulse)=standard_err(livelatsbypulse);
    end
    figure(figure_addon+presentcase+3000), hold on
    rectangles_with_error_bars(meanlats_bypulse,meanlats_bypulse+semlats_bypulse,meanlats_bypulse-semlats_bypulse,[1 0 0;0 1 0;0 0 1;0 0 0]',0,{})
    set(gca,'xtick',[])
end

if latencies_by_contingency
    %plot latency after the second AP in the train, if IPIa was 50 ms, comparing when latency_a(PSCo_succeeded) and latency_a(PSCo_failed) -- preinduction epoch only
    a=pscs_liveinterval_preinduc
    b=latencies_preinduc
    latencies_a_preinduc=latencies_preinduc(2,:)
    afteryes=latencies_a_preinduc(pscs_liveinterval_preinduc(1,:)==50 & latencies_preinduc(1,:))
    afterno=latencies_a_preinduc(pscs_liveinterval_preinduc(1,:)==50 & ~latencies_preinduc(1,:))
    afteryes(~afteryes)=[]
    afterno(~afterno)=[]
    
    figure(figure_addon+presentcase+4000), hold on
    cumulative_histogram(afteryes,'m');set(gca,'ytick',[0 1])
    cumulative_histogram(afterno,'c');set(gca,'ytick',[0 1])
end
