13#include <boost/lexical_cast.hpp>
14#include <boost/pointer_cast.hpp>
43 "The detector vanadium workspace.");
46 "A monitor workspace associated with the detector vanadium workspace.");
49 "A detector vanadium workspace to compare against the primary one.");
52 "A monitor workspace associated with the comparison "
53 "detector vanadium workspace.");
56 "A sample workspace to run some diagnostics on.");
59 "A monitor workspace associated with the sample workspace.");
62 "A hard mask workspace to apply.");
64 "This is the resulting mask workspace.");
74 const std::string reductionManagerName = this->
getProperty(
"ReductionProperties");
75 std::shared_ptr<PropertyManager> reductionManager;
79 throw std::runtime_error(
"DgsDiagnose cannot run without a reduction PropertyManager.");
92 const bool checkBkg =
getBoolPropOrParam(
"BackgroundCheck", reductionManager,
"check_background", detVanWS);
93 const bool rejectZeroBkg =
getBoolPropOrParam(
"RejectZeroBackground", reductionManager,
"diag_samp_zero", detVanWS);
94 const bool createPsdBleed =
getBoolPropOrParam(
"PsdBleed", reductionManager,
"diag_bleed_test", detVanWS);
96 getBoolPropOrParam(
"MedianTestCorrectForSolidAngle", reductionManager,
"diag_correct_solid_angle", detVanWS);
99 const double huge =
getDblPropOrParam(
"HighCounts", reductionManager,
"diag_huge", detVanWS);
100 const double tiny =
getDblPropOrParam(
"LowCounts", reductionManager,
"diag_tiny", detVanWS);
101 const double vanOutHi =
getDblPropOrParam(
"HighOutlier", reductionManager,
"diag_van_out_hi", detVanWS);
102 const double vanOutLo =
getDblPropOrParam(
"LowOutlier", reductionManager,
"diag_van_out_lo", detVanWS);
103 const double vanHi =
getDblPropOrParam(
"MedianTestHigh", reductionManager,
"diag_van_hi", detVanWS);
104 const double vanLo =
getDblPropOrParam(
"MedianTestLow", reductionManager,
"diag_van_lo", detVanWS);
105 const double vanLevelsUp =
getDblPropOrParam(
"MedianTestLevelsUp", reductionManager,
"diag_van_levels", detVanWS, 0);
106 const double vanSigma =
getDblPropOrParam(
"ErrorBarCriterion", reductionManager,
"diag_van_sig", detVanWS);
107 const double variation =
getDblPropOrParam(
"DetVanRatioVariation", reductionManager,
"diag_variation", detVanWS);
108 const double samHi =
getDblPropOrParam(
"SamBkgMedianTestHigh", reductionManager,
"diag_samp_hi", detVanWS);
109 const double samLo =
getDblPropOrParam(
"SamBkgMedianTestLow", reductionManager,
"diag_samp_lo", detVanWS);
110 const double samSigma =
getDblPropOrParam(
"SamBkgErrorBarCriterion", reductionManager,
"diag_samp_sig", detVanWS);
111 double bleedRate =
getDblPropOrParam(
"MaxFramerate", reductionManager,
"diag_bleed_maxrate", detVanWS);
112 const double bleedPixels =
getDblPropOrParam(
"IgnoredPixels", reductionManager,
"diag_bleed_pixels", detVanWS, 80.0);
115 const std::string dvInternal =
"__det_van";
116 const std::string dvCompInternal =
"__det_van_comp";
117 const std::string sampleInternal =
"__sample";
118 const std::string bkgInternal =
"__background_int";
119 const std::string countsInternal =
"__total_counts";
124 bool isStandAlone = !reductionManager->existsProperty(
"IncidentEnergyGuess");
128 detVan->setProperty(
"InputWorkspace", detVanWS);
129 detVan->setProperty(
"OutputWorkspace", dvInternal);
130 detVan->setProperty(
"InputMonitorWorkspace", detVanMonWS);
131 detVan->setProperty(
"ReductionProperties", reductionManagerName);
132 detVan->executeAsChildAlg();
138 detVan->setProperty(
"InputWorkspace", detVanCompWS);
139 detVan->setProperty(
"OutputWorkspace", dvCompInternal);
140 detVan->setProperty(
"InputMonitorWorkspace", detVanCompMonWS);
141 detVan->executeAsChildAlg();
142 dvCompWS = detVan->getProperty(
"OutputWorkspace");
143 detVanCompWS.reset();
145 dvCompWS = std::shared_ptr<MatrixWorkspace>();
149 if (checkBkg || rejectZeroBkg || createPsdBleed) {
151 sampleMonWS = this->
getProperty(
"SampleMonitorWorkspace");
156 cloneWs->setProperty(
"InputWorkspace", sampleWS);
157 cloneWs->setProperty(
"OutputWorkspace", sampleInternal);
158 cloneWs->executeAsChildAlg();
159 tmp = cloneWs->getProperty(
"OutputWorkspace");
160 sampleWS = std::static_pointer_cast<MatrixWorkspace>(
tmp);
164 norm->setProperty(
"InputWorkspace", sampleWS);
165 norm->setProperty(
"OutputWorkspace", sampleWS);
166 norm->setProperty(
"InputMonitorWorkspace", sampleMonWS);
167 norm->setProperty(
"ReductionProperties", reductionManagerName);
168 norm->executeAsChildAlg();
169 sampleWS = norm->getProperty(
"OutputWorkspace");
176 integrate->setProperty(
"InputWorkspace", sampleWS);
177 integrate->setProperty(
"OutputWorkspace", countsInternal);
178 integrate->setProperty(
"IncludePartialBins",
true);
179 integrate->executeAsChildAlg();
180 totalCountsWS = integrate->getProperty(
"OutputWorkspace");
182 totalCountsWS = std::shared_ptr<MatrixWorkspace>();
188 double rangeStart =
getDblPropOrParam(
"BackgroundTofStart", reductionManager,
"bkgd-range-min", sampleWS);
190 double rangeEnd =
getDblPropOrParam(
"BackgroundTofEnd", reductionManager,
"bkgd-range-max", sampleWS);
193 integrate->setProperty(
"InputWorkspace", sampleWS);
194 integrate->setProperty(
"OutputWorkspace", bkgInternal);
195 integrate->setProperty(
"RangeLower", rangeStart);
196 integrate->setProperty(
"RangeUpper", rangeEnd);
197 integrate->setProperty(
"IncludePartialBins",
true);
198 integrate->executeAsChildAlg();
199 backgroundIntWS = integrate->getProperty(
"OutputWorkspace");
202 const std::string detVanIntRangeUnits = reductionManager->getProperty(
"DetVanIntRangeUnits");
204 cvu->setProperty(
"InputWorkspace", backgroundIntWS);
205 cvu->setProperty(
"OutputWorkspace", backgroundIntWS);
206 cvu->setProperty(
"Target", detVanIntRangeUnits);
207 cvu->executeAsChildAlg();
208 backgroundIntWS = cvu->getProperty(
"OutputWorkspace");
213 hmean /= (dvWS + dvCompWS);
214 backgroundIntWS /= hmean;
216 backgroundIntWS /= dvWS;
219 backgroundIntWS = std::shared_ptr<MatrixWorkspace>();
224 if (!createPsdBleed) {
225 sampleWS = std::shared_ptr<MatrixWorkspace>();
229 diag->setProperty(
"InputWorkspace", dvWS);
230 diag->setProperty(
"DetVanCompare", dvCompWS);
231 diag->setProperty(
"SampleWorkspace", sampleWS);
232 diag->setProperty(
"SampleTotalCountsWorkspace", totalCountsWS);
233 diag->setProperty(
"SampleBackgroundWorkspace", backgroundIntWS);
234 diag->setProperty(
"HardMaskWorkspace", hardMaskWS);
235 diag->setProperty(
"LowThreshold", tiny);
236 diag->setProperty(
"HighThreshold", huge);
237 diag->setProperty(
"LowOutlier", vanOutLo);
238 diag->setProperty(
"HighOutlier", vanOutHi);
239 diag->setProperty(
"LowThresholdFraction", vanLo);
240 diag->setProperty(
"HighThresholdFraction", vanHi);
241 diag->setProperty(
"LevelsUp",
static_cast<int>(vanLevelsUp));
242 diag->setProperty(
"CorrectForSolidAngle", vanSA);
243 diag->setProperty(
"SignificanceTest", vanSigma);
244 diag->setProperty(
"DetVanRatioVariation", variation);
245 diag->setProperty(
"SampleBkgLowAcceptanceFactor", samLo);
246 diag->setProperty(
"SampleBkgHighAcceptanceFactor", samHi);
247 diag->setProperty(
"SampleBkgSignificanceTest", samSigma);
248 diag->setProperty(
"MaxTubeFramerate", bleedRate);
249 diag->setProperty(
"NIgnoredCentralPixels",
static_cast<int>(bleedPixels));
252 std::vector<std::string> diag_spectra = dvWS->getInstrument()->getStringParameter(
"diag_spectra");
253 if (diag_spectra.empty() ||
"None" == diag_spectra[0]) {
255 maskWS = diag->getProperty(
"OutputWorkspace");
259 for (
auto tok_iter = tokens.
begin(); tok_iter != tokens.
end();) {
260 auto startIndex = boost::lexical_cast<int>(*tok_iter);
263 auto endIndex = boost::lexical_cast<int>(*tok_iter);
265 g_log.
information() <<
"Pixel range: (" << startIndex <<
", " << endIndex <<
")\n";
266 diag->setProperty(
"StartWorkspaceIndex", startIndex);
267 diag->setProperty(
"EndWorkspaceIndex", endIndex);
272 comb->setProperty(
"InputWorkspace1", maskWS);
273 comb->setProperty(
"InputWorkspace2",
tmp);
274 comb->setProperty(
"OutputWorkspace", maskWS);
275 comb->setProperty(
"OperationType",
"OR");
278 maskWS = diag->getProperty(
"OutputWorkspace");
288 totalCountsWS.reset();
289 backgroundIntWS.reset();
292 if (reductionManager->existsProperty(
"OutputMaskFile")) {
293 std::string maskFilename = reductionManager->getPropertyValue(
"OutputMaskFile");
294 if (!maskFilename.empty()) {
296 saveNxs->setProperty(
"InputWorkspace", maskWS);
297 saveNxs->setProperty(
"OutputFile", maskFilename);
303 g_log.
information() <<
"Number of masked pixels = " <<
m->getNumberMasked() <<
'\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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
A property class for workspaces.
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 information(const std::string &msg)
Logs at information level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Iterator begin()
Iterator referring to first element in the container.
@ TOK_IGNORE_EMPTY
ignore empty tokens
Iterator end()
Iterator referring to the past-the-end element in the container.
DgsDiagnose : This algorithm constructs all of the necessary workspaces for performing detector diagn...
const std::string category() const override
Algorithm's category for identification.
void init() override
Initialize the algorithm's properties.
int version() const override
Algorithm's version for identification.
void exec() override
Execute the algorithm.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
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
bool getBoolPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm, const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws, const bool overrideValue=false)
Function to get boolean property or instrument parameter value.
double getDblPropOrParam(const std::string &pmProp, Mantid::Kernel::PropertyManager_sptr &pm, const std::string &instParam, Mantid::API::MatrixWorkspace_sptr &ws, const double overrideValue=Mantid::EMPTY_DBL())
Function to get double property or instrument parameter value.
@ Input
An input workspace.
@ Output
An output workspace.