Mantid
Loading...
Searching...
No Matches
DgsPreprocessData.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#include "MantidAPI/Run.h"
23#include "Poco/Path.h"
24
25using namespace Mantid::Kernel;
26using namespace Mantid::API;
27using namespace WorkflowAlgorithmHelpers;
28
30
31// Register the algorithm into the AlgorithmFactory
32DECLARE_ALGORITHM(DgsPreprocessData)
33
34
35const std::string DgsPreprocessData::name() const { return "DgsPreprocessData"; }
36
38int DgsPreprocessData::version() const { return 1; }
39
41const std::string DgsPreprocessData::category() const { return "Workflow\\Inelastic\\UsesPropertyManager"; }
42
46 this->declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
47 "An input workspace.");
48 this->declareProperty(
49 std::make_unique<WorkspaceProperty<>>("InputMonitorWorkspace", "", Direction::Input, PropertyMode::Optional),
50 "A monitor workspace associated with the input workspace.");
51 this->declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
52 "The name for the output workspace.");
53 this->declareProperty("TofRangeOffset", 0.0, "An addition to the TOF axis for monitor integration.");
54 this->declareProperty("ReductionProperties", "__dgs_reduction_properties", Direction::Input);
55}
56
60 g_log.notice() << "Starting DgsPreprocessData\n";
61 // Get the reduction property manager
62 const std::string reductionManagerName = this->getProperty("ReductionProperties");
63 std::shared_ptr<PropertyManager> reductionManager;
64 if (PropertyManagerDataService::Instance().doesExist(reductionManagerName)) {
65 reductionManager = PropertyManagerDataService::Instance().retrieve(reductionManagerName);
66 } else {
67 throw std::runtime_error("DgsPreprocessData cannot run without a reduction PropertyManager.");
68 }
69
70 // Log name that will indicate if the preprocessing has been done.
71 const std::string doneLog = "DirectInelasticReductionNormalisedBy";
72
73 MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
74 MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");
75
76 std::string incidentBeamNorm = reductionManager->getProperty("IncidentBeamNormalisation");
77 g_log.notice() << "Incident beam norm method = " << incidentBeamNorm << '\n';
78
79 // Check to see if preprocessing has already been done.
80 bool normAlreadyDone = inputWS->run().hasProperty(doneLog);
81
82 if ("None" != incidentBeamNorm && !normAlreadyDone) {
83 const std::string facility = ConfigService::Instance().getFacility().name();
84 // SNS hard-wired to current normalisation
85 if ("SNS" == facility) {
86 incidentBeamNorm = "ByCurrent";
87 }
88 const std::string normAlg = "Normalise" + incidentBeamNorm;
89 auto norm = createChildAlgorithm(normAlg);
90 norm->setProperty("InputWorkspace", inputWS);
91 norm->setProperty("OutputWorkspace", outputWS);
92 if ("ToMonitor" == incidentBeamNorm) {
93 // Perform extra setup for monitor normalisation
94 double rangeOffset = this->getProperty("TofRangeOffset");
95 double rangeMin = getDblPropOrParam("MonitorIntRangeLow", reductionManager, "norm-mon1-min", inputWS);
96 rangeMin += rangeOffset;
97
98 double rangeMax = getDblPropOrParam("MonitorIntRangeHigh", reductionManager, "norm-mon1-max", inputWS);
99 rangeMax += rangeOffset;
100
101 specnum_t monSpec = static_cast<specnum_t>(inputWS->getInstrument()->getNumberParameter("norm-mon1-spec")[0]);
102 if ("ISIS" == facility) {
103 norm->setProperty("MonitorSpectrum", monSpec);
104 }
105 // Do SNS
106 else {
107 MatrixWorkspace_const_sptr monitorWS = this->getProperty("MonitorWorkspace");
108 if (!monitorWS) {
109 throw std::runtime_error("SNS instruments require monitor workspaces "
110 "for monitor normalisation.");
111 }
112 std::size_t monIndex = monitorWS->getIndexFromSpectrumNumber(monSpec);
113 norm->setProperty("MonitorWorkspace", monitorWS);
114 norm->setProperty("MonitorWorkspaceIndex", monIndex);
115 }
116 norm->setProperty("IntegrationRangeMin", rangeMin);
117 norm->setProperty("IntegrationRangeMax", rangeMax);
118 norm->setProperty("IncludePartialBins", true);
119 }
120 norm->executeAsChildAlg();
121
122 outputWS = norm->getProperty("OutputWorkspace");
123
124 auto addLog = createChildAlgorithm("AddSampleLog");
125 addLog->setProperty("Workspace", outputWS);
126 addLog->setProperty("LogName", doneLog);
127 addLog->setProperty("LogText", normAlg);
128 addLog->executeAsChildAlg();
129 } else {
130 if (normAlreadyDone) {
131 g_log.information() << "Preprocessing already done on " << inputWS->getName() << '\n';
132 }
133 outputWS = inputWS;
134 }
135
136 this->setProperty("OutputWorkspace", outputWS);
137}
138
139} // 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.
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
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
DgsPreprocessData : This algorithm is responsible for normalising the data to current (proton charge)...
int version() const override
Algorithm's version for identification.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
int32_t specnum_t
Typedef for a spectrum Number.
Definition IDTypes.h:14
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