1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need basic help with MAD-X

  1. Jul 13, 2013 #1

    I'm trying to work with the MAD-X software from CERN, but am having trouble with the basic steps. There's a lot of texts about how to define the properties of the accelerator elements but I need to know exactly what I need to do to get the codes into MAD-X... how do I load my text files, and in what format do they need to be? Why does it crash when I type "QF:QUADRAPOLE,L=0.5,K1=0.2;" into the command window? How do I save the output files?

    In principle, I'm looking for a sort of dummies guide for MAD-X. I am not aware at all of the C/C++ or linux environments.

    Best regards
  2. jcsd
  3. Aug 9, 2013 #2


    User Avatar
    Gold Member

    The best way to use MAD-X is to write your code in a text editor and not in the command line.

    If you are using windows then you can drag and drop your file onto the MAD-X icon and it will run. If you are working on Linux or Mac the navigate to the directory where mad lives from a terminal window.

    Now type ./madx < /your_directory/your_file.txt and hit enter. This will run the script.

    Outputs etc. are defined in the script. Below is a simulation of electron beam transport through a quadrupole triplet. A plot and table of twiss parameters are output.

    You may also find this short tutorial about MAD useful, which for most purposes differs only in syntax.

    IB:= 57.6/1.8;


    E_beam = IB*1.8E-3;

    BEAM, ENERGY=E_beam, EXN=1E-6, EYN=1E-6, SIGE=0.01;


    T0: LINE=(T0d1,T0Q1,T0d2,m1,T0d2,T0Q2,T0d2,m2,T0d2,T0Q3,T0d4,fp);

    T0d1: Drift, L:=D2;
    T0Q1: Quadrupole, L=0.0255, K1:=266.664;
    T0d2: Drift, L:=D1;
    m1: MARKER;
    T0Q2: Quadrupole, L=0.0545, K1:=-265.155;
    m2: MARKER;
    T0Q3: Quadrupole, L=0.039, K1:=268.538;
    T0d4: Drift, L:=0.186-(4*D1)-D2;
    fp: Monitor, L=0;
    T0d5: Drift, L=0.114;




    SELECT, FLAG=TWISS, clear;

    SELECT, FLAG=TWISS, column=name,s,betx,alfx,bety,alfy,Dx,DPx;

    USE, period=BEAMLINE;

    twiss,BETX=bx,BETY=by,ALFX=ax,ALFY=ay,file=TWISSTABLE_1.txt, save;
    plot,haxis=s, vaxis1=BETX,betY, vaxis2=Dx,Dy, Hmin=0, Hmax=0.5,Vmin=0,-1,vmax=50,1,interpolate, colour=100;

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook