Mantid
Loading...
Searching...
No Matches
MaskInstrument.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
13
14using namespace Mantid::Kernel;
15using namespace Mantid::API;
16
17namespace Mantid::Algorithms {
18
19// Register the algorithm into the AlgorithmFactory
20DECLARE_ALGORITHM(MaskInstrument)
21
22
25 useAlgorithm("MaskDetectors");
26 deprecatedDate("2020-07-16");
27}
28
30const std::string MaskInstrument::name() const { return "MaskInstrument"; }
31
33int MaskInstrument::version() const { return 1; }
34
36const std::string MaskInstrument::category() const { return "Transforms\\Masking"; }
37
39const std::string MaskInstrument::summary() const { return "Mask detectors in the instrument"; }
40
42 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "The input workspace", Direction::Input));
43 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
44 "Name of the output workspace (can be same as InputWorkspace)");
45 declareProperty(std::make_unique<ArrayProperty<detid_t>>("DetectorIDs"), "List of detector IDs to mask");
46}
47
49 MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
50 MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
51 if (outputWS != inputWS) {
52 outputWS = inputWS->clone();
53 setProperty("OutputWorkspace", outputWS);
54 }
55
56 const std::vector<detid_t> detectorIds = getProperty("DetectorIDs");
57 auto &detectorInfo = outputWS->mutableDetectorInfo();
58 for (const auto &id : detectorIds)
59 detectorInfo.setMasked(detectorInfo.indexOf(id), true);
60
61 const auto &spectrumInfo = outputWS->spectrumInfo();
62 for (size_t i = 0; i < spectrumInfo.size(); ++i) {
63 if (spectrumInfo.hasDetectors(i) && spectrumInfo.isMasked(i))
64 outputWS->getSpectrum(i).clearData();
65 }
66
67 if (auto event = dynamic_cast<DataObjects::EventWorkspace *>(outputWS.get()))
68 event->clearMRU();
69}
70
71} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A property class for workspaces.
Mask specified detectors in an instrument.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
const std::string name() const override
Algorithms name for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void init() override
Virtual method - must be overridden by concrete algorithm.
void exec() override
Virtual method - must be overridden by concrete algorithm.
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54