Ray paths in a non-sequential system can be very complex, especially when ray splitting is allowed. In many cases, it can be useful to limit the ray paths that are observed either in the Layout plot or on the Detector Viewer.
When ZEMAX traces a ray, it records exactly what happens to that ray. For example, the ray may reflect from object 13, split into two at object 46, etc. Filter strings allow you to identify specific characteristics of the rays that you want to see.
ZEMAX offers many filter strings that can be used to provide limitations on ray paths - either during the ray trace itself, or when viewing the results in the Layout plot or Detector Viewer - and supports the ability to combine filter strings using logical operands. More information may be found in section of the ZEMAX manual entitled “The filter string”, located in the chapter of the manual entitled “Non-Sequential Components”.
In this article, a few examples will be provided to illustrate the use of logical operands in constructing filter strings for isolating specific rays.
A simple example of a system where a filter string may be useful to “clean up” the Layout plot is provided in the file “Simple Example.ZMX”. The archive (.ZAR) file for this example is located on the last page of this article.
In this system, a Source Ray object is used to launch rays at a block of BK7 glass. The spectrum of the source is polychromatic, as defined by the three system wavelengths provided in the Wavelength Data dialog box:
The back face of the BK7 glass is specified to be a scattering surface, in which rays scatter according to a Lambertian distribution:
The Scatter Fraction parameter has been set to 0.5, indicating the 50% of the incident energy will be scattered. Ray splitting is also included in this system, so scattering can occur both in transmission and reflection. As a result, the Layout plot for this system is quite messy:
What if we were only interested in seeing those rays that do not have a wavelength of 0.55 microns and that undergo scattering only once before hitting the detector? We can easily create a filter string that will limit the Layout plot to just those rays.
Filter strings that can be used to isolate scattered rays are Sn, Fn, and X_SCATTER(n,b). The Sn and Fn filter strings allow you to target for rays that have scattered from a particular object, while the X_SCATTER(n,b) filter string targets those rays that have scattered "b" times and have hit object "n" (see the section entitled "The filter string" in the chapter of the ZEMAX manual entitled "Non-Sequential Components"). In our example, we are only interested in those rays that scatter once and then hit the detector, so the appropriate filter string would be X_SCATTER(3,1).
In this system, rays that scatter once may also scatter in reflection. Some of these rays may subsequently be reflected off of the front face of the BK7 glass, and then transmit through the back face of the glass and hit the detector. These rays are said to undergo ghost reflection at the front face of the glass, and can therefore be identified using the Gn filter string. In this case, we do not want to see any rays on the detector that have undergone ghost reflection, so the appropriate filter string would be G0 (this will isolate not only the first order ghost reflections described above, but higher order ghost reflections as well, e.g. when a ray reflects off of the front and back faces multiple times before finally passing through the back face and hitting the detector).
Finally, we also want to limit the rays shown in the Layout plot to those that do not have a wavelength of 0.55 microns. In this case, the Wn filter string can be used to filter for wavelength, since the ray wavelengths are defined explicitly in the Wavelength Data dialog box. The appropriate filter string for isolating rays at a wavelength of 0.55 microns is W2, since this wavelength corresponds to wavelength number 2 in the Wavelength Data dialog box.
We can combine the above filter strings together using the “&” and “!” logical operands to form the desired filter:
which will isolate those rays of interest in the Layout plot:
Conversely, imagine now that we were interested in seeing only those rays that have a wavelength of 0.55 microns and that do not ever undergo scattering. In this case, we could use the same filter string to isolate those rays with a wavelength of 0.55 microns, and remove the “!” logical operand from in front of the filter string. To filter for those rays that do not undergo scattering, we would use the filter string F2, and place the “!” logical operand in front of it. Combining these together using the “&” logical operand:
we find exactly what we expect:
The reason that the Fn filter string is used in this case is because ray splitting is on. With ray splitting on, it is very likely that some segment of every ray will undergo scattering (even if that segment was generated after a number of Fresnel reflections in the glass). Thus, the Fn filter string must be used to target segments from a ray that undergo scattering (Sn can only be used to target the ray itself, not any segments of the ray), in this case to isolate those segments out of the Layout plot.
Another example of the use of filter strings is provided in the file “Diffraction Grating.ZMX” (the archive file for this example is located on the last page of this article). In this system, the source spectrum has been defined to model the white color seen on computer monitors:
More details on source color modeling may be found in the article entitled “How to Model Colored and Tristimulus Sources”. As indicated in that article, the wavelength spectrum associated with this source can be seen in the Prescription Data Report:
Light from this source passes through a Diffraction Grating object, which is used to disperse as well as focus the light:
The true color results for this system are then observed using the Detector Color object (for more details, see the article entitled “How to Measure and Optimize Color Data”):
Light from the different wavelengths hits the Detector Color object at similar angles, so when we look at the results in angle space we see the color mix back together to form white in the regions of overlap:
We can see how the resulting color changes as we isolate different wavelengths in the system. For example, let's only consider those rays at a wavelength of either 0.49 or 0.565 microns. In this case, the Wn filter string cannot be used to isolate these rays, because the ray wavelengths are not defined explicitly in the Wavelength Data dialog box. These rays can be isolated, however, using the X_WAVERANGE(n,a,b) filter string. This filter string targets those rays that have hit object "n", and have a wavelength (in microns) between "a" and "b" (see the section entitled "The filter string" in the chapter of the ZEMAX manual entitled "Non-Sequential Components").
The appropriate filter string to use for this example is: “X_WAVERANGE(3,0.48,0.50) | X_WAVERANGE(3,0.56,0.57)” (i.e. the logical operand to use in this case is “|”). The exact values to use in each filter string for the wavelength bounds are not important, as long as the bounds only encompass the wavelength of interest. Applying this filter string to our system, we find:
There are only two colors that contribute to the mixing in this case, generating a green color as a result.
A slightly more complicated system is provided in the sample file “Bulk Scattering.ZMX” (the archive file for this example is located on the last page of this article). In this system, a collimated beam of light at 0.55 microns scatters off of a fold mirror and then passes through a lens. However, the size of the lens is smaller than the size of the scattered beam, so some of the scattered light does not pass through the lens:
Light that does pass through the lens will undergo bulk scattering, and all of the rays that do scatter will also fluoresce, i.e. their wavelength will be changed from 0.55 to 0.65 microns:
You may read more about the wavelength-shifting capabilities of ZEMAX in the article entitled “How to Model Fluorescence using Bulk Scattering”.
Rays that do and do not pass through the lens are recorded by a Detector Color object (more details are provided in the article entitled “How to Measure and Optimize Color Data"). The true color image of the ray distribution shows both the scattered light at 0.55 microns (green) and the fluorescent light at 0.65 microns (red):
There will be some small percentage of rays that do pass through the lens but do not undergo bulk scattering. They can be isolated using the filter string “!X_WAVESHIFT(1,2) & H3” (X_WAVESHIFT(a,b) filters for those rays that shift from wavelength "a" to "b" during bulk scattering, where "a" and "b" correspond to wave number in the Wavelength Data dialog box; see the section entitled "The filter string" in the chapter of the ZEMAX manual entitled "Non-Sequential Components"):

The filter string “X_WAVERANGE(4,0.54,0.56) & H3” could also have been used to yield the same result. If we wanted to eliminate these rays from the detector results, we would use the following filter string: “(X_WAVERANGE(4,0.64,0.66) & H3) | !H3”:
The first term in parentheses looks for those rays that bulk scattered in the lens, and the second term (“!H3”) looks for those rays that do not pass through the lens. Although the results with this filter look similar to the original results:
if you look closely you will see that the total power has been reduced from 258.3 Lumens to 257 Lumens. This reduction of 1.3 Lumens is consistent with the power of those rays that pass through the lens but do not scatter (the numbers may be different if you re-run a ray trace on your computer, but the result will be the same).