Mantid
Loading...
Searching...
No Matches
DgsRemap.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
10
11using namespace Mantid::Kernel;
12using namespace Mantid::API;
13using namespace Mantid::DataObjects;
14
16
17// Register the algorithm into the AlgorithmFactory
18DECLARE_ALGORITHM(DgsRemap)
19
20//----------------------------------------------------------------------------------------------
22const std::string DgsRemap::name() const { return "DgsRemap"; }
23
25int DgsRemap::version() const { return 1; }
26
28const std::string DgsRemap::category() const { return "Workflow\\Inelastic"; }
29
30//----------------------------------------------------------------------------------------------
31
32//----------------------------------------------------------------------------------------------
36 this->declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
37 "An input workspace to mask and group.");
38 this->declareProperty(
39 std::make_unique<WorkspaceProperty<>>("MaskWorkspace", "", Direction::Input, PropertyMode::Optional),
40 "A workspace containing masking information.");
41 this->declareProperty(
42 std::make_unique<WorkspaceProperty<>>("GroupingWorkspace", "", Direction::Input, PropertyMode::Optional),
43 "A workspace containing grouping information");
44 this->declareProperty(std::make_unique<FileProperty>("OldGroupingFile", "", FileProperty::OptionalLoad),
45 "Name of an old grouping format (not XML) file.");
46 this->declareProperty("ExecuteOppositeOrder", false, "Execute grouping before masking.");
47 this->declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
48 "The resulting workspace.");
49}
50
51//----------------------------------------------------------------------------------------------
55 MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
56 MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");
57
58 bool runOpposite = this->getProperty("ExecuteOppositeOrder");
59 if (!runOpposite) {
60 this->execMasking(inputWS);
61 this->execGrouping(inputWS, outputWS);
62 } else {
63 this->execGrouping(inputWS, outputWS);
64 this->execMasking(inputWS);
65 }
66
67 this->setProperty("OutputWorkspace", outputWS);
68}
69
71 MatrixWorkspace_sptr maskWS = this->getProperty("MaskWorkspace");
72 if (maskWS) {
73 auto mask = createChildAlgorithm("MaskDetectors");
74 mask->setProperty("Workspace", iWS);
75 mask->setProperty("MaskedWorkspace", maskWS);
76 mask->executeAsChildAlg();
77 }
78}
79
81 MatrixWorkspace_sptr groupWS = this->getProperty("GroupingWorkspace");
82 std::string oldGroupingFile = this->getProperty("OldGroupingFile");
83 if (groupWS && !oldGroupingFile.empty()) {
84 throw std::runtime_error("Choose either GroupingWorkspace or OldGroupingFile property!");
85 }
86
87 if (groupWS || !oldGroupingFile.empty()) {
88 auto group = createChildAlgorithm("GroupDetectors");
89 group->setProperty("InputWorkspace", iWS);
90 group->setProperty("OutputWorkspace", iWS);
91 if (groupWS) {
92 int64_t ngroups = 0;
93 std::vector<int> groupDetIdList;
94 GroupingWorkspace_sptr gWS = std::dynamic_pointer_cast<GroupingWorkspace>(groupWS);
95 gWS->makeDetectorIDToGroupVector(groupDetIdList, ngroups);
96 group->setProperty("DetectorList", groupDetIdList);
97 }
98 if (!oldGroupingFile.empty()) {
99 group->setProperty("MapFile", oldGroupingFile);
100 }
101 group->setProperty("Behaviour", "Average");
102 group->executeAsChildAlg();
103 oWS = group->getProperty("OutputWorkspace");
104 }
105}
106
107} // namespace Mantid::WorkflowAlgorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
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.
Definition: Algorithm.cpp:842
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
Definition: FileProperty.h:53
A property class for workspaces.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
DgsRemap : This algorithm takes a workspace and masks and groups that workspace if appropriate inform...
Definition: DgsRemap.h:19
void init() override
Initialize the algorithm's properties.
Definition: DgsRemap.cpp:35
int version() const override
Algorithm's version for identification.
Definition: DgsRemap.cpp:25
const std::string category() const override
Algorithm's category for identification.
Definition: DgsRemap.cpp:28
void execGrouping(const API::MatrixWorkspace_sptr &iWS, API::MatrixWorkspace_sptr &oWS)
Definition: DgsRemap.cpp:80
void exec() override
Execute the algorithm.
Definition: DgsRemap.cpp:54
void execMasking(const API::MatrixWorkspace_sptr &iWS)
Definition: DgsRemap.cpp:70
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< GroupingWorkspace > GroupingWorkspace_sptr
shared pointer to the GroupingWorkspace class
STL namespace.
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54