
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% project_units_description
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MV

load('C:\Users\SB12FLPC006\Documents\MATLAB\MyToolbox\layerILines.mat');                   % load index
sessions = fieldnames(allSessions);

clear basepaths
for ii = 1:length(sessions)
    basepaths{ii} = ['D:' allSessions.(sessions{ii}).path];
end

% 1 EXPLORE SESSIONS AND CHECK CELL CLASSIFICATION (SAVE CHANGES AT THE END)
cell_metrics = loadCellMetricsBatch('basepaths',basepaths);
cell_metrics = CellExplorer('metrics',cell_metrics);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2 GENERATE SUMARY PLOTS

udR = []; upR = []; lightPulses = [];
for ii = 1:length(sessions)
    cd(basepaths{ii});
    fprintf(' **Session %3.i/ %3.i \n',ii, size(sessions,1)); %\n
    % get UD responses
    UDStates = detectUD;
    spikes = loadSpikes;
    ud = UDStates.timestamps.DOWN;
    [udccg, t_ud] = CCG([spikes.times ud],[],'binSize',0.01,'duration',1);
    udR = [udR; zscore(squeeze(udccg(:,end,1:end-1)))'];
    
    up = UDStates.timestamps.UP; 
    [upccg, t_up] = CCG([spikes.times up],[],'binSize',0.01,'duration',1);
    upR = [upR; zscore(squeeze(upccg(:,end,1:end-1)))'];
    
    % get pulses responses
    pulses = bz_getAnalogPulses;
    st = pulses.timestamps(:,1);
    [stccg, t_lr] = CCG([spikes.times st],[],'binSize',0.005,'duration',1);
    lightPulses = [lightPulses; zscore(squeeze(stccg(:,end,1:end-1)))'];
end
udResponses.udR = udR;
udResponses.upR = upR;
udResponses.timestamps = t_up;
optoTagResponses.events = lightPulses;
optoTagResponses.timestamps = t_lr;

% save(strcat(dropbox_path,'\DATA\databases\id2Dlx_pieces.mat'),'cell_metrics','udResponses','optoTagResponses');
% load(strcat(dropbox_path,'\DATA\databases\id2Dlx_pieces.mat'));

% 0. DETECT TAGGED CELLS
% artifactSamples = [101; 121];
% % interpolate artifact samples
% for ii = 1:length(artifactSamples)
%     idx = artifactSamples(ii) + [-5:-1 1:5];
%     for jj = 1:size(optoTagResponses.events,1)
%         optoTagResponses.events(jj,artifactSamples(ii)) = interp1(idx,optoTagResponses.events(jj,idx),artifactSamples(ii));
%     end
% end
% smoothing signal
for ii = 1:length(optoTagResponses.events)
    optoTagResponses.eventsSmooth(ii,:) = smooth(optoTagResponses.events(ii,:) - mean(optoTagResponses.events(ii,optoTagResponses.timestamps < 0)),5);
end

% find responsive cells % 5 x 3
optoTagResponses.value = mean(optoTagResponses.events(:,optoTagResponses.timestamps > 0 & optoTagResponses.timestamps < 0.05),2);
[~, sortResponses] = sort(optoTagResponses.value);
figure;
subplot(1,2,1)
imagesc(optoTagResponses.timestamps,[1:size(optoTagResponses.events,1)],optoTagResponses.eventsSmooth(sortResponses,:)); caxis([-3 3]);
xlim([-.1 .4]); colormap(jet); ylabel('Cells'); xlabel('Time [s]'); set(gca, 'TickDir','out');
subplot(1,2,2)
hold on
histogram(optoTagResponses.value,'FaceColor', [.6 .6 .6], 'LineStyle','none');
plot([1.96 1.96], [0 100],'r'); 
ylabel('Cells [#]'); xlabel('Light response [SD]'); set(gca, 'TickDir','out');
optoTagCells = find(optoTagResponses.value > 1.96);

cell_metrics.putativeCellType{[32]} = 'Wide Interneuron';
cell_metrics.putativeCellType{[52]} = 'Wide Interneuron';
cell_metrics.putativeCellType{[71]} = 'Wide Interneuron';
cell_metrics.putativeCellType{[91]} = 'Wide Interneuron';
cell_metrics.putativeCellType{[255]} = 'Wide Interneuron';
cell_metrics.putativeCellType{[270]} = 'Wide Interneuron';

% 1. CELLS CLASIFICATION % 5 x 3
pyr_color = [.8 .2 .2]; pyr_color_light = [1 .8 .8];
nw_color = [.2 .2 .8]; nw_color_light = [.8 .8 1];
ww_color = [.2 .8 .8]; ww_color_light = [.8 1 1];
cellType = [];
for ii = 1:length(cell_metrics.putativeCellType)
    if strcmpi(cell_metrics.putativeCellType{ii}, 'Pyramidal Cell')
        cellType(ii) = 1;
    elseif strcmpi(cell_metrics.putativeCellType{ii}, 'Narrow Interneuron')
        cellType(ii) = 2;
    elseif strcmpi(cell_metrics.putativeCellType{ii}, 'Wide Interneuron')
        cellType(ii) = 3;
    else
        cellType(ii) = 4;
    end
end
pyr = find(cellType == 1);
nwInt = find(cellType == 2);
wwInt = find(cellType == 3);

figure
hold on
s1 = scatter(cell_metrics.troughToPeak(pyr), cell_metrics.burstIndex_Royer2012(pyr),cell_metrics.firingRate(pyr)*10,'o','MarkerFaceColor',...
    pyr_color,'MarkerFaceAlpha',[.3], 'MarkerEdgeColor','none');
s2 = scatter(cell_metrics.troughToPeak(nwInt), cell_metrics.burstIndex_Royer2012(nwInt),cell_metrics.firingRate(nwInt)*10,'o','MarkerFaceColor',...
    nw_color,'MarkerFaceAlpha',[.3], 'MarkerEdgeColor','none');
s3 = scatter(cell_metrics.troughToPeak(wwInt), cell_metrics.burstIndex_Royer2012(wwInt),cell_metrics.firingRate(wwInt)*10,'o','MarkerFaceColor',...
    ww_color,'MarkerFaceAlpha',[.3], 'MarkerEdgeColor','none');
s4 = scatter(cell_metrics.troughToPeak(optoTagCells), cell_metrics.burstIndex_Royer2012(optoTagCells),200,'o','MarkerFaceAlpha',[1], 'MarkerEdgeColor',[0 0 0],'LineWidth',1);
set(gca,'YScale','log','TickDir','out'); ylabel('Burst Index [au]'); xlabel('Spike duration [ms]');
legend([s1 s2 s3 s4], 'Pyramidal', 'Narrow-Wavef Int', 'Wide-Wavef Int', 'Ndnf');

% 1.1 WAVEFORM 6 x 2
waveforms_timestmaps = cell_metrics.waveforms.time{1};
cell_metrics.waveforms.filt_zscored = zscore(cell2mat(cell_metrics.waveforms.filt'),[],2)';
figure
subplot(1,3,1)
plotFill(waveforms_timestmaps, cell_metrics.waveforms.filt_zscored(:,pyr),'color',pyr_color);
plotFill(waveforms_timestmaps, cell_metrics.waveforms.filt_zscored(:,nwInt),'color',nw_color);
plotFill(waveforms_timestmaps, cell_metrics.waveforms.filt_zscored(:,wwInt),'color',ww_color);
axis tight; xlabel('Time [ms]'); ylabel('Amplitude [SD]'); set(gca, 'TickDir', 'out');

subplot(1,3,2)
hold on
plot(waveforms_timestmaps, mean(cell_metrics.waveforms.filt_zscored(:,pyr),2),'--','color',pyr_color_light);
plot(waveforms_timestmaps, mean(cell_metrics.waveforms.filt_zscored(:,nwInt),2),'--','color',nw_color_light);
plot(waveforms_timestmaps, mean(cell_metrics.waveforms.filt_zscored(:,wwInt),2),'--','color',ww_color_light);
plot(waveforms_timestmaps, cell_metrics.waveforms.filt_zscored(:,optoTagCells),'k');
axis tight; xlabel('Time [ms]'); ylabel('Amplitude [SD]'); set(gca, 'TickDir', 'out');
title('Ndnf','FontWeight','normal');

subplot(1,3,[3])
gs = groupStats({cell_metrics.troughToPeak(pyr), cell_metrics.troughToPeak(nwInt), cell_metrics.troughToPeak(wwInt), cell_metrics.troughToPeak(optoTagCells)},[],...
    'inAxis',true,'labelSummary',false,'color',[pyr_color; nw_color; ww_color; 0 0 0]);
ylabel('Spike dur [ms]');
set(gca,'XTick',[1 2 3 4], 'XTickLabel', {'Pyr', 'NW', 'WW', 'Ndnf'},'XTickLabelRotation',90);

% 1.2 ACG 6 X 2
cell_metrics.acg.narrow_normalized = cell_metrics.acg.narrow;
acg_timestmaps = linspace(-50,50, size(cell_metrics.acg.narrow_normalized,1));
for ii = 1:size(cell_metrics.acg.narrow_normalized,2)
    cell_metrics.acg.narrow_probability(:,ii) = cell_metrics.acg.narrow(:,ii)/sum(cell_metrics.acg.narrow(:,ii));
end

figure
subplot(1,3,1)
plotFill(acg_timestmaps, cell_metrics.acg.narrow_probability(:,pyr),'color',pyr_color,'smoothOpt',5);
plotFill(acg_timestmaps, cell_metrics.acg.narrow_probability(:,nwInt),'color',nw_color,'smoothOpt',5);
plotFill(acg_timestmaps, cell_metrics.acg.narrow_probability(:,wwInt),'color',ww_color,'smoothOpt',5);
axis tight; xlabel('Time [ms]'); ylabel('Prob'); set(gca, 'TickDir', 'out');

subplot(1,3,2)
hold on
plot(acg_timestmaps, smooth(mean(cell_metrics.acg.narrow_probability(:,pyr),2),8),'--','color',pyr_color_light);
plot(acg_timestmaps, smooth(mean(cell_metrics.acg.narrow_probability(:,nwInt),2),8),'--','color',nw_color_light);
plot(acg_timestmaps, smooth(mean(cell_metrics.acg.narrow_probability(:,wwInt),2),8),'--','color',ww_color_light);
for ii = 1:length(optoTagCells) 
    plot(acg_timestmaps, smooth(cell_metrics.acg.narrow_probability(:,optoTagCells(ii)),5),'k');
end
axis tight; xlabel('Time [ms]'); ylabel('Prob'); set(gca, 'TickDir', 'out');

subplot(1,3,[3])
groupStats({cell_metrics.acg_tau_rise(pyr), cell_metrics.acg_tau_rise(nwInt), cell_metrics.acg_tau_rise(wwInt), cell_metrics.acg_tau_rise(optoTagCells)},[],...
    'inAxis',true,'labelSummary',false,'color',[pyr_color; nw_color; ww_color; 0 0 0]);
ylabel('T rise [ms]');
set(gca,'XTick',[1 2 3 4], 'XTickLabel', {'Pyr', 'NW', 'WW', 'Ndnf'},'XTickLabelRotation',90);

% 2. FIRING RATE
x_values = log10(10E-2:0.1:10E1);
fr = log10(cell_metrics.firingRate);
figure
hold on
pd = fitdist(fr(pyr)','Kernel');
y_values = pdf(pd,x_values); y_values = y_values/sum(y_values);
area(x_values, y_values,'EdgeColor',pyr_color,'FaceColor',pyr_color,'FaceAlpha',.5);
pd = fitdist(fr(nwInt)','Kernel');
y_values = pdf(pd,x_values); y_values = y_values/sum(y_values);
area(x_values, y_values,'EdgeColor',nw_color,'FaceColor',nw_color,'FaceAlpha',.5);
pd = fitdist(fr(wwInt)','Kernel');
y_values = pdf(pd,x_values); y_values = y_values/sum(y_values);
area(x_values, y_values,'EdgeColor',ww_color,'FaceColor',ww_color,'FaceAlpha',.5);
ylabel('Prob'); xlabel('Firing rate [Hz]');
hold on
plot(fr(optoTagCells),randsample(0.01:0.001:0.018,length(optoTagCells)),'ok','MarkerFaceColor','k');
set(gca,'TickDir','out'); LogScale('x',10);

% 2.1 FIRING RATE ACROSS STATES
figure
hold on
plot([2:5],[nanmedian(cell_metrics.firingRate_WAKEstate(pyr)) nanmedian(cell_metrics.firingRate_NREMepisode(pyr)) nanmedian(cell_metrics.firingRate_REMstate(pyr)) nanmedian(cell_metrics.firingRate(pyr))],'color',pyr_color);
% plot([1 1],quantile(frate.all(pyr),[0.25 0.75]),'color',pyr_color); 
plot([2 2],quantile(cell_metrics.firingRate_WAKEstate(pyr),[0.25 0.75]),'color',pyr_color);
plot([3 3],quantile(cell_metrics.firingRate_NREMstate(pyr),[0.25 0.75]),'color',pyr_color); 
plot([4 4],quantile(cell_metrics.firingRate_REMstate(pyr),[0.25 0.75]),'color',pyr_color);
plot([5 5],quantile(cell_metrics.firingRate(pyr),[0.25 0.75]),'color',pyr_color);
plot([2:5],[nanmedian(cell_metrics.firingRate_WAKEstate(pyr)) nanmedian(cell_metrics.firingRate_NREMepisode(pyr)) nanmedian(cell_metrics.firingRate_REMstate(pyr)) nanmedian(cell_metrics.firingRate(pyr))],...
    'o','color',pyr_color,'MarkerFaceColor',pyr_color_light,'MarkerEdgeColor',pyr_color,'MarkerSize',15);
% int nw
plot([2:5]+0.1,[nanmedian(cell_metrics.firingRate_WAKEstate(nwInt)) nanmedian(cell_metrics.firingRate_NREMepisode(nwInt)) nanmedian(cell_metrics.firingRate_REMstate(nwInt)) nanmedian(cell_metrics.firingRate(nwInt))],'color',nw_color);
% plot([1 1],quantile(frate.all(pyr),[0.25 0.75]),'color',pyr_color); 
plot([2 2]+0.1,quantile(cell_metrics.firingRate_WAKEstate(nwInt),[0.25 0.75]),'color',nw_color);
plot([3 3]+0.1,quantile(cell_metrics.firingRate_NREMstate(nwInt),[0.25 0.75]),'color',nw_color); 
plot([4 4]+0.1,quantile(cell_metrics.firingRate_REMstate(nwInt),[0.25 0.75]),'color',nw_color);
plot([5 5]+0.1,quantile(cell_metrics.firingRate(nwInt),[0.25 0.75]),'color',nw_color);
plot([2:5]+0.1,[nanmedian(cell_metrics.firingRate_WAKEstate(nwInt)) nanmedian(cell_metrics.firingRate_NREMepisode(nwInt)) nanmedian(cell_metrics.firingRate_REMstate(nwInt)) nanmedian(cell_metrics.firingRate(nwInt))],...
    'o','color',nw_color,'MarkerFaceColor',nw_color_light,'MarkerEdgeColor',nw_color,'MarkerSize',15);
% int ww
plot([2:5]+0.2,[nanmedian(cell_metrics.firingRate_WAKEstate(wwInt)) nanmedian(cell_metrics.firingRate_NREMepisode(wwInt)) nanmedian(cell_metrics.firingRate_REMstate(wwInt)) nanmedian(cell_metrics.firingRate(wwInt))],'color',ww_color);
% plot([1 1],quantile(frate.all(pyr),[0.25 0.75]),'color',pyr_color); 
plot([2 2]+0.2,quantile(cell_metrics.firingRate_WAKEstate(wwInt),[0.25 0.75]),'color',ww_color);
plot([3 3]+0.2,quantile(cell_metrics.firingRate_NREMstate(wwInt),[0.25 0.75]),'color',ww_color); 
plot([4 4]+0.2,quantile(cell_metrics.firingRate_REMstate(wwInt),[0.25 0.75]),'color',ww_color);
plot([5 5]+0.2,quantile(cell_metrics.firingRate(wwInt),[0.25 0.75]),'color',ww_color);
plot([2:5]+0.2,[nanmedian(cell_metrics.firingRate_WAKEstate(wwInt)) nanmedian(cell_metrics.firingRate_NREMepisode(wwInt)) nanmedian(cell_metrics.firingRate_REMstate(wwInt)) nanmedian(cell_metrics.firingRate(wwInt))],...
    'o','color',ww_color,'MarkerFaceColor',ww_color_light,'MarkerEdgeColor',ww_color,'MarkerSize',15);
% optoTag
plot([2:5]+0.3,[nanmedian(cell_metrics.firingRate_WAKEstate(optoTagCells)) nanmedian(cell_metrics.firingRate_NREMepisode(optoTagCells)) nanmedian(cell_metrics.firingRate_REMstate(optoTagCells)) nanmedian(cell_metrics.firingRate(optoTagCells))],'color',[0 0 0]);
% plot([1 1],quantile(frate.all(pyr),[0.25 0.75]),'color',pyr_color); 
plot([2 2]+0.3,quantile(cell_metrics.firingRate_WAKEstate(optoTagCells),[0.25 0.75]),'color',[0 0 0]);
plot([3 3]+0.3,quantile(cell_metrics.firingRate_NREMstate(optoTagCells),[0.25 0.75]),'color',[0 0 0]); 
plot([4 4]+0.3,quantile(cell_metrics.firingRate_REMstate(optoTagCells),[0.25 0.75]),'color',[0 0 0]);
plot([5 5]+0.3,quantile(cell_metrics.firingRate(optoTagCells),[0.25 0.75]),'color',[0 0 0]);
plot([2:5]+0.3,[nanmedian(cell_metrics.firingRate_WAKEstate(optoTagCells)) nanmedian(cell_metrics.firingRate_NREMepisode(optoTagCells)) nanmedian(cell_metrics.firingRate_REMstate(optoTagCells)) nanmedian(cell_metrics.firingRate(optoTagCells))],...
    'o','color',[0 0 0],'MarkerFaceColor',[.8 .8 .8],'MarkerEdgeColor',[0 0 0],'MarkerSize',15);
xlim([1.5 5.5]); ylabel('Firing rate [Hz]'); 
set(gca,'XTick',[2 3 4 5],'XTickLabel',{'Wake','NREM','REM','All'},'YScale','log','TickDir','out'); ylim([1.9E-1 2E1]);

% 3. EVENTS FIRING
% 3.1 DOWN STATE firing
for ii = 1:length(udResponses.udR)
    udResponses.downSmooth(ii,:) = smooth(udResponses.udR(ii,:),5);
end
udResponses.t_up = udResponses.timestamps;

win = find(udResponses.t_up>=-0.05 & udResponses.t_up<=0.05); % 
udResponses.downResponse = mean(udResponses.udR(:,win),2); % delta peak response
[~, downSorted_pyr] = sort(udResponses.downResponse(pyr)); downSorted_pyr = pyr(downSorted_pyr);
[~, downSorted_nwInt] = sort(udResponses.downResponse(nwInt)); downSorted_nwInt = nwInt(downSorted_nwInt);
[~, downSorted_wwInt] = sort(udResponses.downResponse(wwInt)); downSorted_wwInt =  wwInt(downSorted_wwInt);

figure % 4 x 3
subplot(2,2,3)
imagesc(udResponses.t_up, 1:length(downSorted_pyr),udResponses.downSmooth(downSorted_pyr,:));
set(gca,'TickDir','out','YTick',[1 length(downSorted_pyr)]); ylabel('PYR','Color',pyr_color); 
xlabel('...                                                           DOWN-UP response [s]'); xlim([-.3 .3]);
subplot(2,2,1)
imagesc(udResponses.t_up, 1:length(downSorted_nwInt),udResponses.downSmooth(downSorted_nwInt,:));
set(gca,'TickDir','out','XTick',[],'YTick',[1 length(downSorted_nwInt)]); ylabel('NW','Color',nw_color); xlim([-.3 .3]);
subplot(2,2,2)
imagesc(udResponses.t_up, 1:length(downSorted_wwInt),udResponses.downSmooth(downSorted_wwInt,:));
set(gca,'TickDir','out','XTick',[],'YTick',[1 length(downSorted_wwInt)]); ylabel('WW','Color',ww_color); xlim([-.3 .3]);
subplot(2,2,4)
imagesc(udResponses.t_up, 1:length(optoTagCells),udResponses.downSmooth(optoTagCells,:));
set(gca,'TickDir','out','YTick',[1 length(optoTagCells)]); ylabel('Ndnf','Color',[0 0 0]); xlim([-.3 .3]);
colormap jet


% 4. POPULATION RESPONSE
[~, optoSorted_pyr] = sort(optoTagResponses.value(pyr)); optoSorted_pyr = pyr(optoSorted_pyr);
[~, optoSorted_nwInt] = sort(optoTagResponses.value(nwInt)); optoSorted_nwInt = nwInt(optoSorted_nwInt);
[~, optoSorted_wwInt] = sort(optoTagResponses.value(wwInt)); optoSorted_wwInt =  wwInt(optoSorted_wwInt);

figure;
subplot(2,2,3)
imagesc(optoTagResponses.timestamps, 1:length(optoSorted_pyr),optoTagResponses.eventsSmooth(optoSorted_pyr,:)); caxis([-3 3]);
set(gca,'TickDir','out','YTick',[1 length(optoSorted_pyr)]); ylabel('PYR','Color',pyr_color); 
xlabel('Light response [s]'); xlim([-.1 .4]); 
subplot(2,2,1)
imagesc(optoTagResponses.timestamps, 1:length(optoSorted_nwInt),optoTagResponses.eventsSmooth(optoSorted_nwInt,:)); caxis([-3 3]);
set(gca,'TickDir','out','XTick',[],'YTick',[1 length(optoSorted_nwInt)]); ylabel('NW','Color',nw_color); xlim([-.1 .4]); 
subplot(2,2,2)
imagesc(optoTagResponses.timestamps, 1:length(optoSorted_wwInt),optoTagResponses.eventsSmooth(optoSorted_wwInt,:)); caxis([-3 3]);
set(gca,'TickDir','out','XTick',[],'YTick',[1 length(optoSorted_wwInt)]); ylabel('WW','Color',ww_color); xlim([-.1 .4]); 
hold on; plot(optoTagResponses.timestamps([1 end]), length(optoSorted_wwInt) - length(optoTagCells)*[1 1],'k','LineWidth',1);
xlim([-.1 .4]); 
colormap jet
subplot(2,2,4)
hold on
bar(1, length(find(optoTagResponses.value(pyr)>.5 & cell_metrics.pulses_modulationSignificanceLevel(pyr)'<0.05))/length(pyr),'FaceColor',pyr_color,'EdgeColor','none');
bar(1, -length(find(optoTagResponses.value(pyr)<.5 & cell_metrics.pulses_modulationSignificanceLevel(pyr)'<0.05))/length(pyr),'FaceColor',pyr_color_light,'EdgeColor','none');
bar(2, length(find(optoTagResponses.value(nwInt)>.5 & cell_metrics.pulses_modulationSignificanceLevel(nwInt)'<0.05))/length(nwInt),'FaceColor',nw_color,'EdgeColor','none');
bar(2, -length(find(optoTagResponses.value(nwInt)<-.5 & cell_metrics.pulses_modulationSignificanceLevel(nwInt)'<0.05))/length(nwInt),'FaceColor',nw_color_light,'EdgeColor','none');
bar(3, length(find(optoTagResponses.value(wwInt)>.5 & cell_metrics.pulses_modulationSignificanceLevel(wwInt)'<0.05))/length(wwInt),'FaceColor',ww_color,'EdgeColor','none');
bar(3, -length(find(optoTagResponses.value(wwInt)<-.5 & cell_metrics.pulses_modulationSignificanceLevel(wwInt)'<0.05))/length(wwInt),'FaceColor',ww_color_light,'EdgeColor','none');
set(gca,'TickDir','out','XTick',[1 2 3],'XTickLabel',{'PYR','NW','WW'},'XTickLabelRotation',45); ylim([-.3 .3]);
ylabel('Frac Mod cells [prob]');

figure
hold on
plot(optoTagResponses.timestamps, optoTagResponses.eventsSmooth(optoSorted_pyr,:),'color',pyr_color_light);
plot(optoTagResponses.timestamps, optoTagResponses.eventsSmooth(optoSorted_nwInt,:),'color',nw_color_light);
plot(optoTagResponses.timestamps, optoTagResponses.eventsSmooth(optoSorted_wwInt,:),'color',ww_color_light);
plot(optoTagResponses.timestamps, optoTagResponses.eventsSmooth(optoTagCells,:),'color','k');


