-
Notifications
You must be signed in to change notification settings - Fork 122
/
RayTracerTester.cpp
93 lines (79 loc) · 3.21 KB
/
RayTracerTester.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
#include "MantidAlgorithms/RayTracerTester.h"
#include "MantidAPI/FileProperty.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidGeometry/IDetector.h"
#include "MantidGeometry/Objects/InstrumentRayTracer.h"
#include "MantidKernel/System.h"
#include "MantidKernel/V3D.h"
#include <cmath>
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using Mantid::Geometry::IDetector_const_sptr;
using Mantid::Geometry::InstrumentRayTracer;
namespace Mantid {
namespace Algorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(RayTracerTester)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
RayTracerTester::RayTracerTester() {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
RayTracerTester::~RayTracerTester() {}
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void RayTracerTester::init() {
declareProperty(new FileProperty("Filename", "", FileProperty::Load, ".xml"),
"The filename (including its full or relative path) of an "
"instrument definition file");
declareProperty("NumAzimuth", 100, "Steps in azimuthal angles");
declareProperty("NumZenith", 50, "Steps in zenith angles");
declareProperty(
new WorkspaceProperty<>("OutputWorkspace", "", Direction::Output),
"An output workspace.");
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void RayTracerTester::exec() {
IAlgorithm_sptr alg =
this->createChildAlgorithm("LoadEmptyInstrument", 0.0, 0.3, true);
alg->setPropertyValue("Filename", getPropertyValue("Filename"));
alg->executeAsChildAlg();
MatrixWorkspace_sptr mws = alg->getProperty("OutputWorkspace");
setProperty("OutputWorkspace", mws);
Workspace2D_sptr ws = boost::dynamic_pointer_cast<Workspace2D>(mws);
detid2index_map detTowi = ws->getDetectorIDToWorkspaceIndexMap();
for (size_t i = 0; i < ws->getNumberHistograms(); i++)
ws->dataY(i)[0] = 0.0;
int NumAzimuth = getProperty("NumAzimuth");
int NumZenith = getProperty("NumZenith");
Progress prog(this, 0.3, 1.0, NumAzimuth);
for (int iaz = 0; iaz < NumAzimuth; iaz++) {
prog.report();
double az = double(iaz) * M_PI * 2.0 / double(NumAzimuth);
for (int iz = 0; iz < NumZenith; iz++) {
double zen = double(iz) * M_PI / double(NumZenith);
double x = cos(az);
double z = sin(az);
double y = cos(zen);
V3D beam(x, y, z);
// Create a ray tracer
InstrumentRayTracer tracker(ws->getInstrument());
tracker.traceFromSample(beam);
IDetector_const_sptr det = tracker.getDetectorResult();
if (det) {
size_t wi = detTowi[det->getID()];
g_log.information() << "Found detector " << det->getID() << std::endl;
ws->dataY(wi)[0] = double(int(az * 57.3) * 1000 + int(iz));
}
}
}
}
} // namespace Mantid
} // namespace Algorithms