Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder Class Reference

#include <SingleCrystalDiffractionTestHelper.h>

Public Member Functions

void addBackground (const bool useBackground)
 
void addPeakByHKL (const Mantid::Kernel::V3D &hkl, const int numEvents, const std::tuple< double, double, double > &sigmas)
 Add a HKL peak to the diffraction dataset. More...
 
std::tuple< Mantid::API::MatrixWorkspace_sptr, Mantid::DataObjects::PeaksWorkspace_sptrbuild ()
 Make a tuple of event workspace and peaks workspace. More...
 
void outputAsHistogram (const bool outputAsHistogram)
 Set whether to create an event workspace or a histogram workspace. More...
 
void setBackgroundParameters (const int nEvents, const double detRange, const double tofRange)
 Set the parameters for the uniform background. More...
 
void setNumPixels (const int numPixels)
 Set the total number of peaks to use. More...
 
void setRandomSeed (const int seed)
 Set the random seed for generating events. More...
 
void setRebinParameters (const std::vector< double > &rebinParams)
 Set the rebin parameters to use. More...
 
 WorkspaceBuilder ()
 

Private Types

using HKLPeakDescriptor = std::tuple< Mantid::Kernel::V3D, int, std::tuple< double, double, double > >
 

Private Member Functions

void createBackground (const int peakIndex)
 Create a flat background for the workspace. More...
 
void createEventWorkspace ()
 Create an empty event workspace with the instrument attached. More...
 
void createInstrument ()
 Create a dummy instrument. More...
 
void createNeighbourSearch ()
 Create a neighbour search tree for finding nearest neighbours. More...
 
void createPeak (const HKLPeakDescriptor &descriptor)
 Create a single HKL peak in the event workspace. More...
 
void createPeaks ()
 Create peaks at the requested HKL positions. More...
 
void createPeaksWorkspace ()
 Create a peaks workspace with the request HKL peaks. More...
 
void rebinWorkspace ()
 Rebin the event workspace to a histogram workspace. More...
 

Private Attributes

std::tuple< int, double, double > m_backgroundParameters
 background parameters More...
 
std::unique_ptr< Mantid::Kernel::NearestNeighbours< 3 > > m_detectorSearcher
 Nearest neighbour search tree for detectors. More...
 
Mantid::DataObjects::EventWorkspace_sptr m_eventWorkspace
 Handle to the event workspace. More...
 
std::mt19937 m_generator
 Random generator for making events. More...
 
Mantid::Geometry::Instrument_sptr m_instrument
 Handle to the instrument object. More...
 
int m_numPixels
 number of pixels along a single axis on the detector bank More...
 
bool m_outputAsHistogram
 whether to output event or histogram data More...
 
std::vector< HKLPeakDescriptorm_peakDescriptors
 List of peak descriptors for creating peaks. More...
 
Mantid::DataObjects::PeaksWorkspace_sptr m_peaksWorkspace
 Handle to the peaks workspace. More...
 
std::vector< double > m_rebinParams
 rebin parameters More...
 
int m_totalNPixels
 total number of pixels in the detector bank More...
 
bool m_useBackground
 whether to add a background More...
 
Mantid::API::MatrixWorkspace_sptr m_workspace
 Handle to the final output workspace (event OR histogram) More...
 

Detailed Description

Definition at line 22 of file SingleCrystalDiffractionTestHelper.h.

Member Typedef Documentation

◆ HKLPeakDescriptor

using Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::HKLPeakDescriptor = std::tuple<Mantid::Kernel::V3D, int, std::tuple<double, double, double> >
private

Definition at line 47 of file SingleCrystalDiffractionTestHelper.h.

Constructor & Destructor Documentation

◆ WorkspaceBuilder()

Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::WorkspaceBuilder ( )
inline

Definition at line 25 of file SingleCrystalDiffractionTestHelper.h.

Member Function Documentation

◆ addBackground()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::addBackground ( const bool  useBackground)
inline

Definition at line 33 of file SingleCrystalDiffractionTestHelper.h.

References m_useBackground.

◆ addPeakByHKL()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::addPeakByHKL ( const Mantid::Kernel::V3D hkl,
const int  numEvents,
const std::tuple< double, double, double > &  sigmas 
)

Add a HKL peak to the diffraction dataset.

Add a peak to the data set to be generated.

This will create a peak in the event workspace at the given HKL postion.

The sigmas parameter is a tuple that controls the distribution of events in the workspace. The first two elements control the x and y variance on the detector bank face. The final element controls the variance in the time of flight spectrum.

Parameters
hkl:: the HKL position of the peak
numEvents:: the number of events to create for the peak
sigmas:: tuple controlling the distribution of events

