Peak.h 5.83 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8

9
#include "MantidDataObjects/BasePeak.h"
Owen Arnold's avatar
Owen Arnold committed
10
#include "MantidGeometry/Crystal/IPeak.h"
11
#include "MantidGeometry/Crystal/PeakShape.h"
12
#include "MantidGeometry/Instrument.h"
13
#include "MantidKernel/Logger.h"
14
#include "MantidKernel/Matrix.h"
15
#include "MantidKernel/PhysicalConstants.h"
16
#include "MantidKernel/System.h"
17
#include "MantidKernel/V3D.h"
18
#include <boost/optional.hpp>
19
#include <memory>
20

21
namespace Mantid {
22
23
24
25
26

namespace Geometry {
class InstrumentRayTracer;
}

27
28
namespace DataObjects {

Whitfield, Ross's avatar
Whitfield, Ross committed
29
30
31
32
/** Structure describing a single-crystal peak. The peak is described
 * by the physical detector position (determined either from detector
 * infomation or calculated from Q-lab) and inital/final energy
 * (calculated from Q-lab or provided wavelength)
33
34
 *
 */
35
class DLLExport Peak : public BasePeak {
36
37
38
39
40
public:
  /// Allow PeakColumn class to directly access members.
  friend class PeakColumn;

  Peak();
Hahn, Steven's avatar
Hahn, Steven committed
41
42
43
  Peak(const Geometry::Instrument_const_sptr &m_inst,
       const Mantid::Kernel::V3D &QLabFrame,
       boost::optional<double> detectorDistance = boost::none);
44
45
46
  Peak(const Geometry::Instrument_const_sptr &m_inst,
       const Mantid::Kernel::V3D &QSampleFrame,
       const Mantid::Kernel::Matrix<double> &goniometer,
Hahn, Steven's avatar
Hahn, Steven committed
47
       boost::optional<double> detectorDistance = boost::none);
48
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
49
       double m_Wavelength);
50
51
52
53
54
55
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
       double m_Wavelength, const Mantid::Kernel::V3D &HKL);
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
       double m_Wavelength, const Mantid::Kernel::V3D &HKL,
       const Mantid::Kernel::Matrix<double> &goniometer);
  Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering,
56
57
       double m_Wavelength);

58
  /// Copy constructor
59
  Peak(const Peak &other);
60

LamarMoore's avatar
LamarMoore committed
61
62
63
64
65
  // MSVC 2015/17 can build with noexcept = default however
  // intellisense still incorrectly reports this as an error despite compiling.
  // https://connect.microsoft.com/VisualStudio/feedback/details/1795240/visual-c-2015-default-move-constructor-and-noexcept-keyword-bug
  // For that reason we still use the supplied default which should be noexcept
  // once the above is fixed we can remove this workaround
66

67
#if defined(_MSC_VER) && _MSC_VER <= 1910
68
69
70
  Peak(Peak &&) = default;
  Peak &operator=(Peak &&) = default;
#else
71
72
  Peak(Peak &&) noexcept = default;
  Peak &operator=(Peak &&) noexcept = default;
73
#endif
74

75
  // Construct a peak from a reference to the interface
76

Owen Arnold's avatar
Owen Arnold committed
77
  explicit Peak(const Geometry::IPeak &ipeak);
78

79
80
  void setDetectorID(int id) override;
  int getDetectorID() const override;
81
82
83
84
  void addContributingDetID(const int id);
  void removeContributingDetector(const int id);
  const std::set<int> &getContributingDetIDs() const;

85
  void setInstrument(const Geometry::Instrument_const_sptr &inst) override;
86
87
  Geometry::IDetector_const_sptr getDetector() const override;
  Geometry::Instrument_const_sptr getInstrument() const override;
88
89
  std::shared_ptr<const Geometry::ReferenceFrame>
  getReferenceFrame() const override;
90

91
  bool findDetector() override;
92
  bool findDetector(const Geometry::InstrumentRayTracer &tracer) override;
93

94
95
  void setSamplePos(double samX, double samY, double samZ) override;
  void setSamplePos(const Mantid::Kernel::V3D &XYZ) override;
96

97
98
99
100
  Mantid::Kernel::V3D getQLabFrame() const override;
  Mantid::Kernel::V3D getQSampleFrame() const override;
  Mantid::Kernel::V3D getDetectorPosition() const override;
  Mantid::Kernel::V3D getDetectorPositionNoCheck() const override;
101

Hahn, Steven's avatar
Hahn, Steven committed
102
103
104
105
  void setQSampleFrame(
      const Mantid::Kernel::V3D &QSampleFrame,
      boost::optional<double> detectorDistance = boost::none) override;
  void
106
  setQLabFrame(const Mantid::Kernel::V3D &qLab,
Hahn, Steven's avatar
Hahn, Steven committed
107
               boost::optional<double> detectorDistance = boost::none) override;
108

109
110
  void setWavelength(double wavelength) override;
  double getWavelength() const override;
111
  double getScattering() const override;
112
  double getAzimuthal() const override;
113
114
  double getDSpacing() const override;
  double getTOF() const override;
115

116
117
118
119
120
121
  double getInitialEnergy() const override;
  double getFinalEnergy() const override;
  double getEnergyTransfer() const override;
  void setInitialEnergy(double m_initialEnergy) override;
  void setFinalEnergy(double m_finalEnergy) override;

122
  virtual Mantid::Kernel::V3D getDetPos() const override;
123
  virtual Mantid::Kernel::V3D getSamplePos() const override;
124
125
  double getL1() const override;
  double getL2() const override;
126

127
  /// Assignment
128
  Peak &operator=(const Peak &other);
129

130
  /// Get the approximate position of a peak that falls off the detectors
131
  Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const;
132

133
private:
134
135
  bool findDetector(const Mantid::Kernel::V3D &beam,
                    const Geometry::InstrumentRayTracer &tracer);
136

137
138
139
140
141
  /// Shared pointer to the instrument (for calculating some values )
  Geometry::Instrument_const_sptr m_inst;

  /// Detector pointed to
  Geometry::IDetector_const_sptr m_det;
142

143
  /// ID of the detector
144
  int m_detectorID;
145

146
147
148
149
150
151
  /// Initial energy of neutrons at the peak
  double m_initialEnergy;

  /// Final energy of the neutrons at peak (normally same as m_InitialEnergy)
  double m_finalEnergy;

152
153
154
155
156
157
  /// Cached source position
  Mantid::Kernel::V3D sourcePos;
  /// Cached sample position
  Mantid::Kernel::V3D samplePos;
  /// Cached detector position
  Mantid::Kernel::V3D detPos;
158

159
160
  /// List of contributing detectors IDs
  std::set<int> m_detIDs;
Owen Arnold's avatar
Owen Arnold committed
161

162
163
  /// Static logger
  static Mantid::Kernel::Logger g_log;
164
};
165
166

} // namespace DataObjects
167
} // namespace Mantid