Mantid
Loading...
Searching...
No Matches
Detector.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 +
8#include "MantidBeamline/DetectorInfo.h"
14#include "MantidKernel/Logger.h"
15
16namespace Mantid::Geometry {
17namespace {
18// static logger object
19Kernel::Logger g_log("Detector");
20} // namespace
21
22using Kernel::V3D;
23
28Detector::Detector(const Detector *base, const ParameterMap *map) : ObjComponent(base, map), m_id(base->m_id) {}
29
35Detector::Detector(const std::string &name, int id, IComponent *parent)
36 : IDetector(), ObjComponent(name, parent), m_id(id) {}
37
45Detector::Detector(const std::string &name, int id, const std::shared_ptr<IObject> &shape, IComponent *parent)
46 : IDetector(), ObjComponent(name, shape, parent), m_id(id) {}
47
52 if (m_map) {
53 const auto *d = dynamic_cast<const Detector *>(m_base);
54 if (d) {
55 return d->getID();
56 }
57 }
58
59 return m_id;
60}
61
65double Detector::getDistance(const IComponent &comp) const { return ObjComponent::getDistance(comp); }
66
71double Detector::getTwoTheta(const V3D &observer, const V3D &axis) const {
72 const V3D sampleDetVec = this->getPos() - observer;
73 return sampleDetVec.angle(axis);
74}
75
83double Detector::getSignedTwoTheta(const V3D &observer, const V3D &axis, const V3D &instrumentUp) const {
84 const V3D sampleDetVec = this->getPos() - observer;
85 double angle = sampleDetVec.angle(axis);
86
87 V3D cross = axis.cross_prod(sampleDetVec);
88 V3D normToSurface = axis.cross_prod(instrumentUp);
89 if (normToSurface.scalar_prod(cross) < 0) {
90 angle *= -1;
91 }
92 return angle;
93}
94
100double Detector::getPhi() const {
101 const Kernel::V3D pos = this->getPos();
102 return std::atan2(pos[1], pos[0]);
103}
104
110double Detector::getPhiOffset(const double &offset) const {
111 double avgPos = getPhi();
112 return avgPos < 0 ? -(offset + avgPos) : offset - avgPos;
113}
114
121 center = this->getPos();
122 return rect;
123}
124
126const ParameterMap &Detector::parameterMap() const { return *m_map; }
127
129size_t Detector::index() const { return m_map->detectorIndex(m_id); }
130
131size_t Detector::registerContents(ComponentVisitor &componentVisitor) const {
132 return componentVisitor.registerDetector(*this);
133}
134
136 const IComponent *root = m_base;
137 while (auto parent = root->getBareParent())
138 root = parent;
139 auto instrument = dynamic_cast<const Instrument *>(root);
140 return m_map->hasDetectorInfo(instrument);
141}
142
143} // namespace Mantid::Geometry
ComponentVisitor : Visitor for IComponents.
virtual size_t registerDetector(const IDetector &detector)=0
const ParameterMap * m_map
A pointer to const ParameterMap containing the parameters.
Definition: Component.h:307
Kernel::V3D getPos() const override
Get the position of the IComponent. Tree structure is traverse through the.
Definition: Component.cpp:325
const Component * m_base
The base component - this is the unmodified component (without the parameters).
Definition: Component.h:305
This class represents a detector - i.e.
Definition: Detector.h:30
const detid_t m_id
The detector id.
Definition: Detector.h:64
bool hasDetectorInfo() const
Definition: Detector.cpp:135
double getDistance(const IComponent &comp) const override
Get the distance between the detector and another component.
Definition: Detector.cpp:65
size_t index() const override
Helper for legacy access mode. Returns the index of the detector.
Definition: Detector.cpp:129
double getPhi() const override
Get the phi angle between the detector with reference to the origin This function will not be support...
Definition: Detector.cpp:100
double getTwoTheta(const Kernel::V3D &observer, const Kernel::V3D &axis) const override
Get the twotheta angle between the detector and an observer.
Definition: Detector.cpp:71
det_topology getTopology(Kernel::V3D &center) const override
returns the detector's topology, namely, the meaning of the detector's angular measurements.
Definition: Detector.cpp:120
virtual size_t registerContents(class ComponentVisitor &componentVisitor) const override
Register the contents of this ObjComponent.
Definition: Detector.cpp:131
double getPhiOffset(const double &offset) const override
Calculate the phi angle between detector and beam, and then offset.
Definition: Detector.cpp:110
Detector(const std::string &name, int id, IComponent *parent)
Constructor.
Definition: Detector.cpp:35
detid_t getID() const override
Gets the detector id.
Definition: Detector.cpp:51
const ParameterMap & parameterMap() const override
Helper for legacy access mode. Returns a reference to the ParameterMap.
Definition: Detector.cpp:126
double getSignedTwoTheta(const Kernel::V3D &observer, const Kernel::V3D &axis, const Kernel::V3D &instrumentUp) const override
Get the two theata angle signed according the quadrant.
Definition: Detector.cpp:83
base class for Geometric IComponent
Definition: IComponent.h:51
virtual double getDistance(const IComponent &) const =0
Get the distance to another IComponent.
virtual const IComponent * getBareParent() const =0
Returns the bare pointer to the IComponent parent.
Interface class for detector objects.
Definition: IDetector.h:43
Base Instrument Class.
Definition: Instrument.h:47
Object Component class, this class brings together the physical attributes of the component to the po...
Definition: ObjComponent.h:33
size_t detectorIndex(const detid_t detID) const
Only for use by Detector. Returns a detector index for a detector ID.
bool hasDetectorInfo(const Instrument *instrument) const
Only for use by ExperimentInfo.
Class for 3D vectors.
Definition: V3D.h:34
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition: V3D.h:274
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
Definition: V3D.h:278
double angle(const V3D &) const
Angle between this and another vector.
Definition: V3D.cpp:165
Mantid::Kernel::Logger g_log("Goniometer")
det_topology
Describes the topology of a detectors group used to calculate angular position and angular measures f...
Definition: IDetector.h:31
int32_t detid_t
Typedef for a detector ID.
Definition: SpectrumInfo.h:21