function []=Go(handles)

%input and preparation for deconvolution

frametime=handles.frametime;
cellnumber=handles.selectedCell;
tau=handles.tau;
%part for deconvolution

if isnan(cellnumber)==0 %if due to regressor constraint no cell is selected;
%kernel
DFForig=handles.RegionStats(cellnumber).DFF; 
DFFkernell=DFForig;

for t=3:size(DFForig,2)-2
    DFFkernell(1,t)=(0.25*DFForig(1,t-2)+0.5*DFForig(1,t-1)+DFForig(1,t)+0.5*DFForig(1,t+1)+0.25*DFForig(1,t+2))/2.5;
end

DFForig=DFFkernell; kernell=1;
DFFtimevektor=frametime:frametime:frametime*size(handles.RegionStats(cellnumber).DFF,2);
decfunct=exp(-DFFtimevektor/tau); 
DFFzeros=[zeros(1,length(DFForig)) DFForig zeros(1,length(DFForig))];
[QValues, RValues]=deconv(DFFzeros,decfunct); %deconvolve
DFFdec=QValues(size(handles.RegionStats(cellnumber).DFF,2)+1:...
    size(handles.RegionStats(cellnumber).DFF,2)+1+size(handles.RegionStats(cellnumber).DFF,2)-1);

try
    if kernell==1 
        DFFdec(1,1:2)=NaN;
        DFFdec(1,end-1:end)=NaN; %As I can't kernel thouse
    end
catch
end
clear kernell DFFzeros DFForig DFFkernell decfunct DFFtimevektor 

tempfluo=DFFdec;

%% exclude data points after saccade
if handles.saccDetect==1
    tempfluoNo=nan(size(tempfluo,2),1);
    tempfluoYes=nan(size(tempfluo,2),1);
    %Saccade detection
    for t=2:size(tempfluo,2)
        if abs(handles.R(t,1)-handles.R(t-1,1))>handles.saccThres 
            tempfluoYes(t,1)=tempfluo(1,t); 
        else
            tempfluoNo(t,1)=tempfluo(1,t); 
        end
    end 
% exclude data points after saccade 
bla=isnan(tempfluoNo);
findbla=find(bla);
for z=1:size(findbla)
    try % if saccade appears at the end of recording
    tempfluoforno=tempfluoYes(findbla(z)+1:1:findbla(z)+handles.PAS); % to repaste QValues after two saccades occure directly after each other
    end
    try % if saccade appears at the end of recording
    tempfluoYes(findbla(z)+1:1:findbla(z)+handles.PAS)=tempfluoNo(findbla(z)+1:1:findbla(z)+handles.PAS);
    end
    for t=1:handles.PAS % This part is needed if two saccades occure directly after each other
     try
        if isnan(tempfluoYes(findbla(z)+t));
           tempfluoYes(findbla(z)+t)=tempfluoforno(t);
        end
     end
    end

    try
     tempfluoNo(findbla(z)+1:1:findbla(z)+handles.PAS)=NaN;
     tempfluoNo=tempfluoNo(1:size(tempfluoYes,1),:); % past same length 
    end
    clear tempfluoforno
end
tempfluo=tempfluoNo';
end %saccDetect

%create mesh
OutToMesh=nan(size(tempfluo,2),3);
OutToMesh(:,1)=tempfluo';
OutToMesh(:,2)=handles.R(:,1);
velmatrix=handles.R(:,4);   %get velocity values from rawVelocity ccw := negative
for x=1:size(handles.R,1)
    if velmatrix(x,1)==0
       velmatrix(x,1)=-handles.R(x,5);
    end
end
OutToMesh(:,3)=velmatrix;
[meshout, RawData]=meshfunction2(OutToMesh);
RawData=RawData';
meshout=meshout';



%% Prepare data
% not best solution to save data (very time consuming)
try load('meshfittingSave')
catch
end

