Description of the element "mag3d" for a dipole magnet with external 3D fields Element entry in the lattice file "sclinac.dat": n mag3d f_len rbend theta airgap width bet1 bet2 invr1 invr2 nstep n : number of the mag3d file to use (n=1 --> mag3d.#01) f_len [cm] : field length in file including fringe fields (not real dipole length) rbend [cm] : bending radius theta [deg]: bending angle airgap [cm]: airgap width [cm] : width bet1 [deg]: entrance angle bet2 [deg]: exit angle r1inv[1/cm]: entrance curvature radius (not used) r2inv[2/cm]: exit curvature radius (not used) nstep : number of integration steps Example: 1 mag3d 93.6 50. 60. 6. 12. 30. 30. 0. 0. 200 Format of the 3D field file: The Z direction of the field data has an angle of "theta/2" with the incomming and outgoing beam directions. So the field is a 3D box at half the bending angle from in and out beam directions. The field file is ASCI and could be read in fortran as follow: open(2, file=magfile, status='old') read(2,*) ngx, xmn, xmx read(2,*) ngy, ymn, ymx read(2,*) ngz, zmn, zmx do i = 1, ngx do j = 1, ngy do k = 1, ngz read(2,*) b1, b2, b3 bx(i,j,k) = b1 by(i,j,k) = b2 bz(i,j,k) = b3 enddo enddo enddo close(2) where: ngx, ngy, ngz: number of data points in every direction xmn, ymn, zmn: field's lower limits in X, Y and Z xmx, ymx, zmx: field's upper limits in X, Y and Z bx , by , bz : field data arrays Central trajectory calculation: TRACK is z-based code; the integration is done with steps in the distance z, so we should first determine the length of the central trajectory. This is done using the input beam energy (Win) and the reference partile mass and charge state (Adesign, Qdesign). Both the field strength and the central trajectory length are adjusted using a fit to have an exit point symmetric to the entrance point for the central trajectory. Once the central trajectory length is determined it'll be considered as the actual length of the magnet and will be divided into "nstep" integration step to track the real beam particles.