Peak.h 5.5 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
29
30
31
32
33
namespace DataObjects {

/** Structure describing a single-crystal peak
 *
 * @author Janik Zikovsky
 * @date 2011-04-15 13:24:07.963491
 */
34
class DLLExport Peak : public BasePeak {
35
36
37
38
39
public:
  /// Allow PeakColumn class to directly access members.
  friend class PeakColumn;

  Peak();
Hahn, Steven's avatar
Hahn, Steven committed
40
41
42
  Peak(const Geometry::Instrument_const_sptr &m_inst,
       const Mantid::Kernel::V3D &QLabFrame,
       boost::optional<double> detectorDistance = boost::none);
43
44
45
  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
46
       boost::optional<double> detectorDistance = boost::none);
47
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
48
       double m_Wavelength);
49
50
51
52
53
54
  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,
55
56
       double m_Wavelength);

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

LamarMoore's avatar
LamarMoore committed
60
61
62
63
64
  // 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
65

66
#if defined(_MSC_VER) && _MSC_VER <= 1910
67
68
  Peak(Peak &&) = default;
  Peak &operator=(Peak &&) = default;
LamarMoore's avatar
LamarMoore committed
69
#elif ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ <= 8))
DavidFair's avatar
DavidFair committed
70
71
  // The noexcept default declaration was fixed in GCC 4.9.0
  // so for versions 4.8.x and below use default only
72
  // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53903
73
74
  Peak(Peak &&) = default;
  Peak &operator=(Peak &&) = default;
75
#else
76
77
  Peak(Peak &&) noexcept = default;
  Peak &operator=(Peak &&) noexcept = default;
78
#endif
79

80
  // Construct a peak from a reference to the interface
81

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

84
85
  void setDetectorID(int id) override;
  int getDetectorID() const override;
86
87
88
89
  void addContributingDetID(const int id);
  void removeContributingDetector(const int id);
  const std::set<int> &getContributingDetIDs() const;

90
  void setInstrument(const Geometry::Instrument_const_sptr &inst) override;
91
92
  Geometry::IDetector_const_sptr getDetector() const override;
  Geometry::Instrument_const_sptr getInstrument() const override;
93

94
  bool findDetector() override;
95
  bool findDetector(const Geometry::InstrumentRayTracer &tracer) override;
96

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

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

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

112
  double getScattering() const override;
113
  double getAzimuthal() const override;
114
115
  double getDSpacing() const override;
  double getTOF() const override;
116

117
  virtual Mantid::Kernel::V3D getDetPos() const override;
118
  virtual Mantid::Kernel::V3D getSamplePos() const override;
119
120
  double getL1() const override;
  double getL2() const override;
121

122
  /// Assignment
123
  Peak &operator=(const Peak &other);
124

125
  /// Get the approximate position of a peak that falls off the detectors
126
  Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const;
127

128
private:
129
130
  bool findDetector(const Mantid::Kernel::V3D &beam,
                    const Geometry::InstrumentRayTracer &tracer);
131

132
133
134
135
136
  /// Shared pointer to the instrument (for calculating some values )
  Geometry::Instrument_const_sptr m_inst;

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

138
  /// ID of the detector
139
  int m_detectorID;
140

141
142
143
144
145
146
  /// Cached source position
  Mantid::Kernel::V3D sourcePos;
  /// Cached sample position
  Mantid::Kernel::V3D samplePos;
  /// Cached detector position
  Mantid::Kernel::V3D detPos;
147

148
149
  /// List of contributing detectors IDs
  std::set<int> m_detIDs;
Owen Arnold's avatar
Owen Arnold committed
150

151
152
  /// Static logger
  static Mantid::Kernel::Logger g_log;
153
154

  // ki-kf for Inelastic convention; kf-ki for Crystallography convention
155
  std::string convention;
156
};
157
158

} // namespace DataObjects
159
} // namespace Mantid