Automatic iteration to focus a beam.

For a brief description see notes on focussing.

Associated notes are:

There are many different ways in which a focus can be defined and in which it can be optimized, and so the program allows many different options. Several different forms of constraint are also available.

Warning: Be very careful when setting the various limits and constraints and make sure that they have not distorted the results for the size of the focus.

Examples of the use of this option are given in files xmpl2d07, xmpl2d15, xmpl3d06, xmpl3d12, xmpl3d18 and xmpl3d76.

This note deals with:

The 'focus'.

Minimisation.

Voltage information.

Centre of the focus (including a free focus).

Number of rays.

Stopping the iteration.

Minimisation technique.

Safety numbers.

Constraints.

Controlling the amount of output information.

Iteration of the kinetic energy.

Colours of the rays.

The 'focus':

This is the set of crossing points at the beam section defined above (that is, the coordinates of the rays as they cross the first test plane).

The program will adjust the voltages to minimise the size of focus.

The requirements of users vary greatly, and so several different types of focus are available with this program, as described below.

Alternatively, the voltages can be adjusted to maximise the current that falls inside a specified circle, see xmpl3d96.

Minimisation:

There is a choice of 4 options for the size of focus -that is, the quantity this is minimised.

(1) Maximum distance of any of the rays from the centre of the focus

(2) Mean of the distances from the centre (that is, the mean of the magnitudes of the distances)

(3) Root-mean-square of the distances.

(4) Another option for the quality of the focus is:

Maximise the current that falls within a given circle.

The circle lies in the test plane and its centre and radius are specified by the user.

Absolute values of the current are used.

Discontinuities in the maximisation routine can easily occur -for example when a small change in a voltage causes a ray to jump from being just inside the circle to being just outside.  To avoid this a second larger radius is specified and the program uses a linearly graded weighting for rays that lie between the two radii.  Rays that lie outside the second radius are of course given a zero weighting.

Constraints:

Various constraints can be placed on the voltages and the angles (see below).

Voltage information:

Up to 20 different voltages can be varied simultaneously. The user is asked to specify the number N of voltages that are to be adjusted, and then has to specify N times: the number of the voltage (not its starting value, which has already been entered, see note on voltages) and the approximate amount by which the user thinks that it should be varied (but this should not be made too large, or else the rays might not go through the lens system).

The scale factor of the magnetic field (if it exists) can be included for variation. It is treated as a ‘quasi-voltage’ that has the voltage number nvolts+1 where nvolts is the number of real voltages -see xmpl3d76.

If the voltages are related to each other then the variable voltages must all be ‘source voltages’.

Centre of the focus (including a free focus):

There is a choice of 4 options:

(1) The coordinates of the centre of a fixed focus can be specified.

(2) The single ‘free’ focus centre can be requested (and of course there is then no need to specify any coordinates).

The program will put the focus point somewhere on the first test plane, to give the smallest focal spot. This is a powerful option that can be used, for example, to minimise the size of an off-axis image when the magnification of a lens is not known.

Be careful when using the free centre option in the presence of planes of reflection symmetry. In 2D cylindrical symmetry the free focus can be off-axis -that is, it can be a ring (but then the reflection of the rays in the radial direction should be disabled).

(3) More than one fixed focus can be specified (eg each representing rays of different energies). Each focus corresponds to a different set of rays. An example is given in xmpl3d18. All the foci must lie on the first test plane.

(4) More than one free focus can be specified (eg each representing rays of different energies). Each focus corresponds to a different set of rays. All the focal points will lie on the first test plane. This is a very powerful option that can be used, for example, to minimise the sizes of a series of focal spots at the exit of an energy analyser for a series of different input energies.

Number of rays:

Some rays might fail to cross the test plane, for various reasons, and so it is necessary to specify the total number of rays that will be considered. For example, there might be 10 rays being traced, and you might specify that only 8 of these are to be considered. This therefore allows 2 to be disregarded. But what happens if more than 8 cross the test plane? If the centre of the focus has been specified, then the BEST 8 are considered (that is, best in terms of the distance from the specified centre). But if the centre of focus has not been specified, the FIRST 8 to cross the test plane are considered (and this set is then used to define the centre of focus).

Stopping the iteration:

To specify when the iteration should stop, the user is asked to specify a 'tolerance level' (at which the minimisation routine will terminate) and, for safety, the maximum number of iterations. The simplex technique is used for minimisation. The tolerance level refers to the fractional change in the quantity being minimised (be careful not to set this too high, particularly when there is only 1 adjustable voltage). If the routine reaches the maximum number of iterations before it reaches the tolerance level, then the previous best set of voltages is saved.

If the maximum number of iterations. is entered as 0 then only the original voltages will be used to find the size of the focus.

Minimisation technique:

