mantid icon indicating copy to clipboard operation
mantid copied to clipboard

Add polarizer efficiency algorithm

Open jclarkeSTFC opened this issue 1 year ago • 4 comments

New algorithm to calculate the supermirror polarizer efficiency using a group workspace with 4 runs for the 4 spin combinations, plus the efficiency of the analyser cell, calculated previously. This is part of the polarized SANS epic.

Output can either be to a workspace, a file, or both.

Fixes #36139

Summary of work

  • Added algorithm
  • Added tests
  • Added doc page

Further detail of work

Calculates how the efficiency of a polarizer varies with wavelength. The ordering of the workspaces in InputWorkspace is taken from the SpinStates parameter, and the analyser efficiency, e_cell, is given by AnalyserEfficiency.

The polarization of the polarizer, P_SM, is given by

image

Since the efficiency, e_SM , is given by (1 + P_SM)/2, we have that

image

To test:

This will generate a simple example:

wsPara = CreateSampleWorkspace('Histogram', Function='User Defined', UserDefinedFunction='name=UserFunction,Formula=0.5*exp(-0.0733*12*x*(1-0.9))',XUnit='Wavelength', xMin='1',XMax='8', BinWidth='1')
wsPara1 = CloneWorkspace(wsPara)
wsAnti = CreateSampleWorkspace('Histogram', Function='User Defined', UserDefinedFunction='name=UserFunction,Formula=0.5*exp(-0.0733*12*x*(1+0.9))',XUnit='Wavelength', xMin='1',XMax='8', BinWidth='1')
wsAnti1 = CloneWorkspace(wsAnti)

grp = GroupWorkspaces([wsPara,wsAnti,wsPara1,wsAnti1])
eCell = CreateSampleWorkspace('Histogram', Function='User Defined', UserDefinedFunction='name=UserFunction,Formula=(1 + tanh(0.0733 * 12 * x * 0.2))/2',XUnit='Wavelength', xMin='1',XMax='16', BinWidth='1')

psm = PolarizerEfficiency(grp, eCell)
print("Polarizer efficiency at a wavelength of " + str(mtd['psm'].dataX(0)[3]) + " Å is " + str(mtd['psm'].dataY(0)[3]))

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.

jclarkeSTFC avatar Apr 17 '24 14:04 jclarkeSTFC

:wave: Hi, @jclarkeSTFC,

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

github-actions[bot] avatar Apr 24 '24 13:04 github-actions[bot]

Code Review:

* Have a few code notes, but it's looking good.

Functional testing:

* Working well from both the script and the algorithm dialog. Tried a few different bad inputs and it handled them well.

* The 1st column of the output data from the script you provided seems to provide an efficiency value of `-1.108...`. I was under the impression efficiencies should always be between 0 and 1, so I just want to check if that's expected or if I've not got confused about something.

Docs:

* Look great! Thanks for including the maths for both the polarisation and the efficiency.

Thanks, I think I've changed all the things you spotted, and I've updated to the new equation.

jclarkeSTFC avatar May 01 '24 15:05 jclarkeSTFC

:wave: Hi, @jclarkeSTFC,

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

github-actions[bot] avatar May 08 '24 12:05 github-actions[bot]

Just making a note that because we'll now be targeting 6.11 for this change, we'll need to rebase and move the release note to the appropriate 6.11 folder.

rbauststfc avatar May 10 '24 14:05 rbauststfc

Re-created the PR here as I can't push to this branch:

  • https://github.com/mantidproject/mantid/pull/37616

cailafinn avatar Jun 27 '24 14:06 cailafinn