Skip to content

Conversation

warunawickramasingha
Copy link
Contributor

@warunawickramasingha warunawickramasingha commented Jul 10, 2024

Description of work

This work adds support for a radial collimator in DiscusMultipleScatteringCorrection algorithm that it restricts scatter points within a small region within the larger sample volume. The algorithm was modified to assign zero weight to tracks where the final scatter is not in a position that allows the final track segment to pass through the collimator toward detectors.

Purpose of work

This work allows the use of DiscusMultipleScatteringCorrection algorithm for ENGINX instrument that has a radial collimator.

Fixes #35373.

Further detail of work

To test:

To test this feature, run the DiscusMultipleScatteringCorrection with and without RadialCollimator and compare the output weights assigned by the algorithm for each spectrum(detector) that are un masked. Note: To test the algorithm in reduced time period, many of the detectors are marked as masked.

Run below code which will Mask all the detectors from spectrum 10 onwards.

from mantid.simpleapi import *

X=[0.99,1.0,1.01]
Y=[0.,100,0.]
Sofq=CreateWorkspace(DataX=X,DataY=Y,UnitX="MomentumTransfer")

run = "ENGINX00194547"
ws=Load(Filename=run+'.nxs', OutputWorkspace=run)
MoveInstrumentComponent(ws, ComponentName="sample position", X=0, Y=0, Z=0, RelativePosition=False)

sphere_xml = " \
<sphere id='some-sphere'> \
    <centre x='0.0'  y='0.0' z='0.0' /> \
    <radius val='0.2' /> \
</sphere> \
<algebra val='some-sphere' /> \
"

SetSample(InputWorkspace=ws,
          Geometry={'Shape': 'CSG', 'Value': sphere_xml},
          Material={'NumberDensity': 0.02, 'AttenuationXSection': 0.0,
                    'CoherentXSection': 0.0, 'IncoherentXSection': 0.0, 'ScatteringXSection': 80.0})

ws_mom = ConvertUnits(InputWorkspace=run, OutputWorkspace=run+'_momentum', Target='Momentum') 
MaskDetectors(ws_mom,  WorkspaceIndexList=range(10, ws_mom.getNumberHistograms()))

results_group1 = DiscusMultipleScatteringCorrection(InputWorkspace=ws_mom, StructureFactorWorkspace=Sofq,
                                                   OutputWorkspace="With_Collimator", NeutronPathsSingle=5,
                                                   NeutronPathsMultiple=10, ImportanceSampling=True, RadialCollimator=True, NumberScatterings=4)

results_group2 = DiscusMultipleScatteringCorrection(InputWorkspace=ws_mom, StructureFactorWorkspace=Sofq,
                                                   OutputWorkspace="No_Collimator", NeutronPathsSingle=5,
                                                   NeutronPathsMultiple=10, ImportanceSampling=True, RadialCollimator=False, NumberScatterings=4)

Click Show Data for workspaces suffixed Scatter_n_Integrated under each group workspaces named With_Collimator and No_Collimator. When the collimator is present (i.e RadialCollimator=True), the integrated weight for Spectrum index 2 (an unmasked detector) should be lower than the weight when there is no collimator(RadialCollimator=False).


Reviewer

Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.

Code Review

  • Is the code of an acceptable quality?
  • Does the code conform to the coding standards?
  • Are the unit tests small and test the class in isolation?
  • If there is GUI work does it follow the GUI standards?
  • If there are changes in the release notes then do they describe the changes appropriately?
  • Do the release notes conform to the release notes guide?

Functional Tests

  • Do changes function as described? Add comments below that describe the tests performed?
  • Do the changes handle unexpected situations, e.g. bad input?
  • Has the relevant (user and developer) documentation been added/updated?

Does everything look good? Mark the review as Approve. A member of @mantidproject/gatekeepers will take care of it.

Gatekeeper

If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.

@warunawickramasingha warunawickramasingha added the Diffraction Issues and pull requests related to diffraction label Jul 10, 2024
@warunawickramasingha warunawickramasingha added this to the Release 6.11 milestone Jul 10, 2024
@warunawickramasingha warunawickramasingha force-pushed the 35373_support_for_guage_volume_DiscusMultipleScatteringCorrection branch 2 times, most recently from 618b54c to e5348ee Compare July 10, 2024 14:33
@warunawickramasingha warunawickramasingha force-pushed the 35373_support_for_guage_volume_DiscusMultipleScatteringCorrection branch from bdb6f48 to 6ff50e7 Compare July 11, 2024 15:13
@github-actions github-actions bot added the Has Conflicts Used by the bot to label pull requests that have conflicts label Jul 26, 2024
Copy link

👋 Hi, @warunawickramasingha,

