% edited on 01/28/2015
% track the center of each reward location
% put the headstage on each reward location
% beep at the beginning of the tracking

fs_sin=8000;
fs0=800;
t=0 : 1/fs_sin : 0.1;
beep0 = sin(fs0*2*pi*t);

Ang_RewardLoc=nan(max(Ind_loc),1);
X_RewardLoc=nan(max(Ind_loc),1);
Y_RewardLoc=nan(max(Ind_loc),1);
pause(10);
for ind=Ind_loc
    % Starting reward loc(ind)
    sound(beep0,fs_sin);
    pause(15);
    [~, ~, locationArray, ~, VTRecsReturned, ~] = NlxGetNewVTData(vt_acq_ent);
    x0_RewardLoc = double(locationArray(end - 1)).*scale_x;
    y0_RewardLoc = (-1)*double(locationArray(end)).*scale_y;
    x1_RewardLoc = x0_RewardLoc-x_center;
    y1_RewardLoc = y0_RewardLoc-y_center;
    if strcmp(rot,'Clockwise')
        if x1_RewardLoc>=0
            if x1_RewardLoc==0 x1_RewardLoc=0.1; end
            ang1_RewardLoc=mod(atan(-y1_RewardLoc./x1_RewardLoc),2*pi);
        else
            ang1_RewardLoc=mod(atan(-y1_RewardLoc./x1_RewardLoc)+pi,2*pi);
        end
    else
        if x1_RewardLoc>=0
            if x1_RewardLoc==0 x1_RewardLoc=0.1; end
            ang1_RewardLoc=mod(atan(y1_RewardLoc./x1_RewardLoc),2*pi);
        else
            ang1_RewardLoc=mod(atan(y1_RewardLoc./x1_RewardLoc)+pi,2*pi);
        end
    end
    Ang_RewardLoc(ind,1)=ang1_RewardLoc;
    X_RewardLoc(ind,1)=x1_RewardLoc;
    Y_RewardLoc(ind,1)=y1_RewardLoc;
end
sound(beep0,fs_sin);