Skip to content
Snippets Groups Projects
Commit 19721e14 authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Re #8074. Refactored SetInstrumentGeometry and added a CompressEvents.

parent b9b0b830
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,7 @@ namespace Mantid ...@@ -98,7 +98,7 @@ namespace Mantid
DataObjects::OffsetsWorkspace_sptr m_offsetsWS; DataObjects::OffsetsWorkspace_sptr m_offsetsWS;
API::MatrixWorkspace_sptr m_maskWS; API::MatrixWorkspace_sptr m_maskWS;
DataObjects::GroupingWorkspace_sptr m_groupWS; DataObjects::GroupingWorkspace_sptr m_groupWS;
double l1; double m_l1;
std::vector<int32_t> specids; std::vector<int32_t> specids;
std::vector<double> l2s; std::vector<double> l2s;
std::vector<double> tths; std::vector<double> tths;
......
...@@ -145,6 +145,41 @@ namespace WorkflowAlgorithms ...@@ -145,6 +145,41 @@ namespace WorkflowAlgorithms
} }
template <typename NumT>
void splitVectors(const std::vector<NumT> &orig, const size_t numVal,
const std::string &label,
std::vector<NumT> &left, std::vector<NumT> &right)
{
// clear the outputs
left.clear();
right.clear();
// check that there is work to do
if (orig.empty())
return;
// do the spliting
if (orig.size() == numVal)
{
left.assign(orig.begin(), orig.end());
right.assign(orig.begin(), orig.end());
}
else if (orig.size() == 2*numVal)
{
left.assign(orig.begin(), orig.begin() + numVal);
right.assign(orig.begin() + numVal, orig.begin());
}
else
{
std::stringstream msg;
msg << "Input number of " << label << " ids is not equal to "
<< "the number of histograms or empty ("
<< orig.size() << " != 0 or " << numVal
<< " or " << (2*numVal) << ")";
throw std::runtime_error(msg.str());
}
}
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Executes the algorithm /** Executes the algorithm
* @throw Exception::FileError If the grouping file cannot be opened or read successfully * @throw Exception::FileError If the grouping file cannot be opened or read successfully
...@@ -161,7 +196,7 @@ namespace WorkflowAlgorithms ...@@ -161,7 +196,7 @@ namespace WorkflowAlgorithms
m_offsetsWS = getProperty("OffsetsWorkspace"); m_offsetsWS = getProperty("OffsetsWorkspace");
m_maskWS = getProperty("MaskWorkspace"); m_maskWS = getProperty("MaskWorkspace");
m_groupWS = getProperty("GroupingWorkspace"); m_groupWS = getProperty("GroupingWorkspace");
l1 = getProperty("PrimaryFlightPath"); m_l1 = getProperty("PrimaryFlightPath");
specids = getProperty("SpectrumIDs"); specids = getProperty("SpectrumIDs");
l2s = getProperty("L2"); l2s = getProperty("L2");
tths = getProperty("Polar"); tths = getProperty("Polar");
...@@ -522,91 +557,31 @@ namespace WorkflowAlgorithms ...@@ -522,91 +557,31 @@ namespace WorkflowAlgorithms
m_lowResW = rebin(m_lowResW); m_lowResW = rebin(m_lowResW);
} }
if (l1 > 0 || !tths.empty() || !l2s.empty() || !phis.empty()) // edit the instrument geometry
if (m_l1 > 0 || !tths.empty() || !l2s.empty() || !phis.empty())
{ {
size_t numreg = m_outputW->getNumberHistograms(); size_t numreg = m_outputW->getNumberHistograms();
// Check size // set up the vectors for doing everything
if (tths.size() < numreg) std::vector<int32_t> specidsReg;
throw std::runtime_error("Input number of 2thetas is smaller than number of histogram."); std::vector<int32_t> specidsLow;
if (l2s.size() < numreg) splitVectors(specids, numreg, "specids", specidsReg, specidsLow);
throw std::runtime_error("Input number of L2s is smaller than number of histogram."); std::vector<double> tthsReg;
if (phis.size() < numreg) std::vector<double> tthsLow;
throw std::runtime_error("Input number of azimuthals is smaller than number of histogram."); splitVectors(tths, numreg, "two-theta", tthsReg, tthsLow);
std::vector<double> l2sReg;
std::vector<int32_t> vec_specid_reg; std::vector<double> l2sLow;
if (specids.size() >= numreg) splitVectors(l2s, numreg, "L2", l2sReg, l2sLow);
{ std::vector<double> phisReg;
vec_specid_reg.resize(numreg, 0); std::vector<double> phisLow;
std::copy(specids.begin(), (specids.begin()+numreg), vec_specid_reg.begin()); splitVectors(phis, numreg, "phi", phisReg, phisLow);
}
std::vector<double> vec_polar_reg(numreg, 0.);
std::copy(tths.begin(), (tths.begin()+numreg), vec_polar_reg.begin());
std::vector<double> vec_l2_reg(numreg, 0.);
std::copy(l2s.begin(), (l2s.begin()+numreg), vec_l2_reg.begin());
std::vector<double> vec_azimuthal_reg(numreg, 0.);
std::copy(phis.begin(), (phis.begin()+numreg), vec_azimuthal_reg.begin());
// Edit instrument // Edit instrument
m_outputW = editInstrument(m_outputW, vec_polar_reg, vec_specid_reg, vec_l2_reg, vec_azimuthal_reg); m_outputW = editInstrument(m_outputW, tthsReg, specidsReg, l2sReg, phisReg);
if (m_processLowResTOF) if (m_processLowResTOF)
{ {
size_t numlow = m_lowResW->getNumberHistograms(); m_lowResW = editInstrument(m_lowResW, tthsLow, specidsLow, l2sLow, phisLow);
// FIXME : There must be some bug in constructing the vectors for EditInstrumentGeometry
// Check size
size_t numall = numreg+numlow;
g_log.information() << "[DBx931] Num-All = " << numall << ".\n";
if (tths.size() != numall)
{
std::stringstream errss;
errss << "Input number of 2thetas (" << tths.size() << " is not equal to "
<< "the number of normal and low resolution histograms " << numall << ".\n";
for (size_t i = 0; i < tths.size(); ++i)
{
errss << "2theta[" << i << "] = " << tths[i] << "\n";
}
g_log.error(errss.str());
throw std::runtime_error(errss.str());
}
if (l2s.size() != numall)
throw std::runtime_error("Input number of L2s is not equal to the number of low and high histograms.");
if (phis.size() != numall)
throw std::runtime_error("Input number of azimuthals is not equal to the number of low and high histograms.");
std::vector<int32_t> vec_specid_low;
if (specids.size() == numall)
{
// vec_specid_low.resize(numlow, 0);
// std::copy((specids.begin()+numreg), specids.end(), vec_specid_low.begin());
for (size_t i = 0; i < numlow; ++i)
{
vec_specid_low.push_back(specids[numreg+i]);
g_log.information() << i << " : " << vec_specid_low[i] << ".\n";
}
}
else if (specids.size() == 0)
{
;
}
else
{
std::stringstream errss;
errss << "SpecIDs has a weird size = " << specids.size() << ", OutputW's size = " << numreg
<< ", LowResW's size = " << numlow << ".\n";
}
std::vector<double> vec_polar_low, vec_l2_low, vec_azimuthal_low;
for (size_t i = 0; i < numlow; ++i)
{
vec_polar_low.push_back(tths[numreg+i]);
vec_l2_low.push_back(l2s[numreg+i]);
vec_azimuthal_low.push_back(phis[numreg+i]);
}
m_lowResW = editInstrument(m_lowResW, vec_polar_low, vec_specid_low, vec_l2_low, vec_azimuthal_low);
} }
} }
...@@ -619,6 +594,22 @@ namespace WorkflowAlgorithms ...@@ -619,6 +594,22 @@ namespace WorkflowAlgorithms
// Convert units to TOF // Convert units to TOF
m_outputW = convertUnits(m_outputW, "TOF"); m_outputW = convertUnits(m_outputW, "TOF");
// compress again if appropriate
double tolerance = getProperty("CompressTolerance");
m_outputEW = boost::dynamic_pointer_cast<EventWorkspace>(m_outputW);
if ((m_outputEW) && (tolerance > 0.))
{
g_log.information() << "running CompressEvents(Tolerance=" << tolerance << ")\n";
API::IAlgorithm_sptr compressAlg = createChildAlgorithm("CompressEvents");
compressAlg->setProperty("InputWorkspace", m_outputEW);
compressAlg->setProperty("OutputWorkspace", m_outputEW);
compressAlg->setProperty("OutputWorkspace", m_outputEW);
compressAlg->setProperty("Tolerance",tolerance);
compressAlg->executeAsChildAlg();
m_outputEW = compressAlg->getProperty("OutputWorkspace");
m_outputW = boost::dynamic_pointer_cast<MatrixWorkspace>(m_outputEW);
}
if ((!m_params.empty()) && (m_params.size() != 1)) if ((!m_params.empty()) && (m_params.size() != 1))
{ {
m_params.erase(m_params.begin()); m_params.erase(m_params.begin());
...@@ -648,8 +639,8 @@ namespace WorkflowAlgorithms ...@@ -648,8 +639,8 @@ namespace WorkflowAlgorithms
API::IAlgorithm_sptr editAlg = createChildAlgorithm("EditInstrumentGeometry"); API::IAlgorithm_sptr editAlg = createChildAlgorithm("EditInstrumentGeometry");
editAlg->setProperty("Workspace", ws); editAlg->setProperty("Workspace", ws);
if (l1 > 0.) if (m_l1 > 0.)
editAlg->setProperty("PrimaryFlightPath", l1); editAlg->setProperty("PrimaryFlightPath", m_l1);
if (!polars.empty()) if (!polars.empty())
editAlg->setProperty("Polar", polars); editAlg->setProperty("Polar", polars);
if (!specids.empty()) if (!specids.empty())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment