Commit eac8e28c authored by Hahn, Steven's avatar Hahn, Steven
Browse files

Pass a const reference instead of a shared_ptr.

parent 170e4f0f
......@@ -11,7 +11,7 @@ namespace Algorithms {
*@param hostAlgorithm :: the pointer to SofQ algorithm hosting the base class.
*This algorithm expects to have EMode and EFixed properties attached to it.
*/
void SofQCommon::initCachedValues(API::MatrixWorkspace_const_sptr workspace,
void SofQCommon::initCachedValues(const API::MatrixWorkspace &workspace,
API::Algorithm *const hostAlgorithm) {
// Retrieve the emode & efixed properties
const std::string emode = hostAlgorithm->getProperty("EMode");
......@@ -29,8 +29,8 @@ void SofQCommon::initCachedValues(API::MatrixWorkspace_const_sptr workspace,
// If GetEi was run then it will have been stored in the workspace, if not
// the user will need to enter one
if (m_efixed == 0.0) {
if (workspace->run().hasProperty("Ei")) {
Kernel::Property *p = workspace->run().getProperty("Ei");
if (workspace.run().hasProperty("Ei")) {
Kernel::Property *p = workspace.run().getProperty("Ei");
Kernel::PropertyWithValue<double> *eiProp =
dynamic_cast<Kernel::PropertyWithValue<double> *>(p);
if (!eiProp)
......@@ -60,7 +60,7 @@ void SofQCommon::initCachedValues(API::MatrixWorkspace_const_sptr workspace,
* @param det A pointer to a detector object
* @return The value of efixed
*/
double SofQCommon::getEFixed(Geometry::IDetector_const_sptr det) const {
double SofQCommon::getEFixed(const Geometry::IDetector &det) const {
double efixed(0.0);
if (m_emode == 1) // Direct
{
......@@ -70,10 +70,10 @@ double SofQCommon::getEFixed(Geometry::IDetector_const_sptr det) const {
if (m_efixedGiven)
efixed = m_efixed; // user provided a value
else {
std::vector<double> param = det->getNumberParameter("EFixed");
std::vector<double> param = det.getNumberParameter("EFixed");
if (param.empty())
throw std::runtime_error(
"Cannot find EFixed parameter for component \"" + det->getName() +
"Cannot find EFixed parameter for component \"" + det.getName() +
"\". This is required in indirect mode. Please check the IDF "
"contains these values.");
efixed = param[0];
......
......@@ -106,7 +106,7 @@ void SofQWCentre::exec() {
std::vector<specnum_t> specNumberMapping;
std::vector<detid_t> detIDMapping;
m_EmodeProperties.initCachedValues(inputWorkspace, this);
m_EmodeProperties.initCachedValues(*inputWorkspace, this);
int emode = m_EmodeProperties.m_emode;
// Get a pointer to the instrument contained in the workspace
......@@ -145,7 +145,7 @@ void SofQWCentre::exec() {
if (spectrumDet->isMonitor())
continue;
const double efixed = m_EmodeProperties.getEFixed(spectrumDet);
const double efixed = m_EmodeProperties.getEFixed(*spectrumDet);
// For inelastic scattering the simple relationship q=4*pi*sinTheta/lambda
// does not hold. In order to
......
......@@ -87,7 +87,7 @@ void SofQWNormalisedPolygon::exec() {
new API::Progress(this, 0.0, 1.0, nreports));
// Compute input caches
m_EmodeProperties.initCachedValues(inputWS, this);
m_EmodeProperties.initCachedValues(*inputWS, this);
std::vector<double> par =
inputWS->getInstrument()->getNumberParameter("detector-neighbour-offset");
......@@ -129,7 +129,7 @@ void SofQWNormalisedPolygon::exec() {
const double phiLower = phi - phiHalfWidth;
const double phiUpper = phi + phiHalfWidth;
const double efixed = m_EmodeProperties.getEFixed(detector);
const double efixed = m_EmodeProperties.getEFixed(*detector);
const specnum_t specNo = inputWS->getSpectrum(i)->getSpectrumNo();
std::stringstream logStream;
for (size_t j = 0; j < nEnergyBins; ++j) {
......@@ -245,7 +245,7 @@ void SofQWNormalisedPolygon::initAngularCachesNonPSD(
det = workspace->getDetector(i);
// Check to see if there is an EFixed, if not skip it
try {
m_EmodeProperties.getEFixed(det);
m_EmodeProperties.getEFixed(*det);
} catch (std::runtime_error &) {
det.reset();
}
......@@ -262,8 +262,7 @@ void SofQWNormalisedPolygon::initAngularCachesNonPSD(
this->m_thetaWidths[i] = -1.0;
continue;
}
const double theta = workspace->detectorTwoTheta(det);
this->m_theta[i] = theta;
this->m_theta[i] = workspace->detectorTwoTheta(*det);
/**
* Determine width from shape geometry. A group is assumed to contain
......@@ -330,7 +329,7 @@ void SofQWNormalisedPolygon::initAngularCachesPSD(
double phiWidth = -DBL_MAX;
// Find theta and phi widths
double theta = workspace->detectorTwoTheta(detector);
double theta = workspace->detectorTwoTheta(*detector);
double phi = detector->getPhi();
specnum_t deltaPlus1 = inSpec + 1;
......@@ -344,7 +343,7 @@ void SofQWNormalisedPolygon::initAngularCachesPSD(
if (spec == deltaPlus1 || spec == deltaMinus1 || spec == deltaPlusT ||
spec == deltaMinusT) {
DetConstPtr detector_n = workspace->getDetector(spec - 1);
double theta_n = workspace->detectorTwoTheta(detector_n) / 2.0;
double theta_n = workspace->detectorTwoTheta(*detector_n) * 0.5;
double phi_n = detector_n->getPhi();
double dTheta = std::fabs(theta - theta_n);
......
......@@ -90,7 +90,7 @@ void SofQWPolygon::exec() {
double halfWidth(0.5 * m_thetaWidth);
const double thetaLower = theta - halfWidth;
const double thetaUpper = theta + halfWidth;
const double efixed = m_EmodeProperties.getEFixed(det);
const double efixed = m_EmodeProperties.getEFixed(*det);
for (size_t j = 0; j < nenergyBins; ++j) {
m_progress->report("Computing polygon intersections");
......@@ -180,9 +180,9 @@ double SofQWPolygon::calculateIndirectQ(const double efixed,
* @param workspace :: Workspace pointer
*/
void SofQWPolygon::initCachedValues(API::MatrixWorkspace_const_sptr workspace) {
m_EmodeProperties.initCachedValues(workspace, this);
m_EmodeProperties.initCachedValues(*workspace, this);
// Index theta cache
initThetaCache(workspace);
initThetaCache(*workspace);
}
/**
......@@ -193,8 +193,8 @@ void SofQWPolygon::initCachedValues(API::MatrixWorkspace_const_sptr workspace) {
* values are required very frequently so the total time is more than
* offset by this precaching step
*/
void SofQWPolygon::initThetaCache(API::MatrixWorkspace_const_sptr workspace) {
const size_t nhist = workspace->getNumberHistograms();
void SofQWPolygon::initThetaCache(const API::MatrixWorkspace &workspace) {
const size_t nhist = workspace.getNumberHistograms();
m_thetaPts = std::vector<double>(nhist);
size_t ndets(0);
double minTheta(DBL_MAX), maxTheta(-DBL_MAX);
......@@ -205,10 +205,10 @@ void SofQWPolygon::initThetaCache(API::MatrixWorkspace_const_sptr workspace) {
m_progress->report("Calculating detector angles");
IDetector_const_sptr det;
try {
det = workspace->getDetector(i);
det = workspace.getDetector(i);
// Check to see if there is an EFixed, if not skip it
try {
m_EmodeProperties.getEFixed(det);
m_EmodeProperties.getEFixed(*det);
} catch (std::runtime_error &) {
det.reset();
}
......@@ -224,13 +224,10 @@ void SofQWPolygon::initThetaCache(API::MatrixWorkspace_const_sptr workspace) {
m_thetaPts[i] = -1.0; // Indicates a detector to skip
} else {
++ndets;
const double theta = workspace->detectorTwoTheta(det);
const double theta = workspace.detectorTwoTheta(*det);
m_thetaPts[i] = theta;
if (theta < minTheta) {
minTheta = theta;
} else if (theta > maxTheta) {
maxTheta = theta;
}
minTheta = std::min(minTheta, theta);
maxTheta = std::max(maxTheta, theta);
}
}
......
......@@ -151,8 +151,8 @@ void TOFSANSResolution::exec() {
// Multiplicative factor to go from lambda to Q
// Don't get fooled by the function name...
const double theta = reducedWS->detectorTwoTheta(det);
const double factor = 4.0 * M_PI * sin(theta / 2.0);
const double theta = reducedWS->detectorTwoTheta(*det);
const double factor = 4.0 * M_PI * sin(0.5 * theta);
const MantidVec &XIn = reducedWS->readX(i);
const MantidVec &YIn = reducedWS->readY(i);
......
......@@ -162,8 +162,8 @@ void TOFSANSResolutionByPixel::exec() {
// Multiplicative factor to go from lambda to Q
// Don't get fooled by the function name...
const double theta = inWS->detectorTwoTheta(det);
double sinTheta = sin(theta / 2.0);
const double theta = inWS->detectorTwoTheta(*det);
double sinTheta = sin(0.5 * theta);
double factor = 4.0 * M_PI * sinTheta;
const MantidVec &xIn = inWS->readX(i);
......
......@@ -386,8 +386,7 @@ void VesuvioL1ThetaResolution::calculateDetector(
<< "detHeight=" << detHeight << std::endl;
// Scattering angle in rad
const double theta =
m_instWorkspace->detectorTwoTheta(IDetector_const_sptr(detector));
const double theta = m_instWorkspace->detectorTwoTheta(*detector);
if (theta == 0.0)
return;
......
......@@ -30,9 +30,9 @@ private:
const Mantid::MantidVec &xData = ws->readX(0);
auto detector = ws->getDetector(0);
double twotheta = ws->detectorTwoTheta(detector);
double lam = (xData[bin_index] + xData[bin_index + 1]) / 2;
double weight = std::sin(twotheta / 2);
double twotheta = ws->detectorTwoTheta(*detector);
double lam = 0.5 * (xData[bin_index] + xData[bin_index + 1]);
double weight = std::sin(0.5 * twotheta);
weight = weight * weight;
weight = weight / (lam * lam * lam * lam);
return weight;
......
......@@ -78,7 +78,7 @@ DetectorParams ConvertToYSpace::getDetectorParameters(
detpar.l1 = sample->getDistance(*source);
detpar.l2 = det->getDistance(*sample);
detpar.pos = det->getPos();
detpar.theta = ws->detectorTwoTheta(det);
detpar.theta = ws->detectorTwoTheta(*det);
detpar.t0 = ConvertToYSpace::getComponentParameter(det, pmap, "t0") *
1e-6; // Convert to seconds
detpar.efixed = ConvertToYSpace::getComponentParameter(det, pmap, "efixed");
......
......@@ -182,7 +182,7 @@ void InelasticDiffRotDiscreteCircle::setWorkspace(
try {
double efixed = workspace->getEFixed(det);
double usignTheta = workspace->detectorTwoTheta(det) / 2.0;
double usignTheta = 0.5 * workspace->detectorTwoTheta(*det);
double q = Mantid::Kernel::UnitConversion::run(usignTheta, efixed);
......
......@@ -292,7 +292,7 @@ void InelasticDiffSphere::setWorkspace(
try {
double efixed = workspace->getEFixed(det);
double usignTheta = workspace->detectorTwoTheta(det) / 2.0;
double usignTheta = 0.5 * workspace->detectorTwoTheta(*det);
double q = Mantid::Kernel::UnitConversion::run(usignTheta, efixed);
......
......@@ -227,7 +227,7 @@ void AppendGeometryToSNSNexus::exec() {
pixel_id.push_back(det->getID());
distance.push_back(det->getDistance(*sample));
azimuthal_angle.push_back(det->getPhi());
polar_angle.push_back(ws->detectorTwoTheta(det));
polar_angle.push_back(ws->detectorTwoTheta(*det));
}
// Write Pixel ID to file
......
......@@ -192,7 +192,7 @@ void FindDetectorsPar::setOutputTable() {
}
// Constant for converting Radians to Degrees
const double rad2deg = 180.0 / M_PI;
constexpr double rad2deg = 180.0 / M_PI;
/** method calculates an angle closest to the initial one taken on a ring
* e.g. given inital angle 179 deg and another one -179 closest one to 179 is
......
......@@ -421,7 +421,7 @@ void SaveAscii2::populateQMetaData() {
const auto detector = m_ws->getDetector(workspaceIndex);
double twoTheta(0.0), efixed(0.0);
if (!detector->isMonitor()) {
twoTheta = m_ws->detectorTwoTheta(detector) / 2.0;
twoTheta = 0.5 * m_ws->detectorTwoTheta(*detector);
try {
efixed = m_ws->getEFixed(detector);
} catch (std::runtime_error) {
......@@ -463,8 +463,9 @@ void SaveAscii2::populateAngleMetaData() {
const auto specNo = m_ws->getSpectrum(i)->getSpectrumNo();
const auto workspaceIndex = m_specToIndexMap[specNo];
auto det = m_ws->getDetector(workspaceIndex);
const auto two_theta = m_ws->detectorTwoTheta(det);
const auto angleInDeg = two_theta * (180 / M_PI);
const auto two_theta = m_ws->detectorTwoTheta(*det);
constexpr double rad2deg = 180. / M_PI;
const auto angleInDeg = two_theta * rad2deg;
const auto angleInDegStr = boost::lexical_cast<std::string>(angleInDeg);
angles.push_back(angleInDegStr);
}
......
......@@ -328,5 +328,6 @@ void SaveFocusedXYE::getFocusedPos(Mantid::API::MatrixWorkspace_const_sptr wksp,
l1 = source->getDistance(*sample);
Geometry::IDetector_const_sptr det = wksp->getDetector(spectrum);
l2 = det->getDistance(*sample);
tth = wksp->detectorTwoTheta(det) * 180. / M_PI;
constexpr double rad2deg = 180. / M_PI;
tth = wksp->detectorTwoTheta(*det) * rad2deg;
}
......@@ -122,10 +122,10 @@ void getFocusedPos(MatrixWorkspace_const_sptr wksp, const int spectrum,
throw std::runtime_error(errss.str());
}
l2 = det->getDistance(*sample);
tth = wksp->detectorTwoTheta(det);
tth = wksp->detectorTwoTheta(*det);
difc = ((2.0 * PhysicalConstants::NeutronMass * sin(tth / 2.0) * (l1 + l2)) /
(PhysicalConstants::h * 1e4));
difc = ((2.0 * PhysicalConstants::NeutronMass * sin(tth * 0.5) * (l1 + l2)) /
(PhysicalConstants::h * 1.e4));
return;
}
......
......@@ -71,8 +71,8 @@ public:
TS_ASSERT_EQUALS(phi, 0);
TS_ASSERT_DELTA(dx, r * step * Geometry::deg2rad, 0.01);
TS_ASSERT_EQUALS(dy, 0.01);
tth = ws->detectorTwoTheta(ws->getInstrument()->getDetector(detID)) *
Geometry::rad2deg;
auto det = ws->getInstrument()->getDetector(detID);
tth = ws->detectorTwoTheta(*det) * Geometry::rad2deg;
TS_ASSERT_LESS_THAN(tth, static_cast<double>(i + 1) * step);
TS_ASSERT_LESS_THAN(static_cast<double>(i) * step, tth);
}
......
......@@ -235,7 +235,7 @@ DetectorAngularCache initAngularCaches(const MatrixWorkspace *const workspace) {
continue;
}
// We have to convert theta from radians to degrees
const double theta = workspace->detectorSignedTwoTheta(det) * 180.0 / M_PI;
const double theta = workspace->detectorSignedTwoTheta(*det) * rad2deg;
thetas[i] = theta;
/**
* Determine width from shape geometry. A group is assumed to contain
......
......@@ -798,7 +798,7 @@ Quat::getEulerAngles(const std::string &convention = "XYZ") const {
V3D axis3(0, 0, 0);
axis3[last] = 1.0;
const double rad2deg = 180.0 / M_PI;
constexpr double rad2deg = 180.0 / M_PI;
angles[2] = atan2(s3, c3) * rad2deg;
......
......@@ -345,7 +345,7 @@ double &V3D::operator[](const size_t Index) {
* @param phi :: Returns the phi (azimuthal) angle in degrees
*/
void V3D::getSpherical(double &R, double &theta, double &phi) const {
const double rad2deg = 180.0 / M_PI;
constexpr double rad2deg = 180.0 / M_PI;
R = norm();
theta = 0.0;
if (R != 0.0)
......
Supports Markdown
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