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"
15
16namespace Mantid {
17namespace HistogramData {
18class BinEdges;
19class CountStandardDeviations;
20class Counts;
21} // namespace HistogramData
22} // namespace Mantid
23
24namespace Mantid {
25namespace Algorithms {
64class MANTID_ALGORITHMS_DLL NormaliseToMonitor final : public API::Algorithm {
65public:
67 const std::string name() const override { return "NormaliseToMonitor"; }
69 const std::string summary() const override {
70 return "Normalizes a 2D workspace by a specified spectrum, spectrum, "
71 "described by a monitor ID or spectrun provided in a separate "
72 "worskspace. ";
73 }
74
76 int version() const override { return 1; }
77 const std::vector<std::string> seeAlso() const override { return {"Divide"}; }
79 const std::string category() const override { return "CorrectionFunctions\\NormalisationCorrections"; }
80
81private:
82 // Overridden Algorithm methods
83 void init() override;
84 void exec() override;
85 std::map<std::string, std::string> validateInputs() override;
86
87protected: // for testing
88 void checkProperties(const API::MatrixWorkspace_sptr &inputWorkspace);
89 API::MatrixWorkspace_sptr getInWSMonitorSpectrum(const API::MatrixWorkspace_sptr &inputWorkspace);
90 size_t getInWSMonitorIndex(const API::MatrixWorkspace_sptr &inputWorkspace);
91 API::MatrixWorkspace_sptr getMonitorWorkspace(const API::MatrixWorkspace_sptr &inputWorkspace);
92 API::MatrixWorkspace_sptr extractMonitorSpectra(const API::MatrixWorkspace_sptr &ws,
93 const std::vector<size_t> &workspaceIndexes);
94 bool setIntegrationProps(const bool isSingleCountWorkspace);
95
96 void normaliseByIntegratedCount(const API::MatrixWorkspace_sptr &inputWorkspace,
97 API::MatrixWorkspace_sptr &outputWorkspace, const bool isSingleCountWorkspace);
98
99 void performHistogramDivision(const API::MatrixWorkspace_sptr &inputWorkspace,
100 API::MatrixWorkspace_sptr &outputWorkspace);
101
102 void normaliseBinByBin(const API::MatrixWorkspace_sptr &inputWorkspace, API::MatrixWorkspace_sptr &outputWorkspace);
103 void normalisationFactor(const HistogramData::BinEdges &X, HistogramData::Counts &Y,
104 HistogramData::CountStandardDeviations &E);
105
106private:
110 bool m_commonBins = false;
112 double m_integrationMin = EMPTY_DBL();
114 double m_integrationMax = EMPTY_DBL();
115 bool m_scanInput = false;
116 std::vector<size_t> m_workspaceIndexes;
117};
118
119// the internal class to verify and modify interconnected properties affecting
120// the different ways to normalize ws by this ws spectrum.
121class MANTID_ALGORITHMS_DLL MonIDPropChanger : public Kernel::IPropertySettings {
122
123public:
124 // properties this property depends on:
125 // "InputWorkspace","MonitorSpectrum","MonitorWorkspace"
126 MonIDPropChanger(const std::string &WSProperty, const std::string &SpectrToNormByProperty,
127 const std::string &MonitorWorkspace)
128 : hostWSname(WSProperty), SpectraNum(SpectrToNormByProperty), MonitorWorkspaceProp(MonitorWorkspace),
129 is_enabled(true) {}
130 // if input to this property is enabled
131 bool isEnabled(const Mantid::Kernel::IPropertyManager *algo) const override;
132 bool isConditionChanged(const Mantid::Kernel::IPropertyManager *algo,
133 const std::string &changedPropName = "") const override;
134 bool applyChanges(const Mantid::Kernel::IPropertyManager *algo, const std::string &propName) override;
135
136 // interface needs it but if indeed proper clone used -- do not know.
137 IPropertySettings *clone() const override {
138 return new MonIDPropChanger(hostWSname, SpectraNum, MonitorWorkspaceProp);
139 }
140
141private:
142 // the name of the property, which specifies the workspace which has to be
143 // modified
144 std::string hostWSname;
145 // the name of the property, which specifies the spectra num (from WS) to
146 // normalize by
147 std::string SpectraNum;
148 // the name of the property, which specifies if you want to allow normalizing
149 // by any spectra.
151
152 // the string with existing allowed monitors indexes
153 mutable std::vector<int> iExistingAllowedValues;
154 // if the monitors id input string is enabled.
155 mutable bool is_enabled;
156 // auxiliary function to obtain list of monitor's ID-s (allowed_values) from a
157 // workspace;
158 bool monitorIdReader(const API::MatrixWorkspace_const_sptr &inputWS) const;
159};
160
161} // namespace Algorithms
162} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
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.
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:42