EUROPEAN ORGANIZATION FOR NUCLEAR RESEARCH

Beam Lines

The accelerator to be studied is known to MAD-X either as a sequence of physical elements called sequence, or as a hierarchically structured list of elements called a beam line. A beam line is built from simpler beam lines whose definitions can be nested to any level. A powerful syntax allows to repeat, to reflect, or to replace pieces of beam lines. However, internally MAD-X knows only sequences, and lines as shown below are converted into flat sequences with the same name when they are expanded. Consequently, only sequences can be SAVEd onto a file (see save).

Formally a beam line is defined by a LINE command:

label(arg{,arg}): LINE=(member{,member});
Label gives a name to the beam line for later reference.

The formal argument list (arg{,arg}) is optional (see below). Each "member" may be one of the following:

Beam lines may be nested to any level.

Simple Beam Lines

The simplest beam line consists of single elements:
label: LINE=(member{,member});
Example:
l:      line=(a,b,c,d,a,d);
        use,period=l;
The USE command tells MAD to perform all subsequent calculations on the sequence
a,b,c,d,a,d

Sub-lines

Instead of referring to an element, a beam line member can refer to another beam line defined in a separate command. This provides a shorthand notation for sub-lines which occur several times in a beam line. Lines and sub-lines can be entered in any order, but when a line is expanded, all its sub-lines must be known.

Example:

l:      line=(a,b,s,b,a,s,a,b);
s:      line=(c,d,e);
        use,period=l;
this example produces the following expansion steps:

1. replace sub-line s:

(a,b,(c,d,e),b,a,(c,d,e),a,b)

2. omit parentheses:

a,b,c,d,e,b,a,c,d,e,a,b

Reflection and Repetition

An unsigned repetition count and an asterisk indicate repetition of a beam line member. A minus prefix causes reflection, i.e. all elements in the subsequence are taken in reverse order. Sub-lines of reflected lines are also reflected, but physical elements are not. If both reflection and repetition are desired, the minus sign must precede the repetition count.

Example:

r:      line=(g,h);
s:      line=(c,r,d);
t:      line=(2*s,2*(e,f),-s,-(a,b));
        use,period=t;
Attention: the repetition "2*s" will only work if
"s" is itself a line. In case "s" is an element replace by
"2*(s)". 
Proceeding step by step, this example produces

1. Replace sub-line S:

((c,r,d),(c,r,d),(e,f),(e,f),(d,-r,c),(b,a))

2. replace sub-line r:

((c,(g,h),d),(c,(g,h),d),(e,f),(e,f),(d,(h,g),c),(b,a))

3. omit parentheses:

c,g,h,d,c,g,h,d,e,f,e,f,d,h,g,c,b,a
Note that the inner sub-line R is reflected together with the outer sub-line S.

Replaceable Arguments

A beam line definition may contain a formal argument list, consisting of labels separated by commas and enclosed in parentheses. Such a line can be expanded for different values of its arguments. When this line is referred to, its label must be followed by a list of actual arguments separated by commas and enclosed in parentheses. These arguments must be beam line, or element names. The number of actual arguments must agree with the number of formal arguments. All occurrences of a formal argument on the right-hand side of the line definition are replaced by the corresponding actual argument.

Example:

s:        line=(a,b,c);
l(x,y):   line=(d,x,e,3*y);
l4f:      line=(4*f);
lm2s:     line=(-2*s);
res:      line=l(l4f,lm2s);
Proceeding step by step, this example generates the expansion
d,f,f,f,f,e,c,b,a,c,b,a,c,b,a,c,b,a,c,b,a,c,b,a
Second example:
cel(sf,sd):     line=(qf,d,sf,d,b,d,qd,d,sd,d,b,d);
arc:            line=(cel(sf1,sd1),cel(sf2,sd2),cel(sf1,sd1));
                use,period=arc;
This example generates the expansion

1. Replace the line CEL and its formal arguments:

((qf,d,(sf1),d,b,d,qd,d,(sd1),d,b,d)
 (qf,d,(sf2),d,b,d,qd,d,(sd2),d,b,d)
 (qf,d,(sf1),d,b,d,qd,d,(sd1),d,b,d))

2. Omit parentheses:

qf,d,sf1,d,b,d,qd,d,sd1,d,b,d
qf,d,sf2,d,b,d,qd,d,sd2,d,b,d
qf,d,sf1,d,b,d,qd,d,sd1,d,b,d

Warning: Line Depreciation

MADX has been devolopped using sequences, in fact internally the code works with sequences only. Consequently, there may exist some inconveniences when only lines are used. It is recommended to convert as soon as possible lines into sequences (by means of the save command) in a design phase and to use only sequences for a finalised machine.

Limits of Construction of Lines

Since Lines are in fact depreciated there are some limits of how they can be constructed. Please find below a running MADX run which shows an example of OK (valid) and WRONG (invalid) cases.
!----------------------------------------------------------------------
beam, PARTICLE=electron, energy=1;

qf: QUADRUPOLE, L:=1,K1:=1;
qd: QUADRUPOLE, L:=1,K1:=-1;
d: DRIFT, l=1;
m: MARKER;

rpl(a,b): LINE=(a,b);
sl: LINE=(qf,d,qd);
test0: LINE=(rpl(sl,sl));          !OK 
test1: LINE=(rpl((sl),(sl)));      !OK
test2: LINE=(rpl((sl),(-sl)));     !OK
test3: LINE=(sl,-sl);              !OK
test4: LINE=(rpl((3*sl),(3*sl)));  ! WRONG
test5: LINE=(3*sl,3*sl);           !OK
test6: LINE=(rpl((3*sl),(-3*sl))); ! WRONG
test7: LINE=(3*sl,-3*sl);          !OK

use, period=test0;
twiss,BETX=1,bety=1;

use, period=test1;
twiss,BETX=1,bety=1;

use, period=test2;
twiss,BETX=1,bety=1;

use, period=test3;
twiss,BETX=1,bety=1;

use, period=test4;
twiss,BETX=1,bety=1;

use, period=test5;
twiss,BETX=1,bety=1;

use, period=test6;
twiss,BETX=1,bety=1;

use, period=test7;
twiss,BETX=1,bety=1;
!----------------------------------------------------------------------
hansg, June 17, 2002