forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SingleCrystalDiffractionTestHelper.h
100 lines (87 loc) · 4.06 KB
/
SingleCrystalDiffractionTestHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidFrameworkTestHelpers/ComponentCreationHelper.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidKernel/NearestNeighbours.h"
#include <random>
#include <tuple>
namespace Mantid {
namespace SingleCrystalDiffractionTestHelper {
class WorkspaceBuilder {
public:
WorkspaceBuilder() : m_numPixels(0), m_totalNPixels(0), m_outputAsHistogram(false), m_generator(std::mt19937()()){};
/// Set the total number of peaks to use
void setNumPixels(const int numPixels);
/// Set whether to create an event workspace or a histogram workspace
void outputAsHistogram(const bool outputAsHistogram) { m_outputAsHistogram = outputAsHistogram; };
/// Set the rebin parameters to use
void setRebinParameters(const std::vector<double> &rebinParams) { m_rebinParams = rebinParams; }
void addBackground(const bool useBackground) { m_useBackground = useBackground; }
/// Set the parameters for the uniform background
void setBackgroundParameters(const int nEvents, const double detRange, const double tofRange) {
m_backgroundParameters = std::make_tuple(nEvents, detRange, tofRange);
}
/// Set the random seed for generating events
void setRandomSeed(const int seed) { m_generator.seed(seed); }
/// Add a HKL peak to the diffraction dataset
void addPeakByHKL(const Mantid::Kernel::V3D &hkl, const int numEvents,
const std::tuple<double, double, double> &sigmas);
/// Make a tuple of event workspace and peaks workspace
std::tuple<Mantid::API::MatrixWorkspace_sptr, Mantid::DataObjects::PeaksWorkspace_sptr> build();
private:
using HKLPeakDescriptor = std::tuple<Mantid::Kernel::V3D, int, std::tuple<double, double, double>>;
/// Create a dummy instrument
void createInstrument();
/// Create a peaks workspace with the request HKL peaks
void createPeaksWorkspace();
/// Create an empty event workspace with the instrument attached
void createEventWorkspace();
/// Create a neighbour search tree for finding nearest neighbours
void createNeighbourSearch();
/// Create peaks at the requested HKL positions
void createPeaks();
/// Create a single HKL peak in the event workspace
void createPeak(const HKLPeakDescriptor &descriptor);
/// Create a flat background for the workspace
void createBackground(const int peakIndex);
/// Rebin the event workspace to a histogram workspace
void rebinWorkspace();
/// Nearest neighbour search tree for detectors
std::unique_ptr<Mantid::Kernel::NearestNeighbours<3>> m_detectorSearcher;
/// List of peak descriptors for creating peaks
std::vector<HKLPeakDescriptor> m_peakDescriptors;
/// Handle to the instrument object
Mantid::Geometry::Instrument_sptr m_instrument;
/// Handle to the final output workspace (event OR histogram)
Mantid::API::MatrixWorkspace_sptr m_workspace;
/// Handle to the event workspace
Mantid::DataObjects::EventWorkspace_sptr m_eventWorkspace;
/// Handle to the peaks workspace
Mantid::DataObjects::PeaksWorkspace_sptr m_peaksWorkspace;
// Instance variables for builder settings
/// number of pixels along a single axis on the detector bank
int m_numPixels;
/// total number of pixels in the detector bank
int m_totalNPixels;
/// whether to output event or histogram data
bool m_outputAsHistogram;
/// whether to add a background
bool m_useBackground;
/// rebin parameters
std::vector<double> m_rebinParams;
/// background parameters
std::tuple<int, double, double> m_backgroundParameters;
// Other instance varianbles
/// Random generator for making events
std::mt19937 m_generator;
};
} // namespace SingleCrystalDiffractionTestHelper
} // namespace Mantid