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:
void setIntHKL(const Kernel::V3D &HKL) 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 getSigmaIntensity() const override;
double getIntensityOverSigma() const override;
......@@ -148,12 +140,6 @@ private:
/// Count in the bin at the peak
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)
double m_absorptionWeightedPathLength;
......
......@@ -83,11 +83,19 @@ public:
void setQLabFrame(const Mantid::Kernel::V3D &qLab,
boost::optional<double> = boost::none) override;
void setWavelength(double wavelength) override;
double getWavelength() const override;
double getScattering() const override;
double getAzimuthal() const override;
double getDSpacing() 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 getSamplePos() const override;
double getL1() const override;
......@@ -100,6 +108,9 @@ private:
/// Q_sample vector
Mantid::Kernel::V3D m_Qsample;
/// Initial energy of neutrons at the peak
double m_wavelength;
/// Static logger
static Mantid::Kernel::Logger g_log;
};
......
......@@ -104,11 +104,19 @@ public:
setQLabFrame(const Mantid::Kernel::V3D &qLab,
boost::optional<double> detectorDistance = boost::none) override;
void setWavelength(double wavelength) override;
double getWavelength() const override;
double getScattering() const override;
double getAzimuthal() const override;
double getDSpacing() 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 getSamplePos() const override;
double getL1() const override;
......@@ -133,6 +141,12 @@ private:
/// ID of the detector
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
Mantid::Kernel::V3D sourcePos;
/// Cached sample position
......
......@@ -32,11 +32,11 @@ namespace DataObjects {
/** Default constructor */
BasePeak::BasePeak()
: 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_absorptionWeightedPathLength(0), m_GoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_runNumber(0), m_monitorCount(0),
m_row(-1), m_col(-1), m_peakNumber(0), m_intHKL(V3D(0, 0, 0)),
m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) {}
m_binCount(0), m_absorptionWeightedPathLength(0),
m_GoniometerMatrix(3, 3, true), m_InverseGoniometerMatrix(3, 3, true),
m_runNumber(0), m_monitorCount(0), m_row(-1), m_col(-1), m_peakNumber(0),
m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_peakShape(std::make_shared<NoShape>()) {}
//----------------------------------------------------------------------------------------------
/** Constructor including goniometer
......@@ -46,11 +46,11 @@ BasePeak::BasePeak()
BasePeak::BasePeak(const Mantid::Kernel::Matrix<double> &goniometer)
: 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_absorptionWeightedPathLength(0), m_GoniometerMatrix(goniometer),
m_InverseGoniometerMatrix(goniometer), m_runNumber(0), m_monitorCount(0),
m_row(-1), m_col(-1), m_peakNumber(0), m_intHKL(V3D(0, 0, 0)),
m_intMNP(V3D(0, 0, 0)), m_peakShape(std::make_shared<NoShape>()) {
m_binCount(0), m_absorptionWeightedPathLength(0),
m_GoniometerMatrix(goniometer), m_InverseGoniometerMatrix(goniometer),
m_runNumber(0), m_monitorCount(0), m_row(-1), m_col(-1), m_peakNumber(0),
m_intHKL(V3D(0, 0, 0)), m_intMNP(V3D(0, 0, 0)),
m_peakShape(std::make_shared<NoShape>()) {
if (fabs(m_InverseGoniometerMatrix.Invert()) < 1e-8)
throw std::invalid_argument(
"BasePeak::ctor(): Goniometer matrix must non-singular.");
......@@ -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_L(other.m_L), m_intensity(other.m_intensity),
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_GoniometerMatrix(other.m_GoniometerMatrix),
m_InverseGoniometerMatrix(other.m_InverseGoniometerMatrix),
......@@ -80,8 +78,6 @@ BasePeak::BasePeak(const Geometry::IPeak &ipeak)
m_intensity(ipeak.getIntensity()),
m_sigmaIntensity(ipeak.getSigmaIntensity()),
m_binCount(ipeak.getBinCount()),
m_initialEnergy(ipeak.getInitialEnergy()),
m_finalEnergy(ipeak.getFinalEnergy()),
m_absorptionWeightedPathLength(ipeak.getAbsorptionWeightedPathLength()),
m_GoniometerMatrix(ipeak.getGoniometerMatrix()),
m_InverseGoniometerMatrix(ipeak.getGoniometerMatrix()),
......@@ -95,39 +91,6 @@ BasePeak::BasePeak(const Geometry::IPeak &ipeak)
"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. */
int BasePeak::getRunNumber() const { return m_runNumber; }
......@@ -148,18 +111,6 @@ void BasePeak::setMonitorCount(double 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 */
double BasePeak::getH() const { return m_H; }
......@@ -267,18 +218,6 @@ void BasePeak::setSigmaIntensity(double 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. */
Mantid::Kernel::Matrix<double> BasePeak::getGoniometerMatrix() const {
......@@ -438,8 +377,6 @@ BasePeak &BasePeak::operator=(const BasePeak &other) {
m_intensity = other.m_intensity;
m_sigmaIntensity = other.m_sigmaIntensity;
m_binCount = other.m_binCount;
m_initialEnergy = other.m_initialEnergy;
m_finalEnergy = other.m_finalEnergy;
m_GoniometerMatrix = other.m_GoniometerMatrix;
m_InverseGoniometerMatrix = other.m_InverseGoniometerMatrix;
m_runNumber = other.m_runNumber;
......
......@@ -30,7 +30,8 @@ namespace DataObjects {
//----------------------------------------------------------------------------------------------
/** 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)
......@@ -55,9 +56,7 @@ LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame)
LeanElasticPeak::LeanElasticPeak(
const Mantid::Kernel::V3D &QSampleFrame,
const Mantid::Kernel::Matrix<double> &goniometer)
: BasePeak(goniometer) {
this->setQSampleFrame(QSampleFrame);
}
: BasePeak(goniometer), m_Qsample(QSampleFrame) {}
//----------------------------------------------------------------------------------------------
/** Constructor that uses the Q position of the peak (in the sample frame)
......@@ -70,10 +69,7 @@ LeanElasticPeak::LeanElasticPeak(
*/
LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame,
double wavelength)
: BasePeak() {
this->setQSampleFrame(QSampleFrame);
this->setWavelength(wavelength);
}
: BasePeak(), m_Qsample(QSampleFrame), m_wavelength(wavelength) {}
//----------------------------------------------------------------------------------------------
/** Constructor that uses the Q position of the peak (in the lab frame).
......@@ -86,17 +82,15 @@ LeanElasticPeak::LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame,
LeanElasticPeak::LeanElasticPeak(
const Mantid::Kernel::V3D &QSampleFrame,
const Mantid::Kernel::Matrix<double> &goniometer, double wavelength)
: BasePeak(goniometer) {
this->setQSampleFrame(QSampleFrame);
this->setWavelength(wavelength);
}
: BasePeak(goniometer), m_Qsample(QSampleFrame), m_wavelength(wavelength) {}
/**
* @brief Copy constructor
* @param other : Source
*/
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
......@@ -104,7 +98,17 @@ LeanElasticPeak::LeanElasticPeak(const LeanElasticPeak &other)
* @param ipeak :: const reference to an IPeak object
*/
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
......@@ -145,6 +149,10 @@ Geometry::Instrument_const_sptr LeanElasticPeak::getInstrument() const {
"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
* peak,
......@@ -222,22 +230,49 @@ void LeanElasticPeak::setQLabFrame(const Mantid::Kernel::V3D &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) {
throw Exception::NotImplementedError(
"LeanElasticPeak has no sample information");
}
/** Set sample position
*
*/
/** Set sample position */
void LeanElasticPeak::setSamplePos(const Mantid::Kernel::V3D &) {
throw Exception::NotImplementedError(
"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 */
Mantid::Kernel::V3D LeanElasticPeak::getDetPos() const {
......@@ -275,6 +310,7 @@ LeanElasticPeak &LeanElasticPeak::operator=(const LeanElasticPeak &other) {
if (&other != this) {
BasePeak::operator=(other);
m_Qsample = other.m_Qsample;
m_wavelength = other.m_wavelength;
}
return *this;
}
......
......@@ -30,7 +30,8 @@ namespace DataObjects {
//----------------------------------------------------------------------------------------------
/** 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");
}
......@@ -159,7 +160,8 @@ Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering,
*/
Peak::Peak(const Peak &other)
: 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),
m_detIDs(other.m_detIDs), convention(other.convention) {}
......@@ -170,7 +172,9 @@ Peak::Peak(const Peak &other)
* @return
*/
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");
setInstrument(ipeak.getInstrument());
detid_t id = ipeak.getDetectorID();
......@@ -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
* cache
......@@ -308,6 +329,22 @@ Geometry::IDetector_const_sptr Peak::getDetector() const { return m_det; }
/** Return a shared ptr to the instrument for this peak. */
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
* peak,
......@@ -615,6 +652,18 @@ bool Peak::findDetector(const Mantid::Kernel::V3D &beam,
return found;
}
//----------------------------------------------------------------------------------------------
/** Get the final neutron energy in meV */
double Peak::getFinalEnergy() const { return m_finalEnergy; }
/** Get the initial (incident) neutron energy in meV */
double Peak::getInitialEnergy() const { return m_initialEnergy; }
/** Get the difference between the initial and final neutron energy in meV */
double Peak::getEnergyTransfer() const {
return getInitialEnergy() - getFinalEnergy();
}
/** Set sample position
*
* @ doubles x,y,z-> samplePos(x), samplePos(y), samplePos(z)
......@@ -637,6 +686,18 @@ void Peak::setSamplePos(const Mantid::Kernel::V3D &XYZ) {
this->samplePos[2] = XYZ[2];
}
/** Set the final energy
* @param m_finalEnergy :: final energy in meV */
void Peak::setFinalEnergy(double m_finalEnergy) {
this->m_finalEnergy = m_finalEnergy;
}
/** Set the initial energy
* @param m_initialEnergy :: initial energy in meV */
void Peak::setInitialEnergy(double m_initialEnergy) {
this->m_initialEnergy = m_initialEnergy;
}
// -------------------------------------------------------------------------------------
/** Return the detector position vector */
Mantid::Kernel::V3D Peak::getDetPos() const { return detPos; }
......@@ -664,6 +725,8 @@ Peak &Peak::operator=(const Peak &other) {
m_inst = other.m_inst;
m_det = other.m_det;
m_detectorID = other.m_detectorID;
m_initialEnergy = other.m_initialEnergy;
m_finalEnergy = other.m_finalEnergy;
sourcePos = other.sourcePos;
samplePos = other.samplePos;
detPos = other.detPos;
......
......@@ -33,8 +33,8 @@ public:
TS_ASSERT_EQUALS(p.getH(), 0.0)
TS_ASSERT_EQUALS(p.getK(), 0.0)
TS_ASSERT_EQUALS(p.getL(), 0.0)
TS_ASSERT_EQUALS(p.getInitialEnergy(), 0.0)
TS_ASSERT_EQUALS(p.getFinalEnergy(), 0.0)
TS_ASSERT(std::isinf(p.getInitialEnergy()))
TS_ASSERT(std::isinf(p.getFinalEnergy()))
TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(0, 0, 0))
TS_ASSERT_EQUALS(p.getQLabFrame(), V3D())
......@@ -49,7 +49,7 @@ public:
TS_ASSERT_THROWS(p.getDetPos(), const Exception::NotImplementedError &)
TS_ASSERT_THROWS(p.getSamplePos(), const Exception::NotImplementedError &)
TS_ASSERT(std::isnan(p.getTOF()))
TS_ASSERT(std::isnan(p.getScattering()))
TS_ASSERT_EQUALS(p.getScattering(), 0.)
TS_ASSERT(std::isnan(p.getAzimuthal()))
TS_ASSERT_THROWS(p.getL1(), const Exception::NotImplementedError &)
TS_ASSERT_THROWS(p.getL2(), const Exception::NotImplementedError &)
......@@ -200,14 +200,13 @@ public:
}
void test_get_energy() {
const double initialEnergy{100};
const double finalEnergy{110};
LeanElasticPeak p;
p.setWavelength(1.);
p.setInitialEnergy(initialEnergy);
p.setFinalEnergy(finalEnergy);
TS_ASSERT_DELTA(p.getInitialEnergy(), 81.8042024359, 1e-7);
TS_ASSERT_DELTA(p.getFinalEnergy(), 81.8042024359, 1e-7);
TS_ASSERT_EQUALS(p.getEnergyTransfer(), initialEnergy - finalEnergy);
TS_ASSERT_EQUALS(p.getEnergyTransfer(), 0.);
}
void test_Peak_to_LeanElasticPeak_through_IPeak() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment