Skip to content
Snippets Groups Projects
Bin2DPowderDiffraction-v1.rst 3.62 KiB
Newer Older

.. algorithm::

.. summary::

.. alias::

.. properties::

Description
-----------

This algorithm performs binning of the given workspace in :math:`(d, d_{\perp})` space, there :math:`d` is the d-Spacing and

.. math::
   :label:

    d_{\perp} = \sqrt{\lambda^2 - 2\log\cos\theta}

As the result a Matrix workspace is created. If :math:`\theta=0` or :math:`\cos\theta\le 0`, algorithm will terminate with the error message,
since no reasonable :math:`d` or :math:`d_{\perp}` value can be calculated. In this case is recommended to check whether detector positions
are correct and mask the problem detectors.


More details on the multidimensional TOF powder diffraction data reduction in:

-  *J. Appl. Cryst.* (2015) **48**, pp. 1627-1636
-  *J. Appl. Cryst.* (2017) **50**, pp. 866-875.


Restrictions on the input workspace
###################################

-  X-axis must have the wavelength units.
-  Only Histograms can be handled.
-  Only :ref:`EventWorkspaces <EventWorkspace>` are suported for the moment.
-  The input workspace must have an instrument set.
-  The input workspace must have a Spectrum axis as a Y-axis.


Binning parameters
------------------
Either *Axis1Binning* and *Axis2Binning* or *BinEdgesFile* must be specified, but not both. *Axis1Binning* contains binning parameters
in d-Spacing. *Axis2Binning* contains binning parameters in d-SpacingPerpendicular. Binning parameters should be set the same way as
for :ref:`algm-Rebin` algorithm.

In the case if non-equidistant binning is required, bin edges can be specified in the *BinEdgesFile*.

BinEdgesFile
############

*BinEdgesFile* is an ascii-file, where the bin edges are specified in a following format.

First 2 lines contain header:
    #dp_min #dp_max
    #d_bins

Then follows the line dp = :math:`d_{\perp\,n}`  :math:`d_{\perp\,n+1}` where the bin edges for the *n*-th bin are specified,
starting from the lowest values. In the next line bin edges for d-Spacing are listed as :math:`d_0, d_1, \dots, d_m`. The all is
repeated as many times as necessary. For example:

::

    #dp_min #dp_max
    #d_bins
    dp = 3.0  4.0
        1.0  3.0  6.0

    dp = 4.0  4.5
        2.0  4.0  5.15  6.0

In this example following bin edges are specified for the :math:`d_{\perp}`-axis: 3.0, 4.0, 4.5. The *d*-axis for the first spectrum
(:math:`d_{\perp}` from 3.0 to 4.0) will contain bin edges 1.0, 3.0, 6.0 and for the second spectrum (:math:`d_{\perp}` from 4.0 to 4.5)
bin edges 2.0, 4.0, 5.15, 6.0.


Usage
-----

**Example - Bin2DPowderDiffraction**

.. testcode:: Bin2DPowderDiffractionExample

   # Create an input workspace
   wsIn = CreateSampleWorkspace(WorkspaceType="Event", Function="Powder Diffraction",
                                NumBanks=1, XUnit="Wavelength", NumEvents=10,
                                XMin=1.0, XMax=6.0, BinWidth=1.0)
   # Move detector to get reasonable 2theta
   MoveInstrumentComponent(wsIn, 'bank1', X=1,Y=0,Z=1, RelativePosition=False)

   # Do binning
   wsOut = Bin2DPowderDiffraction(wsIn, Axis1Binning="2,2,6", Axis2Binning="1,2,5", NormalizeByBinArea=False)

   # Do binning and normalize the result by bin area
   wsOutNorm = Bin2DPowderDiffraction(wsIn, Axis1Binning="2,2,6", Axis2Binning="1,2,5", NormalizeByBinArea=True)

   # Print the result
   print "Y values without normalization:"
   print wsOut.extractY()
   print "Y values with normalization by bin area:"
   print wsOutNorm.extractY()

Output:

.. testoutput:: Bin2DPowderDiffractionExample

    Y values without normalization:
    [[ 278.    0.]
     [  14.  145.]]
    Y values with normalization by bin area:
    [[ 69.5    0.  ]
     [  3.5   36.25]]

.. categories::

.. sourcelink::