-
Notifications
You must be signed in to change notification settings - Fork 122
/
HFIRSANSNormalise.cpp
68 lines (54 loc) · 2.34 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
66
67
68
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidWorkflowAlgorithms/HFIRSANSNormalise.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/ListValidator.h"
#include <boost/algorithm/string.hpp>
#include "Poco/NumberFormatter.h"
namespace Mantid {
namespace WorkflowAlgorithms {
using namespace Kernel;
using namespace API;
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(HFIRSANSNormalise)
void HFIRSANSNormalise::init() {
declareProperty(
make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
"Workspace to be corrected");
std::vector<std::string> normOptions{"Monitor", "Timer"};
this->declareProperty("NormalisationType", "Monitor",
boost::make_shared<StringListValidator>(normOptions),
"Type of Normalisation to use");
declareProperty(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);
double 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;
}
IAlgorithm_sptr 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 WorkflowAlgorithms
} // namespace Mantid