Nov 18, 2021

Introduction to stray light analysis

Category: Product News
Introduction to stray light analysis

Stray light analysis is an important validation step for both optical and mechanical assemblies. This blog post demonstrates stray light analysis techniques using the Filter String functionality in Non-Sequential Mode, as well as other important features.


When performing stray light analysis, optical designers may ask the following:

  • How significant are rays that ghost reflect off various optical or mechanical surfaces?

  • How much energy do rays that reflect more than four times carry through the system?

  • How effective is a baffle in limiting the stray light on the detector?

Each of these, and many more, may be answered using Filter Strings in OpticStudio. 

In this article, we will demonstrate how to use Filter Strings to analyze and characterize rays with specific optical properties by evaluating the amount of moonlight that contaminates the detector of a Cassegrain-type telescope when viewing a distant star. 

What are Filter Strings?

Filter Strings are a means of defining a specific test that each ray must pass before it is displayed (on the Layouts or Detector Viewer) or reported in the Ray Database Viewer. Filter Strings can be used to perform a full Opto-Mechanical assessment of stray light, as OpticStudio will consider partial reflections from optics, reflections from mechanical components, and scattering from both optics and mechanics. 

The Filter String syntax consists of logical operations between flags that indicate if one segment within a ray hit, missed, reflected, refracted, scattered, diffracted, or ghost reflected from an object within an NSC group. A complete listing of the available Filter String flags and discussion may be found in "The Filter String" section of the OpticStudio Help File.

System outline and initial ray trace

Imagine viewing a star with a telescope during a full moon. Some of the light from the moon, though off-axis (where the axis is described as the distance from the star to the vertex of the telescope barrel), reaches the detector plane (camera) of the telescope. We need to determine exactly how much stray light from the moon is reaching the detector.

This scenario is simulated using the following purely non-sequential OpticStudio lens file.

Note: For the purposes of demonstrating Filter Strings in OpticStudio, it is assumed that you are familiar with the standard procedure of performing a Non-Sequential Ray Trace and viewing the results on the Detector Viewer. If you are unfamiliar with these concepts, please refer to the article on "How to create a simple non-sequential system".

Non-Sequential Ray Trace

The moon in the telescope model is represented by an off-axis Source Ellipse. The moon is approximated as a collimated source, so rays from the moon (in green above) are parallel to one another. Similarly, the object of interest is represented by an on-axis collimated Source Ellipse. As in a typical Cassegrain-like telescope design, collimated rays (the blue rays in the layout above) from an on-axis field focus to a well-corrected spot at the image plane. However, some of the rays (from both the moon and the star) do not follow the desired sequence of optical surfaces, yet still reach the detector.

An initial non-sequential ray trace can be performed with Use Polarization, Ignore Errors, Split Rays, Scatter Rays, and Save Rays all checked. Note that rays must be saved first before Filter Strings can be applied to the Ray Database and Detector Viewers! For the time being, we will leave the "Filter" entry blank since filters may also be applied later on in the settings of individual analysis features.

An initial non-sequential ray trace can be performed with Use Polarization, Ignore Errors, Split Rays, Scatter Rays, and Save Rays all checked.

The "Lost Energy" values due to thresholds and errors are very important and should be reviewed with great care to ensure accurate evaluation of the current ray sample. If a ray falls below the minimum energy threshold for tracing, the ray will be terminated. The minimum relative and absolute energy thresholds are defined by the "Minimum Relative Ray Intensity" and "Minimum Absolute Ray Intensity" entries under the non-Sequential tab of the System General dialog. To reduce the calculation times in the current example, the Minimum Relative Ray Intensity is set to 1.00E-007. This value may need to be reduced in some applications to limit the lost energy due to thresholds.

Filter for error rays

Energy loss due to errors is extremely important, and it is imperative that the magnitude of these errors is made as small as possible. There are several reasons why these errors occur, which are thoroughly discussed in a series of articles that begin with How to locate geometry errors (part 1)

If the reported energy loss due to errors is significant, it is sometimes useful to review the propagation of the ray in great detail to locate the probable cause of error. This can be done via Filter Strings in the Ray Database Viewer. The Ray Database Viewer may be opened by selecting Analyze Ribbon...Database...Ray Database Viewer. In the settings of the Ray Database Viewer, we select the previously saved database file from the File pull down menu. Now, the Ray Database settings allow the option to apply a filter. The Filter String, Z, will only display those rays which have fatal errors. To apply this Filter String, first check the Apply Filter box and type the string into the appropriate entry.

