-
Notifications
You must be signed in to change notification settings - Fork 122
/
ComputeSensitivity.cpp
99 lines (86 loc) · 3.97 KB
/
ComputeSensitivity.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidWorkflowAlgorithms/ComputeSensitivity.h"
#include "MantidAPI/AlgorithmProperty.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/PropertyManagerDataService.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidKernel/PropertyManager.h"
#include "MantidWorkflowAlgorithms/EQSANSInstrument.h"
namespace Mantid {
namespace WorkflowAlgorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ComputeSensitivity)
using namespace Kernel;
using namespace API;
using namespace DataObjects;
void ComputeSensitivity::init() {
declareProperty(make_unique<API::FileProperty>(
"Filename", "", API::FileProperty::Load, "_event.nxs"),
"Flood field or sensitivity file.");
declareProperty(make_unique<WorkspaceProperty<>>("PatchWorkspace", "",
Direction::Input,
PropertyMode::Optional),
"Workspace defining the area of the detector to be patched. "
"All masked pixels in this workspace will be patched.");
declareProperty("ReductionProperties", "__eqsans_reduction_properties",
Direction::Input);
declareProperty(make_unique<WorkspaceProperty<>>("OutputWorkspace", "",
Direction::Output),
"Workspace containing the sensitivity correction.");
declareProperty("OutputMessage", "", Direction::Output);
}
void ComputeSensitivity::exec() {
std::string outputMessage;
progress(0.1, "Setting up sensitivity calculation");
// Reduction property manager
boost::shared_ptr<PropertyManager> reductionManager = getProcessProperties();
const std::string outputWS = getPropertyValue("OutputWorkspace");
// Find beam center
if (reductionManager->existsProperty("SANSBeamFinderAlgorithm")) {
// const std::string algTxt =
// reductionManager->getPropertyValue("SANSBeamFinderAlgorithm");
IAlgorithm_sptr ctrAlg =
reductionManager->getProperty("SANSBeamFinderAlgorithm");
ctrAlg->setPropertyValue("ReductionProperties",
getPropertyValue("ReductionProperties"));
ctrAlg->setChild(true);
ctrAlg->execute();
std::string outMsg2 = ctrAlg->getPropertyValue("OutputMessage");
outputMessage += outMsg2;
}
progress(0.2, "Computing sensitivity");
// Set patch information so that the SANS sensitivity algorithm can
// patch the sensitivity workspace
const std::string patchWSName = getPropertyValue("PatchWorkspace");
if (patchWSName.size() > 0) {
IAlgorithm_sptr patchAlg = createChildAlgorithm("EQSANSPatchSensitivity");
patchAlg->setPropertyValue("PatchWorkspace", patchWSName);
if (!reductionManager->existsProperty("SensitivityPatchAlgorithm")) {
reductionManager->declareProperty(
make_unique<AlgorithmProperty>("SensitivityPatchAlgorithm"));
}
reductionManager->setProperty("SensitivityPatchAlgorithm", patchAlg);
}
if (reductionManager->existsProperty("SensitivityAlgorithm")) {
const std::string fileName = getPropertyValue("Filename");
IAlgorithm_sptr effAlg =
reductionManager->getProperty("SensitivityAlgorithm");
effAlg->setChild(true);
effAlg->setProperty("Filename", fileName);
effAlg->setPropertyValue("OutputSensitivityWorkspace", outputWS);
effAlg->execute();
MatrixWorkspace_sptr effWS =
effAlg->getProperty("OutputSensitivityWorkspace");
setProperty("OutputWorkspace", effWS);
std::string outMsg2 = effAlg->getPropertyValue("OutputMessage");
outputMessage += outMsg2;
setProperty("OutputMessage", outputMessage);
} else {
g_log.error() << "Could not find sensitivity algorithm\n";
}
}
} // namespace WorkflowAlgorithms
} // namespace Mantid