Mantid
Loading...
Searching...
No Matches
NormaliseToMonitor.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2008 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
10#include "MantidAlgorithms/DllConfig.h"
14
15namespace Mantid {
16namespace HistogramData {
17class BinEdges;
18class CountStandardDeviations;
19class Counts;
20} // namespace HistogramData
21} // namespace Mantid
22
23namespace Mantid {
24namespace Algorithms {
63class MANTID_ALGORITHMS_DLL NormaliseToMonitor final : public API::Algorithm {
64public:
66 const std::string name() const override { return "NormaliseToMonitor"; }
68 const std::string summary() const override {
69 return "Normalizes a 2D workspace by a specified spectrum, spectrum, "
70 "described by a monitor ID or spectrun provided in a separate "
71 "worskspace. ";
72 }
73
75 int version() const override { return 1; }
76 const std::vector<std::string> seeAlso() const override { return {"Divide"}; }
78 const std::string category() const override { return "CorrectionFunctions\\NormalisationCorrections"; }
79
80private:
81 // Overridden Algorithm methods
82 void init() override;
83 void exec() override;
84 std::map<std::string, std::string> validateInputs() override;
85
86protected: // for testing
87 void checkProperties(const API::MatrixWorkspace_sptr &inputWorkspace);
88 API::MatrixWorkspace_sptr getInWSMonitorSpectrum(const API::MatrixWorkspace_sptr &inputWorkspace);
89 size_t getInWSMonitorIndex(const API::MatrixWorkspace_sptr &inputWorkspace);
90 API::MatrixWorkspace_sptr getMonitorWorkspace(const API::MatrixWorkspace_sptr &inputWorkspace);
91 API::MatrixWorkspace_sptr extractMonitorSpectra(const API::MatrixWorkspace_sptr &ws,
92 const std::vector<size_t> &workspaceIndexes);
93 bool setIntegrationProps(const bool isSingleCountWorkspace);
94
95 void normaliseByIntegratedCount(const API::MatrixWorkspace_sptr &inputWorkspace,
96 API::MatrixWorkspace_sptr &outputWorkspace, const bool isSingleCountWorkspace);
97
98 void performHistogramDivision(const API::MatrixWorkspace_sptr &inputWorkspace,
99 API::MatrixWorkspace_sptr &outputWorkspace);
100
101 void normaliseBinByBin(const API::MatrixWorkspace_sptr &inputWorkspace, API::MatrixWorkspace_sptr &outputWorkspace);
102 void normalisationFactor(const HistogramData::BinEdges &X, HistogramData::Counts &Y,
103 HistogramData::CountStandardDeviations &E);
104
105private:
109 bool m_commonBins = false;
111 double m_integrationMin = EMPTY_DBL();
113 double m_integrationMax = EMPTY_DBL();
115 std::vector<size_t> m_workspaceIndexes;
116};
117
118// the internal class to verify and modify interconnected properties affecting
119// the different ways to normalize ws by this ws spectrum.
120class MANTID_ALGORITHMS_DLL MonIDPropChanger : public Kernel::IPropertySettings {
121
122public:
123 // properties this property depends on:
124 // "InputWorkspace","MonitorSpectrum","MonitorWorkspace"
125 MonIDPropChanger(const std::string &WSProperty, const std::string &SpectrToNormByProperty,
126 const std::string &MonitorWorkspace)
127 : hostWSname(WSProperty), SpectraNum(SpectrToNormByProperty), MonitorWorkspaceProp(MonitorWorkspace),
128 is_enabled(true) {}
129 // if input to this property is enabled
130 bool isEnabled(const Mantid::Kernel::IPropertyManager *algo) const override;
131 bool isConditionChanged(const Mantid::Kernel::IPropertyManager *algo,
132 const std::string &changedPropName = "") const override;
133 void applyChanges(const Mantid::Kernel::IPropertyManager *algo, Kernel::Property *const pProp) override;
134
135 // interface needs it but if indeed proper clone used -- do not know.
136 IPropertySettings *clone() const override {
137 return new MonIDPropChanger(hostWSname, SpectraNum, MonitorWorkspaceProp);
138 }
139
140private:
141 // the name of the property, which specifies the workspace which has to be
142 // modified
143 std::string hostWSname;
144 // the name of the property, which specifies the spectra num (from WS) to
145 // normalize by
146 std::string SpectraNum;
147 // the name of the property, which specifies if you want to allow normalizing
148 // by any spectra.
150
151 // the string with existing allowed monitors indexes
152 mutable std::vector<int> iExistingAllowedValues;
153 // if the monitors id input string is enabled.
154 mutable bool is_enabled;
155 // auxiliary function to obtain list of monitor's ID-s (allowed_values) from a
156 // workspace;
157 bool monitorIdReader(const API::MatrixWorkspace_const_sptr &inputWS) const;
158};
159
160} // namespace Algorithms
161} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
IPropertySettings * clone() const override
Make a copy of the present type of IPropertySettings.
MonIDPropChanger(const std::string &WSProperty, const std::string &SpectrToNormByProperty, const std::string &MonitorWorkspace)
Normalizes a 2D workspace by a specified monitor spectrum.
const std::string summary() const override
Summary of algorithms purpose.
int version() const override
Algorithm's version for identification overriding a virtual method.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
API::MatrixWorkspace_sptr m_monitor
A single spectrum workspace containing the monitor.
size_t getInWSMonitorIndex(const API::MatrixWorkspace_sptr &inputWorkspace)
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso algorithms related to this algorithm.
Interface to PropertyManager.
Interface for modifiers to Property's that specify if they should be enabled or visible in a GUI.
Base class for properties.
Definition: Property.h:94
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Helper class which provides the Collimation Length for SANS instruments.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43