if exist('meshfitting','var')
    meshfitting.mesh(:,:,end+1)=meshout;
    meshfitting.exportmat(end+1,:)=handles.Exportmat(cellnumber,:);
    meshfitting.RawData(:,:,end+1)=RawData;
else
    meshfitting.mesh=meshout;
    meshfitting.exportmat=handles.Exportmat(cellnumber,:);
    meshfitting.RawData=RawData;
end

%% Calculate PVIndex based on eye movement correlation (Supp figure)
eyePosPos=handles.R(:,1);
eyePosPos(eyePosPos<0)=0;
eyePosNeg=handles.R(:,1);
eyePosNeg(eyePosNeg>0)=0;
eyePosNeg=eyePosNeg*(-1);

eyeVelPos=diff(handles.R(:,1));
eyeVelPos(2:end+1)=eyeVelPos;
eyeVelPos(1,1)=0;
eyeVelNeg=eyeVelPos;
eyeVelPos(eyeVelPos<0)=0;
eyeVelNeg(eyeVelPos>0)=0;
eyeVelNeg=eyeVelNeg*(-1);

% crop vel at 4 °
eyeVelPos(eyeVelPos>4)=4;
eyeVelNeg(eyeVelNeg>4)=4;

PVDFF=handles.Exportmat{cellnumber,7};

%conv Reg here
%parameters

frametime=0.5;
tau=1.1;
cellnumber=handles.selectedCell;
DFFtimevektor=frametime:frametime:frametime*size(PVDFF,2);
decfunct=exp(-DFFtimevektor/tau);

%conv here
ppzeros=[zeros(1,length(eyePosPos)) eyePosPos' zeros(1,length(eyePosPos))];
ppconvl= conv(ppzeros,decfunct);
ppconv=ppconvl(1,size(eyePosPos,1)+1:...
    size(eyePosPos,1)+1+size(eyePosPos,1)-1);
clear ppzeros ppconvl


pnzeros=[zeros(1,length(eyePosNeg)) eyePosNeg' zeros(1,length(eyePosNeg))];
pnconvl= conv(pnzeros,decfunct);
pnconv=pnconvl(1,size(eyePosNeg,1)+1:...
    size(eyePosNeg,1)+1+size(eyePosNeg,1)-1);
clear pnzeros pnconvl

vpzeros=[zeros(1,length(eyeVelPos)) eyeVelPos' zeros(1,length(eyeVelPos))];
vpconvl= conv(vpzeros,decfunct);
vpconv=vpconvl(1,size(eyeVelPos,1)+1:...
    size(eyeVelPos,1)+1+size(eyeVelPos,1)-1);
clear vpzeros vpconvl


vnzeros=[zeros(1,length(eyeVelNeg)) eyeVelNeg' zeros(1,length(eyeVelNeg))];
vnconvl= conv(vnzeros,decfunct);
vnconv=vnconvl(1,size(eyeVelNeg,1)+1:...
    size(eyeVelNeg,1)+1+size(eyeVelNeg,1)-1);
clear vnzeros vnconvl

%correlation
t1=corr(PVDFF',ppconv')>0;
t11=corr(PVDFF',ppconv');
t2=corr(PVDFF',pnconv')>0;
t21=corr(PVDFF',pnconv');
t3=corr(PVDFF',vpconv')>0;
t31=corr(PVDFF',vpconv');
t4=corr(PVDFF',vnconv')>0;
t41=corr(PVDFF',vnconv');

%overwrite regressor value 16 (not used for other stuff)
if any([t1,t2]) && any([t3,t4])
    PVindexTemp=(max(t11,t21)-max(t31,t41))/...
        (max(t11,t21)+max(t31,t41));
    meshfitting.exportmat{end,9}(1,16)=PVindexTemp;
else
    PVindexTemp=NaN;
    meshfitting.exportmat{end,9}(1,16)=PVindexTemp;
end

% not best solution to save data (very time consuming)
pause(1)
save('meshfittingSave','meshfitting')
pause(1)

end %isnan(cellnumber)
end %function end