25using namespace Kernel;
44 "An input event workspace.");
46 "An output event workspace.");
47 declareProperty(
"CreateMaskWorkspace",
true,
"Determines if masked workspace needs to be created.");
49 "The parameter that is used to scale the standard deviation in order to set the masking threshold of "
50 "the low angle bank. The masking threshold is calculated by the equation "
51 "maskingThreshold = 1.0 + (LABThresholdMultiplier x standard deviation of the normalized LAB data);");
53 "The parameter that is used to scale the standard deviation in order to set the masking threshold of "
54 "the high angle bank. The masking threshold is calculated by the equation "
55 "maskingThreshold = 1.0 + (HABThresholdMultiplier x standard deviation of the normalized HAB data);");
56 declareProperty(
"ApplyMaskDirectlyToWorkspace",
false,
"Determines if mask is directly applied to workspace.");
58 "Path to the detector mask XML file. It must be provided for the algorithm to create the .xml file.");
60 "Path to the RKH file. It must be provided for the algorithm to create the .out file.");
66 return std::accumulate(values.begin(), values.end(), 0.0) /
static_cast<double>(values.size());
72 double m =
mean(values);
73 double accum = std::accumulate(values.begin(), values.end(), 0.0, [
m](
double total,
double x) {
74 const double diff = x - m;
75 return total + diff * diff;
77 return std::sqrt(accum /
static_cast<double>(values.size()));
83 std::transform(values.begin(), values.end(), values.begin(), [factor](
double x) { return x * factor; });
87 std::map<std::string, std::string> result;
90 const size_t nHist = inputWS->getNumberHistograms();
92 result[
"InputWorkspace"] =
"Expected an EventWorkspace with exactly 17776 histograms "
93 "for SANS ISIS reduction of LOQ.";
114 std::span<double> valuesSpan(values);
121 auto &
Y = outputWS->mutableY(i);
122 Y[0] = valuesSpan[i];
139 const double normStdLAB =
stddev(LAB);
140 const double normStdHAB =
stddev(HAB);
154 return {normStdLAB, normStdHAB};
158 const size_t nHist = ws->getNumberHistograms();
159 std::vector<double> values;
160 values.reserve(nHist);
161 for (
size_t i = 0; i < nHist; ++i) {
162 const auto &
Y = ws->readY(i);
163 values.insert(values.end(),
Y.cbegin(),
Y.cend());
170 integration->initialize();
171 integration->setProperty(
"InputWorkspace", ws);
172 integration->setProperty(
"OutputWorkspace",
"processedWS");
175 integration->execute();
176 return integration->getProperty(
"OutputWorkspace");
184 double labThresholdMultiplier =
getProperty(
"LABThresholdMultiplier");
185 double habThresholdMultiplier =
getProperty(
"HABThresholdMultiplier");
186 const double maskingThresholdLAB = 1.0 + (labThresholdMultiplier * normStdLAB);
187 const double maskingThresholdHAB = 1.0 + (habThresholdMultiplier * normStdHAB);
191 maskDetectorsLAB->initialize();
192 maskDetectorsLAB->setProperty(
"InputWorkspace", directMaskWS);
193 maskDetectorsLAB->setProperty(
"OutputWorkspace", directMaskWS);
196 maskDetectorsLAB->setProperty(
"Operator",
"GreaterEqual");
197 maskDetectorsLAB->setProperty(
"Value", maskingThresholdLAB);
198 maskDetectorsLAB->execute();
202 maskDetectorsHAB->initialize();
203 maskDetectorsHAB->setProperty(
"InputWorkspace", directMaskWS);
204 maskDetectorsHAB->setProperty(
"OutputWorkspace", directMaskWS);
206 maskDetectorsHAB->setProperty(
"Operator",
"GreaterEqual");
207 maskDetectorsHAB->setProperty(
"Value", maskingThresholdHAB);
208 maskDetectorsHAB->execute();
213 extractMask->initialize();
214 extractMask->setProperty(
"InputWorkspace", directMaskWS);
215 extractMask->setProperty(
"OutputWorkspace", maskName);
216 extractMask->execute();
221 std::string outputMaskFilePath =
getProperty(
"OutputMaskFilePath");
223 saveMask->initialize();
224 saveMask->setProperty(
"InputWorkspace", extractedmaskWS);
225 saveMask->setProperty(
"OutputFile", outputMaskFilePath);
229 bool createMaskWorkspace =
getProperty(
"CreateMaskWorkspace");
230 if (createMaskWorkspace) {
234 if (!
isDefault(
"OutputFlatCellFilePath")) {
245 conjoin->initialize();
246 conjoin->setProperty(
"InputWorkspace1", monitor_ws);
247 conjoin->setProperty(
"InputWorkspace2", ws);
248 conjoin->setProperty(
"CheckOverlapping",
false);
254 AnalysisDataService::Instance().addOrReplace(maskName, conjoinedWS);
260 bool applyMaskDirectlyToWorkspace =
getProperty(
"ApplyMaskDirectlyToWorkspace");
267 conjoin->initialize();
268 conjoin->setProperty(
"InputWorkspace1", monitor_ws);
269 if (applyMaskDirectlyToWorkspace) {
270 conjoin->setProperty(
"InputWorkspace2", ws);
272 conjoin->setProperty(
"InputWorkspace2", outputWS);
274 conjoin->setProperty(
"CheckOverlapping",
false);
285 std::string outputFlatCellFilePath =
getProperty(
"OutputFlatCellFilePath");
290 saveRKH->setProperty(
"InputWorkspace", outputWS);
291 saveRKH->setProperty(
"Filename", outputFlatCellFilePath);
292 saveRKH->setProperty(
"Append",
false);
#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 createDetectorMaskWorkspace(const API::MatrixWorkspace_sptr &ws)
void exec() override
Execution code.
void createFlatcellWorkspace(const API::MatrixWorkspace_sptr &ws)
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.