diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ReflectometryTransform.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ReflectometryTransform.h index 7b725f9cd8e1b1fab2ab0c29ce50097088668138..934a48175d31f8c31b57ee36a8268576f08a9b2e 100644 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ReflectometryTransform.h +++ b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ReflectometryTransform.h @@ -7,6 +7,8 @@ #include "MantidAPI/IMDEventWorkspace_fwd.h" #include "MantidDataObjects/MDEventFactory.h" +#include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> namespace Mantid { namespace API { @@ -15,6 +17,7 @@ class MatrixWorkspace; namespace DataObjects { class CalculateReflectometry; +class TableWorkspace; /** ReflectometryMDTransform : Abstract type for reflectometry transforms to MDWorkspaces. This is a Strategy Design Pattern. @@ -82,7 +85,7 @@ public: /// Execuate transformation using normalised polynomial binning Mantid::API::MatrixWorkspace_sptr - executeNormPoly(Mantid::API::MatrixWorkspace_const_sptr inputWs) const; + executeNormPoly(Mantid::API::MatrixWorkspace_const_sptr inputWs, boost::optional<boost::shared_ptr<Mantid::DataObjects::TableWorkspace> >& vertexes) const; virtual ~ReflectometryTransform(); ReflectometryTransform(const std::string &d0Label, const std::string &d0ID, diff --git a/Code/Mantid/Framework/DataObjects/src/ReflectometryTransform.cpp b/Code/Mantid/Framework/DataObjects/src/ReflectometryTransform.cpp index 82e5d37386822fafb0d2c9de606b8996809d538c..8c5b7949c8ac8dc106a87534ae920b4682ecc91c 100644 --- a/Code/Mantid/Framework/DataObjects/src/ReflectometryTransform.cpp +++ b/Code/Mantid/Framework/DataObjects/src/ReflectometryTransform.cpp @@ -3,10 +3,12 @@ #include "MantidAPI/BinEdgeAxis.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/SpectrumDetectorMapping.h" +#include "MantidAPI/TableRow.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataObjects/CalculateReflectometry.h" #include "MantidDataObjects/FractionalRebinning.h" #include "MantidDataObjects/RebinnedOutput.h" +#include "MantidDataObjects/TableWorkspace.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidGeometry/Instrument/DetectorGroup.h" #include "MantidGeometry/Instrument/ReferenceFrame.h" @@ -224,7 +226,15 @@ Mantid::API::MatrixWorkspace_sptr ReflectometryTransform::execute( } MatrixWorkspace_sptr ReflectometryTransform::executeNormPoly( - MatrixWorkspace_const_sptr inputWS) const { + MatrixWorkspace_const_sptr inputWS, boost::optional<boost::shared_ptr<Mantid::DataObjects::TableWorkspace> >& vertexes) const { + // Create a table for the output if we want to debug vertex positioning + if(vertexes){ + (*vertexes)->addColumn("double","Qx"); + (*vertexes)->addColumn("double","Qy"); + (*vertexes)->addColumn("int","OriginIndex"); + (*vertexes)->addColumn("int", "OriginBin"); + (*vertexes)->addColumn("double", "CellSignal"); + } MatrixWorkspace_sptr temp = WorkspaceFactory::Instance().create( "RebinnedOutput", m_d1NumBins, m_d0NumBins, m_d0NumBins); @@ -304,6 +314,19 @@ MatrixWorkspace_sptr ReflectometryTransform::executeNormPoly( outWS->getSpectrum(qIndex - 1)->getSpectrumNo()); detIDMapping.push_back(detector->getID()); } + + //Debugging + if(vertexes){ + TableRow row = (*vertexes)->appendRow(); + row << ll.X() << ll.Y() << int(i) << int(j) << signal; + row = (*vertexes)->appendRow(); + row << ul.X() << ul.Y() << int(i) << int(j) << signal; + row = (*vertexes)->appendRow(); + row << ur.X() << ur.Y() << int(i) << int(j) << signal; + row = (*vertexes)->appendRow(); + row << lr.X() << lr.Y() << int(i) << int(j) << signal; + + } } } outWS->finalize(); diff --git a/Code/Mantid/Framework/MDAlgorithms/src/ConvertToReflectometryQ.cpp b/Code/Mantid/Framework/MDAlgorithms/src/ConvertToReflectometryQ.cpp index de57ca5b7d325262145b0dd247bb79741cdd0d7e..7f2936bb9b15eb3492041f0c4d15343d19f01084 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/ConvertToReflectometryQ.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/ConvertToReflectometryQ.cpp @@ -1,9 +1,11 @@ #include "MantidMDAlgorithms/ConvertToReflectometryQ.h" #include "MantidAPI/IEventWorkspace.h" +#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/WorkspaceValidators.h" #include "MantidDataObjects/EventWorkspace.h" +#include "MantidDataObjects/TableWorkspace.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidKernel/ArrayProperty.h" @@ -18,6 +20,7 @@ #include "MantidMDAlgorithms/ReflectometryTransformQxQz.h" #include "MantidMDAlgorithms/ReflectometryTransformP.h" +#include <boost/optional.hpp> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> @@ -235,6 +238,10 @@ void ConvertToReflectometryQ::init() { declareProperty(new WorkspaceProperty<IMDWorkspace>("OutputWorkspace", "", Direction::Output), "Output 2D Workspace."); + + declareProperty(new WorkspaceProperty<ITableWorkspace>("OutputVertexes", "", + Direction::Output), + "Output TableWorkspace with vertex information. See DumpVertexes property."); declareProperty(new Kernel::PropertyWithValue<int>("NumberBinsQx", 100), "The number of bins along the qx axis. Optional and only " @@ -242,6 +249,11 @@ void ConvertToReflectometryQ::init() { declareProperty(new Kernel::PropertyWithValue<int>("NumberBinsQz", 100), "The number of bins along the qx axis. Optional and only " "applies to 2D workspaces. Defaults to 100."); + + declareProperty( + new Kernel::PropertyWithValue<bool>("DumpVertexes", false), + "If set, with 2D rebinning, the intermediate vertexes for each polygon will be written out for debugging purposes. Creates a second output table workspace."); + setPropertySettings( "NumberBinsQx", new EnabledWhenProperty("OutputAsMDWorkspace", IS_NOT_DEFAULT)); @@ -260,6 +272,8 @@ void ConvertToReflectometryQ::init() { setPropertySettings( "MaxRecursionDepth", new EnabledWhenProperty("OutputAsMDWorkspace", IS_DEFAULT)); + + } //---------------------------------------------------------------------------------------------- @@ -338,6 +352,8 @@ void ConvertToReflectometryQ::exec() { IMDWorkspace_sptr outputWS; + TableWorkspace_sptr vertexes = boost::make_shared<Mantid::DataObjects::TableWorkspace>(); + if (outputAsMDWorkspace) { if (transMethod == centerTransform()) { auto outputMDWS = transform->executeMD(inputWs, bc); @@ -356,7 +372,10 @@ void ConvertToReflectometryQ::exec() { outputWS2D->copyExperimentInfoFrom(inputWs.get()); outputWS = outputWS2D; } else if (transMethod == normPolyTransform()) { - auto outputWSRB = transform->executeNormPoly(inputWs); + const bool dumpVertexes = this->getProperty("DumpVertexes"); + auto vertexesTable = dumpVertexes ? boost::optional<boost::shared_ptr<Mantid::DataObjects::TableWorkspace> >(vertexes) : boost::optional<boost::shared_ptr<Mantid::DataObjects::TableWorkspace> >(); + + auto outputWSRB = transform->executeNormPoly(inputWs, vertexesTable); outputWSRB->copyExperimentInfoFrom(inputWs.get()); outputWS = outputWSRB; } else { @@ -366,6 +385,7 @@ void ConvertToReflectometryQ::exec() { // Execute the transform and bind to the output. setProperty("OutputWorkspace", outputWS); + setProperty("OutputVertexes", vertexes); } } // namespace Mantid diff --git a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToReflectometryQTest.h b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToReflectometryQTest.h index 7fe868c879964593b04c0825d9ebeb0e82725470..b8c95a031249f47921d9ed9767b216ffff9479b2 100644 --- a/Code/Mantid/Framework/MDAlgorithms/test/ConvertToReflectometryQTest.h +++ b/Code/Mantid/Framework/MDAlgorithms/test/ConvertToReflectometryQTest.h @@ -52,6 +52,7 @@ private: alg->setProperty("InputWorkspace", in_ws); alg->setProperty("OutputDimensions", outputdimensions); alg->setPropertyValue("OutputWorkspace", "OutputTransformedWorkspace"); + alg->setPropertyValue("OutputVertexes", "vertexes"); alg->setProperty("OverrideIncidentTheta", true); alg->setProperty("OutputAsMDWorkspace", outputAsMD); alg->setProperty("IncidentTheta", 0.5); @@ -284,6 +285,8 @@ public: specaxisalg->initialize(); specaxisalg->setPropertyValue("InputWorkspace", "testws"); specaxisalg->setPropertyValue("OutputWorkspace", "testws"); + specaxisalg->setPropertyValue("OutputVertexes", "vertexes"); + specaxisalg->setPropertyValue("Target", "signed_theta"); specaxisalg->execute(); @@ -299,6 +302,7 @@ public: alg.setProperty("InputWorkspace", ws->getItem(0)); alg.setProperty("OutputDimensions", "Q (lab frame)"); alg.setPropertyValue("OutputWorkspace", "OutputTransformedWorkspace"); + alg.setPropertyValue("OutputVertexes", "vertexes"); alg.setProperty("OverrideIncidentTheta", true); alg.setProperty("IncidentTheta", 0.5); TS_ASSERT(alg.execute()); @@ -317,6 +321,7 @@ public: alg.setProperty("OutputDimensions", "Q (lab frame)"); alg.setProperty("OutputAsMDWorkspace", false); alg.setPropertyValue("OutputWorkspace", "OutputTransformedWorkspace"); + alg.setPropertyValue("OutputVertexes", "vertexes"); alg.setProperty("OverrideIncidentTheta", true); alg.setProperty("IncidentTheta", 0.5); alg.setProperty("Method", "NormalisedPolygon");