-
Notifications
You must be signed in to change notification settings - Fork 121
/
SpecularReflectionCalculateTheta.cpp
91 lines (68 loc) · 3.23 KB
/
SpecularReflectionCalculateTheta.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
#include "MantidAlgorithms/SpecularReflectionCalculateTheta.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/PropertyWithValue.h"
#include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"
#include <cmath>
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
using namespace Mantid::API;
namespace {
const std::string multiDetectorAnalysis = "MultiDetectorAnalysis";
const std::string lineDetectorAnalysis = "LineDetectorAnalysis";
const std::string pointDetectorAnalysis = "PointDetectorAnalysis";
}
namespace Mantid {
namespace Algorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(SpecularReflectionCalculateTheta)
//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string SpecularReflectionCalculateTheta::name() const {
return "SpecularReflectionCalculateTheta";
}
/// Algorithm's version for identification. @see Algorithm::version
int SpecularReflectionCalculateTheta::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string SpecularReflectionCalculateTheta::category() const {
return "Reflectometry";
}
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void SpecularReflectionCalculateTheta::init() {
declareProperty(
make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "",
Direction::Input),
"An Input workspace to calculate the specular relection theta on.");
this->initCommonProperties();
declareProperty(make_unique<PropertyWithValue<double>>(
"TwoTheta", Mantid::EMPTY_DBL(), Direction::Output),
"Calculated two theta scattering angle in degrees.");
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void SpecularReflectionCalculateTheta::exec() {
MatrixWorkspace_sptr inWS = this->getProperty("InputWorkspace");
const std::string analysisMode = this->getProperty("AnalysisMode");
Instrument_const_sptr instrument = inWS->getInstrument();
IComponent_const_sptr detector =
this->getDetectorComponent(inWS, analysisMode == pointDetectorAnalysis);
IComponent_const_sptr sample = this->getSurfaceSampleComponent(instrument);
const V3D detSample = detector->getPos() - sample->getPos();
boost::shared_ptr<const ReferenceFrame> refFrame =
instrument->getReferenceFrame();
const double upoffset = refFrame->vecPointingUp().scalar_prod(detSample);
const double beamoffset =
refFrame->vecPointingAlongBeam().scalar_prod(detSample);
const double twoTheta = 2 * std::atan(upoffset / beamoffset) * 180 / M_PI;
std::stringstream strstream;
strstream << "Recalculated two theta as: " << twoTheta;
this->g_log.information(strstream.str());
this->setProperty("TwoTheta", twoTheta);
}
} // namespace Algorithms
} // namespace Mantid