25using namespace Kernel;
43 "An input event workspace.");
45 "An output event workspace.");
46 declareProperty(
"CreateMaskWorkspace",
true,
"Determines if masked workspace needs to be created.");
48 "The parameter that is used to scale the standard deviation in order to set the masking threshold of "
49 "the low angle bank.");
51 "The parameter that is used to scale the standard deviation in order to set the masking threshold of "
52 "the high angle bank.");
53 declareProperty(
"ApplyMaskDirectlyToWorkspace",
false,
"Determines if mask is directly applied to workspace.");
55 "Path to the detector mask XML file. It must be provided for the algorithm to create the xml file.");
61 return std::accumulate(values.begin(), values.end(), 0.0) /
static_cast<double>(values.size());
67 double m =
mean(values);
68 double accum = std::accumulate(values.begin(), values.end(), 0.0, [
m](
double total,
double x) {
69 const double diff = x - m;
70 return total + diff * diff;
72 return std::sqrt(accum /
static_cast<double>(values.size()));
78 std::transform(values.begin(), values.end(), values.begin(), [factor](
double x) { return x * factor; });
82 std::map<std::string, std::string> result;
85 const size_t nHist = inputWS->getNumberHistograms();
87 result[
"InputWorkspace"] =
"Expected an EventWorkspace with exactly 17776 histograms "
88 "for SANS ISIS reduction of LOQ.";
109 std::span<double> valuesSpan(values);
115 const size_t nHist = inputWS->getNumberHistograms();
116 for (
size_t i = 0; i < nHist; ++i) {
117 auto &
Y = outputWS->mutableY(i);
118 Y[0] = valuesSpan[i];
135 const double normStdLAB =
stddev(LAB);
136 const double normStdHAB =
stddev(HAB);
150 return {normStdLAB, normStdHAB};
154 const size_t nHist = ws->getNumberHistograms();
155 std::vector<double> values;
156 values.reserve(nHist);
157 for (
size_t i = 0; i < nHist; ++i) {
158 const auto &
Y = ws->readY(i);
159 values.insert(values.end(),
Y.cbegin(),
Y.cend());
166 integration->initialize();
167 integration->setProperty(
"InputWorkspace", ws);
168 integration->setProperty(
"OutputWorkspace",
"processedWS");
171 integration->execute();
172 return integration->getProperty(
"OutputWorkspace");
180 double labThresholdMultiplier =
getProperty(
"LABThresholdMultiplier");
181 double habThresholdMultiplier =
getProperty(
"HABThresholdMultiplier");
182 const double maskingThresholdLAB = 1.0 + (labThresholdMultiplier * normStdLAB);
183 const double maskingThresholdHAB = 1.0 + (habThresholdMultiplier * normStdHAB);
187 maskDetectorsLAB->initialize();
188 maskDetectorsLAB->setProperty(
"InputWorkspace", directMaskWS);
189 maskDetectorsLAB->setProperty(
"OutputWorkspace", directMaskWS);
192 maskDetectorsLAB->setProperty(
"Operator",
"GreaterEqual");
193 maskDetectorsLAB->setProperty(
"Value", maskingThresholdLAB);
194 maskDetectorsLAB->execute();
198 maskDetectorsHAB->initialize();
199 maskDetectorsHAB->setProperty(
"InputWorkspace", directMaskWS);
200 maskDetectorsHAB->setProperty(
"OutputWorkspace", directMaskWS);
202 maskDetectorsHAB->setProperty(
"Operator",
"GreaterEqual");
203 maskDetectorsHAB->setProperty(
"Value", maskingThresholdHAB);
204 maskDetectorsHAB->execute();
209 extractMask->initialize();
210 extractMask->setProperty(
"InputWorkspace", directMaskWS);
211 extractMask->setProperty(
"OutputWorkspace", maskName);
212 extractMask->execute();
217 std::string outputMaskFilePath =
getProperty(
"OutputMaskFilePath");
219 saveMask->initialize();
220 saveMask->setProperty(
"InputWorkspace", extractedmaskWS);
221 saveMask->setProperty(
"OutputFile", outputMaskFilePath);
225 bool applyMaskDirectlyToWorkspace =
getProperty(
"ApplyMaskDirectlyToWorkspace");
226 if (applyMaskDirectlyToWorkspace) {
229 bool createMaskWorkspace =
getProperty(
"CreateMaskWorkspace");
230 if (createMaskWorkspace) {
231 AnalysisDataService::Instance().addOrReplace(maskName, extractedmaskWS);
#define DECLARE_ALGORITHM(classname)
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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
bool isDefault(const std::string &name) const
A property class for workspaces.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
void execEvent()
Execution code for EventWorkspaces.
API::MatrixWorkspace_sptr integrateInput(const API::Workspace_sptr &ws)
std::vector< double > extractIntegratedValues(const API::MatrixWorkspace_sptr &ws) const
void exec() override
Execution code.
void init() override
Initialisation code.
double stddev(std::span< double > values) const
Computes the standard deviation of the input span.
double mean(std::span< const double > values) const
Computes the mean of the input span.
FlatCellStats normalizeBanks(std::span< double > values) const
void scale(std::span< double > values, double factor) const
Scales each of the elements of the input vector.
void createAndSaveMaskWorkspace(const API::MatrixWorkspace_sptr &ws, double normStdLAB, double normStdHAB)
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
@ Input
An input workspace.
@ Output
An output workspace.