Peak.h 5.97 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
  /*
92
  bool findDetector() override;
93
  bool findDetector(const Geometry::InstrumentRayTracer &tracer) override;
94
95
96
  */
  bool findDetector();
  bool findDetector(const Geometry::InstrumentRayTracer &tracer);
97

98
99
  void setSamplePos(double samX, double samY, double samZ) override;
  void setSamplePos(const Mantid::Kernel::V3D &XYZ) override;
100

101
102
103
104
  Mantid::Kernel::V3D getQLabFrame() const override;
  Mantid::Kernel::V3D getQSampleFrame() const override;
  Mantid::Kernel::V3D getDetectorPosition() const override;
  Mantid::Kernel::V3D getDetectorPositionNoCheck() const override;
105

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

113
114
  void setWavelength(double wavelength) override;
  double getWavelength() const override;
115
  double getScattering() const override;
116
  double getAzimuthal() const override;
117
118
  double getDSpacing() const override;
  double getTOF() const override;
119

120
121
122
123
124
125
  double getInitialEnergy() const override;
  double getFinalEnergy() const override;
  double getEnergyTransfer() const override;
  void setInitialEnergy(double m_initialEnergy) override;
  void setFinalEnergy(double m_finalEnergy) override;

126
  virtual Mantid::Kernel::V3D getDetPos() const override;
127
  virtual Mantid::Kernel::V3D getSamplePos() const override;
128
129
  double getL1() const override;
  double getL2() const override;
130

131
  /// Assignment
132
  Peak &operator=(const Peak &other);
133

134
  /// Get the approximate position of a peak that falls off the detectors
135
  Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const;
136

137
private:
138
139
  bool findDetector(const Mantid::Kernel::V3D &beam,
                    const Geometry::InstrumentRayTracer &tracer);
140

141
142
143
144
145
  /// Shared pointer to the instrument (for calculating some values )
  Geometry::Instrument_const_sptr m_inst;

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

147
  /// ID of the detector
148
  int m_detectorID;
149

150
151
152
153
154
155
  /// 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;

156
157
158
159
160
161
  /// Cached source position
  Mantid::Kernel::V3D sourcePos;
  /// Cached sample position
  Mantid::Kernel::V3D samplePos;
  /// Cached detector position
  Mantid::Kernel::V3D detPos;
162

163
164
  /// List of contributing detectors IDs
  std::set<int> m_detIDs;
Owen Arnold's avatar
Owen Arnold committed
165

166
167
  /// Static logger
  static Mantid::Kernel::Logger g_log;
168
};
169

170
171
using Peak_uptr = std::unique_ptr<Peak>;

172
} // namespace DataObjects
173
} // namespace Mantid