34 return "Calculate normalization for an MDEvent workspace for single crystal "
35 "direct geometry inelastic measurement.";
46 "An input MDWorkspace.");
51 for (
size_t i = 0; i < dimChars.size(); i++) {
54 std::string propName =
"AlignedDim" + dim;
58 "Enter it as a comma-separated list of values with the format: "
59 "'name,minimum,maximum,number_of_bins'. Leave blank for NONE.");
62 auto solidAngleValidator = std::make_shared<CompositeValidator>();
66 m_progress = std::make_unique<API::Progress>(
this, 0, 1, 1);
70 "An input workspace containing integrated vanadium (a measure of the "
74 "If set to true, the algorithm does "
75 "not check history if the workspace was modified since the"
76 "ConvertToMD algorithm was run, and assume that the direct "
77 "geometry inelastic mode is used.");
81 "An input MDHistoWorkspace used to accumulate normalization "
82 "from multiple MDEventWorkspaces. If unspecified a blank "
83 "MDHistoWorkspace will be created.");
87 "An input MDHistoWorkspace used to accumulate data from "
88 "multiple MDEventWorkspaces. If unspecified a blank "
89 "MDHistoWorkspace will be created.");
92 "A name for the output data MDHistoWorkspace.");
94 "A name for the output normalization MDHistoWorkspace.");
104 m_convention = Kernel::ConfigService::Instance().getString(
"Q.convention");
106 setProperty<Workspace_sptr>(
"OutputWorkspace", outputWS);
116 for (uint16_t expInfoIndex = 0; expInfoIndex <
m_numExptInfos; expInfoIndex++) {
117 const auto ¤tExptInfo = *(
m_inputWS->getExperimentInfo(expInfoIndex));
118 if (!currentExptInfo.run().hasProperty(
"RUBW_MATRIX")) {
119 throw std::runtime_error(
"Wokspace does not contain a log entry for the RUBW matrix."
124 bool skipNormalization =
false;
129 if (!skipNormalization) {
130 if (currentExptInfo.run().hasProperty(
"useLogTimes")) {
136 g_log.
warning(
"Binning limits are outside the limits of the MDWorkspace. "
137 "Not applying normalization.");
144 [](
const std::atomic<signal_t> &a,
const signal_t &b) { return a + b; });
150 outputWS->setDisplayNormalization(
m_inputWS->displayNormalizationHisto());
160 throw std::invalid_argument(
"Invalid energy transfer mode. Algorithm only "
161 "supports direct geometry spectrometers.");
166 m_hmin = hdim->getMinimum();
167 m_kmin = kdim->getMinimum();
168 m_lmin = ldim->getMinimum();
170 m_hmax = hdim->getMaximum();
171 m_kmax = kdim->getMaximum();
172 m_lmax = ldim->getMaximum();
175 const auto &exptInfoZero = *(
m_inputWS->getExperimentInfo(0));
176 auto source = exptInfoZero.getInstrument()->getSource();
177 auto sample = exptInfoZero.getInstrument()->getSample();
178 if (source ==
nullptr || sample ==
nullptr) {
180 "Instrument not sufficiently defined: failed to get source and/or "
186 double originaldEmin = exptInfoZero.run().getBinBoundaries().front();
187 double originaldEmax = exptInfoZero.run().getBinBoundaries().back();
188 if (exptInfoZero.run().hasProperty(
"Ei")) {
189 m_Ei = exptInfoZero.run().getPropertyValueAsType<
double>(
"Ei");
191 throw std::invalid_argument(
"Ei stored in the workspace is not positive");
194 throw std::invalid_argument(
"Could not find Ei value in the workspace.");
197 if (
m_Ei - originaldEmin < eps) {
198 originaldEmin =
m_Ei - eps;
200 if (
m_Ei - originaldEmax < eps) {
201 originaldEmax =
m_Ei - 1e-7;
203 if (originaldEmin == originaldEmax) {
204 throw std::runtime_error(
"The limits of the original workspace used in "
205 "ConvertToMD are incorrect");
210 m_kfmin = std::sqrt(energyToK * (
m_Ei - originaldEmin));
211 m_kfmax = std::sqrt(energyToK * (
m_Ei - originaldEmax));
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A validator which provides a TENTATIVE check that a workspace contains common bins in each spectrum.
A validator which checks that a workspace has a valid instrument.
A property class for workspaces.
Exception for errors associated with the instrument definition.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void warning(const std::string &msg)
Logs at warning level.
The concrete, templated class for properties.
API::IMDEventWorkspace_sptr m_inputWS
Input workspace.
void createNormalizationWS(const DataObjects::MDHistoWorkspace &dataWS)
Create & cached the normalization workspace.
bool m_diffraction
Flag indicating if the input workspace is from diffraction.
static std::string getDimensionChars()
void cacheDimensionXValues()
Stores the X values from each H,K,L,E dimension as member variables Energy dimension is transformed t...
void findIntegratedDimensions(const std::vector< coord_t > &otherDimValues, bool &skipNormalization)
Checks the normalization workspace against the indices of the original dimensions.
void calculateNormalization(const std::vector< coord_t > &otherValues, uint16_t expInfoIndex)
Computed the normalization for the input workspace (for MDNormSCD/MDNormDirectSC).
DataObjects::MDHistoWorkspace_sptr m_normWS
Normalization workspace.
Kernel::V3D m_samplePos
Sample position.
std::vector< coord_t > getValuesFromOtherDimensions(bool &skipNormalization, uint16_t expInfoIndex=0) const
Retrieve logged values from non-HKL dimensions.
std::vector< std::atomic< signal_t > > m_signalArray
internal array to accumulate signals to avoid copying (serial) each loop
bool m_accumulate
Flag to accumulate normalization.
DataObjects::MDHistoWorkspace_sptr binInputWS()
Runs the BinMD algorithm on the input to provide the output workspace All slicing algorithm propertie...
uint16_t m_numExptInfos
number of experiment infos
Kernel::V3D m_beamDir
Beam direction.
coord_t m_hmin
limits for h,k,l, dE dimensions
std::unique_ptr< API::Progress > m_progress
Progress bar.
void calculateNormContinuous(const std::vector< coord_t > &otherValues, uint16_t expInfoIndex, const Geometry::SymmetryOperation *so=nullptr)
Computes the normalization for the input workspace for the case of a continous rotation.
std::string inputEnergyMode() const
Currently looks for the ConvertToMD algorithm in the history.
std::string m_convention
ki-kf for Inelastic convention; kf-ki for Crystallography convention
double m_Ei
cached values for incident energy and momentum, final momentum min/max
MDNormDirectSC : Generate MD normalization for single crystal direct geometry inelastic.
const std::string name() const override
Algorithm's name for use in the GUI and help.
void cacheInputs()
Set up starting values for cached variables.
void init() override
Initialize the algorithm's properties.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
@ NoNormalization
Don't normalize = return raw counts.
std::string toString(const T &value)
Convert a number to a string.
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double h
Planck constant in J*s.
static constexpr double meV
1 meV in Joules.
double signal_t
Typedef for the signal recorded in a MDBox, etc.
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.