The Methodical Accelerator Design code (MAD) is a single-particle dynamics code which is extensively used for the design and optimization of systems of electromagnetic fields for beam lines and storage rings, most typically those used in high-energy applications. After the 8-th version of MAD, the next version – known as “X” – saw a re-vamping of the major code; since that time the code has been known as MAD-X. While MAD-X is not the best code for every job, it is a must for anyone that may have the need for doing basic layout, design, and optimization of optics and for doing basic particle tracking and sensitivity analyses of beam lines, synchrotrons, storage rings, etc, with its superior fitting and optimization routines. MAD or MAD-X has been used for the design and analysis of almost all major accelerators and beam lines at CERN, Fermilab, numerous light sources and many other major facilities since its introduction in the late 1980’s.

Below we describe briefly where to obtain and download MAD-X to your computer, how to run the code, and give a brief example of a typical MAD calculation.

On the site, go to the Releases sub-page to choose the development or production release that you would like to install on your computer. The following instructions assume that you have downloaded the 64 bit development release from the development release repository and placed it in a desired directory. From that directory:

### D.1.1 On Linux (all distributions)

In a terminal, execute the commands:

• renames the file madx-linux64 to madx

• changes the permissions for the executable file madx

• runs the executable file madx

### D.1.2 On MacOSX (starting from Leopard)

In a terminal, execute the commands:

• renames the file madx-macosx64 to madx

• changes the permissions for the executable file madx

• runs the executable file madx

### D.1.3 On Windows (starting from Windows XP)

In a terminal, execute the commands:

• renames the file madx-win64.exe to madx.exe

• runs the executable file madx.exe

By running the executable files as described above (./madx from a Mac console, for instance) MAD-X will accept MAD commands from the terminal and perform calculations and generate output. A more typical process is to edit a text file that contains MAD commands and then submit that file for execution by MAD:

edit the ASCII text file lattice.madx and then (from a Mac, for instance),

The user should download the pdf MAD-X Users’ Guide from the Documentation tab on the MAD-X web page. This web page also contains example input files as well as tutorials and a primer for learning the basics of the MAD envrionment.

Here is an input file of a MAD calculation wherein

• a simple FODO lattice is input,
• some initial values for $$\beta_x$$ and $$\beta_y$$ are given ($$\alpha$$’s are zero, by default),
• the Courant-Snyder (Twiss) parameters are computed at the end of each element starting with the initial values,
• a plot of the amplitude functions $$\beta_x$$ and $$\beta_y$$ is created,
• the periodic Courant-Snyder (Twiss) parameters are found (MATCH),
• the periodic Courant-Snyder parameters are computed,
• a plot of the periodic functions are made, and
• a table of summary parameters of the calculation is written to a file

edit a text file, titling it fodo.madx:

TITLE, 'Example 1: FODO.MADX';

BEAM, PARTICLE=ELECTRON,PC=3.0;

D: DRIFT, L=1.0;

FODO: LINE=(QF,5*(D),QD,QD,5*(D),QF);

USE, PERIOD=FODO;
TWISS,SAVE,BETX=15.0,BETY=5.0;

PLOT,HAXIS=S, VAXIS=BETX, BETY;

MATCH, SEQUENCE=FODO;

TWISS, SAVE;
PLOT,HAXIS=S, VAXIS=BETX, BETY;

Value, TABLE(SUMM,Q1);
Value, TABLE(SUMM,Q2);
WRITE,TABLE=SUMM,FILE=FODO.txt;

Upon executing this file (./madx fodo.madx) an output file fodo.txt is produced, as well as a postcript file madx.ps. These will contain:

fodo.txt:

@ NAME             %04s "SUMM"
@ TYPE             %04s "SUMM"
@ TITLE            %20s "Example 1: FODO.MADX"
@ ORIGIN           %17s "5.02.13 Darwin 64"
@ DATE             %08s "03/03/17"
@ TIME             %08s "21.07.29"
*             LENGTH             ORBIT5               ALFA            GAMMATR                 Q1                DQ1            BETXMAX              DXMAX              DXRMS             XCOMAX             XCORMS                 Q2                DQ2            BETYMAX              DYMAX              DYRMS             YCOMAX             YCORMS             DELTAP            SYNCH_1            SYNCH_2            SYNCH_3            SYNCH_4            SYNCH_5             NFLIPS
\$                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le
12                 -0                  0                  0       0.1913459932      -0.2182118039        19.81848928                  0                  0                  0                  0       0.1913459932      -0.2182118039        19.81848928                 -0                  0                  0                  0                  0                  0                  0                  0                  0                  0                  0

madx.ps (when converted to pdf) contains two images:

Naturally, MAD-X provides many options for adjusting plots, creating custom tables of output, performing particle tracking, and much more.