opalmap.tex 86 KB
Newer Older
snuverink_j's avatar
snuverink_j committed
1 2 3 4 5 6 7 8 9 10 11 12
%=================================================
%=================================================
%
% WARNING: NOT USED IN opal_user_guide.tex
%
%=================================================
%=================================================

\input{header}



13
\chapter{\textit{OPAL-map}} \label{sec:SplitOperatorMethods}
snuverink_j's avatar
snuverink_j committed
14 15


16
\section{\textit{OPAL-map} Conventions}
snuverink_j's avatar
snuverink_j committed
17 18 19 20 21

\label{chp:definitions}
\index{Conventions|(}
\index{Global!Reference}
\index{Reference!Global}
22
The accelerator and/or beam line to be studied with \textit{OPAL-map} is described as
snuverink_j's avatar
snuverink_j committed
23 24
a sequence of beam elements placed sequentially along a reference or
design orbit.
snuverink_j's avatar
snuverink_j committed
25
The global reference orbit, also known as the design orbit see~Figure~\ref{global}
snuverink_j's avatar
snuverink_j committed
26 27 28
is the path of a charged particle having the central design momentum
of the accelerator through idealised magnets with no fringe fields.

29
In case of \textit{OPAL-t} and \textit{OPAL-cycl} with time as the independent variable no such
snuverink_j's avatar
snuverink_j committed
30
explicit design orbit exists. The rest of this chapter is only relevant to
31
\textit{OPAL-map} except Section~\ref{units} on the physical units.
snuverink_j's avatar
snuverink_j committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63


\section{Design or Reference Orbit}
\index{Design!Orbit}
\index{Orbit!Design}
\index{Reference!Orbit}
\index{Orbit!Reference}
The reference orbit consists of a series of
straight line segments and circular arcs.
It is defined under the assumption that all elements are
perfectly aligned along the design orbit.
The accompanying tripod of the reference orbit spans
a local curvilinear right handed coordinate system $(x,y,s)$.
The local $s$-axis is the tangent to the reference orbit.
The other two axes are perpendicular to the reference orbit and
are labelled~$x$ (in the bend plane)
and~$y$ (perpendicular to the bend plane).

\section{Closed Orbit}
\index{Closed!Orbit}
\index{Orbit!Closed}
\index{Misalignment}
\index{Field!Error}
\index{Error!Field}
\index{Error!Misalignment}
\index{Fringe Field}
\index{Field!Fringe}
Due to various errors like misalignment errors, field errors,
fringe fields etc.,
the closed orbit does not coincide with the design orbit.
It also changes with the momentum error.
The closed orbit is described with respect to the reference orbit,
snuverink_j's avatar
snuverink_j committed
64
using the local reference system see~Figure~\ref{local}.
snuverink_j's avatar
snuverink_j committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
It is evaluated including any nonlinear effects.

\begin{figure}[ht]
  \begin{center}
    \setlength{\unitlength}{1pt}
    \begin{picture}(400,250)
                                % axes
      \thicklines
      \put(180,100){\vector(0,1){90}}
      \put(180,0){\line(0,1){33.3}}
      \put(187,185){\makebox(0,0){$y$}}
      \put(280,0){\vector(-1,1){160}}
      \put(120,150){\makebox(0,0){$x$}}
      \thinlines
      \put(180,100){\circle*{4}}
                                % coordinates
      \put(150,130){\line(0,1){60}}
      \put(155,125){\line(0,1){60}}
      \put(160,120){\line(0,1){60}}
      \put(165,115){\line(0,1){60}}
      \put(170,110){\line(0,1){60}}
      \put(175,105){\line(0,1){60}}
      \put(180,160){\line(-1,1){30}}
      \put(180,150){\line(-1,1){30}}
      \put(180,140){\line(-1,1){30}}
      \put(180,130){\line(-1,1){30}}
      \put(180,120){\line(-1,1){30}}
      \put(180,110){\line(-1,1){30}}
                                % radius of curvature and centre
      \put(280,0){\vector(-3,1){172}}
      \put(160,30){\makebox(0,0){$\rho$}}
      \put(280,0){\vector(0,1){142}}
      \put(290,60){\makebox(0,0){$\rho$}}
      \put(280,0){\circle*{4}}
      \put(295,15){\vector(-1,-1){12}}
      \put(295,15){\makebox(0,0)[bl]{\shortstack{centre of \\curvature}}}
      \path(270,3.3)(280,9)
      \path(260,6.7)(280,18)
      \path(250,10)(280,27)
      \path(240,13.3)(280,36)
      \path(230,16.7)(280,45)
      \path(220,20)(280,54)
      \path(210,23.3)(280,63)
      \path(200,26.7)(280,72)
      \path(190,30)(280,81)
      \path(180,33.3)(280,90)
      \path(170,36.7)(280,99)
      \path(160,40)(280,108)
      \path(150,43.3)(280,117)
      \path(140,46.7)(280,126)
      \path(130,50)(280,135)
      \path(120,53.3)(278,142)
      \path(110,56.7)(218,117.9)
                                % actual orbit
      \thicklines
      \bezier{150}(0,100)(75,165)(150,190)
      \bezier{150}(150,190)(240,220)(320,220)
      \put(320,220){\vector(1,0){4}}
      \put(80,180){\vector(1,-1){12}}
      \put(80,180){\makebox(0,0)[br]{\shortstack{actual \\orbit}}}
                                % reference orbit
      \bezier{150}(40,0)(100,60)(180,100)
      \bezier{150}(180,100)(260,140)(340,160)
      \put(340,160){\vector(4,1){4}}
      \put(330,165){\makebox{$s$}}
      \put(320,135){\vector(-1,1){12}}
      \put(320,135){\makebox(0,0)[tl]{\shortstack{reference \\orbit}}}
    \end{picture}
    \caption{Local Reference System}
    \label{fig:local}
  \end{center}
\end{figure}

\index{Betatron Motion}
\index{Synchrotron Motion}
140
\textit{OPAL-map} computes the betatron and synchrotron oscillations
snuverink_j's avatar
snuverink_j committed
141 142 143 144 145 146 147 148
with respect to the closed orbit.
Results are given in the local $(x, y, s)$-system
defined by the reference orbit.

\section{Global Reference System}
\index{Global!Reference}
\index{Reference!Global}

snuverink_j's avatar
snuverink_j committed
149
The global reference orbit see~Figure~\ref{global}
snuverink_j's avatar
snuverink_j committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
of the accelerator is uniquely defined by the sequence of physical elements.
The local reference system $(x, y, s)$
may thus be related to a global Cartesian coordinate system $(X, Y, Z)$.
The positions between beam elements are numbered $0, \ldots , i, \ldots n$.
The local reference system $(x_i, y_i, s_i)$ at position $i$,
i.e.\ the displacement and direction of the reference orbit
with respect to the system $(X, Y, Z)$ are defined by three displacements
$(X_i, Y_i, Z_i)$ and three angles $(\Theta_i, \Phi_i, \Psi_i)$.

\begin{figure}[ht]%                                         1.2
  \begin{center}
    \setlength{\unitlength}{1pt}
    \begin{picture}(400,270)
                                % global axes
      \thicklines
      \put(20,150){\line(2,-1){40}}
      \dashline{3}(60,130)(100,110)
      \put(100,110){\line(2,-1){60}}
      \put(193,63){\vector(2,-1){90}}
      \put(300,20){\makebox(0,0){$Z$}}
      \put(20,100){\line(3,1){30}}
      \dashline{3}(50,110)(248,176)
      \put(248,176){\vector(3,1){132}}
      \put(373,210){\makebox(0,0){$X$}}
      \put(80,0){\vector(0,1){270}}
      \put(70,265){\makebox(0,0){$Y$}}
                                %local axes
      \put(133.3,0){\vector(1,3){90}}
      \put(215,270){\makebox(0,0){$x$}}
      \put(300,150){\vector(-2,1){160}}
      \put(140,220){\makebox(0,0){$y$}}
      \put(0,100){\vector(2,1){270}}
      \put(260,240){\makebox(0,0){$s$}}
                                % projection of s onto ZX
      \thinlines
      \put(100,110){\circle*{4}}
      \put(200,200){\circle*{4}}
      \path(0,110)(170,110)
      \dashline{3}(170,110)(240,110)
      \path(240,110)(290,110)
      \put(280,90){\makebox(0,0)[t]{\shortstack{projection of $s$ \\
            onto $(Z,X)$-plane}}}
      \put(280,95){\vector(0,1){13}}
      \put(20,110){\circle*{4}}
      \put(50,110){\circle*{4}}
                                % hashing of xy plane
      \path(210,195)(160,45)
      \path(220,190)(169.7,39.7)
      \path(230,185)(187.5,57.5)
      \path(240,180)(205,75)
      \path(250,175)(222.5,92.5)
      \path(260,170)(240,110)
      \path(270,165)(257.5,127.5)
      \path(280,160)(275,145)

      \path(196.7,190)(278.9,148.9)
      \path(193.3,180)(271.1,141.1)
      \path(190,170)(263.3,133.3)
      \path(186.7,160)(255.5,125.5)
      \path(183.3,150)(247.7,117.7)
      \path(180,140)(239.9,109.9)
      \path(176.7,130)(232.1,101.1)
      \path(173.3,120)(224.3,94.3)
      \path(170,110)(216.5,86.5)
      \path(166.7,100)(208.7,78.7)
      \path(163.3,90)(200.9,70.9)
      \path(160,80)(193.1,63.1)
      \path(156.7,70)(185.3,55.3)
      \path(153.3,60)(177.5,47.5)
      \path(150,50)(169.7,39.7)
                                % hashing of projection plane
      \put(70,110){\line(0,1){25}}
      \put(80,110){\line(0,1){30}}
      \put(90,110){\line(0,1){35}}
      \put(100,110){\line(0,1){40}}
      \put(110,110){\line(0,1){45}}
      \put(120,110){\line(0,1){50}}
      \put(130,110){\line(0,1){55}}
      \put(140,110){\line(0,1){60}}
      \put(150,110){\line(0,1){65}}
      \put(160,110){\line(0,1){70}}
      \put(170,110){\line(0,1){75}}
      \put(180,140){\line(0,1){50}}
      \put(190,170){\line(0,1){25}}
                                % intersection of xy and ZX
      \put(130,0){\line(1,1){230}}
      \put(135,5){\circle*{4}}
      \put(193.3,63.3){\circle*{4}}
      \put(240,110){\circle*{4}}
      \put(286.7,156.7){\circle*{4}}
      \put(335,205){\circle*{4}}
      \thicklines
      \put(200,25){\vector(-1,1){20}}
      \put(200,20){\makebox(0,0)[t]{\shortstack{intersection of \\
            $(x,y)$ and $(Z,X)$ planes}}}
                                % reference orbit
      \bezier{80}(140,150)(170,185)(200,200)
      \bezier{80}(200,200)(230,215)(260,220)
      \put(260,220){\makebox(0,0)[l]{\shortstack{reference \\orbit}}}
                                % roll angle
      \bezier{30}(160,30)(160,40)(150,50)
      \put(152,48){\vector(-1,1){2}}
      \put(150,30){\makebox(0,0){$\psi$}}
      \put(140,30){\makebox(0,0)[br]{roll angle}}
                                % pitch angle
      \bezier{20}(60,110)(60,120)(55,125)
      \put(57,123){\vector(-1,2){2}}
      \put(50,118){\makebox(0,0){$\phi$}}
      \put(40,125){\makebox(0,0)[br]{pitch angle}}
                                % azimuth
      \bezier{20}(130,95)(140,100)(140,110)
      \put(140,105){\vector(0,1){5}}
      \put(130,105){\makebox(0,0){$\theta$}}
      \put(115,95){\makebox(0,0)[t]{azimuth}}
    \end{picture}
    \caption{Global Reference System}
    \label{fig:global}
  \end{center}
\end{figure}

\index{Displacement}
The above quantities are defined more precisely as follows:
\begin{description}
\item[X]
  \index{Horizontal Displacement}
  Displacement of the local origin in $X$-direction.
\item[Y]
  \index{Vertical Displacement}
  Displacement of the local origin in $Y$-direction.
\item[Z]
  \index{Longitudinal Displacement}
  Displacement of the local origin in $Z$-direction.
  \index{Angle}
\item[THETA]
  \index{Azimuth Angle}
  Angle of rotation (azimuth) about the global $Y$-axis,
  between the global $Z$-axis and the projection
  of the reference orbit onto the $(Z, X)$-plane.
  A positive angle \texttt{THETA} forms a right-hand screw with the $Y$-axis.
\item[PHI]
  \index{Pitch Angle}
  Pitch angle, i.e. the angle between the reference orbit and its projection
  onto the $(Z, X)$-plane.
  A positive angle \texttt{PHI} correspond to $Y$ increasing with $s$.
  If only horizontal bends are present,
  the reference orbit remains in the ($Z$, $X$)-plane.
  In this case \texttt{PHI} is always zero.
\item[PSI]
  \index{Roll Angle}
  Roll angle about the local $s$-axis,
  i.e. the angle between the intersection $(x, y)$- and
  $(Z, X)$-planes and the local $x$-axis.
  A positive angle \texttt{PSI} forms a right-hand screw with the $s$-axis.
\end{description}
The angles \texttt{(THETA, PHI, PSI)} are \textbf{not} the Euler angles.
The reference orbit starts at the origin and points by default
in the direction of the positive $Z$-axis.
The initial local axes $(x, y, s)$
coincide with the global axes $(X, Y, Z)$ in this order.
The six quantities $(X_0, Y_0, Z_0, \Theta_0, \Phi_0, \Psi_0)$
thus all have zero initial values by default.
The program user may however specify different initial conditions.

Internally the displacement is described by a vector $V$
and the orientation by a unitary matrix $W$.
The column vectors of $W$ are the unit vectors spanning
the local coordinate axes in the order $(x, y, s)$.
$V$ and $W$ have the values:
\[
V=\left(\begin{array}{c}
    X \\
    Y \\
    Z
  \end{array}\right),
\qquad
W=\Theta\Phi\Psi
\]
where
\[
\Theta=\left(\begin{array}{ccc}
snuverink_j's avatar
snuverink_j committed
330
    \cos\theta &  0 &  \sin\theta \\
snuverink_j's avatar
snuverink_j committed
331
    0         &  1 &   0 \\
snuverink_j's avatar
snuverink_j committed
332
    -\sin\theta &  0 &  \cos\theta
snuverink_j's avatar
snuverink_j committed
333 334 335 336
  \end{array}\right),
\quad
\Phi=\left(\begin{array}{ccc}
    1 &  0        &  0 \\
snuverink_j's avatar
snuverink_j committed
337 338
    0 &  \cos\phi &  \sin\phi \\
    0 & -\sin\phi &  \cos\phi
snuverink_j's avatar
snuverink_j committed
339 340 341 342 343
  \end{array}\right),
\quad
\]
\[
\Psi=\left(\begin{array}{ccc}
snuverink_j's avatar
snuverink_j committed
344 345
    \cos\psi & -\sin\psi &  0 \\
    \sin\psi &  \cos\psi &  0 \\
snuverink_j's avatar
snuverink_j committed
346 347 348 349 350 351 352 353 354 355 356 357
    0        &  0        &  1
  \end{array}\right).
\]

The reference orbit should be closed and it should not be twisted.
This means that the displacement of the local reference system
must be periodic with the revolution frequency of the accelerator,
while the position angles must be periodic $\pmod{2\pi}$
with the revolution frequency.
If \texttt{PSI} is not periodic $\pmod{2\pi}$,
coupling effects are introduced.
When advancing through a beam element,
358
\textit{OPAL-map} computes $V_i$ and $W_i$
snuverink_j's avatar
snuverink_j committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
by the recurrence relations
\[
V_i = W_{i-1}R_i + V_{i-1}, \qquad
W_i = w_{i-1}S_i.
\]

The vector $R_i$ is the displacement and the matrix
$S_i$ is the rotation of the local reference system
at the exit of the element $i$ with respect to the entrance
of the same element.
The values of $R_i$ and $S_i$
are listed below for each physical element type.

\section{Local Reference Systems}
\index{Local!Reference}
\index{Reference!Local}
\subsection{Reference System for Straight Beam Elements}
\label{sec:straight}
snuverink_j's avatar
snuverink_j committed
377
In straight elements the local reference system see~Figure~\ref{straight}
snuverink_j's avatar
snuverink_j committed
378 379 380
is simply translated by the length of the element along the local $s$-axis.
This is true for
\begin{itemize}
snuverink_j's avatar
snuverink_j committed
381 382 383 384 385 386 387 388 389 390
\item Drift spaces see~Section~\ref{drift}
\item Quadrupoles see~Section~\ref{quadrupole}
\item Sextupoles see~Section~\ref{sextupole}
\item Octupoles see~Section~\ref{octupole}
\item Multipoles see~Section~\ref{octupole}
\item Solenoids see~Section~\ref{solenoid}
\item RF cavities see~Section~\ref{cavity}
\item Electrostatic separators see~Section~\ref{separator}
\item Closed orbit correctors see~Section~\ref{corrector}
\item Beam position monitors see~Section~\ref{monitors}
snuverink_j's avatar
snuverink_j committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
\end{itemize}
The corresponding $R$, $S$ are
\[
R=\left(\begin{array}{c}
    0 \\
    0 \\
    L
  \end{array}\right),
\qquad
S=\left(\begin{array}{ccc}
    1 & 0 & 0 \\
    0 & 1 & 0 \\
    0 & 0 & 1 \\
  \end{array}\right).
\]
A rotation of the element about the $S$-axis has no effect
on $R$ and $S$, since the rotations of the reference system
before and after the element cancel.

\begin{figure}[ht]
  \begin{center}
    \setlength{\unitlength}{1pt}
    \begin{picture}(400,100)
      \thinlines
                                % axes
      \put(150,50){\circle{8}}\put(150,50){\circle*{2}}
      \put(140,40){\makebox(0,0){$y_1$}}
      \put(250,50){\circle{8}}\put(250,50){\circle*{2}}
      \put(260,40){\makebox(0,0){$y_2$}}
      \put(100,50){\line(1,0){46}}
      \put(154,50){\line(1,0){92}}
      \put(254,50){\vector(1,0){46}}
      \put(290,40){\makebox(0,0){$s$}}
      \put(150,0){\line(0,1){46}}
      \put(150,54){\vector(0,1){46}}
      \put(140,90){\makebox(0,0){$x_1$}}
      \put(250,0){\line(0,1){46}}
      \put(250,54){\vector(0,1){46}}
      \put(260,90){\makebox(0,0){$x_2$}}
                                % magnet outline
      \thicklines
      \put(150,54){\line(0,1){26}}
      \put(150,46){\line(0,-1){26}}
      \put(250,54){\line(0,1){26}}
      \put(250,46){\line(0,-1){26}}
      \put(150,20){\line(1,0){100}}
      \put(150,80){\line(1,0){100}}
      \put(200,2){\vector(1,0){50}}
      \put(200,2){\vector(-1,0){50}}
      \put(200,10){\makebox(0,0){L}}
    \end{picture}
    \caption{Reference System for Straight Beam Elements}
    \label{fig:straight}
  \end{center}
\end{figure}

\subsection{Reference System for Bending Magnets}
\label{rbend}
snuverink_j's avatar
snuverink_j committed
449
Both rectangular see~Figure~\ref{rbend} and sector see~Figure~\ref{sbend}
snuverink_j's avatar
snuverink_j committed
450 451 452 453 454 455
bending magnets have a curved reference orbit.
For both types of magnets
\[
R=\left(\begin{array}{c}
    \rho(\cos\alpha-1) \\
    0 \\
snuverink_j's avatar
snuverink_j committed
456
    \rho\sin\alpha
snuverink_j's avatar
snuverink_j committed
457 458 459
  \end{array}\right),
\qquad
S=\left(\begin{array}{ccc}
snuverink_j's avatar
snuverink_j committed
460
    \cos\alpha & 0 & -\sin\alpha \\
snuverink_j's avatar
snuverink_j committed
461
    0          & 1 &  0 \\
snuverink_j's avatar
snuverink_j committed
462
    \sin\alpha & 0 &  \cos\alpha
snuverink_j's avatar
snuverink_j committed
463 464 465 466 467 468 469 470 471
  \end{array}\right),
\]
where $\alpha$ is the bend angle.
A positive bend angle represents a bend to the right,
i.e. towards negative $x$ values.
For sector bending magnets,
the bend radius is given by $\rho$,
and for rectangular bending magnets it has the value
\[
snuverink_j's avatar
snuverink_j committed
472
\rho = L / 2 n(\alpha/2).
snuverink_j's avatar
snuverink_j committed
473 474 475 476 477 478 479 480 481 482
\]
If the magnet is rotated about the $s$-axis by an angle psi,
$R$ and $S$ are transformed by
\[
R^{*} = T R, \qquad S^{*} = T S T^{-1}.
\]
where $T$ is the orthogonal rotation matrix
\[
T=
\begin{pmatrix}
snuverink_j's avatar
snuverink_j committed
483 484
    \cos\psi & -\sin\psi &  0 \\
    \sin\psi &  \cos\psi &  0 \\
snuverink_j's avatar
snuverink_j committed
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
    0        &  0        &  1
\end{pmatrix}.
\]
The special value $\psi = \pi/2$ represents a bend down.

\begin{figure}[ht]
  \begin{center}
    \setlength{\unitlength}{1pt}
    \begin{picture}(400,215)
                                % axes
      \thinlines
      \put(150,150){\circle{8}}\put(150,150){\circle*{2}}
      \put(160,140){\makebox(0,0){$y_1$}}
      \put(250,150){\circle{8}}\put(250,150){\circle*{2}}
      \put(240,140){\makebox(0,0){$y_2$}}
      \put(74,124.7){\vector(3,1){72}}
      \put(84,135){\makebox(0,0){$s_1$}}
      \put(254,148.7){\vector(3,-1){72}}
      \put(316,135){\makebox(0,0){$s_2$}}
      \put(200,0){\vector(-1,3){48.7}}
      \put(165,75){\makebox(0,0){$\rho$}}
      \put(148.7,154){\vector(-1,3){18}}
      \put(118,206){\makebox(0,0){$x_1$}}
      \put(200,0){\vector(1,3){48.7}}
      \put(235,75){\makebox(0,0){$\rho$}}
      \put(251.3,154){\vector(1,3){18}}
      \put(282,206){\makebox(0,0){$x_2$}}
      \bezier{20}(190.5,28.5)(200,31.7)(209.5,28.5)
      \put(200,20){\makebox(0,0){$\alpha$}}
      \put(154,150){\line(1,0){92}}
      \put(200,150){\circle*{4}}
      \put(200,150){\vector(0,1){60}}
      \put(210,200){\makebox(0,0){$x$}}
      \put(150,154){\line(0,1){44}}
      \put(150,146){\line(0,-1){46}}
      \put(151,154){\line(1,4){11}}
      \put(250,154){\line(0,1){44}}
      \put(250,146){\line(0,-1){46}}
      \put(249,154){\line(-1,4){11}}
                                % magnet outline
      \thicklines
      \put(200,102){\vector(-1,0){50}}
      \put(200,102){\vector(1,0){50}}
      \put(200,110){\makebox(0,0){L}}
      \put(151,154){\line(1,4){6}}
      \put(149,146){\line(-1,-4){6}}
      \put(249,154){\line(-1,4){6}}
      \put(251,146){\line(1,-4){6}}
      \put(157,178){\line(1,0){86}}
      \put(143,122){\line(1,0){114}}
      \bezier{10}(150,195)(155.5,195)(160.9,193.7)
      \put(155.5,195){\vector(3,-1){5.4}}
      \put(150,205){\makebox(0,0)[l]{$e_1$}}
      \bezier{10}(250,195)(244.5,195)(239.1,193.7)
      \put(244.5,195){\vector(-3,-1){5.4}}
      \put(250,205){\makebox(0,0)[r]{$e_2$}}
    \end{picture}
    \caption[Reference System for a Rectangular Bending Magnet]%
    {Reference System for a Rectangular Bending Magnet;
      the signs of pole-face rotations are positive as shown.}
    \label{fig:rbend}
  \end{center}
\end{figure}

\begin{figure}[ht]
  \begin{center}
    \setlength{\unitlength}{1pt}
    \begin{picture}(400,215)
                                % axes
      \thinlines
      \put(150,150){\circle{8}}\put(150,150){\circle*{2}}
      \put(160,140){\makebox(0,0){$y_1$}}
      \put(250,150){\circle{8}}\put(250,150){\circle*{2}}
      \put(240,140){\makebox(0,0){$y_2$}}
      \put(74,124.7){\vector(3,1){72}}
      \put(84,135){\makebox(0,0){$s_1$}}
      \put(254,148.7){\vector(3,-1){72}}
      \put(316,135){\makebox(0,0){$s_2$}}
      \put(200,0){\vector(-1,3){48.7}}
      \put(165,75){\makebox(0,0){$\rho$}}
      \put(148.7,154){\vector(-1,3){18}}
      \put(118,206){\makebox(0,0){$x_1$}}
      \put(200,0){\vector(1,3){48.7}}
      \put(235,75){\makebox(0,0){$\rho$}}
      \put(251.3,154){\vector(1,3){18}}
      \put(282,206){\makebox(0,0){$x_2$}}
      \bezier{20}(190.5,28.5)(200,31.7)(209.5,28.5)
      \put(200,20){\makebox(0,0){$\alpha$}}
      \put(200,158.8){\circle*{4}}
      \put(200,158.8){\vector(0,1){50}}
      \put(210,200){\makebox(0,0){$r$}}
      \put(151,154){\line(1,4){10}}
      \put(249,154){\line(-1,4){10}}
                                % magnet outline
      \thicklines
      \bezier{100}(154,151.3)(200,166.7)(246,151.3)
      \put(162,154){\vector(-3,-1){8}}
      \put(238,154){\vector(3,-1){8}}
      \put(210,168){\makebox(0,0){L}}
      \put(151,154){\line(1,4){6}}
      \put(149,146){\line(-1,-4){6}}
      \put(249,154){\line(-1,4){6}}
      \put(251,146){\line(1,-4){6}}
      \bezier{90}(157,178)(200,188.4)(243,178)
      \bezier{110}(143,122)(200,148.6)(257,122)
      \bezier{20}(137.4,187.9)(149.1,191.5)(159.7,188.8)
      \put(153.7,190.8){\vector(3,-1){6}}
      \put(150,180){\makebox(0,0){$e_1$}}
      \bezier{20}(262.6,187.9)(250.9,191.5)(240.3,188.8)
      \put(246.3,190.8){\vector(-3,-1){6}}
      \put(250,180){\makebox(0,0){$e_2$}}
    \end{picture}
    \caption[Reference System for a Sector Bending Magnet]%
    {Reference System for a Sector Bending Magnet;
      the signs of pole-face rotations are positive as shown.}
    \label{fig:sbend}
  \end{center}
\end{figure}

\subsection{Rotation of the Reference System}
\label{sec:refrot}
For a rotation of the reference system by an angle $\psi$ about the
snuverink_j's avatar
snuverink_j committed
607
beam ($s$) axis see~Figure~\ref{srot}:
snuverink_j's avatar
snuverink_j committed
608 609
\[
S=\left(\begin{array}{ccc}
snuverink_j's avatar
snuverink_j committed
610 611
    \cos\psi & -\sin\psi &  0 \\
    \sin\psi &  \cos\psi &  0 \\
snuverink_j's avatar
snuverink_j committed
612 613 614 615 616
    0        &  0        &  1 \\
  \end{array}\right),
\]
while for a
rotation of the reference system by an angle $\theta$ about
snuverink_j's avatar
snuverink_j committed
617
 the vertical ($y$) axis see~Figure~\ref{yrot}:
snuverink_j's avatar
snuverink_j committed
618 619
\[
S=\left(\begin{array}{ccc}
snuverink_j's avatar
snuverink_j committed
620
    \cos\theta &  0 & -\sin\theta \\
snuverink_j's avatar
snuverink_j committed
621
    0          &  1 &  0 \\
snuverink_j's avatar
snuverink_j committed
622
    \sin\theta &  0 &  \cos\theta
snuverink_j's avatar
snuverink_j committed
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
  \end{array}\right).
\]
In both cases the displacement $R$ is zero.

\begin{figure}[ht]%
  \begin{center}
    \setlength{\unitlength}{1pt}
    \begin{picture}(400,200)
      \thinlines
      \put(200,100){\circle{8}}\put(200,100){\circle*{2}}
      \put(190,90){\makebox(0,0){$s$}}
      \put(100,100){\line(1,0){96}}
      \put(204,100){\vector(1,0){96}}
      \put(290,90){\makebox(0,0){$x_1$}}
      \put(200,0){\line(0,1){96}}
      \put(200,104){\vector(0,1){96}}
      \put(190,210){\makebox(0,0){$y_1$}}
      \put(103,75.75){\line(4,1){93}}
      \put(204,101){\vector(4,1){93}}
      \put(287,134){\makebox(0,0){$x_2$}}
      \put(224.25,3){\line(-1,4){23.25}}
      \put(199,104){\vector(-1,4){23.25}}
      \put(166,187){\makebox(0,0){$y_2$}}
      \bezier{20}(260,100)(260,107.5)(258,114.5)
      \put(260,106.5){\vector(-1,4){2}}
      \put(250,106.25){\makebox(0,0){$\psi$}}
      \put(220,150){\circle{8}}\put(220,150){\circle*{2}}
      \put(220,140){\makebox(0,0){beam}}
    \end{picture}
    \caption{Reference System for a Rotation Around the s-Axis}
    \label{fig:srot}
  \end{center}
\end{figure}

\begin{figure}[ht]%
  \begin{center}
    \setlength{\unitlength}{1pt}
    \begin{picture}(400,200)
      \thinlines
      \put(200,100){\circle{8}}\put(200,100){\circle*{2}}
      \put(190,90){\makebox(0,0){$y$}}
      \put(100,100){\line(1,0){96}}
      \put(204,100){\vector(1,0){96}}
      \put(290,110){\makebox(0,0){$s_1$}}
      \put(200,0){\line(0,1){96}}
      \put(200,104){\vector(0,1){96}}
      \put(190,190){\makebox(0,0){$x_1$}}
      \put(103,124.25){\line(4,-1){93}}
      \put(204,99){\vector(4,-1){93}}
      \put(287,66){\makebox(0,0){$s_2$}}
      \put(175.75,3){\line(1,4){23.25}}
      \put(201,104){\vector(1,4){23.25}}
      \put(234,187){\makebox(0,0){$x_2$}}
      \bezier{20}(260,100)(260,92.5)(258,85.5)
      \put(260,93.5){\vector(-1,-4){2}}
      \put(250,93.75){\makebox(0,0){$\theta$}}
      \thicklines
      \put(100,130){\vector(1,0){200}}
      \put(290,140){\makebox(0,0){beam}}
    \end{picture}
    \caption{Reference System for a Rotation Around the y-Axis}
    \label{fig:yrot}
  \end{center}
\end{figure}

\subsection{Elements which do not Change the Local Reference}
The following elements do not affect the
reference orbit and are ignored for geometry calculations:
\begin{itemize}
snuverink_j's avatar
snuverink_j committed
692 693
\item Beam-beam interactions %Beam-beam interactions see~Section~\ref{sec:beambeam}
\item Marker see~Section~\ref{marker}
snuverink_j's avatar
snuverink_j committed
694 695 696 697 698 699
\end{itemize}

\section{Sign Conventions for Magnetic Fields}
\label{sec:sign}
\index{Sign Conventions For Fields}
\index{Field!Signs}
700
The \textit{OPAL-map} program uses the following Taylor expansion for the normal and
snuverink_j's avatar
snuverink_j committed
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
skewed field components respectively in the mid-plane $y$=0,
described in \bibref{SLAC-75}{matrix}:
\[
B_x(x,0)=\sum_{k=0}^{\infty}\frac{B_{kn}x^k}{k!}, \qquad
B_x(x,0)=\sum_{k=0}^{\infty}\frac{B_{ks}x^k}{k!}.
\]
Note the factorial in the denominator.
The field coefficients have the following meaning:
\begin{description}
\item[$B_{0n}$] Normal dipole field component.
  The component is positive if the field points in the positive $y$
  direction.
  A positive field bends a positively charged particle travelling in
  positive $s$-direction to the right.
\item[$B_{0s}$] Skew dipole field component.
  The component is positive if the field points in the negative $y$
  direction.
  A positive field bends a positively charged particle travelling in
  positive $s$-direction down.
\item[$B_{1n}$] Normal quadrupole field component
  $B_{1n}=\uglyparder{B_y}{x}$.
  The component is positive if $B_y$ is positive on the positive $x$-axis.
  A positive value corresponds to horizontal focussing of a positively
  charged particle.
\item[$B_{1s}$] Skew quadrupole field component
  $B_{1s}=\uglyparder{B_x}{x}$.
  The component is positive if $B_x$ is negative on the positive $x$-axis.
\item[$B_{2n}$] Normal sextupole field component
  $B_{2n}=\uglyparder[2]{B_y}{x}$.
  The component is positive if $B_y$ is positive on the $x$-axis.
\item[$B_{2s}$] Skew sextupole field component
  $B_{2s}=\uglyparder[2]{B_x}{x}$.
  The component is negative if $B_x$ is positive on the $x$-axis.
\item[$B_{3n}$] Normal octupole field component
  $B_{3n}=\uglyparder[3]{B_y}{x}$.
  The component is positive if $B_y$ is positive on the positive $x$-axis.
\item[$B_{3s}$] Skew octupole field component
  $B_{3s}=\uglyparder[3]{B_x}{x}$.
  The component is negative if $B_x$ is positive on the $x$-axis.
\end{description}
All derivatives are taken on the $x$-axis.
Using this expansion and the curvature $h$ of the reference orbit,
the longitudinal component of the vector potential for a magnet with
mid-plane symmetry is to order~4:
\index{Field!Vector Potential}
\index{Vector Potential}

\begin{align*}
  A_s \quad = \quad
  & B_{0n}\left(x-\frac{hx^2}{2(1+hx)}\right) \\
  &+B_{1n}\left(\frac{1}{2}(x^2-y^2)-\frac{h}{6}x^{3}
  +\frac{h^2}{24}(4x^{4}-y^{4})+\ldots\right) \\
  &+B_{2n}\left(\frac{1}{6}(x^{3}-3xy^2)-\frac{h}{24}(x^{4}-y^{4})
   +\ldots\right) \\
  &+B_{3n}\left(\frac{1}{24}(x^{4}-6x^2y^2+y^{4})+\ldots\right)
   + \ldots
\end{align*}
Taking $\mathrm{curl} A$ in curvilinear coordinates,
the field components can be computed as
\index{Field!Components}
\begin{align*}
  B_x(x,y) \quad = \quad
  & B_{1n}\left(y+\frac{h^2}{6}y^{3}+\ldots\right)
   +B_{2n}\left(xy-\frac{h^{3}}{6}y^{3}+\ldots\right) \\
  &+B_{3n}\left(\frac{1}{6}(3x^2y-y^{3})+\ldots\right) + \ldots \\
  B_y(x,y) \quad = \quad
  & B_{0n}
   +B_{1n}\left(x-\frac{h}{2}y^2+\frac{h^2}{2}xy^2+\ldots\right) \\
  &+B_{2n}\left(\frac{1}{2}(x^2-y^2)-\frac{h}{2}xy^2+\ldots\right) \\
  &+B_{3n}\left(\frac{1}{6}(x^{3}-3xy^2)+\ldots\right) + \ldots
\end{align*}
One can easily verify that both $\mathrm{curl} B$ and $\mathrm{div} B$
are zero to the order of the $B_3$ term.
Introducing the magnetic rigidity $B \rho$,
the multipole coefficients are computed as
\[
K_{kn}=eB_{kn}/p_0=B_{kn}/B\rho,\qquad
K_{ks}=eB_{ks}/p_0=B_{ks}/B\rho.
\]
Note that the $K_k$ have the \textbf{same sign} as the corresponding
field components $B_k$.
The signs will be changed due to the sign of particle charges and
the direction of travel of the beam.

785
\section{Variables in \textit{OPAL-map}}
snuverink_j's avatar
snuverink_j committed
786 787 788 789 790 791 792 793
\label{sec:variables}
\index{Variables}
For each variable the physical units are listed in square brackets.

\subsection{Canonical Variables Describing Orbits}
\label{sec:canon}
\index{Canonical Variables}
\index{Variables!Canonical}
794
\textit{OPAL-map} uses the following canonical variables
snuverink_j's avatar
snuverink_j committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
to describe the motion of particles:

\begin{description}
\item[X]
  Horizontal position $x$ of the (closed) orbit,
  referred to the ideal orbit [m].

\item[PX]
  Horizontal canonical momentum of the (closed) orbit referred
  to the ideal orbit, divided by the reference momentum:
  $\mathtt{PX} = p_x / p_0$.

\item[Y]
  Vertical position $y$ of the (closed) orbit,
  referred to the ideal orbit [m].

\item[PY]
  Vertical canonical momentum of the (closed) orbit referred
  to the ideal orbit, divided by the reference momentum:
  $\mathtt{PY} = p_y / p_0$.

\item[T]
  The negative time difference,
  multiplied by the instantaneous velocity of the particle [m]:
  $\mathtt{T} = - v \delta(t)$.
  A positive \texttt{T} means that the particle arrives ahead of the
  \textbf{reference particle}.
  \texttt{T} describes the deviation of the particle from the orbit of
  a fictitious reference particle having the constant
  \textbf{reference momentum} $p_s$ and the
  \textbf{reference velocity} $v_s$.
  $v_s$ defines the revolution frequency.
  The velocities have the values
  \[
  v = c p / \sqrt{p^2 + m^2 c^2}, \qquad
  v_s = c p_s / \sqrt{p_s^2 + m^2 c^2},
  \]
  where $c$ is the velocity of light, $m$ is the particle rest mass,
  and $p$ is the instantaneous momentum of the particle.

\item[PT]
  Momentum error, divided by the reference momentum:
  $\mathtt{PT} = \delta p / p_s$.
  This value is only non-zero when synchrotron motion is present.
  It describes the deviation of the particle from the orbit of a
  particle with the reference momentum $p_s$.
\end{description}

The independent variable is:
\begin{description}
\item[S]
  Arc length $s$ along the reference orbit [m].
\end{description}

The longitudinal variables is in the limit of fully relativistic particles
($\gamma \gg 1, v = c, p c = E$),
the variables \texttt{T, PT} used here agree with the longitudinal variables
used in \bibref{TRANSPORT}{transport}.
This means that \texttt{T} becomes the negative path length difference,
while \texttt{PT} is the fractional momentum error.
The reference momentum must be constant in order to keep the system
canonical.

\subsection{Normalised Variables and other Derived Quantities}
\label{sec:normal}
\index{Normalised Variables}
\index{Variables!Normalised}
\begin{description}
\item[XN]
  The normalised horizontal displacement [$\mathrm{m}^{1/2}$]:
  $\mathtt{XN} = x_n = \Re(\transpose{E_1} S Z)$.

\item[PXN]
  The normalised horizontal transverse momentum [$\mathrm{m}^{1/2}$]:
  $\mathtt{PXN} = p_{xn} = \Im(\transpose{E_1} S Z$).

\item[WX]
  The horizontal Courant-Snyder invariant [m]:
  $\mathtt{WX} = \sqrt{x_n^2 + p_{xn}^2}$.

\item[PHIX]
  The horizontal phase:
  $\mathtt{PHIX} = - \arctan(p_{xn} / x_n) / 2 \pi$.

\item[YN]
  The normalised vertical displacement [$\mathrm{m}^{1/2}$]:
  $\mathtt{YN} = y_n = \Re(\transpose{E_2} S Z)$.

\item[PYN]
  The normalised vertical transverse momentum [$\mathrm{m}^{1/2}$]:
  $\mathtt{PYN} = p_{yn} = \Im(\transpose{E_2} S Z)$.

\item[WY]
  The vertical Courant-Snyder invariant [m]:
  $\mathtt{WY} = \sqrt{y_n^2 + p_{yn}^2}$.

\item[PHIY]
  The vertical phase:
  $\mathtt{PHIY} = - \arctan(p_{yn} / y_n) / 2 \pi$.

\item[TN]
  The normalised longitudinal displacement [$\mathrm{m}^{1/2}$]:
  $\mathtt{TN} = t_n = \Re(\transpose{E_3} S Z)$.

\item[PTN]
  The normalised longitudinal transverse momentum [$\mathrm{m}^{1/2}$]:
  $\mathtt{PTN} = p_{tn} = Im(\transpose{E_3} S Z)$.

\item[WT]
  The longitudinal invariant [m]:
  $\mathtt{WT} = \sqrt{t_n^2 + p_{tn}^2}$.

\item[PHIT]
  The longitudinal phase:
  $\mathtt{PHIT} = + \arctan(p_{tn} / t_n) / 2 \pi$.

\end{description}
in the above formulas $Z$ is the phase space vector
$Z = \transpose{(x, p_x, y, p_y, t, p_t)}$.
The matrix $S$ is the ``symplectic unit matrix''
\[
S =
\begin{pmatrix}
    0 & 1 & 0 & 0 & 0 & 0 \\
   -1 & 0 & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & 1 & 0 & 0 \\
    0 & 0 &-1 & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 & 1 \\
    0 & 0 & 0 & 0 &-1 & 0
  \end{pmatrix},
\]
and the vectors $E_i$ are the three complex eigenvectors.
The superscript $T$ denotes the transpose of a vector or matrix.

\section{Physical Units}
\label{sec:units}
\index{Units}
\index{Physical Units}
933
Throughout the computations \textit{OPAL} uses international units see~Table~\ref{units},
snuverink_j's avatar
snuverink_j committed
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
as defined by SI (Syst\`eme International).

\begin{table}[ht] \footnotesize
  \begin{center}
    \caption{Physical Units}
    \label{tab:units}
    \begin{tabular}{|l|l|}
      \hline
      quantity                         & dimension \\
      \hline
      Length                           & m (metres) \\
      Angle                            & rad (radians) \\
      Quadrupole coefficient           & $\mathrm{m}^{-2}$ \\
      Multipole coefficient, 2n poles  & $\mathrm{m}^{-n}$ \\
      Electric voltage                 & MV (Megavolts) \\
      Electric field strength          & MV/m \\
      Frequency                        & MHz (Megahertz) \\
      Phase angles                     & $2\pi$ \\
      Particle energy                  & GeV \\
      Particle mass                    & GeV/$c^2$ \\
      Particle momentum                & GeV/c \\
      Beam current                     & A (Amperes) \\
      Particle charge                  & e (elementary charges) \\
      Impedances                       & M$\Omega$ (Megohms) \\
      Emittances                       & $\pi$ m mrad \\
959
      Emittances \textit{OPAL-t}             & m rad \footnote{(normalized and un-normalized)}\\
snuverink_j's avatar
snuverink_j committed
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
      RF power                         & MW (Megawatts) \\
      Higher mode loss factor          & V/pc \\
      \hline
    \end{tabular}
  \end{center}
\end{table}

\index{Conventions|)}






Typically, the total Hamiltonian can be written as the sum of two parts, $H = H_{1} + H_{2}$,
which correspond to the external and space charge contributions respectively.
Such a situation is ideally suited to multi-map
snuverink_j's avatar
snuverink_j committed
977
symplectic Split-Operator methods~\ref{forestall}, also known as fractional step methods \ref{SanzSerna}.
snuverink_j's avatar
snuverink_j committed
978 979 980 981 982
A second-order accurate algorithm for a single step is given by
\begin{equation} \label{eq:splitOper1}
{\cal M}(\tau)={\cal M}_1(\tau/2)~{\cal M}_2(\tau)~{\cal M}_1(\tau/2) + \mathcal{O}(\tau^3)
\end{equation}
where $\tau$ denotes the step size, ${\cal M}_1$ is the map corresponding
snuverink_j's avatar
snuverink_j committed
983
%Equation~\ref{mad9pham}
snuverink_j's avatar
snuverink_j committed
984 985 986
to $H_{1}$  and ${\cal M}_2$ is the map corresponding to $H_{2}$.
If desired this approach can be
easily generalized to higher order accuracy using Yoshida's
snuverink_j's avatar
snuverink_j committed
987
scheme. % ~\ref{yoshida}.
snuverink_j's avatar
snuverink_j committed
988
This is the simplest 2nd order symplectic\footnote{Products of symplectic operators are symplectic as well.} Split-Operator integration method, which first applies all external forces for the first half of one integration step, then adds the complete influence of the internal forces for one entire integration step, and then applies another half of an integration step worth of external forces.
989
Details following when \textit{OPAL-map} is implemented.
snuverink_j's avatar
snuverink_j committed
990 991 992 993 994 995 996




Each \texttt{member} may be one of the following:
\begin{itemize}

snuverink_j's avatar
snuverink_j committed
997
\item A {SEQUENCE} see~Section~\ref{sequence} label,
snuverink_j's avatar
snuverink_j committed
998 999 1000
\end{itemize}
Beam lines can be nested to any level.

1001
The {TWISS} command see~Section~\ref{twiss} tells \textit{OPAL} to perform
snuverink_j's avatar
snuverink_j committed
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
lattice calculations on the sequence
\begin{verbatim}
A,B,C,D,A,D
\end{verbatim}

\subsection{Reflection and Repetition}
\label{sec:refrep}
An unsigned repetition count and an asterisk indicate
repetition of a beam line member.
An optional minus sign (\texttt{-}) prefix causes reflection,
i.e. all elements in the subsequence are taken in reverse order.
Sub-lines of reflected lines are also reflected,
but on physical elements the reflection flag is ignored.
The minus sign must precede any repetition count.
Repetitions are expanded immediately when a line is read,
so are reflections of anonymous beam lines.
The result is a flat line referring to a sequence of named elements and/or
beam lines.
1020
Please note this is not yet supported for \texttt{DOPAL-t} and \texttt{DOPAL-cycl}.
snuverink_j's avatar
snuverink_j committed
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
When the line is output, it has the form resulting from this expansion.

Example:
\begin{verbatim}
R:LINE=(G,H);
S:LINE=(C,R,D);
T:LINE=(2*S,2*(E,F),-S,-(A,B));
TWISS,LINE=T;
\end{verbatim}
The three lines are stored as follows:
\begin{verbatim}
R:LINE=(G,H);
S:LINE=(C,R,D);
T:LINE=(S,S,E,F,E,F,-S,B,A);
\end{verbatim}
When \texttt{T} is expanded, substitution is recursive:
\begin{enumerate}
\item Replace sub-line \texttt{S}:
\begin{verbatim}
(C,R,D,C,R,D,E,F,E,F,D,-R,C,B,A)
\end{verbatim}
\item Replace sub-line \texttt{R}:
\begin{verbatim}
(C,G,H,D,C,G,H,D,E,F,E,F,D,H,G,C,B,A)
\end{verbatim}
\end{enumerate}
Note that the inner sub-line R is reflected together with
the outer sub-line S.
\index{Line|)}

\section{Beam Line Sequences}
\label{sec:sequence}
\index{SEQUENCE}
\index{Sequence|(}
A sequence of elements can easily be generated from a data base
using a command looking like
\begin{verbatim}
label:SEQUENCE,REFER=keyword,L=expression,REFPOS=name;
   object-definition;
   ...;
   object-definition;
ENDSEQUENCE;
\end{verbatim}
It reads a sequence of element definitions,
compiles an object which resembles a beam line definition,
and gives it the name "label".
The resulting sequence can be used like a beam line.
1068
Please note this is not yet supported for \texttt{DOPAL-t} and \texttt{DOPAL-cycl}.
snuverink_j's avatar
snuverink_j committed
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
The attributes of the sequence are:
\begin{description}
\item[REFER]
  \index{REFER}
  The reference points for the elements are specified by the \texttt{REFER}
  attribute:
  \begin{description}
  \item[REFER=CENTRE]
    \index{CENTRE}
    The reference points are at the element centres (default).
  \item[REFER=ENTRY]
    \index{ENTRY}
    The reference points are at element entrances.
  \item[REFER=EXIT]
    \index{EXIT}
    The reference points are at element exits.
  \end{description}
\item[L]
  \index{L}
  The length of the \texttt{SEQUENCE} can be given on the
  \texttt{SEQUENCE} command,
  or it may be entered with the \texttt{ENDSEQUENCE} command.
\item[REFPOS]
  \index{REFPOS}
  Normally, the reference position for a nested sequence is defined by
  the \texttt{REFER} attribute of the enclosing sequence,
  but, if \texttt{REFPOS} is given, it specifies a \textbf{unique}
  element in the sequence whose \texttt{AT} attribute becomes the
  reference point for the sequence.
\end{description}
For each non-drift element in the sequence one element definition appears
following the \texttt{SEQUENCE} command and preceding the
\texttt{ENDSEQUENCE} command.
snuverink_j's avatar
snuverink_j committed
1102
These look similar to ordinary element definitions see~Chapter~\ref{element},
snuverink_j's avatar
snuverink_j committed
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
but they may contain an optional specification to place the element:
\begin{verbatim}
class-name,AT=expression;
class-name,AT=expression,FROM=name;
class-name,DRIFT=expression;

object-name,class-name,
	AT=expression,attribute,...,attribute;
object-name,class-name,
	AT=expression,FROM=name,attribute,...,attribute;
object-name,class-name,
	DRIFT=expression,attribute,...,attribute;
\end{verbatim}
The meaning of the \texttt{AT} specifications is:
\begin{description}
\item[AT=expression]
  \index{AT}
  Place the element's entrance, centre, or exit at the specifiet
  position.
\item[FROM=name]
  \index{FROM}
  Interpret the \texttt{AT} specification as relative to the
  \textbf{unique} element \texttt{name}.
\item[FROM=\#S]
  \index{\#S}
  Like omitting the \texttt{FROM} specification, \texttt{AT} is
  relative to the beginning of the sequence.
\item[FROM=\#E]
  \index{\#E}
  The \texttt{AT} specification is relative to the end of the
  sequence.
\item[FROM=PREVIOUS]
  \index{PREVIOUS}
  The \texttt{AT} specification is relative to the previous element.
\item[FROM=NEXT]
  \index{NEXT}
  The \texttt{AT} specification is relative to the following element.
\item[DRIFT=expression]
  \index{DRIFT}
  The element is preceded by a drift of the given length.
\end{description}

One should consider the following:

\begin{enumerate}
\item The name \texttt{class-name} must be an element
snuverink_j's avatar
snuverink_j committed
1149
  class name see~Section~\ref{elm-class},
snuverink_j's avatar
snuverink_j committed
1150 1151 1152 1153 1154
  it may optionally be preceded by a minus sign (\texttt{-}).
  This  inverts the order of the elements in the inserted object.
  This makes sense only for a beam line or sequence.

\item If the name \texttt{object-name} is not given,
1155
  \textit{OPAL} inserts the element specified by \texttt{class-name}.
snuverink_j's avatar
snuverink_j committed
1156 1157 1158 1159
  In this case no further attributes are allowed.

\item If there is a non-blank \texttt{object-name},
  this name should not be defined earlier in the data.
1160
  \textit{OPAL} then first makes a copy of \texttt{class-name} and gives it
snuverink_j's avatar
snuverink_j committed
1161 1162 1163 1164 1165 1166 1167 1168 1169
  the new name \texttt{object-name}.
  Any further attributes override the attributes inherited from
  \texttt{class-name}.b

\item The elements must be entered in order of increasing position,
  and they must not overlap.
  Their positions are evaluated while reading the \texttt{SEQUENCE}
  definition, and become \textbf{constant} values.

snuverink_j's avatar
snuverink_j committed
1170 1171
\item A {LINE} see~Section~\ref{line} or
  {SEQUENCE} see~Section~\ref{sequence} can be nested in another
snuverink_j's avatar
snuverink_j committed
1172 1173 1174 1175
  \texttt{SEQUENCE} or \texttt{LINE}.
\end{enumerate}

Within the \texttt{SEQUENCE},
1176
\textit{OPAL} generates the drift spaces for proper positioning.
snuverink_j's avatar
snuverink_j committed
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196

Example:
\begin{verbatim}
// Define element classes for a simple cell:
B:  SBEND,L=35.09,ANGLE = 0.011306116;
QF: QUADRUPOLE,L=1.6,K1=-0.02268553;
QD: QUADRUPOLE,L=1.6,K1=0.022683642;
SF: SEXTUPOLE,L=0.4,K2=-0.13129;
SD: SEXTUPOLE,L=0.76,K2=0.26328;
// Define the cell as a sequence:
CELL:SEQUENCE,L=79.0;
   B1: B, AT=19.115;
   SF1:SF,AT=37.42;
   QF1:QF,AT=38.70;
   B2: B, AT=58.255,ANGLE=-B1->ANGLE;
   SD1:SD,AT=76.74;
   QD1:QD,AT=78.20;
ENDSEQUENCE;
\end{verbatim}
In this example all members of the sequence have a new name,
1197
and \textit{OPAL} generates copies of the corresponding classes.
snuverink_j's avatar
snuverink_j committed
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
The bending magnet \texttt{B1} is wrapped to change sign,
but its definition is still equal to \texttt{B}.
Thus \texttt{B2}, which has the negative field of \texttt{B1},
has the same effect as the wrapped element \texttt{B1}.
\index{Sequence|)}


\section{Lines and Sequences with arguments}
\index{Line!Argument}
\index{Sequence!Argument}
\index{Argument!Line}
\index{Argument!Sequence}
A line or sequence definition can also have parameters like a
snuverink_j's avatar
snuverink_j committed
1211
{MACRO} see~Section~\ref{macro}.
snuverink_j's avatar
snuverink_j committed
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
Such a line or sequence can be nested (and instantiated) in another
line or sequence, but it \textbf{must have a unique name} when
instantiated in a sequence.
\par
Examples:
\begin{verbatim}
CELL(X,Y):SEQUENCE,L=79;
   QF&X: QF,AT=...;
   Y&X:  Y,L=1,AT=...;
   QD&X: QD,AT=...;
ENDSEQUENCE;
\end{verbatim}
When used as
\begin{verbatim}
CELL12: CELL(12,SF);
\end{verbatim}
this expands to
\begin{verbatim}
CELL12:SEQUENCE,L=79;
   QF12: QF,AT=...;
   SF12: SF,L=1,AT=...;
   QD12: QD,AT=...;
ENDSEQUENCE;
\end{verbatim}
A second example:
\begin{verbatim}
CELL(X,Y):LINE=(D1,QF&X,D2,Y&X,D3,QD&X,D4);
\end{verbatim}
If the proper drifts are used, this example is equivalent to
the sequence example above.

\section{Shared Lines}
\label{sec:seq-class}
\index{Line!Shared}
\index{Share Lines}
\index{Sequence!Shared}
\index{Shared Sequences}
1249
Please note this is not yet supported for \texttt{DOPAL-t} and \texttt{DOPAL-cycl}.
snuverink_j's avatar
snuverink_j committed
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
Normally, when a beam line or sequence is referred to in another line,
each reference refers to a \textbf{distinct} copy of the line.
\begin{verbatim}
L:LINE=(A,B,C);
S:SEQUENCE,L=real;
   ...
ENDSEQUENCE;
\end{verbatim}
Such a line or sequence is cloned when it is inserted in another line
or sequence, thus permitting assignment of errors to its elements
without affecting other occurrences of the same line.

A beam line or sequence can be shared by using the keyword
\texttt{SHARED},
\index{SHARED}
then the line or sequence is unique,
and all references in other lines refer to the \textbf{same} instance.
Example:
\begin{verbatim}
// Define the interaction region common to both rings:
SHARED IR2:SEQUENCE,L=...;
   ...
ENDSEQUENCE;
RING1:LINE=(...,IR2,...);
RING2:LINE=(...,IR2,...);
// Now assign imperfections to IR2 wich
// will be seen by both rings:
EALIGN,LINE=IR2,DX=...,DY=...;
\end{verbatim}
Counterexample:
\begin{verbatim}
// Define one superperiod of the machine:
SUPER:SEQUENCE,L=...;
   ...
ENDSEQUENCE;
// Each occurrence of SUPER is distinct:
RING:LINE=(8*SUPER);
// Assign different imperfections to each SUPER:
EALIGN,LINE=RING,DX=...,DY=...;
\end{verbatim}

\section{Sequence Editor}
\label{sec:editor}
\index{Edit!Sequence}
\index{Sequence Editor|(}
\index{SEQEDIT}
\index{ENDEDIT}
1297
Please note this is not yet supported for \texttt{DOPAL-t} and \texttt{DOPAL-cycl}.
snuverink_j's avatar
snuverink_j committed
1298 1299 1300 1301 1302 1303
During editing of a sequence, all element positions are evaluated
immediately when defined and stored as \textbf{constant} values.
To modify a sequence it must be selected for editing by the command
\begin{verbatim}
SEQEDIT,SEQUENCE=old-name;
\end{verbatim}
1304
\textit{OPAL} enters editing mode during which it only recognises the
snuverink_j's avatar
snuverink_j committed
1305
sequence editor commands see~Table~\ref{edit},
snuverink_j's avatar
snuverink_j committed
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
and makes the sequence \texttt{old-name} the current sequence being edited.
Editing mode is switched off by the command
\begin{verbatim}
ENDEDIT,NAME=new-name;
\end{verbatim}
If \texttt{new-name} is non-blank, it becomes the name of the edited sequence,
otherwise the modified sequence is stored under its old name.

\begin{table}[ht] \footnotesize
  \begin{center}
    \caption{Commands accepted in editor mode}
    \label{tab:edit}
    \begin{tabular}{|p{0.3\textwidth}|p{0.6\textwidth}|}
      \hline
      \tabhead{Command & Purpose}
      \hline
snuverink_j's avatar
snuverink_j committed
1322 1323 1324 1325 1326 1327 1328 1329 1330
      \tabline{SELECT}{Select elements to be affected}
      \tabline{CYCLE}{Change starting point (cyclic interchange)}
      \tabline{FLATTEN}{Flatten the sequence}
      \tabline{INSTALL}{Install new elements}
      \tabline{MOVE}{Move elements}
      \tabline{REFLECT}{Reflect the sequence}
      \tabline{REMOVE}{Remove elements}
      \tabline{REPLACE}{Replace elements}
      \tabline{ENDEDIT}{Leave sequence edit mode}
snuverink_j's avatar
snuverink_j committed
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
      \hline
    \end{tabular}
  \end{center}
\end{table}

\subsection{Selecting Element(s)}
\label{sec:editselect}
\index{SELECT}
Elements are selected by a command
\begin{verbatim}
SELECT, RANGE=range, CLASS=name, PATTERN=regex,
        FULL=logical, CLEAR=logical;
\end{verbatim}
When the clause \texttt{SELECTED} is used in an editor command,
that command acts on all elements currently selected.
A selection remains active until it is explicitly turned off by
\begin{verbatim}
SELECT, CLEAR=TRUE;
\end{verbatim}
\index{CLEAR}
or by an \texttt{ENDEDIT} command
\begin{verbatim}
ENDEDIT;
\end{verbatim}
snuverink_j's avatar
snuverink_j committed
1355
See also details on element selection see~Section~\ref{select}.
snuverink_j's avatar
snuverink_j committed
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365

\subsection{Change Start Point}
\label{sec:editcycle}
\index{CYCLE}
The command
\begin{verbatim}
CYCLE, START=place;
\end{verbatim}
\index{START}
makes a cyclic interchange of all elements in the current edit
snuverink_j's avatar
snuverink_j committed
1366
sequence so as to start at the specified place see~Section~\ref{aplace}.
snuverink_j's avatar
snuverink_j committed
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
This element should preferrably be a zero-length element like a
\texttt{MARKER}.
All further edit commands refer to the \textbf{new} positions.

\subsection{Flatten the Sequence being Edited}
\label{sec:editflat}
The sequence loaded into the editor can be flattened by the command
\begin{verbatim}
FLATTEN;
\end{verbatim}
This creates a copy of the sequence with all sub-lines and
sub-sequences expanded,
thus allowing changes also to elements within those nested parts.

\subsection{Install an Element}
\label{sec:editinstall}
\index{INSTALL}
New element(s) can be installed in the edited sequence by the commands
\begin{verbatim}
object-name: class-name, AT=at-expression, SELECTED,
             attributes;
object-name: class-name, AT=at-expression, FROM=place,
             attributes;
object-name: class-name, AT=at-expression, attributes;
class-name, AT=at-expression, SELECTED;
class-name, AT=at-expression, FROM=place;
class-name, AT=at-expression;
\end{verbatim}
It has the following attributes:
\begin{description}
\item[object\_name]
The name of the element to be installed.
If the object name is given, attributes may also be specified to
override the attributes of the class.
\item[class\_name]
The name of the class from which the element is to be defined.
\item[AT]
  \index{AT}
  The position where to install the element.
\item[FROM]
  \index{FROM}
  Three cases are possible:
  \begin{description}
  \item[SELECTED]
    \index{SELECTED}
    New elements are inserted at \texttt{AT=at-expression} from each
    currently selected element.
  \item[FROM=place]
    A new element is installed at position \texttt{AT=at-expression}
snuverink_j's avatar
snuverink_j committed
1416
    relative to the (unique) element at {place} see~Section~\ref{aplace}.
snuverink_j's avatar
snuverink_j committed
1417 1418 1419 1420 1421 1422 1423
  \item[FROM omitted or blank]
    A new element is installed at the absolute position
    \texttt{AT=at-expression}.
  \end{description}
  Relative positions may be negative.
\end{description}
The two names \texttt{object-name} and \texttt{class-name} interact
snuverink_j's avatar
snuverink_j committed
1424
in the same way as for a sequence definition see~Section~\ref{sequence}.
snuverink_j's avatar
snuverink_j committed
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
The reference points for elements is defined by the REFER attribute of the
\texttt{SEQUENCE}.

\subsection{Move an Element}
\label{sec:editmove}
\index{MOVE}
The commands
\begin{verbatim}
MOVE, SELECTED, BY=by-expression;
MOVE, ELEMENT=place, BY=by-expression;
MOVE, ELEMENT=place, TO=to-expression;
MOVE, ELEMENT=place, TO=to-expression, FROM=from-name;
\end{verbatim}
move element(s) to new location(s).
Three cases are possible:
\begin{description}
\item[SELECTED,BY=by-expression]
  \index{SELECTED}
  All currently selected elements are moved by \texttt{by-expression}.
\item[ELEMENT=place,BY=by-expression]
  \index{ELEMENT}
  \index{BY}
  The (unique) element at \texttt{place} is moved by \texttt{by-expression}.
\item[ELEMENT=place,TO=to-expression]
  \index{TO}
  The (unique) element at \texttt{place} is moved to the absolute position
  \texttt{to-expression}.
\item[ELEMENT=place,TO=to-expression,FROM=from-name]
  \index{FROM}
snuverink_j's avatar
snuverink_j committed
1454
  The (unique) element at {place} see~Section~\ref{aplace} is moved to
snuverink_j's avatar
snuverink_j committed
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
  position \texttt{to-expression} relative to element
  \texttt{from-name}.  A relative position may be negative.
\end{description}
Except in the first case, it is an error to move more than one element
with one \texttt{MOVE} command.
The \texttt{MOVE} command must not attempt to change the order of
elements in the sequence;
elements can not ``hop'' over each other.

\subsection{Reflect a Sequence}
\label{sec:editreflect}
\index{REFLECT}
The command
\begin{verbatim}
REFLECT;
\end{verbatim}
reverses the order of all elements in the sequence currently being
edited.
All further editing commands must refer to the \textbf{new} positions.
The sequence members are \textbf{not} reflected.

\subsection{Remove an Element}
\label{sec:editremove}
\index{REMOVE}
One or more element(s) can be removed by the commands
\begin{verbatim}
REMOVE, SELECTED;
REMOVE, ELEMENT=place;
\end{verbatim}
Two cases are possible:
\begin{description}
\item[SELECTED]
  \index{SELECTED}
  Removes all currently selected elements,
\item[ELEMENT=place]
  \index{ELEMENT}
snuverink_j's avatar
snuverink_j committed
1491
  Removes the single element at {place} see~Section~\ref{aplace}.
snuverink_j's avatar
snuverink_j committed
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
  It is an error of \texttt{name} occurs more than once in the sequence.
\end{description}

\subsection{Replace an Element}
\label{sec:editreplace}
\index{REPLACE}
The commands
\begin{verbatim}
REPLACE, SELECTED, BY=new-name;
REPLACE, ELEMENT=place, BY=new-name;
\end{verbatim}
replace one or more element(s) in the sequence.
Two cases are possible:
\begin{description}
\item[SELECTED]
  \index{SELECTED}
  All currently selected elements are replaced by an occurrence of the
  element \texttt{new-name}.
\item[ELEMENT=old-name]
  \index{ELEMENT}
snuverink_j's avatar
snuverink_j committed
1512
  The (unique) element at {place} see~Section~\ref{aplace} is replaced
snuverink_j's avatar
snuverink_j committed
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
  by \texttt{new-name}.
  It is an error if \texttt{old-name} is not unique.
\end{description}
Example:
\begin{verbatim}
REPLACE, ELEMENT=QF15, BY=QF17; // replace one element
\end{verbatim}
\index{Sequence Editor|)}

\subsection{Example for the Sequence Editor}
\label{sec:editxmpl}
\index{Editor Examples}
\begin{verbatim}
SEQ: SEQUENCE, L=79.00;
   B1:  B, AT=19.115;
   SF1: SF, AT=37.42;
   QF1: QF, AT=38.70;
   B2:  B, AT=58.255;
   SD1: SD, AT=76.74;
   QD1: QD, AT=78.20;
END;

B2W:B2,ANGLE=0.1*B2->ANGLE;

EDIT, SEQUENCE=SEQ;
   MOVE, ELEMENT=SF1, TO=-1.27, FROM=QF1;
   MOVE, ELEMENT=SD1, BY=0.01;
   REPLACE, ELEMENT=B2, BY=BS2;
END, NAME=NEWSEQ;
\end{verbatim}
This example moves the two sextupoles and replaces the element \texttt{B2}
by the element \texttt{B2W}.
The effect of the above \texttt{REPLACE} command is equivalent to
\begin{verbatim}
INSTALL, ELEMENT=B2W, AT=0, FROM=B2;
REMOVE, CLASS=B2;
\end{verbatim}
In this example a new element \texttt{B2W} is installed at the position
of \texttt{B2} and the the latter is removed.
This works, since all positions are e


\clearpage
\subsection{CERN SPS Lattice}
\label{sec:sps}
\index{SPS}
The CERN SPS lattice may be represented using the following beam elements:
\begin{verbatim}
QF:QUADRUPOLE,...; // focusing quadrupole
QD:QUADRUPOLE,...; // defocusing quadrupole
B1:RBEND,...;      // bending magnet of type 1
B2:RBEND,...;      // bending magnet of type 2
DS:DRIFT,...;      // short drift space
DM:DRIFT,...;      // drift space replacing two bends
DL:DRIFT,...;      // long drift space
\end{verbatim}
The SPS machine is represented by the lines
\begin{verbatim}
SPS:   LINE=(6*SUPER);
SUPER: LINE=(7*P44,INSERT,7*P44);
INSERT:LINE=(P24,2*P00,P42);
P00:   LINE=(QF,DL,QD,DL);
P24:   LINE=(QF,DM,2*B2,DS,PD);
P42:   LINE=(PF,QD,2*B2,DM,DS);
P44:   LINE=(PF,PD);
PD:    LINE=(QD,2*B2,2*B1,DS);
PF:    LINE=(QF,2*B1,2*B2,DS);
\end{verbatim}
In order not to overload the example,
small gaps between magnetic elements have been omitted.

\subsection{LEP Lattice}
\label{sec:lep}
\index{LEP}
A preliminary description of LEP has been given in the
\bibref{LEP pink book}{LEP}.
1589
Translation of those element sequences to the \textit{OPAL} input format gives:
snuverink_j's avatar
snuverink_j committed
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628
\begin{verbatim}
LEP: LINE=(4*SUP);
SUP: LINE=(OCT, -OCT);
OCT: LINE=(LOBS, RFS, DISS, ARC, DISL, RFL, LOBL);
LOBS:LINE=(L1, QS1, L2, QS2, L3, QS3, L4, QS4);
RFS: LINE=(L5, QS5, L5, QS6, L5, 2*(QS7, L5, QS8, L5));
DISS:LINE=(QS11, L25, BW, L22, QS12, L25, B4, L22, QS13,
           L25, B4, L22, QS14, L25, B4, L31, QS15, L25,
           B4, L32, SF, L23, QS16);
ARC: LINE=(L21, B6, L22, SD, L23, QD,
           7*(CELL(SF1, SD1), CELL(SF, SD)),
           CELL(SF1, SD1), L24, B6, L41, QF, L21, B6,
           L22, SD4, L23, QD, 7*(CELL(SF4, SD3),
           CELL(SF3, SD4)), CELL(SF4, SD3), L24, B6,
           L22, SF3, L23);
DISL:LINE=(QL16, L34, B4, L22, QL15, L33, B4, L22,
           QL14, L25, B4, L22, QL13, L25, B4, L22, QL12,
           L25, BW, L22, QL11);
RFL: LINE=(2*(L5, QL8, L5, QL7), L5, QL6, L5, QL5, L5);
LOBL:LINE=(QL4, L14, QL3, L13, QL2, L12, QL1, L11);
BW:  LINE=(W, L26, W);
B4:  LINE=(B, L26, B);
B6:  LINE=(B, L26, B, L26,B);
CELL(SF,SD):LINE=(L24, B6, L22, SF, L23, QF, L21, B6,
                  L22, SD, L23, QD);
\end{verbatim}
Here the element definitions have been left out to save space.

\section{Global Reference Momentum}
\label{sec:P0}
\index{P0}
Before any physics computations are attempted the following command
should be entered:
\begin{verbatim}
P0=real;
\end{verbatim}
This command sets the global reference momentum in GeV/c,
which is used to compute the magnetic fields from the normalized
multipole coefficients.
snuverink_j's avatar
snuverink_j committed
1629
The {BEAM}~command see~Chapter~\ref{beam} then renomalizes the
snuverink_j's avatar
snuverink_j committed
1630 1631 1632 1633 1634 1635
multipole coefficients.
This mechanism allows sending a beam with a momentum different from the
design momentum through a beam line.

\section{BEAM command options}

snuverink_j's avatar
snuverink_j committed
1636
By default the particle momentum is P0 see~Section~\ref{P0}.
snuverink_j's avatar
snuverink_j committed
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
A different value can be defined by one of the following:
\begin{description}
\item[ENERGY]
  \index{ENERGY}
  \index{Particle!Energy}\index{Energy}
  \index{Total Energy}
  The total energy per particle in GeV.
  If given, it must be greater then the particle mass.
\item[PC]
  \index{PC}
  \index{Momentum}
  \index{Particle!Momentum}
  The momentum per particle in GeV/c.
  If given, it must be greater than zero.
\item[GAMMA]
  \index{GAMMA}
  The ratio between total energy and rest energy of the particles
  $\gamma = E / m_0$.
  If given, it must be greater than one.
  If the mass is changed a new value for the energy should be entered.
  Otherwise the energy remains unchanged,
  and the momentum and $\gamma$ are recalculated.
\end{description}
The emittances are defined by:
\begin{description}
\item[EX]
  \index{EX}
  \index{Emittance!Horizontal}
  The horizontal emittance
snuverink_j's avatar
snuverink_j committed
1666
  $E_x=\sigma_x^2/\beta_x$
snuverink_j's avatar
snuverink_j committed
1667 1668 1669 1670 1671
  (default:~1~m).
\item[EY]
  \index{EY}
  \index{Emittance!Vertical}
  The vertical emittance
snuverink_j's avatar
snuverink_j committed
1672
  $E_y=\sigma_y^2/\beta_y$
snuverink_j's avatar
snuverink_j committed
1673 1674 1675 1676 1677
  (default:~1~m).
\item[ET]
  \index{ET}
  \index{Emittance!Longitudinal}
  The longitudinal emittance
snuverink_j's avatar
snuverink_j committed
1678
  $E_t=\sigma_e/(p_0c) \cdot c\sigma_t$
snuverink_j's avatar
snuverink_j committed
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
  (default:~1~m).
  The emittances can be replaced
  by the normalised emittances and the energy spread:
\item[EXN]
  \index{EXN}
  \index{Normalised Emittance}\index{emittance!normalised}
  The normalised horizontal emittance [m]:
  $E_{xn}=4\beta\gamma E_x$
  (ignored if $E_x$ is given).
\item[EYN]
  \index{EYN}
  The normalised vertical emittance [m]:
  $E_{yn}=4\beta \gamma E_y$
  (ignored if $E_y$ is given).
\item[SIGT]
  \index{SIGT}
  \index{Bunch!Length}
snuverink_j's avatar
snuverink_j committed
1696
  The bunch length $c\sigma_t$ [m].
snuverink_j's avatar
snuverink_j committed
1697 1698 1699
\item[SIGE]
  \index{SIGE}
  \index{Energy!Spread}
snuverink_j's avatar
snuverink_j committed
1700
  The {\em relative} energy spread $\sigma_e/p_0 c$ [1].
snuverink_j's avatar
snuverink_j committed
1701 1702 1703 1704 1705 1706 1707 1708 1709
\end{description}
For the time being, only the particle definition
(\texttt{PARTICLE,MASS,CHARGE,PC,
ENERGY,GAMMA}) is used.
The other parameters will be implemented as needed when new commands
become available.
%Certain commands compute the synchrotron tune $Q_s$
%from the RF cavities.
%If $Q_s\neq 0$,
snuverink_j's avatar
snuverink_j committed
1710
%the relative energy spread $\sigma_e/p_0c$
snuverink_j's avatar
snuverink_j committed
1711
%and the bunch length $c\sigma_t$ are
snuverink_j's avatar
snuverink_j committed
1712
%\[
snuverink_j's avatar
snuverink_j committed
1713
%\frac{\sigma_e}{p_0c}=\sqrt{\frac{2\pi Q_s E_t}{\eta C}},
snuverink_j's avatar
snuverink_j committed
1714
%\qquad
snuverink_j's avatar
snuverink_j committed
1715
%c\sigma_t=\sqrt{\frac{\eta C E_t}{2\pi Q_s}},
snuverink_j's avatar
snuverink_j committed
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746
%\]
%where $C$ is the machine circumference, and
%$\eta = (1/\gamma^2) - (1/\gamma_{tr}^2)$.
%Finally, the \texttt{BEAM} command accepts
%\begin{description}
%\item[KBUNCH]
%  \index{Bunch!Number}
%  The number of particle bunches in the machine (default:~1).
%\item[NPART]
%  \index{Bunch}
%  The number of particles per bunch (default:~0).
%\item[BCURRENT]
%  \index{Beam!Current}\index{Bunch!Current}
%  \index{Current}
%  The bunch current (default:~0~A).
%\item[BUNCHED]
%  \index{Bunch}
%  A logical flag.
%  If set, the beam is treated as bunched whenever this makes sense.
%\item[RADIATE]
%  \index{Radiation}
%  \index{Synchrotron!Radiation}
%  A logical flag.
%  If set, synchrotron radiation is considered in all bipolar magnets.
%\end{description}

\section{Tracking}

\section{Define Initial Conditions}
\label{sec:trackstart}
\index{START}
1747 1748
The \texttt{START} command is not used in \texttt{DOPAL-t} and \texttt{DOPAL-cycl}. In
\textit{OPAL-t} and \textit{OPAL-cycl} initial conditions are defined by generating a particle
snuverink_j's avatar
snuverink_j committed
1749
distribution using the \texttt{DISTRIBUTION} command see~Chapter~\ref{distribution} or
1750
run \textit{OPAL} in the restart mode see~Section~\ref{Restart}.
snuverink_j's avatar
snuverink_j committed
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764

The \texttt{START} command defines the initial coordinates of
the particles to be tracked.
There may be many \texttt{START} statements, one for each particle.
Particles are always started with coordinates relative
to the computed closed orbit for the defined energy error.
The command format is:
\begin{verbatim}
START, X=real, PX=real, Y=real, PY=real, T=real,
       DELTAP=real;
START, FX=real, PHIX=real, FY=real, PHIY=real, FT=real,
       PHIT=real;
\end{verbatim}
\texttt{START} statements must be entered after the
snuverink_j's avatar
snuverink_j committed
1765 1766
{TRACK} command see~Section~\ref{trackmode},
but before the {RUN} command see~Section~\ref{trackrun}.
snuverink_j's avatar
snuverink_j committed
1767 1768

\subsection{Absolute Particle Positions}
snuverink_j's avatar
snuverink_j committed
1769 1770
The first form of the {START} command see~Section~\ref{trackstart} defines
absolute particle positions see~Section~\ref{variables}:
snuverink_j's avatar
snuverink_j committed
1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794
\begin{description}
\item[X]
  \index{X}
  Horizontal position $x$, referred to the ideal orbit [m].
\item[PX]
  \index{PX}
  Horizontal canonical momentum, divided by the reference momentum [1].
\item[Y]
  \index{Y}
  Vertical position $y$, referred to the ideal orbit [m].
\item[PY]
  \index{PY}
  Vertical canonical momentum, divided by the reference momentum [1].
\item[T]
  \index{T}
  The negative time difference,
  multiplied by the instantaneous velocity of the particle [m].
\item[PT]
  \index{PT}
  Momentum error, divided by the reference momentum [1].
\end{description}

\subsection{Normalised Particle Positions}
The second form of the \texttt{START} command defines
snuverink_j's avatar
snuverink_j committed
1795
normalised particle positions see~Section~\ref{normal}:
snuverink_j's avatar
snuverink_j committed
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819