This article is accompanied by a sample file which is used to demonstrate some of the powerful uses of the Filter String. The file is available via download from the very last page of the article.
ZEMAX's Non-Sequential ray tracing capabilties can further be extended to finding rays which have specific characteristcs or properties. For example, imagine you are studying the stray light in a telescope:
Each of these, and many similar questions, may be answered conveniently using what are known as Filter Strings in ZEMAX. 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.
It is important to note that filter strings can be used to perform a full Opto-Mechanical assessment of stray light. Therefore, ZEMAX 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 availabe filter string flags and discussion may be found in "The filter string" section of Chapter 12 in the ZEMAX Users's Guide.
In this article, we will demonstrate where filter strings are entered, how they are applied, and how they may be used to analyze rays with certain optical properties. To do so, we will evaluate the amount of "moon" light that gets into the image area of a Cassegrain-type telescope when viewing a distant star. The basic concept? A large number of rays will be traced and saved to a database. We will then "dig" through this ray database to find rays which have explicit properties.
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 barrell), 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 (NS) ZEMAX lens file. Download the file attached to this article and open it from within ZEMAX.
![]() | FILE: "Stray Light_Telescope.ZMX" |


Energy loss due to errors is extremely important, and it is imperative that the magnitude of these errors are made as small as possible. There are several reasons why these errors occur, which are thoroughly discussed in an article entitled How To Locate Geometry Errors.
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 "Analysis > Database > Ray Database Viewer" or by pressing the "Rdb" button on the button bar. In the settings of the Ray Database Viewer, 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" field 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.
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.


.gif)





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 are 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.
Open the Object Properties dialog for Object 3 and place an 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, re-run a NS ray trace and save the rays to a different file name.
Once the ray trace is complete, make sure that the appropriate .ZRD file is selected in the Detector Viewer and apply the same ghost filter, G3. 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.