

% slac wiggler data https://www-group.slac.stanford.edu/met/MagMeas/MAGDATA/LCLS-II/Undulator/X-LEAP-1/DATASET0001/Tuning/Z%20Scans/




if(1==1) % WIGGLER 2 - 2D map from SLAC - run 014
    % read the field map
    Bmap = read2Dfieldmap( 'S:\magdata\LCLS-II\Undulator\X-LEAP-2\DATASET0002\Tuning\Z Scans/Run 022/' );  % 2D field map
%      Bmap = read2Dfieldmap_corrected( 'xleap2-wiggler-data/SLAC/X-LEAP-4/DATASET0001/Tuning/Z Scans/Run 014/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = -520e-6 * 4. / energy_GeV; y0 = 0; xp0 = 0; yp0 = 0; gamma0 = energy_GeV*1000./0.511;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    if(1==1) % plot field integrals?
        y_offset_scan_Q = 0; plot_field_integrals_raw( y_offset_scan_Q, Bmap, relative_field_rolloff );
    end
    results = plot_orbit( x0, y0, xp0, yp0, gamma0, Bmap, relative_field_rolloff ); % trajectory
    matrix_element; display(mat); display(normmat); display('dx  dy  dxp  dyp = ');display(round((ray0(2:end) - [x0,0,0,0])*1e6));
end


if(1==0) % WIGGLER 2 - 2D map from SLAC - run 010
    % read the field map
    Bmap = read2Dfieldmap( 'S:\magdata\LCLS-II\Undulator\X-LEAP-3\DATASET0002\Tuning\Z Scans/Run 004/' );  % 2D field map
%      Bmap = read2Dfieldmap_corrected( 'xleap2-wiggler-data/SLAC/X-LEAP-4/DATASET0001/Tuning/Z Scans/Run 010/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = -520e-6 * 4. / energy_GeV; y0 = 0; xp0 = 0; yp0 = 0; gamma0 = energy_GeV*1000./0.511;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    if(1==1) % plot field integrals?
        y_offset_scan_Q = 0; plot_field_integrals_raw( y_offset_scan_Q, Bmap, relative_field_rolloff );
    end
    results = plot_orbit( x0, y0, xp0, yp0, gamma0, Bmap, relative_field_rolloff ); % trajectory
    matrix_element; display(mat); display(normmat); display('dx  dy  dxp  dyp = ');display(round((ray0(2:end) - [x0,0,0,0])*1e6));
end

if(1==0) % WIGGLER 2 - 2D map from SLAC - run 003
    % read the field map
%      Bmap = read2Dfieldmap( 'xleap2-wiggler-data/SLAC/X-LEAP-4/DATASET0001/Tuning/Z Scans/Run 003/' );  % 2D field map
    Bmap = read2Dfieldmap_corrected( 'S:\magdata\LCLS-II\Undulator\X-LEAP-3\DATASET0002\Tuning\Z Scans/Run 003/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = -520e-6 * 4. / energy_GeV; y0 = 0; xp0 = 0; yp0 = 0; gamma0 = energy_GeV*1000./0.511;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    if(1==0) % plot field integrals?
        y_offset_scan_Q = 0; plot_field_integrals_raw( y_offset_scan_Q, Bmap, relative_field_rolloff );
    end
    results = plot_orbit( x0, y0, xp0, yp0, gamma0, Bmap, relative_field_rolloff ); % trajectory
    matrix_element; display(mat); display(normmat); display('dx  dy  dxp  dyp = ');display(round((ray0(2:end) - [x0,0,0,0])*1e6));
end

if(1==0) % WIGGLER 1 - 2D map from SLAC - run 019 - Y map
    % read the field map
%      Bmap = read2Dfieldmap_y( 'xleap2-wiggler-data/SLAC/X-LEAP-1/DATASET0001/Tuning/Z Scans/Run 019/' );  % 2D field map
    Bmap = read2Dfieldmap_y_corrected( 'S:\magdata\LCLS-II\Undulator\X-LEAP-3\DATASET0002\Tuning\Z Scans/Run 004/' );  % 2D field map
%      % plot the field
%      plot_2dfields_contours
%      if(1==1) % plot field integrals?
%          y_offset_scan_Q = 1; plot_field_integrals_raw( y_offset_scan_Q, Bmap, relative_field_rolloff );
%      end
    if(1==1) % plot field profiles?
        pzs = [1.072,1.614,2.167,2.721,3.262,3.828];
        uzs = unique(Bmap(:,1));
        ipzs = round(interp1(uzs,1:numel(uzs),pzs));
        pzs = uzs(ipzs);
        figure; hold on;
        minys = []; minBys = [];
        labels = [];
        for z = pzs'
            sBmap = Bmap(Bmap(:,1)==z,:);
            interpys = linspace(min(sBmap(:,4)),max(sBmap(:,4)),111);
            interpBys = interp1(sBmap(:,4),sBmap(:,3),interpys);
            minBy = min(interpBys); minBys = [minBys, minBy];
            miny = interpys(interpBys == minBy); minys = [minys, miny];
            plot(1e3*sBmap(:,4),sBmap(:,3))
            labels = [labels; ['z = ',num2str(z),' m']];
        end
        for i = 1:numel(minys)
            plot([1e3*minys(i)],[minBys(i)],'*')
        end
        hold off; xlabel('y offset (mm)'); ylabel('By (T)'); legend(labels);
    end
    if(1==0) % replace 2D map with on axis field map and plot field integral?
        xpositions = Bmap(:,4);
        Bmap = Bmap(xpositions==0,1:3); % on-axis field from 2D field map
        % plot the field intergral on this slice
        plot_field_integral;
    end
end

%  if(1==1) % WIGGLER 1 - 2D map from SLAC - run 018 - SLICE
%      % read the field map
%  %      Bmap = read2Dfieldmap( 'xleap2-wiggler-data/SLAC/X-LEAP-1/DATASET0001/Tuning/Z Scans/Run 018/' );  % 2D field map
%      Bmap = read2Dfieldmap_corrected( 'xleap2-wiggler-data/SLAC/X-LEAP-1/DATASET0001/Tuning/Z Scans/Run 018/' );  % 2D field map
%      % plot the field
%      plot_2dfields_contours
%      if(1==1) % replace 2D map with on axis field map and plot field integral?
%          xpositions = Bmap(:,4);
%          Bmap = Bmap(xpositions==-1e-3,1:3); % on-axis field from 2D field map
%          % plot the field intergral on this slice
%  %          plot_field_integral;
%          plot_field_integral_raw;
%      end
%      % plot the trajectory calculated from 3D kinematics with the Lorentz force
%      energy_GeV = 4.;
%      x0 = 566e-6 * 4. / energy_GeV; y0 = 0; xp0 = 0; yp0 = 0; gamma0 = energy_GeV*1000./0.511;
%      relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
%  %      if(1==1) % replace 2D map with on axis field map?
%  %          y_offset_scan_Q = 0; plot_field_integrals_raw( y_offset_scan_Q, Bmap, relative_field_rolloff );
%  %      end
%  %      results = plot_orbit( x0, y0, xp0, yp0, gamma0, Bmap, relative_field_rolloff ); % trajectory
%  %      matrix_element; display(mat); display(normmat); display(round((ray0(2:end) - [x0,0,0,0])*1e6));
%  end

if(1==0) % WIGGLER 1 - 2D map from SLAC - run 018
    % read the field map
    Bmap = read2Dfieldmap( 'S:\magdata\LCLS-II\Undulator\X-LEAP-3\DATASET0002\Tuning\Z Scans/Run 004/' );  % 2D field map
%      Bmap = read2Dfieldmap_corrected( 'xleap2-wiggler-data/SLAC/X-LEAP-1/DATASET0001/Tuning/Z Scans/Run 018/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 566e-6 * 4. / energy_GeV; y0 = 0; xp0 = 0; yp0 = 0; gamma0 = energy_GeV*1000./0.511;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    if(1==1) % plot field integrals?
        y_offset_scan_Q = 0; plot_field_integrals_raw( y_offset_scan_Q, Bmap, relative_field_rolloff );
    end
%      results = plot_orbit( x0, y0, xp0, yp0, gamma0, Bmap, relative_field_rolloff ); % trajectory
%      matrix_element; display(mat); display(normmat); display(round((ray0(2:end) - [x0,0,0,0])*1e6));
end

if(1==0) % WIGGLER 1 - 2D map from SLAC - run 014
    % read the field map
    Bmap = read2Dfieldmap( 'S:\magdata\LCLS-II\Undulator\X-LEAP-3\DATASET0002\Tuning\Z Scans/Run 004/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    if(1==0) % replace 2D map with on axis field map?
        xpositions = Bmap(:,4);
        Bmap = Bmap(xpositions==0,1:3); % on-axis field from 2D field map
        % plot the field intergral on this slice
        plot_field_integral;
    end
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 566e-6; y0 = 0; xp0 = 0; yp0 = 0; gamma0 = energy_GeV*1000./0.511;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    results = plot_orbit( x0, y0, xp0, yp0, gamma0, Bmap, relative_field_rolloff ); % trajectory
    matrix_element; display(mat); display(normmat);
end


if(1==0) % WIGGLER 1 - 2D map from SLAC - run 013
    % read the field map
    Bmap = read2Dfieldmap( 'S:\magdata\LCLS-II\Undulator\X-LEAP-3\DATASET0002\Tuning\Z Scans/Run 004/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    if(1==0) % replace 2D map with on axis field map?
        xpositions = Bmap(:,4);
        Bmap = Bmap(xpositions==0,1:3); % on-axis field from 2D field map
        % plot the field intergral on this slice
        plot_field_integral;
    end
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 566e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 1 - 1D file from SLAC
    % read the field map
    Bmap = readfieldmap( 'S:\magdata\LCLS-II\Undulator\X-LEAP-3\DATASET0002\Tuning\Z Scans\Run 004\002gap000.000x+00.00y+00.00/zscan.dat' ); 
    % plot the field
    figure; set(gcf,'color','w'); plot(Bmap(:,1),Bmap(:,2)); hold on; plot(Bmap(:,1),Bmap(:,3)); hold off;
    xlabel('z position (m)'); ylabel('Magnetic field (T)'); legend('Bx','By','location','best'); enhance_plot('arial',20,2,8);
    % plot the field intergral
    plot_field_integral;
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 566e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm)
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end



if(1==0) % WIGGLER 1 - 2D map from SLAC
    % read the field map
    Bmap = read2Dfieldmap( 'S:\magdata\LCLS-II\Undulator\X-LEAP-3\DATASET0002\Tuning\Z Scans/Run 007/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    if(1==0) % replace 2D map with on axis field map?
        xpositions = Bmap(:,4);
        Bmap = Bmap(xpositions==0,1:3); % on-axis field from 2D field map
        % plot the field intergral on this slice
        plot_field_integral;
    end
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 566e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 1 - 1D file from ANL
    % read the field map
    Bmap = readfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-onaxis/xLEAP-II-1.dat' ); 
    % plot the field
    figure; set(gcf,'color','w'); plot(Bmap(:,1),Bmap(:,2)); hold on; plot(Bmap(:,1),Bmap(:,3)); hold off;
    xlabel('z position (m)'); ylabel('Magnetic field (T)'); legend('Bx','By','location','best'); enhance_plot('arial',20,2,8);
    % plot the field intergral
    plot_field_integral;
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 566e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm)
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 1 - 2D map from ANL
    % read the field map
    Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-1/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    if(1==0) % replace 2D map with on axis field map?
        xpositions = Bmap(:,4);
        Bmap = Bmap(xpositions==0,1:3); % on-axis field from 2D field map
        % plot the field intergral on this slice
        plot_field_integral;
    end
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 566e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end



if(1==0) % WIGGLER 2 - 1D file from ANL
    % read the field map
    Bmap = readfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-onaxis/xLEAP-II-2.dat' ); 
    % plot the field
    figure; set(gcf,'color','w'); plot(Bmap(:,1),Bmap(:,2)); hold on; plot(Bmap(:,1),Bmap(:,3)); hold off;
    xlabel('z position (m)'); ylabel('Magnetic field (T)'); legend('Bx','By','location','best'); enhance_plot('arial',20,2,8);
    % plot the field intergral
    plot_field_integral;
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = -500e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm)
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 2 - 2D map from ANL
    % read the field map
    Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-2/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    if(1==0) % replace 2D map with on axis field map?
        xpositions = Bmap(:,4);
        Bmap = Bmap(xpositions==0,1:3); % on-axis field from 2D field map
        % plot the field intergral on this slice
        plot_field_integral;
    end
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = -500e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 3 - 1D file from ANL
    % read the field map
    Bmap = readfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-onaxis/xLEAP-II-3.dat' ); 
    % plot the field
    figure; set(gcf,'color','w'); plot(Bmap(:,1),Bmap(:,2)); hold on; plot(Bmap(:,1),Bmap(:,3)); hold off;
    xlabel('z position (m)'); ylabel('Magnetic field (T)'); legend('Bx','By','location','best'); enhance_plot('arial',20,2,8);
    % plot the field intergral
    plot_field_integral;
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 516e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm)
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 3 - 2D map from ANL
    % read the field map
    Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-3/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    if(1==0) % replace 2D map with on axis field map?
        xpositions = Bmap(:,4);
        Bmap = Bmap(xpositions==0,1:3); % on-axis field from 2D field map
        % plot the field intergral on this slice
        plot_field_integral;
    end
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = 516e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 4 - 1D file from ANL
    % read the field map
    Bmap = readfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-onaxis/xLEAP-II-4.dat' ); 
    % plot the field
    figure; set(gcf,'color','w'); plot(Bmap(:,1),Bmap(:,2)); hold on; plot(Bmap(:,1),Bmap(:,3)); hold off;
    xlabel('z position (m)'); ylabel('Magnetic field (T)'); legend('Bx','By','location','best'); enhance_plot('arial',20,2,8);
    % plot the field intergral
    plot_field_integral;
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = -520e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm)
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 4 - 2D map from ANL
    % read the field map
    Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-4/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    if(1==0) % replace 2D map with on axis field map?
        xpositions = Bmap(:,4);
        Bmap = Bmap(xpositions==0,1:3); % on-axis field from 2D field map
        % plot the field intergral on this slice
        plot_field_integral;
    end
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = -520e-6; y0 = 0; xp0 = 0; yp0 = 0;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    results = plot_orbit( x0, y0, xp0, yp0, energy_GeV*1000./0.511, Bmap, relative_field_rolloff ); % trajectory
end


if(1==0) % WIGGLER 4 - 2D map from ANL
    % read the field map
    Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-4/' );  % 2D field map
%      Bmap = read2Dfieldmap_corrected( 'xleap2-wiggler-data/SLAC/X-LEAP-4/DATASET0001/Tuning/Z Scans/Run 010/' );  % 2D field map
    % plot the field
    plot_2dfields_contours
    % plot the trajectory calculated from 3D kinematics with the Lorentz force
    energy_GeV = 4.;
    x0 = -520e-6 * 4. / energy_GeV; y0 = 0; xp0 = 0; yp0 = 0; gamma0 = energy_GeV*1000./0.511;
    relative_field_rolloff = 0.003; % 1-By(x=1)/By(x=0mm) - not used for 2D field maps
    if(1==1) % plot field integrals?
        y_offset_scan_Q = 0; plot_field_integrals_raw( y_offset_scan_Q, Bmap, relative_field_rolloff );
    end
    results = plot_orbit( x0, y0, xp0, yp0, gamma0, Bmap, relative_field_rolloff ); % trajectory
    matrix_element; display(mat); display(normmat); display('dx  dy  dxp  dyp = ');display(round((ray0(2:end) - [x0,0,0,0])*1e6));
end

























%  %  wiggler 1
%  Bmap = readfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-onaxis/xLEAP-II-1.dat' ); % 1D scan from ANL
%  plot_field_integral
%  Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-1/' );  % 2D field map
%  Bmap = Bmap(Bmap(:,4)==0,1:3); % on-axis field from 2D field map
%  %  results = plot_orbit( 644*1e-6, 0., 0, 0., 3490./0.511, Bmap, 0.003 );
%  results = plot_orbit( 566e-6, 0., 0, 0., energy_GeV*1000./0.511, Bmap, 0.003 );
%  plot_2dfields_contours
%  plot_field_integral

%  %  wiggler 2
%  %  Bmap = readfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-onaxis/xLEAP-II-2.dat' ); % 1D scan
%  Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-2/' );  % 2D field map
%  %  results = plot_orbit( 644*1e-6, 0., 0, 0., 3490./0.511, Bmap, 0.003 );
%  results = plot_orbit( -500e-6, 0., 0, 0., energy_GeV*1000./0.511, Bmap, 0.003 );
%  %  plot_2dfields_contours
%  
%  %  wiggler 3
%  %  Bmap = readfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-onaxis/xLEAP-II-3.dat', 34 ); % 1D scan
%  Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-3/' );  % 2D field map
%  %  results = plot_orbit( 644*1e-6, 0., 0, 0., 3490./0.511, Bmap, 0.003 );
%  results = plot_orbit( 516e-6, 0., 0, 0., energy_GeV*1000./0.511, Bmap, 0.003 );
%  %  plot_2dfields_contours
%  
%  %  wiggler 4
%  %  Bmap = readfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-onaxis/xLEAP-II-4.dat' ); % 1D scan
%  Bmap = read2Dfieldmap( 'xleap2-wiggler-data/ANL/xLEAP-II-4/' );  % 2D field map
%  %  results = plot_orbit( 644*1e-6, 0., 0, 0., 3490./0.511, Bmap, 0.003 );
%  results = plot_orbit( -520e-6, 0., 0, 0., energy_GeV*1000./0.511, Bmap, 0.003 );
%  %  plot_2dfields_contours

