mantid icon indicating copy to clipboard operation
mantid copied to clipboard

Add Supermirror Polarizer Efficiency Algorithm

Open cailafinn opened this issue 7 months ago • 0 comments

Re-release as I can't push directly to @jclarkeSTFC's fork

  • #37180

New algorithm to calculate the supermirror polarizer efficiency using a group workspace containing spin states, 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

$$ \huge P_{SM} = \frac{T_{00} - T_{01}}{2P_{cell}(T_{00} + T_{01})} = \frac{T_{00} - T_{01}}{2(2\epsilon_{cell} - 1)(T_{00} + T_{01})} $$

Since the efficiency, $\epsilon_{SM}$ , is given by $\frac{1 + P_{SM}}{2}$, we have that

$$ \huge \epsilon_{SM} = \frac{1}{2} + \frac{T_{00} - T_{01}}{4(2\epsilon_{cell} - 1)(T_{00} + T_{01})} $$

Error correction:

$$ \huge \sigma_{\epsilon_{SM}} = \sqrt{|\frac{\delta \epsilon_{SM}}{\delta T_{00}}|^2 * \sigma^2_{T_{00}} + |\frac{\delta \epsilon_{SM}}{\delta T_{01}}|^2 * \sigma^2_{T_{01}} + |\frac{\delta \epsilon_{SM}}{\delta \epsilon_{cell}}|^2 * \sigma^2_{\epsilon_{cell}}} $$

where:

$$ \huge \frac{\delta \epsilon_{SM}}{\delta T_{00}} = \frac{T_{01}}{2(2\epsilon_{cell} - 1)(T_{00} + T_{01})^2} $$

$$ \huge \frac{\delta \epsilon_{SM}}{\delta T_{01}} = \frac{-T_{00}}{2(2\epsilon_{cell} - 1)(T_{00} + T_{01})^2} $$

$$ \huge \frac{\delta \epsilon_{SM}}{\delta \epsilon_{cell}} = \frac{T_{01} - T_{00}}{2(2\epsilon_{cell} - 1)^2(T_{00} + T_{01})} $$

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', NumBanks='1', BankPixelWidth='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', NumBanks='1', BankPixelWidth='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', NumBanks='1', BankPixelWidth='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.

cailafinn avatar Jun 27 '24 14:06 cailafinn