Mantid
Loading...
Searching...
No Matches
DgsProcessDetectorVanadium.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 +
14
15#include <boost/algorithm/string/predicate.hpp>
16
17using namespace Mantid::Kernel;
18using namespace Mantid::API;
19using namespace WorkflowAlgorithmHelpers;
20
22
23// Register the algorithm into the AlgorithmFactory
24DECLARE_ALGORITHM(DgsProcessDetectorVanadium)
25
26//----------------------------------------------------------------------------------------------
28const std::string DgsProcessDetectorVanadium::name() const { return "DgsProcessDetectorVanadium"; }
29
31int DgsProcessDetectorVanadium::version() const { return 1; }
32
34const std::string DgsProcessDetectorVanadium::category() const { return "Workflow\\Inelastic\\UsesPropertyManager"; }
35
36//----------------------------------------------------------------------------------------------
37
38//----------------------------------------------------------------------------------------------
42 // auto wsValidator = std::make_shared<CompositeValidator>();
43 // wsValidator->add<WorkspaceUnitValidator>("TOF");
44 this->declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
45 "An input workspace containing the detector vanadium data in TOF units.");
46 this->declareProperty(
47 std::make_unique<WorkspaceProperty<>>("InputMonitorWorkspace", "", Direction::Input, PropertyMode::Optional),
48 "A monitor workspace associated with the input workspace.");
49 this->declareProperty(
50 std::make_unique<WorkspaceProperty<>>("MaskWorkspace", "", Direction::Input, PropertyMode::Optional),
51 "A mask workspace");
52 this->declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
53 "The name for the output workspace.");
54 this->declareProperty("ReductionProperties", "__dgs_reduction_properties", Direction::Output);
55}
56
57//----------------------------------------------------------------------------------------------
61 g_log.notice() << "Starting DgsProcessDetectorVanadium\n";
62 // Get the reduction property manager
63 const std::string reductionManagerName = this->getProperty("ReductionProperties");
64 std::shared_ptr<PropertyManager> reductionManager;
65 if (PropertyManagerDataService::Instance().doesExist(reductionManagerName)) {
66 reductionManager = PropertyManagerDataService::Instance().retrieve(reductionManagerName);
67 } else {
68 throw std::runtime_error("DgsProcessDetectorVanadium cannot run without a "
69 "reduction PropertyManager.");
70 }
71
72 MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
73 MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");
74 MatrixWorkspace_sptr monWS = this->getProperty("InputMonitorWorkspace");
75
76 // Normalise result workspace to incident beam parameter
77 auto norm = createChildAlgorithm("DgsPreprocessData");
78 norm->setProperty("InputWorkspace", inputWS);
79 norm->setProperty("OutputWorkspace", inputWS);
80 norm->setProperty("InputMonitorWorkspace", monWS);
81 norm->executeAsChildAlg();
82 inputWS.reset();
83 inputWS = norm->getProperty("OutputWorkspace");
84
85 double detVanIntRangeLow = getDblPropOrParam("DetVanIntRangeLow", reductionManager, "wb-integr-min", inputWS);
86
87 double detVanIntRangeHigh = getDblPropOrParam("DetVanIntRangeHigh", reductionManager, "wb-integr-max", inputWS);
88
89 const std::string detVanIntRangeUnits = reductionManager->getProperty("DetVanIntRangeUnits");
90
91 if ("TOF" != detVanIntRangeUnits) {
92 // Convert the data to the appropriate units
93 auto cnvun = createChildAlgorithm("ConvertUnits");
94 cnvun->setProperty("InputWorkspace", inputWS);
95 cnvun->setProperty("OutputWorkspace", inputWS);
96 cnvun->setProperty("Target", detVanIntRangeUnits);
97 cnvun->setProperty("EMode", "Elastic");
98 cnvun->executeAsChildAlg();
99 inputWS = cnvun->getProperty("OutputWorkspace");
100 }
101
102 // Rebin the data (not Integration !?!?!?)
103 std::vector<double> binning{detVanIntRangeLow, detVanIntRangeHigh - detVanIntRangeLow, detVanIntRangeHigh};
104
105 auto rebin = createChildAlgorithm("Rebin");
106 rebin->setProperty("InputWorkspace", inputWS);
107 rebin->setProperty("OutputWorkspace", outputWS);
108 rebin->setProperty("PreserveEvents", false);
109 rebin->setProperty("Params", binning);
110 rebin->executeAsChildAlg();
111 outputWS = rebin->getProperty("OutputWorkspace");
112
113 // Mask and group workspace if necessary.
114 MatrixWorkspace_sptr maskWS = this->getProperty("MaskWorkspace");
116 // grouping (In ISIS)?
117 auto remap = createChildAlgorithm("DgsRemap");
118 remap->setProperty("InputWorkspace", outputWS);
119 remap->setProperty("OutputWorkspace", outputWS);
120 remap->setProperty("MaskWorkspace", maskWS);
121 remap->executeAsChildAlg();
122 outputWS = remap->getProperty("OutputWorkspace");
123
124 const std::string facility = ConfigService::Instance().getFacility().name();
125 if ("ISIS" == facility) {
126 // Scale results by a constant
127 double wbScaleFactor = inputWS->getInstrument()->getNumberParameter("wb-scale-factor")[0];
128 outputWS *= wbScaleFactor;
129 }
130
131 if (reductionManager->existsProperty("SaveProcessedDetVan")) {
132 bool saveProc = reductionManager->getProperty("SaveProcessedDetVan");
133 if (saveProc) {
134 std::string outputFile;
135 if (reductionManager->existsProperty("SaveProcDetVanFilename")) {
136 outputFile = reductionManager->getPropertyValue("SaveProcDetVanFilename");
137 }
138 if (outputFile.empty()) {
139 outputFile = this->getPropertyValue("OutputWorkspace");
140 outputFile += ".nxs";
141 }
142
143 // Don't save private calculation workspaces
144 if (!outputFile.empty() && !boost::starts_with(outputFile, "ChildAlgOutput") &&
145 !boost::starts_with(outputFile, "__")) {
146 auto save = createChildAlgorithm("SaveNexus");
147 save->setProperty("InputWorkspace", outputWS);
148 save->setProperty("FileName", outputFile);
149 save->execute();
150 }
151 }
152 }
153
154 this->setProperty("OutputWorkspace", outputWS);
155}
156
157} // 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
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
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
Kernel::Logger & g_log
Definition: Algorithm.h:451
A property class for workspaces.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
DgsProcessDetectorVanadium : This is the algorithm responsible for processing the detector vanadium i...
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
double getDblPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm, const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws, const double overrideValue=Mantid::EMPTY_DBL())
Function to get double property or instrument parameter value.
STL namespace.
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54