Export total power value from objects as a detector

  • 19 September 2022
  • 2 replies



I desgined a great 3D matrix of spheres as a detector.

I would like to know how to export the total power value of each detector in a single file (all the values) with a ZPL macro.


Thanks, Carmen

2 replies

Userlevel 6
Badge +2

Hi Carmen,


Here is a simple example with 2 spheres (attached to my reply):

The code is as follows:

# Clear all detectors
clear = NSDD(1, 0, 0, 0)

# Run a raytrace
NSTR 1, 0, 0, 0, 0, 1, 0

# Read power of all objects between the first and last
# object (defined below)

# First object
first_object = 2

# Last object
last_object = 3

# Specify PRINT output file
OUTPUT "test.txt"

# Loop over the detectors
FOR object, first_object, last_object, 1
# Record total flux of current object
flux = NSDD(1, object, 0, 0)

# Print flux to file specified by OUTPUT
PRINT flux

Please note the following about the OUTPUT keyword:

If a valid filename is provided, then subsequent PRINT commands will output to the filename specified. If a filename with no path is provided, output will be directed to the <data>\Macros folder.


The result gives the following values:


And these are the text tab of the detector viewers:

Sphere 2, NSCG Surface 1: 
Number of pixels: 4512, Total Hits = 19543

Peak Power : 1.0460E-02 Watts
Total Power : 1.9543E-01 Watts
Sphere 3, NSCG Surface 1: 
Number of pixels: 4512, Total Hits = 80457

Peak Power : 1.0500E-02 Watts
Total Power : 8.0457E-01 Watts

Let me know if you have any other question.

Take care,


It works! Thanks David

Take care too