Commit 2055b957 authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Move energy/wavelength out of BasePeak and into Peak/LeanElasticPeak

parent b4ac05af
...@@ -78,14 +78,6 @@ public: ...@@ -78,14 +78,6 @@ public:
void setIntHKL(const Kernel::V3D &HKL) override; void setIntHKL(const Kernel::V3D &HKL) override;
void setIntMNP(const Mantid::Kernel::V3D &MNP) override; void setIntMNP(const Mantid::Kernel::V3D &MNP) override;
void setWavelength(double wavelength) override;
double getWavelength() const override;
double getInitialEnergy() const override;
double getFinalEnergy() const override;
double getEnergyTransfer() const override;
void setInitialEnergy(double m_initialEnergy) override;
void setFinalEnergy(double m_finalEnergy) override;
double getIntensity() const override; double getIntensity() const override;
double getSigmaIntensity() const override; double getSigmaIntensity() const override;
double getIntensityOverSigma() const override; double getIntensityOverSigma() const override;
...@@ -148,12 +140,6 @@ private: ...@@ -148,12 +140,6 @@ private:
/// Count in the bin at the peak /// Count in the bin at the peak
double m_binCount; double m_binCount;
/// 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;
/// absorption weighted path length (aka t bar) /// absorption weighted path length (aka t bar)
double m_absorptionWeightedPathLength; double m_absorptionWeightedPathLength;
......
...@@ -83,11 +83,19 @@ public: ...@@ -83,11 +83,19 @@ public:
void setQLabFrame(const Mantid::Kernel::V3D &qLab, void setQLabFrame(const Mantid::Kernel::V3D &qLab,
boost::optional<double> = boost::none) override; boost::optional<double> = boost::none) override;
void setWavelength(double wavelength) override;
double getWavelength() const override;
double getScattering() const override; double getScattering() const override;
double getAzimuthal() const override; double getAzimuthal() const override;
double getDSpacing() const override; double getDSpacing() const override;
double getTOF() const override; double getTOF() const override;
double getInitialEnergy() const override;
double getFinalEnergy() const override;
double getEnergyTransfer() const override;
void setInitialEnergy(double m_initialEnergy) override;
void setFinalEnergy(double m_finalEnergy) override;
virtual Mantid::Kernel::V3D getDetPos() const override; virtual Mantid::Kernel::V3D getDetPos() const override;
virtual Mantid::Kernel::V3D getSamplePos() const override; virtual Mantid::Kernel::V3D getSamplePos() const override;
double getL1() const override; double getL1() const override;
...@@ -100,6 +108,9 @@ private: ...@@ -100,6 +108,9 @@ private:
/// Q_sample vector /// Q_sample vector
Mantid::Kernel::V3D m_Qsample; Mantid::Kernel::V3D m_Qsample;
/// Initial energy of neutrons at the peak
double m_wavelength;
/// Static logger /// Static logger
static Mantid::Kernel::Logger g_log; static Mantid::Kernel::Logger g_log;
}; };
......
...@@ -104,11 +104,19 @@ public: ...@@ -104,11 +104,19 @@ public:
setQLabFrame(const Mantid::Kernel::V3D &qLab, setQLabFrame(const Mantid::Kernel::V3D &qLab,
boost::optional<double> detectorDistance = boost::none) override; boost::optional<double> detectorDistance = boost::none) override;
void setWavelength(double wavelength) override;
double getWavelength() const override;
double getScattering() const override; double getScattering() const override;
double getAzimuthal() const override; double getAzimuthal() const override;
double getDSpacing() const override; double getDSpacing() const override;
double getTOF() const override; double getTOF() const override;
double getInitialEnergy() const override;
double getFinalEnergy() const override;
double getEnergyTransfer() const override;
void setInitialEnergy(double m_initialEnergy) override;
void setFinalEnergy(double m_finalEnergy) override;
virtual Mantid::Kernel::V3D getDetPos() const override; virtual Mantid::Kernel::V3D getDetPos() const override;
virtual Mantid::Kernel::V3D getSamplePos() const override; virtual Mantid::Kernel::V3D getSamplePos() const override;
double getL1() const override; double getL1() const override;
...@@ -133,6 +141,12 @@ private: ...@@ -133,6 +141,12 @@ private:
/// ID of the detector /// ID of the detector
int m_detectorID; int m_detectorID;
/// 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;
/// Cached source position /// Cached source position
Mantid::Kernel::V3D sourcePos; Mantid::Kernel::V3D sourcePos;
/// Cached sample position /// Cached sample position
......
...@@ -32,11 +32,11 @@ namespace DataObjects { ...@@ -32,11 +32,11 @@ namespace DataObjects {
/** Default constructor */ /** Default constructor */
BasePeak::BasePeak() BasePeak::BasePeak()
: m_H(0), m_K(0), m_L(0), m_intensity(0), m_sigmaIntensity(0), : m_H(0), m_K(0), m_L(0), m_intensity(0), m_sigmaIntensity(0),
m_binCount(0), m_initialEnergy(0.), m_finalEnergy(0.), m_binCount(0), m_absorptionWeightedPathLength(0),
m_absorptionWeightedPathLength(0), m_GoniometerMatrix(3, 3, true), m_GoniometerMatrix(3, 3, true), m_InverseGoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_runNumber(0), m_monitorCount(0), m_runNumber(0), m_monitorCount(0), m_row(-1), m_col(-1), m_peakNumber(0),
m_row(-1), m_col(-1), m_peakNumber(0), m_intHKL(V3D(0, 0, 0)), m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) {} m_peakShape(std::make_shared<NoShape>()) {}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Constructor including goniometer /** Constructor including goniometer
...@@ -46,11 +46,11 @@ BasePeak::BasePeak() ...@@ -46,11 +46,11 @@ BasePeak::BasePeak()
BasePeak::BasePeak(const Mantid::Kernel::Matrix<double> &goniometer) BasePeak::BasePeak(const Mantid::Kernel::Matrix<double> &goniometer)
: m_H(0), m_K(0), m_L(0), m_intensity(0), m_sigmaIntensity(0), : m_H(0), m_K(0), m_L(0), m_intensity(0), m_sigmaIntensity(0),
m_binCount(0), m_initialEnergy(0.), m_finalEnergy(0.), m_binCount(0), m_absorptionWeightedPathLength(0),
m_absorptionWeightedPathLength(0), m_GoniometerMatrix(goniometer), m_GoniometerMatrix(goniometer), m_InverseGoniometerMatrix(goniometer),
m_InverseGoniometerMatrix(goniometer), m_runNumber(0), m_monitorCount(0), m_runNumber(0), m_monitorCount(0), m_row(-1), m_col(-1), m_peakNumber(0),
m_row(-1), m_col(-1), m_peakNumber(0), m_intHKL(V3D(0, 0, 0)), m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) { m_peakShape(std::make_shared<NoShape>()) {
if (fabs(m_InverseGoniometerMatrix.Invert()) < 1e-8) if (fabs(m_InverseGoniometerMatrix.Invert()) < 1e-8)
throw std::invalid_argument( throw std::invalid_argument(
"BasePeak::ctor(): Goniometer matrix must non-singular."); "BasePeak::ctor(): Goniometer matrix must non-singular.");
...@@ -60,8 +60,6 @@ BasePeak::BasePeak(const BasePeak &other) ...@@ -60,8 +60,6 @@ BasePeak::BasePeak(const BasePeak &other)
: m_bankName(other.m_bankName), m_H(other.m_H), m_K(other.m_K), : m_bankName(other.m_bankName), m_H(other.m_H), m_K(other.m_K),
m_L(other.m_L), m_intensity(other.m_intensity), m_L(other.m_L), m_intensity(other.m_intensity),
m_sigmaIntensity(other.m_sigmaIntensity), m_binCount(other.m_binCount), m_sigmaIntensity(other.m_sigmaIntensity), m_binCount(other.m_binCount),
m_initialEnergy(other.m_initialEnergy),
m_finalEnergy(other.m_finalEnergy),
m_absorptionWeightedPathLength(other.m_absorptionWeightedPathLength), m_absorptionWeightedPathLength(other.m_absorptionWeightedPathLength),
m_GoniometerMatrix(other.m_GoniometerMatrix), m_GoniometerMatrix(other.m_GoniometerMatrix),
m_InverseGoniometerMatrix(other.m_InverseGoniometerMatrix), m_InverseGoniometerMatrix(other.m_InverseGoniometerMatrix),
...@@ -80,8 +78,6 @@ BasePeak::BasePeak(const Geometry::IPeak &ipeak) ...@@ -80,8 +78,6 @@ BasePeak::BasePeak(const Geometry::IPeak &ipeak)
m_intensity(ipeak.getIntensity()), m_intensity(ipeak.getIntensity()),
m_sigmaIntensity(ipeak.getSigmaIntensity()), m_sigmaIntensity(ipeak.getSigmaIntensity()),
m_binCount(ipeak.getBinCount()), m_binCount(ipeak.getBinCount()),
m_initialEnergy(ipeak.getInitialEnergy()),
m_finalEnergy(ipeak.getFinalEnergy()),
m_absorptionWeightedPathLength(ipeak.getAbsorptionWeightedPathLength()), m_absorptionWeightedPathLength(ipeak.getAbsorptionWeightedPathLength()),
m_GoniometerMatrix(ipeak.getGoniometerMatrix()), m_GoniometerMatrix(ipeak.getGoniometerMatrix()),
m_InverseGoniometerMatrix(ipeak.getGoniometerMatrix()), m_InverseGoniometerMatrix(ipeak.getGoniometerMatrix()),
...@@ -95,39 +91,6 @@ BasePeak::BasePeak(const Geometry::IPeak &ipeak) ...@@ -95,39 +91,6 @@ BasePeak::BasePeak(const Geometry::IPeak &ipeak)
"Peak::ctor(): Goniometer matrix must non-singular."); "Peak::ctor(): Goniometer matrix must non-singular.");
} }
//----------------------------------------------------------------------------------------------
/** Set the incident wavelength of the neutron. Calculates the energy from this.
* Assumes elastic scattering.
*
* @param wavelength :: wavelength in Angstroms.
*/
void BasePeak::setWavelength(double wavelength) {
// Velocity of the neutron (non-relativistic)
double velocity = PhysicalConstants::h /
(wavelength * 1e-10 * PhysicalConstants::NeutronMass);
// Energy in J of the neutron
double energy = PhysicalConstants::NeutronMass * velocity * velocity / 2.0;
// Convert to meV
m_initialEnergy = energy / PhysicalConstants::meV;
m_finalEnergy = m_initialEnergy;
}
// -------------------------------------------------------------------------------------
/** Calculate the neutron wavelength (in angstroms) at the peak
* (Note for inelastic scattering - it is the wavelength corresponding to the
* final energy)*/
double BasePeak::getWavelength() const {
// Energy in J of the neutron
double energy = PhysicalConstants::meV * m_finalEnergy;
// v = sqrt(2.0 * E / m)
double velocity = sqrt(2.0 * energy / PhysicalConstants::NeutronMass);
// wavelength = h / mv
double wavelength =
PhysicalConstants::h / (PhysicalConstants::NeutronMass * velocity);
// Return it in angstroms
return wavelength * 1e10;
}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Return the run number this peak was measured at. */ /** Return the run number this peak was measured at. */
int BasePeak::getRunNumber() const { return m_runNumber; } int BasePeak::getRunNumber() const { return m_runNumber; }
...@@ -148,18 +111,6 @@ void BasePeak::setMonitorCount(double m_monitorCount) { ...@@ -148,18 +111,6 @@ void BasePeak::setMonitorCount(double m_monitorCount) {
this->m_monitorCount = m_monitorCount; this->m_monitorCount = m_monitorCount;
} }
//----------------------------------------------------------------------------------------------
/** Get the final neutron energy in meV */
double BasePeak::getFinalEnergy() const { return m_finalEnergy; }
/** Get the initial (incident) neutron energy in meV */
double BasePeak::getInitialEnergy() const { return m_initialEnergy; }
/** Get the difference between the initial and final neutron energy in meV */
double BasePeak::getEnergyTransfer() const {
return getInitialEnergy() - getFinalEnergy();
}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Get the H index of the peak */ /** Get the H index of the peak */
double BasePeak::getH() const { return m_H; } double BasePeak::getH() const { return m_H; }
...@@ -267,18 +218,6 @@ void BasePeak::setSigmaIntensity(double m_sigmaIntensity) { ...@@ -267,18 +218,6 @@ void BasePeak::setSigmaIntensity(double m_sigmaIntensity) {
this->m_sigmaIntensity = m_sigmaIntensity; this->m_sigmaIntensity = m_sigmaIntensity;
} }
/** Set the final energy
* @param m_finalEnergy :: final energy in meV */
void BasePeak::setFinalEnergy(double m_finalEnergy) {
this->m_finalEnergy = m_finalEnergy;
}
/** Set the initial energy
* @param m_initialEnergy :: initial energy in meV */
void BasePeak::setInitialEnergy(double m_initialEnergy) {
this->m_initialEnergy = m_initialEnergy;
}
// ------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------
/** Get the goniometer rotation matrix at which this peak was measured. */ /** Get the goniometer rotation matrix at which this peak was measured. */
Mantid::Kernel::Matrix<double> BasePeak::getGoniometerMatrix() const { Mantid::Kernel::Matrix<double> BasePeak::getGoniometerMatrix() const {
...@@ -438,8 +377,6 @@ BasePeak &BasePeak::operator=(const BasePeak &other) { ...@@ -438,8 +377,6 @@ BasePeak &BasePeak::operator=(const BasePeak &other) {
m_intensity = other.m_intensity; m_intensity = other.m_intensity;
m_sigmaIntensity = other.m_sigmaIntensity; m_sigmaIntensity = other.m_sigmaIntensity;
m_binCount = other.m_binCount; m_binCount = other.m_binCount;
m_initialEnergy = other.m_initialEnergy;
m_finalEnergy = other.m_finalEnergy;
m_GoniometerMatrix = other.m_GoniometerMatrix; m_GoniometerMatrix = other.m_GoniometerMatrix;
m_InverseGoniometerMatrix = other.m_InverseGoniometerMatrix; m_InverseGoniometerMatrix = other.m_InverseGoniometerMatrix;
m_runNumber = other.m_runNumber; m_runNumber = other.m_runNumber;
......
...@@ -30,7 +30,8 @@ namespace DataObjects { ...@@ -30,7 +30,8 @@ namespace DataObjects {
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Default constructor */ /** Default constructor */
LeanElasticPeak::LeanElasticPeak() : BasePeak(), m_Qsample(V3D(0, 0, 0)) {} LeanElasticPeak::LeanElasticPeak()
: BasePeak(), m_Qsample(V3D(0, 0, 0)), m_wavelength(0.) {}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Constructor that uses the Q position of the peak (in the sample frame) /** Constructor that uses the Q position of the peak (in the sample frame)
...@@ -55,9 +56,7 @@ LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame) ...@@ -55,9 +56,7 @@ LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame)
LeanElasticPeak::LeanElasticPeak( LeanElasticPeak::LeanElasticPeak(
const Mantid::Kernel::V3D &QSampleFrame, const Mantid::Kernel::V3D &QSampleFrame,
const Mantid::Kernel::Matrix<double> &goniometer) const Mantid::Kernel::Matrix<double> &goniometer)
: BasePeak(goniometer) { : BasePeak(goniometer), m_Qsample(QSampleFrame) {}
this->setQSampleFrame(QSampleFrame);
}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Constructor that uses the Q position of the peak (in the sample frame) /** Constructor that uses the Q position of the peak (in the sample frame)
...@@ -70,10 +69,7 @@ LeanElasticPeak::LeanElasticPeak( ...@@ -70,10 +69,7 @@ LeanElasticPeak::LeanElasticPeak(
*/ */
LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame, LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame,
double wavelength) double wavelength)
: BasePeak() { : BasePeak(), m_Qsample(QSampleFrame), m_wavelength(wavelength) {}
this->setQSampleFrame(QSampleFrame);
this->setWavelength(wavelength);
}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Constructor that uses the Q position of the peak (in the lab frame). /** Constructor that uses the Q position of the peak (in the lab frame).
...@@ -86,17 +82,15 @@ LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame, ...@@ -86,17 +82,15 @@ LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame,
LeanElasticPeak::LeanElasticPeak( LeanElasticPeak::LeanElasticPeak(
const Mantid::Kernel::V3D &QSampleFrame, const Mantid::Kernel::V3D &QSampleFrame,
const Mantid::Kernel::Matrix<double> &goniometer, double wavelength) const Mantid::Kernel::Matrix<double> &goniometer, double wavelength)
: BasePeak(goniometer) { : BasePeak(goniometer), m_Qsample(QSampleFrame), m_wavelength(wavelength) {}
this->setQSampleFrame(QSampleFrame);
this->setWavelength(wavelength);
}
/** /**
* @brief Copy constructor * @brief Copy constructor
* @param other : Source * @param other : Source
*/ */
LeanElasticPeak::LeanElasticPeak(const LeanElasticPeak &other) LeanElasticPeak::LeanElasticPeak(const LeanElasticPeak &other)
: BasePeak(other), m_Qsample(other.m_Qsample) {} : BasePeak(other), m_Qsample(other.m_Qsample),
m_wavelength(other.m_wavelength) {}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Constructor making a LeanElasticPeak from IPeak interface /** Constructor making a LeanElasticPeak from IPeak interface
...@@ -104,7 +98,17 @@ LeanElasticPeak::LeanElasticPeak(const LeanElasticPeak &other) ...@@ -104,7 +98,17 @@ LeanElasticPeak::LeanElasticPeak(const LeanElasticPeak &other)
* @param ipeak :: const reference to an IPeak object * @param ipeak :: const reference to an IPeak object
*/ */
LeanElasticPeak::LeanElasticPeak(const Geometry::IPeak &ipeak) LeanElasticPeak::LeanElasticPeak(const Geometry::IPeak &ipeak)
: BasePeak(ipeak), m_Qsample(ipeak.getQSampleFrame()) {} : BasePeak(ipeak), m_Qsample(ipeak.getQSampleFrame()),
m_wavelength(ipeak.getWavelength()) {}
//----------------------------------------------------------------------------------------------
/** Set the wavelength of the neutron. Assumes elastic scattering.
*
* @param wavelength :: wavelength in Angstroms.
*/
void LeanElasticPeak::setWavelength(double wavelength) {
m_wavelength = wavelength;
}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Set the detector ID of the pixel at the centre of the peak and look up and /** Set the detector ID of the pixel at the centre of the peak and look up and
...@@ -145,6 +149,10 @@ Geometry::Instrument_const_sptr LeanElasticPeak::getInstrument() const { ...@@ -145,6 +149,10 @@ Geometry::Instrument_const_sptr LeanElasticPeak::getInstrument() const {
"LeanElasticPeak::setInstrument(): Has no instrument"); "LeanElasticPeak::setInstrument(): Has no instrument");
} }
// -------------------------------------------------------------------------------------
/** Return the neutron wavelength (in angstroms) */
double LeanElasticPeak::getWavelength() const { return m_wavelength; }
// ------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------
/** Calculate the time of flight (in microseconds) of the neutrons for this /** Calculate the time of flight (in microseconds) of the neutrons for this
* peak, * peak,
...@@ -222,22 +230,49 @@ void LeanElasticPeak::setQLabFrame(const Mantid::Kernel::V3D &qLab, ...@@ -222,22 +230,49 @@ void LeanElasticPeak::setQLabFrame(const Mantid::Kernel::V3D &qLab,
this->setQSampleFrame(getInverseGoniometerMatrix() * qLab); this->setQSampleFrame(getInverseGoniometerMatrix() * qLab);
} }
/** Set sample position //----------------------------------------------------------------------------------------------
* /** Get the final neutron energy in meV */
*/ double LeanElasticPeak::getFinalEnergy() const {
// Velocity of the neutron (non-relativistic)
const double velocity =
PhysicalConstants::h /
(m_wavelength * 1e-10 * PhysicalConstants::NeutronMass);
// Energy in J of the neutron
const double energy =
PhysicalConstants::NeutronMass * velocity * velocity / 2.0;
// Convert to meV
return energy / PhysicalConstants::meV;
}
/** Get the initial (incident) neutron energy in meV */
double LeanElasticPeak::getInitialEnergy() const { return getFinalEnergy(); }
/** Get the difference between the initial and final neutron energy in meV,
* elastic so always 0 */
double LeanElasticPeak::getEnergyTransfer() const { return 0.; }
/** Set sample position */
void LeanElasticPeak::setSamplePos(double, double, double) { void LeanElasticPeak::setSamplePos(double, double, double) {
throw Exception::NotImplementedError( throw Exception::NotImplementedError(
"LeanElasticPeak has no sample information"); "LeanElasticPeak has no sample information");
} }
/** Set sample position /** Set sample position */
*
*/
void LeanElasticPeak::setSamplePos(const Mantid::Kernel::V3D &) { void LeanElasticPeak::setSamplePos(const Mantid::Kernel::V3D &) {
throw Exception::NotImplementedError( throw Exception::NotImplementedError(
"LeanElasticPeak has no sample information"); "LeanElasticPeak has no sample information");
} }
/** Set the final energy */
void LeanElasticPeak::setFinalEnergy(double) {
throw Exception::NotImplementedError("Use LeanElasticPeak::setWavelength");
}
/** Set the initial energy */
void LeanElasticPeak::setInitialEnergy(double) {
throw Exception::NotImplementedError("Use LeanElasticPeak::setWavelength");
}
// ------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------
/** Return the detector position vector */ /** Return the detector position vector */
Mantid::Kernel::V3D LeanElasticPeak::getDetPos() const { Mantid::Kernel::V3D LeanElasticPeak::getDetPos() const {
...@@ -275,6 +310,7 @@ LeanElasticPeak &LeanElasticPeak::operator=(const LeanElasticPeak &other) { ...@@ -275,6 +310,7 @@ LeanElasticPeak &LeanElasticPeak::operator=(const LeanElasticPeak &other) {
if (&other != this) { if (&other != this) {
BasePeak::operator=(other); BasePeak::operator=(other);
m_Qsample = other.m_Qsample; m_Qsample = other.m_Qsample;
m_wavelength = other.m_wavelength;
} }
return *this; return *this;
} }
......
...@@ -30,7 +30,8 @@ namespace DataObjects { ...@@ -30,7 +30,8 @@ namespace DataObjects {
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Default constructor */ /** Default constructor */
Peak::Peak() : BasePeak(), m_detectorID(-1) { Peak::Peak()
: BasePeak(), m_detectorID(-1), m_initialEnergy(0.), m_finalEnergy(0.) {
convention = Kernel::ConfigService::Instance().getString("Q.convention"); convention = Kernel::ConfigService::Instance().getString("Q.convention");
} }
...@@ -159,7 +160,8 @@ Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering, ...@@ -159,7 +160,8 @@ Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering,
*/ */
Peak::Peak(const Peak &other) Peak::Peak(const Peak &other)
: BasePeak(other), m_inst(other.m_inst), m_det(other.m_det), : BasePeak(other), m_inst(other.m_inst), m_det(other.m_det),
m_detectorID(other.m_detectorID), sourcePos(other.sourcePos), m_detectorID(other.m_detectorID), m_initialEnergy(other.m_initialEnergy),
m_finalEnergy(other.m_finalEnergy), sourcePos(other.sourcePos),
samplePos(other.samplePos), detPos(other.detPos), samplePos(other.samplePos), detPos(other.detPos),
m_detIDs(other.m_detIDs), convention(other.convention) {} m_detIDs(other.m_detIDs), convention(other.convention) {}
...@@ -170,7 +172,9 @@ Peak::Peak(const Peak &other) ...@@ -170,7 +172,9 @@ Peak::Peak(const Peak &other)
* @return * @return
*/ */
Peak::Peak(const Geometry::IPeak &ipeak) Peak::Peak(const Geometry::IPeak &ipeak)
: BasePeak(ipeak), m_detectorID(ipeak.getDetectorID()) { : BasePeak(ipeak), m_detectorID(ipeak.getDetectorID()),
m_initialEnergy(ipeak.getInitialEnergy()),
m_finalEnergy(ipeak.getFinalEnergy()) {
convention = Kernel::ConfigService::Instance().getString("Q.convention"); convention = Kernel::ConfigService::Instance().getString("Q.convention");
setInstrument(ipeak.getInstrument()); setInstrument(ipeak.getInstrument());
detid_t id = ipeak.getDetectorID(); detid_t id = ipeak.getDetectorID();
...@@ -182,6 +186,23 @@ Peak::Peak(const Geometry::IPeak &ipeak) ...@@ -182,6 +186,23 @@ Peak::Peak(const Geometry::IPeak &ipeak)
} }
} }
//----------------------------------------------------------------------------------------------
/** Set the incident wavelength of the neutron. Calculates the energy from this.
* Assumes elastic scattering.
*
* @param wavelength :: wavelength in Angstroms.
*/
void Peak::setWavelength(double wavelength) {
// Velocity of the neutron (non-relativistic)
double velocity = PhysicalConstants::h /
(wavelength * 1e-10 * PhysicalConstants::NeutronMass);
// Energy in J of the neutron
double energy = PhysicalConstants::NeutronMass * velocity * velocity / 2.0;
// Convert to meV
m_initialEnergy = energy / PhysicalConstants::meV;
m_finalEnergy = m_initialEnergy;
}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Set the detector ID of the pixel at the centre of the peak and look up and /** Set the detector ID of the pixel at the centre of the peak and look up and
* cache * cache
...@@ -308,6 +329,22 @@ Geometry::IDetector_const_sptr Peak::getDetector() const { return m_det; } ...@@ -308,6 +329,22 @@ Geometry::IDetector_const_sptr Peak::getDetector() const { return m_det; }
/** Return a shared ptr to the instrument for this peak. */ /** Return a shared ptr to the instrument for this peak. */
Geometry::Instrument_const_sptr Peak::getInstrument() const { return m_inst; } Geometry::Instrument_const_sptr Peak::getInstrument() const { return m_inst; }
// -------------------------------------------------------------------------------------
/** Calculate the neutron wavelength (in angstroms) at the peak
* (Note for inelastic scattering - it is the wavelength corresponding to the
* final energy)*/
double Peak::getWavelength() const {
// Energy in J of the neutron
double energy = PhysicalConstants::meV * m_finalEnergy;
// v = sqrt(2.0 * E / m)
double velocity = sqrt(2.0 * energy / PhysicalConstants::NeutronMass);
// wavelength = h / mv
double wavelength =
PhysicalConstants::h / (PhysicalConstants::NeutronMass * velocity);
// Return it in angstroms
return wavelength * 1e10;
}
// ------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------
/** Calculate the time of flight (in microseconds) of the neutrons for this /** Calculate the time of flight (in microseconds) of the neutrons for this