Mantid
Loading...
Searching...
No Matches
HFIRSANSNormalise.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 +
9#include "MantidAPI/Run.h"
11
12#include <boost/algorithm/string.hpp>
13
14#include "Poco/NumberFormatter.h"
15
17
18using namespace Kernel;
19using namespace API;
20
21// Register the algorithm into the AlgorithmFactory
22DECLARE_ALGORITHM(HFIRSANSNormalise)
23
24void HFIRSANSNormalise::init() {
25 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
26 "Workspace to be corrected");
27
28 std::vector<std::string> normOptions{"Monitor", "Timer"};
29 this->declareProperty("NormalisationType", "Monitor", std::make_shared<StringListValidator>(normOptions),
30 "Type of Normalisation to use");
31
32 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
33 "Corrected workspace");
34 declareProperty("OutputMessage", "", Direction::Output);
35}
36
38 MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
39 MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
40 std::string normalisation = getProperty("NormalisationType");
41
42 // Get the monitor or timer
43 boost::algorithm::to_lower(normalisation);
44 auto norm_count = inputWS->run().getPropertyValueAsType<double>(normalisation);
45
46 double factor;
47 if (boost::iequals(normalisation, "monitor")) {
48 factor = 1.0e8 / norm_count;
49 } else {
50 factor = 1.0 / norm_count;
51 }
52
53 auto scaleAlg = createChildAlgorithm("Scale");
54 scaleAlg->setProperty("InputWorkspace", inputWS);
55 scaleAlg->setProperty("OutputWorkspace", outputWS);
56 scaleAlg->setProperty("Factor", factor);
57 scaleAlg->setProperty("Operation", "Multiply");
58 scaleAlg->executeAsChildAlg();
59 MatrixWorkspace_sptr scaledWS = scaleAlg->getProperty("OutputWorkspace");
60
61 setProperty("OutputWorkspace", scaledWS);
62 setProperty("OutputMessage", "Normalisation by " + normalisation + ": " + Poco::NumberFormatter::format(norm_count));
63}
64
65} // namespace Mantid::WorkflowAlgorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
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
A property class for workspaces.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54