-
Notifications
You must be signed in to change notification settings - Fork 122
/
HFIRSANSNormalise.cpp
65 lines (51 loc) · 2.39 KB
/
HFIRSANSNormalise.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidWorkflowAlgorithms/HFIRSANSNormalise.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidKernel/ListValidator.h"
#include <boost/algorithm/string.hpp>
#include "Poco/NumberFormatter.h"
namespace Mantid::WorkflowAlgorithms {
using namespace Kernel;
using namespace API;
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(HFIRSANSNormalise)
void HFIRSANSNormalise::init() {
declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
"Workspace to be corrected");
std::vector<std::string> normOptions{"Monitor", "Timer"};
this->declareProperty("NormalisationType", "Monitor", std::make_shared<StringListValidator>(normOptions),
"Type of Normalisation to use");
declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
"Corrected workspace");
declareProperty("OutputMessage", "", Direction::Output);
}
void HFIRSANSNormalise::exec() {
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
std::string normalisation = getProperty("NormalisationType");
// Get the monitor or timer
boost::algorithm::to_lower(normalisation);
auto norm_count = inputWS->run().getPropertyValueAsType<double>(normalisation);
double factor;
if (boost::iequals(normalisation, "monitor")) {
factor = 1.0e8 / norm_count;
} else {
factor = 1.0 / norm_count;
}
auto scaleAlg = createChildAlgorithm("Scale");
scaleAlg->setProperty("InputWorkspace", inputWS);
scaleAlg->setProperty("OutputWorkspace", outputWS);
scaleAlg->setProperty("Factor", factor);
scaleAlg->setProperty("Operation", "Multiply");
scaleAlg->executeAsChildAlg();
MatrixWorkspace_sptr scaledWS = scaleAlg->getProperty("OutputWorkspace");
setProperty("OutputWorkspace", scaledWS);
setProperty("OutputMessage", "Normalisation by " + normalisation + ": " + Poco::NumberFormatter::format(norm_count));
}
} // namespace Mantid::WorkflowAlgorithms