function [Electron_NEW] = probe(Electron, TH_max, Probe_diam, TH_calc,Probe_calc,A,focus)
% TH_max - apertura (max. dopadajici uhel theta)
% Probe_diam - spot size (prumer svazku)
% TH_calc - sposob vypoctu nah. cisla pre vyber dopadajuceho uhlu theta
% Probe_calc - sposob vypoctu nah. cisla pre dopadajuci uhol theta
% A - rozhonuti generujem nnove naklony a posuny alebo pri pohybe po kouli
%     nechavam tie same


Electron_NEW = Electron;
for i = 1:length(Electron.Z)
    
        ind = find(Electron.Z(i,:)~=0);  % len v miestach kolizie
        index = ind(end);
    
    
    %     Z = Electron_NEW.Z(i,1:index).*(-1);
    %     Y = Electron_NEW.Y(i,1:index);
    %     X = Electron_NEW.X(i,1:index);
    %
    % ak je A == 0 generuje sa len prvy krat, ak je rovno 1 generuje sa
    % furt iny naklon a posun
    if A == 0 && i == 1
        [TH_nx,TH_ny,XE,YE] = generate(TH_max, Probe_diam, TH_calc,Probe_calc);
    elseif A == 1
        [TH_nx,TH_ny,XE,YE] = generate(TH_max, Probe_diam, TH_calc,Probe_calc);
    elseif A ~= 0 && A~=1
        error('A must be equal 0 or 1 (0- generates TH_n,XE,YE only once;  1 - generates in every step)')
    end
    
    % % tilt
    TH_ny = 0; % zatial
    
    
    RMx = [cos(TH_nx), -sin(TH_nx); sin(TH_nx),cos(TH_nx)];
    Mx = [Electron.X(i,:);Electron.Z(i,:)]';
    M_newx = Mx*RMx;
    
    Electron_NEW.Z(i,:) = M_newx(:,2)';
    Electron_NEW.X(i,:) = M_newx(:,1)';
    
    RMy = [cos(TH_ny), -sin(TH_ny); sin(TH_ny),cos(TH_ny)];
    My = [Electron.Y(i,:); Electron.Z(i,:)]';
    M_newy = My*RMy;
    
    Electron_NEW.Z(i,:) = M_newy(:,2)';
    Electron_NEW.Y(i,:) = M_newy(:,1)';
    
    % % focus
    
    focus_shift_x = tan(TH_nx)*focus; 
    focus_shift_y = tan(TH_ny)*focus;
    
    % % Shift
    
    Electron_NEW.X(i,1:index) = Electron_NEW.X(i,1:index) + XE +focus_shift_x;
    Electron_NEW.Y(i,1:index) = Electron_NEW.Y(i,1:index) + YE +focus_shift_y;
    Electron_NEW.Th(i,1:index)= Electron_NEW.Th(i,1:index) + TH_nx; % naklon od osi z v smere x
    Electron_NEW.Ps(i,1:index)= Electron_NEW.Ps(i,1:index) + TH_ny;
   
end
Electron_NEW.Zcalc = Electron_NEW.Z.*(-1);
% ZN = ZN*(-1);