Definition at line 55 of file SingleCrystalDiffractionTestHelper.cpp.

References m_peakDescriptors, and Mantid::DataHandling::numEvents().

◆ build()

std::tuple< MatrixWorkspace_sptr, PeaksWorkspace_sptr > Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::build ( )

Make a tuple of event workspace and peaks workspace.

Build a new set of diffraction data.

This will use the configured parameters supplied by the user to create a new event workspace with events at the specified HKL peak positions.

This will return a tuple where the first element is a matrix workspace pointer that is either an event workspace or a histogram workspace depending on the options set. The second element will be a peaks workspace.

Returns
a tuple containing a matrix workspace and a peaks workspace

Definition at line 71 of file SingleCrystalDiffractionTestHelper.cpp.

References createEventWorkspace(), createInstrument(), createNeighbourSearch(), createPeaks(), createPeaksWorkspace(), m_outputAsHistogram, m_peaksWorkspace, m_workspace, and rebinWorkspace().

◆ createBackground()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::createBackground ( const int  peakIndex)
private

Create a flat background for the workspace.

Create a uniform background around each peak in the workspace.

This will NOT add background to the entire workspace as that would cause the generator to take too long to be used in a unit test. Instead this will generate a uniform background in a "box" around a peak.

Parameters
peakIndex:: index of the peak to create a uniform background for

Definition at line 203 of file SingleCrystalDiffractionTestHelper.cpp.

References index, m_backgroundParameters, m_detectorSearcher, m_eventWorkspace, m_generator, and m_peaksWorkspace.

Referenced by createPeaks().

◆ createEventWorkspace()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::createEventWorkspace ( )
private

Create an empty event workspace with the instrument attached.

Create an empty event workspace.

This will create an empty event workspace with the instrument attached

Definition at line 116 of file SingleCrystalDiffractionTestHelper.cpp.

References m_eventWorkspace, m_instrument, m_totalNPixels, m_workspace, and Mantid::API::ISpectrum::setDetectorID().

Referenced by build().

◆ createInstrument()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::createInstrument ( )
private

Create a dummy instrument.

Create a new instrument.

This will create a simple rectangular instrument with the requested number of pixels

Definition at line 90 of file SingleCrystalDiffractionTestHelper.cpp.

References ComponentCreationHelper::createTestInstrumentRectangular(), m_instrument, and m_numPixels.

Referenced by build().

◆ createNeighbourSearch()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::createNeighbourSearch ( )
private

Create a neighbour search tree for finding nearest neighbours.

Create a KD-Tree of detector positions that can be used to find the closest detector to a given event position.

Definition at line 235 of file SingleCrystalDiffractionTestHelper.cpp.

References m_detectorSearcher, and m_eventWorkspace.

Referenced by build().

◆ createPeak()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::createPeak ( const HKLPeakDescriptor descriptor)
private

Create a single HKL peak in the event workspace.

Create a single peak for a given HKL descriptor.

This will create a Gaussian distributed set of events located at the TOF position of a corresponding HKL value.

This distribution of events is controlled by the sigmas parameter of the HKL descriptor which describes the variance in the x, y, and TOF position.

Parameters
descriptora HKLPeakDescriptor which describes the position, intensity and variance in a peak

Definition at line 156 of file SingleCrystalDiffractionTestHelper.cpp.

References index, m_detectorSearcher, m_eventWorkspace, m_generator, and m_peaksWorkspace.

Referenced by createPeaks().

◆ createPeaks()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::createPeaks ( )
private

Create peaks at the requested HKL positions.

Create peaks for all HKL descriptors passed to the builder.

Definition at line 135 of file SingleCrystalDiffractionTestHelper.cpp.

References createBackground(), createPeak(), index, m_peakDescriptors, and m_useBackground.

Referenced by build().

◆ createPeaksWorkspace()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::createPeaksWorkspace ( )
private

Create a peaks workspace with the request HKL peaks.

Create an empty peaks workspace.

This will create an empty peaks workspace with a oriented lattice and will also set the instrument.

Definition at line 101 of file SingleCrystalDiffractionTestHelper.cpp.

References m_instrument, and m_peaksWorkspace.

Referenced by build().

◆ outputAsHistogram()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::outputAsHistogram ( const bool  outputAsHistogram)
inline

Set whether to create an event workspace or a histogram workspace.

Definition at line 30 of file SingleCrystalDiffractionTestHelper.h.

References m_outputAsHistogram, and outputAsHistogram().

Referenced by outputAsHistogram().

◆ rebinWorkspace()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::rebinWorkspace ( )
private

Rebin the event workspace to a histogram workspace.

Rebin the event workspace using the parameters provided.

Definition at line 247 of file SingleCrystalDiffractionTestHelper.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), m_eventWorkspace, m_rebinParams, and m_workspace.

Referenced by build().

◆ setBackgroundParameters()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::setBackgroundParameters ( const int  nEvents,
const double  detRange,
const double  tofRange 
)
inline

Set the parameters for the uniform background.

Definition at line 35 of file SingleCrystalDiffractionTestHelper.h.

References m_backgroundParameters.

◆ setNumPixels()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::setNumPixels ( const int  numPixels)

Set the total number of peaks to use.

Definition at line 37 of file SingleCrystalDiffractionTestHelper.cpp.

References m_numPixels, and m_totalNPixels.

◆ setRandomSeed()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::setRandomSeed ( const int  seed)
inline

Set the random seed for generating events.

Definition at line 39 of file SingleCrystalDiffractionTestHelper.h.

References m_generator.

◆ setRebinParameters()

void Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::setRebinParameters ( const std::vector< double > &  rebinParams)
inline

Set the rebin parameters to use.

Definition at line 32 of file SingleCrystalDiffractionTestHelper.h.

References m_rebinParams.

Member Data Documentation

◆ m_backgroundParameters

std::tuple<int, double, double> Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_backgroundParameters
private

background parameters

Definition at line 92 of file SingleCrystalDiffractionTestHelper.h.

Referenced by createBackground(), and setBackgroundParameters().

◆ m_detectorSearcher

std::unique_ptr<Mantid::Kernel::NearestNeighbours<3> > Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_detectorSearcher
private

Nearest neighbour search tree for detectors.

Definition at line 67 of file SingleCrystalDiffractionTestHelper.h.

Referenced by createBackground(), createNeighbourSearch(), and createPeak().

◆ m_eventWorkspace

Mantid::DataObjects::EventWorkspace_sptr Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_eventWorkspace
private

Handle to the event workspace.

Definition at line 75 of file SingleCrystalDiffractionTestHelper.h.

Referenced by createBackground(), createEventWorkspace(), createNeighbourSearch(), createPeak(), and rebinWorkspace().

◆ m_generator

std::mt19937 Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_generator
private

Random generator for making events.

Definition at line 97 of file SingleCrystalDiffractionTestHelper.h.

Referenced by createBackground(), createPeak(), and setRandomSeed().

◆ m_instrument

Mantid::Geometry::Instrument_sptr Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_instrument
private

Handle to the instrument object.

Definition at line 71 of file SingleCrystalDiffractionTestHelper.h.

Referenced by createEventWorkspace(), createInstrument(), and createPeaksWorkspace().

◆ m_numPixels

int Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_numPixels
private

number of pixels along a single axis on the detector bank

Definition at line 82 of file SingleCrystalDiffractionTestHelper.h.

Referenced by createInstrument(), and setNumPixels().

◆ m_outputAsHistogram

bool Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_outputAsHistogram
private

whether to output event or histogram data

Definition at line 86 of file SingleCrystalDiffractionTestHelper.h.

Referenced by build(), and outputAsHistogram().

◆ m_peakDescriptors

std::vector<HKLPeakDescriptor> Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_peakDescriptors
private

List of peak descriptors for creating peaks.

Definition at line 69 of file SingleCrystalDiffractionTestHelper.h.

Referenced by addPeakByHKL(), and createPeaks().

◆ m_peaksWorkspace

Mantid::DataObjects::PeaksWorkspace_sptr Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_peaksWorkspace
private

Handle to the peaks workspace.

Definition at line 77 of file SingleCrystalDiffractionTestHelper.h.

Referenced by build(), createBackground(), createPeak(), and createPeaksWorkspace().

◆ m_rebinParams

std::vector<double> Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_rebinParams
private

rebin parameters

Definition at line 90 of file SingleCrystalDiffractionTestHelper.h.

Referenced by rebinWorkspace(), and setRebinParameters().

◆ m_totalNPixels

int Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_totalNPixels
private

total number of pixels in the detector bank

Definition at line 84 of file SingleCrystalDiffractionTestHelper.h.

Referenced by createEventWorkspace(), and setNumPixels().

◆ m_useBackground

bool Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_useBackground
private

whether to add a background

Definition at line 88 of file SingleCrystalDiffractionTestHelper.h.

Referenced by addBackground(), and createPeaks().

◆ m_workspace

Mantid::API::MatrixWorkspace_sptr Mantid::SingleCrystalDiffractionTestHelper::WorkspaceBuilder::m_workspace
private

Handle to the final output workspace (event OR histogram)

Definition at line 73 of file SingleCrystalDiffractionTestHelper.h.

Referenced by build(), createEventWorkspace(), and rebinWorkspace().


The documentation for this class was generated from the following files: