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/System.h"
13#include "MantidKernel/V3D.h"
14
15#include <cmath>
16
17using namespace Mantid::Kernel;
18using namespace Mantid::API;
19using namespace Mantid::DataObjects;
22
23namespace Mantid::Algorithms {
24
25// Register the algorithm into the AlgorithmFactory
26DECLARE_ALGORITHM(RayTracerTester)
27
28//----------------------------------------------------------------------------------------------
31void RayTracerTester::init() {
32 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Load, ".xml"),
33 "The filename (including its full or relative path) of an "
34 "instrument definition file");
35 declareProperty("NumAzimuth", 100, "Steps in azimuthal angles");
36 declareProperty("NumZenith", 50, "Steps in zenith angles");
37 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
38 "An output workspace.");
39}
40
41//----------------------------------------------------------------------------------------------
45 auto alg = createChildAlgorithm("LoadEmptyInstrument", 0.0, 0.3, true);
46 alg->setPropertyValue("Filename", getPropertyValue("Filename"));
47 alg->executeAsChildAlg();
48
49 MatrixWorkspace_sptr mws = alg->getProperty("OutputWorkspace");
50 setProperty("OutputWorkspace", mws);
51 Workspace2D_sptr ws = std::dynamic_pointer_cast<Workspace2D>(mws);
52
53 detid2index_map detTowi = ws->getDetectorIDToWorkspaceIndexMap();
54 for (size_t i = 0; i < ws->getNumberHistograms(); i++)
55 ws->mutableY(i)[0] = 0.0;
56
57 int NumAzimuth = getProperty("NumAzimuth");
58 int NumZenith = getProperty("NumZenith");
59 Progress prog(this, 0.3, 1.0, NumAzimuth);
60 InstrumentRayTracer tracker(ws->getInstrument());
61 for (int iaz = 0; iaz < NumAzimuth; iaz++) {
62 prog.report();
63 double az = double(iaz) * M_PI * 2.0 / double(NumAzimuth);
64 for (int iz = 0; iz < NumZenith; iz++) {
65 const double zen = double(iz) * M_PI / double(NumZenith);
66 const double x = cos(az);
67 const double z = sin(az);
68 const double y = cos(zen);
69 V3D beam(x, y, z);
70 beam.normalize();
71
72 // Create a ray tracer
73 tracker.traceFromSample(beam);
75 if (det) {
76 size_t wi = detTowi[det->getID()];
77 g_log.information() << "Found detector " << det->getID() << '\n';
78 ws->mutableY(wi)[0] = double(int(az * 57.3) * 1000 + int(iz));
79 }
80 }
81 }
82}
83
84} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
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.
Definition: Algorithm.cpp:842
Kernel::Logger & g_log
Definition: Algorithm.h:451
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
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:105
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Definition: ProgressBase.h:51
Class for 3D vectors.
Definition: V3D.h:34
double normalize()
Make a normalized vector (return norm value)
Definition: V3D.cpp:130
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