function dop=dopEventData(dop)
% dopOSCCI Mark II: dopEventData ~ 19-Jan-2012 (last edit)
%
% prepare the doppler data for summary: find event markers, create event
% epoch stack, and create base & period of interest filters.
%
% Includes:
% - dopEventMarks (find the appropriate markers)
% - dopEventStack (stack the data into events/trials)
% - dopEventFilter (create filter for base and poi selection
% - dopEventActRej (creates epoch screen based upon activation rejection
%       values, see dopTaskDef)
% - dopEventBaseCorrect (runs baseline correction adjustment)
% - dopEventDifference (calculates difference between the left and right
%       doppler channels)
% - dopEventAverage (calculates average activation of left & right channels)
% - dopEventScreen (creates event/epoch screening array)
%

try
    if ~dop.sum.skip && ~dop.sum.quit
        %% find the markers
        
        dop.mk=dopEventMarks(dop.inData(:,3:end,:),...
            'epochs',dop.def.epochs,'sep',dop.def.sep,'sample',dop.def.downHertz,...
            'eventLabels',dop.def.evNames,'evChs',dop.def.evChs,...
            'evType',dop.def.evType,'evMatch',dop.def.evMatch);
        
        %% stack the data
        dop.stack=dopEventStack(dop.inData(:,1:2),dop.mk,...
            'epoch',dop.def.epoch,'sample',dop.def.downHertz,...
            'eventLabels',dop.def.evNames,'evChs',dop.def.evChs);
        %% raw stack
        % use this to calculate dropout
        dop.raw.stack=dopEventStack(dop.raw.data(:,1:2),dop.mk,...
            'epoch',dop.def.epoch,'sample',dop.def.downHertz,...
            'eventLabels',dop.def.evNames,'evChs',dop.def.evChs,...
            'record',dop.data.rawInfo.sampleRate);
        
        %% event filter
        dop.filter=dopEventFilter('epoch',dop.def.epoch,'base',dop.def.base,...
            'poi',dop.def.poi,'sample',dop.def.downHertz,...
            'eventLabels',dop.def.evNames,'evChs',dop.def.evChs,...
            'evType',dop.def.evType,'evMatch',dop.def.evMatch);
        
        % 1-11-10
        % need to work here down for the indBase line exercise...
        %% activation rejection
        dop.actRej=dopEventActRej(dop.stack,'actRej',dop.def.actRej,'actSep',dop.def.actSep);
        
        %% baseline correction
        dop=dopEventBaseCorrect(dop);
        
        %% calculate mean channel
        dop.avg=dopEventAverage(dop.stack);
        
        %% calculate difference channel
        dop.dif=dopEventDifference(dop.stack);
        
        %% event/epoch screening
        % create screen for problematic epochs - activation screening
        [dop.scrn.ev dop.sum.skip dop.sum.skipReason]=...
            dopEventScreen(dop.mk,dop.stack,dop.actRej,'evChs',dop.def.evChs,...
            'eventLabels',dop.def.evNames,'inShort',dop.def.inShort,...
            'actRej',dop.def.actRej,'epSelLabels',dop.def.saveEpochSelectionLabels,...
            'evType',dop.def.evType,'evMatch',dop.def.evMatch);
        
    end
catch err
   %% catch dopOSCCI error
    % 
save(dopOSCCIdebug(mfilename));rethrow(err); 
%     dopOSCCIcrash(err,dop,mfilename);
end



