Skip to content

Optimize source using chopper cascade acceptance diagram#136

Open
nvaytet wants to merge 17 commits intomainfrom
source-optimize
Open

Optimize source using chopper cascade acceptance diagram#136
nvaytet wants to merge 17 commits intomainfrom
source-optimize

Conversation

@nvaytet
Copy link
Copy Markdown
Member

@nvaytet nvaytet commented Mar 23, 2026

Alternative to #131 , needs #139

Instead of using readings from a run, we compute analytically the chopper acceptance diagram and mask out the regions in the probability distribution that are rejected by the choppers.

We just make a new source from the masking, thus requiring no changes to the rest of the codebase.

To optimize the source, we pass the list of choppers in the beamline as optimize_for:

new_source = tof.Source(facility='ess', neutrons=1e6, optimize_for=choppers)

Original with 1M neutrons (72907 visible at the detector, 927093 blocked)
original_source

Optimized source with 1M neutrons (1M visible, 0 neutrons are blocked)
optimized_source

TODO: still need to write some tests.

@nvaytet
Copy link
Copy Markdown
Member Author

nvaytet commented Mar 24, 2026

@YooSunYoung I got it down to only a few iterations, but it seems we cannot mask out tighly around the polygons after all. This leads to weird results (see the spikes and striping)
Screenshot_20260324_171821

Neutrons sampled from the source:
Figure 1 (11)

If I either don't mask at all (and iterate more), or mask just rectangles using the polygon bounding boxes, I don't get the effect, but I have to do 28 iterations to sample 3M neutrons (this takes ~6s just to build the source).

Screenshot_20260324_172350 Figure 1 (12)

I guess the thing that we really save on is RAM, so it's still worth it. But I don't think we save much in compute time...

@nvaytet
Copy link
Copy Markdown
Member Author

nvaytet commented Mar 30, 2026

I believe that the artifacts above can be explained by the Gaussian noise that is added to the neutron birth time and wavelength during the sampling.
Because the gaussian distribution has a long tail which extends outside the current cell, when everything is smooth, things even out nicely between neighbouring cells.

But when we have a mask where sets the probability to 0, suddenly things no longer balance out. We have some contributions that should be coming from outside the polygons to even things out that no longer exist because their probability has been set to 0. While the cells that are not masked contribute their tails to the surroundings.

Instead, we want to use uniform noise between -0.5 and 0.5 cell size.
We went with Gaussian to begin with, as it was good at mimicking smooth transitions in regions where we had gradients. But we now believe this is causing issues here (as well as possibly creating neutrons outside of the range a user had specified). To have data that looks as good as we had before, we need higher resolution source distributions (see #139 ).

@nvaytet nvaytet changed the base branch from main to more-ess-sources April 7, 2026 07:17
Base automatically changed from more-ess-sources to main April 7, 2026 14:14
@nvaytet
Copy link
Copy Markdown
Member Author

nvaytet commented Apr 7, 2026

After updates in #139 and some further performance improvements in the masking, building an optimized source is now fast, uses a tight mask, and no longer has weird artifacts/striping.

Without optimization (1M neutrons, Odin choppers): 942625 neutrons blocked, 57375 visible
Screenshot_20260407_210732

With optimization (1M neutrons, Odin choppers): 0 blocked, 1M visible
Screenshot_20260407_210743

@nvaytet nvaytet marked this pull request as ready for review April 7, 2026 22:29
@nvaytet nvaytet requested review from YooSunYoung April 8, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant