Skip to content

Commit

Permalink
Add Algorithm Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Despiix committed Nov 12, 2024
1 parent 132d8ec commit 81efe72
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
12 changes: 7 additions & 5 deletions Framework/Algorithms/src/CreateMonteCarloWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include <vector>

#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Progress.h"
#include "MantidAPI/Workspace.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAlgorithms/CreateMonteCarloWorkspace.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/Logger.h"
#include "MantidAPI/Progress.h"

namespace {
Mantid::Kernel::Logger g_log("CreateMonteCarloWorkspace");
Expand All @@ -41,10 +41,12 @@ const std::string CreateMonteCarloWorkspace::name() const { return "CreateMonteC
int CreateMonteCarloWorkspace::version() const { return 1; }

/// Algorithm's category for identification. @see Algorithm::category
const std::string CreateMonteCarloWorkspace::category() const { return "TODO: FILL IN A CATEGORY"; }
const std::string CreateMonteCarloWorkspace::category() const { return "Simulation"; }

/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string CreateMonteCarloWorkspace::summary() const { return "TODO: FILL IN A SUMMARY"; }
const std::string CreateMonteCarloWorkspace::summary() const {
return "Creates a randomly simulated workspace by sampling from the probability distribution of input data.";
}

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
Expand All @@ -55,7 +57,8 @@ void CreateMonteCarloWorkspace::init() {

declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
"Input Workspace containing data to be fitted");
declareProperty("Seed", 32, mustBePositive, "Integer that initializes a random-number generator");
declareProperty("Seed", 32, mustBePositive,
"Integer that initializes a random-number generator, good for reproducibility");
declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("OutputWorkspace", "", Direction::Output),
"Name of output workspace.");
}
Expand Down Expand Up @@ -105,7 +108,6 @@ void CreateMonteCarloWorkspace::exec() {
int numSteps = 7;
API::Progress progress(this, 0.0, 1.0, numSteps);


MatrixWorkspace_sptr instWs = getProperty("InputWorkspace");
int seed_input = getProperty("Seed");
progress.report();
Expand Down
47 changes: 28 additions & 19 deletions docs/source/algorithms/CreateMonteCarloWorkspace-v1.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.. algorithm::

.. summary::
Expand All @@ -9,36 +8,46 @@

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

TODO: Enter a full rst-markup description of your algorithm here.

The algorithm generates a simulated workspace by sampling from the probability
distribution of input data, useful for testing of fitting functions and modeling.
By generating a simulated dataset that mirrors the probability
distribution of existing data.

Usage
-----
.. Try not to use files in your examples,
but if you cannot avoid it then the (small) files must be added to
autotestdata\UsageData and the following tag unindented
.. include:: ../usagedata-note.txt

**Example - CreateMonteCarloWorkspace**

.. testcode:: CreateMonteCarloWorkspaceExample
.. testcode:: Create simulation and compare

# Create a host workspace
ws = CreateWorkspace(DataX=range(0,3), DataY=(0,2))
or
ws = CreateSampleWorkspace()
from mantid.api import AnalysisDataService as ADS

wsOut = CreateMonteCarloWorkspace()
# Create Sample Workspace and Run Simulation
ws = CreateSampleWorkspace(Random= True)
wsOut = CreateMonteCarloWorkspace(InputWorkspace= 'ws', Seed= 32, OutputWorkspace= "New")

# Print the result
print "The output workspace has %%i spectra" %% wsOut.getNumberHistograms()
# Plot both of the above
fig, axes = plt.subplots(edgecolor='#ffffff', num='New', subplot_kw={'projection': 'mantid'})
for data, color, label in [(ADS.retrieve('New'), '#1f77b4', 'New: spec 1'),
(ADS.retrieve('ws'), '#ff7f0e', 'ws: spec 1')]:
axes.plot(data, color=color, label=label, wkspIndex=0)

Output:
axes.tick_params(axis='both', which='major', size=6, tickdir='out', width=1, gridOn=False, label1On=True)
axes.set(title='New', xlabel='Time-of-flight ($\\mu s$)', ylabel='Counts ($\\mu s$)$^{-1}$', ylim=[-0.00225, 0.04725])
axes.legend(fontsize=8.0).set_draggable(True)

.. testoutput:: CreateMonteCarloWorkspaceExample
fig.show()

The output workspace has ?? spectra
Output:
A histogram similar to the original but generated in a random way.

.. image:: ../../../images/New.png
:alt: Overplot of simulated data over input data
:width: 500px
:height: 400px
:scale: 100%
:align: center
:class: custom-class

.. categories::

Expand Down
Binary file added images/New.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 81efe72

Please sign in to comment.