23using namespace Kernel;
25using namespace DataObjects;
31 "Name of the input workspace2D");
33 "Each histogram from the input workspace maps to a histogram in this\n"
34 "workspace with one value that indicates if there was a dead detector");
36 "Spectra whose total number of counts are equal to or above this value\n"
37 "will be marked bad (default off)");
39 "Spectra whose total number of counts are equal to or below this value\n"
40 "will be marked bad (default 0)");
41 auto mustBePosInt = std::make_shared<BoundedValidator<int>>();
42 mustBePosInt->setLower(0);
44 "The index number of the first spectrum to include in the calculation\n"
47 "The index number of the last spectrum to include in the calculation\n"
48 "(default the last histogram)");
50 "No bin with a boundary at an x value less than this will be used\n"
51 "in the summation that decides if a detector is 'bad' (default: the\n"
52 "start of each histogram)");
54 "No bin with a boundary at an x value higher than this value will\n"
55 "be used in the summation that decides if a detector is 'bad'\n"
56 "(default: the end of each histogram)");
68 double highThreshold =
getProperty(
"HighThreshold");
69 bool useHighThreshold = !
isEmpty(highThreshold);
70 if (useHighThreshold && highThreshold <= lowThreshold) {
71 throw std::invalid_argument(
"The high threshold must be higher than the low threshold");
77 const auto inputLength =
static_cast<int>(inputWS->getNumberHistograms());
79 maxIndex = inputLength - 1;
80 if (maxIndex < minIndex) {
81 std::ostringstream os;
82 os <<
"Invalid workspace indices. Min=" << minIndex <<
",Max=" << maxIndex;
83 throw std::invalid_argument(os.str());
86 if (minIndex > inputLength || maxIndex > inputLength) {
87 std::ostringstream os;
88 os <<
"Workspace indices must be lower than workspace size. Size=" << inputLength <<
", Min=" << minIndex
89 <<
",Max=" << maxIndex;
90 throw std::invalid_argument(os.str());
93 const double rangeLower =
getProperty(
"RangeLower");
94 const double rangeUpper =
getProperty(
"RangeUpper");
97 if (std::dynamic_pointer_cast<EventWorkspace>(countsWS))
98 throw std::runtime_error(
"Error! Integration output is not a Workspace2D.");
104 const double deadValue(1.0);
106 const int diagLength = maxIndex - minIndex;
107 const auto progStep =
static_cast<int>(std::ceil(diagLength / 100.0));
109 bool checkForMask =
false;
111 if (instrument !=
nullptr) {
112 checkForMask = ((instrument->getSource() !=
nullptr) && (instrument->getSample() !=
nullptr));
116 const auto &spectrumInfo = countsWS->spectrumInfo();
117#pragma omp parallel for if (countsWS->threadSafe() && outputWS->threadSafe()), reduction(+ : numFailed)
118 for (
int i = minIndex; i <= maxIndex; ++i) {
119 bool keepData =
true;
120 int countsInd = i - minIndex;
121 if (i % progStep == 0) {
122 progress(
static_cast<double>(countsInd) / diagLength);
126 if (checkForMask && spectrumInfo.hasDetectors(countsInd)) {
127 if (spectrumInfo.isMonitor(countsInd))
129 if (spectrumInfo.isMasked(countsInd))
133 const double &yValue = countsWS->y(countsInd)[0];
135 if (!std::isfinite(yValue)) {
138 if (yValue <= lowThreshold) {
142 if (useHighThreshold && (yValue >= highThreshold)) {
148 outputWS->mutableY(i)[0] = deadValue;
153 g_log.
information() << numFailed <<
" spectra fell outside the given limits.\n";
#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.
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...
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
A property class for workspaces.
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.
Takes a workspace as input and identifies all spectra where the sum of the counts in all bins is outs...
void exec() override
Overridden exec.
void init() override
Overridden init.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void information(const std::string &msg)
Logs at information level.
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.
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.