Skip to content

Commit

Permalink
Merge pull request mantidproject#38334 from mantidproject/38290-renam…
Browse files Browse the repository at this point in the history
…e-heliumanalyserefficiency-algorithm-parameters-for-consistency

Rename some HeliumAnalyserEfficiency algorithm parameters
  • Loading branch information
SilkeSchomann authored Nov 15, 2024
2 parents 78943b8 + 2ed8835 commit 7b21a39
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ using namespace API;
constexpr double HeliumAnalyserEfficiency::ABSORPTION_CROSS_SECTION_CONSTANT = 0.0733;

namespace PropertyNames {
auto constexpr INPUT_WORKSPACE{"InputWorkspace"};
auto constexpr OUTPUT_WORKSPACE{"OutputWorkspace"};
auto constexpr OUTPUT_FIT_CURVES{"OutputFitCurves"};
auto constexpr OUTPUT_FIT_PARAMS{"OutputFitParameters"};
auto constexpr SPIN_STATES{"SpinStates"};
auto constexpr PD{"GasPressureTimesCellLength"};
auto constexpr PD_ERROR{"GasPressureTimesCellLengthError"};
auto constexpr START_LAMBDA{"StartLambda"};
auto constexpr END_LAMBDA{"EndLambda"};
auto constexpr IGNORE_FIT_QUALITY_ERROR{"IgnoreFitQualityError"};

auto constexpr GROUP_INPUTS{"Inputs"};
auto constexpr GROUP_FIT_OPTIONS{"Fit Options"};
auto constexpr GROUP_OUTPUTS{"Outputs"};
static const std::string INPUT_WORKSPACE{"InputWorkspace"};
static const std::string OUTPUT_WORKSPACE{"OutputWorkspace"};
static const std::string OUTPUT_FIT_CURVES{"OutputFitCurves"};
static const std::string OUTPUT_FIT_PARAMS{"OutputFitParameters"};
static const std::string SPIN_STATES{"SpinStates"};
static const std::string PXD{"PXD"};
static const std::string PXD_ERROR{"PXDError"};
static const std::string START_X{"StartX"};
static const std::string END_X{"EndX"};
static const std::string IGNORE_FIT_QUALITY_ERROR{"IgnoreFitQualityError"};

static const std::string GROUP_INPUTS{"Inputs"};
static const std::string GROUP_FIT_OPTIONS{"Fit Options"};
static const std::string GROUP_OUTPUTS{"Outputs"};
} // namespace PropertyNames

