mantid icon indicating copy to clipboard operation
mantid copied to clipboard

Apply TotScat Correction before focussing

Open DanielMurphy22 opened this issue 3 years ago • 1 comments

After updates to the TotScattCalculateSelfScattering algorithm, and dicussion with Helen, it was decided that we should try to apply this correction on a per detector basis BEFORE the data gets focussed. Currently the correction is focussed and then applied to focussed data.

In addition to changing the order of this workflow for polaris, we should investigate whether applying an absoulte normalisation is appropriate.

DanielMurphy22 avatar Nov 08 '21 14:11 DanielMurphy22

Context and Remaining work

Current proof of concept here: https://github.com/mantidproject/mantid/pull/33008 allows the user to apply the vanadium and placzek corrections per detector before focussing.

Remaining:

  • only implement the placzek correction in the per detector setting
  • Add a switch to choose to use this per detector vanadium correction (this could be extended to other instruments easily in future).
  • Need a check so that the placzek (soon to be always per detector) can only be used with a per detector vanadium correction.
  • the per detector vanadium should be saved to .nxs and loaded when appropriate for future runs.

DanielMurphy22 avatar Mar 03 '22 14:03 DanielMurphy22

Update on current status:

  • old PR: https://github.com/mantidproject/mantid/pull/33008/
  • new current working branch: bad_tests_dec22_placzek_bf_focus with compare to main here: https://github.com/mantidproject/mantid/compare/bad_tests_dec22_placzek_bf_focus?expand=1

Work done:

moved over a lot of the code from the old PR and the following files are complete:

  • polaris_advanced_config
  • abstract_inst
  • calibrate
  • SplineBackground.h and .cpp
  • polaris.py but some changes may be needed
  • most of focus.py

written test_calibrate -> mostly happy with and test_focus -> trying to address in latest commit that the per_detector tests aren't genuinely running the per_detector workflow

  • note that these new tests rely heavily on having run a polaris script in workbench(for me calcuate_pdf) at least with a successful create_vanadium() + setting the config by running the systemtest ISIS_PowderPolaris. This means these tests don't setup correctly. This issue is only worth addressing if these tests are worth merging as unit or systemtests.

Work to do:

  • Use per_detector consistently. In calibrate (create_vanadium) I take it as a kwarg. In focus I take it as an instrument setting. I think I prefer harmonising to use the instrument setting so a user could run a pdf reductions script in per detector mode by simply making one change in the Polaris object.
  • Make the focus tests genuinely run the per_detector workflow, current blocker is the save_unsplined_vanadium (in polaris.create_vanadium) is not called in the per_detector fashion. When I try this I get a problem with focus._normalize_one_spectrum() in Divide where ValueError: Number of histograms not identical. I should be careful when correcting this as the _normalize_one_spectrum() function has changed quite a bit since it was called _divide_one_spectrum_by_spline() in the old PR: https://github.com/mantidproject/mantid/pull/33008/
  • Check what to prevent after apply_per_detector_placzek in focus.focus_one_ws(), such as _apply_vanadium_corrections() shouldn't be called later on in the per detector routine as already performed. Have separate functions where possible to simplify the readability!
  • Do I need the ConvertTo/FromDistribution around DiffractionFocussing in focus.focus_one_ws()?
  • need to move over TotScattCalculateSelfScattering and polaris_algs.generate_TS_pdf() changes!
  • Consider not keeping or revamping the tests! They are like unit tests on workflow functions which are too slow to merge!
  • REMEMBER to remove dummy function from production code (at bottom of calibrate and test=False and if test:). I attempted a mocking implementation on last commit of branch new_dec22_placzek_bf_focus. This was complicated and should only be pursued if the tests are worth merging!

DanielMurphy22 avatar Dec 20 '22 16:12 DanielMurphy22

  • Also in the per_detector mode should we always apply the placzek correction and require that the mode="PDF"?

DanielMurphy22 avatar Dec 20 '22 16:12 DanielMurphy22