The simplex technique is chosen for the minimisation process because we have found it to be the most dependable for simulations in charged particle optics.

If the approximate position of the minimum is known in advance, then start from this position and make the initial step sizes of the voltages small (the simplex routine will automatically make them larger if necessary).

Note that the simplex technique is efficient at finding a minimum that is in the region of the initial variables, but if there is a deeper minimum that is further away the simplex technique might fail to find it. So if you suspect that there a local minimum has been mistaken for the true minimum, then use larger initial step sizes and a series of different starting positions, always keeping a careful record of the values of the minimum 'focus size' obtained.

If the number of variables is larger than about 4 then try to split them into 2 or more groups. Vary each group separately and iterate between the groups. For example if there are 5 variables, 2 of which are concerned primarily with one aspect and the other 3 with a different aspect, then vary numbers 1 and 2, then 3, 4 and 5, then go back to 1 and 2, etc).

It also helps sometimes to restart the minimisation a few times, using the most recently optimised parameters each time.

Safety numbers:

The user is asked to specify two numbers, a 'maximum distance' and a 'penalty factor', to prevent answers being distorted by rays that are very much out-of-focus. If you do not want to use this facility simply make the 'maximum distance' very large and make the 'penalty factor' 1.0.

If you do want to use the facility then the 'maximum distance' would usually be the radius of an aperture or screen. The minimisation technique would run into difficulties if such rays are completely excluded as soon the maximum distance is reached, and so a 'penalty factor' is applied instead. The penalty is graded. For any ray that has a distance d from the centre that is in the range m_d to 5*m_d, where m_d is the maximum distance, d is multiplied by the penalty factor p_f. For d > m_d, the penalised distance is 5*m_d*p_f.

Constraints:

Two kinds of constraint are available, for voltages and angles respectively.

The user specifies the number of voltage constraints (in the range 0 to 7) and the number of angle constraints (0 or 1).

(1) Voltage constraints:

Without this type of constraint the voltages might change so much that too many rays fail to reach the focus, causing the iterations to stop.

For each voltage constraint the user states whether it is 'lower' or 'upper' -that is, whether the voltage is to be inhibited from going below or above some limit. The user then specifies the number of the voltage and the limit to its value. Finally the user specifies a 'penalty factor', which gives the user some extra control, and which should be given the value 1 if this control is not needed. The penalty factor has the dimensions 'mm per volt'. If the numbered voltage goes outside the specified limit, the excess is multiplied by the penalty factor, and this quantity is added in the minimisation routine to the distance of the ray from the centre of the focus.

A given voltage can be specified more than once, if the user wants to impose increasing levels of constraint on the voltage.

(2) Angle constraints:

An angle constraint is defined by 4 or 5 numbers in CPO2D or CPO3D respectively. The first 2 or 3 of these are the direction cosines (or numbers proportional to them) of the required central direction of the beam at the focus (also see below). The next is a conversion factor 'f' that has the dimension 'mm per radian'. Then comes the limit 'l' in the angle 'u' between the defined direction and the direction of a ray.

The program deals with the angle constraint in the following way. For each ray the angle difference u is calculated. If u is greater than l then the excess (du = u - l) is multiplied by the conversion factor f to convert it to a distance (before June 2007 du was not allowed to be greater than 5l). Finally this distance is added in the minimisation routine to the distance of the ray from the centre of the focus.

Further note on angle constraints: In CPO3D the three ‘direction cosines’ represent x/r, y/r and z/r, where r = sqrt(x*x + y*y + z*z), x = xf - xi etc and the specified direction is that of the vector from (xi,yi,zi) to (xf,yf,zf). These ‘direction cosines’ are therefore signed quantities.

These angle constraints are useful for making a beam as parallel as possible -by using a large value of the conversion factor 'f'.

Controlling the amount of output information:

When the number of iterations is large the user might want to severely limit the information given in the information box on the screen and in the output data file. To limit this information to the barest minimum, the values of the variable voltages and the size of the focus, put the letter 'z' (for 'zero') for the printing level (see note on printing levels).

Including kinetic energy in the iteration:

If the kinetic energy of a particle needs to be one of the adjustable parameters, use a total energy and adjust the voltage of an electrode near the ray starting position.

Colours of the rays:

During an iterative calculation the previous rays are redrawn (for comparison) in green (colour number 2), so this colour should be avoided for the new rays.

(The green rays are redrawn without using the interpolation points.)

For users who are editing or constructing an 'input data file' without the use of the data-builder -that is, pre-processor:

But Manual editing is certainly not recommended -it is a relic from the time when the databuilder was not available All users are strongly encouraged to use the databuilder, which always gives the correct formats and which has many options for which the formats are not described or easily deduced.

Specifying the parameters:

In CPO2D:

To activate this option:

