Skip to main content

Hi everyone,

 

Inspired by this discussion with @Devorse, I made a User Analysis which sorts the Merit Function operands by descending order of contribution. The source code and executable are attached to this post.

In the Double Gauss 28 degree field sample file, with a default Merit Function:

 

Sequential merit function: RMS spot x+y centroid X Wgt = 1.0000 Y Wgt = 1.0000 GQ 4 rings 6 arms

 

The Merit Function Editor looks as below:

 

 

And the analysis returns:

 

 

Installation

To install this user analysis, download the attached archive (MeritFunctionContribution.zip) and extract it on your computer. Copy the file MeritFunctionContribution.exe to your {Documents}\Zemax\ZOS-API\User Analysis folder.

To run the user analysis, after the step above has been completed, simply press Programming..User Analyses..MeritFunctionContribution.

If you need to recompile the source code, please follow the steps outlined in this knowledgebase article.

Note 1: there’s little error traping in the code, I’m not sure how it would react if the Merit Function can’t be calculated.

Note 2: as @Sandrine Auriol pointed out, one needs to make sure the Merit Function is up-to-date before running the User Analysis.

 

I hope this can serve as a starting point to develop further Merit Function analysis tools.

Take care,

 

David

Hi David! Thank you for your solution. I tested and it all works well. Just a comment. The merit function needs to be updated before running the user-analysis.

I have updated the name of the solution from “User analysis to sort Merit Function operands by descending order of contribution” to “API (CS User Analysis): Sequential Sort Merit Function operands by descending order of contribution” to be consistent with the other titles. Let me know if that is ok.

Usually with the solutions, we add a word document to explain what it does. But the name of the solution with your instructions is perfect. So happy to keep it this way.

Thank you for your contribution!


Hi Sandrine,

 

Thank you for your feedback. You are right, one needs to update the Merit Function before running this User Analysis. In view of fixing this issue, do you know if a call to the CalculateMeritFunction() method as the effect of updating the Merit Function?

I will make a separate document to attach with the archive so that everything is self-contained. I will be away for a couple of weeks though so you might have to wait until my return if its ok.

Take care,

 

David


Hi David!

Yes I have tried and CalculateMeritFunction() works. 

No problem, we can do the update on your return.

Thank you.


Reply