The filter may be applied to a small portion of the saved database by adjusting the First Ray and Last Ray fields appropriately. Or, alternatively, the entire database may be processed if the Last Ray is set to the total number of rays launched in the initial ray trace (or, you can simply enter a negative value, such as -1, in the Last Ray field).

OpticStudio Ray Database Viewer

In this example, the energy loss due to errors was zero, so not a single ray is displayed in the Ray Database Viewer once the error filter is applied. However, the filter capability in the Ray Database Viewer is not limited to displaying rays with errors. Any single filter, or any combination of filters, may be applied to the saved ray database; only those rays which pass the test will be displayed for more in-depth analysis.

Stray light from the moon

From the Detector Viewer, it is clearly visible that the majority of the energy is at the centermost pixels of the detector. However, even on a log scale, it is very difficult to discern how much total power is associated with the rays which fall outside this central region. What portion of this energy is stray light from the moon source?

Detector Viewer

To determine the fraction of total power, which is associated with the moonlight, let's first isolate the rays from the moon. To do so, we may set the # Analysis Rays for Source Object 1 to zero and re-run the ray trace, or we can utilize the Filter String to only display those rays which originated from a specific source. For the purposes of demonstrating the effectiveness of the Filter Strings and to save us from having to run a new ray trace, we will choose the latter.

Filter Strings may be applied to 3D Layouts, Detector Viewers, and (as we have already seen) within the Ray Database Viewer. Within the settings of each of these analysis tools, the desired Filter String may be typed into the Filter entry. We may further demonstrate some of these capabilities using the current example file.

Within the settings of the Detector Viewer, select the previously saved ZRD file from the Ray Database pull down menu. Once the desired Ray Database is selected, the Filter entry becomes enabled. 

The "On" Filter String flag will filter the database for only those rays which originated from source number n. Since we wish to only display those rays which originate from the moon (Source Object 2), the Filter String "O2" can be applied. 

The "On" Filter String flag will filter the database for only those rays which originated from source number n. Since we wish to only display those rays which originate from the moon (Source Object 2), the Filter String "O2" can be applied. .

Depending upon the size of the saved ray database and the complexity of the string, it may take OpticStudio some time to process the data. Once complete, the Detector Viewer should show the filtered ray data. 

Note that the data in the bottom portion of the Detector Viewer displays both the chosen ray database file and the Filter String applied. Therefore, the settings need not be re-opened to verify which filter has been applied to the data you are viewing.

Filtered Detector Viewer

From the filtered Detector Viewer in the present example, the "hot spot" is no longer present, which was undoubtedly the image of the star (rays originating from Source 1).

For the current ray trace, roughly 8.531E-006 Watts of the Moon's initial total power reaches the camera. But, as the moon is much brighter than the star, 10-5 rejection against stray moonlight may be inadequate, so it may be desirable to reduce the amount of stray moonlight to achieve better resolution of the image of the star. There are many methods which could be used in attempt to reduce the stray light from the moon. However, these topics go beyond the scope of this article, and will not be covered: we will concentrate on identifying the sources of the stray light in this article.

Map the stray moonlight: Layout analysis

With the filter in place, not only is it easy to determine how much light from the moon is reaching the detector, but we may also utilize this filter visually recognize whether or not rays come from a preferential "region" of the moon. That is, we can determine if stray light rays come from a specific region of the moon.

Detector Object 11, as you might imagine, is not well suited to answer this question. However, as was mentioned earlier, Filter Strings may also be applied to Layouts. In the current example, open the settings of the NSC 3D Layout, and once again select the previously saved ZRD file from the Ray Database pull down menu. Displaying the entire ray database on the layout would become too crowded to perform any substantial analysis, so we will apply an appropriate filter in a moment. 

It is important to note that Filter String flags may be used alone, or they may be combined using logical operands. Some of the more common logical operands include: "&" (Logical AND), "|" (Logical OR), "^" (Exclusive OR), and "!" (Logical NOT). This is extremely useful when filtering for rays with multiple specific properties. 

To demonstrate, let's filter for rays which still originate from the moon AND which reach the camera. Note that although the second portion of the string was not necessary when viewing the results from the Detector Viewer, we must explicitly add this flag to the string in the layout. Otherwise, all rays from the moon will be displayed, whether they reach the detector or not. To represent the second argument, the "Hn" flag may be used. The "Hn" flag represents rays which hit object n.

