Mantid
Loading...
Searching...
No Matches
PolarizationEfficienciesWildes.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2024 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
9#include "MantidAPI/Axis.h"
10#include "MantidAPI/Progress.h"
16#include "MantidKernel/Unit.h"
17#include <cmath>
18
19namespace {
21namespace PropNames {
22auto constexpr INPUT_NON_MAG_WS{"InputNonMagWorkspace"};
23auto constexpr INPUT_MAG_WS{"InputMagWorkspace"};
24auto constexpr FLIPPERS{"Flippers"};
25auto constexpr INPUT_P_EFF_WS{"InputPolarizerEfficiency"};
26auto constexpr INPUT_A_EFF_WS{"InputAnalyserEfficiency"};
27auto constexpr OUTPUT_P_EFF_WS{"OutputPolarizerEfficiency"};
28auto constexpr OUTPUT_F_P_EFF_WS{"OutputFpEfficiency"};
29auto constexpr OUTPUT_F_A_EFF_WS{"OutputFaEfficiency"};
30auto constexpr OUTPUT_A_EFF_WS{"OutputAnalyserEfficiency"};
31auto constexpr OUTPUT_PHI_WS{"OutputPhi"};
32auto constexpr OUTPUT_RHO_WS{"OutputRho"};
33auto constexpr OUTPUT_ALPHA_WS{"OutputAlpha"};
34auto constexpr OUTPUT_TPMO_WS{"OutputTwoPMinusOne"};
35auto constexpr OUTPUT_TAMO_WS{"OutputTwoAMinusOne"};
36auto constexpr INCLUDE_DIAGNOSTICS{"IncludeDiagnosticOutputs"};
37
38auto constexpr OUTPUT_EFF_GROUP{"Efficiency Outputs"};
39auto constexpr OUTPUT_DIAGNOSTIC_GROUP{"Diagnostic Outputs"};
40} // namespace PropNames
41
42auto constexpr INPUT_EFF_WS_ERROR{
43 "If a magnetic workspace group has been provided then input efficiency workspaces should not be provided."};
44auto constexpr INITIAL_CONFIG{"00,01,10,11"};
45auto constexpr MAG_KEY_PREFIX = "mag_";
46
47constexpr auto fnPhi = [](const auto &x) { return ((x[0] - x[1]) * (x[0] - x[2])) / (x[0] * x[3] - x[1] * x[2]); };
48constexpr auto fnFp = [](const auto &x) { return (x[0] - x[1] - x[2] + x[3]) / (2 * (x[0] - x[1])); };
49constexpr auto fnFa = [](const auto &x) { return (x[0] - x[1] - x[2] + x[3]) / (2 * (x[0] - x[2])); };
50constexpr auto fnNumerator = [](const auto &x, const auto &fa) {
51 return (1 - 2 * fa) * x[4] + (2 * fa - 1) * x[6] - x[5] + x[7];
52};
53constexpr auto fnDenominator = [](const auto &x, const auto &fp) {
54 return (1 - 2 * fp) * x[4] + (2 * fp - 1) * x[5] - x[6] + x[7];
55};
56
57constexpr size_t INDEPENDENT_INTENSITY_VAR_COUNT = 4;
58constexpr size_t DERIVED_EFFICIENCY_VAR_COUNT = 1;
59constexpr size_t DERIVED_EFFICIENCY_INPUT_INDEX = INDEPENDENT_INTENSITY_VAR_COUNT;
60constexpr size_t EFFICIENCY_FROM_DERIVED_INPUT_VAR_COUNT =
61 INDEPENDENT_INTENSITY_VAR_COUNT + DERIVED_EFFICIENCY_VAR_COUNT;
62
63// When one efficiency is supplied and the other is solved from phi = (2p - 1)(2a - 1)
64// we need to account for the covariance between the derived efficiency and the non-magnetic intensities.
65// We provide the covariance matrix provider with a function to calculate the derived efficiency from the provided
66// intensities so the differential can be calculated. This function includes the unknown value of the efficiency to be
67// calculated, so for each bin we solve for this from the known values.
68auto covarianceMatrixProviderForDerivedEfficiency() {
69 return Mantid::Algorithms::Arithmetic::makeCovarianceMatrixProvider<INDEPENDENT_INTENSITY_VAR_COUNT,
70 DERIVED_EFFICIENCY_VAR_COUNT>(
71 [](const auto &inputs) {
72 const auto phi = fnPhi(inputs);
73 const double suppliedEfficiency = inputs[DERIVED_EFFICIENCY_INPUT_INDEX].value();
74 const double unknownEfficiency = 0.5 + (1 / (4 * suppliedEfficiency - 2)) * phi.value();
75 return 0.5 + (1 / (4 * unknownEfficiency - 2)) * phi;
76 });
77}
78} // namespace
79
80namespace Mantid::Algorithms {
81
82using namespace API;
83using namespace Kernel;
85
86// Register the algorithm in the AlgorithmFactory
87DECLARE_ALGORITHM(PolarizationEfficienciesWildes)
88
89std::string const PolarizationEfficienciesWildes::summary() const {
90 return "Calculates the efficiencies of the polarizer, flippers and the analyser for a two-flipper instrument setup.";
91}
92
95 std::make_unique<WorkspaceProperty<WorkspaceGroup>>(PropNames::INPUT_NON_MAG_WS, "", Direction::Input),
96 "Group workspace containing the transmission measurements for the non-magnetic sample");
97 declareProperty(std::make_unique<WorkspaceProperty<WorkspaceGroup>>(PropNames::INPUT_MAG_WS, "", Direction::Input,
99 "Group workspace containing the transmission measurements for the magnetic sample.");
100 const auto spinValidator = std::make_shared<SpinStateValidator>(std::unordered_set<int>{4});
101 declareProperty(PropNames::FLIPPERS, INITIAL_CONFIG, spinValidator,
102 "Flipper configurations of the input group workspace(s).");
103 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::INPUT_P_EFF_WS, "", Direction::Input,
105 "Workspace containing the known wavelength-dependent efficiency for the polarizer.");
106 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::INPUT_A_EFF_WS, "", Direction::Input,
108 "Workspace containing the known wavelength-dependent efficiency for the analyser.");
110 std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_F_P_EFF_WS, "", Direction::Output),
111 "Output workspace containing the polarizing flipper efficiencies");
113 std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_F_A_EFF_WS, "", Direction::Output),
114 "Output workspace containing the analysing flipper efficiencies");
115 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_P_EFF_WS, "",
117 "Output workspace containing the polarizer efficiencies.");
118 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_A_EFF_WS, "",
120 "Output workspace containing the analyser efficiencies.");
121 declareProperty(PropNames::INCLUDE_DIAGNOSTICS, false, "Whether to include additional diagnostic outputs.");
122 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_PHI_WS, "phi",
124 "Output workspace containing the values for Phi.");
125 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_RHO_WS, "rho",
127 "Output workspace containing the values for Rho.");
128 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_ALPHA_WS, "alpha",
130 "Output workspace containing the values for Alpha.");
131 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_TPMO_WS, "two_p_minus_one",
133 "Output workspace containing the values for the term (2p-1).");
134 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>(PropNames::OUTPUT_TAMO_WS, "two_a_minus_one",
136 "Output workspace containing the values for the term (2a-1).");
137
138 auto makeSettingIncludeDiagnosticsIsSelected = [] {
139 return std::make_unique<Kernel::EnabledWhenProperty>(PropNames::INCLUDE_DIAGNOSTICS, IS_EQUAL_TO, "1");
140 };
141
142 setPropertySettings(PropNames::OUTPUT_PHI_WS, makeSettingIncludeDiagnosticsIsSelected());
143 setPropertySettings(PropNames::OUTPUT_RHO_WS, makeSettingIncludeDiagnosticsIsSelected());
144 setPropertySettings(PropNames::OUTPUT_ALPHA_WS, makeSettingIncludeDiagnosticsIsSelected());
145 setPropertySettings(PropNames::OUTPUT_TPMO_WS, makeSettingIncludeDiagnosticsIsSelected());
146 setPropertySettings(PropNames::OUTPUT_TAMO_WS, makeSettingIncludeDiagnosticsIsSelected());
147
148 const auto &effOutputGroup = PropNames::OUTPUT_EFF_GROUP;
149 setPropertyGroup(PropNames::OUTPUT_P_EFF_WS, effOutputGroup);
150 setPropertyGroup(PropNames::OUTPUT_F_P_EFF_WS, effOutputGroup);
151 setPropertyGroup(PropNames::OUTPUT_F_A_EFF_WS, effOutputGroup);
152 setPropertyGroup(PropNames::OUTPUT_A_EFF_WS, effOutputGroup);
153
154 const auto &diagnosticOutputGroup = PropNames::OUTPUT_DIAGNOSTIC_GROUP;
155 setPropertyGroup(PropNames::OUTPUT_PHI_WS, diagnosticOutputGroup);
156 setPropertyGroup(PropNames::OUTPUT_RHO_WS, diagnosticOutputGroup);
157 setPropertyGroup(PropNames::OUTPUT_ALPHA_WS, diagnosticOutputGroup);
158 setPropertyGroup(PropNames::OUTPUT_TPMO_WS, diagnosticOutputGroup);
159 setPropertyGroup(PropNames::OUTPUT_TAMO_WS, diagnosticOutputGroup);
160}
161
162namespace {
164 const std::string &propertyName, std::map<std::string, std::string> &problems) {
165 if (!WorkspaceHelpers::matchingBins(workspace, refWs, true)) {
166 problems[propertyName] = "All input workspaces must have the same X values.";
167 return false;
168 }
169
170 return true;
171}
172
173bool isValidInputWorkspace(const Mantid::API::MatrixWorkspace_sptr &workspace,
174 const Mantid::API::MatrixWorkspace_sptr &refWs, const std::string &propertyName,
175 std::map<std::string, std::string> &problems) {
176 if (workspace == nullptr) {
177 problems[propertyName] = "All input workspaces must be matrix workspaces.";
178 return false;
179 }
180
181 Kernel::Unit_const_sptr unit = workspace->getAxis(0)->unit();
182 if (unit->unitID() != "Wavelength") {
183 problems[propertyName] = "All input workspaces must be in units of Wavelength.";
184 return false;
185 }
186
187 if (workspace->getNumberHistograms() != 1) {
188 problems[propertyName] = "All input workspaces must contain only a single spectrum.";
189 return false;
190 }
191
192 return hasMatchingBins(workspace, refWs, propertyName, problems);
193}
194
195bool isValidInputWSGroup(const Mantid::API::WorkspaceGroup_sptr &groupWs, const std::string &propertyName,
196 std::map<std::string, std::string> &problems) {
197 if (groupWs == nullptr) {
198 problems[propertyName] = "The input workspace must be a group workspace.";
199 return false;
200 }
201
202 if (groupWs->size() != 4) {
203 problems[propertyName] = "The input group must contain a workspace for all four flipper configurations.";
204 return false;
205 }
206
207 const MatrixWorkspace_sptr refWs = std::dynamic_pointer_cast<MatrixWorkspace>(groupWs->getItem(0));
208 for (size_t i = 0; i < groupWs->size(); ++i) {
209 const MatrixWorkspace_sptr childWs = std::dynamic_pointer_cast<MatrixWorkspace>(groupWs->getItem(i));
210 if (!isValidInputWorkspace(childWs, refWs, propertyName, problems)) {
211 return false;
212 }
213 }
214
215 return true;
216}
217} // namespace
218
219std::map<std::string, std::string> PolarizationEfficienciesWildes::validateInputs() {
220 std::map<std::string, std::string> problems;
221
222 const bool hasMagWsGrp = !isDefault(PropNames::INPUT_MAG_WS);
223 const bool hasInputPWs = !isDefault(PropNames::INPUT_P_EFF_WS);
224 const bool hasInputAWs = !isDefault(PropNames::INPUT_A_EFF_WS);
225
226 if (!isDefault(PropNames::OUTPUT_P_EFF_WS) && !hasMagWsGrp && !hasInputPWs && !hasInputAWs) {
227 problems[PropNames::OUTPUT_P_EFF_WS] = "If output polarizer efficiency is requested then either the magnetic "
228 "workspace or the known analyser efficiency should be provided.";
229 }
230
231 if (!isDefault(PropNames::OUTPUT_A_EFF_WS) && !hasMagWsGrp && !hasInputPWs && !hasInputAWs) {
232 problems[PropNames::OUTPUT_A_EFF_WS] = "If output analyser efficiency is requested then either the magnetic "
233 "workspace or the known polarizer efficiency should be provided.";
234 }
235
236 const WorkspaceGroup_sptr nonMagWsGrp = getProperty(PropNames::INPUT_NON_MAG_WS);
237 if (!isValidInputWSGroup(nonMagWsGrp, PropNames::INPUT_NON_MAG_WS, problems)) {
238 // We need to use a child workspace from the nonMag group as a reference for later checks, so stop here if there are
239 // any issues with this input
240 return problems;
241 }
242
243 const MatrixWorkspace_sptr nonMagRefWs = std::dynamic_pointer_cast<MatrixWorkspace>(nonMagWsGrp->getItem(0));
244
245 // If a magnetic workspace has been provided then we will use that to calculate the polarizer and analyser
246 // efficiencies, so individual efficiency workspaces should not be provided as well
247 if (hasMagWsGrp) {
248 if (hasInputPWs) {
249 problems[PropNames::INPUT_P_EFF_WS] = INPUT_EFF_WS_ERROR;
250 }
251
252 if (hasInputAWs) {
253 problems[PropNames::INPUT_A_EFF_WS] = INPUT_EFF_WS_ERROR;
254 }
255
256 const WorkspaceGroup_sptr magWsGrp = getProperty(PropNames::INPUT_MAG_WS);
257 if (isValidInputWSGroup(magWsGrp, PropNames::INPUT_MAG_WS, problems)) {
258 // Check that bins match between the input mag and nonMag workspace groups
259 const MatrixWorkspace_sptr magWs = std::dynamic_pointer_cast<MatrixWorkspace>(magWsGrp->getItem(0));
260 hasMatchingBins(magWs, nonMagRefWs, PropNames::INPUT_MAG_WS, problems);
261 }
262 } else {
263 if (hasInputPWs) {
264 const MatrixWorkspace_sptr inputPolEffWs = getProperty(PropNames::INPUT_P_EFF_WS);
265 isValidInputWorkspace(inputPolEffWs, nonMagRefWs, PropNames::INPUT_P_EFF_WS, problems);
266 }
267
268 if (hasInputAWs) {
269 const MatrixWorkspace_sptr inputAnaEffWs = getProperty(PropNames::INPUT_A_EFF_WS);
270 isValidInputWorkspace(inputAnaEffWs, nonMagRefWs, PropNames::INPUT_A_EFF_WS, problems);
271 }
272 }
273
274 return problems;
275}
276
278 Progress progress(this, 0.0, 1.0, 10);
279 progress.report(0, "Extracting spin state workspaces");
281
282 progress.report(1, "Calculating flipper efficiencies");
284
285 const bool solveForP = !isDefault(PropNames::OUTPUT_P_EFF_WS);
286 const bool solveForA = !isDefault(PropNames::OUTPUT_A_EFF_WS);
287 if (solveForP || solveForA) {
288 progress.report(4, "Finding polarizer and analyser efficiencies");
289 calculatePolarizerAndAnalyserEfficiencies(solveForP, solveForA);
290 }
291
292 progress.report(8, "Setting algorithm outputs");
293 setOutputs();
294
295 // Ensure that we don't carry over values from a previous run if an instance of this algorithm is run twice
297}
298
300 // Calculate the polarizing and analysing flipper efficiencies
301 const auto &[ws00, ws01, ws10, ws11] = getFlipperWorkspaces();
302
303 constexpr int var_num = 4;
304 // Calculate fp
305 const auto errorPropFp = Arithmetic::makeErrorPropagation<var_num>([](const auto &x) { return fnFp(x); });
306 m_wsFp = errorPropFp.evaluateWorkspaces(true, ws00, ws01, ws10, ws11);
307
308 // Calculate fa
309 const auto errorPropFa = Arithmetic::makeErrorPropagation<var_num>([](const auto &x) { return fnFa(x); });
310 m_wsFa = errorPropFa.evaluateWorkspaces(true, ws00, ws01, ws10, ws11);
311
312 // Calculate phi
313 const auto errorPropPhi = Arithmetic::makeErrorPropagation<var_num>([](const auto &x) { return fnPhi(x); });
314 m_wsPhi = errorPropPhi.evaluateWorkspaces(true, ws00, ws01, ws10, ws11);
315}
316
318 const auto &[ws00, ws01, ws10, ws11] = getFlipperWorkspaces();
319 const auto &[ws00Mag, ws01Mag, ws10Mag, ws11Mag] = getFlipperWorkspaces(true);
320
321 constexpr int var_num = 8;
322 const auto errorProp = Arithmetic::makeErrorPropagation<var_num>([](const auto &x) {
323 const auto fp = fnFp(x);
324 const auto fa = fnFa(x);
325 const auto numerator = fnNumerator(x, fa);
326 const auto denominator = fnDenominator(x, fp);
327 return sqrt(fnPhi(x) * (numerator / denominator));
328 });
329 const auto outWs = errorProp.evaluateWorkspaces(true, ws00, ws01, ws10, ws11, ws00Mag, ws01Mag, ws10Mag, ws11Mag);
330 return outWs;
331}
332
334 const bool solveForA) {
335 const auto &[ws00, ws01, ws10, ws11] = getFlipperWorkspaces();
336 if (m_magWsProvided) {
337 const auto &[ws00Mag, ws01Mag, ws10Mag, ws11Mag] = getFlipperWorkspaces(true);
338 constexpr int var_num = 8;
339 const MatrixWorkspace_sptr wsTPMO = calculateTPMO();
340
341 if (solveForP) {
342 m_wsP = (wsTPMO + 1) / 2;
343 }
344
345 if (solveForA) {
346 const auto errorProp = Arithmetic::makeErrorPropagation<var_num>([](const auto &x) {
347 const auto phi = fnPhi(x);
348 const auto fp = fnFp(x);
349 const auto fa = fnFa(x);
350 const auto numerator = fnNumerator(x, fa);
351 const auto denominator = fnDenominator(x, fp);
352 const auto TPMO = sqrt(phi * (numerator / denominator));
353 return (phi / (2 * TPMO)) + 0.5;
354 });
355 m_wsA = errorProp.evaluateWorkspaces(true, ws00, ws01, ws10, ws11, ws00Mag, ws01Mag, ws10Mag, ws11Mag);
356 }
357
358 return;
359 }
360
361 if (solveForP) {
362 if (const MatrixWorkspace_sptr inWsP = getProperty(PropNames::INPUT_P_EFF_WS)) {
363 m_wsP = inWsP->clone();
364 } else {
365 const MatrixWorkspace_sptr inWsA = getProperty(PropNames::INPUT_A_EFF_WS);
366 const auto errorProp =
367 Arithmetic::makeErrorPropagation<EFFICIENCY_FROM_DERIVED_INPUT_VAR_COUNT>([](const auto &inputValues) {
368 const auto suppliedEfficiencyFactor = (2 * inputValues[DERIVED_EFFICIENCY_INPUT_INDEX]) - 1;
369 return (fnPhi(inputValues) / (2 * suppliedEfficiencyFactor)) + 0.5;
370 });
371 m_wsP = errorProp.evaluateWorkspacesWithCovariance(true, covarianceMatrixProviderForDerivedEfficiency(), ws00,
372 ws01, ws10, ws11, inWsA);
373 }
374 }
375
376 if (solveForA) {
377 if (const MatrixWorkspace_sptr inWsA = getProperty(PropNames::INPUT_A_EFF_WS)) {
378 m_wsA = inWsA->clone();
379 } else {
380 const MatrixWorkspace_sptr inWsP = getProperty(PropNames::INPUT_P_EFF_WS);
381 const auto errorProp =
382 Arithmetic::makeErrorPropagation<EFFICIENCY_FROM_DERIVED_INPUT_VAR_COUNT>([](const auto &inputValues) {
383 const auto suppliedEfficiencyFactor = (2 * inputValues[DERIVED_EFFICIENCY_INPUT_INDEX]) - 1;
384 return (fnPhi(inputValues) / (2 * suppliedEfficiencyFactor)) + 0.5;
385 });
386 m_wsA = errorProp.evaluateWorkspacesWithCovariance(true, covarianceMatrixProviderForDerivedEfficiency(), ws00,
387 ws01, ws10, ws11, inWsP);
388 }
389 }
390}
391
393 setProperty(PropNames::OUTPUT_F_P_EFF_WS, m_wsFp);
394 setProperty(PropNames::OUTPUT_F_A_EFF_WS, m_wsFa);
395
396 if (m_wsP != nullptr) {
397 setProperty(PropNames::OUTPUT_P_EFF_WS, m_wsP);
398 }
399
400 if (m_wsA != nullptr) {
401 setProperty(PropNames::OUTPUT_A_EFF_WS, m_wsA);
402 }
403
404 if (getProperty(PropNames::INCLUDE_DIAGNOSTICS)) {
405 setProperty(PropNames::OUTPUT_PHI_WS, m_wsPhi);
406
407 const auto wsRho = (2 * m_wsFp) - 1;
408 setProperty(PropNames::OUTPUT_RHO_WS, wsRho);
409
410 const auto wsAlpha = (2 * m_wsFa) - 1;
411 setProperty(PropNames::OUTPUT_ALPHA_WS, wsAlpha);
412
413 if (m_wsP != nullptr) {
414 const auto wsTPMO = (2 * m_wsP) - 1;
415 setProperty(PropNames::OUTPUT_TPMO_WS, wsTPMO);
416 } else if (isChild()) {
417 // Clear diagnostic output property that may have been populated in a previous run as a child algorithm
418 resetPropertyValue(PropNames::OUTPUT_TPMO_WS);
419 }
420
421 if (m_wsA != nullptr) {
422 const auto wsTAMO = (2 * m_wsA) - 1;
423 setProperty(PropNames::OUTPUT_TAMO_WS, wsTAMO);
424 } else if (isChild()) {
425 // Clear diagnostic output property that may have been populated in a previous run as a child algorithm
426 resetPropertyValue(PropNames::OUTPUT_TAMO_WS);
427 }
428 } else if (isChild()) {
429 // Clear diagnostic output properties that may have been populated in a previous run as a child algorithm
430 resetPropertyValue(PropNames::OUTPUT_PHI_WS);
431 resetPropertyValue(PropNames::OUTPUT_RHO_WS);
432 resetPropertyValue(PropNames::OUTPUT_ALPHA_WS);
433 resetPropertyValue(PropNames::OUTPUT_TPMO_WS);
434 resetPropertyValue(PropNames::OUTPUT_TAMO_WS);
435 }
436}
437
439 m_wsFp = nullptr;
440 m_wsFa = nullptr;
441 m_wsPhi = nullptr;
442 m_wsP = nullptr;
443 m_wsA = nullptr;
444 m_magWsProvided = false;
445 m_spinStateWorkspaces.clear();
446}
447
448void PolarizationEfficienciesWildes::resetPropertyValue(const std::string &propertyName) {
449 setPropertyValue(propertyName, getPropertyValue(propertyName));
450}
451
453 const std::string &keyPrefix) {
454 const auto &flipperConfig = getPropertyValue(PropNames::FLIPPERS);
456 workspaceForSpinState(wsGrp, flipperConfig, FlipperConfigurations::OFF_OFF));
458 workspaceForSpinState(wsGrp, flipperConfig, FlipperConfigurations::OFF_ON));
460 workspaceForSpinState(wsGrp, flipperConfig, FlipperConfigurations::ON_OFF));
462 workspaceForSpinState(wsGrp, flipperConfig, FlipperConfigurations::ON_ON));
463}
464
466 const WorkspaceGroup_sptr magWsGrp = getProperty(PropNames::INPUT_MAG_WS);
467 const WorkspaceGroup_sptr nonMagWsGrp = getProperty(PropNames::INPUT_NON_MAG_WS);
468 if (magWsGrp) {
469 m_magWsProvided = true;
470 populateSpinStateWorkspaces(magWsGrp, MAG_KEY_PREFIX);
471 }
472 populateSpinStateWorkspaces(nonMagWsGrp);
473}
474
486
487} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:542
IPeaksWorkspace_sptr workspace
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
bool isChild() const override
To query whether algorithm is a child.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
bool isDefault(const std::string &name) const
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
Helper class for reporting progress from algorithms.
Definition Progress.h:25
A property class for workspaces.
void resetPropertyValue(const std::string &propertyName)
Sets the property value to its current value.
void resetMemberVariables()
Clear the values for all the algorithm member variables.
void exec() override
Execute the algorithm with the provided properties.
void mapSpinStateWorkspaces()
Populates the spin state workspaces map.
void populateSpinStateWorkspaces(const WorkspaceGroup_sptr &wsGrp, const std::string &keyPrefix="")
Populates the spin state workspaces map from ws group given key prefix.
MatrixWorkspace_sptr calculateTPMO()
Calculate (2p-1) from intensities.
void calculatePolarizerAndAnalyserEfficiencies(const bool solveForP, const bool solveForA)
Calculate the polarizer and/or analyser efficiencies, as requested.
void init() override
Setup the algorithm's properties and prepare constants.
std::map< std::string, std::string > validateInputs() override
Check that the inputs to the algorithm are valid.
FlipperWorkspaces getFlipperWorkspaces(const bool mag=false)
Access flipper workspaces in the spin state workspaces map.
std::unordered_map< std::string, MatrixWorkspace_sptr > m_spinStateWorkspaces
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings const > settings)
Add a PropertySettings instance to the chain of settings for a given property.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
auto makeCovarianceMatrixProvider(DependentFuncs &&...dependentFuncs)
MANTID_ALGORITHMS_DLL API::MatrixWorkspace_sptr workspaceForSpinState(const API::WorkspaceGroup_sptr &group, const std::string &spinStateOrder, const std::string &targetSpinState)
Returns the workspace in the group associated with the given targetSpinState according to the order d...
std::shared_ptr< const Unit > Unit_const_sptr
Shared pointer to the Unit base class (const version)
Definition Unit.h:196
STL namespace.
static bool matchingBins(const std::shared_ptr< const MatrixWorkspace > &ws1, const std::shared_ptr< const MatrixWorkspace > &ws2, const bool firstOnly=false)
Checks whether the bins (X values) of two workspace are the same.
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54