
%This program calculates the trajectory slope and position from the field
%integrals.  See LCLS-TN-05-22, "Undulator Field Integral Measurements" for
%a discussion of the calculation.
%Zachary Wolf
%6/20/08

%Constants
Q_ELEC = -1.60217733e-19;    %Electron charge (C)
M_ELEC = 9.1093897e-31;      %Electron mass (kg)
C_LIGHT = 2.99792458e8;      %Speed of light (m/s)
JOULE_PER_EV = 1.60217733e-19;  %Conversion factor, 1 eV = 1.60217733e-19 J

%Input parameters
%elec_energy_ev = 13.64e9;    %Electron energy (eV)
%I1_x = 40.e-6;               %First integral of Bx (Tm)
%I1_y = 40.e-6;               %First integral of By (Tm)
%I2_x = 50.e-6;               %Second integral of Bx (Tm^2)
%I2_y = 50.e-6;               %Second integral of By (Tm^2)

%Input parameters
%elec_energy_ev = 135.0e6;    %Electron energy (eV)
%I1_x = 0.04 * 1.e-4;         %First integral of Bx (Tm)
%I1_y = 0.04 * 1.e-4;         %First integral of By (Tm)
%I2_x = 0.20 * 1.e-4;         %Second integral of Bx (Tm^2)
%I2_y = 0.20 * 1.e-4;         %Second integral of By (Tm^2)

%Input parameters
elec_energy_ev = 135.0e6;    %Electron energy (eV)
I1_x = 0.00 * 1.e-4;         %First integral of Bx (Tm)
I1_y = -5.9e-6;              %First integral of By (Tm)
I2_x = 0.00 * 1.e-4;         %Second integral of Bx (Tm^2)
I2_y = 0.00 * 1.e-4;         %Second integral of By (Tm^2)

%Calculate gamma
elec_energy_j = elec_energy_ev * JOULE_PER_EV;
gamma = elec_energy_j / (M_ELEC * C_LIGHT^2);

%Calculate the factor relating trajectories to field integrals
%Approximate the electron velocity by the speed of light
fact = Q_ELEC / (gamma * M_ELEC * C_LIGHT);

%Calculate the trajectory information
dx_dz = - fact * I1_y;
dy_dz = fact * I1_x;
x = - fact * I2_y;
y = fact * I2_x;

%Print the results
gamma
fact
dx_dz
dy_dz
x
y

%Done