Filter String flags may be used alone, or they may be combined using logical operands. Some of the more common logical operands include: "&" (Logical AND), "|" (Logical OR), "^" (Exclusive OR), and "!" (Logical NOT). This is extremely useful when filtering for rays with multiple specific properties.

The filtered NSC 3D Layout in this case does not really indicate that rays come from a preferential region of the moon. As expected, rays within the center region of the Source Ellipse do not make it to the detector since they are blocked by the secondary mirror and the baffle surrounding this secondary. Since the number of rays which pass the filter condition is so large, and since OpticStudio must re-evaluate the filter each time the plot is rotated, it is difficult to glean any productive, additional information from the layout in the current sample file. Nevertheless, this methodology can certainly prove to be useful in other circumstances.

Filtered NSC 3D Layout

Map the stray moonlight: Detector analysis

Though we were not very successful in determining if rays came from specific regions of the moon via the Layout, another strategically placed Detector Rectangle could prove to be more useful. We can insert an additional Detector Rectangle in the NSC Editor  with the following parameters.

Y Position  1.0
Z Position -9.0
Tilt About X 5.0
X Half Width 6.1
Y Half Width 6.1
# X Pixels 50
# Y Pixels 50

This Detector Rectangle is placed directly in front of the moon. This way, using the Filter String capabilities once again, we can better visualize the distribution of those rays which originate from the moon and hit the camera. Once the new Detector Rectangle is defined we can open a new Detector Viewer to view the results of future ray traces. 

If we perform a new ray trace and save the rays to a new database name, such as "Stray Light_Telescope_1A.ZRD," we can see the initial ray distribution on the newly defined detector.

Since no current filter is applied, the irradiance distribution on this detector includes rays from both sources. Again, we are only concerned with rays which originate from the moon AND reach the detector. Therefore, let's apply the following filter to Detector Object 12.

Once the filtered data is processed and displayed, it is much easier to observe the distribution of rays from the moon which actually reach the detector plane. It is apparent that undesired, stray rays at the detector plane, do indeed originate from "preferential" regions of the moon. These regions are highlighted in the Detector Viewer below. This information may be useful in determining which of the various stray light reduction techniques could be used to reduce the undesired light from the moon.

Evaluating reflections from the first corrector lens

As you may recall from the initial ray trace, a definitive, rotationally symmetric ring surrounded the hot spot of the detector.

It is possible that this ring of rays is due to multiple reflections off of the currently uncoated, FIRST CORRECTOR lens (Object 3). To confirm this, we may again use the Filter String capabilities. 

(Q3) How are stray rays caused by multiple reflection in the first reflector affecting the total power at the camera?

The flag "Gn" refers to rays which are ghost reflected from parent segment's object n. This flag only gets set for ray segments reflected from refractive objects when ray splitting is activated. Let's observe the ray distribution at the camera from those rays (from both the star and the moon) which have ghost reflected from the first correcting lens.

The "ring" of rays is undoubtedly due to ghost reflections from the corrector lens, and accounts for a small, but measurable fraction (5.780E-006) of the total power on the detector plane. To reduce the significance of these undesired rays on the camera, we may coat the corrector lens with an anti-reflective coating. 

Reducing effects of ghost reflections with anti-reflective coatings

In the Object Properties dialog for Object 3 we place an anti-reflective (AR) coating on both the front and back faces of the corrector. This is a single-layer MgF2 coatings optimized for the current primary wavelength.

When the coatings have been applied, we re-run a non-sequential ray trace and save the rays to a different file name.

Once the ray trace is complete, the appropriate ZRD file is selected in the Detector Viewer and the same ghost filter, G3, applied. By coating the corrector lens, we have effectively eliminated the spurious "ring" of rays and reduced the total "ghosted" energy by an order of magnitude.

To learn more, check out our webinar: Methods of Stray Light Analysis in OpticStudio – Zemax and the series of stray light articles on our Knowledgebase Introduction to stray light analysis - Part 1 – Knowledgebase (

To try out Zemax capabilities please download a free trial here.

Michael Cheng
Principal Optical Engineer
Zemax An Ansys Company

Yihua Hsiao
Optical Engineer
Zemax An Ansys Company