Skip to content

Commit

Permalink
Refs #9584 Add examples for SumSpectra
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Jun 9, 2014
1 parent b86d06b commit a0200e6
Showing 1 changed file with 83 additions and 19 deletions.
102 changes: 83 additions & 19 deletions Code/Mantid/docs/source/algorithms/SumSpectra-v1.rst
Expand Up @@ -16,34 +16,98 @@ spectra.

The algorithm adds to the **OutputWorkspace** three additional
properties (Log values). The properties (Log) names are:
**"NumAllSpectra"**, **"NumMaskSpectra"** and **"NumZeroSpectra"**,
**NumAllSpectra**, **NumMaskSpectra** and **NumZeroSpectra**,
where:

| ``  NumAllSpectra  -- is the number of spectra contributed to the sum``
| ``  NumMaskSpectra -- the spectra dropped from the summations because they are masked. ``
| ``                    If monitors (``\ **``IncludeMonitors``**\ ``=false) are not included in the summation,``
| ``                    they are not counted here. ``
| ``  NumZeroSpectra -- number of zero bins in histogram workspace or empty spectra for event workspace. ``
| ``                    These spectra are dropped from the summation of histogram workspace ``
| ``                    when ``\ **``WeightedSum``**\ `` property is set to True.``
* NumAllSpectra is the number of spectra contributed to the sum

* NumMaskSpectra is the spectra dropped from the summations because they are masked. 

* If monitors are not included in the summation, they are not counted here.

* NumZeroSpectra isthe number of zero bins in histogram workspace or empty spectra for event workspace. 

* These spectra are dropped from the summation of histogram workspace when WeightedSum property is set to True.

Assuming **pWS** is the output workspace handle, from Python these
properties can be accessed by the code:

| ``   nSpectra       = pWS.getRun().getLogData("NumAllSpectra").value``
| ``   nMaskedSpectra = pWS.getRun().getLogData("NumMaskSpectra").value ``
| ``   nZeroSpectra   = pWS.getRun().getLogData("NumZeroSpectra").value``
.. code-block:: python
   nSpectra       = pWS.getRun().getLogData("NumAllSpectra").value
   nMaskedSpectra = pWS.getRun().getLogData("NumMaskSpectra").value 
   nZeroSpectra   = pWS.getRun().getLogData("NumZeroSpectra").value
Usage
-----
**Example - a simple example of running SumSpectra.**

.. testcode:: ExSumSpectraSimple

ws = CreateSampleWorkspace("Histogram", Random=True)
print "Workspace has %d spectra" % ws.getNumberHistograms()

ws = SumSpectra(ws)
print "Workspace has %d spectra" % ws.getNumberHistograms()

Output:

.. testoutput:: ExSumSpectraSimple

Workspace has 200 spectra
Workspace has 1 spectra

**Example - running SumSpectra with a list of indicies.**

.. testcode:: ExSumSpectraListOfIndicies

ws = CreateSampleWorkspace("Histogram", Random=True)
print "Workspace has %d spectra" % ws.getNumberHistograms()

ws = SumSpectra(ws, ListOfWorkspaceIndices='0-3, 10-13')
print "Workspace has %d spectra" % ws.getNumberHistograms()

Output:

.. testoutput:: ExSumSpectraListOfIndicies

Workspace has 200 spectra
Workspace has 1 spectra

**Example - a running SumSpectra with a start and end index.**

.. testcode:: ExSumSpectraStartEnd

ws = CreateSampleWorkspace("Histogram", Random=True)
print "Workspace has %d spectra" % ws.getNumberHistograms()

ws = SumSpectra(ws, StartWorkspaceIndex=0, EndWorkspaceIndex=9)
print "Workspace has %d spectra" % ws.getNumberHistograms()

Output:

.. testoutput:: ExSumSpectraStartEnd

Workspace has 200 spectra
Workspace has 1 spectra

**Example - a running SumSpectra in weighted sum mode.**

.. testcode:: ExSumSpectraWeighted

ws = CreateSampleWorkspace("Histogram", Random=True)
print "Workspace has %d spectra" % ws.getNumberHistograms()

ws = SumSpectra(ws, WeightedSum=True)
print "Workspace has %d spectra" % ws.getNumberHistograms()

Output:

It is also available in stats property obtained by qtiGenie function
avrg\_spectra
.. testoutput:: ExSumSpectraWeighted

| ``  (avrg,stats) = avrg_spectra(Input_workspace)``
| ``   stats==[nSpectra,nMaskedSpectra,nZeroSpectra]``
Workspace has 200 spectra
Workspace has 1 spectra

From C++ they can be reached as strings by the code:

| ``     std::string rez=pWS->run().getLogData("NumAllSpectra")->value();``
| ``     std::string rez=pWS->run().getLogData("NumMaskSpectra")->value();``
| ``     std::string rez=pWS->run().getLogData("NumZeroSpectra")->value();``

.. categories::

0 comments on commit a0200e6

Please sign in to comment.