mantidproject / mantid

Main repository for Mantid code
https://www.mantidproject.org
GNU General Public License v3.0
207 stars 122 forks source link

Add Supermirror Polarizer Efficiency Algorithm #37616

Open cailafinn opened 4 days ago

cailafinn commented 4 days ago

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


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

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

Functional Tests

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.