19using namespace Kernel;
26 auto val = std::make_shared<HistogramValidator>();
28 "Name of a white beam vanadium workspace");
32 "Name of a matching second white beam vanadium run from the same "
35 "A MaskWorkpace where each spectra that failed the test is "
36 "masked. Each histogram from the input workspace maps to a "
37 "histogram in this workspace with one value that indicates "
38 "if there was a dead detector.");
39 auto moreThanZero = std::make_shared<BoundedValidator<double>>();
40 moreThanZero->setLower(0.0);
42 "Identify histograms whose total number of counts has "
43 "changed by more than this factor of the median change "
44 "between the two input workspaces.");
45 auto mustBePosInt = std::make_shared<BoundedValidator<int>>();
46 mustBePosInt->setLower(0);
48 "The index number of the first spectrum to include in the "
49 "calculation (default: 0)");
54 "The index number of the last spectrum to include in the "
55 "calculation (default: the last spectrum in the workspace)");
57 "No bin with a boundary at an x value less than this will be included "
58 "in the summation used to decide if a detector is 'bad' (default: the "
59 "start of each histogram)");
61 "No bin with a boundary at an x value higher than this value will "
62 "be included in the summation used to decide if a detector is 'bad' "
63 "(default: the end of each histogram)");
81 const double rangeLower =
getProperty(
"RangeLower");
82 const double rangeUpper =
getProperty(
"RangeUpper");
90 countRatio = counts1 / counts2;
91 }
catch (std::invalid_argument &) {
92 g_log.
error() <<
"The two white beam workspaces size must match.";
96 g_log.
notice() <<
name() <<
": The median of the ratio of the integrated counts is: " << average <<
'\n';
100 g_log.
notice() <<
"Tests failed " << numFailed <<
" spectra. "
101 <<
"These have been masked on the OutputWorkspace\n";
121 int &startWsIndex,
int &endWsIndex) {
124 if (whiteBeam1->getInstrument()->getName() != whiteBeam2->getInstrument()->getName()) {
125 throw std::invalid_argument(
"The two input white beam vanadium workspaces "
126 "must be from the same instrument");
128 int maxWsIndex =
static_cast<int>(whiteBeam1->getNumberHistograms()) - 1;
130 static_cast<int>(whiteBeam2->getNumberHistograms()) - 1) {
131 throw std::invalid_argument(
"The input white beam vanadium workspaces must "
132 "be have the same number of histograms");
138 if ((startWsIndex < 0) || (startWsIndex > maxWsIndex)) {
139 g_log.
warning(
"StartWorkspaceIndex out of range, changed to 0");
144 endWsIndex = maxWsIndex;
145 if ((endWsIndex < 0) || (endWsIndex > maxWsIndex)) {
146 g_log.
warning(
"EndWorkspaceIndex out of range, changed to max Workspace number");
147 endWsIndex = maxWsIndex;
149 if ((endWsIndex < startWsIndex)) {
150 g_log.
warning(
"EndWorkspaceIndex can not be less than the StartWorkspaceIndex, "
151 "changed to max Workspace number");
152 endWsIndex = maxWsIndex;
175 variation = 1.0 / variation;
178 double largest = average * variation;
180 double lowest = average / variation;
182 const auto numSpec =
static_cast<int>(counts1->getNumberHistograms());
183 const auto progStep =
static_cast<int>(std::ceil(numSpec / 30.0));
188 bool checkForMask =
false;
190 if (instrument !=
nullptr) {
191 checkForMask = ((instrument->getSource() !=
nullptr) && (instrument->getSample() !=
nullptr));
194 const double deadValue(1.0);
196 const auto &spectrumInfo = counts1->spectrumInfo();
198 for (
int i = 0; i < numSpec; ++i) {
201 if (i % progStep == 0) {
208 if (spectrumInfo.isMonitor(i))
210 if (spectrumInfo.isMasked(i)) {
212 maskWS->mutableY(i)[0] = deadValue;
217 const double signal1 = counts1->y(i)[0];
218 const double signal2 = counts2->y(i)[0];
221 if (!std::isfinite(signal1) || !std::isfinite(signal2)) {
222 maskWS->mutableY(i)[0] = deadValue;
229 const double ratio = signal1 / signal2;
230 if (ratio < lowest || ratio > largest) {
231 maskWS->mutableY(i)[0] = deadValue;
#define DECLARE_ALGORITHM(classname)
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
A property class for workspaces.
std::vector< double > calculateMedian(const API::MatrixWorkspace &input, bool excludeZeroes, const std::vector< std::vector< size_t > > &indexmap)
Calculate the median of the given workspace.
std::vector< std::vector< size_t > > makeInstrumentMap(const API::MatrixWorkspace &countsWS)
method to create the map with all spectra
double m_fracDone
An estimate of the percentage of the algorithm runtimes that has been completed.
@ RTMarkDetects
Time taken to find failing detectors.
API::MatrixWorkspace_sptr integrateSpectra(const API::MatrixWorkspace_sptr &inputWS, const int indexMin, const int indexMax, const double lower, const double upper, const bool outputWorkspace2D=false)
Get the total counts for each spectra.
DataObjects::MaskWorkspace_sptr generateEmptyMask(const API::MatrixWorkspace_const_sptr &inputWS)
Create a masking workspace to return.
double advanceProgress(double toAdd)
Update the fraction complete estimate assuming that the algorithm has completed a task with estimated...
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
void retrieveProperties(API::MatrixWorkspace_sptr &whiteBeam1, API::MatrixWorkspace_sptr &whiteBeam2, double &variation, int &minSpec, int &maxSpec)
Loads and checks the values passed to the algorithm.
int doDetectorTests(const API::MatrixWorkspace_const_sptr &counts1, const API::MatrixWorkspace_const_sptr &counts2, const double average, double variation)
Apply the detector test criterion.
void init() override
Initialize the algorithm.
void exec() override
Executes the algorithm that includes calls to SolidAngle and Integration.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
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
std::shared_ptr< MaskWorkspace > MaskWorkspace_sptr
shared pointer to the MaskWorkspace class
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.