diff --git a/Framework/DataObjects/src/MDHistoWorkspace.cpp b/Framework/DataObjects/src/MDHistoWorkspace.cpp index 342dd4130f4258f6b823c5f2d063024bd3a19315..b252a498aad33642742e10489117fc463dccccf0 100644 --- a/Framework/DataObjects/src/MDHistoWorkspace.cpp +++ b/Framework/DataObjects/src/MDHistoWorkspace.cpp @@ -43,13 +43,13 @@ MDHistoWorkspace::MDHistoWorkspace( m_coordSystem(None), m_displayNormalization(displayNormalization) { std::vector<Mantid::Geometry::MDHistoDimension_sptr> dimensions; if (dimX) - dimensions.push_back(dimX); + dimensions.push_back(std::move(dimX)); if (dimY) - dimensions.push_back(dimY); + dimensions.push_back(std::move(dimY)); if (dimZ) - dimensions.push_back(dimZ); + dimensions.push_back(std::move(dimZ)); if (dimT) - dimensions.push_back(dimT); + dimensions.push_back(std::move(dimT)); this->init(dimensions); } @@ -89,7 +89,10 @@ MDHistoWorkspace::MDHistoWorkspace( * @param other :: MDHistoWorkspace to copy from. */ MDHistoWorkspace::MDHistoWorkspace(const MDHistoWorkspace &other) - : IMDHistoWorkspace(other) { + : IMDHistoWorkspace(other), + m_nEventsContributed(other.m_nEventsContributed), + m_coordSystem(other.m_coordSystem), + m_displayNormalization(other.m_displayNormalization) { // Dimensions are copied by the copy constructor of MDGeometry this->cacheValues(); // Allocate the linear arrays @@ -97,16 +100,11 @@ MDHistoWorkspace::MDHistoWorkspace(const MDHistoWorkspace &other) m_errorsSquared = new signal_t[m_length]; m_numEvents = new signal_t[m_length]; m_masks = new bool[m_length]; - m_nEventsContributed = other.m_nEventsContributed; - this->setCoordinateSystem(other.getSpecialCoordinateSystem()); - m_displayNormalization = other.displayNormalization(); // Now copy all the data - for (size_t i = 0; i < m_length; ++i) { - m_signals[i] = other.m_signals[i]; - m_errorsSquared[i] = other.m_errorsSquared[i]; - m_numEvents[i] = other.m_numEvents[i]; - m_masks[i] = other.m_masks[i]; - } + std::copy_n(other.m_signals, m_length, m_signals); + std::copy_n(other.m_errorsSquared, m_length, m_errorsSquared); + std::copy_n(other.m_numEvents, m_length, m_numEvents); + std::copy_n(other.m_masks, m_length, m_masks); } //---------------------------------------------------------------------------------------------- @@ -258,13 +256,11 @@ void MDHistoWorkspace::initVertexesArray() { */ void MDHistoWorkspace::setTo(signal_t signal, signal_t errorSquared, signal_t numEvents) { - for (size_t i = 0; i < m_length; i++) { - m_signals[i] = signal; - m_errorsSquared[i] = errorSquared; - m_numEvents[i] = numEvents; - m_masks[i] = false; // Not masked by default; - m_nEventsContributed += uint64_t(numEvents); - } + std::fill_n(m_signals, m_length, signal); + std::fill_n(m_errorsSquared, m_length, errorSquared); + std::fill_n(m_numEvents, m_length, numEvents); + std::fill_n(m_masks, m_length, false); + m_nEventsContributed = static_cast<uint64_t>(numEvents) * m_length; } //---------------------------------------------------------------------------------------------- diff --git a/Framework/Kernel/inc/MantidKernel/PhysicalConstants.h b/Framework/Kernel/inc/MantidKernel/PhysicalConstants.h index c384229be657f2d1b4f26a801f8f853f5391f619..3a6416de3ebaaeccbb06a18af732a727de229e78 100644 --- a/Framework/Kernel/inc/MantidKernel/PhysicalConstants.h +++ b/Framework/Kernel/inc/MantidKernel/PhysicalConstants.h @@ -38,66 +38,66 @@ namespace Mantid { namespace PhysicalConstants { /** Avagodro constant in mol<SUP>-1</SUP>. Taken from <http://physics.nist.gov/cuu/Constants> on 2010-12-28. */ -static const double N_A = 6.02214179e23; +static constexpr double N_A = 6.02214179e23; /** Planck constant in J*s. Taken from <http://physics.nist.gov/cuu/Constants> on 2007-10-31 and confirmed again on 2010-12-28. */ -static const double h = 6.62606896e-34; +static constexpr double h = 6.62606896e-34; /** Planck constant in J*s, divided by 2 PI. */ -static const double h_bar = h / (2 * M_PI); +static constexpr double h_bar = h / (2 * M_PI); /** Standard acceleration due to gravity. Precise value in ms<SUP>-2</SUP>. */ -static const double g = 9.80665; +static constexpr double g = 9.80665; /** Mass of the neutron in kg. Taken from * <http://physics.nist.gov/cuu/Constants> on 30/10/2007. */ -static const double NeutronMass = 1.674927211e-27; +static constexpr double NeutronMass = 1.674927211e-27; /** Mass of the neutron in AMU. Taken from * <http://physics.nist.gov/cuu/Constants> on 02/01/2013. */ -static const double NeutronMassAMU = 1.008664916; +static constexpr double NeutronMassAMU = 1.008664916; /** AMU in kg. Taken from <http://physics.nist.gov/cuu/Constants> on 10/09/2014. */ -static const double AtomicMassUnit = 1.660538921e-27; +static constexpr double AtomicMassUnit = 1.660538921e-27; /** 1 meV in Joules. Taken from <http://physics.nist.gov/cuu/Constants> on * 28/03/2008. */ -static const double meV = 1.602176487e-22; +static constexpr double meV = 1.602176487e-22; /** 1 meV in wavenumber (cm<SUP>-1</SUP>). Taken from * <http://physics.nist.gov/cuu/Constants> on 02/04/2008. */ -static const double meVtoWavenumber = 8.06554465; +static constexpr double meVtoWavenumber = 8.06554465; /** 1 meV in Kelvin. Taken from <http://physics.nist.gov/cuu/Constants> on * 09/09/2011. */ -static const double meVtoKelvin = 11.604519; +static constexpr double meVtoKelvin = 11.604519; /** Transformation coefficient to transform neutron energy into neutron * wavevector: K-neutron[m^-10] = sqrt(E_neutron[meV]/E_transtormation[mEv]);*/ -static const double E_mev_toNeutronWavenumberSq = +static constexpr double E_mev_toNeutronWavenumberSq = 1.0e20 * h_bar * h_bar / (2 * NeutronMass * meV); //[meV*Angstrom^2] /** Muon lifetime. Taken from Particle Data Group on 15/1/2016 * <http://pdg.lbl.gov/2015/tables/rpp2015-sum-leptons.pdf>. */ -static const double MuonLifetime = 2.1969811e-6; +static constexpr double MuonLifetime = 2.1969811e-6; /** Standard atmospheric pressure in kPa. * Taken from * <http://physics.nist.gov/cgi-bin/cuu/Value?stdatm|search_for=adopted_in!> on * 01/12/2010 **/ -static const double StandardAtmosphere = 101.325; +static constexpr double StandardAtmosphere = 101.325; /** Boltzmann Constant in meV/K * Taken from <http://physics.nist.gov/cuu/Constants> on 10/07/2012 */ -static const double BoltzmannConstant = 8.6173324e-02; +static constexpr double BoltzmannConstant = 8.6173324e-02; /** Muon gyromagnetic ratio in MHz/G * Taken from CalMuonDetectorPhases and DynamicKuboToyabe on 02/02/2016 */ -static const double MuonGyromagneticRatio = 0.01355342; +static constexpr double MuonGyromagneticRatio = 0.01355342; } // namespace PhysicalConstants } // namespace Mantid diff --git a/Framework/Kernel/src/Matrix.cpp b/Framework/Kernel/src/Matrix.cpp index d44a14762b24da8e66c53b2e65ad135e30766723..4d84050f8ac7a613b3e0c37beeda59477b57d82c 100644 --- a/Framework/Kernel/src/Matrix.cpp +++ b/Framework/Kernel/src/Matrix.cpp @@ -327,14 +327,12 @@ std::vector<T> Matrix<T>::operator*(const std::vector<T> &Vec) const @return Matrix(This * Vec) */ { - std::vector<T> Out; if (ny > Vec.size()) throw Kernel::Exception::MisMatch<size_t>(ny, Vec.size(), "Matrix::operator*(Vec)"); - Out.resize(nx); + std::vector<T> Out(nx); for (size_t i = 0; i < nx; i++) { - Out[i] = 0; for (size_t j = 0; j < ny; j++) { Out[i] += V[i][j] * Vec[j]; } diff --git a/Framework/Kernel/src/V3D.cpp b/Framework/Kernel/src/V3D.cpp index 2789308460c52c156e486fb1951878d4e2a196d8..c381a86c8ffc48a8854b22d07c9466b0bbc07675 100644 --- a/Framework/Kernel/src/V3D.cpp +++ b/Framework/Kernel/src/V3D.cpp @@ -28,7 +28,7 @@ V3D::V3D(const double xx, const double yy, const double zz) along +X and rotates counter-clockwise in the XY plane */ void V3D::spherical(const double &R, const double &theta, const double &phi) { - const double deg2rad = M_PI / 180.0; + constexpr double deg2rad = M_PI / 180.0; z = R * cos(theta * deg2rad); const double ct = sin(theta * deg2rad); x = R * ct * cos(phi * deg2rad); @@ -379,9 +379,9 @@ double V3D::normalize() { /** Round each component to the nearest integer */ void V3D::round() { - x = double(long(x + (x < 0 ? -0.5 : +0.5))); - y = double(long(y + (y < 0 ? -0.5 : +0.5))); - z = double(long(z + (z < 0 ? -0.5 : +0.5))); + x = std::round(x); + y = std::round(y); + z = std::round(z); } /** diff --git a/Framework/MDAlgorithms/src/MDNormDirectSC.cpp b/Framework/MDAlgorithms/src/MDNormDirectSC.cpp index 3b0b81789cc40afe95f83eccd1392f8eb10ab45b..fc17760af2e8800356752386497a58749c2db972 100644 --- a/Framework/MDAlgorithms/src/MDNormDirectSC.cpp +++ b/Framework/MDAlgorithms/src/MDNormDirectSC.cpp @@ -317,10 +317,8 @@ Kernel::Matrix<coord_t> MDNormDirectSC::findIntergratedDimensions( if (affineMat[row][0] == 1.) { m_hIntegrated = false; m_hIdx = row; - if (m_hmin < dimMin) - m_hmin = dimMin; - if (m_hmax > dimMax) - m_hmax = dimMax; + m_hmin = std::max(m_hmin, dimMin); + m_hmax = std::min(m_hmax, dimMax); if (m_hmin > dimMax || m_hmax < dimMin) { skipNormalization = true; } @@ -328,10 +326,8 @@ Kernel::Matrix<coord_t> MDNormDirectSC::findIntergratedDimensions( if (affineMat[row][1] == 1.) { m_kIntegrated = false; m_kIdx = row; - if (m_kmin < dimMin) - m_kmin = dimMin; - if (m_kmax > dimMax) - m_kmax = dimMax; + m_kmin = std::max(m_kmin, dimMin); + m_kmax = std::min(m_kmax, dimMax); if (m_kmin > dimMax || m_kmax < dimMin) { skipNormalization = true; } @@ -339,10 +335,8 @@ Kernel::Matrix<coord_t> MDNormDirectSC::findIntergratedDimensions( if (affineMat[row][2] == 1.) { m_lIntegrated = false; m_lIdx = row; - if (m_lmin < dimMin) - m_lmin = dimMin; - if (m_lmax > dimMax) - m_lmax = dimMax; + m_lmin = std::max(m_lmin, dimMin); + m_lmax = std::min(m_lmax, dimMax); if (m_lmin > dimMax || m_lmax < dimMin) { skipNormalization = true; } @@ -351,10 +345,8 @@ Kernel::Matrix<coord_t> MDNormDirectSC::findIntergratedDimensions( if (affineMat[row][3] == 1.) { m_dEIntegrated = false; m_eIdx = row; - if (m_dEmin < dimMin) - m_dEmin = dimMin; - if (m_dEmax > dimMax) - m_dEmax = dimMax; + m_dEmin = std::max(m_dEmin, dimMin); + m_dEmax = std::min(m_dEmax, dimMax); if (m_dEmin > dimMax || m_dEmax < dimMin) { skipNormalization = true; } @@ -377,9 +369,10 @@ Kernel::Matrix<coord_t> MDNormDirectSC::findIntergratedDimensions( * Stores the X values from each H,K,L dimension as member variables */ void MDNormDirectSC::cacheDimensionXValues() { - const double energyToK = 8.0 * M_PI * M_PI * PhysicalConstants::NeutronMass * - PhysicalConstants::meV * 1e-20 / - (PhysicalConstants::h * PhysicalConstants::h); + constexpr double energyToK = 8.0 * M_PI * M_PI * + PhysicalConstants::NeutronMass * + PhysicalConstants::meV * 1e-20 / + (PhysicalConstants::h * PhysicalConstants::h); if (!m_hIntegrated) { auto &hDim = *m_normWS->getDimension(m_hIdx); m_hX.resize(hDim.getNBins()); @@ -407,9 +400,8 @@ void MDNormDirectSC::cacheDimensionXValues() { m_eX.resize(eDim.getNBins()); for (size_t i = 0; i < m_eX.size(); ++i) { double temp = m_Ei - eDim.getX(i); - if (temp <= 0) - temp = 0.; - m_eX[i] = std::sqrt(energyToK * (temp)); + temp = std::max(temp, 0.); + m_eX[i] = std::sqrt(energyToK * temp); } } } @@ -423,9 +415,10 @@ void MDNormDirectSC::cacheDimensionXValues() { void MDNormDirectSC::calculateNormalization( const std::vector<coord_t> &otherValues, const Kernel::Matrix<coord_t> &affineTrans) { - const double energyToK = 8.0 * M_PI * M_PI * PhysicalConstants::NeutronMass * - PhysicalConstants::meV * 1e-20 / - (PhysicalConstants::h * PhysicalConstants::h); + constexpr double energyToK = 8.0 * M_PI * M_PI * + PhysicalConstants::NeutronMass * + PhysicalConstants::meV * 1e-20 / + (PhysicalConstants::h * PhysicalConstants::h); const auto &exptInfoZero = *(m_inputWS->getExperimentInfo(0)); typedef Kernel::PropertyWithValue<std::vector<double>> VectorDoubleProperty; auto *rubwLog = @@ -648,8 +641,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { if ((ki >= m_kmin) && (ki <= m_kmax) && (li >= m_lmin) && (li <= m_lmax)) { double momi = fmom * (hi - hStart) + m_kfmin; - Mantid::Kernel::VMD v(hi, ki, li, momi); - intersections.push_back(v); + intersections.emplace_back(hi, ki, li, momi); } } } @@ -662,8 +654,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { double lhmin = fl * (m_hmin - hStart) + lStart; if ((khmin >= m_kmin) && (khmin <= m_kmax) && (lhmin >= m_lmin) && (lhmin <= m_lmax)) { - Mantid::Kernel::VMD v(m_hmin, khmin, lhmin, momhMin); - intersections.push_back(v); + intersections.emplace_back(m_hmin, khmin, lhmin, momhMin); } } double momhMax = fmom * (m_hmax - hStart) + m_kfmin; @@ -673,8 +664,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { double lhmax = fl * (m_hmax - hStart) + lStart; if ((khmax >= m_kmin) && (khmax <= m_kmax) && (lhmax >= m_lmin) && (lhmax <= m_lmax)) { - Mantid::Kernel::VMD v(m_hmax, khmax, lhmax, momhMax); - intersections.push_back(v); + intersections.emplace_back(m_hmax, khmax, lhmax, momhMax); } } } @@ -697,8 +687,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { if ((hi >= m_hmin) && (hi <= m_hmax) && (li >= m_lmin) && (li <= m_lmax)) { double momi = fmom * (ki - kStart) + m_kfmin; - Mantid::Kernel::VMD v(hi, ki, li, momi); - intersections.push_back(v); + intersections.emplace_back(hi, ki, li, momi); } } } @@ -710,8 +699,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { double lkmin = fl * (m_kmin - kStart) + lStart; if ((hkmin >= m_hmin) && (hkmin <= m_hmax) && (lkmin >= m_lmin) && (lkmin <= m_lmax)) { - Mantid::Kernel::VMD v(hkmin, m_kmin, lkmin, momkMin); - intersections.push_back(v); + intersections.emplace_back(hkmin, m_kmin, lkmin, momkMin); } } double momkMax = fmom * (m_kmax - kStart) + m_kfmin; @@ -721,8 +709,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { double lkmax = fl * (m_kmax - kStart) + lStart; if ((hkmax >= m_hmin) && (hkmax <= m_hmax) && (lkmax >= m_lmin) && (lkmax <= m_lmax)) { - Mantid::Kernel::VMD v(hkmax, m_kmax, lkmax, momkMax); - intersections.push_back(v); + intersections.emplace_back(hkmax, m_kmax, lkmax, momkMax); } } } @@ -742,8 +729,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { if ((hi >= m_hmin) && (hi <= m_hmax) && (ki >= m_kmin) && (ki <= m_kmax)) { double momi = fmom * (li - lStart) + m_kfmin; - Mantid::Kernel::VMD v(hi, ki, li, momi); - intersections.push_back(v); + intersections.emplace_back(hi, ki, li, momi); } } } @@ -755,8 +741,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { double klmin = fk * (m_lmin - lStart) + kStart; if ((hlmin >= m_hmin) && (hlmin <= m_hmax) && (klmin >= m_kmin) && (klmin <= m_kmax)) { - Mantid::Kernel::VMD v(hlmin, klmin, m_lmin, momlMin); - intersections.push_back(v); + intersections.emplace_back(hlmin, klmin, m_lmin, momlMin); } } double momlMax = fmom * (m_lmax - lStart) + m_kfmin; @@ -766,8 +751,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { double klmax = fk * (m_lmax - lStart) + kStart; if ((hlmax >= m_hmin) && (hlmax <= m_hmax) && (klmax >= m_kmin) && (klmax <= m_kmax)) { - Mantid::Kernel::VMD v(hlmax, klmax, m_lmax, momlMax); - intersections.push_back(v); + intersections.emplace_back(hlmax, klmax, m_lmax, momlMax); } } } @@ -782,8 +766,7 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { double l = qin.Z() - qout.Z() * kfi; if ((h >= m_hmin) && (h <= m_hmax) && (k >= m_kmin) && (k <= m_kmax) && (l >= m_lmin) && (l <= m_lmax)) { - Mantid::Kernel::VMD v(h, k, l, kfi); - intersections.push_back(v); + intersections.emplace_back(h, k, l, kfi); } } } @@ -792,21 +775,15 @@ MDNormDirectSC::calculateIntersections(const double theta, const double phi) { // endpoints if ((hStart >= m_hmin) && (hStart <= m_hmax) && (kStart >= m_kmin) && (kStart <= m_kmax) && (lStart >= m_lmin) && (lStart <= m_lmax)) { - Mantid::Kernel::VMD v(hStart, kStart, lStart, m_kfmin); - intersections.push_back(v); + intersections.emplace_back(hStart, kStart, lStart, m_kfmin); } if ((hEnd >= m_hmin) && (hEnd <= m_hmax) && (kEnd >= m_kmin) && (kEnd <= m_kmax) && (lEnd >= m_lmin) && (lEnd <= m_lmax)) { - Mantid::Kernel::VMD v(hEnd, kEnd, lEnd, m_kfmax); - intersections.push_back(v); + intersections.emplace_back(hEnd, kEnd, lEnd, m_kfmax); } // sort intersections by final momentum - typedef std::vector<Mantid::Kernel::VMD>::iterator IterType; - std::stable_sort<IterType, bool (*)(const Mantid::Kernel::VMD &, - const Mantid::Kernel::VMD &)>( - intersections.begin(), intersections.end(), compareMomentum); - + std::stable_sort(intersections.begin(), intersections.end(), compareMomentum); return intersections; }