Mantid
Loading...
Searching...
No Matches
RayTracerTester.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
12#include "MantidKernel/V3D.h"
13
14#include <cmath>
15
16using namespace Mantid::Kernel;
17using namespace Mantid::API;
18using namespace Mantid::DataObjects;
21
22namespace Mantid::Algorithms {
23
24// Register the algorithm into the AlgorithmFactory
25DECLARE_ALGORITHM(RayTracerTester)
26
27//----------------------------------------------------------------------------------------------
30void RayTracerTester::init() {
31 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Load, ".xml"),
32 "The filename (including its full or relative path) of an "
33 "instrument definition file");
34 declareProperty("NumAzimuth", 100, "Steps in azimuthal angles");
35 declareProperty("NumZenith", 50, "Steps in zenith angles");
36 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
37 "An output workspace.");
38}
39
40//----------------------------------------------------------------------------------------------
44 auto alg = createChildAlgorithm("LoadEmptyInstrument", 0.0, 0.3, true);
45 alg->setPropertyValue("Filename", getPropertyValue("Filename"));
46 alg->executeAsChildAlg();
47
48 MatrixWorkspace_sptr mws = alg->getProperty("OutputWorkspace");
49 setProperty("OutputWorkspace", mws);
50 Workspace2D_sptr ws = std::dynamic_pointer_cast<Workspace2D>(mws);
51
52 detid2index_map detTowi = ws->getDetectorIDToWorkspaceIndexMap();
53 for (size_t i = 0; i < ws->getNumberHistograms(); i++)
54 ws->mutableY(i)[0] = 0.0;
55
56 int NumAzimuth = getProperty("NumAzimuth");
57 int NumZenith = getProperty("NumZenith");
58 Progress prog(this, 0.3, 1.0, NumAzimuth);
59 InstrumentRayTracer tracker(ws->getInstrument());
60 for (int iaz = 0; iaz < NumAzimuth; iaz++) {
61 prog.report();
62 double az = double(iaz) * M_PI * 2.0 / double(NumAzimuth);
63 for (int iz = 0; iz < NumZenith; iz++) {
64 const double zen = double(iz) * M_PI / double(NumZenith);
65 const double x = cos(az);
66 const double z = sin(az);
67 const double y = cos(zen);
68 V3D beam(x, y, z);
69 beam.normalize();
70
71 // Create a ray tracer
72 tracker.traceFromSample(beam);
74 if (det) {
75 size_t wi = detTowi[det->getID()];
76 g_log.information() << "Found detector " << det->getID() << '\n';
77 ws->mutableY(wi)[0] = double(int(az * 57.3) * 1000 + int(iz));
78 }
79 }
80 }
81}
82
83} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Kernel::Logger & g_log
Definition Algorithm.h:422
@ Load
allowed here which will be passed to the algorithm
Helper class for reporting progress from algorithms.
Definition Progress.h:25
A property class for workspaces.
Algorithm to test ray tracer by spraying evenly spaced rays around.
void exec() override
Run the algorithm.
This class is responsible for tracking rays and accumulating a list of objects that are intersected a...
IDetector_const_sptr getDetectorResult() const
Gets the results of the trace, then returns the first detector (that is NOT a monitor) found in the r...
void traceFromSample(const Kernel::V3D &dir) const
Trace a given track from the sample position in the given direction.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Class for 3D vectors.
Definition V3D.h:34
double normalize()
Make a normalized vector (return norm value)
Definition V3D.cpp:129
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
Definition IDetector.h:102
std::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
@ Output
An output workspace.
Definition Property.h:54