Skip to content
Snippets Groups Projects
Commit 8dff6843 authored by Anders Markvardsen's avatar Anders Markvardsen
Browse files

Extend Q1D2 to optionally output parts of cross section. Re #2159

Needed for merging detector information from different
detectors banks
parent 76e97bb7
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,9 @@ public: ...@@ -44,6 +44,9 @@ public:
size_t waveLengthCutOff(API::MatrixWorkspace_const_sptr dataWS, const double RCut, const double WCut, size_t waveLengthCutOff(API::MatrixWorkspace_const_sptr dataWS, const double RCut, const double WCut,
const size_t specInd) const; const size_t specInd) const;
void outputParts(API::Algorithm* alg, API::MatrixWorkspace_sptr sumOfCounts,
API::MatrixWorkspace_sptr sumOfNormFactors);
private: private:
/// the experimental workspace with counts across the detector /// the experimental workspace with counts across the detector
/* API::MatrixWorkspace_const_sptr m_dataWS; /* API::MatrixWorkspace_const_sptr m_dataWS;
......
...@@ -69,6 +69,11 @@ void Q1D2::init() ...@@ -69,6 +69,11 @@ void Q1D2::init()
declareProperty("WaveCut", 0.0, mustBePositive, declareProperty("WaveCut", 0.0, mustBePositive,
"To increase resolution by starting to remove some wavelengths below this" "To increase resolution by starting to remove some wavelengths below this"
"freshold (angstrom)"); "freshold (angstrom)");
declareProperty("OutputParts", false,
"Set to true to output two additional workspaces which will have the names OutputWorkspace_sumOfCounts "
"OutputWorkspace_sumOfNormFactors. The division of _sumOfCounts and _sumOfNormFactors equals the workspace"
" returned by the property OutputWorkspace "
"(default is false)." );
} }
/** /**
@ throw invalid_argument if the workspaces are not mututially compatible @ throw invalid_argument if the workspaces are not mututially compatible
...@@ -194,6 +199,27 @@ void Q1D2::exec() ...@@ -194,6 +199,27 @@ void Q1D2::exec()
} }
PARALLEL_CHECK_INTERUPT_REGION PARALLEL_CHECK_INTERUPT_REGION
bool doOutputParts = getProperty("OutputParts");
if (doOutputParts)
{
MatrixWorkspace_sptr ws_sumOfCounts = WorkspaceFactory::Instance().create(outputWS);
for (size_t i = 0; i < ws_sumOfCounts->dataY(0).size(); i++)
{
ws_sumOfCounts->dataY(0)[i] = outputWS->dataY(0)[i];
ws_sumOfCounts->dataE(0)[i] = sqrt(outputWS->dataE(0)[i]);
}
MatrixWorkspace_sptr ws_sumOfNormFactors = WorkspaceFactory::Instance().create(outputWS);
for (size_t i = 0; i < ws_sumOfNormFactors->dataY(0).size(); i++)
{
ws_sumOfNormFactors->dataY(0)[i] = normSum[i];
ws_sumOfNormFactors->dataE(0)[i] = sqrt(normError2[i]);
}
helper.outputParts(this, ws_sumOfCounts, ws_sumOfNormFactors);
}
progress.report("Normalizing I(Q)"); progress.report("Normalizing I(Q)");
//finally divide the number of counts in each output Q bin by its weighting //finally divide the number of counts in each output Q bin by its weighting
normalize(normSum, normError2, YOut, EOutTo2); normalize(normSum, normError2, YOut, EOutTo2);
......
...@@ -132,6 +132,28 @@ size_t Qhelper::waveLengthCutOff(API::MatrixWorkspace_const_sptr dataWS, const d ...@@ -132,6 +132,28 @@ size_t Qhelper::waveLengthCutOff(API::MatrixWorkspace_const_sptr dataWS, const d
return std::lower_bound(Xs.begin(), Xs.end(), WMin) - Xs.begin(); return std::lower_bound(Xs.begin(), Xs.end(), WMin) - Xs.begin();
} }
void Qhelper::outputParts(API::Algorithm* alg, API::MatrixWorkspace_sptr sumOfCounts,
API::MatrixWorkspace_sptr sumOfNormFactors)
{
std::string baseName = alg->getPropertyValue("OutputWorkspace");
alg->declareProperty(
new API::WorkspaceProperty<API::MatrixWorkspace>("SumOfCounts","",Kernel::Direction::Output),
"The name of the MatrixWorkspace to store sum of counts" );
alg->setPropertyValue("SumOfCounts",baseName+"_sumOfCounts");
alg->setProperty("SumOfCounts", sumOfCounts);
alg->declareProperty(
new API::WorkspaceProperty<API::MatrixWorkspace>("sumOfNormFactors","",Kernel::Direction::Output),
"The name of the MatrixWorkspace to store sum of normalising factors" );
alg->setPropertyValue("sumOfNormFactors",baseName+"_sumOfNormFactors");
alg->setProperty("sumOfNormFactors", sumOfNormFactors);
}
} // namespace Algorithms } // namespace Algorithms
} // namespace Mantid } // namespace Mantid
...@@ -80,6 +80,60 @@ public: ...@@ -80,6 +80,60 @@ public:
Mantid::API::AnalysisDataService::Instance().remove(outputWS); Mantid::API::AnalysisDataService::Instance().remove(outputWS);
} }
void testOutputParts()
{
Mantid::Algorithms::Q1D2 Q1D2;
Q1D2.initialize();
const std::string outputWS("Q1D2Test_OutputParts");
TS_ASSERT_THROWS_NOTHING(
Q1D2.setProperty("DetBankWorkspace", m_inputWS);
Q1D2.setProperty("WavelengthAdj", m_wavNorm);
Q1D2.setPropertyValue("OutputWorkspace",outputWS);
Q1D2.setPropertyValue("OutputBinning","0,0.02,0.5");
Q1D2.setProperty("OutputParts", true);
// The property PixelAdj is undefined but that shouldn't cause this to throw
Q1D2.execute()
)
TS_ASSERT( Q1D2.isExecuted() )
Mantid::API::MatrixWorkspace_sptr result;
TS_ASSERT_THROWS_NOTHING( result = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>
(Mantid::API::AnalysisDataService::Instance().retrieve(outputWS)) )
Mantid::API::MatrixWorkspace_sptr sumOfCounts;
TS_ASSERT_THROWS_NOTHING( sumOfCounts = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>
(Mantid::API::AnalysisDataService::Instance().retrieve(outputWS+"_sumOfCounts")) )
Mantid::API::MatrixWorkspace_sptr sumOfNormFactors;
TS_ASSERT_THROWS_NOTHING( sumOfNormFactors = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>
(Mantid::API::AnalysisDataService::Instance().retrieve(outputWS+"_sumOfNormFactors")) )
TS_ASSERT_DELTA( result->readY(0)[1], 1131778.3299, 0.01 )
TS_ASSERT_DELTA( sumOfCounts->readY(0)[1], 1016.8990, 0.01 )
TS_ASSERT_DELTA( sumOfNormFactors->readY(0)[1], 0.00089849, 0.01 )
TS_ASSERT_DELTA( result->readE(0)[1], 57964.04, 0.01 )
TS_ASSERT_DELTA( sumOfCounts->readE(0)[1], 31.888, 0.01 )
TS_ASSERT_DELTA( sumOfNormFactors->readE(0)[1], 3.6381851288154988e-005, 0.01 )
TS_ASSERT_EQUALS( result->getNumberHistograms(), 1 )
TS_ASSERT_EQUALS( sumOfCounts->getNumberHistograms(), 1 )
TS_ASSERT_EQUALS( sumOfNormFactors->getNumberHistograms(), 1 )
TS_ASSERT_EQUALS( result->dataY(0).size(), 25 )
TS_ASSERT_EQUALS( sumOfCounts->dataY(0).size(), 25 )
//TS_ASSERT_EQUALS( sumOfNormFactors->getNumberHistograms(), 1 )
Mantid::API::AnalysisDataService::Instance().remove(outputWS);
Mantid::API::AnalysisDataService::Instance().remove(outputWS+"_sumOfCounts");
Mantid::API::AnalysisDataService::Instance().remove(outputWS+"_sumOfNormFactors");
}
void testPixelAdj() void testPixelAdj()
{ {
Mantid::Algorithms::Q1D2 Q1D; Mantid::Algorithms::Q1D2 Q1D;
......
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