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 +
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 auto const &detInfo = ws->detectorInfo();
61 InstrumentRayTracer tracker(ws->componentInfo(), detInfo);
62 for (int iaz = 0; iaz < NumAzimuth; iaz++) {
63 prog.report();
64 double az = double(iaz) * M_PI * 2.0 / double(NumAzimuth);
65 for (int iz = 0; iz < NumZenith; iz++) {
66 const double zen = double(iz) * M_PI / double(NumZenith);
67 const double x = cos(az);
68 const double z = sin(az);
69 const double y = cos(zen);
70 V3D beam(x, y, z);
71 beam.normalize();
72
73 // Create a ray tracer
74 tracker.traceFromSample(beam);
75 auto const detIndex = tracker.getDetectorResult();
76 if (detIndex != ComponentInfo::invalidIndex) {
77 auto const detID = detInfo.detid(detIndex);
78 size_t wi = detTowi[detID];
79 g_log.information() << "Found detector " << detID << '\n';
80 ws->mutableY(wi)[0] = double(int(az * 57.3) * 1000 + int(iz));
81 }
82 }
83 }
84}
85
86} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:547
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:426
@ 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.
ComponentInfo : Provides a component centric view on to the instrument.
static constexpr size_t invalidIndex
Returned by indexOfOrInvalid() for a component ID that is not part of this instrument.
This class is responsible for tracking rays and accumulating a list of objects that are intersected a...
void traceFromSample(const Kernel::V3D &dir) const
Trace a given track from the sample position in the given direction.
size_t getDetectorResult() const
Get the index of the first non-monitor detector intersected since the previous call to trace,...
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:35
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::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
@ Output
An output workspace.
Definition Property.h:55