function [output_txt] =correl_hist(obj,event_obj,...
                      varargin,tw,znorm,signals,MeanCorrel,confint,HalfPeak, HPW,widths1,widths2,kindex)

pos = get(event_obj,'Position');
x = pos(1) ;y = pos(2);
% 
if znorm==1
    histYlabel='Z-Score';
else histYlabel='Counts/Bin';
end



totalstring= strcat('Total Count =  ',num2str(sum(varargin{x}(y,:))),'spikes');
HPWstring = strcat('Half Peak Width =  ',num2str(HPW(x,y)),'ms');
Kstring = strcat('K-Index =  ',num2str(kindex(x,y)));
legendnames={'Mean', '95% CI', HPWstring, totalstring, Kstring};


lag=-tw:tw;

figure(7);
set(gcf,'Name','selected unit-pair CCH');clf
title([signals(y).name ' X ' signals(x).name])
hold on
    
    p1=plot(lag,varargin{x}(y,:));
    if znorm==1
        p2=plot(lag,0,'k-')
    else
        p2=plot(lag,MeanCorrel{x}(y),'k-');
    end
    p3=plot(lag,confint{x}(y,1),'r-');
    p4=plot(lag,confint{x}(y,2),'r-');
    p5=plot((widths1(x,y)-1001):(widths2(x,y)-1001),HalfPeak(x,y),'g-');
    p6=plot(1,2,'w-');
    p7=plot(1,1,'w-');
    legend([p2(1),p3(1),p5(1),p6(1),p7(1)],legendnames, 'fontsize',8);

   
axis tight
xlabel('Time (ms)',...
    'fontsize', 14 ...
    ,'fontweight', 'bold');
ylabel(histYlabel,...
    'fontsize', 14 ...
    ,'fontweight', 'bold');
% waitforbuttonpress
output_txt={[signals(y).name ' X ' signals(x).name]};

% 
% wfbp=waitforbuttonpress
% if wfbp==0
% x = pos(1) ;y = pos(2);
% lag=-tw:tw;
% 
% % figure
% figure('NumberTitle','off',...
%        'Name',[signals(y).name ' X ' signals(x).name]);clf
%    hold on
%     p1=plot(lag,varargin{x}(y,:));
%     if znorm==1
%         plot(lag,0,'k-')
%     else
%     p2=plot(lag,MeanCorrel{x}(y),'k-');
%     end
%     p3=plot(lag,confint{x}(y,1),'r-');
%     p4=plot(lag,confint{x}(y,2),'r-');
%     p5=plot((widths1(x,y)-1001):(widths2(x,y)-1001),HalfPeak(x,y),'g-');
%     legend([p2(1),p3(1),p5(1),p6(1),p7(1)],legendnames, 'fontsize',8);
%     
% axis tight
% xlabel('Time (ms)',...
%     'fontsize', 14 ...
%     ,'fontweight', 'bold');
% ylabel(histYlabel,...
%     'fontsize', 14 ...
%     ,'fontweight', 'bold');
% end
% 
% 


% output_txt={['Unit: ',num2str(ysigs)]}
% time=x-basal
% output_txt{end+1}=['Time (s): ',num2str(time)]
% zvalue=IZ(y,x)
% output_txt{end+1} = ['Z-Score: ',num2str(zvalue)]
