16#include "boost/make_shared.hpp"
31Peak::Peak() :
BasePeak(), m_row(-1), m_col(-1), m_detectorID(-1), m_initialEnergy(0.), m_finalEnergy(0.) {}
44 boost::optional<double> detectorDistance)
143 :
BasePeak(), m_row(-1), m_col(-1) {
150 const auto detectorDir =
V3D(sin(scattering), 0.0, cos(scattering));
169 :
BasePeak(ipeak), m_initialEnergy(ipeak.getInitialEnergy()), m_finalEnergy(ipeak.getFinalEnergy()) {
170 const auto *peak =
dynamic_cast<const Peak *
>(&ipeak);
172 throw std::invalid_argument(
"Cannot construct a Peak from this non-Peak object");
174 detid_t id = peak->getDetectorID();
182 boost::optional<double> detectorDistance)
214 throw std::runtime_error(
"Peak::setInstrument(): No instrument is set!");
217 throw std::runtime_error(
"Peak::setInstrument(): No detector was found!");
243 parent = parent->getParent();
256 parent = parent->getParent();
264 std::pair<int, int> xy = retDet->getXYForDetectorID(
m_detectorID);
303 throw std::runtime_error(
"Peak::setInstrument(): No instrument is set!");
307 if (sourceObj ==
nullptr)
309 "to get source component from "
312 if (sampleObj ==
nullptr)
314 "to get sample component from "
372 return wavelength * 1e10;
381 double L1 = this->
getL1();
382 double L2 = this->
getL2();
390 double tof = L1 / vi + L2 / vf;
402 return detDir.
angle(beamDir);
411 return atan2(detDir.
Y(), detDir.
X());
423 two_theta = detDir.
angle(beamDir);
424 }
catch (std::runtime_error &) {
444 beamDir /= beamDir.
norm();
447 detDir /= detDir.
norm();
458 double wvi = 1.0 / wi;
466 return (beamDir * wvi - detDir * wvf) * qSign;
515 throw std::invalid_argument(
"Setting QLab without an instrument would lead "
516 "to an inconsistent state for the Peak");
535 const double norm_q = qLab.
norm();
537 throw std::invalid_argument(
"Peak::setQLabFrame(): Q cannot be 0,0,0.");
539 std::shared_ptr<const ReferenceFrame> refFrame = this->
m_inst->getReferenceFrame();
540 const V3D refBeamDir = refFrame->vecPointingAlongBeam();
542 const double qSign = (
m_convention !=
"Crystallography") ? 1.0 : -1.0;
543 const double qBeam = qLab.
scalar_prod(refBeamDir) * qSign;
546 throw std::invalid_argument(
"Peak::setQLabFrame(): Q cannot be 0 in the beam direction.");
548 const double one_over_wl = (norm_q * norm_q) / (2.0 * qBeam);
549 const double wl = (2.0 * M_PI) / one_over_wl;
551 std::ostringstream mess;
552 mess <<
"Peak::setQLabFrame(): Wavelength found was negative (" << wl <<
" Ang)! This Q is not physical.";
553 throw std::invalid_argument(mess.str());
559 V3D detectorDir = -qLab * qSign;
560 detectorDir[refFrame->pointingAlongBeam()] = one_over_wl - qBeam;
564 if (detectorDistance.is_initialized()) {
574 g_log.
debug(
"Could not find detector after setting qLab via setQLab with "
584 const auto component =
getInstrument()->getComponentByName(
"extended-detector-space");
588 const auto object = std::dynamic_pointer_cast<const ObjComponent>(component);
590 return detectorDir * distance;
594 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
595 std::map<std::string, double> colVals = {
597 auto it = colVals.find(name);
598 if (it != colVals.end())
655 else if (
m_inst->hasParameter(
"tube-gap")) {
656 std::vector<double> gaps =
m_inst->getNumberParameter(
"tube-gap",
true);
658 const auto gap =
static_cast<double>(gaps.front());
661 for (
int i = 0; i < 3; i++) {
664 V3D beam1 = beam + gapDir;
667 V3D beam2 = beam - gapDir;
726 if (&other !=
this) {
755 if (det ==
nullptr) {
Structure describing a single-crystal peak.
Mantid::Kernel::Matrix< double > getInverseGoniometerMatrix() const
Get the goniometer rotation matrix at which this peak was measured.
BasePeak & operator=(BasePeak &&) noexcept=default
Mantid::Kernel::V3D m_samplePos
Cached sample position.
void setHKL(double H, double K, double L) override
Set all three H,K,L indices of the peak.
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
virtual double getValueByColName(std::string colName) const
Helper function for displaying/sorting peaks.
Structure describing a single-crystal peak.
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Structure describing a single-crystal peak.
int getCol() const override
For RectangularDetectors only, returns the column (x) of the pixel of the detector or -1 if not found...
Geometry::Instrument_const_sptr getInstrument() const
Return a shared ptr to the instrument for this peak.
Geometry::IDetector_const_sptr m_det
Detector pointed to.
Peak()
Default constructor.
double getDSpacing() const override
Calculate the d-spacing of the peak, in 1/Angstroms
int m_row
Cached row in the detector.
std::string getBankName() const
Find the name of the bank that is the parent of the detector.
const std::set< int > & getContributingDetIDs() const
Return the set of detector IDs that contribute to this peak.
void addContributingDetID(const int id)
Add a detector ID that contributed to this peak.
static Mantid::Kernel::Logger g_log
Static logger.
Mantid::Kernel::V3D getDetectorPosition() const
Forwarding function.
int getRow() const override
For RectangularDetectors only, returns the row (y) of the pixel of the detector or -1 if not found.
std::set< int > m_detIDs
List of contributing detectors IDs.
void setWavelength(double wavelength) override
Set the incident wavelength of the neutron.
std::string m_bankName
Name of the parent bank.
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
void removeContributingDetector(const int id)
Removes an ID from the list of contributing detectors.
Mantid::Kernel::V3D detPos
Cached detector position.
Peak & operator=(Peak &&) noexcept=default
double getInitialEnergy() const override
Get the initial (incident) neutron energy in meV.
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
void setRow(int row)
For RectangularDetectors only, sets the row (y) of the pixel of the detector.
void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, boost::optional< double > detectorDistance=boost::none) override
Set the peak using the peak's position in reciprocal space, in the sample frame.
void setQLabFrame(const Mantid::Kernel::V3D &qLab, boost::optional< double > detectorDistance=boost::none) override
Set the peak using the peak's position in reciprocal space, in the lab frame.
void setDetectorID(int id)
Set the detector ID of the pixel at the centre of the peak and look up and cache values related to it...
double m_initialEnergy
Initial energy of neutrons at the peak.
void setBankName(std::string bankName)
Set the BankName of this peak.
Geometry::Instrument_const_sptr m_inst
Shared pointer to the instrument (for calculating some values )
double getEnergyTransfer() const override
Get the difference between the initial and final neutron energy in meV.
Mantid::Kernel::V3D sourcePos
Cached source position.
double getAzimuthal() const override
Calculate the azimuthal angle of the peak
int m_col
Cached column in the detector.
bool findDetector()
After creating a peak using the Q in the lab frame, the detPos is set to the direction of the detecto...
Geometry::IDetector_const_sptr getDetector() const
Return a shared ptr to the detector at center of peak.
void setInitialEnergy(double m_initialEnergy) override
Set the initial energy.
double getFinalEnergy() const override
Get the final neutron energy in meV.
Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const
Get the approximate position of a peak that falls off the detectors.
double getWavelength() const override
Calculate the neutron wavelength (in angstroms) at the peak (Note for inelastic scattering - it is th...
void setCol(int col)
For RectangularDetectors only, sets the column (x) of the pixel of the detector.
double getTOF() const override
Calculate the time of flight (in microseconds) of the neutrons for this peak, using the geometry of t...
std::shared_ptr< const Geometry::ReferenceFrame > getReferenceFrame() const override
Return a shared ptr to the reference frame from the instrument for this peak.
virtual Mantid::Kernel::V3D getDetPos() const
Return the detector position vector.
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
double getL2() const override
Return the L2 flight path length (sample to detector), in meters.
int getDetectorID() const
Get the ID of the detector at the center of the peak
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
void setFinalEnergy(double m_finalEnergy) override
Set the final energy.
double getScattering() const override
Calculate the scattering angle of the peak
double getValueByColName(std::string colName) const override
Helper function for displaying/sorting peaks.
Mantid::Kernel::V3D getDetectorPositionNoCheck() const
Forwarding function.
double m_finalEnergy
Final energy of the neutrons at peak (normally same as m_InitialEnergy)
int m_detectorID
ID of the detector.
Structure describing a single-crystal peak.
This class is responsible for tracking rays and accumulating a list of objects that are intersected a...
IDetector_const_sptr getDetectorResult() const
Gets the results of the trace, then returns the first detector (that is NOT a monitor) found in the r...
void traceFromSample(const Kernel::V3D &dir) const
Trace a given track from the sample position in the given direction.
Defines a track as a start point and a direction.
Exception for errors associated with the instrument definition.
Exception thrown when an attempt is made to dereference a null pointer.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
constexpr double X() const noexcept
Get x.
double normalize()
Make a normalized vector (return norm value)
constexpr double Y() const noexcept
Get y.
std::string toString() const
double angle(const V3D &) const
Angle between this and another vector.
double norm() const noexcept
double cosAngle(const V3D &) const
cos(Angle) between this and another vector
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< const RectangularDetector > RectangularDetector_const_sptr
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::shared_ptr< Mantid::Geometry::IDetector > IDetector_sptr
Shared pointer to IDetector.
MANTID_KERNEL_DLL int endsWithInt(const std::string &word)
Get an int from the end of a word.
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double h
Planck constant in J*s.
static constexpr double meV
1 meV in Joules.
static constexpr double h_bar
Planck constant in J*s, divided by 2 PI.
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.