Skip to content

Commit

Permalink
Refs #12585 doc test running and release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Jul 7, 2016
1 parent 5fcf12e commit b2d4ff4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 24 deletions.
11 changes: 6 additions & 5 deletions Framework/MDAlgorithms/src/IntegratePeaksMDHKL.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "MantidMDAlgorithms/IntegratePeaksMDHKL.h"

#include "MantidDataObjects/MDFramesToSpecialCoordinateSystem.h"
#include "MantidAPI/CommonBinsValidator.h"
#include "MantidAPI/InstrumentValidator.h"
#include "MantidAPI/WorkspaceUnitValidator.h"
Expand Down Expand Up @@ -37,7 +37,7 @@ IntegratePeaksMDHKL::IntegratePeaksMDHKL() {}
void IntegratePeaksMDHKL::init() {
declareProperty(make_unique<WorkspaceProperty<IMDWorkspace>>(
"InputWorkspace", "", Direction::Input),
"An input Sample MDEventWorkspace in HKL.");
"An input Sample MDHistoWorkspace or MDEventWorkspace in HKL.");
declareProperty("DeltaHKL", 0.5,
"Distance from integer HKL to integrate peak.");
declareProperty("GridPoints", 201,
Expand Down Expand Up @@ -80,10 +80,12 @@ void IntegratePeaksMDHKL::init() {
*/
void IntegratePeaksMDHKL::exec() {
IMDWorkspace_sptr m_inputWS = getProperty("InputWorkspace");
if (m_inputWS->getSpecialCoordinateSystem() != Mantid::Kernel::HKL) {
Mantid::DataObjects::MDFramesToSpecialCoordinateSystem converter;
boost::optional<Mantid::Kernel::SpecialCoordinateSystem> coordinateSystem = converter(m_inputWS.get());
if( *coordinateSystem != Mantid::Kernel::SpecialCoordinateSystem::HKL) {
std::stringstream errmsg;
errmsg << "Input MDWorkspace's coordinate system is not HKL but "
<< m_inputWS->getSpecialCoordinateSystem() << ".";
<< coordinateSystem << ".";
throw std::invalid_argument(errmsg.str());
}

Expand Down Expand Up @@ -175,7 +177,6 @@ void IntegratePeaksMDHKL::integratePeak(const int neighborPts,
MDHistoWorkspace_sptr out,
double &intensity,
double &errorSquared) {
// AnalysisDataService::Instance().addOrReplace("box", out);
std::vector<int> gridPts;
const size_t dimensionality = out->getNumDims();
for (size_t i = 0; i < dimensionality; ++i) {
Expand Down
60 changes: 47 additions & 13 deletions docs/source/algorithms/IntegratePeaksMDHKL-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ Description
-----------

:ref:`IntegratePeaksMDHKL <algm-IntegratePeaksMDHKL>` provides integration of a
:ref:`MDHistoWorkspace <MDHistoWorkspace>` or :ref:`MDEventWorkspace <MDEventWorkspace>` in 3-dimensions.
The units of the workspace must be HKL. The main usage will be for data normalized by :ref:`MDNormSCD <algm-MDNormSCD>`.
:ref:`MDHistoWorkspace <MDHistoWorkspace>` or :ref:`MDEventWorkspace <MDWorkspace>` in 3-dimensions.
The units of the workspace must be HKL. The main usage will be for data normalized by
:ref:`MDNormSCD <algm-MDNormSCD>`.
A 3D box is created for each peak and the background and peak data are separated. The intensity and sigma of the
intensity is found from the grid inside the peak and the background is subtracted. The boxes are created and integrated
in parallel and less memory is required than binning all HKL at once.

:math:`I_{corr} = I_{peak} - pts_{peak}/pts_{bg} * I_{bg}`

with the errors summed in quadrature:

:math:`\sigma_{I,corr}^2 = \sigma_{I,peak}^2 + pts_{peak}/pts_{bg} * \sigma_{I,bg}^2`

Using the DeltaHKL parameter, the problem of nearly peaks or regions of diffuse scattering can be avoided. Also for
normalized data, the unmeasured data points are excluded from the background. See white regions in last figure.

.. figure:: /images/peak3d.png
:alt: peak3d.png
Expand All @@ -28,42 +37,67 @@ in parallel and less memory is required than binning all HKL at once.
.. figure:: /images/IntegratePeaksMDHKLbox.png
:alt: IntegratePeaksMDHKLbox.png
:width: 400px
:align: left
:align: center

Integration slice at center of box.

.. figure:: /images/IntegratePeaksMDHKLpeak.png
:alt: IntegratePeaksMDHKLpeak.png
:width: 400px
:align: center

Integration slice of peak grid points.

.. figure:: /images/IntegratePeaksMDHKLbkg.png
:alt: IntegratePeaksMDHKLbkg.png
:width: 400px
:align: right
:align: center

Integration Output. Slice at center of box (left) with peak (center) grid point and background (right) points separated.
Integration slice of background grid points.


Usage
-----

**Example - IntegratePeaksMDHKL simple cut**
**Example - IntegratePeaksMDHKL event histo**

.. testcode:: IntegratePeaksMDHKLExample

mdws = CreateMDWorkspace(Dimensions=3, Extents=[-10,10,-10,10,-10,10], Names='[H,0,0],[0,K,0],[0,0,L]',Units='U,U,U')
#Create PeaksWorkspace
sampleWs = CreateSampleWorkspace()
pws = CreatePeaksWorkspace(InstrumentWorkspace=sampleWs,NumberOfPeaks=3)
p = pws.getPeak(0)
p.setHKL(5,0,0)
p = pws.getPeak(1)
p.setHKL(0,0,0)
p = pws.getPeak(2)
p.setHKL(-5,0,0)
#Test with MDEventWorkspace
mdws = CreateMDWorkspace(Dimensions=3, Extents=[-10,10,-10,10,-10,10], Names='[H,0,0],[0,K,0],[0,0,L]',Units='A^-1,A^-1,A^-1',Frames='HKL,HKL,HKL')
FakeMDEventData(InputWorkspace=mdws, PeakParams=[100000,-5,0,0,1])
FakeMDEventData(InputWorkspace=mdws, PeakParams=[100000,0,0,0,1])
FakeMDEventData(InputWorkspace=mdws, PeakParams=[100000,5,0,0,1])
pws = CreatePeaksWorkspace(mdws, NumberOfPeaks=0)
# Add peak to the peaks workspace
AddPeak( pws, ws, TOF=100, DetectorID=101, Height=1 )

#Integrate out 2 dimensions
#pws =IntegratePeaksMDHKL(InputWorkspace=mdws,PeaksWorkspace=pws)
pws =IntegratePeaksMDHKL(InputWorkspace=mdws,PeaksWorkspace=pws,DeltaHKL=1.5,GridPoints=21)
for i in range(3):
p = pws.getPeak(i)
print p.getIntensity(),p.getSigmaIntensity()
#Test with MDHistoWorkspace
mdws = BinMD(InputWorkspace=mdws,AlignedDim0="[H,0,0],-10,10,101",AlignedDim1="[0,K,0],-10,10,101",AlignedDim2="[0,0,L],-10,10,101")
pws =IntegratePeaksMDHKL(InputWorkspace=mdws,PeaksWorkspace=pws,DeltaHKL=1.5,GridPoints=21)
for i in range(3):
p = pws.getPeak(i)
print p.getIntensity(),p.getSigmaIntensity()


Output:

.. testoutput:: IntegratePeaksMDHKLExample

99913.3212993 316.143446399
99913.3212993 316.143446399
99913.3212993 316.143446399
99945.2374619 316.168987268
99951.6716018 316.174385251
99926.3456269 316.148488307


16 changes: 10 additions & 6 deletions docs/source/release/v3.8.0/diffraction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ Single Crystal Diffraction
has been expanded and improved from previous release. It provides an integrated user-friendly interface for
instrument scientists and users to access data, calculate and refine UB matrix, merge multiple data sets
for slice-view and peak integration.
.. figure:: ../../images/peak3d.png
:width: 487
:align: right

- :ref:`IntegratePeaksMDHKL <algm-IntegratePeaksMDHKL>` has been added to integrate data in HKL space. The
main usage will be for data normalized by :ref:`MDNormSCD <algm-MDNormSCD>`, but it also works for MDHistoWorkspaces
and MDEventWorkspaces. The MD data must be in units of HKL. A 3D box is created for each peak and the background
main usage will be to normalize the data using
:ref:`MDNormSCD <algm-MDNormSCD>` and then integrate the resulting MDHistoWorkspace,
but it also integrates MDHistoWorkspaces and MDEventWorkspaces without normalizing.
The MD data must be in units of HKL. A 3D box is created for each peak and the background
and peak data are separated. The intensity and sigma of the intensity is found from the grid inside the peak and
the background is subtracted. The boxes are created and integrated in parallel and less memory is required than
binning all HKL at once.
binning all HKL space at once. The figure shows the grid points within an HKL box that are in one peak from Si data.
.. figure:: ../../images/peak3d.png
:width: 487
:align: center



Engineering Diffraction
Expand Down

0 comments on commit b2d4ff4

Please sign in to comment.