Mantid
|
#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_sptr > | build () |
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< HKLPeakDescriptor > | m_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... | |
Definition at line 22 of file SingleCrystalDiffractionTestHelper.h.
|
private |
Definition at line 47 of file SingleCrystalDiffractionTestHelper.h.
|
inline |
Definition at line 25 of file SingleCrystalDiffractionTestHelper.h.
|
inline |
Definition at line 33 of file SingleCrystalDiffractionTestHelper.h.
References m_useBackground.
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.
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().
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.
Definition at line 71 of file SingleCrystalDiffractionTestHelper.cpp.
References createEventWorkspace(), createInstrument(), createNeighbourSearch(), createPeaks(), createPeaksWorkspace(), m_outputAsHistogram, m_peaksWorkspace, m_workspace, and rebinWorkspace().
|
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.
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().
|
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().
|
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().
|
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().
|
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.
descriptor | a 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().
|
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().
|
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().
|
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().
|
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().
|
inline |
Set the parameters for the uniform background.
Definition at line 35 of file SingleCrystalDiffractionTestHelper.h.
References m_backgroundParameters.
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.
|
inline |
Set the random seed for generating events.
Definition at line 39 of file SingleCrystalDiffractionTestHelper.h.
References m_generator.
|
inline |
Set the rebin parameters to use.
Definition at line 32 of file SingleCrystalDiffractionTestHelper.h.
References m_rebinParams.
|
private |
background parameters
Definition at line 92 of file SingleCrystalDiffractionTestHelper.h.
Referenced by createBackground(), and setBackgroundParameters().
|
private |
Nearest neighbour search tree for detectors.
Definition at line 67 of file SingleCrystalDiffractionTestHelper.h.
Referenced by createBackground(), createNeighbourSearch(), and createPeak().
|
private |
Handle to the event workspace.
Definition at line 75 of file SingleCrystalDiffractionTestHelper.h.
Referenced by createBackground(), createEventWorkspace(), createNeighbourSearch(), createPeak(), and rebinWorkspace().
|
private |
Random generator for making events.
Definition at line 97 of file SingleCrystalDiffractionTestHelper.h.
Referenced by createBackground(), createPeak(), and setRandomSeed().
|
private |
Handle to the instrument object.
Definition at line 71 of file SingleCrystalDiffractionTestHelper.h.
Referenced by createEventWorkspace(), createInstrument(), and createPeaksWorkspace().
|
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().
|
private |
whether to output event or histogram data
Definition at line 86 of file SingleCrystalDiffractionTestHelper.h.
Referenced by build(), and outputAsHistogram().
|
private |
List of peak descriptors for creating peaks.
Definition at line 69 of file SingleCrystalDiffractionTestHelper.h.
Referenced by addPeakByHKL(), and createPeaks().
|
private |
Handle to the peaks workspace.
Definition at line 77 of file SingleCrystalDiffractionTestHelper.h.
Referenced by build(), createBackground(), createPeak(), and createPeaksWorkspace().
|
private |
rebin parameters
Definition at line 90 of file SingleCrystalDiffractionTestHelper.h.
Referenced by rebinWorkspace(), and setRebinParameters().
|
private |
total number of pixels in the detector bank
Definition at line 84 of file SingleCrystalDiffractionTestHelper.h.
Referenced by createEventWorkspace(), and setNumPixels().
|
private |
whether to add a background
Definition at line 88 of file SingleCrystalDiffractionTestHelper.h.
Referenced by addBackground(), and createPeaks().
|
private |
Handle to the final output workspace (event OR histogram)
Definition at line 73 of file SingleCrystalDiffractionTestHelper.h.
Referenced by build(), createEventWorkspace(), and rebinWorkspace().