source: TRACY3/trunk/tracy/tracy/doc/soltracy3_userManual_developer.tex @ 11

Last change on this file since 11 was 11, checked in by zhangj, 11 years ago
File size: 132.6 KB
Line 
1\documentclass{article}
2\author{Jianfeng Nadolski \footnote{LAL, Orsay, France.Email: \href{mailto:zhangj@lal.in2p3.fr}{zhangj@lal.in2p3.fr}}}
3\title{Soltracy3 mannual for developpers}
4
5\usepackage{amsmath}
6\usepackage{amssymb}
7\usepackage{graphicx}
8\usepackage[colorlinks=true,urlcolor=magenta,citecolor=blue]{hyperref}
9\usepackage{color}
10\usepackage{setspace}
11
12
13%% auto center the sentence in the line
14\newenvironment{tightcenter}{%
15   \vspace{0.02in} 
16 \setlength\topsep{0pt}
17  \setlength\parskip{0pt}
18  \begin{center}
19}{%
20  \end{center}
21\vspace{0.02in} 
22 }
23
24%% auto wrap a long word
25\newcommand*\wrapletters[1]{\wr@pletters#1\@nil}
26\def\wr@pletters#1#2\@nil{#1\allowbreak\if&#2&\else\wr@pletters#2\@nil\fi}
27
28% define the file path font
29\newcommand{\pathfont}[1]{\textit{\wrapletters{#1}}} 
30% define the font and color of the Tracy command in Tracy file
31\newcommand{\tracycommand}[2]{\begin{tightcenter} 
32                               \textsf{\textcolor{red}{#1}} \quad \textsf{\textcolor{blue}{#2}} 
33                              \end{tightcenter}}
34\newcommand{\tracycomm}[1]{\textsf{\textcolor{red}{#1}}}
35\newcommand{\tracypara}[1]{\textsf{\textcolor{blue}{#1}}}
36
37% lattice element definition
38\newcommand{\latticedef}[3]{\begin{tightcenter}
39                               \textsf{\textcolor{black}{#1}}   
40                               \textsf{\textcolor{red}{#2}} \quad \textsf{\textcolor{blue}{#3}} 
41                              \end{tightcenter}}
42\newcommand{\elemname}[1]{\textsf{\textcolor{black}{#1}}}
43\newcommand{\elemkeyword}[1]{\textsf{\textcolor{red}{#1}}}
44\newcommand{\elempara}[1]{\textsf{\textcolor{blue}{#1}}}
45
46\newcommand{\notespace}[1]{\vspace{0.1in}\textbf{#1} \vspace{0.05in}}
47
48
49\begin{document}
50
51\maketitle
52\tableofcontents
53
54%\onehalfspacing
55
56\section{Log}
57
58\begin{itemize}
59\item[05/10/2012] Add the control flag to control the entrance and exit edge effects and fringe
60field of the dipole, with``edge\_effect1 = 1'' in the dipole definition in the lattice file, the
61entrance edge effect and fringe field of the dipole are turned on, with ``edge\_effect1 = 0'',
62this effects are turned off. These two effects at the exit of the dipole are controlled by
63``edge\_effect2''.
64\end{itemize}
65
66\section{Introduction}
67  Tracy is a code to do long term tracking, and is written in the mixture of c and c++.
68This code is kept on developing. Soleil version of Tracy 3 is a code with more flexibility and easy to use.  User does not need to know the structure of the code, what they need to do is to write an input script, and then run the code.
69   Based on the need, user can write the files to define multipole field errors, misalignment errors of the lattice elements, and vacuum chamber, and then provide the file name in the user input script, in order to set the field errors of the lattice elements and the vacuum limit for the different region of the lattice.
70Attention:
71In the user defined file, such as the user input script, the file to define multipole field errors or alignment errors, or the file to define vacuum chambers, the maximum numbers of column is 130 (Not including comment line which starts with symbol \#.), and the spaces between each parameters or variables can’t contain “TAB” key, otherwise the code can’t work properly. This is because the routine to read the user defined input file is written in C. These limits will be improved in the future development.
72Although the user can define the file name whatever they want,  it is suggested to name the file which is used to define multipole field error with the extension “.fe” and name the file which is used to define the misalignment error with the extension “.ae”.   
73
74  There are two versions of Tracy 3, non-parallel version and parallel version.  Non-parallel version Tracy is for the single computer, parallel version of Tracy is for the the cluster. The user defined input script which can be used for both parallel and non-parallel version Tracy. The ascii file with any extension isacceptable for Tracy3, but the extension is suggested to be “.prm”.
75
76\section{ Non-parallel version Tracy}
77\subsection {Compile}
78The make file of Tracy is generated by “automake”. Based on the compilers used,
79user needs to update “\textsf{\wrapletters{make\_for\_gcc.sh}}” under
80path ``\pathfont{\$HOME/TracyIII/}''
81or the ``Makefile.am'' under path ``\pathfont{\$HOME/TracyIII/tracy/tracy/src}''
82and ``\pathfont{\$HOME/TracyIII/tracy/tools}''. The compilers used on the server
83``metis'' of SOLEIL Synchrotron are ``gfortran'', and ``gcc''.
84
85To compile the code, run the command under the shell terminal:
86\begin{tightcenter}
87 \textsf{make\_for\_gcc.sh}     \qquad   \textsf{opt} 
88\end{tightcenter}
89Then the executive file ``soltracy'' is automatically
90generated under path ``\pathfont{\$HOME/TracyIII/tracy/tools}''.   
91
92\subsection{Run}
93 To execute Tracy, the user needs to define an input file with the
94 the lattice file names and the related commands (section~\ref{}).
95 The name of the input file can be any valid characters. Although
96 there is no limitation to the extension of the file, the extension
97 ``.prm'' is preferred. For example, To run the user defined input file
98 ``Input\_test.prm'', user can type the command:
99\begin{tightcenter}
100  \textsf{soltracy}       \qquad        \textsf{Input\_test.prm}
101\end{tightcenter}
102
103\section{ Parallel version Tracy}
104In order to reduce the tracking time, the parallel version Tracy can be used
105on the cluster. Until now, the following three features of Tracy are
106parallelized:
107\begin{itemize} 
108\item 
109Frequency map analysis for on momentum particle, command ``FmapFlag''.
110\item 
111Frequency map analysis for off momentum particle, command ``FmapdpFlag''.
112\item 
113Track momentum acceptance at lattice elements, command ``MomentumAccFlag''.
114\end{itemize}
115
116\subsection{Compile}
117The commonly used compilers for parallel computation are MPI 2, and Intel
118MPI which is based on MPI 2. For the cluster of SOLEIL Synchrotron, Intel
119MPI is installed. To get the parallel Tracy work, three files of the
120non-parallel version Tracy need to be modified. The details are shown in
121the following steps.
122\begin{enumerate}
123\item
124The path of included files of Intel MPI is added in ``Makefile.am'' under
125path ``\pathfont{\$HOME/TracyIII/tracy/tracy/src}'' (shown in BLUE color):
126
127          \wrapletters{INCLUDES = -I../inc -I\$(NUM\_REC)/inc \quad
128          -I/opt/intel/impi/3.2.2.006/include64}
129
130\item
131 The execute file, source file, paths of included files and library of Intel
132MPI are modified in ``Makefile.am'' under path ``\pathfont{\$HOME/TracyIII/tracy/tools}''
133 (shown in BLUE color):
134
135bin\_PROGRAMS = psoltracy
136
137soltracy\_SOURCES  = \texttt{soltracy.cc  nrutil.c nrcheck.c    }
138\texttt{  nrlinwww.c   nrframe.c ../tracy/src/tracy\_lib.cc $\rightarrow$}
139
140  psoltracy\_SOURCES  = \texttt{psoltracy.cc  nrutil.c  nrcheck.c   
141  nrlinwww.c   nrframe.c   ../tracy/src/tracy\_lib.cc}
142
143  LIBS =  \texttt{\wrapletters{-L\$(NUM\_REC)/lib \quad
144          -L/opt/intel/impi/3.2.2.006/lib64   \quad -L\$(LIBPATH)  \quad
145          -lrecipes\_c\_icc \quad -lstdc++ \quad -lgfortran \quad -lmpichcxx}}
146 
147INCLUDES = \texttt{\wrapletters{-I\$(TRACY\_LIB)/tracy/inc \quad -I\$(NUM\_REC)/inc
148                   \quad  -I/opt/intel/impi/3.2.2.006/include64}}
149
150\item
151The compilers used in the parallel computing are defined in the
152``\wrapletters{make\_for\_psoltracy.sh}'' located in path ``\$HOME/TracyIII''
153as (shown in BLUE color):
154
155                 CC = \texttt{mpiicc}
156
157                CXX = \texttt{mpiicpc}
158
159                F77 = \texttt{mpiifort}
160
161Depending on the compilers used to do parallel computation, user needs to
162update the compilers in ``make\_for\_psoltracy.sh'' and the paths of included
163files and library which are shown above with blue color.
164
165After updating compilers, paths of included files and library for parallel
166computation, user can run
167\begin{tightcenter}
168\textsf{make\_for\_psoltracy.sh}
169\end{tightcenter}
170under the shell script to compile the parallel Tracy. After compilation,
171the execute file ``psoltracy'' is automatically generated under the
172path ``\pathfont{\$HOME/TracyIII/tracy/tools}''.
173\end{enumerate}
174
175
176\subsection{Run}
177As the non-parallel version Tracy, user needs to write the commands in a
178script which must be with the file extension ``.prm''. The syntaxes to define
179the script ``*.prm'' are the same for both non-parallel and parallel
180Tracy.
181
182To run the parallel Tracy, user need to contact the administrator of their
183cluster to know how to run parallel programs on the cluster. For the cluster
184on Synchrotron SOLEIL, the nodes used to do parallel computation are assigned
185by PBS (Portable Batch System), so a script is need. For example, user define
186the input script \texttt{test.prm} to tell Tracy what jobs are need to be done on the
187cluster,  define script \textsf{\wrapletters{lance\_tracy3\_parallel.sh}} to assign
188the numbers of CPUs to do
189parallel computation and lance job to the SOLEIL cluster; and then type the
190following command under the bash shell to submit the job and run the parallel
191Tracy on the cluster:
192\begin{tightcenter}
193  \textsf{lance\_tracy3\_parallel.sh  \qquad   test.prm}
194\end{tightcenter}
195
196
197\section{ User input script}
198There are two types of keywords in the user input script. The first type is
199to set the file, the file names, and define parameters for the related
200calculations; the key words for such definitions are ended with the
201characters ``Flag''. The second type is to define Boolean commands with or
202without parameters to do different calculations. The rules of the definition
203of input scripts are:
204\begin{itemize}
205\item
206The blank lines and lines starting with ``\#'' (comment line) are ignored
207by the code.
208\item
209Keywords without ``Flag'' as the final 4 characters are NOT executed according
210to the defined sequence in user input script. If the same command keywords
211are defined many times in the user script, only the last defined keyword is
212executed.
213\item
214The commands with the last 4 characters as ``Flag'' are executed according
215to the sequence in the code.
216\item
217The definition of lattice file at the beginning of the user script is mandatory.
218\item
219If the horizontal correctors, or vertical correctors, or girders, Beam Position
220Monitors, or skew quadrupoles are defined in the lattice file, user must
221declare the element name at the beginning of Tracy input file.
222\item
223One keyword command uses one line. User can not define more than one command
224at the same line.   
225\item
226Except explanation, all commands with Boolean flag are the generic commands,
227that is, the commands are not machine dependent.
228\end{itemize}
229
230\subsection{File path}
231In the user input script, user can specify the name of the files which are used
232in the calculation, such as the lattice file, multipole field error file,
233misalignment error file, vacuum chamber file. When specifying the file name without
234file path in the Tracy input file, Tracy will look for the file in the current
235work path. Otherwise, user need to provide the absolute path of the file which is
236not located at the current path, such as: ``\texttt{\wrapletters{/home/physmach/Tracy3/tracy/soleil.lat}}''.
237Another method is to provide the filename without absolute path, but put all the
238called external files at a certain directory, and this directory is defined in the
239Tracy input file using the command:
240                \tracycommand{in\_dir}{user\_defined\_path}
241For example,
242                \tracycommand{in\_dir}{/home/zhang/codes/TracyIII/lattice/}
243This example tells the code all the files defined with absolute file path in the Tracy
244input file are located
245at the directory \pathfont{/home/zhang/codes/TracyIII/lattice/}. If user declares the files
246without absolute path and does not set the directory through command \textsf{in\_dir}; or
247the files specified in the script are not found at the current working path,
248the code will give an error message and stop running.
249
250\section{File names}   
251
252\subsection{Lattice file name}
253In the input script, user must define the lattice name, this is mandatory.
254The command is:
255
256\tracycommand{lat\_file}{lattice\_file\_name}
257
258Here \tracypara{lattice\_file\_name} is the lattice file name without the extension ``.lat''.
259For example, the following command sets the lattice file of SOLEIL ring:
260\tracycommand{lat\_file}{solamor2}
261
262n Tracy 3, after reading the lattice, Twiss parameters are automatically printed to the
263file \textsl{linlat.out}.                                 
264 
265If one of these elements (Horizontal/vertical correctors or beam position monitors, or
266girders, or skew quadrupoles.) are defined in the lattice file, for example to read
267the misalignment errors of the lattice element and then do orbit correction, to read multipole
268field errors (SOLEIL lattice), etc.; user MUST specify the names of these elements using the
269corresponding commands in the Tracy input file:
270\tracycommand{h\_corr}{HCM}
271\tracycommand{v\_corr}{VCM}
272\tracycommand{gs}{GS}
273\tracycommand{ge}{GE}
274\tracycommand{bpm\_name}{BPM}
275\tracycommand{qt}{QT}
276Here \tracypara{HCM} is the name of horizontal correctors for horizontal orbit correction,
277or the horizontal correctors on which the multipole field errors are added in SOLEIL lattice;
278\tracypara{VCM} is the name of vertical correctors used for vertical orbit correction, or
279the vertical correctors on which the multipole field errors are added in SOLEIL lattice;
280\tracypara{GS} is the name of the start girder; \tracypara{GE} is the name of the end girder;
281\tracypara{BPM} is the name of beam position monitors defined in the lattice file;
282\tracypara{QT} is the name of the skew quadrupoles defined in the lattice.  Generally,
283user needs to define horizontal, vertical correctors and BPMs when reading the misalignment
284errors or correcting closed orbit distortion. 
285
286\subsection{Multipole field error file name (SOLEIL lattice)}
287User can read the multipole field errors on SOLEIL lattice from an external file;
288the file is specified in the user script using the following command:
289\tracycommand{multipole\_file}{multipole\_file\_name}
290Here \tracypara{multipole\_file\_name} is the user defined multipole field error file,
291the format of this file is given in section~\ref{}.
292
293If the multipole field errors of horizontal, vertical correctors and skew quadrupoles
294are defined in the \tracypara{multipole\_file}, user MUST specify the names of these
295lattice elements in the Tracy input file as the following example:
296\tracycommand{h\_corr}{CH}
297\tracycommand{v\_corr}{CV}
298\tracycommand{qt}{QT}
299Here \tracypara{CH}, \tracypara{CV} and \tracypara{QT} are the names of horizontal,
300vertical correctors, and skew quadrupoles respectively which are defined in the lattice file.
301
302\subsection{Files of multipole field errors of correctors and skew quadrupoles (SOLEIL lattice)}
303Horizontal, vertical correctors and skew quadrupoles are integrated with the sextupole quadrupoles
304on SOLEIL storage ring. To define the multipole field errors on these elements, user need to define the orders and relative strengths of multipole field errors in the multipole  field error file (section Error: Reference source not found) and specify the file name in the user input script “*.prm” (section Multipole field error file name), then specify the file names as the following example:
305\tracycommand{fic\_hcorr}{corh.txt}
306\tracycommand{fic\_vcorr}{corv.txt}
307\tracycommand{fic\_skew}{corqt.txt}
308Here \tracypara{corh.txt} and \tracypara{corv.txt} are the files with measured current values corh,
309corv, corqt (with unit [Ampere]) for the horizontal, vertical correctors and skew quadrupoles
310respectively. Based on the measured current values, user can get the integrated field strength as:\\
311\vspace{0.02in}
312\texttt{Hcorr\_strength [T.m] = corh *\_convHcorr /brho; (horizontal correctors) \\}
313\vspace{0.02in}
314\texttt{Vcorr\_strength [T.m] = corv *\_convVcorr /brho;  (vertical correctors)} \\
315\vspace{0.02in}
316\texttt{Qt\_strength [T.m] = corqt *\_convQt /brho;  (skew quadrupoles)} \\
317\vspace{0.02in}
318
319Here brho is the momentum rigidity, and the conversion constants between current and field are \texttt{\_convHcorr} = 8.14e-4, \texttt{\_convVcorr} = 4.642e-4, \texttt{\_convQt} = 93.83e-4.
320 
321For SOLEIL lattice, the SAME ORDER of multipole field errors on the same elements are added together,
322so the SAME ORDER of horizontal/vertical, skew quadrupoles, and sextupoles are added together since
323these elements are integrated at the same magnets.
324
325\subsection{ File to define field strength of virtual coupling source elements (SOLEIL lattice)}
326 On SOLEIL storage ring, the coupling is thought to come from the rotation of quadrupoles
327and vertical displacements of sextupoles. The strengths of these coupling sources are
328written in a file, then read by the following command:
329\tracycommand{virtualskewquad\_file}{virtual\_skew\_quad\_currents.txt}
330
331Here \tracypara{virtual\_skew\_quad\_currents.txt} is the user defined file with strength
332of vertical coupling source.
333
334In order to use this command to read the virtual sources of coupling, user needs to define
335the virtual coupling element as a skew quadrupole in the lattice file:
336\latticedef{SQ:}{quadrupole,}{tilt=45.0, K= 0.0, method=4, N=1;}
337and this virtual coupling element MUST be with the name “SQ”. Now there 152 elements defined as the virtual coupling sources in the SOLEIL lattice. The syntaxs to define skew quadrupole are explained in section .
338  The measured current value qtcorr[i] of the ith coupling source is converted to the corresponding integrated skew quadrupole field strength corr\_strength as
339corr\_strength [m-1] = qtcorr[i]*conv/brho;
340here brho is momentum rigidity, and the conversion constant conv is 93.88e-4 [A-1.T].
341
342\subsection{Cut off value}
343  Set the cut off value of all random distribution (Gaussian distribution) to “n” times of the RMS value sigma:
344normalcut       n
345
346\section{Physics: Hamiltionian}
347The dynamic motion of a conserved system can be described by a Hamiltonian. For an accelerator system without radiation
348damping (energy loss) and RF cavities (energy gain), the motion of a single electron in the magnetic field can be described using the
349following Hamitonian in the curvilinear coordinate system (Merz...)
350\begin{eqnarray}
351H (x,P_x; y, P_y; -t, \delta; s) &=&  L + V  \\
352                                 &=& -(1+h_{\mathrm{ref}}x)[\sqrt(P^2 - (P_x - eA_x)^2 - (P_y - eA_y)^2 ) + eA_z(x,P_x; y, P_y,s)]  \\
353P^2 & =& P_x^2 + P_y^2 + P_z^2
354\end{eqnarray}
355$h_{\mathrm{ref}}$ is the curvature of reference orbit inside the dipole.
356The $(x,P_x; y, P_y; -t, \delta)$ are the canonical cooridinates of the $H$, and $P_x, P_y, P-z$ are respectively the
357horizontal, vertical, and longitudinal mechanical momentums. A more convienent way is to expand the electron motion
358around the motion of a reference particle with total momentum $P_0$, so
359\begin{eqnarray}
360\frac{1}{P_0}H (x,P_x; y, P_y; -t, \delta; s) &=& \\
361H (x,p_x; y, p_y; -t, \delta; s) &=& -(1+h_{\mathrm{ref}}x)\sqrt((1+\delta)^2 - (p_x - \frac{e}{P_0}A_x)^2 - (p_y - \frac{e}{P_0}A_y)^2 ) + \frac{e}{P_0}A_z(x,p_x; y, p_y,s) \\
362                                &=& -(1+h_{\mathrm{ref}}x)\sqrt((1+\delta)^2 - (p_x - \frac{1}{B \rho}A_x)^2 - (p_y - \frac{1}{B \rho}A_y)^2 ) + \frac{1}{B \rho}A_z(x,p_x; y, p_y,s)
363\end{eqnarray}
364with
365\begin{eqnarray}
366p_x &=& \frac{P_x}{P_0}  \\
367p_y &=& \frac{P_y}{P_0}  \\
368p &=& \frac{P}{P_0} = \frac{\Delta P + P_0}{P_0} = (1+\delta)   \\
369\delta &=& \frac{\Delta P}{P_0} \\
370B \rho &=& \frac{P_0}{e} (magnetic rigidity)
371\end{eqnarray}
372
373With some operations (J. Bengtsson's linear transverse dynamics for sotrage ring with applications to the low energy antiproton ring (LEAR) at CERN; Tracy 2 manual.),
374the Hamitonian can be expressed with the canonical coordinates $(x,p_x; y, p_y; -ct, \delta; s)$ (Tracy-2 Manual, J. Bengtsson)
375
376\begin{align*} 
377%\label{Tracy:Exact:H}
378H (x,p_x; y, p_y; -ct, \delta; s) \\
379&=-(1+h_{\mathrm{ref}}x)(\sqrt{(1+\delta)^2 - (p_x - \frac{A_x}{B \rho})^2 - (p_y - \frac{A_y}{B \rho})^2}  + \frac{A_z}{B \rho}) + \delta  \\ 
380&= -(1+h_{\mathrm{ref}}x)(\sqrt{(1+\delta)^2 - (p_x - \frac{A_x}{B \rho})^2 - (p_y - \frac{A_y}{B \rho})^2 }) + h_{\mathrm{ref}} x \frac{A_z}{B \rho}  \\
381& + \frac{A_z}{B \rho} + \delta  \\ 
382&= \underbrace{-(1+h_{\mathrm{ref}}x)\sqrt{(1+\delta)^2 - (p_x - \frac{A_x}{B \rho})^2 - (p_y - \frac{A_y}{B \rho})^2 )}}_\text{kinetic energy} \\
383& + \underbrace{\frac{x}{\rho} +\frac{x}{2\rho^2}}_\text{Gemometic components due to the curvilinear coordinate inside the dipole}\\ 
384& +\underbrace{\frac{A_z}{B \rho}}_\text{magnet contribution}  \\
385& +\underbrace{\delta}_\text{due to the canonical coordinate $-ct$ instead of $-t$}\\ 
386A_z & =A_z(x,p_x; y, p_y,s)
387\end{align*}
388
389The equation is the exact Hamitonian used in Tracy. The $A_x$ are due to the longidutinal fringe field, this is an natural results due to the Maxwell Equation; $h_{\mathrm{ref}}$ is not zero only inside the dipoles.
390
391For the system without fringe field of the magnet, or only consider the field inside the body of the magnet, $A_x = 0$ and $A_y = 0$,
392so the Hamiltonian is
393\begin{align}
394\label{eqn:exact:H:NoFF}
395H (x,p_x; y, p_y; -ct, \delta; s) \\
396&= \underbrace{-(1+h_{\mathrm{ref}}x)\sqrt{(1+\delta)^2 - p_x^2 - p_y^2)}}_\text{kinetic energy} \\
397& + \underbrace{\frac{x}{\rho} +\frac{x}{2\rho^2}}_\text{Gemometic components due to the curvilinear coordinate inside the dipole}\\ 
398& +\underbrace{\frac{A_z}{B \rho}}_\text{magnet contribution}  \\
399& +\underbrace{\delta}_\text{due to the canonical coordinate $-ct$ instead of $-t$}\\ 
400\end{align}
401
402From eqn.~\ref{eqn:exact:H:NoFF}, it is easy to get the map of the particle inside different lattice elements.
403
404
405\subsection{Map of drift}
406\label{H:drift}
407
408In the drift, $A_z = 0$, and $h_{\mathrm{ref}}$ = 0, from eqn.~\ref{eqn:exact:H:NoFF}, we can get the Hamiltonian
409inside a drift is
410\begin{align}
411\label{eqn:H:exact:drift}
412H (x,p_x; y, p_y; -ct, \delta; s) = -\sqrt{(1+\delta)^2 - p_x^2 - p_y^2)} + \delta
413\end{align}
414
415In large ring, in order to increase the tracking speed, we can expand the sqare root in
416eqn.~\ref{eqn:H:exact:drift} to get the approximate Hamitonian.
417That is,
418\begin{align}
419\label{eqn:H:approxi:drift}
420H (x,p_x; y, p_y; -ct, \delta; s) &= -(1+\delta) \left[ 1 - \frac{p_x^2 + p_y^2}{2 (1+\delta)^2} \right] + \delta\\
421                                  &= \frac{p_x^2 + p_y^2}{2(1+\delta)}
422\end{align}
423
424
425From eqn.~\ref{eqn:H:exact:drift}, it is easy to get the map inside the drift for the
426\textbf{small ring}:
427\begin{align}
428x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = \frac{p_{x0}}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\
429y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}= \frac{p_{y0}}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\ 
430(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} =-\frac{1+\delta_0}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}}+1 \\
431or \\
432(ct)^{'} = \frac{1+\delta_0}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}}-1 \\
433p_x  = p_{x0} \\
434p_y  = p_{y0} \\
435\delta = \delta_0
436\end{align}
437
438From eqn.~\ref{eqn:H:approxi:drift}, it is easy to get the map inside the drift for the
439\textbf{big ring}:
440\begin{align}
441x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = \frac{p_{x0}}{1+\delta_0} \\
442y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}= \frac{p_{y0}}{1+\delta_0} \\ 
443(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} =-\frac{p_{x0^2}+p_{y0}^2}{2(1+\delta_0)} \\
444or \\
445(ct)^{'} = \frac{p_{x0^2}+p_{y0}^2}{2(1+\delta_0)} \\
446p_x  = p_{x0} \\
447p_y  = p_{y0} \\
448\delta = \delta_0
449\end{align}
450
451\subsection{Map of mutipoles}
452 From eqn.~\ref{eqn:exact:H:NoFF}, we can get the Hamiltonian
453inside a multipole without fringe field is
454\begin{align}
455\label{eqn:H:exact}
456H (x,p_x; y, p_y; -ct, \delta; s) \\
457=& \underbrace{-\sqrt{(1+\delta)^2 - p_x^2 - p_y^2}+\delta}_\text{H drift} \\
458& \underbrace{-h_{\mathrm{ref}}x \sqrt{(1+\delta)^2 - p_x^2 - p_y^2}}_\text{H kick} \\
459& + \underbrace{\frac{x}{\rho} +\frac{x}{2\rho^2}-\frac{A_z}{B \rho}}_\text{H kick} 
460\end{align}
461
462In eqn.~\ref{eqn:H:exact}, the Hamiltonian is decomposed into two part, one is the Hamiltonian
463of the drift which is due to the kinetic energy of the system (section~\ref{H:drift}), another part is the kick
464due to the multipoles which will give the kick to the particle.
465Now we only need to focus on the Hamiltonian of the multipoles which induces the kick map:
466\begin{align}
467\label{eqn:H:exact:multipole}
468H (x,p_x; y, p_y; -ct, \delta; s) \\
469&=-h_{\mathrm{ref}}x \sqrt{(1+\delta)^2 - p_x^2 - p_y^2} \\
470& +\frac{x}{\rho} +\frac{x}{2\rho^2}-\frac{A_z}{B \rho}
471\end{align}
472
473Similarly, by expand the sqare root in eqn.~\ref{eqn:H:exact}, we can get the approximate Hamiltonian
474of the multipole as
475\begin{align}
476\label{eqn:H:approxi:multipole}
477H (x,p_x; y, p_y; -ct, \delta; s) \\
478&=-h_{\mathrm{ref}}x \sqrt{(1+\delta)^2 - p_x^2 - p_y^2} \\
479& +\frac{x}{\rho} +\frac{x}{2\rho^2}-\frac{A_z}{B \rho} \\
480&=-h_{\mathrm{ref}} x \delta + \frac{1}{2}h_{\mathrm{ref}} h_{B} x^2 - \frac{A_z}{B \rho}+(h_B - h_{\mathrm{ref}})x
481\end{align}
482where $h_{\mathrm{ref}}$ is the curvature due to the curlininear coordinates inside the dipole,
483$h_{\mathrm{ref}} = 1/\rho_{ref}$;
484$h_{\mathrm{bend}}$ is due to the bending curvature of the dipole which is determined by the dipole
485field, $h_{\mathrm{bend}} = 1/ \rho_{bend}$. $h_{\mathrm{ref}} \neq 0$ only inside dipoles.
486
487In the dipole, $A_z \neq 0$, and $h_{\mathrm{ref}} \neq $ 0, so
488from eqn.~\ref{eqn:H:exact:multipole}, we can get the kick map due to the dipole
489in the \textbf{small ring} which use the exact Hamiltonian:
490\begin{align}
491\label{eqn:kickmap:exact}
492x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = h_{\mathrm{ref}} x_0 \frac{p_{x0}}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\
493y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}=  h_{\mathrm{ref}} x_0 \frac{p_{y0}}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\ 
494p_x^{'}  = -\frac{\partial H}{\partial y_0} = h_{\mathrm{ref}} \sqrt{(1+\delta_0)^2 - p_{x0}^2 - p_{y0}^2} - h_{\mathrm{bend}} - h_{\mathrm{ref}}h_{\mathrm{bend}}x - \frac{B_y}{B \rho}\\
495p_y^{'}  = -\frac{\partial H}{\partial y_0} = \frac{1}{B \rho} \frac{\partial A_z}{\partial y_0} = \frac{B_x}{B \rho}\\
496(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} =-h_{\mathrm{ref}} x_0 \frac{1+\delta_0}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\
497or \\
498(ct)^{'} = h_{\mathrm{ref}} x_0 \frac{1+\delta_0}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\
499\delta = \delta_0 \\
500B \rho = \frac{p_0}{e}
501\end{align}
502where
503\begin{align}
504\frac{\partial A_z}{\partial x} = - B_y \\
505\frac{\partial A_z}{\partial y} = B_x
506\end{align}
507since
508\begin{align}
509A_x = 0 \\
510A_y =0
511\end{align}
512inside the body of the multipoles, and
513\begin{align*}
514\vec{B} = \Delta \times \vec{A}  \\
515\hat{x} & \hat{y} & \hat{z} \\
516\frac{\partial}{x} &  \frac{\partial}{y} &  \frac{\partial}{z} \\
517A_& A_y & A_z \\
518\end{align*}
519
520
521In the dipole, $A_z \neq 0$, and $h_{\mathrm{ref}} \neq $ 0, so
522from eqn.~\ref{eqn:H:approxi:multipole}, we can get the kick map due to the dipole
523in the \textbf{big ring} which use the exact Hamiltonian:
524\begin{align}
525\label{eqn:kickmap:approxi}
526x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = h_{\mathrm{ref}} x_0 \frac{p_{x0}}{1+\delta_0} \\
527y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}=  h_{\mathrm{ref}} x_0 \frac{p_{y0}}{1+\delta_0} \\ 
528p_x^{'}  = -\frac{\partial H}{\partial y_0} = h_{\mathrm{ref}} \delta_0 - (h_{\mathrm{bend}} - h_{\mathrm{ref}}) - h_{\mathrm{ref}}h_{\mathrm{bend}}x - \frac{B_y}{B \rho}\\
529p_y^{'}  = -\frac{\partial H}{\partial y_0} = \frac{1}{B \rho} \frac{\partial A_z}{\partial y_0} = \frac{B_x}{B \rho}\\
530(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} =\frac{-h_{\mathrm{ref}} x_0}{1+\delta_0} \frac{-(p_{x0}^2+p_{y0}^2)}{2(1+\delta_0)} \\
531or \\
532(ct)^{'} =-\frac{h_{\mathrm{ref}} x_0}{1+\delta_0} \frac{(p_{x0}^2+p_{y0}^2)}{2(1+\delta_0)} \\ 
533\delta^{'} = 0
534\end{align}
535
536For other multipoles (quadrupoles, sextupole, decapole, octupole, etc), the curvilinear coordinate is
537the cartesian coordinates, that is $h_{ref}$ = 0, so from eqn.~\ref{eqn:kickmap:exact}, the kick map for
538these multipoles in the small ring is: 
539\begin{align}
540\label{eqn:kickmap:exact:multipole}
541x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = 0 \\
542y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}=  0 \\
543p_x^{'}  = -\frac{\partial H}{\partial y_0} = - (h_{\mathrm{bend}} + \frac{B_y}{B \rho})\\
544p_y^{'}  = -\frac{\partial H}{\partial y_0} = \frac{1}{B \rho} \frac{\partial A_z}{\partial y_0} = \frac{B_x}{B \rho}\\
545(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} = 0\\
546or \\
547(ct)^{'} = 0 \\
548\delta^{'} = 0
549\end{align}
550
551With $h_{ref} = 0$, from eqn:~\ref{eqn:kickmap:approxi}, the kick map for these
552multipoles (quadrupoles, sextupole, decapole, octupole, etc) in the big ring is:
553\begin{align}
554\label{eqn:kickmap:approxi:multipole}
555x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = 0 \\
556y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}=  0 \\
557p_x^{'}  = -\frac{\partial H}{\partial y_0} = - (h_{\mathrm{bend}} + \frac{B_y}{B \rho})\\
558p_y^{'}  = -\frac{\partial H}{\partial y_0} = \frac{1}{B \rho} \frac{\partial A_z}{\partial y_0} = \frac{B_x}{B \rho}\\
559(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} = 0\\
560or \\
561(ct)^{'} = 0 \\
562\delta^{'} = 0
563\end{align}
564
565From the eqn~\ref{eqn:kickmap:exact} to eqn.~\ref{eqn:kickmap:approxi:multipole}, it's clear
566that the kick map from the main body of dipoles are different in the small ring and big ring;
567while the kick map from the main body of other type of multipoles are the same in small
568rings and big rings.
569
570
571
572
573
574
575
576
577\section{Magnetic field}
578
579A. Dragt ....(Lie methods for acceleator........)
580
581\section{FF of dipole}
582\subsection{kick map}
583E. Forest ...........
584
585\section{FF of quadrupole}
586\subsection{kick map}
587
588
589\section{ Lattice file}
590In the lattice, RF cavity with the correct harmonic number must be defined!!!
591Otherwise Tracy will give the error message:
592\textcolor{red}{Elem\_GetPos: there are no kids in family 0 ()}. This obigatory is for the
593correct calculation of positive/negtive momentum compaction factor.
594To deactive the RF cavity, the cavity voltage can be defined as 0.
595
596
597The followings are the rules to define a lattice file used in Tracy 3. The curvelinear coordinates are
598used. \textbf{The ideal particle or design particle sees the perfect magnetic field in all magnets, and its}
599\textbf{orbit is used as the reference orbit and base of the curvilinear coordinate}. Since the reference orbit
600is a curve inside the dipoles and a straight line in other lattice elements (drifts and the magnets except
601dipoles), so the length of the dipole is the the path length of the reference particle inside the dipole
602which is equal to $\rho*\theta$ where $\rho$ is the bending radius of the dipole and $theta$ is the bending angle
603with unit [rad], and all the other magnet lengths are the straight length of the magnets.
604
605Due to the same reason, the curvature of the curvilinear cooridnates h = 1/$\rho$ is not zero only inside dipole;
606in other magnets and drift h = 0, and the curvilinear coordinates goes to cartesian cooridnates.
607As a result, the independent variable $s$ inside the dipole harmitonian is the arc length, while the staight
608length in other lattice elements.
609
610\subsection{Lattice}
611The $n^{th}$ field component of the lattice element is defined as in Tracy (n = 1, 2, 3, 4 ...):
612\begin{eqnarray*}
613b_n & = & \frac{1}{B \rho} \frac{1}{(n-1)!} \frac{\partial^{n-1} B_y }{\partial x ^{n-1}}|_{x=0,y=0} \\
614a_n & = & \frac{1}{B \rho} \frac{1}{(n-1)!} \frac{\partial^{n-1} B_x }{\partial x ^{n-1}}|_{x=0,y=0} \\
615B \rho & = & \frac{p_0}{e}
616\end{eqnarray*}
617$B \rho$ is the magnetic rigidity, $p_0$ is the design beam momentum, $e$ is the electric charge.
618For example, for sextupole,  n = 3, so $b_3$ and $a_3$ are defined as
619\begin{eqnarray*}
620b_3 & = & \frac{1}{B \rho} \frac{1}{2} \frac{\partial^{2} B_y }{\partial x ^{2}}|_{x=0,y=0} \\
621a_3 & = & \frac{1}{B \rho} \frac{1}{2} \frac{\partial^{2} B_x }{\partial x ^{2}}|_{x=0,y=0} 
622\end{eqnarray*}.
623
624 \notespace{NOTES:} 
625In \textbf{AT} (Accelerator Toolbox) and \textbf{BETA} code, the definition of are the same as in \textbf{Tracy}.
626While In \textbf{MAD8}, \textbf{MADX} and \textbf{ELEGANT}, the order of the field compoent start from 0, that is
627n = 0, 1, 2, 3, ..., and the $n^{th}$ field strength components of the lattice element $b_n$ and $a_n$ are defined as
628\begin{eqnarray*}
629b_n & = & \frac{1}{B \rho} \frac{\partial^{n} B_y }{\partial x ^{n}}|_{x=0,y=0} \\
630a_n & = & \frac{1}{B \rho} \frac{\partial^{n} B_x }{\partial x ^{n}}|_{x=0,y=0} \\
631B \rho & = & \frac{p_0}{e}
632\end{eqnarray*}
633For example, for sextupole,  n = 3, its field component $b_2$ and $a_2$ are defined as
634\begin{eqnarray*}
635b_2 & = & \frac{1}{B \rho} \frac{\partial^{2} B_y }{\partial x ^{2}}|_{x=0,y=0} \\
636a_2 & = & \frac{1}{B \rho} \frac{\partial^{2} B_x }{\partial x ^{2}}|_{x=0,y=0} 
637\end{eqnarray*}.
638
639
640                               
641\subsection{Syntax}
642Every line embraced by “{}” is comment line. For example:
643
644          {*****drift space *****} 
645
646Each sentence is ended by ‘;’ or no punctuation.
647Tracy is not sensitive to capital/small letters in the lattice.
648User can define any lattice element with any valid name (but must start with a character) they want, but the element type is fixed.
649For the lattice of the ring, the definition of RF cavity is mandatory, and the harmonic number of the RF cavity is also mandatory; for the lattice of the linac, the definition of the RF cavity is optional.
650
651\subsection{Variables}
652  User can define the variables in the lattice file. For example:
653\begin{tightcenter}
654                   \textsf{Intmeth = 4};
655\end{tightcenter}
656Then when the code is running,  the variable \textsf{intmeth} in the lattice
657file will be replaced by \textsf{4}.
658
659Tracy accept math operation. For example,
660\latticedef{DL1: }{drift,}{L = 0.1*2 + 0.1-0.01;}
661
662\subsection{Start line}
663  The lattice file must begin with the sentence:
664\begin{tightcenter}
665                \textsf{define} \quad    \textsf{lattice};
666\end{tightcenter}
667This definition is mandatory.
668
669\subsection{Global variables}
670  After define the ring, user needs to define the system parameters of the lattice:
671Energy, the beam energy with unit [GeV].
672 dP, the relative momentum offset of the particle.
673CODeps, the convergence for the algorism to find the closed orbit.
674 For example:
675                Energy = 2.739;
676dP    = 1.0d-10;
677                                                           CODeps= 1.0d-15;
678These definitions are mandatory.
679
680\subsection{DRIFT}
681
682                  \latticedef{Name:}{drift,}{L = $\langle \dots \rangle$;}
683
684\begin{table}[htbp]
685\centering
686\caption{Parameters of dipole in the lattice file.}
687\label{tab:dipole-para}
688%\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.1\linewidth} | p{0.6\linewidth} |}
689\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
690\hline
691\textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description}    \\
692\hline
693\textbf{L}  & [m]     & 0.0 & Length.  \\ 
694\hline
695\end{tabular}
696\end{table}
697The definition of the length of a drift is mandatory.
698
699\vspace{0.05in} 
700\textit{Example:}
701                      \latticedef{SD1a:}{drift,}{L= 0.900000;}
702
703\subsection{DIPOLE}
704
705\latticedef{Element\_name:}{bending,}{L = $\langle \dots \rangle$, T = $\langle \dots \rangle$,
706\textbf{T1} = $\langle \dots \rangle$, \textbf{T2}=$\langle \dots \rangle$,
707\textbf{H1} = $\lbrack \dots \rbrack$, \textbf{H2}= $\lbrack \dots \rbrack$,
708\textbf{gap} = $\lbrack \dots \rbrack$, \textbf{edge\_effect1} = $\lbrack \dots \rbrack$
709\textbf{edge\_effect2} = $\lbrack \dots \rbrack$, \textbf{K} =$\lbrack \dots \rbrack$,
710\textbf{method} = $\langle \dots \rangle$, \textbf{N} = $\langle \dots \rangle$;}
711 
712
713
714 \begin{table}[tbp]
715 \centering
716 \caption{Parameters of dipole in the lattice file.}
717 \label{tab:dipole-para}
718%% \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|l|c|c|p{0.4\linewidth}|}
719\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
720 \hline
721 \textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description}    \\
722 \hline
723 \textbf{L}       & [m] & 0.0             &  Curved path length of
724  the design particle inside the dipole. L = $\rho * \theta$, where $\rho$ is the
725  bending radius of the dipole, and $\theta$ is the bending angle of the dipole.   \\
726  \hline
727 \textbf{T}     &[degree] & 0.0          & Total bending angle                      \\
728 \hline
729 \textbf{T1}    &[degree] & 0.0 & Entrance angle                            \\
730  \hline
731\textbf{T2}    &[degree] & 0.0 & Exit Angle \\
732\hline
733\textbf{K}     &   L $\neq$ 0, m$^{-2}$. \newline  L = 0, m$^{-1}$. & 0.0
734               & L $\neq$ 0, quadrupole field strength; \newline L = 0, integrated field strength. \\
735\hline                                             
736\textbf{Method}  & - & 4 &   1,2,4. Symplectic integration method. The
737            value ``1'' means $1^{\mathrm{st}}$ order, ``2'' means $2^{\mathrm{nd}}$ order,
738           and ``4'' means $4^{\mathrm{th}}$ order.    \\ 
739\hline
740\textbf{Gap}    &[m] & 0.0 &   Distance between two poles of the dipole,
741            the gap size determine the fringe field. If the gap size is 0, then the dipole has
742            no fringe field (\textcolor{red}{??????}).   \\ 
743\hline
744\textbf{edge\_effect1} & - & 0 & 1/0.
745                ``1'' to turn on the edge focusing effect and the fringe field at the entrance of
746                  the dipole. ``0'' to turn off the two effects. \\
747\hline
748 \textbf{edge\_effect2} & - & 0 & 1/0. ``1'' to turn on the edge focusing effect and the
749  fringe field at the exit of the dipole. ``0'' to turn off the two effects. \\
750\hline 
751\textbf{N}      & - & 1 &  number of cut slices. \\
752 \hline
753 \end{tabular}
754 \end{table}
755
756\vspace{0.05in} 
757For example:\\
758\vspace{0.05in}
759\textsf{beta\_gap=37e-3; tracy\_gap=beta\_gap*2*0.724;}
760\latticedef{BEND1 :}{ \textbf{bending},}{ \textbf{L} = 1.05243, \textbf{T} = 11.25, \textbf{T1} = 5.5906,
761\textbf{T2} = 5.67658, \textbf{K} = 0.00204,gap=tracy\_gap,
762\textbf{edge\_effect1} = 1, \textbf{edge\_effect2} = 1, \textbf{N} = 4,
763\textbf{method} = intmeth;}
764
765The parameters of ``bending'' are optional, the default values for the missing parameters are 0,
766 and the default value for ``method'' is also 0.
767
768
769\vspace{0.05in}
770\textbf{Attention:}
771\begin{itemize}
772\item 
773The bending magnet in Tracy is a symplectic element.
774The independent variable $s$ inside the dipole harmitonian is the arc length,
775so the length of the dipole is defined the curved path length of the design
776particle inside the dipole.
777\item 
778One can refer to the definition of $T1$,$T2$, $H1$, $H2$ on page 116 of SLAC-75 for more
779information.
780\item
781In the lattice files of ELEGANT, MADX and BETA, the dipole angles are defined with the unit [rad].
782But in TRACY, the unit is [degree].
783\item
784BETA dipole gap is the Elegant gap; but Tracy dipole gap is different from
785the definition in both BETA and Elegant.
786Tracy definition of dipole with fringe field: \\
787\textsf{
788beta\_gap=0.04;
789{tracy\_gap=beta\_gap*2*1/6;}
790{Due to the Tanh-like fringe field, K1=0.2, and tracy\_gap = beta\_gap *2* FINT (K brown para.)}
791tracy\_gap = beta\_gap*2*0.348;}
792
793
794 \latticedef{DIP:}{bending,}{L=0.27646,T= 45, T1=0, T2=0,gap=tracy\_gap,edge\_effect1=1,edge\_effect2=1,method=intmeth,N=4;} 
795
796Elegant definition of dipole with dipole fringe field: \\
797\textsf{DIP: csbend,N\_KICKS=100,INTEGRATION\_ORDER=4,L=0.27646,angle= 0.785398, E1=0, E2=0,hgap=0.02,Fint=0.348,nonlinear=1,edge1\_effects=2,edge2\_effects=2,edge\_order=2;}
798\end{itemize}
799
800\subsection{QUADRUPOLE}
801\textbf{Definition:} \\
802\latticedef{Element\_Name:}{ quadrupole,}{ L = $\lbrack \dots \rbrack$, tilt = $\lbrack \dots \rbrack$,
803                            K =$\lbrack \dots \rbrack$, FF1 =  $\lbrack \dots \rbrack$,       
804                            FF2= $\lbrack \dots \rbrack$, FFscaling =  $\lbrack \dots \rbrack$,
805                            method = $\lbrack \dots \rbrack$, N= $\langle \dots \rangle$;}
806
807\begin{table}[htbp]
808\centering
809\caption{Parameters of quadrupoles in the lattice file.}
810\label{tab:quad-para}
811\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
812\hline
813\textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description}    \\
814\hline
815         L & [m] &  0.0 & Length of the quadrupole \\
816\hline
817        Tilt & [degree] & 0.0  & tilt angle of the quadrupole.
818                                 If ‘tilt’ is non-zero, then the
819                                 quadrupole is a skew quadruple. \\
820\hline
821       K &  L $\neq$ 0, [m$^{-2}$]. \newline L = 0, [m$^{-1}$]. & 0.0 &  L $\neq$ 0, Gradient
822$\frac{\frac{\partial B_y }{\partial x}}{B \rho}$; \newline  L = 0, integrated field strength
823$\frac{\frac{\partial B_y }{\partial x} L }{B \rho}$. \\
824  \hline                 
825   FF1 & - & 0  & 1 or 0. \newline 
826                   1: to avtive fringe field at the left edge. \textsf{QuadFringeOnFlag}
827   should be set in the Tracy input file. 0: left fringe field off. \\
828\hline
829   FF2 & - & 0  & 1 or 0. \newline 
830                   1: to avtive fringe field at the right edge. \textsf{QuadFringeOnFlag}
831   should be set in the Tracy input file. 0: right fringe field off. \\
832\hline
833FFscaling & - & 1 & Scaling factor of the dipole fringe field. \\
834\hline
835Method & - & 4 & 1,2,4. Order of symplectic integration method. 
836Value ``1'' means 1st order, ``2'' means 2nd order, and ``4'' means 4th order. \\
837\hline
838N & - & 1 & Pieces of the quadrupole to be cut when it is treated in the code. \\
839\hline
840\end{tabular}
841\end{table}
842
843
844
845Example: \\
846
847\textsf{Nq=8/2; dgsurg=1.00; dgsurgL=1.00; quadfringe=1.0; LQC=0.3602;}
848\latticedef{QP1a:}{quadrupole,}{ L=LQC/2, K= -1.073038*dgsurg, FF1=quadfringe, FF2=0,
849              FFscaling =1, method=intmeth, N=Nq;}
850
851The parameters of “quadrupole” are optional, the default value for “method” is 4, the default value for “FFscaling” is 1, the default value for the other parameters are 0.
852
853\subsection{SKEW QUADRUPOLE}
854
855The skew quadrupole is a quadrupole with a 45 [degree] tilt angle. For example:
856\latticedef{QT:}{quadrupole,}{tilt=45.0, K= 0.0, method=intmeth, N=1;}
857
858\notespace{NOTES:} 
859If skew quadrupoles are defined in the lattice file with a name \tracypara{skewquad},
860User must specify the name of  skew quadrupole in the tracy input file using
861the commands:
862\tracycommand{qt}{skewquad} 
863
864\subsection{SEXTUPOLE}
865
866\latticedef{Element\_Name:}{sextupole,}{L = $\lbrack \dots \rbrack$, K = $\lbrack \dots \rbrack$,
867 FF1 = $\lbrack \dots \rbrack$, FF2=$\lbrack \dots \rbrack$,method = $\lbrack \dots \rbrack$,
868 N=$\lbrack \dots \rbrack$;}
869
870
871 \begin{table}[htpb]
872 \centering
873 \caption{Parameters of sextupoles in the lattice file.}
874 \label{tab:sext-para}
875\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
876\hline
877\textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description} \\
878\hline
879\textbf{L}        [m] &   & 0.0 & Length\\
880\hline
881\textbf{K}         &L $\neq$ 0, [m$^{-3}$]. \newline L = 0, [m$^{-2}$]. & 0.0 &
882                   If L $\neq$ 0,
883                   $= \frac{1}{2} \frac{1}{B \rho} \frac{\partial^{2} B_y }{\partial x ^{2}}|_{x=0,y=0}$,   
884                     $B \rho$ is the magnetic rigidity, $p_0$ is the design beam momentum,
885                     $e$ is the electric charge. If L = 0, K is the integrated field
886             strength $L\frac{1}{2} \frac{1}{B \rho} \frac{\partial^{2} B_y }{\partial x ^{2}}|_{x=0,y=0}$ \\   
887\hline
888 \textbf{FF1}      & - & 0 & \textbf{1} or \textbf{0}. \textbf{1}: tringe on the fringe field at the
889                      left edge. \textbf{0}: tringe off the fringe field at the     
890                      left edge.\\
891 \hline
892 \textbf{FF2}      & - & 0 & \textbf{1} or \textbf{0}. \textbf{1}: tringe on the fringe field at the
893                      right edge. \textbf{0}: tringe off the fringe field at the     
894                      right edge.\\
895 \hline
896 \textbf{Method}   & - & 4 & \textbf{1},\textbf{2},\textbf{4}. Order of symplectic integration method.       
897                      \textbf{1}: 1st order; \textbf{2}: 2nd order; \textbf{4} 4th order. \\
898 \hline
899 \textbf{N}       & - & 1 &  Pieces of this element to be cut, used in the symplectic   
900                      integration. \\
901
902 \hline
903 \end{tabular}
904 \end{table}
905
906
907
908\textit{Example:} \\
909\textsf{NqSx=1; coef=1.0/0.16; method4sextu = 4; sextfringe = 0;} 
910\latticedef{SX1:}{sextupole,}{ L=0.16, K =  1.719190*coef, method=method4sextu, N = NqSx,
911                              FF1=sextfringe, FF2=sextfringe;}
912
913The parameters of “sextupole” are optional, the default value for “method” is 4,
914the default value for the other parameters is 0.
915
916
917\notespace{NOTES:} 
918
919In \textbf{AT} (Accelerator Toolbox) and \textbf{BETA} code, the european notation of
920the order of magnetic field is used. That is n = 1, 2, 3, ...n; and the definition of
921K are the same as in \textbf{Tracy}.
922While In \textbf{MAD8}, \textbf{MADX} and \textbf{ELEGANT}, the U.S. notation of the
923order order of the field is used, that is n = 0, 1, 2, 3, ..n. For sextupole,  n = 2,
924and its gradient is defined as
925\begin{equation*}
926K_2  =  \frac{1}{B \rho} \frac{\partial^{2} B_y }{\partial x ^{2}}|_{x=0,y=0} 
927\end{equation*}
928
929\subsection{MULTIPOLE}
930
931\latticedef{Element\_Name:}{Multipole,}{L= $\lbrack \dots \rbrack$, T =$\lbrack \dots \rbrack$,
932               T1=$\lbrack \dots \rbrack$, T2=$\lbrack \dots \rbrack$,
933tilt=$\lbrack \dots \rbrack$, HOM = (i, $\langle$ $b_i$ $\rangle$, $\langle$ $a_i$ $\rangle$,
934j, $\langle$ $b_j$ $\rangle$, $\langle$ $a_j$ $\rangle$,
.$n$, $\langle$ $b_n$ $\rangle$, $\langle$ 
935$a_n$ $\rangle$), $N$ =$\lbrack \dots \rbrack$$\langle$, method =$\lbrack \dots \rbrack$;}
936
937\begin{table}[htpb]
938\centering
939\caption{Parameters of the multipoles.}
940\label{tab:mult-para}
941\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
942\hline
943\textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description} \\
944\hline
945\textbf{L}         & [m] & 0.0 & Length \\
946\hline
947\textbf{T}         & [degree] & 0.0  & Total bending angle \\
948\hline
949\textbf{T1}        & [degree] & 0.0 & Entrance angle \\
950\hline
951\textbf{T2}        & [degree] & 0.0 & Exit Angle \\
952\hline
953\textbf{Tilt}      & [degree] & 0.0 & Rotation angle of the quadrupole; if \tracypara{Tilt}
954                     is non-zero, then the quadrupole is a skew quadruple.???? \\
955\hline
956\textbf{HOM}       & - & (0, 0, 0) & Multipole field components of the element. The format
957                     is \textit{n}, \textit{$b_{n}$}, \textit{$a_n$}, etc. \newline 
958                     \textit{n} is order of the multipole
959                     field in U.S. notation (?????), n=1 (dipole field),
960                     n=2 (quadrupole field), n=3 (sextupole field),
961                     n=4 (octuple field), n=5 (decuple field).
962                     \textit{$b_n$} is $n^{\mathrm{th}}$ component of the upright multipole
963                     field with the unit [$\frac{1}{m^{-n}}$];
964                     \textit{$a_n$} is $n^{\mathrm{th}}$ component
965                      of the skew multipole field with the
966                      unit [$\frac{1}{m^-n}$]. \\
967\hline
968\textbf{N}         & - & 1 & Pieces of this element to be cut \\
969\hline
970\textbf{Method}    & - & 4 & 1,2,4. Symplectic integration method.
971                      1 is $1^{\mathrm{st}}$ order, 2 is $2^{\mathrm{nd}}$ order, 4 is
972                      $4\mathrm{th}$ order. \\
973\hline
974\end{tabular}
975\end{table}
976
977The multipole field components $a_n$ and $b_n$ are defined as
978\begin{eqnarray}   
979b_n & = & \frac{1}{B \rho} \frac{1}{(n-1)!} \frac{\partial^{n-1} B_y }{\partial x ^{n-1}}|_{x=0,y=0} \\
980a_n & = & \frac{1}{B \rho} \frac{1}{(n-1)!} \frac{\partial^{n-1} B_x }{\partial x ^{n-1}}|_{x=0,y=0} \\
981B \rho & = & \frac{p_0}{e}
982\end{eqnarray}
983$B \rho$ is the magnetic rigidity, $p_0$ is the design beam momentum, $e$ is the electric charge.
984
985If the magnetic field $\vec{B^{tip}}$ is measured at the location with the radius $r_0$, then
986$b_n$ and $a_n$ are defined as
987\begin{eqnarray*}
988b_n & = & \frac{1}{B \rho} \frac{B_y^{tip}}{r_0^{n-1}}\\
989a_n & = & \frac{1}{B \rho} \frac{B_x^{tip}}{r_0^{n-1}} \\
990\vec{B^{tip}} & = & B_y^{tip} \hat{y} +  B_x^{tip} \hat{x} 
991\end{eqnarray*}
992
993 The $n^{th}$ order magnetic field is
994 \begin{equation}
995 B_y^n + i * B_x^n = (b_n + i*a_n) * (x + i*y)^n
996 \end{equation}
997 The total magnetic field with $1^{st}$ to $n^{th}$ order field components can be calculated using 
998 \begin{eqnarray}
999\label{eqn:total:field}
1000 B_y + i * B_x & = & (b_n + i*a_n) * (x+i*y)*(x + i*y)^{n-1} + O(n-1) \\
1001             & = & [(b_n*x - a_n*y) + b_{n-1} + i*(a_n*x + b_n*y + a_{n-1})]*(x+i*y)^{n-1} + O(n-2) \\
1002              & ...& 
1003 \end{eqnarray}
1004
1005The eqn.~\ref{eqn:total:field} is used in Tracy3 to calculate the effective fields of the
1006magnet. This equation clearly shows that, all the field errors gives the same effect the
1007beam: horizontal focusing and vertical decusing. But since the field strength of the
1008$n^{th}$ order magnet is proportial to the $n^{th}$ order of $x/y$ and $x/y$ at the
1009entrance of the magnet is small, so the higher $n$ is, the weak of the $n^{th}$ order
1010multipole field is.
1011
1012\vspace{0.05in}
1013\textit{Example 1: }
1014
1015\latticedef{B:}{multipole,}{L=0.70, T=10.0, T1=5.0, T2=5.0, HOM = (1, -1.0, 0), N=8, Method=2;}
1016
1017In this example, the multipole is a dipole with field component  $b_1$ = -1.0, or the
1018field strength is $B_{y0}$, and the field direction is down. This field gives a horizontal
1019focusing to the electron.
1020
1021\vspace{0.05in}
1022\textit{Example 2:} 
1023
1024 \latticedef{QF:}{multipole,}{L=0.70, HOM = (1, 2.50, 0.0, 4, 1.01e7, 0.0), N=8, Method=4;}
1025
1026In this example, the multipole is a dipole with $4^{th}$ order upright multipole filed errors (octupole),
1027and $b_4$ = 1.01e7. 
1028
1029To add multipole errors in the defined lattice files, user can also define the multipoles
1030inside an external file (Section~\ref{sec:mult:field:error}) (???? To be checked, can this
1031routine mesured with the general one???).
1032
1033 \notespace{NOTES:} \\
1034In \textbf{AT} (Accelerator Toolbox) and \textbf{BETA} code, the definition of are the same
1035as in \textbf{Tracy}. While In \textbf{MAD8}, \textbf{MADX} and \textbf{ELEGANT}, the order
1036of the field compoent start from 0, that is n = 0, 1, 2, 3, ..., and the $n^{th}$ field
1037strength components of the lattice element $b_n$ and $a_n$ are defined as
1038\begin{eqnarray*}
1039b_n & = & \frac{1}{B \rho} \frac{\partial^{n} B_y }{\partial x ^{n}}|_{x=0,y=0} \\
1040a_n & = & \frac{1}{B \rho} \frac{\partial^{n} B_x }{\partial x ^{n}}|_{x=0,y=0} \\
1041B \rho & = & \frac{p_0}{e}
1042\end{eqnarray*}
1043
1044\subsection{ wiggler (To be updated.)}
1045
1046\latticedef{Element\_Name:}{Wiggler,}{L  = $\langle$ length $\rangle$,BoBrhoV = $\langle$ B/Brho $\rangle$,
1047BoBrhoH = $\langle$ B/Brho $\rangle$, Lambda  = $\langle$ period $\rangle$,kxV= $\langle$ [m] $\rangle$,kxH     = $\langle$ [m] $\rangle$,phi     = $\langle$ phase $\rangle$,
1048               harm(n, kxV, BoBrhoV, kxH, BoBrhoH, phi), N = $\langle$ no of integration steps $\rangle$,
1049               Method  = $\langle$ method $\rangle$;}
1050
1051
1052\begin{table}[htbp]
1053\centering
1054\caption{The parameters of wigglers in a lattice file.}
1055\label{tab:wiggler-para}
1056\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
1057\hline
1058\textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description} \\
1059\textbf{L} & [m] & 0.0 & Length \\ \hline
1060\textbf{BoBrhoV} & ??? & ??? & the normalized vertical field \\ \hline
1061\textbf{BoBrhoH} & ??? & ??? &  the normalized horizontal field \\ \hline
1062\textbf{Labmda} & [m] & ??? & period length  \\ \hline
1063\textbf{kxV} & [m] & ??? & ??? \\ \hline
1064\textbf{kxH} & [m] & ??? & ??? \\ \hline
1065\textbf{phi} & [degree] & ??? & ??? \\ \hline
1066\textbf{harm} & ??? & ??? & ??? \\ \hline
1067\textbf{N} & - & - & No of integration steps \\ \hline
1068\textbf{Method} & - & - &  Symplectic integration method.
10691 is 1st order, 2 is 2nd order, 4 is 4th order.\\
1070\hline
1071\end{tabular}
1072\end{table}
1073
1074\vspace{0.05in}
1075\textit{ Example 1:}
1076\latticedef{U143:}{wiggler,}{L=4.80, K=0.5, Lambda=0.15, N=20, Method=0;}
1077
1078\vspace{0.05in}   
1079\textit{Example 2:}
1080\latticedef{EPU:}{wiggler,}{L=4.80, Lambda=0.15, N=20, Method=0,
1081                                 harm=(3, kxV\_3, BoBrhoV\_3, kxH\_3, BoBrhoH\_3, phi\_3);}
1082
1083\subsection{FIELD MAP (To be updated

..)}
1084
1085\latticedef{Element\_Name:}{Fieldmap,}{L = $\langle$ length [m] $\rangle$, N = $\langle$ 
1086            no of integration steps $\rangle$, file1 = $\langle$ file name (lower case) $\rangle$};
1087
1088\begin{table}[htbp]
1089\centering
1090\caption{Parameters of field map in the lattice file.}
1091\label{tab:fieldmap-para}
1092\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
1093\hline
1094\textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description} \\
1095\hline
1096\textbf{L} & [m] & 0.0 & Length \\ \hline
1097\textbf{L} & [m] & 0.0 & Length of the field map \\ 
1098\hline
1099\textbf{N} & - & ??? & the number of integration steps \\
1100\hline
1101\textbf{file1} & - & ??? & field map file \\
1102\hline
1103\end{tabular}
1104\end{table}
1105
1106\vspace{0.05in}
1107\textit{Example:}
1108\latticedef{FM:}{Fieldmap,}{L = 1.0, N = 20, file1 = "U19\_Bxyz.dat";}
1109
1110
1111\subsection{INSERTION DEVICE}
1112
1113\latticedef{Element\_Name:}{insertion,}{scaling1 = 1/0, scaling2=1/0,method = interpolation\_method,
1114         N=Number of slice, file1 = name of the file with 1st order radia map, 
1115         file2 = name of the file with 2nd order radia map;}
1116
1117\begin{table}[htbp]
1118\centering
1119\caption{Parameters of the insertion devices.}
1120\label{tab:insertiondevice-para}
1121\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
1122\hline
1123\textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description} \\
1124\textbf{scaling1} & - & ??? &  scaling factor for the 1st order field map \\
1125\hline
1126\textbf{scaling2} & - & ??? &  scaling factor for the 2rd order field map \\
1127\hline
1128\textbf{method} & - & ??? & 1, 3. The order of symplectic interpolation method. 1 is linear
1129  interpolation, 3 is spline interpolation.\\
1130\hline
1131\textbf{N} & - & ??? & pieces of this element is cut when it is treated in the code \\
1132\hline
1133\textbf{file1} & - & ??? & The 1st order of insertion device field are read from the
1134files generated by RADIA. If user does not specify the file name with the file path,
1135then the code will look for the files in the current working directory. The path of
1136the Radia map file must be in small letters, otherwise the code can’t find the file. \\
1137\hline
1138\textbf{file2} & - & ??? & 
1139The 2nd order of insertion device field are read from the files generated by RADIA.
1140If user does not specify the file name with the file path, then the code will look
1141for the files in the current working directory. The path of the Radia map file must
1142be in small letters, otherwise the code can’t find the file. \\
1143\hline
1144\end{tabular}
1145\end{table}
1146
1147\vspace{0.05in}
1148\textit{Example:}
1149 \latticedef{WIGSLIC:}{insertion,}{N = 10, scaling1=1.0, scaling2=1.0, method=2, file1="/home/sources/physmach/tracy2.7/w150g11pole60\_oppose\_radia\_pour\_tracy.txt", file2= "/home/sources/physmach/brunelle/tracy-2.7/w150g11pole20\_fin.dat";}
1150     
1151 All the parameters for ‘insertion’ is optional, the default value for scaling1 and scaling2 are 1,
1152the default ‘method’ is 3 which means spline interpolation, the default ‘N’ is 1, the default
1153values for all the other parameters are 0.
1154
1155\subsection{RF CAVITY}
1156
1157\latticedef{Element\_Name}{cavity,}{Frequency = RF frequency, Voltage = RF voltage, Phase = synchrotron 
1158                           Phase, harnum = harmonic number of the RF cavity;}
1159
1160
1161\begin{table}[htbp]
1162\centering
1163\caption{Parameters of RF cacity.}
1164\label{tab:RFCavity-para}
1165\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
1166\hline
1167\textbf{Parameter Name}    &  \textbf{Units}      &\textbf{Default}   & \textbf{Description} \\
1168\hline
1169\textbf{frequency} & [Hz] & ??? &  RF frequency  \\
1170\hline
1171\textbf{voltage} & [Volt] & ??? &  RF voltage  \\
1172\hline
1173\textbf{phase} & [degree] & ??? & synchrotron phase \\
1174\hline
1175\textbf{harnum} & - & ??? & harmonic number \\
1176\hline
1177\end{tabular}
1178\end{table}
1179
1180
1181\vspace{0.05in}
1182\textit{Example:}
1183\latticedef{CAV:}{Cavity,}{Frequency = 499.95e6, Voltage=1.22e6, phase = 30, harnum=328;}
1184
1185The harmonic number of the RF cavity is mandatory, and the other parameters of “cavity” are
1186optional, the default values are 0.
1187
1188\subsection{CORRECTOR}
1189
1190\latticedef{Element\_Name:}{corrector,}{horizontal/vertical, method = integrated method;}
1191
1192\begin{table}[htbp]
1193\centering
1194\caption{Parameters of correctors.}
1195\label{tab:corrector-para}
1196\begin{tabular}{| p{0.2\linewidth} | p{0.2\linewidth} | p{0.1\linewidth} | p{0.4\linewidth} |}
1197\hline
1198\textbf{Horizontal / vertical} & - & ??? & â€œhorizontal”: horizontal corrector; “vertical”: vertical
1199 corrector \\
1200\hline
1201\textbf{method} & - & ??? & 1, 2, 4. Order of symplectic integration method.
1202Value ‘1’ means 1st order, ‘2’ means 2nd order, and ‘4’ means 4th order \\
1203\hline
1204\end{tabular}
1205\end{table}
1206
1207
1208\vspace{0.05in}
1209\textit{Example 1:} 
1210\latticedef{CH:}{corrector,}{horizontal, method=intmeth;}
1211It defines a horizontal corrector.
1212
1213\vspace{0.05in}
1214\textit{Example 2:} 
1215\latticedef{CV:}{corrector,}{vertical, method=intmeth;}
1216It defines a vertical corrector.
1217
1218The parameters of “corrector” are optional, the default value for ‘method’ is 0.
1219
1220\notespace{NOTES:} 
1221For a lattice with correctors, user must specify the name of  corrector in the Tracy
1222input file with the commands:
1223           \tracycommand{h\_corr}{HCM}
1224                         or
1225           \tracycommand{v\_corr}{VCM}
1226Here \tracypara{HCM} is the name of the corrector defined in the lattice for horizontal
1227orbit correction (????); \tracypara{VCM} is the name of the corrector defined in the
1228lattice for vertical orbit correction.
1229
1230
1231\subsection{MARKER}
1232
1233\latticedef{Element\_Name:}{marker;}{}
1234
1235\subsection{BEAM POSITION MONITOR (To be updated)}
1236 BPM is a special marker in the lattice; the “symbol” name must be “BPM” (???). User can
1237define the BPM as:????
1238\latticedef{BPM:}{type;}{}
1239
1240Normally Its type is defined as “Marker” type, but in order to include the misalignment
1241error of BPM into the lattice, it must be defined as “Beam Position Monitor” type
1242which is in fact multipole type, since only the element with multipole type is saved
1243with displacement error, field error, etc.
1244
1245\notespace{NOTES:}
1246For lattice with BPMs, user must specify the name of  BPM in the Tracy input file
1247 with the command:
1248                    \latticedef{bpm}{beaPosMonitor}
1249Here “beaPosMonitor” is the name of the BPMs defined in the lattice.
1250
1251\subsection{GIRDER}
1252  Girder is a special element, it’s the girder used in the real machine to support the magnetic elements and other elements. It is defined as:
1253                   Symbol: type;
1254
1255  Normally Its type is defined as “Marker” type, but in order to include the misalignment error of girder into the lattice, it must be defined as “multipole” type, since only the element with multipole type is saved with displacement error, field error, etc.
1256  For convenience, it’s better to define the beginning of the girder and also the end of the girder, and the elements between the beginning and end of the girders are the elements who are put on the girder in the real machine.
1257
1258Notice:
1259For lattice with girders,
1260 User must specify the name of  girder in the input file “*.prm” with the commands:
1261                                   gs       Girder\_Start
1262                                   ge       Girder\_End
1263
1264Here ‘Girder\_Start’ is the name of the start of girder defined in the lattice; ‘Girder\_End’ is the name of the end of girder defined in the lattice.
1265
1266\subsection{SOLENOID...TO BE UPDATED...}
1267
1268
1269\subsection{ELEMENT BLOCK}
1270  To construct the element block, use the following format:
1271           Symbol: elem1, elem2,
., block1,block2;
1272Here “Symbol” is the name of the element block, and “elem1”, “elem2”, “block1”, “block2” are the element or sub element blocks in this element block.
1273  If there are N the same element/block subsequently, user can use ‘N*element/block’ to simply the definition. For example:
1274                        SINJ: SD1a, ssep, 3*SEP,esep,SD1c,eHU600,SD1d;
1275In this example element block, there are 9 elements/blocks, and 3 elements/blocks “SEP” subsequently.
1276
1277\subsection{LINE}
1278 User can define the cell structure using the command:
1279
1280             CELL : $\langle$ block name $\rangle$, SYMMETRY=$\langle$ symmetry $\rangle$;
1281
1282$\langle$ block name $\rangle$ is the name of a block; $\langle$ symmetry $\rangle$ is the number of super symmetry or the number of the block in the ring.
1283
1284Example:
1285
1286         CELL: BL1, Symmetry=12;
1287
1288This example defines the cell with block “BL1”, and the number of super symmetry is 12. The output of the Tracy3 with symmetry large than 1 will give the
1289tunes and chromaticities in one symmetric period.
1290
1291\subsection{RING}
1292To define the ring, use the command:
1293               RING: elem, block
.
1294It’s similar to define an element block, but must with the fixed symbol name “RING”. For example:
1295RING: DEBUT,SUP1,SUP2,SUP3,SUP4,CAV,FIN;
12965.1.23  End line
1297 To end the lattice file, user needs to use the following command at the end of the lattice file:
1298End;
1299This command is mandatory.
1300
1301
1302\section{Commands}
1303  The following commands turn on the boolean flags in the code to set the machine parameters and carry on different calculations. All these commands are optional; user can choose whichever they need. If user wants to use the flag, they can write the flag in the script, if they do not want to use it, they can delete or comment out (add “\#” at the beginning of command line) the flag. The Boolean flags in the user input script have the following features:
1304If the flags are not active, then the default values for all the boolean commands are false.
1305The code will execute the command according to the sequence defined in the input script “*.prm”. For example,
1306FitTune4Flag     qp7a qp7b  qp9a qp9b  18.18 10.28
1307                          ReadMultipoleFlag
1308                       FitTune4Flag     qp7a qp7b  qp9a qp9b  18.202 10.317
1309The code will fit tunes to the target tunes (18.18  10.28), and then read multipole field errors into the lattice, then fit the tunes to a new set of values (18.202 10.317).
1310User can define the same Boolean commands as often as they want in the same input script; but user can only define maximum 500 commands in one input script. 
1311The user defined script can be used both for the non-parallel and parallel version Tracy; the output files are the same for both versions.
1312
1313\subsection{QuadFringeOnFlag }
1314To activate quadrupole fringe field, use the command:\\
1315QuadFringeOnFlag\\
1316in the “*.prm” script. With this command, user can define the fringe field at the entrance or exit of the quadrupole together with the command FF1 = 1 or FF2 = 1 of the quadrupoles which are defined in the lattice file; if FF1 or FF2 not equals to 1, then there is no fringe field at the entrance or exit of the quadrupoles even if QuadFringeOnFlag is active in the “*.prm” file.
1317 This flag is a global flag, if user set this flag in the input script, it will always have effects until this flag is reset.
1318
1319\subsection{QuadFringeOffFlag }
1320To deactivate quadrupole fringe field, use the command:
1321QuadFringeOffFlag
1322With this command, user can deactivate the fringe field at the entrance and exit of the quadrupole, even if FF1 = 1 or FF2 = 1 for the quadrupole in the lattice file.
1323  This flag is a global flag, if user set this flag in the input script, it will always have effects until this flag is reset.
1324
1325\subsection{RFvoltageFlag}
1326  User can reset the RF voltage by setting “RFvoltageFlag” to replace the value of RF voltage which is defined in the lattice. For example:
1327RFvoltageFlag    3000000
1328Here “RFvoltageFlag” is the name of the keyword command, ‘3000000’ is the value of RF voltage with the unit [volt].
1329  If the ring has more than one RF cavities, the related parameters are defined as the total values for one RF cavity.
1330
1331\subsection{PrintTrackFlag}
1332To print the coordinates tracked around COD at each element to a file, use the command:
1333PrintTrackFlag           track\_file        x    px   y  py  delta    ctau     nturn
1334
1335For example:
1336PrintTrackFlag           track.out         0.001     0.0    0.0    0.0    0.0    0.0     50
1337
1338The parameters and the default values of “PrintTrackFlag” are shown in Table .
1339
1340\begin{table}[h]
1341\centering
1342\caption{}
1343\label{}
1344\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1345\hline
1346\hline
1347\end{tabular*}
1348\end{table}
1349
1350Table   Parameters of command "PrintTrackFlag".
1351Name
1352Description
1353Default value
1354Unit
1355track\_file
1356File to save the tracked coordinates around each lattice element
1357track.out
1358-
1359x
1360Start tracking horizontal coordinate
13610.001
1362[m]
1363px
1364Start tracking horizontal canonical momentum px normalized by reference momentum p0, that is: px = px/p0.  Normally px is approximate as horizontal deviation with unit [rad].
13650.0
1366
1367-
1368y
1369Start tracking vertical coordinate
13700.0
1371[m]
1372py
1373Start tracking vertical canonical momentum py normalized by reference momentum p0, that is: py = py/p0. Normally px is approximate as vertical deviation with unit [rad].
13740.0
1375
1376-
1377delta
1378Start tracking relative energy offset
13790.0
1380-
1381ctau
1382Start tracking longitudinal coordinate
13830.0
1384[m]
1385nturn
1386Number of turn for tracking
138750
1388-
1389
1390\subsection{PrintTrackElemFlag}
1391To print the coordinates tracked (NOT around COD) at a certain element to a file, use the command:
1392PrintTrackFlag           track\_file        x    px   y  py  delta    ctau     nelem1 nelem2
1393
1394For example:
1395PrintTrackFlag           track.out         0.001     0.0    0.0    0.0    0.0    0.0     50 1 2
1396
1397The parameters and the default values of “PrintTrackElemFlag” are shown in Table .
1398
1399\begin{table}[h]
1400\centering
1401\caption{}
1402\label{}
1403\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1404\hline
1405\hline
1406\end{tabular*}
1407\end{table}
1408
1409Table   Parameters of command "PrintTrackElemFlag".
1410Name
1411Description
1412Default value
1413Unit
1414track\_file
1415File to save the tracked coordinates around each lattice element
1416track.out
1417-
1418x
1419Start tracking horizontal coordinate
14200.001
1421[m]
1422px
1423Start tracking horizontal canonical momentum px normalized by reference momentum p0, that is: px = px/p0.  Normally px is approximate as horizontal deviation with unit [rad].
14240.0
1425
1426-
1427y
1428Start tracking vertical coordinate
14290.0
1430[m]
1431py
1432Start tracking vertical canonical momentum py normalized by reference momentum p0, that is: py = py/p0. Normally px is approximate as vertical deviation with unit [rad].
14330.0
1434
1435-
1436delta
1437Start tracking relative energy offset
14380.0
1439-
1440ctau
1441Start tracking longitudinal coordinate
14420.0
1443[m]
1444nelem1
1445index of start lattice element for tracking
1446
1447nelem2
1448index of end lattice element for tracking
1449
1450\subsection{PrintTwissFlag}
1451
1452Print Twiss parameters to a user defined file \\
1453
1454With the command “PrintTwissFlag”, Tracy 3 will print the Twiss parameters to a user defined file. The format is:
1455                            PrintTwissFlag                user\_defined\_file
1456
1457If user use the command PrintTwissFlag but without define the file name, then the code will print the Twiss parameters to a default file “twiss.out”.
1458
1459\subsection{PrintCODFlag}
1460Print COD (Close Orbit Distortion) to a user defined file\\
1461
1462With the command “PrintCODFlag”, the code will print the close orbit distortion to a user defined file. The format is:
1463                            PrintCODFlag                user\_defined\_file
1464If user use the command PrintCODFlag but without defining the file name, then the closed orbit will be printed to the default file “printcod.out”.
1465In Tracy 3, close orbit file “cod.out” is automatically generated after reading the lattice.
1466   In the outuput file of the command PrintCODFlag, the data is saved in the following format:
1467  \# i    name  s  code  betax   nux   betay   nuy  xcod   ycod      dSx     dSy      dipx   dipy
1468  \#               [m]          [m]              [m]            [mm]   [mm]    [mm]   [mm] [mrad]  [mrad]
1469 \#
1470Where “\#” denotes the command line, the meanings of the above parameters are shown in Table .
1471
1472\begin{table}[h]
1473\centering
1474\caption{}
1475\label{}
1476\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1477\hline
1478\hline
1479\end{tabular*}
1480\end{table}
1481
1482Table   Parameters in the output file of close orbit.
1483Name
1484Description
1485Unit
1486i
1487  Number of the element
1488-
1489name
1490  Element name defined in lattice
1491-
1492s
1493  Longitudinal length
1494[m]
1495code
1496Symbol for the element:
1497 0.5   dipole
1498-1.0   defocusing quadrupole
1499 1.0   focusing quadrupole
1500-1.5   defocusing sextupole
1501 1.5   focusing sextupole
1502 0      other element
1503
1504
1505
1506-
1507betax
1508Horizontal beta function
1509[m]
1510nux
1511Horizontal tune
1512-
1513betay
1514Vertical beta function
1515[m]
1516nuy
1517Vertical tune
1518-
1519xcod
1520Horizontal closed orbit distortion
1521[mm]
1522ycod
1523Vertical closed orbit distortion
1524[mm]
1525dSx
1526Horizontal displacement of the element
1527[mm]
1528dSy
1529vertical displacement of the element
1530[mm[
1531dipx
1532Horizontal dipole strength of the element
1533[mrad]
1534dipy
1535vertical dipole strength of the element
1536[mrad]
1537
1538\subsection{ReadChamberFlag}
1539Read vacuum chamber setting from an external file \\
1540
1541  To read the vacuum chamber from the user defined chamber file, use the command:
1542ReadChamberFlag        Chamber\_example.dat
1543  In the file ‘Chamber\_example.dat’, user can specify the vacuum limit at the different region of the lattice; the format of the chamber file is given in section .
1544
1545\subsection{ReadfefileFlag}
1546Read lattice element multipole field errors from an external file \\
1547
1548  To read the multipole field errors of the lattice elements from the user defined file, use the command:
1549ReadfefileFlag             dip.fe
1550Tracy will read the systematic and random multipole field errors of the lattice elements defined in the file “dip.fe”, and then replace the corresponding field components of the elements with the new field errors. The formats to specify the systematic and random multipole field errors in a file are given in section Error: Reference source not found.
1551
1552\subsection{ReadaefileFlag}
1553Read lattice element misalignment errors from a file \\
1554
1555  To read the misalignment error of the lattice elements from the user defined file, use the command:
1556ReadaefileFlag             dip.ae
1557Tracy will read the systematic and random misalignment errors of the lattice elements from the file “dip.fe”, and replace the misalignment errors of the corresponding components of the elements. The formats to define the systematic and random misalignment errors of the lattice elements in a file are given in section .
1558
1559\subsection{CODCorrectFlag}
1560Closed orbit (COD) correction \\
1561
1562   The orbit distortion is corrected using SVD (Singular Value Decomposition) method in Tracy 3. In order to do orbit correction, user needs to call the command
1563CODCorrectFlag
1564and then specify the following parameters in the user defined “*.prm” file.
1565Specify the element names of horizontal, vertical correctors, and beam position monitors used in the orbit correction as the following examples:
1566h\_corr       HC
1567v\_corr      VC
1568BPM        bpm
1569User also need to specify the states of the correctors to trigger on/off the correction using the following parameters:
1570hcorr\_file        hcorr\_56nom.state
1571vcorr\_file        vcorr\_56nom.state
1572  In the file “hcorr\_56nom.state”, a list of numbers (1 or 0) are given to the horizontal correctors, according to the sequence in the lattice; “1” means the corresponding corrector is used for horizontal orbit correction, “0” means this corrector is not used in the horizontal orbit correction. The definition rules of vertical corrector states in “vcorr\_56nom.state” are the same as “vcorr\_56nom.state”. 
1573 
1574This parameter defines number of iterations to correct the orbit distortion, this value should be an integer number not smaller than 1.
1575n\_orbit       3
1576This parameter defines number of singular values in H-plane, must be not larger than the number of correctors used for orbit correction
1577nwh           60
1578This defines number of singular values in V-plane, must be not larger  than the number of correctors used for orbit correction
1579nwv           60
1580
1581  In Tracy 3, during the closed orbit correction:
15821) Beam response matrices between beam position monitors and horizontal/vertical correctors are calculated and written to the files “svdh.out”/ “svdv.out”, respectively. The maximum number of horizontal/vertical correctors used for orbit correction is 250.
15832) The code corrects the closed orbit distortion.
15843) Horizontal and vertical orbits at the locations of all beam position monitors during the correction are saved to the files “horbit.out” and “vorbit.out”, respectively.
15854) A file “OrScanFile.out” will be saved with the summaries of the mean and RMS values of the orbits before and after correction.
15865) Finally, Twiss parameters, closed orbit distortion at the lattice elements are saved to a summary file “summary\_miserr\_codcorr.out”, the format of this file is explained in Table .
1587
1588\subsection{TuneTracFlag}
1589
1590Get tunes by tracking \\
1591
1592  To get tunes by tracking, use command:
1593TuneTracFlag
1594  The tunes obtained by tracking are printed on the screen.
1595
1596\subsection{ChromTracFlag}
1597Get chromaticities by tracking \\
1598
1599  To get chromaticity by tracking, use command:
1600ChromTracFlag
1601  The chromaticities obtained by tracking are printed on the screen.
1602
1603\subsection{AmplitudeTuneShiftFlag}
1604
1605Tune shift with amplitude \\
1606
1607
1608  To calculate tune shift with amplitude, one needs to use the following command:
1609AmplitudeTuneShiftFlag nudx\_file nudz\_file nxpoint  nypoint nturn  xmax  ymax  delta
1610For example:
1611AmplitudeTuneShiftFlag   nudx.out  nudz.out 50  30  516  0.035  0.02  0.0
1612
1613The meanings of parameters and default values of command “AmplitudeTuneShiftFlag” are shown in Table . If user uses the command AmplitudeTuneShiftFlag without parameters, then the code will use all the default values.
1614
1615\begin{table}[h]
1616\centering
1617\caption{}
1618\label{}
1619\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1620\hline
1621\hline
1622\end{tabular*}
1623\end{table}
1624
1625Table     Parameters of the command to calculate tune shift with amplitude
1626Parameters
1627Meaning
1628Default values
1629nudx\_file
1630File to save the calculated tune shift with horizontal  amplitude
1631nudx.out
1632nudz\_file
1633File to save the calculated tune shift with vertical amplitude
1634nudz.out
1635nxpoint
1636Number of points in horizontal direction
163731
1638nypoint
1639Number of points in vertical direction
164021
1641nturn
1642Number of turns to track tune
1643516
1644xmax
1645Maximum amplitude of x with the unit [m]
16460.025
1647ymax
1648Maximum amplitude of y with the unit [m]
16490.005
1650delta
1651Energy offset of the particle
16520.0
1653     
1654\subsection{EnergyTuneShiftFlag}
1655Tune shift with energy \\
1656
1657
1658To calculate tune shift with energy, one needs to use the command:
1659EnergyTuneShiftFlag  nudp\_file  npoint  nturn  deltamax
1660For example:
1661EnergyTuneShiftFlag   nudptest.out    31    1026    0.06
1662The meaning of parameters and default values of this command are shown in Table .
1663If user uses command EnergyTuneShiftFlag without parameters, then the code will use all the default values.
1664
1665\begin{table}[h]
1666\centering
1667\caption{}
1668\label{}
1669\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1670\hline
1671\hline
1672\end{tabular*}
1673\end{table}
1674
1675Table   Parameters of the command to calculate tune shift with energy
1676parameter
1677meaning
1678default value
1679nudp\_file
1680File to save the calculated tune shift with energy
1681nudp.out
1682npoint
1683Number of points
168431
1685nturn
1686Number of turns  for tracking
1687516
1688deltamax
1689Maximum energy offset of the particle
16900.06
1691   
1692\subsection{FmapFlag}
1693Frequency map analysis for on momentum particle.
1694Track the coordinates (x, px, y, py, delta, ctau) of the particle,
1695the coordinates (x, px, y, py) are tracked around the closed orbit;
1696while (delta, ctau) is tracked around the zero orbit.
1697
1698The grid of the particle is x= 1e-6 + xcod ~ xmax + xcod, with the
1699step size xmax/nturn,
1700z= 1e-6 + zcod ~ zmax + zcod, with the
1701step size ymax/nturn; px = 0 + pxcod; pz = 0 + pzcod;
1702ctau = 0; delta = set value.
1703
1704To do frequency map analysis for the on momentum particle, use the command:
1705FmapFlag   fmap\_file    nxpoint   nypoint    nturn  xmax   ymax   delta   diffusion \\
1706or
1707FmapFlag   fmap\_file    nxpoint   nypoint    nturn  xmax   ymax   delta   diffusion printloss \\
1708
1709 For example:
1710FmapFlag   fmap.out   31   21   516   0.025   0.005   0.0   true 
1711or
1712FmapFlag   fmap.out   31   21   516   0.025   0.005   0.0   true  true
1713
1714
1715The meaning of parameters and default values of this command are shown in Table . If user uses command FmapFlag without parameters, then the code will use all the default values.
1716
1717\begin{table}[h]
1718\centering
1719\caption{}
1720\label{}
1721\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1722\hline
1723\hline
1724\end{tabular*}
1725\end{table}
1726
1727Table   Parameters of the command to do frequency map analysis for on momentum particle.
1728Parameters
1729meaning
1730Default values
1731fmap\_file
1732File to save the calculated frequency map analysis
1733fmap.out
1734nxpoint
1735Number of points in the horizontal direction
173631
1737nypoint
1738Number of points in the vertical direction
173921
1740nturn
1741Number of turns for tracking; if ``diffusion'' is
1742true, then the tunes will calculated in the first Nturn
1743and then the second Nturn, and the tune difference
1744between these two tunes is the tune diffusion.
1745516
1746xmax
1747Maximum amplitude in the horizontal direction with the unit [m]
17480.025
1749ymax
1750Maximum amplitude in the vertical direction with the unit [m]
17510.005
1752delta
1753Energy offset of the particle
17540.0
1755diffusion
1756Boolean flag, true/false; to compute tune diffusion at the first N turns and second N turns.
1757true
1758
1759printloss (optional)
1760Boolean flag, true/flase; print out the last information of the tracked particleto and external file? If true, the output file is ``fmap\_file.loss''.
1761\subsection{FmapdpFlag}
1762Frequency map analysis for off momentum particle \\
1763
1764To do frequency map analysis for the off momentum particle, use the command:
1765FmapdpFlag   fmapdp\_file    nxpoint    nepoint    nturn    xmax  emax  y  diffusion
1766or
1767FmapdpFlag   fmapdp\_file    nxpoint    nepoint    nturn    xmax  emax  y  diffusion printloss
1768
1769The meaning of parameters and default values are shown in Table .  If user only uses the command FmapdpFlag but without defining all the parameters, then the code uses the default values.
1770
1771\begin{table}[h]
1772\centering
1773\caption{}
1774\label{}
1775\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1776\hline
1777\hline
1778\end{tabular*}
1779\end{table}
1780
1781Table  Parameters of the command “FmapdpFlag”.
1782parameters
1783meaning
1784default value
1785fmapdp\_file
1786File to save the calculated frequency map analysis
1787fmapdp.out
1788nxpoint
1789Number of points in the horizontal direction
179031
1791nepoint
1792Number of points for the energy
179321
1794nturn
1795Number of turns for tracking
1796516
1797xmax
1798Maximum amplitude in the horizontal direction with the unit [m]
17990.025
1800emax
1801Maximum energy offset of the particle
18020.005
1803y
1804Amplitude in the vertical direction with the unit [m]
18050.0
1806diffusion
1807Boolean flag to compute tune diffusion
1808true
1809
1810printloss (optional)
1811Boolean flag, true/flase; print out the last information of the tracked particleto and external file? If true, the output file is ``fmapdp\_file.loss''.
1812
1813
1814\subsection{ErrorCouplingFlag}
1815Add coupling by the random rotation of the full quadrupoles \\
1816
1817  To simulate coupling in the lattice, use can add the random rotation error to all the full quadrupole, using the command as the following example:
1818ErrorCouplingFlag         0    0.0007
1819In this example, “0” is the random seed number; “0.0007” is the RMS value of the rotation angles of all the quadrupoles with the unit [rad].
1820  After setting the rotation error in the lattice, the code will generate a file with the file name “flat\_file\_errcoupling\_full.dat” at the current working directory, user can check the error setting of quadrupoles in this file; then the coupling will be calculated and Twiss parameters after adding the random rotation errors will be saved to the file “linlat\_errcoupling.out”.
1821
1822\subsection{ErrorCoupling2Flag}
1823Add coupling by random rotation of the half quadrupoles \\
1824
1825  In order to get the beam parameters in the middle of the quadrupoles, each quadrupole in the lattice can be cut into two parts. In such case, the coupling of the lattice can be generated by random rotation of all the half quadrupoles in the lattice, using the command as the following example:
1826ErrorCoupling2Flag         0    0.0007
1827In this example, “0” is the random seed number; “0.0007” is the RMS value of the rotation angle of the quadrupole with the unit [rad].
1828  After setting the errors in the lattice, the code will generate a file at the current working directory with the file name “flat\_file\_errcoupling\_half.dat”, user can check the error setting of quadrupoles in this file. After adding the random rotation errors, the coupling will be calculated and Twiss parameters will be saved to the file “linlat\_errcoupling2.out”.
1829  This command is dedicated for Soleil lattice in which each quadrupole is cut into two half quadrupoles.
1830
1831\subsection{CouplingFlag}
1832Calculate coupling and emittance \\
1833
1834  To calculate coupling and emittance, use command:
1835CouplingFlag
1836  After calculation, the coupling and the emittance will be printed on the screen, and the Twiss parameters will be automatically saved to the file “linlat\_coupling.out”.
1837
1838\subsection{MomentumAccFlag}
1839Calculate momentum acceptance by tracking \\
1840
1841The following command calculate momentum acceptance at a predefined lattice region by tracking:
1842MomentumAccFlag   MomAccFile   TrackDim     istart    istop     deltaminp
1843Deltamaxp     nstepp    deltaminn    deltamaxn   nstepn   turns  zinitial
1844For example:
1845MomentumAccFlag   momacc.out      4D     1   209     0.01     0.05    100       -0.01       
1846-0.05   100   1026   0.0001
1847The meaning of parameters and default values are shown in Table . If user uses MomentumAccFlag without parameters, then the code will use the default values.
1848
1849\begin{table}[h]
1850\centering
1851\caption{}
1852\label{}
1853\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1854\hline
1855\hline
1856\end{tabular*}
1857\end{table}
1858
1859Table   Parameters of the command to calculate momentum acceptance
1860parameter
1861meaning
1862Default value
1863MomAccFile
1864File to save the tracked momentum acceptance at each element; saved in the current directory.
1865momentumacceptance.out
1866TrackDim
18674D/6D  tracking to get the momentum acceptance
18686D
1869istart
1870Start element in the lattice for the tracking
18711
1872istop
1873End element in the lattice for tracking
1874108
1875nstepp
1876Number of steps to do tracking in the positive energy range
1877100
1878nstepn
1879Number of steps to do tracking in the negative energy range
1880100
1881Deltaminp
1882Positive start energy of the tracking
18830.01
1884Deltamaxp
1885Positive end energy of the tracking
18860.05
1887Deltaminn
1888Negative start energy of the tracking
1889-0.01
1890Deltamaxn
1891Negative end energy of the tracking
1892-0.05
1893nturns
1894Number of turn
18951026
1896zinitial
1897The initial vertical coordinate which is used to search for 6D closed orbit. This value should be a small value.
18980.0003   [m]
1899
1900         
1901\subsection{ReadMultipoleFlag}
1902Read multipole field error from a file (SOLEIL lattice) \\
1903
1904
1905  After defining the file names of multipole field errors on SOLEIL storage ring (section  and ), use the command:
1906ReadMultipoleFlag
1907to read multipole field errors and set the corresponding values to SOLEIL lattice. The multipole field errors of correctors and skew quadrupoles are added on the thick sextupoles which are integrated at the same magnets. The format of multipole errors file is given in section  .
1908
1909  After setting the multipole field errors in the lattice, the code will generate a file at the current working directory, and the file name is “flat\_file\_errmultipole.dat”, user can check the field components of the lattice elements in this file to verify the multipole field errors.
1910
1911\subsection{ReadVirtualSkewquadFlag}
1912Read the sources of coupling from a file (SOLEIL lattice) \\
1913
1914  The sources of coupling on SOLEIL storage ring can be read from an external file.  Use the command:
1915ReadVirtualSkewquadFlag
1916to read and set the field strength to the virtual skew quadrupoles. Currently this command only works for Soleil lattice.
1917The coupling sources MUST be defined as the skew quadrupoles with the name “SQ”, the rules and related information are explained in section.
1918
1919\subsection{FitTuneFlag}
1920Fit tunes for the lattice with full quadrupole \\
1921
1922Betatron tunes can be fit using two families of quadrupoles. The command is:
1923FitTuneFlag      Quad1   Quad2   nux   nuz
1924For example:
1925FitTuneFlag      q7 q9   18.202   10.317
1926The parameters of this command are shown in Table .
1927Table   Parameters of the command “FitTuneFlag”.
1928Parameters
1929Meaning
1930Default values
1931Quad1
1932Quadrupole family used to fit the tunes
1933-
1934Quad2
1935Quadrupole family used to fit the tunes
1936-
1937nux
1938Target horizontal tune
19390.0
1940nuz
1941Target vertical tune
19420.0
1943
1944  After fitting the tunes, field strengths of the fitted quadrupoles before and after the fitting are printed to the screen; user can copy the new quadrupole field strengths to the lattice file for further analysis.
1945FitTuneFlag is a generic command; it works for the lattices with full qudrupoles.
1946
1947\subsection{FitTune4Flag}
1948Fit tunes for the lattice with half quadrupoles \\
1949
1950For the lattice with each quadrupole cut into two pieces, betatron tunes can be fit using two families of quadrupoles. The command is:
1951FitTune4Flag      Q1a  Q1b  Q2a  Q2b  nux  nuz
1952The parameters of this command are shown in Table .
1953
1954\begin{table}[h]
1955\centering
1956\caption{}
1957\label{}
1958\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
1959\hline
1960\hline
1961\end{tabular*}
1962\end{table}
1963
1964Table  Parameters of the command “FitTune4Flag”.
1965Parameters
1966Meaning
1967Default values
1968Q1a
1969First half of the quadrupole family used to fit the tunes
1970-
1971Q1b
1972Second half of the quadrupole family used to fit the tunes
1973-
1974Q2a
1975First half of the quadrupole family used to fit the tunes
1976-
1977Q2b
1978Second half of the quadrupole family used to fit the tunes
1979-
1980nux
1981Target horizontal tune
19820.0
1983nuz
1984Target vertical tune
19850.0
1986
1987For example:
1988FitTune4Flag      qp7a  qp7b   qp9a  qp9b  18.202 10.317
1989In this example, all the variables have the same meaning as the ones in the command “FitTuneFlag”, except “qp7a” and “qp7b” are the two half pieces of the full quadrupole “qp7”, and “qp9a” and “qp9b” are the two half pieces of the full quadrupole 'qp9'.
1990  After fitting the tunes, the field strengths of fitted quadrupole before and after the fitting are printed to the screen; user can copy the new field strengths of quadrupoles to the lattice file for further analysis. 
1991  FitTune4Flag is a command that works for the lattices in which each quadrupole are cut into two halves.
1992
1993\subsection{FitChromFlag}
1994Fit chromaticity \\
1995
1996 Chromaticities can be fit using two families of sextupoles, the command is:
1997FitChromFlag     SX1    SX2    epsilon\_x    epsilon\_z
1998The parameters of this command are shown in Table .
1999
2000\begin{table}[h]
2001\centering
2002\caption{}
2003\label{}
2004\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
2005\hline
2006\hline
2007\end{tabular*}
2008\end{table}
2009
2010Table    Parameters of the command “FitChromFlag”.
2011Parameters
2012Meaning
2013Default values
2014SX1
2015First sextupole family used to fit the chromaticities
2016-
2017SX2
2018Second sextupole family used to fit the chromaticities
2019-
2020epsilon\_x
2021Target horizontal chromaticity
20220.0
2023epsilon\_z
2024Target vertical chromaticity
20250.0
2026
2027 For example:
2028FitChromFlag     sx9 sx10   2.0    2.6
2029  After fitting the chromaticites, the field strengths of fitted sextupoles before and after the fitting are printed to the screen; user can copy the new field strengths of sextupoles to the lattice file for further analysis. 
2030
2031\subsection{TouschekFlag (TO BE UPDATED)}
2032Touschek lifetime determined by RF acceptance \\
2033
2034  To calculate Touschek lifetime, use the following command:
2035TouschekFlag
2036  Here the momentum acceptance is limited by the RF acceptance.
2037
2038\subsection{IBSFlag (TO BE UPDATED)}
2039Intra Beam Scattering (IBS)  \\
2040
2041
2042  To calculate Intra Beam Scattering, use the command:
2043IBSFlag
2044
2045\subsection{TousTrackFlag (TO BE UPDATED)}
2046Touschek lifetime determined by the minimum value of RF acceptance and momentum acceptance \\
2047
2048  Touschek lifetime can be calculated by 
2049TousTrackFlag
2050In this case, the energy acceptance at each lattice element is limited by the minimum value of RF acceptance and momentum acceptance obtained by tracking, and the chamber file MUST be defined in the user script.
2051
2052\subsection{PhaseSpaceFlag}
2053Obtain phase space by tracking \\
2054
2055  To calculate phase space, use the command:  \\
2056\textbf{PhaseSpaceFlag}      Phase\_phase\_file      Phase\_Dim     Phase\_X      Phase\_Px
2057                                           Phase\_Y     Phase\_Py   Phase\_delta   Phase\_ctau               
2058                                           Phase\_nturn     damping\_flag
2059
2060For example:
2061\textbf{PhaseSpaceFlag}   phasespace.out    6D   1e-6    0.0    1e-6   0.0   0.012   0.0   1000   false
2062
2063The meanings of parameters and defaults values of PhaseSpaceFlag are shown in Table \ref{tab:phasespace-para}.
2064If user uses PhaseSpaceFlag without parameters, then the code will use the default values.
2065
2066\begin{table}[h]
2067\centering
2068\caption{Parameters of the command \textbf{PhaseSpaceFlag} to calculate phase space.}
2069\label{tab:phasespace-para}
2070\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} p{0.2\linewidth}  p{0.5\linewidth}   p{0.15\linewidth} }
2071\hline
2072\hline
2073\textbf{Symbol}    &  \textbf{Units}               & \textbf{Parameter}    \\
2074\hline
2075\textbf{Phase\_phase\_file} & File to save tracked phase space;
2076                              saved in the current directory.     &    phase.out \\
2077\textbf{Phase\_Dim}  &  4D~/~6D tracking                            &    4D \\
2078\textbf{Phase\_X}    &  Horizontal coordinate at the start
2079                        point of tracking.                        &    0.0 \\
2080\textbf{Phase\_Px}   &  Horizontal canonical momentum~/~derivative
2081                        at the start point of tracking.           &    0.0 \\
2082\textbf{Phase\_Y}    &  Vertical coordinate at the start point
2083                        of tracking.                              &    0.0 \\
2084\textbf{Phase\_Py}   &  Vertical canonical momentum~/~derivative
2085                        at the start point of tracking.           &    0.0 \\
2086\textbf{Phase\_delta}&  Energy at the start point of tracking     &    0.0 \\
2087\textbf{Phase\_ctau} &  Longitudinal position at the start point
2088                        of tracking.                              &    0.0 \\
2089\textbf{Phase\_nturn}&  Number of turns for tracking              &    512 \\
2090\textbf{Damping\_flag}& Boolean flag to turn on~/~off the radiation
2091                        damping during the tracking.              &    false \\
2092\hline
2093\hline
2094\end{tabular*}
2095\end{table}
2096
2097
2098\subsection{IDCorrFlag (Tested for TaiWan light source; TO BE CONTINUE DEVELOPPED.)}
2099Insertion device (ID) compensation  \\
2100
2101   To compensate the beta beat introduced by the insertion devices, several families of Quadruoples can be used. Defining the following command in the “*.prm” can active this action:
2102IDCorrFlag
2103  User also needs to define the following parameters used for the compensation of insertion device:
2104N\_calls      1
2105N\_steps    1
2106N\_Fam     11
2107IDCquads qs1 qs2 qs3 qs4 qs5 ql1 ql2 ql3 q1 q2 q3
2108scl\_dbetax  5e-1
2109scl\_dbetay  5e-1
2110scl\_dnux    0.1
2111scl\_dnuy    0.1
2112scl\_nux     1e1
2113scl\_nuy     1e1
2114ID\_step    0.7
2115
2116The meanings of the above commands and the default values used to do ID compensation using quadrupoles are shown in Table .
2117
2118\begin{table}[h]
2119\centering
2120\caption{}
2121\label{}
2122\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
2123\hline
2124\hline
2125\end{tabular*}
2126\end{table}
2127
2128Table   Parameters of commands to do ID compensation using quadrupoles.
2129Parameters
2130Meanings
2131Default values
2132N\_calls
2133Number of calls to do ID compensation
21341
2135N\_steps   
2136Number of steps.
21371
2138N\_Fam     
2139Number of quadrupole families used to do ID correction.
214015
2141IDCquads
2142Name of quadrupole families used to do ID correction.
2143-
2144scl\_dbetax 
2145Scaling weight factor of the change step of horizontal beta function during the ID correction.
21461
2147scl\_dbetay 
2148Scaling weight factor of the change step of vertical beta function during the ID correction.
21491
2150scl\_dnux   
2151
2152Scaling weight factor of the change step of horizontal tune during the ID correction.
21530.1
2154scl\_dnuy   
2155Scaling weight factor of the change step of vertical tune during the ID correction.
21560.1
2157scl\_nux     
2158
2159Scaling weight factor of horizontal tune during the ID correction.
2160100
2161scl\_nuy     
2162
2163Scaling weight factor of vertical tune during the ID correction.
2164100
2165ID\_step   
2166
2167
21680.7
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178Frequency map analysis for on momentum particle, command ``FmapFlag''.
2179\begin{itemize}
2180\item 
2181Frequency map analysis for off momentum particle, command ``FmapdpFlag''.
2182\item 
2183Track momentum acceptance at lattice elements, command ``MomentumAccFlag''.
2184\end{itemize}
2185
2186\subsection{Compile}
2187The commonly used compilers for parallel computation are MPI 2, and Intel MPI which is based on MPI 2. For the cluster of SOLEIL Synchrotron, Intel MPI is installed. To get the parallel Tracy work, three files of the non-parallel version Tracy need to be modified.
2188The details are shown in the following steps.
2189\begin{enumerate}
2190\item
2191The path of included files of Intel MPI is added in ``Makefile.am'' under
2192path ``\$HOME/TracyIII/tracy/tracy/src'' (shown in BLUE color):
2193
2194          INCLUDES = -I../inc -I\$(NUM\_REC)/inc
2195          -I/opt/intel/impi/3.2.2.006/include64 
2196\item
2197 The execute file, source file, paths of included files and library of Intel
2198MPI are modified in ``Makefile.am'' under path ``\$HOME/TracyIII/tracy/tools''
2199 (shown in BLUE color):
2200
2201bin\_PROGRAMS = psoltracy
2202
2203soltracy\_SOURCES  = soltracy.cc  nrutil.c nrcheck.c   
2204  nrlinwww.c   nrframe.c ../tracy/src/tracy\_lib.cc   ->
2205  psoltracy\_SOURCES  = psoltracy.cc  nrutil.c  nrcheck.c   
2206  nrlinwww.c   nrframe.c   ../tracy/src/tracy\_lib.cc
2207
2208  LIBS = -L\$(NUM\_REC)/lib
2209  -L/opt/intel/impi/3.2.2.006/lib64   -L\$(LIBPATH) 
2210    -lrecipes\_c\_icc -lstdc++ -lgfortran -lmpichcxx
2211 
2212INCLUDES = -I\$(TRACY\_LIB)/tracy/inc -I\$(NUM\_REC)/inc
2213  -I/opt/intel/impi/3.2.2.006/include64
2214\item
2215The compilers used in the parallel computing are defined in the ``make\_for\_psoltracy.sh'' located in path ``\$HOME/TracyIII'' as (shown in BLUE color):
2216
2217CC = mpiicc
2218
2219                CXX = mpiicpc
2220
2221                F77 = mpiifort
2222
2223Depending on the compilers used to do parallel computation, user needs to
2224update the compilers in ``make\_for\_psoltracy.sh'' and the paths of included
2225files and library which are shown above with blue color.
2226
2227 After updating compilers, paths of included files and library for parallel
2228computation, user can run
2229
2230make\_for\_psoltracy.sh
2231
2232under the shell script to compile the parallel Tracy. After compilation,
2233the execute file ``psoltracy'' is automatically generated under the
2234path ``\$HOME/TracyIII/tracy/tools''.
2235
2236
2237\end{enumerate}
2238
2239\subsection{Run}
2240  As the non-parallel version Tracy, user needs to write the commands in a script which must be with the file extension “.prm”. The syntaxes to define the script “*.prm” are the same for both non-parallel and parallel Tracy.
2241  To run the parallel Tracy, user need to contact the administrator of their cluster to know how to run parallel programs on the cluster. For the cluster on Synchrotron SOLEIL, the nodes used to do parallel computation are assigned by PBS (Portable Batch System), so a script is need. For example, user define the input script “test.prm” to tell Tracy what jobs are need to be done on the cluster,  define script “lance\_tracy3\_parallel.sh” to assign the numbers of CPUs to do parallel computation and lance job to the SOLEIL cluster. and then type the following command under the bash shell to submit the job and run the parallel Tracy on the cluster:
2242
2243    lance\_tracy3\_parallel.sh     test.prm
2244
2245\section{ User input script}
2246  There are two types of keywords in the user input script. The first type is to set the file, the file names, and define parameters for the related calculations; the key words for such definitions are ended with the characters “Flag”. The second type is to define Boolean commands with or without parameters to do different calculations. The rules of the definition of input scripts are:
2247The blank lines and lines starting with "\#" (comment line) are ignored by the code.
2248Keywords without “Flag” as the final 4 characters are NOT executed according to the defined sequence in user input script. If the same command keywords are defined many times in the user script, only the last defined keyword is executed.
2249The commands with the last 4 characters as “Flag” are executed according to the sequence in the code.
2250The definition of lattice file at the beginning of the user script is mandatory. If the lattice file is with any of the following elements: horizontal correctors, vertical correctors, girders, BPM, skew quadrupoles, user must declare the element name at the beginning of input script.
2251One keyword command uses one line. User can not define more than one command at the same line.   
2252Except explanation, all commands with Boolean flag are the generic commands, and can be used on all the lattice of the ring.
2253\subsection{  File path}
2254   In the user input script, user can specify the name of the files which are used in the calculation, such as the lattice file, multipole field error file, misalignment error file, vacuum chamber file. When specifying the file name, user can provide the absolute path for the file which is not located at the current path, such as: “/home/physmach/Tracy3/tracy/soleil.lat”; or for convenience, user provides the filename without absolute path, but put the files at a certain directory and then specific this directory using the command:
2255                       in\_dir            user\_defined\_path
2256        For example:
2257                       in\_dir                /home/zhang/codes/TracyIII/lattice/
2258
2259This command tells the code all the files specified in the script are located at the directory “/home/zhang/codes/TracyIII/lattice/”. If user declares the files without absolute path and does not set the directory through command in\_dir; or the files specified in the script are not found at the current working path, the code will give an error message and stop running.
2260
2261\section{  File names}   
2262
2263\subsection{Lattice file name}
2264In the input script, user must define the lattice name, this is mandatory. The command is:   
2265lat\_file            lattice\_file\_name
2266Here “lattice\_file\_name” is the lattice file name without “.lat” extension. For example, the following command sets the lattice file of SOLEIL ring:
2267lat\_file   solamor2\_reglage\_focalisation\_chcvqt\_thicksextu\_LQPintermediaire\_QFF
2268  In Tracy 3, after reading the lattice, Twiss parameters are automatically printed to the file “linlat.out”.                                 
2269  If one of these elements (Horizontal/vertical correctors or beam position monitors, or girders, or skew quadrupoles.) are defined in the lattice file, for example to read the misalignment errors of the lattice element and then do orbit correction, to read multipole field errors (SOLEIL lattice), etc.; user MUST specify the names of these elements using the corresponding commands in the “*.prm” script:
2270h\_corr             HCM
2271v\_corr             VCM
2272gs                     GS
2273ge                     GE
2274bpm\_name     BPM
2275qt                     QT
2276Here “HCM” is the name of horizontal correctors used for horizontal orbit correction, or the horizontal correctors on which the multipole field errors are added in SOLEIL lattice;  “VCM” is the name of vertical correctors used for vertical orbit correction, or the vertical correctors on which the multipole field errors are added in SOLEIL lattice; “GS” is the name of the start girder;  ‘GE’ is the name of the end girder; “BPM” is the name of beam position monitors defined in the lattice file; “QT” is the name of the skew quadrupoles defined in the lattice.  Generally, user needs to define horizontal, vertical correctors and BPMs when reading the misalignment errors or correcting closed orbit distortion 
2277
2278\subsection{Multipole field error file name (SOLEIL lattice)}
2279  User can read the multipole field errors on SOLEIL lattice from an external file; the file is specified in the user script using the following command:
2280multipole\_file           multipole\_file\_name
2281Here “multipole\_file\_name” is the user defined multipole field error file, the format of this file is given in section Error: Reference source not found.
2282
2283If the multipole field errors of horizontal, vertical correctors and skew quadrupoles are defined in the “multipole\_file”, user MUST specify the names of these lattice elements in the “*.prm” file as the following example:
2284h\_corr      CH
2285v\_corr      CV
2286qt              QT
2287Here “CH”, “CV” and “QT” are the names of horizontal, vertical correctors, and skew quadrupoles respectively which are defined in the lattice file.
2288
2289\subsection{Files of multipole field errors of correctors and skew quadrupoles (SOLEIL lattice)}
2290  Horizontal, vertical correctors and skew quadrupoles are integrated with the sextupole quadrupoles on SOLEIL storage ring. To define the multipole field errors on these elements, user need to define the orders and relative strengths of multipole field errors in the multipole  field error file (section Error: Reference source not found) and specify the file name in the user input script “*.prm” (section Multipole field error file name), then specify the file names as the following example:
2291fic\_hcorr         corh.txt
2292fic\_vcorr         corv.txt
2293fic\_skew          corqt.txt
2294Here “corh.txt” and “corv.txt” are the files with measured current values corh, corv, corqt (with unit [Ampere]) for the horizontal, vertical correctors and skew quadrupoles respectively. Based on the measured current values, user can get the integrated field strength as:
2295Hcorr\_strength [T.m] = corh *\_convHcorr /brho; (horizontal correctors)
2296Vcorr\_strength [T.m] = corv *\_convVcorr /brho;  (vertical correctors)
2297Qt\_strength [T.m] = corqt *\_convQt /brho;  (skew quadrupoles)
2298here brho is the momentum rigidity, and the conversion constants between current and field are \_convHcorr = 8.14e-4, \_convVcorr = 4.642e-4, \_convQt = 93.83e-4.
2299  For SOLEIL lattice, the SAME ORDER of multipole field errors on the same elements are added together, so the SAME ORDER of horizontal/vertical, skew quadrupoles, and sextupoles are added together since these elements are integrated at the same magnets.
2300
2301\subsection{ File to define field strength of virtual coupling source elements (SOLEIL lattice)}
2302  On SOLEIL storage ring, the coupling is thought to come from the rotation of quadrupoles and vertical displacements of sextupoles. The strengths of these coupling sources are written in a file, then read by the following command:
2303virtualskewquad\_file   virtual\_skew\_quad\_currents.txt
2304
2305Here “virtual\_skew\_quad\_currents.txt” is the user defined file with strength of vertical coupling source.
2306  In order to use this command to read the virtual sources of coupling, user needs to define the virtual coupling element as a skew quadrupole in the lattice file:
2307SQ: quadrupole, tilt=45.0, K= 0.0, method=4, N=1;
2308and this virtual coupling element MUST be with the name “SQ”. Now there 152 elements defined as the virtual coupling sources in the SOLEIL lattice. The syntaxs to define skew quadrupole are explained in section .
2309  The measured current value qtcorr[i] of the ith coupling source is converted to the corresponding integrated skew quadrupole field strength corr\_strength as
2310corr\_strength [m-1] = qtcorr[i]*conv/brho;
2311here brho is momentum rigidity, and the conversion constant conv is 93.88e-4 [A-1.T].
2312
2313\subsection{Cut off value}
2314  Set the cut off value of all random distribution (Gaussian distribution) to “n” times of the RMS value sigma:
2315normalcut       n
2316
2317\section{Physics: Hamiltionian}
2318The dynamic motion of a conserved system can be described by a Hamiltonian. For an accelerator system without radiation
2319damping (energy loss) and RF cavities (energy gain), the motion of a single electron in the magnetic field can be described using the
2320following Hamitonian in the curvilinear coordinate system (Merz...)
2321\begin{eqnarray}
2322H (x,P_x; y, P_y; -t, \delta; s) &=&  L + V  \\
2323                                 &=& -(1+h_{\mathrm{ref}}x)[\sqrt(P^2 - (P_x - eA_x)^2 - (P_y - eA_y)^2 ) + eA_z(x,P_x; y, P_y,s)]  \\
2324P^2 & =& P_x^2 + P_y^2 + P_z^2
2325\end{eqnarray}
2326$h_{\mathrm{ref}}$ is the curvature of reference orbit inside the dipole.
2327The $(x,P_x; y, P_y; -t, \delta)$ are the canonical cooridinates of the $H$, and $P_x, P_y, P-z$ are respectively the
2328horizontal, vertical, and longitudinal mechanical momentums. A more convienent way is to expand the electron motion
2329around the motion of a reference particle with total momentum $P_0$, so
2330\begin{eqnarray}
2331\frac{1}{P_0}H (x,P_x; y, P_y; -t, \delta; s) &=& \\
2332H (x,p_x; y, p_y; -t, \delta; s) &=& -(1+h_{\mathrm{ref}}x)\sqrt((1+\delta)^2 - (p_x - \frac{e}{P_0}A_x)^2 - (p_y - \frac{e}{P_0}A_y)^2 ) + \frac{e}{P_0}A_z(x,p_x; y, p_y,s) \\
2333                                &=& -(1+h_{\mathrm{ref}}x)\sqrt((1+\delta)^2 - (p_x - \frac{1}{B \rho}A_x)^2 - (p_y - \frac{1}{B \rho}A_y)^2 ) + \frac{1}{B \rho}A_z(x,p_x; y, p_y,s)
2334\end{eqnarray}
2335with
2336\begin{eqnarray}
2337p_x &=& \frac{P_x}{P_0}  \\
2338p_y &=& \frac{P_y}{P_0}  \\
2339p &=& \frac{P}{P_0} = \frac{\Delta P + P_0}{P_0} = (1+\delta)   \\
2340\delta &=& \frac{\Delta P}{P_0} \\
2341B \rho &=& \frac{P_0}{e} (magnetic rigidity)
2342\end{eqnarray}
2343
2344With some operations (J. Bengtsson's linear transverse dynamics for sotrage ring with applications to the low energy antiproton ring (LEAR) at CERN; Tracy 2 manual.),
2345the Hamitonian can be expressed with the canonical coordinates $(x,p_x; y, p_y; -ct, \delta; s)$ (Tracy-2 Manual, J. Bengtsson)
2346
2347\begin{align*} 
2348%\label{Tracy:Exact:H}
2349H (x,p_x; y, p_y; -ct, \delta; s) \\
2350&=-(1+h_{\mathrm{ref}}x)(\sqrt{(1+\delta)^2 - (p_x - \frac{A_x}{B \rho})^2 - (p_y - \frac{A_y}{B \rho})^2}  + \frac{A_z}{B \rho}) + \delta  \\ 
2351&= -(1+h_{\mathrm{ref}}x)(\sqrt{(1+\delta)^2 - (p_x - \frac{A_x}{B \rho})^2 - (p_y - \frac{A_y}{B \rho})^2 }) + h_{\mathrm{ref}} x \frac{A_z}{B \rho}  \\
2352& + \frac{A_z}{B \rho} + \delta  \\ 
2353&= \underbrace{-(1+h_{\mathrm{ref}}x)\sqrt{(1+\delta)^2 - (p_x - \frac{A_x}{B \rho})^2 - (p_y - \frac{A_y}{B \rho})^2 )}}_\text{kinetic energy} \\
2354& + \underbrace{\frac{x}{\rho} +\frac{x}{2\rho^2}}_\text{Gemometic components due to the curvilinear coordinate inside the dipole}\\ 
2355& +\underbrace{\frac{A_z}{B \rho}}_\text{magnet contribution}  \\
2356& +\underbrace{\delta}_\text{due to the canonical coordinate $-ct$ instead of $-t$}\\ 
2357A_z & =A_z(x,p_x; y, p_y,s)
2358\end{align*}
2359
2360The equation is the exact Hamitonian used in Tracy. The $A_x$ are due to the longidutinal fringe field, this is an natural results due to the Maxwell Equation; $h_{\mathrm{ref}}$ is not zero only inside the dipoles.
2361
2362For the system without fringe field of the magnet, or only consider the field inside the body of the magnet, $A_x = 0$ and $A_y = 0$,
2363so the Hamiltonian is
2364\begin{align}
2365\label{eqn:exact:H:NoFF}
2366H (x,p_x; y, p_y; -ct, \delta; s) \\
2367&= \underbrace{-(1+h_{\mathrm{ref}}x)\sqrt{(1+\delta)^2 - p_x^2 - p_y^2)}}_\text{kinetic energy} \\
2368& + \underbrace{\frac{x}{\rho} +\frac{x}{2\rho^2}}_\text{Gemometic components due to the curvilinear coordinate inside the dipole}\\ 
2369& +\underbrace{\frac{A_z}{B \rho}}_\text{magnet contribution}  \\
2370& +\underbrace{\delta}_\text{due to the canonical coordinate $-ct$ instead of $-t$}\\ 
2371\end{align}
2372
2373From eqn.~\ref{eqn:exact:H:NoFF}, it is easy to get the map of the particle inside different lattice elements.
2374
2375
2376\subsection{Map of drift}
2377\label{H:drift}
2378
2379In the drift, $A_z = 0$, and $h_{\mathrm{ref}}$ = 0, from eqn.~\ref{eqn:exact:H:NoFF}, we can get the Hamiltonian
2380inside a drift is
2381\begin{align}
2382\label{eqn:H:exact:drift}
2383H (x,p_x; y, p_y; -ct, \delta; s) = -\sqrt{(1+\delta)^2 - p_x^2 - p_y^2)} + \delta
2384\end{align}
2385
2386In large ring, in order to increase the tracking speed, we can expand the sqare root in
2387eqn.~\ref{eqn:H:exact:drift} to get the approximate Hamitonian.
2388That is,
2389\begin{align}
2390\label{eqn:H:approxi:drift}
2391H (x,p_x; y, p_y; -ct, \delta; s) &= -(1+\delta) \left[ 1 - \frac{p_x^2 + p_y^2}{2 (1+\delta)^2} \right] + \delta\\
2392                                  &= \frac{p_x^2 + p_y^2}{2(1+\delta)}
2393\end{align}
2394
2395
2396From eqn.~\ref{eqn:H:exact:drift}, it is easy to get the map inside the drift for the
2397\textbf{small ring}:
2398\begin{align}
2399x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = \frac{p_{x0}}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\
2400y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}= \frac{p_{y0}}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\ 
2401(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} =-\frac{1+\delta_0}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}}+1 \\
2402or \\
2403(ct)^{'} = \frac{1+\delta_0}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}}-1 \\
2404p_x  = p_{x0} \\
2405p_y  = p_{y0} \\
2406\delta = \delta_0
2407\end{align}
2408
2409From eqn.~\ref{eqn:H:approxi:drift}, it is easy to get the map inside the drift for the
2410\textbf{big ring}:
2411\begin{align}
2412x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = \frac{p_{x0}}{1+\delta_0} \\
2413y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}= \frac{p_{y0}}{1+\delta_0} \\ 
2414(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} =-\frac{p_{x0^2}+p_{y0}^2}{2(1+\delta_0)} \\
2415or \\
2416(ct)^{'} = \frac{p_{x0^2}+p_{y0}^2}{2(1+\delta_0)} \\
2417p_x  = p_{x0} \\
2418p_y  = p_{y0} \\
2419\delta = \delta_0
2420\end{align}
2421
2422\subsection{Map of mutipoles}
2423 From eqn.~\ref{eqn:exact:H:NoFF}, we can get the Hamiltonian
2424inside a multipole without fringe field is
2425\begin{align}
2426\label{eqn:H:exact}
2427H (x,p_x; y, p_y; -ct, \delta; s) \\
2428=& \underbrace{-\sqrt{(1+\delta)^2 - p_x^2 - p_y^2}+\delta}_\text{H drift} \\
2429& \underbrace{-h_{\mathrm{ref}}x \sqrt{(1+\delta)^2 - p_x^2 - p_y^2}}_\text{H kick} \\
2430& + \underbrace{\frac{x}{\rho} +\frac{x}{2\rho^2}-\frac{A_z}{B \rho}}_\text{H kick} 
2431\end{align}
2432
2433In eqn.~\ref{eqn:H:exact}, the Hamiltonian is decomposed into two part, one is the Hamiltonian
2434of the drift which is due to the kinetic energy of the system (section~\ref{H:drift}), another part is the kick
2435due to the multipoles which will give the kick to the particle.
2436Now we only need to focus on the Hamiltonian of the multipoles which induces the kick map:
2437\begin{align}
2438\label{eqn:H:exact:multipole}
2439H (x,p_x; y, p_y; -ct, \delta; s) \\
2440&=-h_{\mathrm{ref}}x \sqrt{(1+\delta)^2 - p_x^2 - p_y^2} \\
2441& +\frac{x}{\rho} +\frac{x}{2\rho^2}-\frac{A_z}{B \rho}
2442\end{align}
2443
2444Similarly, by expand the sqare root in eqn.~\ref{eqn:H:exact}, we can get the approximate Hamiltonian
2445of the multipole as
2446\begin{align}
2447\label{eqn:H:approxi:multipole}
2448H (x,p_x; y, p_y; -ct, \delta; s) \\
2449&=-h_{\mathrm{ref}}x \sqrt{(1+\delta)^2 - p_x^2 - p_y^2} \\
2450& +\frac{x}{\rho} +\frac{x}{2\rho^2}-\frac{A_z}{B \rho} \\
2451&=-h_{\mathrm{ref}} x \delta + \frac{1}{2}h_{\mathrm{ref}} h_{B} x^2 - \frac{A_z}{B \rho}+(h_B - h_{\mathrm{ref}})x
2452\end{align}
2453where $h_{\mathrm{ref}}$ is the curvature due to the curlininear coordinates inside the dipole,
2454$h_{\mathrm{ref}} = 1/\rho_{ref}$;
2455$h_{\mathrm{bend}}$ is due to the bending curvature of the dipole which is determined by the dipole
2456field, $h_{\mathrm{bend}} = 1/ \rho_{bend}$. $h_{\mathrm{ref}} \neq 0$ only inside dipoles.
2457
2458In the dipole, $A_z \neq 0$, and $h_{\mathrm{ref}} \neq $ 0, so
2459from eqn.~\ref{eqn:H:exact:multipole}, we can get the kick map due to the dipole
2460in the \textbf{small ring} which use the exact Hamiltonian:
2461\begin{align}
2462\label{eqn:kickmap:exact}
2463x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = h_{\mathrm{ref}} x_0 \frac{p_{x0}}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\
2464y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}=  h_{\mathrm{ref}} x_0 \frac{p_{y0}}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\ 
2465p_x^{'}  = -\frac{\partial H}{\partial y_0} = h_{\mathrm{ref}} \sqrt{(1+\delta_0)^2 - p_{x0}^2 - p_{y0}^2} - h_{\mathrm{bend}} - h_{\mathrm{ref}}h_{\mathrm{bend}}x - \frac{B_y}{B \rho}\\
2466p_y^{'}  = -\frac{\partial H}{\partial y_0} = \frac{1}{B \rho} \frac{\partial A_z}{\partial y_0} = \frac{B_x}{B \rho}\\
2467(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} =-h_{\mathrm{ref}} x_0 \frac{1+\delta_0}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\
2468or \\
2469(ct)^{'} = h_{\mathrm{ref}} x_0 \frac{1+\delta_0}{\sqrt{(1+\delta_0)^2 -(p_{x0}^2+p_{y0}^2)}} \\
2470\delta = \delta_0 \\
2471B \rho = \frac{p_0}{e}
2472\end{align}
2473where
2474\begin{align}
2475\frac{\partial A_z}{\partial x} = - B_y \\
2476\frac{\partial A_z}{\partial y} = B_x
2477\end{align}
2478since
2479\begin{align}
2480A_x = 0 \\
2481A_y =0
2482\end{align}
2483inside the body of the multipoles, and
2484\begin{align*}
2485\vec{B} = \Delta \times \vec{A}  \\
2486\hat{x} & \hat{y} & \hat{z} \\
2487\frac{\partial}{x} &  \frac{\partial}{y} &  \frac{\partial}{z} \\
2488A_& A_y & A_z \\
2489\end{align*}
2490
2491
2492In the dipole, $A_z \neq 0$, and $h_{\mathrm{ref}} \neq $ 0, so
2493from eqn.~\ref{eqn:H:approxi:multipole}, we can get the kick map due to the dipole
2494in the \textbf{big ring} which use the exact Hamiltonian:
2495\begin{align}
2496\label{eqn:kickmap:approxi}
2497x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = h_{\mathrm{ref}} x_0 \frac{p_{x0}}{1+\delta_0} \\
2498y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}=  h_{\mathrm{ref}} x_0 \frac{p_{y0}}{1+\delta_0} \\ 
2499p_x^{'}  = -\frac{\partial H}{\partial y_0} = h_{\mathrm{ref}} \delta_0 - (h_{\mathrm{bend}} - h_{\mathrm{ref}}) - h_{\mathrm{ref}}h_{\mathrm{bend}}x - \frac{B_y}{B \rho}\\
2500p_y^{'}  = -\frac{\partial H}{\partial y_0} = \frac{1}{B \rho} \frac{\partial A_z}{\partial y_0} = \frac{B_x}{B \rho}\\
2501(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} =\frac{-h_{\mathrm{ref}} x_0}{1+\delta_0} \frac{-(p_{x0}^2+p_{y0}^2)}{2(1+\delta_0)} \\
2502or \\
2503(ct)^{'} =-\frac{h_{\mathrm{ref}} x_0}{1+\delta_0} \frac{(p_{x0}^2+p_{y0}^2)}{2(1+\delta_0)} \\ 
2504\delta^{'} = 0
2505\end{align}
2506
2507For other multipoles (quadrupoles, sextupole, decapole, octupole, etc), the curvilinear coordinate is
2508the cartesian coordinates, that is $h_{ref}$ = 0, so from eqn.~\ref{eqn:kickmap:exact}, the kick map for
2509these multipoles in the small ring is: 
2510\begin{align}
2511\label{eqn:kickmap:exact:multipole}
2512x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = 0 \\
2513y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}=  0 \\
2514p_x^{'}  = -\frac{\partial H}{\partial y_0} = - (h_{\mathrm{bend}} + \frac{B_y}{B \rho})\\
2515p_y^{'}  = -\frac{\partial H}{\partial y_0} = \frac{1}{B \rho} \frac{\partial A_z}{\partial y_0} = \frac{B_x}{B \rho}\\
2516(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} = 0\\
2517or \\
2518(ct)^{'} = 0 \\
2519\delta^{'} = 0
2520\end{align}
2521
2522With $h_{ref} = 0$, from eqn:~\ref{eqn:kickmap:approxi}, the kick map for these
2523multipoles (quadrupoles, sextupole, decapole, octupole, etc) in the big ring is:
2524\begin{align}
2525\label{eqn:kickmap:approxi:multipole}
2526x^{'} = \frac{dx}{ds} = \frac{\partial H}{\partial p_{x0}} = 0 \\
2527y^{'} = \frac{dy}{ds} = \frac{\partial H}{\partial p_{y0}}=  0 \\
2528p_x^{'}  = -\frac{\partial H}{\partial y_0} = - (h_{\mathrm{bend}} + \frac{B_y}{B \rho})\\
2529p_y^{'}  = -\frac{\partial H}{\partial y_0} = \frac{1}{B \rho} \frac{\partial A_z}{\partial y_0} = \frac{B_x}{B \rho}\\
2530(-ct)^{'} = \frac{d(-ct)}{ds} = \frac{\partial H}{\partial \delta_0} = 0\\
2531or \\
2532(ct)^{'} = 0 \\
2533\delta^{'} = 0
2534\end{align}
2535
2536From the eqn~\ref{eqn:kickmap:exact} to eqn.~\ref{eqn:kickmap:approxi:multipole}, it's clear
2537that the kick map from the main body of dipoles are different in the small ring and big ring;
2538while the kick map from the main body of other type of multipoles are the same in small
2539rings and big rings.
2540
2541
2542
2543
2544
2545
2546
2547
2548\section{Magnetic field}
2549
2550A. Dragt ....(Lie methods for acceleator........)
2551
2552\section{FF of dipole}
2553\subsection{kick map}
2554E. Forest ...........
2555
2556\section{FF of quadrupole}
2557\subsection{kick map}
2558
2559
2560\section{ Lattice file}
2561In the lattice, RF cavity must be defined!!! Otherwise Tracy will give the error message:
2562\textcolor{red}{Elem\_GetPos: there are no kids in family 0 ()}. This obigatory is for the
2563correct calculation of positive/negtive momentum compaction factor.
2564
2565
2566
2567The followings are the rules to define a lattice file used in Tracy 3. The curvelinear coordinates are
2568used. \textbf{The ideal particle or design particle sees the perfect magnetic field in all magnets, and its}
2569\textbf{orbit is used as the reference orbit and base of the curvilinear coordinate}. Since the reference orbit
2570is a curve inside the dipoles and a straight line in other lattice elements (drifts and the magnets except
2571dipoles), so the length of the dipole is the the path length of the reference particle inside the dipole
2572which is equal to $\rho*\theta$ where $\rho$ is the bending radius of the dipole and $theta$ is the bending angle
2573with unit [rad], and all the other magnet lengths are the straight length of the magnets.
2574
2575Due to the same reason, the curvature of the curvilinear cooridnates h = 1/$\rho$ is not zero only inside dipole;
2576in other magnets and drift h = 0, and the curvilinear coordinates goes to cartesian cooridnates.
2577As a result, the independent variable $s$ inside the dipole harmitonian is the arc length, while the staight
2578length in other lattice elements.
2579
2580\subsection{Lattice}
2581The $n^{th}$ field component of the lattice element is defined as in Tracy (n = 1, 2, 3, 4 ...):
2582\begin{eqnarray*}
2583b_n & = & \frac{1}{B \rho} \frac{1}{(n-1)!} \frac{\partial^{n-1} B_y }{\partial x ^{n-1}}|_{x=0,y=0} \\
2584a_n & = & \frac{1}{B \rho} \frac{1}{(n-1)!} \frac{\partial^{n-1} B_x }{\partial x ^{n-1}}|_{x=0,y=0} \\
2585B \rho & = & \frac{p_0}{e}
2586\end{eqnarray*}
2587$B \rho$ is the magnetic rigidity, $p_0$ is the design beam momentum, $e$ is the electric charge.
2588For example, for sextupole,  n = 3, so $b_3$ and $a_3$ are defined as
2589\begin{eqnarray*}
2590b_3 & = & \frac{1}{B \rho} \frac{1}{2} \frac{\partial^{2} B_y }{\partial x ^{2}}|_{x=0,y=0} \\
2591a_3 & = & \frac{1}{B \rho} \frac{1}{2} \frac{\partial^{2} B_x }{\partial x ^{2}}|_{x=0,y=0} 
2592\end{eqnarray*}.
2593
2594 \textbf{Notes:} 
2595In \textbf{AT} (Accelerator Toolbox) and \textbf{BETA} code, the definition of are the same as in \textbf{Tracy}.
2596While In \textbf{MAD8}, \textbf{MADX} and \textbf{ELEGANT}, the order of the field compoent start from 0, that is
2597n = 0, 1, 2, 3, ..., and the $n^{th}$ field strength components of the lattice element $b_n$ and $a_n$ are defined as
2598\begin{eqnarray*}
2599b_n & = & \frac{1}{B \rho} \frac{\partial^{n} B_y }{\partial x ^{n}}|_{x=0,y=0} \\
2600a_n & = & \frac{1}{B \rho} \frac{\partial^{n} B_x }{\partial x ^{n}}|_{x=0,y=0} \\
2601B \rho & = & \frac{p_0}{e}
2602\end{eqnarray*}
2603For example, for sextupole,  n = 3, its field component $b_2$ and $a_2$ are defined as
2604\begin{eqnarray*}
2605b_2 & = & \frac{1}{B \rho} \frac{\partial^{2} B_y }{\partial x ^{2}}|_{x=0,y=0} \\
2606a_2 & = & \frac{1}{B \rho} \frac{\partial^{2} B_x }{\partial x ^{2}}|_{x=0,y=0} 
2607\end{eqnarray*}.
2608
2609
2610                               
2611\subsection{Syntax}
2612Every line embraced by “{}” is comment line. For example:
2613
2614          {*****drift space *****} 
2615
2616Each sentence is ended by ‘;’ or no punctuation.
2617Tracy is not sensitive to capital/small letters in the lattice.
2618User can define any lattice element with any valid name (but must start with a character) they want, but the element type is fixed.
2619For the lattice of the ring, the definition of RF cavity is mandatory, and the harmonic number of the RF cavity is also mandatory; for the lattice of the linac, the definition of the RF cavity is optional.
2620
2621\subsection{Variables}
2622  User can define the variables in the lattice file. For example:
2623                    Intmeth = 4;
2624so when the code is running,  each  “intmeth” in the lattice file will be replaced by “4”.
2625
2626\subsection{Start line}
2627  The lattice file must begin with the sentence:
2628                        define    lattice;
2629This definition is mandatory.
2630
2631\subsection{Global variables}
2632  After define the ring, user needs to define the system parameters of the lattice:
2633Energy, the beam energy with unit [GeV].
2634 dP, the relative momentum offset of the particle.
2635CODeps, the convergence for the algorism to find the closed orbit.
2636 For example:
2637                Energy = 2.739;
2638dP    = 1.0d-10;
2639                                                           CODeps= 1.0d-15;
2640These definitions are mandatory.
2641
2642\section{Multipole field error file}
2643\label{sec:mult:field:error}
2644  The multipole field errors of the lattice elements can be defined in a file, and then the file is read into the lattice. User can define the systematic or random multipole field error of the lattice elements.
2645  There are two ways to define the multipole field errors, one way is to define the errors for all the families with the same type, for example, the error for all the quadrupoles; another way is to define the error for each family, for example, the “Q1” family of the quadrupoles.
2646 
2647\subsection{Systematic errors}
2648     To define the systematic multipole field error of the element, the user just need to follow the rules as below.       
2649   This command is commonly used to add the mangets design errors in the lattice.
2650Input format of multipole error:
2651       keywords/name   sys   $r0$(radius where the multipole field error is measured. If $r0$ = 0, then the An and Bn are the integrated
2652multipole field strength at the position $x$ = $z$ = 0).
2653                                            $n$(order of multipole field error, in US. notation. Dip errors is 1, quadrupole error is 2, sextupole field error is 3, decaper field error is 4, octoper field error is 5, etc.),   
2654$Bn$($n^{\mathrm{th}}$ integrated upright component of the 
2655                                            multipole field)  An($n^{\mathrm{th}}$ integrated skew component of the multipole field)
2656                                             m, Bm, Am,......   
2657The "keywords" means one type of lattice elements or the family name; the keywords of the type of lattice elements are:
2658                                dip        dipole \\
2659                              quad       quadrupole \\
2660                               sext       sextupole \\
2661                              hcorr      horizontal corrector \\
2662                              vcorr      vorizontal corrector \\
2663                              qt           skew quadrupole \\
2664
2665“sys” is a keyword to denote that user are setting the systematic multipole error.
2666Bn defines the upright component of the magnetic field, then for the component of a skew quadrupole or a vertical corrector, Bn = 0
2667An defines the skew component of the magnetic field, then for the component of a dipole or upright quadrupole, An = 0.
2668The line start with ‘\#’ is a comment line.
2669The blank lines in the multipole definition file are neglected by the code.
2670
2671There are two ways to define the multipole field errors strength, one is to define the measured field errors at the pole tip location $r_0$,
2672then $b_n$ and $a_n$ are respectively the scale coefficient of the main magnetic field coeffeicient. For example, to define the decupole field
2673errors inside a horizontal bending dipole with coefficient $b_1$, we define the normal scale coefficience as $c_5$ and skew scale coefficience
2674as $d_5$, then the $b_5$ component of this decupole is $c_5$ * $b_1$ and the skew coefficience $a_5$ is $d_5$ * $b_1$; that is
2675\begin{eqnarray*}
2676 b_5 &=& \frac{1}{B \rho} \frac{c_5 * B_0}{r_0^5}  \\
2677 a_5 &=& \frac{1}{B \rho} \frac{d_5 * B_0}{r_0^5} \\
2678\end{eqnarray*}
2679where
2680\begin{equation}
2681 b_1 = \frac{1}{B \rho} B_0.
2682\end{equation}
2683This method is the simplest way to define the multipole errors inside a lattice element. The default scaling factors $c_n$ and $d_n$ are 1.
2684
2685Another way is to direct define the multipole field coefficiences $b_n$ and $a_n$, that is, set $r_0 = 0$.
2686If the multipole field $\vec{B^{tip}}$ are measured at the tips with radius $r_0$, then $b_n$ and $a_n$ can
2687be calculated using
2688\begin{eqnarray*}   
2689b_n & = & \frac{1}{B \rho} \frac{1}{(n-1)!} \frac{\partial^{n-1} B_y }{\partial x ^{n-1}}|_{x=0,y=0}  =  \frac{1}{B \rho} \frac{B_y^{tip}}{r_0^{n-1}} \\
2690a_n & = & \frac{1}{B \rho} \frac{1}{(n-1)!} \frac{\partial^{n-1} B_x }{\partial x ^{n-1}}|_{x=0,y=0}  =  \frac{1}{B \rho} \frac{B_x^{tip}}{r_0^{n-1}} \\
2691\vec{B^{tip}} & = &  B_x^{tip} \hat{x} + B_y^{tip} \hat{y}
2692\end{eqnarray*}
2693
2694The assigned multipoles errors will be added to the corresponding $n^{th}$ order multipole errors of the lattice element.
2695
2696
2697   For the soleil lattice, the use can define the multipole errors for the type or each family. But to define the multipole error for all the quadrupoles, user can NOT define the multipole errors by the type. There are two choice: one is to define the multipole errors for each quadrupole family; second is to define the field errors by quadrupole type, and then define the multipole errors on Q2 and Q7 families (the lattice with full quadrupoles) or  QP2a, QP2b, QP7a and QP7b families (lattice with quadrupoles which are cut into two halves). This is due to that Q2/QP2a/QP2b and Q7/QP7a/QP7b are the quadrupoles which have lengths larger than other quadrupoles in the lattice, and the multipole errors on them are different from the ones on the other short quadrupoles.
2698   
2699The following is an example file to define systematic multipole errors on Soleil lattice:
2700   
2701\#dipole
2702
2703  dip sys 20e-3 2 2.2e-40 0.0 3 -3.0e-4 0.0  4 2.0e-5 0.0  5  -1.0e-4 0.0  6 -6.0e-5 0.0  7 -1.0e-4 0.0
2704
2705\#quadrupole
2706
2707
2708\#for all short quadrupoles
2709
2710
2711  quad sys 30e-3 6 2.4e-4  0.0  10 0.7e-4 0.0    14   0.9e-4  0.0
2712
2713\#for all long quadrupoles qp2 and qp7
2714
2715  qp2a sys 30e-3 6 0.7e-4  0.0  10  1.9e-4   0.0   14 1.0e-4  0.0
2716  qp2b sys  30e-3 6 0.7e-4  0.0  10  1.9e-4   0.0   14 1.0e-4  0.0
2717  qp7a sys  30e-3 6 0.7e-4  0.0  10  1.9e-4   0.0   14 1.0e-4  0.0
2718  qp7b sys  30e-3 6 0.7e-4  0.0  10  1.9e-4   0.0   14 1.0e-4  0.0
2719
2720\#for all short quadrupoles,sextupole mesure quadrupoles longs
2721
2722   quad sys 30e-3 3 -1.6e-4  0.0   4  -3.4e-4   0.0
2723
2724\#for long quadrupoles qp2 and qp7
2725
2726  qp2a sys 30e-3 3  2.9e-4  0.0   4  -8.6e-4   0.0
2727
2728  qp2b sys 30e-3 3  2.9e-4  0.0   4  -8.6e-4   0.0
2729
2730  qp7a sys 30e-3 3  2.9e-4  0.0   4  -8.6e-4   0.0
2731
2732  qp7b sys 30e-3 3  2.9e-4  0.0   4  -8.6e-4   0.0
2733
2734
2735\# for sextupoles
2736
2737  sext sys  32e-3  5  5.4e-4   0.0  7  3.3e-4 0.0  9 -4.7e-4 0.0  15 -9.0e-4 0.0  21 -20.9e-4 0.0  27  0.8e-4 0.0
2738
2739
2740\# for horizontal correctors, all An=0
2741  hcorr sys 35e-3 5 0.430 0.0   7 0.063 0.0  11 -0.037 0.0
2742
2743\# for vertical correctors, all Bn=0
2744
2745  vcorr sys 35e-3 5 0.0 -0.430  7  0.0  0.063  11 0.0  0.037
2746
2747
2748\# for sextupole associated skew quadrupole, all Bn=0
2749
2750\#  qt sys 35e-3  4  0.0  -0.0
2751
2752  qt sys 35e-3    4  0.0  -0.680
2753
2754\subsection{Ramdom error}
2755To define random multipole field errors on the lattice elements, user needs to define the seed of the random errors, and then follow the same rule as the ones to define systematic multipole error except replacing “sys” by “rms”. For example:
2756                                 seed             seed\_number
2757                                  quad                   rms                30e-3 6 2.4e-4  0.0  10 0.7e-4 0.0    14   0.9e-4  0.0
2758
2759The random multipole error is multiplied by the random scale factor; the new value is added to the corresponding components of the magnetic field. The random scale factor is generated by a random function which follows the normal distribution (mean value is 0 and standard deviation is 1). The cut off value for the normal distribution function is 2 times of the RMS value. If user does not define seed for the random function before the setting of errors, then the code will stop and give an error message.
2760
2761  Here is example file to define random multipole error in the lattice:
2762
2763 \#define seed for the ramdom multipole error
2764seed       1000000
2765
2766\#dipole
2767\#  dip 20e-3 2 2.2e-4 0.0 3 -3.0e-4 0.0  4 2.0e-5 0.0  5  -1.0e-4 0.0  6 -6.0e-5 0.0  7 -1.0e-4 0.0
2768  dip rms  20e-3 2 2.2e-40 0.0 3 -3.0e-4 0.0  4 2.0e-5 0.0  5  -1.0e-4 0.0  6 -6.0e-5 0.0  7 -1.0e-4 0.0
2769
2770\#quadrupole
2771quad rms  30e-3 3 -1.6e-4  0.0   4  -3.4e-4   0.0  6 2.4e-4  0.0  10 0.7e-4 0.0    14   0.9e-4  0.0
2772
2773Q2  rms 30e-3 3  2.9e-4  0.0   4  -8.6e-4   0.0   6 0.7e-4  0.0  10  1.9e-4   0.0   14 1.0e-4  0.0
2774Q7  rms 30e-3 3  2.9e-4  0.0   4  -8.6e-4   0.0   6 0.7e-4  0.0  10  1.9e-4   0.0   14 1.0e-4  0.0
2775
2776\section{ Misalignment error file}
2777        The misalignment error of the lattice elements can be defined in a file, and then the file is read into the lattice. User can define the systematic or random misalignment error of the lattice elements.
2778       There are two ways to define the misalignment error, one way is to define the error for all the families in one type, for example, the error for all the quadrupoles; another way is to define the error for each family, for example, the “Q1” family of the quadrupoles.
2779  The systermatic misalignment error file works for the lattices with full or half quadrupoles; the random misalignment error file only works for lattice with full quadrupoles.
2780
2781\subsection{Systematic errors}
2782     To define the systematic misalignment error of the element, user just needs to follow the rules as below.       
2783input format of misalignment error:
2784       type/family         name               sys              dx                 dy                       dr
2785
2786The "keywords" means one type of lattice elements or the name of the family, and keywords of the type of lattice elements are:
2787                              All                  all the elements in the lattice
2788                              girder            girder
2789                              dipole             dipole
2790                              quad                quadrupole
2791                              sext                 sextupole
2792                              bpm                  beam position monitor
2793                              family name     family name of the elements
2794“sys” is a keyword to denote that user are setting the systematic displacement error.
2795dx defines the displacement in x direction with unit [m].
2796dy defines the displacement in y direction with unit [m].
2797dr defines the rotation angle with unit [rad]).
2798The line start with ‘\#’ is comment line.
2799The blank line in the misalignment error file is neglected by the code.
2800
2801   The following is an example file to define systematic multipole error on Soleil lattice:
2802
2803\#----------------------------------------------------------------------- 
2804\#  systematic  alignment error for SOLEIL
2805\#  name       x(m)      y(m)      r (rad)
2806\#-----------------------------------------------------------------------
2807\begin{table}[h]
2808\centering
2809\caption{}
2810\label{}
2811\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
2812\hline
2813\hline
2814\end{tabular*}
2815\end{table}
2816
2817girder  sys   100.0e-6  100.0e-6            0.5e-03
2818quad    sys    30.0e-6   30.0e-6       80.0e-06
2819sext    sys    30.0e-6   30.0e-6      100.0e-06
2820dipole  sys   500.0e-6  500.0e-6            0.2e-03
2821
2822\subsection{Random errors}
2823To define random misalignment errors on the lattice elements, user need to follow the same rule as the ones to define systematic misalignment error except replacing “sys” by “rms”. That is:
2824input format of misalignment error:
2825seed            seed\_number
2826      type/family      name               rms              dx                 dy                       dr
2827The random misalignment error is multiplied by the random scale factor; the new value is added to the corresponding components of the misalignment components. The random scale factor is generated by a random function which follows the normal distribution (mean value is 0 and standard deviation is 1), the cut off value for the normal distribution function is 2 times of the RMS value.       
2828  If user does not define seed for the random function before the setting of errors, then the code will stop and give an error message.
2829  Here is example file to define random misalignment error in the lattice:
2830\#----------------------------------------------------------------------- 
2831\#  random  alignment error for SOLEIL
2832\#  name       x(m)      y(m)      r (rad)
2833\#-----------------------------------------------------------------------
2834\begin{table}[h]
2835\centering
2836\caption{}
2837\label{}
2838\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|p{0.2\linewidth} |p{0.5\linewidth} | p{0.15\linewidth} |}
2839\hline
2840\hline
2841\end{tabular*}
2842\end{table}
2843
2844girder  rms   100.0e-6  100.0e-6            0.5e-03
2845quad    rms    30.0e-6   30.0e-6       80.0e-06
2846sext    rms    30.0e-6   30.0e-6      100.0e-06
2847dipole  rms   500.0e-6  500.0e-6            0.2e-03
28485.4 Vacuum chamber file
2849User can define the script to set the vacuum chamber limitation around the ring. The characteristic for the vacuum chamber script are:
2850Lines start with “\#” are comment.
2851The format of the vacuum chamber definition is
2852             MK1, MK2, minimum x, maximum x, minimum y, maximum y. 
2853To set the vacuum chamber, it is needed to add two markers in the lattice, such as MK1 and MK2, MK1 is before the first element and MK2 is after the end element of the vacuum chamber region.
2854The numbers of MK1 and MK2 are the same in the lattice.
2855The units are [meter] for minimum x, maximum x, minimum y, maximum y. 
2856The first line is to define the global vacuum chamber limit around the ring, and the key words should be "Start","All".
2857
2858
2859The following is one example of the user vacuum chamber script:
2860
2861         \#*********************************************
2862         \# Script to set the vacuum chamber
2863         \#
2864         \#**********************************************
2865         \# MK1 MK2  dxmin  dxmax  dymin   dymax  (Apertures in  meter)
2866         Start  All    -35e-3  35e-3  -12.5e-3   12.5e-3
2867        \#sdm1 esdm  -21e-3  21e-3   -5e-3     5e-3
2868          debut ehu600  -35e-3  35e-3  -7e-3    7e-3
2869          ssep  esep   -20e-3  35e-3  -7e-3    7e-3
2870          ssdm  esdm   -21e-3  21e-3  -5e-3    5e-3
2871           ssdac esdac  -35e-3  25e-3  -2.5e-3   2.5e-3
2872
2873\end{document}
2874
2875 
2876
Note: See TracBrowser for help on using the repository browser.