namespace {
Expand All @@ -64,12 +64,11 @@ void HeliumAnalyserEfficiency::init() {

auto mustBePositive = std::make_shared<BoundedValidator<double>>();
mustBePositive->setLower(0);
declareProperty(PropertyNames::PD, 12.0, mustBePositive, "Gas pressure in bar multiplied by cell length in metres");
declareProperty(PropertyNames::PD_ERROR, 0.0, mustBePositive, "Error in gas pressure multiplied by cell length");
declareProperty(PropertyNames::START_LAMBDA, 1.75, mustBePositive,
declareProperty(PropertyNames::PXD, 12.0, mustBePositive, "Gas pressure in bar multiplied by cell length in metres");
declareProperty(PropertyNames::PXD_ERROR, 0.0, mustBePositive, "Error in gas pressure multiplied by cell length");
declareProperty(PropertyNames::START_X, 1.75, mustBePositive,
"Lower boundary of wavelength range to use for fitting");
declareProperty(PropertyNames::END_LAMBDA, 8.0, mustBePositive,
"Upper boundary of wavelength range to use for fitting");
declareProperty(PropertyNames::END_X, 8.0, mustBePositive, "Upper boundary of wavelength range to use for fitting");
declareProperty(PropertyNames::IGNORE_FIT_QUALITY_ERROR, false,
"Whether the algorithm should ignore a poor chi-squared (fit cost value) of greater than 1 and "
"therefore not throw an error",
Expand All @@ -87,11 +86,11 @@ void HeliumAnalyserEfficiency::init() {
"The name of the table workspace containing the fit parameter results.");

setPropertyGroup(PropertyNames::SPIN_STATES, PropertyNames::GROUP_INPUTS);
setPropertyGroup(PropertyNames::PD, PropertyNames::GROUP_INPUTS);
setPropertyGroup(PropertyNames::PD_ERROR, PropertyNames::GROUP_INPUTS);
setPropertyGroup(PropertyNames::PXD, PropertyNames::GROUP_INPUTS);
setPropertyGroup(PropertyNames::PXD_ERROR, PropertyNames::GROUP_INPUTS);

setPropertyGroup(PropertyNames::START_LAMBDA, PropertyNames::GROUP_FIT_OPTIONS);
setPropertyGroup(PropertyNames::END_LAMBDA, PropertyNames::GROUP_FIT_OPTIONS);
setPropertyGroup(PropertyNames::START_X, PropertyNames::GROUP_FIT_OPTIONS);
setPropertyGroup(PropertyNames::END_X, PropertyNames::GROUP_FIT_OPTIONS);
setPropertyGroup(PropertyNames::IGNORE_FIT_QUALITY_ERROR, PropertyNames::GROUP_FIT_OPTIONS);

setPropertyGroup(PropertyNames::OUTPUT_WORKSPACE, PropertyNames::GROUP_OUTPUTS);
Expand Down Expand Up @@ -149,7 +148,7 @@ void HeliumAnalyserEfficiency::exec() {
// Theoretically, the analyser efficiency is given by (1 + tanh(mu * phe * wavelength))/2.
// Using the analyser efficiency value that we calculated from the data,
// we fit this function to find pHe, the helium atom polarization in the analyser.
const double mu = ABSORPTION_CROSS_SECTION_CONSTANT * static_cast<double>(getProperty(PropertyNames::PD));
const double mu = ABSORPTION_CROSS_SECTION_CONSTANT * static_cast<double>(getProperty(PropertyNames::PXD));

double pHe, pHeError;
fitAnalyserEfficiency(mu, eff, pHe, pHeError);
Expand Down Expand Up @@ -190,11 +189,11 @@ void HeliumAnalyserEfficiency::fitAnalyserEfficiency(const double mu, const Matr
auto fit = createChildAlgorithm("Fit");
fit->initialize();
fit->setProperty("Function", "name=UserFunction,Formula=(1 + tanh(" + std::to_string(mu) + "*phe*x))/2,phe=0.1");
fit->setProperty("InputWorkspace", eff);
const double startLambda = getProperty(PropertyNames::START_LAMBDA);
fit->setProperty("StartX", startLambda);
const double endLambda = getProperty(PropertyNames::END_LAMBDA);
fit->setProperty("EndX", endLambda);
fit->setProperty(PropertyNames::INPUT_WORKSPACE, eff);
const double startLambda = getProperty(PropertyNames::START_X);
fit->setProperty(PropertyNames::START_X, startLambda);
const double endLambda = getProperty(PropertyNames::END_X);
fit->setProperty(PropertyNames::END_X, endLambda);
fit->setProperty("CreateOutput", true);
fit->execute();

Expand All @@ -210,7 +209,7 @@ void HeliumAnalyserEfficiency::fitAnalyserEfficiency(const double mu, const Matr
setProperty(PropertyNames::OUTPUT_FIT_PARAMS, fitParameters);
}
if (!API::Algorithm::getPropertyValue(PropertyNames::OUTPUT_FIT_CURVES).empty()) {
const MatrixWorkspace_sptr fitWorkspace = fit->getProperty("OutputWorkspace");
const MatrixWorkspace_sptr fitWorkspace = fit->getProperty(PropertyNames::OUTPUT_WORKSPACE);
setProperty(PropertyNames::OUTPUT_FIT_CURVES, fitWorkspace);
}

Expand All @@ -229,7 +228,7 @@ void HeliumAnalyserEfficiency::convertToTheoreticalEfficiency(MatrixWorkspace_sp

// The value tCrit is used to give us the correct error bounds
const double tCrit = calculateTCrit(eff->blocksize());
const double muError = ABSORPTION_CROSS_SECTION_CONSTANT * static_cast<double>(getProperty(PropertyNames::PD_ERROR));
const double muError = ABSORPTION_CROSS_SECTION_CONSTANT * static_cast<double>(getProperty(PropertyNames::PXD_ERROR));

for (size_t i = 0; i < binPoints.size(); ++i) {
const double lambda = binPoints[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class HeliumAnalyserEfficiencyTest : public CxxTest::TestSuite {
MantidVec e;
auto wsGrp = createExampleGroupWorkspace("wsGrp", e, "Wavelength");
auto heliumAnalyserEfficiency = createHeliumAnalyserEfficiencyAlgorithm(wsGrp, "E");
heliumAnalyserEfficiency->setProperty("StartLambda", 4.0);
heliumAnalyserEfficiency->setProperty("EndLambda", 6.0);
heliumAnalyserEfficiency->setProperty("StartX", 4.0);
heliumAnalyserEfficiency->setProperty("EndX", 6.0);
heliumAnalyserEfficiency->setProperty("IgnoreFitQualityError", true);
heliumAnalyserEfficiency->execute();
TS_ASSERT(heliumAnalyserEfficiency->isExecuted());
Expand Down Expand Up @@ -290,7 +290,7 @@ class HeliumAnalyserEfficiencyTest : public CxxTest::TestSuite {
MantidVec expectedEfficiencies;
auto wsGrp = createExampleGroupWorkspace("wsGrp", expectedEfficiencies);
auto heliumAnalyserEfficiency = createHeliumAnalyserEfficiencyAlgorithm(wsGrp, "E");
heliumAnalyserEfficiency->setProperty("GasPressureTimesCellLengthError", pdError);
heliumAnalyserEfficiency->setProperty("PXDError", pdError);
heliumAnalyserEfficiency->execute();

TS_ASSERT(heliumAnalyserEfficiency->isExecuted());
Expand Down
6 changes: 3 additions & 3 deletions docs/source/algorithms/HeliumAnalyserEfficiency-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Description
-----------

Takes a normalised group workspace and combines this with the cell path length multiplied by the gas pressure (``GasPressureTimesCellLength``)
Takes a normalised group workspace and combines this with the cell path length multiplied by the gas pressure (``PXD``)
to calculate the efficiency of the analyser. The input workspace must be a group of four single spectrum histogram workspaces, each
representing the transmission of a known spin state as specified by the ``SpinStates`` parameter.

Expand All @@ -26,12 +26,12 @@ The efficiency of the analyser cell is given by
If our four periods are :math:`T_{00}, T_{01}, T_{10}, T_{11}`, with the subscript denoting the spin configuration, then
:math:`T_{para} = T_{00} + T_{11}` and :math:`T_{anti} = T_{01} + T_{10}`, and we can calculate :math:`\epsilon_{cell}` from the above equation.
The value of :math:`pd` is given by the input ``GasPressureTimesCellLength``, and :math:`\lambda` is the wavelength of each bin, so we fit
The value of :math:`pd` is given by the input ``PXD``, and :math:`\lambda` is the wavelength of each bin, so we fit
:math:`\frac{1 + \tanh(0.0733 p d \lambda p_{He})}{2}` to our calculated :math:`\epsilon_{cell}` to give us :math:`p_{He}` and hence the
theoretical efficiency curve.

To calculate the error, :math:`\sigma_{\epsilon_{cell}}`, we need the error on :math:`p_{He}`, :math:`\sigma_{p_{He}}`, and
the error of :math:`pd`, :math:`\sigma_{pd}`, given by ``GasPressureTimesCellLengthError``. The covariance between :math:`pd` and :math:`p_{He}`
the error of :math:`pd`, :math:`\sigma_{pd}`, given by ``PXDError``. The covariance between :math:`pd` and :math:`p_{He}`
is assumed to be zero. Then the error :math:`\sigma_{\epsilon_{cell}}` is given by

.. math::
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The following parameter names in :ref:`algm-HeliumAnalyserEfficiency` have been updated for consistency: `GasPressureTimesCellLength` is now `PxD`, `GasPressureTimesCellLengthError` is now `PXDError`, `StartLambda` is now `StartX`, and `EndLambda` is now `EndX`. Any scripts using the old names will need to be updated.

0 comments on commit 7b21a39

Please sign in to comment.