New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add polarizer efficiency algorithm #37180
base: main
Are you sure you want to change the base?
Add polarizer efficiency algorithm #37180
Conversation
👋 Hi, @jclarkeSTFC, Conflicts have been detected against the base branch. Please rebase your branch against the base branch. |
96070c7
to
e86fc0b
Compare
e86fc0b
to
0355e62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp
Outdated
Show resolved
Hide resolved
Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp
Outdated
Show resolved
Hide resolved
Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp
Outdated
Show resolved
Hide resolved
Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp
Outdated
Show resolved
Hide resolved
Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp
Outdated
Show resolved
Hide resolved
897c81b
to
209a674
Compare
Thanks, I think I've changed all the things you spotted, and I've updated to the new equation. |
4eba049
to
c74397b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally working well, just a couple more things I noticed. Apologies for not catching them in the first review.
Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp
Outdated
Show resolved
Hide resolved
Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp
Outdated
Show resolved
Hide resolved
👋 Hi, @jclarkeSTFC, Conflicts have been detected against the base branch. Please rebase your branch against the base branch. |
Calculate polarizer efficiency using a group workspace with 4 runs for the 4 spin combinations, plus the efficiency of the analyser cell, calculated previously.
Missing const in a few places, deleted unneeded methods and used the operator overloads instead.
Includes updating expected test results
You can now either have an output workspace, or save to a file, or both.
Co-authored-by: Caila Finn <47181718+cailafinn@users.noreply.github.com>
Co-authored-by: Caila Finn <47181718+cailafinn@users.noreply.github.com>
This validator does not work when the type is specified explicitly as being a WorkspaceGroup, so instead we'll have to to check for wavelength in validateInputs().
cc92f48
to
19babc8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs built and looking good. Code has a few more notes. Functionally it's working well for the normal use case, but there's a crash to desktop (segfault) when using an invalid workspace type for the Cell efficiency workspace.
if (inputWorkspace->size() != 4) { | ||
errorList[PropertyNames::INPUT_WORKSPACE] = | ||
"The input group workspace must have four periods corresponding to the four spin configurations."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was pointed out (thanks @rbauststfc), that the formula for the calculation only requires two periods
void PolarizerEfficiency::validateGroupInput() { | ||
const auto &results = validateInputs(); | ||
if (results.size() > 0) { | ||
const auto &result = results.cbegin(); | ||
throw std::runtime_error("Issue in " + result->first + " property: " + result->second); | ||
} | ||
} | ||
|
||
bool PolarizerEfficiency::processGroups() { | ||
validateGroupInput(); | ||
calculatePolarizerEfficiency(); | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed during the flipper efficiency alg work that if the input property is explicitly a workspace group (like has now been done in this one) then these methods aren't strictly necessary as it expects a group during a normal exec. This may be worth testing as it simplifies the call stack for the validation and may help with that error reporting issue we noted before.
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want some checks for the analyser efficiency workspace in here:
- In wavelength
- Is the same size (number of histograms) as the input workspaces
- Is a
MatrixWorkspace
As it stands, you can provide something like a workspaceGroup and crash when you cast it to a MatrixWorkspace
on L133. We also want tests adding for this.
const auto &groupWorkspace = | ||
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(getProperty(PropertyNames::INPUT_WORKSPACE)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May not be in the ADS. Get directly from the property.
const auto &groupWorkspace = | |
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(getProperty(PropertyNames::INPUT_WORKSPACE)); | |
const WorkspaceGroup_sptr inputWorkspace = getProperty(PropertyNames::INPUT_WORKSPACE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this, and relevant to the other comment about simplifying the validation, have we done some testing to see if you really can pass in a workspace that's not in the ADS to a WorkspaceGroup
property? I did what I consider to be some very incomplete testing, but it seemed to show that the property type was enforcing that the workspace group had to be in the ADS. It would be good to establish this conclusively, as it will be relevant to all the other polarised SANS algorithms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can confirm this. Below shows the debugging from C++ in the tests. The CreateSampleWorkspace
outputs are present in the ADS due to it being a non-child alg, but the group is not as the GroupWorkspaces
alg is a child algorithm. The group only exists as a pointer in the C++ code, which is then passed to the FlipperEfficiency
alg, without entering the ADS, and the alg is still able to process normally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, brilliant, thanks for checking 👍
auto effCell = convertToHistIfNecessary( | ||
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(getProperty(PropertyNames::ANALYSER_EFFICIENCY))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
auto effCell = convertToHistIfNecessary( | |
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(getProperty(PropertyNames::ANALYSER_EFFICIENCY))); | |
auto effCell = convertToHistIfNecessary(getProperty(PropertyNames::INPUT_WORKSPACE)); |
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. |
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
Further detail of work
Calculates how the efficiency of a polarizer varies with wavelength. The ordering of the workspaces in
InputWorkspace
is taken from theSpinStates
parameter, and the analyser efficiency, e_cell, is given byAnalyserEfficiency
.The polarization of the polarizer, P_SM, is given by
Since the efficiency, e_SM , is given by (1 + P_SM)/2, we have that
To test:
This will generate a simple example:
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.