Put the letter ‘i’, ‘m’ or ‘r’ as the next letter in the line that starts with ‘y’ for ‘iterate to focus?’.

‘i’ corresponds to the choice: Maximum distance of any of the rays from the centre of the focus.

‘m’ corresponds to: Mean of the distances from the centre (that is, the mean of the magnitudes of the distances).

‘r’ corresponds to: Root-mean-square of the distances.

Then enter the number of voltages that are to be adjusted by the program (maximum 7).

Then, using a separate line for each of the voltages that are to be varied, enter the number of the voltage (not its starting value, which has already been entered, see note on voltages), and the approximate amount by which you think it should be varied.

To specify the centre of the focus:

(1) If you want to specify the centre of the focus, enter 's' on the next line, followed by the (r,z) or (x,z) coordinates of that focus, all on the same line.

(2) For a single free centre enter 'f' (and of course there is then no need to enter any coordinates).

(3) For more than one fixed focus (eg each representing rays of different energies) put 'S', followed (on the same line) by the number of rays that will be used. Follow this with a series of lines each containing 4 numbers, the first two specifying the range of ray numbers and the last two the specified coordinates of the focus for those rays. For example if there are 6 rays, the first 3 of which should focus at (r,z) = (0.0,1.0) and the last 3 at (0.0,1.05), as in the 'example' file xmpl2d16, then the set of lines would be:

S 6

1 3 0.0 1.0

3 6 0.0 1.05

(4) For more than one free focus (eg each representing rays of different energies) put 'T', followed (on the same line) by the number of rays that will be used. Follow this with a series of lines each containing 2 numbers to specify the range of ray numbers.

In CPO3D:

The parameters of the minimisation procedure are specified on a set of extra lines of data that must be entered AFTER the lines that specify the test planes (for an example of these extra lines, and detailed commentary on them, see the files xmpl3d06.dat and xmpl3d12.dat).

On the first of the extra lines, enter the number of voltages that are to be adjusted by the program (the maximum number is 7).

Then, using a separate line for each of the voltages that are to be varied, enter the number of the voltage (not its starting value, which has already been entered, see note on voltages) and the approximate amount by which you think it should be varied (but do not make this too large, or you might stop the rays from going through the lens system).

Then specify the centre of the focus:

(1) If you want to specify the centre of the focus, enter 's' on the next line, followed by the x, y and z coordinates of that focus, all on the same line.

(2) For a single free centre enter 'f' (and of course there is then no need to enter any coordinates

(3) For more than one fixed focus (eg each representing rays of different energies) put 'S', followed (on the same line) by the number of rays that will be used. Follow this with a series of lines each containing 5 numbers, the first two specifying the range of ray numbers and the last two the specified coordinates x, y and z of the focus for those rays. For example if there are 6 rays, the first 3 of which should focus at (x,y,z) = (0,1,0) and the last 3 at (0,1.05,0), as in the ‘example’ file xmpl3d18, then the set of lines would be:

S 6

1 3 0.0 1.0 0.0

3 6 0.0 1.05 0.0

(4) For more than one free focus (eg each representing rays of different energies) put 'T', followed (on the same line) by the number of rays that will be used. Follow this with a series of lines each containing 2 numbers to specify the range of ray numbers.

In CPO2D and CPO3D:

Enter the total number of rays that will be considered on the next line.

On the next line enter a 'tolerance level' (at which the minimisation routine will terminate) and, for safety, the maximum number of iterations.

The next line should contain 2 numbers, a 'maximum distance' and a 'penalty factor', to prevent answers being distorted by rays that are very much out-of-focus. If you do not want to use this facility simply make the 'maximum distance' very large and make the 'penalty factor' 1.0.

Then enter the number of voltage constraints (in the range 0 to 7) and the number of angle constraints (0 or 1).

Use a separate line for each voltage constraint, and on each of these lines specify 4 parameters. The first of these parameters should be entered in the first 5 spaces, and is either the word 'lower' or 'upper', to specify whether the voltage is to be inhibited from going below or above some limit. The next parameter is the number of the voltage, followed by the limit to its value. The final parameter is a 'penalty factor', which gives the user some extra control, and which should be given the value 1 if this control is not needed. The penalty factor has the dimensions 'mm/100 volts'. If the numbered voltage goes outside the specified limit, the excess is multiplied by the penalty factor, and this quantity is added in the minimisation routine to the distance of the ray from the centre of the focus.

A given voltage can be specified more than once, if the user wants to impose increasing levels of constraint on the voltage.

If there is an angle constraint, enter 4 numbers on the next line. The first 2 of these are the direction cosines (or numbers proportional to them) of the required central direction of the beam at the focus. The next is the limit in the angle between this direction and the direction of a ray. The last number is the 'penalty factor', which has the dimension 'mm/10 degrees' and is used in the same way as the penalty factor for voltages.