Conflicts have been detected against the base branch. Please rebase your branch against the base branch.

Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, just a few comments/typos - the only big thing is that I'm not sure the way the hexahedron is constructed is sufficiently general to work for both configurations of collimator (axis vertical or along beam). But you have probably spent more time staring at the drawings than I have!

I will give it a quick manual test, but we will need to get in touch with ENGIN-X scientists for proper scientific validation.

const bool radialCollimator = getProperty("RadialCollimator");
if (radialCollimator) {
auto numberOfHist = inputWS->getNumberHistograms();
for (size_t histIdx = 0; histIdx < numberOfHist; ++histIdx) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, nice idea to add some validation that the collimator is a valid option, I wonder though if we should instead just ignore detectors without a valid shape (and maybe throw a warning)? This could be quite a large loop for e.g. WISH!

const auto &detRightFrontBottomPos = detectorAbsolPos + cuboidGeometry.rightFrontBottom;
const auto detRightFrontTopPos = detLeftFrontTopPos + detRightFrontBottomPos - detLeftFrontBottomPos;

const auto detCentorPos =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible typo?

Suggested change
const auto detCentorPos =
const auto detCenterPos =

I'm assuming this not always be the same as detectorAbsolPos which is the center of the 3D cuboid - whereas this is the center of the 2D cross-section of the detector as viewed from the sample?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. This is the centre of the 2D cross section as viewed from the sample.

// Define the unit vectors needed for calculations
const auto unitVecLeftToRight =
(detRightFrontTopPos - detLeftFrontTopPos) / (detRightFrontTopPos - detLeftFrontTopPos).norm();
const auto unitVecBottomToUp = (detTopMiddlePos - detCentorPos) / (detTopMiddlePos - detCentorPos).norm();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this - will this still work for both possible configurations of collimator we know about (i.e. axis of cylinder vertical, and axis of cylinder along beam)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should work, the names like *Up given for the variable are just to tally with the paper drawing I had and they should work with vector geometry irrespective of the coordinate system.

@warunawickramasingha warunawickramasingha force-pushed the 35373_support_for_guage_volume_DiscusMultipleScatteringCorrection branch from 6ff50e7 to aca906b Compare August 19, 2024 16:15
@github-actions github-actions bot removed the Has Conflicts Used by the bot to label pull requests that have conflicts label Aug 19, 2024
@sf1919
Copy link
Contributor

sf1919 commented Aug 20, 2024

As this is not failing on tests associated with libopenblas problems I will not re-run the tests for this PR.

Copy link
Contributor

@RichardWaiteSTFC RichardWaiteSTFC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, in simple tests this seems to work well: I can confirm with a sample larger than the gauge volume the multiple scattering is reduced with the collimator. I also tested with a sample much smaller than the gauge volume and the multiple scattering with/without the collimator was consistent as expected.

There's a couple of minor things:

  1. It would be good to have some explanation of the radial collimator option in the algorithm docs -(e.g. where to specify the collimator details etc.)
  2. Make determination of vector in scattering plane general (see other comment)

I was talking to Stephen Nneji (SScanSS developer) who is more familiar with the collimator on ENGIN-X - he says that there are multiple collimators with different angular openings that can be used, so I think in separate issue we will probably need to add the angular opening as a input argument (given it's not static on the instrument).

Given we will need to touch this again anyway and this feature is still in development until ENGIN-X scientists can do some testing/validation, the above can be addressed during maintenance - I think we should get this merged as is! After validation we can also beef up the unit tests (assert some values etc.).

Thanks again for all your effort on this and getting it over the line!

const auto unitVecSampleToDet = Kernel::normalize(detCentrePos - samplePos);
const auto unitVecLeftToRight = Kernel::normalize(
V3D(-1.0 * unitVecSampleToDet.Z(), 0,
-1.0 * unitVecSampleToDet.X())); // this is a vector normal to unitVecSampleToDet on XZ plane
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for getting the vector in the scattering plane on ENGIN-X (and WISH - another instrument with a radial collimator)I think - but it won't work for all instruments. In future perhaps you can get the ki vector from the workspace, however I'm happy to leave it as is for now - want to get this in the release (my fault for dragging my feet with the testing sorry)!

@SilkeSchomann SilkeSchomann self-assigned this Sep 10, 2024
@SilkeSchomann SilkeSchomann merged commit d4d3acd into main Sep 10, 2024
10 checks passed
@SilkeSchomann SilkeSchomann deleted the 35373_support_for_guage_volume_DiscusMultipleScatteringCorrection branch September 10, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Diffraction Issues and pull requests related to diffraction
Projects
Status: Merged
Archived in project
Development

Successfully merging this pull request may close these issues.

Add support for a gauge volume in DiscusMultipleScatteringCorrection
5 participants