function [sumStart, ...
          sumEnd, ...
          sumDur, ...
          meanSumInt, ...
          meanSumHt, ...
          meanPsWalkSpeed,...
          meanPsDist,...
          sumInt, ...
          sumHt, ...
          psWalkSpeed, ...
          psDist,...
          numCad] = integrateSummitBump(data, ...
                                        genoName, ...
                                        outDir, ...
                                        endPad, ...
                                        smoothWin, ...
                                        sumStart,...
                                        moveThresh,...
                                        minSumDur)
    
    cadLimit = 24;  % max # of cadaver plots to show in a single figure

    numCad = size(data.Cadavers.speed.toDmatrix,2);
    numFigs = ceil(numCad/cadLimit);
    
    [sumInt, sumHt, psWalkSpeed, psDist] = deal(NaN(1,numCad));
    
    % Calculate average speed
    avgTtdSpeed = nanmean(transpose(data.Cadavers.speed.toDmatrix));
    avgTtdSpeedSmooth = smoothdata(avgTtdSpeed,'movmean',smoothWin);
    
    % Set up variables to plot data.params.lastFrames
    xTtd = 1:length(avgTtdSpeedSmooth);
    yTtd = 0:0.1:1.5;
    endXTtd = repmat(data.params.lastFrames,1,length(yTtd));   
    
    %% Automatically find sumEnd by determining point where speed returns to baseline (speed at sumStart)

    % Set normalized speed before cutoff and after data.params.lastFrames
    % to 0 to force summiting to be observed after designated time but
    % within last frames
    normAvgSpeedTtd = avgTtdSpeedSmooth - avgTtdSpeedSmooth(sumStart);
    
    % Add in padding after last frames to let speed come to 0 so
    % we can integrate over the entire bump
    normAvgSpeedTtd(xTtd>data.params.lastFrames + endPad) = -1;
    sumEnd = max(find(normAvgSpeedTtd >= 0));  
    
    if sumEnd-sumStart <= minSumDur*60*3
        sumEnd = sumStart + (minSumDur*60*3);
    end    
    
    %% Calculate mean summit duration (sumDur), integrate under normalized speed bump (avgSumInt) and find change in ypos (avgSumHt)
    sumDur = (sumEnd-sumStart)/(data.params.fr*3600);     
    meanSumInt = trapz(normAvgSpeedTtd(sumStart:sumEnd))/(sumEnd-sumStart); % 2020-08-10-now dividing distance traveled by summit duration!
    
    avgYpos = smoothdata(nanmean(transpose(data.Cadavers.ypos.toDmatrix)),'movmean',smoothWin);
    meanSumHt = avgYpos(sumEnd) - avgYpos(sumStart);          
    
% %     %% Calculate mean activity score based on avg distance traveled/pixel before summiting
        % again, gives slightly different value than nanmean(psDist), so
        % going to just use that instead!
% %     % Grab data prior to summiting
% %     preSum = avgTtdSpeedSmooth(1:sumStart);
% %     
% %     % Remove any NaN values that may be present
% %     preSum = preSum(~isnan(preSum));
% %     
% %     % Integrate this region and normalize by length of region (excluding
% %     % NaN values)
% %     avgPsDist = trapz(preSum)/length(preSum);

% %     %% Calculate mean activity score, based on avg speed when moving (i.e. speed > moveThresh) before summiting
% %     %% This wasn't giving the same answer as
        % nanmean(summit.genoX.psWalkSpeed) so decided to drop
% %     % Use NON-smoothed speed for this calculation; smoothing changes
% %     % thresholding of moving vs. still
% %     preSum = avgTtdSpeed(1:sumStart);
% %     
% %     % Find all frames where, on avg, speed is above moveThresh (fly is
% %     % walking)
% %     walk = preSum>moveThresh;
% %     
% %     % Calculate mean speed during these frames
% %     avgPSpsWalkSpeed = nanmean(preSum(walk));
    
    %% Plot and save figure with data averages (for eye check)
    figure;
    subplot(2,1,1);
    hold on;
    
    plot(avgYpos);
    scatter(sumStart, avgYpos(sumStart));
    scatter(sumEnd, avgYpos(sumEnd));    
    plot(endXTtd,yTtd);
    
    text(data.params.lastFrames,1,'Time of death');
    ylim([0 1]);
    xlim([0 data.params.lastFrames+endPad]);
    ylabel('Mean Cadaver Height');
    xlabel('Frames before death');
    
    subplot(2,1,2);
    hold on;
    
    plot(avgTtdSpeedSmooth);
    scatter(sumStart,avgTtdSpeedSmooth(sumStart));
    scatter(sumEnd,avgTtdSpeedSmooth(sumEnd));
    plot(endXTtd,yTtd);
    
    text(data.params.lastFrames,1,'Time of death');
    xlim([0 data.params.lastFrames+endPad]);
    ylabel('Mean Cadaver Speed');
    xlabel('Frames before death');
    ylim([0 1.5]);
    
    suptitle(strcat(genoName,'-mean'));
    safeGenoName = makeSafeName(genoName);
    print(strcat(outDir,safeGenoName,'-mean'),'-dpng');
    close();    
    
    %% Calculate individual sumInt and sumHt for all ROIs in set using sumStart and sumEnd determined
    % from bulk data; plot all speed data for eye check
    for j = 1:numFigs
        figure;
        hold on;
        
        if j*cadLimit > numCad
            lastCad = numCad;
        else
            lastCad = j*cadLimit;
        end            
        
        for i=1+((j-1)*cadLimit):lastCad
            indSpeed = data.Cadavers.speed.toDmatrix(:,i);
            indSpeedSmooth = smoothdata(indSpeed,'movmean',smoothWin);       
            indSpeedNorm = indSpeedSmooth - indSpeedSmooth(sumStart);
            
            % Calculate summit duration in hours, based on average
            % start and stop using normalized speed (speed - minus(speed at
            % point of summit start)
            sumInt(i) = trapz(indSpeedNorm(sumStart:sumEnd))/(sumEnd-sumStart);

            % Calculate height differential over summiting
            ypos = smoothdata(data.Cadavers.ypos.toDmatrix(:,i),'movmean',smoothWin);
            sumHt(i) = ypos(sumEnd) - ypos(sumStart);
            
            % Calculate individual activity scores - mean distance traveled per frame, regardless
            % of walking or not
            preSumInd = indSpeedSmooth(1:sumStart);
            preSumInd = preSumInd(~isnan(preSumInd));
            psDist(i) = trapz(preSumInd)/length(preSumInd);

            % Calculate individual activity score, based on avg speed when
            % walking using NON-smoothed data
            preSumInd = indSpeed(1:sumStart);
            walk = preSumInd > moveThresh;
            psWalkSpeed(i) = nanmean(preSumInd(walk));

            % Plot speed data                      
            subplot(cadLimit/3,3,i-((j-1)*cadLimit));
            %plotCad = lastCad - (j-1)*cadLimit; 
            %subplot(ceil(plotCad/3),3,i-((j-1)*cadLimit));
            hold on;
            
            plot(avgTtdSpeedSmooth,'-b');
            plot(xTtd,repmat(avgTtdSpeedSmooth(sumStart),1,length(xTtd)),':b');
            scatter(sumStart,avgTtdSpeedSmooth(sumStart),'g');
            scatter(sumEnd,avgTtdSpeedSmooth(sumEnd),'g'); 
            
            plot(indSpeedSmooth,'-r');  
            plot(xTtd,repmat(indSpeedSmooth(sumStart),1,length(xTtd)),':r');
            scatter(sumStart,indSpeedSmooth(sumStart),'k');
            scatter(sumEnd,indSpeedSmooth(sumEnd),'k'); 
            
            plot(endXTtd,yTtd);   % time of death
            
            xlim([0 data.params.lastFrames + endPad]);
            
            set(gca,'xtick',0:4*data.params.fr*3600:data.params.lastFrames,'xticklabel',data.params.hoursBeforeDeath:-4:0)
            
            %maxSpeed = max(avgTtdSpeedSmooth);
            maxSpeed = 1.5;
            if max(indSpeedSmooth) > maxSpeed
                maxSpeed = max(indSpeedSmooth);
                ylabel(strcat(num2str(i),'*')); % mark ROIs whose speed is higher than average
            else
                ylabel(num2str(i));
            end
            
            ylim([0 maxSpeed]);
            %ylim([0 2]);
        end
        
        suptitle(strcat(genoName,"-plot ",num2str(j)," of ", num2str(numFigs)));
        set(gcf,'PaperUnits','inches','PaperPosition',[0 0 10 8]);
        print(strcat(outDir,safeGenoName,"-plot ",num2str(j)," of ", num2str(numFigs),"-cads ",num2str(1+((j-1)*cadLimit))," to ",(num2str((lastCad)))),'-dpng');
        
        % For summit paper Fig 1
        set(gcf,'PaperUnits','inches','PaperPosition',[0 0 8 8],'Renderer','Painters'); % setting 'Renderer' to 'Painters' forces Matlab to write vector file!
        print(strcat(outDir,safeGenoName,"-plot ",num2str(j)," of ", num2str(numFigs),"-cads ",num2str(1+((j-1)*cadLimit))," to ",(num2str((lastCad)))),'-dpdf');
        close();  
         
    end
    
    meanPsWalkSpeed = nanmean(psWalkSpeed);
    meanPsDist = nanmean(psDist);
end