This concept will first be illustrated by an example. All the quadrupoles in the accelerator form a class QUADRUPOLE. Let us define three subclasses for the focussing quadrupoles, the defocussing quadrupoles, and the skewed quadrupoles:
MQF:QUADRUPOLE,L=LQM,K1=KQD; // Focusing quadrupoles MQD:QUADRUPOLE,L=LQM,K1=KQF; // Defocusing quadrupoles MQT:QUADRUPOLE,L=LQT; // Skewed quadrupolesThese classes can be thought of as new keywords which define elements with specified default attributes. We now use them to define the real quadrupoles:
QD1:MQD; // Defocusing quadrupoles QD2:MQD; QD3:MQD; ... QF1:MQF; // Focusing quadrupoles QF2:MQF; QF3:MQF; ... QT1:MQT,K1S=KQT1; // Skewed quadrupoles QT2:MQT,K1S=KQT2; ...These quadrupoles inherit all unspecified attributes from their class. In this way, the user can build up a hierarchy of objects with a rather economic input structure.
The full power of the class concept is revealed when object classes are used to select instances of elements for printing. Example:
SELECT,CLASS=QUADRUPOLE; // Select all quadrupoles PRINT,CLASS=MQT; // Select skewed quadrupoles
More formally, for each element keyword MAD maintains a class of elements with the same name. A defined element becomes itself a class which can be used to define new objects, which will become members of this class. A new object inherits all attributes from its class; but its definition may override some of those values by new ones. All class and object names can be used in range selections, providing a powerful mechanism to specify positions for matching constraints and printing.
When an object is used in a beam line, MAD automatically makes a copy of that element, unless the object is defined as SHARED. The user can later attach imperfections to all copies individually. Example:
QF:QUADRUPOLE,...; // Define the class QF L:LINE=(...,QF,...,QF,...) // Each QF is distinct QF1:QF,...; // QF1 is derived from QF
On the contrary, if an object is defined as shared using the keyword SHARED, its use in more than one beam line implies the same object occurs in all those beam lines. Example:
SHARED QF:QUADRUPOLE,...; // Define shared quadrupole QF L1:LINE=(...,QF,...,QF,...) // All the QF's are the same ... L2:LINE=(...,QF,...) // ... also in this line.