-
Notifications
You must be signed in to change notification settings - Fork 124
/
PoldiAutoCorrelation5.cpp
162 lines (135 loc) · 6.47 KB
/
PoldiAutoCorrelation5.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidSINQ/PoldiAutoCorrelation5.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/MaskWorkspace.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidSINQ/PoldiUtilities/PoldiDeadWireDecorator.h"
#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"
#include <boost/shared_ptr.hpp>
namespace Mantid {
namespace Poldi {
// Register the algorithm into the algorithm factory
DECLARE_ALGORITHM(PoldiAutoCorrelation5)
using namespace Kernel;
using namespace API;
using namespace PhysicalConstants;
using namespace Geometry;
/// Initialisation method.
void PoldiAutoCorrelation5::init() {
// Input workspace containing the raw data.
declareProperty(make_unique<WorkspaceProperty<DataObjects::Workspace2D>>(
"InputWorkspace", "", Direction::InOut),
"Input workspace containing raw POLDI data.");
// the minimal value of the wavelength to consider
declareProperty("wlenmin", 1.1, "Minimum wavelength considered",
Direction::Input);
// the maximal value of the wavelength to consider
declareProperty("wlenmax", 5.0, "Maximum wavelength considered",
Direction::Input);
// The output Workspace2D containing the Poldi data autocorrelation function.
declareProperty(make_unique<WorkspaceProperty<DataObjects::Workspace2D>>(
"OutputWorkspace", "", Direction::Output),
"Output workspace containing the correlation spectrum.");
/* Auto correlation core object which performs the actual calculation.
* In future versions this will be replaced by a factory to cater for
* slightly different variants of the algorithm as they are implemented
* in the original fortran analysis software.
*/
m_core = boost::shared_ptr<PoldiAutoCorrelationCore>(
new PoldiAutoCorrelationCore(g_log));
}
/** ***************************************************************** */
/** Executes the algorithm. Reading in the file and creating and populating
* the output workspace
*
* @throw Exception::NotFoundError Error when saving the PoldiDeadWires Results
*data to Workspace
* @throw std::runtime_error Error when saving the PoldiDeadWires Results data
*to Workspace
*/
void PoldiAutoCorrelation5::exec() {
g_log.information() << "_Poldi start conf -------------- \n";
/* From localWorkspace three things are used:
* - Count data from POLDI experiment
* - POLDI instrument definition
* - Some data from the "Log" (for example chopper-speed)
*/
DataObjects::Workspace2D_sptr localWorkspace =
this->getProperty("InputWorkspace");
g_log.information() << "_Poldi ws loaded -------------- \n";
double wlen_min = this->getProperty("wlenmin");
double wlen_max = this->getProperty("wlenmax");
PoldiInstrumentAdapter instrumentAdapter(localWorkspace);
PoldiAbstractChopper_sptr chopper = instrumentAdapter.chopper();
PoldiAbstractDetector_sptr detector = instrumentAdapter.detector();
boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector(
new PoldiDeadWireDecorator(localWorkspace->detectorInfo(), detector));
// log configuration information
logConfigurationInformation(cleanDetector, chopper);
// putting together POLDI instrument for calculations
m_core->setInstrument(cleanDetector, chopper);
m_core->setWavelengthRange(wlen_min, wlen_max);
try {
Mantid::DataObjects::Workspace2D_sptr outputws =
m_core->calculate(localWorkspace);
setProperty("OutputWorkspace",
boost::dynamic_pointer_cast<Workspace>(outputws));
} catch (Mantid::Kernel::Exception::NotFoundError &) {
throw std::runtime_error("Error when saving the PoldiIPP Results data to "
"Workspace : NotFoundError");
} catch (std::runtime_error &) {
throw std::runtime_error("Error when saving the PoldiIPP Results data to "
"Workspace : runtime_error");
}
}
void PoldiAutoCorrelation5::logConfigurationInformation(
boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector,
PoldiAbstractChopper_sptr chopper) {
if (cleanDetector && chopper) {
g_log.information()
<< "____________________________________________________ \n";
g_log.information()
<< "_Poldi chopper conf ------------------------------ \n";
g_log.information() << "_Poldi - Chopper speed: "
<< chopper->rotationSpeed() << " rpm\n";
g_log.information() << "_Poldi - Number of slits: "
<< chopper->slitPositions().size() << '\n';
g_log.information() << "_Poldi - Cycle time: "
<< chopper->cycleTime() << " µs\n";
g_log.information() << "_Poldi - Zero offset: "
<< chopper->zeroOffset() << " µs\n";
g_log.information() << "_Poldi - Distance: "
<< chopper->distanceFromSample() << " mm\n";
if (g_log.is(Poco::Message::PRIO_DEBUG)) {
for (size_t i = 0; i < chopper->slitPositions().size(); ++i) {
g_log.information() << "_Poldi - Slits: " << i
<< ": Position = " << chopper->slitPositions()[i]
<< "\t Time = " << chopper->slitTimes()[i]
<< " µs\n";
}
}
g_log.information()
<< "_Poldi detector conf ------------------------------ \n";
g_log.information() << "_Poldi - Element count: "
<< cleanDetector->elementCount() << '\n';
g_log.information() << "_Poldi - Central element: "
<< cleanDetector->centralElement() << '\n';
g_log.information() << "_Poldi - 2Theta(central): "
<< cleanDetector->twoTheta(199) / M_PI * 180.0 << "°\n";
g_log.information() << "_Poldi - Distance(central): "
<< cleanDetector->distanceFromSample(199) << " mm\n";
std::set<int> deadWires = cleanDetector->deadWires();
g_log.information() << "_Poldi - Number of dead wires: "
<< deadWires.size() << '\n';
g_log.information() << "_Poldi - Wire indices: ";
for (auto deadWire : deadWires) {
g_log.information() << deadWire << " ";
}
g_log.information() << '\n';
}
}
} // namespace Poldi
} // namespace Mantid