Mantid
Loading...
Searching...
No Matches
FindDetectorsInShape.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 +
15#include <Poco/DOM/DOMParser.h>
16#include <Poco/DOM/Document.h>
17#include <Poco/DOM/Element.h>
18
19namespace Mantid::DataHandling {
20// Register the algorithm into the algorithm factory
21DECLARE_ALGORITHM(FindDetectorsInShape)
22
23using namespace Kernel;
24using namespace API;
25using namespace Geometry;
26
29 "Name of the input workspace");
30 declareProperty("ShapeXML", "", std::make_shared<MandatoryValidator<std::string>>(),
31 "The XML definition of the shape");
32 declareProperty("IncludeMonitors", false,
33 "Whether monitors should be included if they are contained in the\n"
34 "shape (default false)");
35 declareProperty("DetectorList", std::vector<int>(), "The list of detector ids included within the shape",
37}
38
40 const MatrixWorkspace_const_sptr WS = getProperty("Workspace");
41 bool includeMonitors = getProperty("IncludeMonitors");
42 std::string shapeXML = getProperty("ShapeXML");
43
44 // convert into a Geometry object
46 auto shape_sptr = sFactory.createShape(shapeXML);
47
48 const auto &detectorInfo = WS->detectorInfo();
49 const auto &detIDs = detectorInfo.detectorIDs();
50
51 std::vector<int> foundDets;
52
53 // progress
54 detid2det_map::size_type objCmptCount = detectorInfo.size();
55 auto iprogress_step = static_cast<int>(objCmptCount / 100);
56 if (iprogress_step == 0)
57 iprogress_step = 1;
58 int iprogress = 0;
59
60 for (size_t i = 0; i < detectorInfo.size(); ++i) {
61 if ((includeMonitors) || (!detectorInfo.isMonitor(i))) {
62 // check if the centre of this item is within the user defined shape
63 if (shape_sptr->isValid(detectorInfo.position(i))) {
64 // shape encloses this objectComponent
65 g_log.debug() << "Detector contained in shape " << detIDs[i] << '\n';
66 foundDets.emplace_back(detIDs[i]);
67 }
68 }
69 iprogress++;
70 if (iprogress % iprogress_step == 0) {
71 progress(static_cast<double>(iprogress) / static_cast<double>(objCmptCount));
73 }
74 }
75 setProperty("DetectorList", foundDets);
76}
77
78} // namespace Mantid::DataHandling
#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
Kernel::Logger & g_log
Definition: Algorithm.h:451
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
Definition: Algorithm.cpp:1687
A property class for workspaces.
void init() override
Virtual method - must be overridden by concrete algorithm.
void exec() override
Virtual method - must be overridden by concrete algorithm.
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Definition: ShapeFactory.h:89
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
Validator to check that a property is not left empty.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54