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
15using namespace Mantid::Kernel;
16using namespace Mantid::API;
17using namespace WorkflowAlgorithmHelpers;
18
20
21// Register the algorithm into the AlgorithmFactory
22DECLARE_ALGORITHM(DgsProcessDetectorVanadium)
23
24//----------------------------------------------------------------------------------------------
26const std::string DgsProcessDetectorVanadium::name() const { return "DgsProcessDetectorVanadium"; }
27
29int DgsProcessDetectorVanadium::version() const { return 1; }
30
32const std::string DgsProcessDetectorVanadium::category() const { return "Workflow\\Inelastic\\UsesPropertyManager"; }
33
34//----------------------------------------------------------------------------------------------
35
36//----------------------------------------------------------------------------------------------
40 // auto wsValidator = std::make_shared<CompositeValidator>();
41 // wsValidator->add<WorkspaceUnitValidator>("TOF");
42 this->declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
43 "An input workspace containing the detector vanadium data in TOF units.");
44 this->declareProperty(
45 std::make_unique<WorkspaceProperty<>>("InputMonitorWorkspace", "", Direction::Input, PropertyMode::Optional),
46 "A monitor workspace associated with the input workspace.");
47 this->declareProperty(
48 std::make_unique<WorkspaceProperty<>>("MaskWorkspace", "", Direction::Input, PropertyMode::Optional),
49 "A mask workspace");
50 this->declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
51 "The name for the output workspace.");
52 this->declareProperty("ReductionProperties", "__dgs_reduction_properties", Direction::Output);
53}
54
55//----------------------------------------------------------------------------------------------
59 g_log.notice() << "Starting DgsProcessDetectorVanadium\n";
60 // Get the reduction property manager
61 const std::string reductionManagerName = this->getProperty("ReductionProperties");
62 std::shared_ptr<PropertyManager> reductionManager;
63 if (PropertyManagerDataService::Instance().doesExist(reductionManagerName)) {
64 reductionManager = PropertyManagerDataService::Instance().retrieve(reductionManagerName);
65 } else {
66 throw std::runtime_error("DgsProcessDetectorVanadium cannot run without a "
67 "reduction PropertyManager.");
68 }
69
70 MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
71 MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");
72 MatrixWorkspace_sptr monWS = this->getProperty("InputMonitorWorkspace");
73
74 // Normalise result workspace to incident beam parameter
75 auto norm = createChildAlgorithm("DgsPreprocessData");
76 norm->setProperty("InputWorkspace", inputWS);
77 norm->setProperty("OutputWorkspace", inputWS);
78 norm->setProperty("InputMonitorWorkspace", monWS);
79 norm->executeAsChildAlg();
80 inputWS.reset();
81 inputWS = norm->getProperty("OutputWorkspace");
82
83 double detVanIntRangeLow = getDblPropOrParam("DetVanIntRangeLow", reductionManager, "wb-integr-min", inputWS);
84
85 double detVanIntRangeHigh = getDblPropOrParam("DetVanIntRangeHigh", reductionManager, "wb-integr-max", inputWS);
86
87 const std::string detVanIntRangeUnits = reductionManager->getProperty("DetVanIntRangeUnits");
88
89 if ("TOF" != detVanIntRangeUnits) {
90 // Convert the data to the appropriate units
91 auto cnvun = createChildAlgorithm("ConvertUnits");
92 cnvun->setProperty("InputWorkspace", inputWS);
93 cnvun->setProperty("OutputWorkspace", inputWS);
94 cnvun->setProperty("Target", detVanIntRangeUnits);
95 cnvun->setProperty("EMode", "Elastic");
96 cnvun->executeAsChildAlg();
97 inputWS = cnvun->getProperty("OutputWorkspace");
98 }
99
100 // Rebin the data (not Integration !?!?!?)
101 std::vector<double> binning{detVanIntRangeLow, detVanIntRangeHigh - detVanIntRangeLow, detVanIntRangeHigh};
102
103 auto rebin = createChildAlgorithm("Rebin");
104 rebin->setProperty("InputWorkspace", inputWS);
105 rebin->setProperty("OutputWorkspace", outputWS);
106 rebin->setProperty("PreserveEvents", false);
107 rebin->setProperty("Params", binning);
108 rebin->executeAsChildAlg();
109 outputWS = rebin->getProperty("OutputWorkspace");
110
111 // Mask and group workspace if necessary.
112 MatrixWorkspace_sptr maskWS = this->getProperty("MaskWorkspace");
114 // grouping (In ISIS)?
115 auto remap = createChildAlgorithm("DgsRemap");
116 remap->setProperty("InputWorkspace", outputWS);
117 remap->setProperty("OutputWorkspace", outputWS);
118 remap->setProperty("MaskWorkspace", maskWS);
119 remap->executeAsChildAlg();
120 outputWS = remap->getProperty("OutputWorkspace");
121
122 const std::string facility = ConfigService::Instance().getFacility().name();
123 if ("ISIS" == facility) {
124 // Scale results by a constant
125 double wbScaleFactor = inputWS->getInstrument()->getNumberParameter("wb-scale-factor")[0];
126 outputWS *= wbScaleFactor;
127 }
128
129 if (reductionManager->existsProperty("SaveProcessedDetVan")) {
130 bool saveProc = reductionManager->getProperty("SaveProcessedDetVan");
131 if (saveProc) {
132 std::string outputFile;
133 if (reductionManager->existsProperty("SaveProcDetVanFilename")) {
134 outputFile = reductionManager->getPropertyValue("SaveProcDetVanFilename");
135 }
136 if (outputFile.empty()) {
137 outputFile = this->getPropertyValue("OutputWorkspace");
138 outputFile += ".nxs";
139 }
140
141 // Don't save private calculation workspaces
142 if (!outputFile.empty() && !outputFile.starts_with("ChildAlgOutput") && !outputFile.starts_with("__")) {
143 auto save = createChildAlgorithm("SaveNexus");
144 save->setProperty("InputWorkspace", outputWS);
145 save->setProperty("FileName", outputFile);
146 save->execute();
147 }
148 }
149 }
150
151 this->setProperty("OutputWorkspace", outputWS);
152}
153
154} // namespace Mantid::WorkflowAlgorithms
std::string name
Definition Run.cpp:60
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
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.
Kernel::Logger & g_log
Definition Algorithm.h:422
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:126
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