OPERATION SOFTWARE FOR COMMISSIONING OFKEKB LINAC PROGRAMMED WITH SAD
N. Akasaka, H. Koiso, and K. OideKEK, High Energy Accelerator Research Organization, 1-1 Oho, Ibaraki 305, JAPAN
Abstract
SAD was originally developed for accelerator design. In
order to use it as a language for KEKB operation software,
Python interpreter and EPICS channel access interface
were embedded into it. Tkinter, which encapsulates Tcl/Tkin Python, provides graphical user interface (GUI).
Hardware instruments are accessed through EPICS channel
access routine. In this paper, some of practical tools usedin the commissioning of KEKB linac are presented.
1INTRODUCTION

SAD (Strategic Accelerator Design) started as a code foraccelerator design at KEK in 1986[1]. Its functionality has
been increasing since then, which includes: optics
matching, particle tracking, Taylor map, spin calculation,
Mathematica-style functions, EPICS channel accessfunctions and Tcl/Tk[2] interface via Python[3]. Amongthese, the last three are important for accelerator control:
Mathematica-style function for programming control
logic, EPICS channel access for controlling hardware, andTcl/Tk interface for GUI. Currently, hardware in KEKB
linac is accessed by executing shell commands within
SAD, since EPICS is not introduced there yet.
Merits of using SAD for accelerator control are:1) Unification of model/control/GUI in a single script.
A large accelerator such as KEKB requires tight
relationship between a computer model andobservation/control of the beam. SAD ensures direct
relationship between them, so that an accelerator
physicist or an operator can write a necessary software
only with SAD.
2) Immediate and powerful execution of a program.
SAD is an interpreter language and easy to learn/try
programming. Mathematica-style functions for listmanipulation, functional operations, symbolic andnumerical math, etc., make a program very compact
and highly structured.
3) Libraries with object-oriented features.
Although SAD is not a fully object-oriented language,
it still has some of object-oriented features in its
libraries. For instance, a beam line is identified as an
BeamLine object, which accepts many functions suchas Join, Delete, Insert, Times, etc.
Considering the fact that most commissioning tasks needan accelerator model, we choose SAD as the most suitable
tool for the commissioning of KEKB according to thefirst merit stated above. Although implementing
accelerator modeling capability of SAD in other interpreter

languages such as Java, Python, Tcl/Tk, Mathematicaetc., might have some possibility, it would requiresignificant time and effort, and we do not think there isenough reason to do that within the very limited time
before the commissioning of KEKB. Even when noaccelerator model is necessary, SAD does not fall behindwith these interpreter languages.
2ACCELERATOR MODEL

SAD has many functions which are related to accelerator
models. Only a small part of them is introduced in thischapter.
2.1 Definition of the beam line
A beam line is defined in SAD as a series of components
like drift space, magnets from 2-pole (bend) to 220-pole,solenoids, and accelerating cavities etc. Magnets andaccelerating cavities can be spatially overlapped.
Alignment errors (offsets and rotations), fringe field formagnets, position dependence of accelerating voltage foraccelerating cavities, can be assigned if necessary.
BeamLine[], which takes beam line components as itsarguments, creates a beam line object, andExtractBeamLine[] returns the current line objects or abeam line object specified by its argument.
2.1 Optics-related functions
CALCULATE command calculates the optics using thecurrent values of the components. SAD accepts this typeof non-Mathematica-style commands. These are rather
historical, but very convenient for interactive use.
Twiss[] function returns the value of calculated optical
functions (αx, βx, etc.) at the entrance of a component. GO
command executes optical matching. The matchingconditions can be imposed on both geometry and optical
functions by FIT, FIX, and FREE commands.
2.2 Plotting functions
OpticsPlot[] function creates a plot of calculated optical
functions or any given list of values. The abscissa is thedistance in the beam line measured from its entrance. A
schematic beam line is automatically drawn below theplot. This drawing can be used for selecting components
by binding events to them. When the data is given as alist, it is a nested list of the position or component namein the lattice and the value in the form like:{{SPA1B8, 0},{SPA1C5, 0},.....}.

Application (SAD)
Tkinter.n (SAD)
SAD (Fortran & C)
Tk Widgets (C & Tcl)

Fig. 3 KBFrame before application-specific components
are placed.

Tk (C)
Xlib (C)Fig. 1 Levels of graphics processing in SAD.

w = KBMainFrame[”Ex1”,f,Title->”Example 1”];

Tcl/Tk is one of the most widely used toolkits forbuilding GUI. One can easily place common user interface
components like buttons or text entries and customize
their behavior for the application. Applications can send
SAD expressions to another application on the same Xserver and receive their result. This is realized by directly
calling Xlib functions instead of using send command ofTk, which only sends Tcl commands.

A frame is created with the name f , which is used forarranging application-specific components in it. The
downward arrow on the right of the menu bar is the taskmenu, with which one can switch between SAD
applications running on the same X-server.
KBFrame provides convenience functions that
arrange components without explicit use of geometry
managers. This function assumes fixed parameter values
for geometry management so that the user doesn’t have tocare about it at the expense of some of the flexibility ofTcl/Tk ‘pack’ geometry manager. The components can bearranged in the main application window or in a dialog
box created for them.
KBFrame is used in the applications presented
below.

3.2 Programming style

4.2 Klystron status

In the case of creating a button in a new window, theSAD script would be as follows:

Figure 4 is the panel for displaying klystron status in AC sectors of the linac. When one or more klystrons aretripped, it brings itself on top of the other windows and(optionally) warns the operator with synthesized voice.
The voice is generated on a Macintosh with text-tospeech, which reads input strings aloud. UDP packets areused for the communication between SAD and theMacintosh.

3GRAPHICAL PROGRAMMINGSAD outputs graphics on an X-window server. Figure 1
shows the levels of graphics processing.
3.1 Tcl/Tkw = Window[];b = Button[w,Text->“Hello”,Command:>Print[“Hello, World!”]];The result is shown in Fig. 2. The first line creates awindow and the next 3 lines create a button whose label is“Hello”. The first argument of Button[] is the parent ofthe button. The button is automatically packed in theparent window w . The attributes of the button, Text andCommand in this case, are passed as (delayed) rules. When
this button is clicked, it executes the SAD function
Print[“Hello, World!”] and prints “Hello, World!” on
the console. Any SAD function can be specified for
Command attribute.

Fig. 4 Klystron status display.
Fig. 2 Hello World example in SAD.
4EXAMPLES

4.1 KBFrameKBFrame is written to provide a default main window
with a menu bar, status line, progress bar, etc. The code
below creates a window shown in Fig. 3:

4.3 BPM display
Figure 5 shows the BPM monitoring panel. This is an
example which uses an accelerator model in SAD. The
displayed data from top to bottom are horizontal beam
position, horizontal steering strength, vertical beam
position, vertical steering strength, and bunch current. The
plots and the accelerator line below is drawn byOpticsPlot[]. The value of BPM reading can bedisplayed by clicking on the corresponding data point inthe plot.
4.4 Optics matching and emittance measurement

not explained above, which include: ColumnPlot[] (bargraph), FitPlot[] (fit arbitrary function to given data andplot the result), and ListPlot3D[].

Twiss parameters and emittance can be measured from thebeam sizes with different strength of a Q-magnet. The
panel in Fig. 6 shows the result of fitting of the measured
data. Calculated twiss parameters and emittance aredisplayed at the top of the panel. The measurement
conditions (changed Q and observed screen) are specified inanother panel by selecting components in the schematic
beam line drawn by OpticsPlot[].

Fig. 7 Orbit history panel.
5ACKNOWLEDGMENT

The authors wish to thank N. Yamamoto for initial
implementation of EPICS channel access and Tcl/Tk inSAD, K. Furukawa and N. Kamikubota for preparing
shell commands to access hardware, and KEKB linac
commissioning group for cooperation.

Fig. 6 Emittance calculation panel.
4.5 Orbit history

6Figure 7 is a display of the fluctuation of BPM readings.
The deviation from the time-average of each BPM readingis plotted as a function of time. If BPM readings don’tchange at all, the displayed plot becomes a perfectly flatplane. This plot is created by a 3D plotting function
ListBirdsEyePlot[]. SAD has other plotting functions

REFERENCES[1] http://www-acc-theory.kek.jp/SAD/sad.html.
[2] “Practical Programming in Tcl and Tk”, Brent Welch,Prentice Hall.

Fig. 5 BPM display.