|
|
|
|||
|
About McXtrace Documentation |
6.3 Writing instrument definitionsThe purpose of the instrument definition file is to specify a sequence of components, along with their position and parameters, which together make up a beamline. Each component is given its own local coordinate system, the position and orientation of which may be specified by its translation and rotation relative to another component. Examples of instrument definitions can be found in the example directory of your McXtrace installation. Further examples may be found as they are built on the McXtrace web-page [Mcx]. As a summary, the usual grammar for instrument descriptions is
DEFINE INSTRUMENT name(parameters)
DECLARE C_code
INITIALIZE C_code {NEXUS}
TRACE components
{FINALLY C_code}
END
6.3.1 The instrument definition head
This marks the beginning of the definition. It also gives the name of the instrument and the list of instrument parameters. Instrument parameters describe the configuration of the instrument, and usually correspond to setting parameters of the components, see section 6.5. A motor position is a typical example of an instrument parameter. The input parameters of the instrument constitute the input that the user (or possibly a front-end program) must supply when the generated simulation is started. By default, the parameters will be floating point numbers, and will have the C type
Here
Here Optional parameters can greatly increase the convenience for users of instruments for which
some parameters are seldom changed or of unclear significance to the user. Also, if all
instrument parameters have default values, then the simple command 6.3.2 The DECLARE section
This gives C declarations that may be referred to in the rest of the instrument definition. A
typical use is to declare global variables or small functions that are used elsewhere in the
instrument. The 6.3.3 The INITIALIZE section
This section contains code that is executed once when the simulation starts. This section is optional. Instrument setting parameters may be modified in this section (e.g. doing tests or automatic settings). 6.3.4 The NEXUS extensionTo use the NeXus format [Nex] the simulation must be linked with the HDF5 library, which
must have been pre-installed. Preferrably, McXtrace should have been installed with the
The default NeXus format is NeXus 5 with compression. However, that format may
be changed with the optional keyword
It is possible to set the type of NeXus file with a string argument, containing words ”4”, ”5”
or ”XML”. Optionally, if the string also contains the You may choose the name of the output file with the Then, the output format is chosen as usual with the 6.3.5 The TRACE sectionAs a summary, the usual grammar for component instances within the instrument TRACE section is
COMPONENT name = comp(parameters)
AT (...) [RELATIVE [reference|PREVIOUS] | ABSOLUTE]
{ROTATED {RELATIVE [reference|PREVIOUS] | ABSOLUTE} }
The TRACE keyword starts a section giving the list of components that constitute the instrument. Components are declared like this:
This declares a component named name that is an instance of the component definition named comp. The parameter list gives the setting and definition parameters for the component. The expressions \(e_1, e_2, \ldots \) define the values of the parameters. For setting parameters arbitrary ANSI-C expressions may be used, while for definition parameters only constant numbers, strings, names of instrument parameters, or names of C identifiers are allowed (see section 6.5.1 for details of the difference between definition and setting parameters). To assign the value of a general expression to a definition parameter, it is necessary to declare a variable in the DECLARE section, assign the value to the variable in the INITIALIZE section, and use the variable as the value for the parameter. The McXtrace program takes care to rename parameters appropriately in the output so that no conflicts occur between different component definitions or between component and instrument definitions. It is thus possible (and common) to use a component definition multiple times in an instrument description. Be aware of the C variable type conversions when setting numerical parameter values, as in
The McXtrace compiler will automatically search for a file containing a definition of the
component if it has not been declared previously. The definition is searched for in a file called
“name.comp”. See section 5.2.2 for details on which directories are searched. This facility is
often used to refer to existing component definitions in standard component libraries. It is also
possible to write component definitions in the main file before the instrument definitions, or to
explicitly read definitions from other files using The physical position of a component is specified using an AT modifier following the component declaration:
This places the component at position \((x,y,z)\) in the coordinate system of the previously declared component name. Placement may also be absolute (not relative to any component) by writing
Any C expression may be used for \(x\), \(y\), and \(z\). The AT modifier is required. Rotation is achieved similarly by writing
This will result in a coordinate system that is rotated first the angle \(\phi _x\) (in degrees) around the \(x\) axis, then \(\phi _y\) around the \(y\) axis, and finally \(\phi _z\) around the \(z\) axis. Rotation may also be specified using ABSOLUTE rather than RELATIVE. If no rotation is specified, the default is \((0,0,0)\) using the same relative or absolute specification used in the AT modifier. We recommend to apply all rotations of an instrument description on Arm class components only, acting as goniometers, and position the optics on top of these. This usually makes it much easier to orient pieces of the beamline, and avoid positioning errors. The position of a component is actually the origin of its local coordinate system. Usually, this is used as the input window position (e.g. for guide-like components), or the center position for cylindrical/spherical components. The PREVIOUS keyword is a generic name to refer to the previous component in the simulation. Moreover, the PREVIOUS(n) keyword will refer to the \(n\)-th previous component, starting from the current component, so that PREVIOUS is equivalent to PREVIOUS(1). This keyword should be used after the RELATIVE keyword, but not for the first component instance of the instrument description.
Invalid PREVIOUS references will be assumed to be absolute placement. The order and position of components in the TRACE section does not allow components to overlap, except for particular cases (see the GROUP keyword below). Indeed, many components of the McXtrace library start by propagating the x-ray event to the begining of the component itself. If the corresponding propagation length is found to be negative (i.e. the x-ray is already after or aside the component, and has thus passed the ’active’ position), the x-ray event is ABSORBed, resulting in a zero intensity and event counts after a given position. The number of such removed x-rays is indicated at the end of the simulation. Getting such warning messages may be an indication that either some components overlap, or some x-rays are getting outside of the simulation, for instance this usually happens after a monochromator, as the non-reflected beam is indeed lost. A special warning appears when no x-ray has reached some part of the simulation. This is usually the sign of either overlapping components or a very low intensity. For experienced users, we recommend as well the usage of the WHEN and EXTEND keywords, as well as other syntax extensions presented in section 6.4.2 below. 6.3.6 The SAVE section
This gives code that will be executed when the simulation is requested to save data, for instance
when receiving a USR2 signal (on Unix systems), or using the 6.3.7 The FINALLY section
This gives code that will be executed when the simulation has ended. When existing, the SAVE section is first executed. The FINALLY section is optional. A simulation may be requested to end before all x-rays have been traced when recieving a TERM or INT signal (on Unix systems), or with Control-C, causing code in FINALLY to be evaluated. 6.3.8 The end of the instrument definitionThe end of the instrument definition must be explicitly marked using the keyword
|
||||
| |||||