60#include <boost/format.hpp>
77 const double &min,
const double &max,
const int &nBins) {
78 std::string
id = dimension->getDimensionId();
79 return boost::str(boost::format(
"%s, %f, %f, %d") %
id % min % max % nBins);
84using namespace ConnectedComponentMappingTypes;
104 "Input md workspace.");
106 "A PeaksWorkspace containing the peaks to integrate.");
108 auto positiveIntValidator = std::make_shared<BoundedValidator<int>>();
109 positiveIntValidator->setExclusive(
true);
110 positiveIntValidator->setLower(0);
113 "Number of bins to use while creating each local image. "
114 "Defaults to 20. Increase to reduce pixelation");
116 auto compositeValidator = std::make_shared<CompositeValidator>();
117 auto positiveDoubleValidator = std::make_shared<BoundedValidator<double>>();
118 positiveDoubleValidator->setExclusive(
true);
119 positiveDoubleValidator->setLower(0);
120 compositeValidator->add(positiveDoubleValidator);
125 "Background outer radius estimate. Choose liberal value.");
128 "An output integrated peaks workspace.");
131 "MDHistoWorkspaces containing the labeled clusters used by "
136 return "Integrate single crystal peaks using connected component analysis. "
137 "Binning invididual to each peak.";
148 const double peakOuterRadius =
getProperty(
"BackgroundOuterRadius");
149 const double halfPeakOuterRadius = peakOuterRadius / 2;
150 if (peakWS != inPeakWS) {
151 peakWS = inPeakWS->clone();
156 if (mdCoordinates ==
None) {
157 throw std::invalid_argument(
"The coordinate system of the input "
158 "MDWorkspace cannot be established. Create "
159 "your workspace with the an MDFrame which is "
160 "not a General Frame or Unknown Frame.");
165 auto outImageResults = std::make_shared<WorkspaceGroup>();
170 for (
int i = 0; i < peakWS->getNumberPeaks(); ++i) {
177 binMDAlg->setProperty(
"InputWorkspace", mdWS);
178 binMDAlg->setPropertyValue(
"OutputWorkspace",
"output_ws");
179 binMDAlg->setProperty(
"AxisAligned",
true);
181 for (
int j = 0; j < static_cast<int>(mdWS->getNumDims()); ++j) {
182 std::stringstream propertyName;
183 propertyName <<
"AlignedDim" << j;
185 auto dimension = mdWS->getDimension(j);
187 double min = center[j] - halfPeakOuterRadius;
188 double max = center[j] + halfPeakOuterRadius;
190 binMDAlg->setPropertyValue(propertyName.str(),
191 extractFormattedPropertyFromDimension(dimension, min, max, numBins));
197 auto iterator = localImage->createIterator();
198 iterator->setNormalization(normalization);
201 cumulative += iterator->getSignal();
202 }
while (iterator->next());
203 const double threshold = cumulative /
signal_t(localImage->getNPoints());
207 const size_t startId = 1;
208 const size_t nThreads = 1;
218 outImageResults->addWorkspace(outHistoWS);
224 if (std::isnan(signalValue)) {
225 g_log.
warning() <<
"Warning: image for integration is off edge of detector for peak " << i <<
'\n';
228 <<
" Has no corresponding cluster/blob detected on "
229 "the image. This could be down to your Threshold "
232 const auto labelIdAtPeak =
static_cast<size_t>(signalValue);
233 ICluster *
const cluster = clusterMap[labelIdAtPeak].get();
235 peak.setIntensity(integratedValues.get<0>());
236 peak.setSigmaIntensity(std::sqrt(integratedValues.get<1>()));
#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.
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
A property class for workspaces.
ConnectedComponentLabelling : Implements connected component labeling on MDHistoWorkspaces.
size_t getStartLabelId() const
Getter for the start label id.
ConnectedComponentMappingTypes::ClusterTuple executeAndFetchClusters(Mantid::API::IMDHistoWorkspace_sptr ws, BackgroundStrategy *const strategy, Mantid::API::Progress &progress) const
Execute and return clusters, as well as maps to integratable clusters.
HardThresholdBackground : Implementation of BackgroundStrategy using a fixed background signal value ...
ICluster : Abstract cluster.
boost::tuple< double, double > ClusterIntegratedValues
virtual ClusterIntegratedValues integrate(std::shared_ptr< const Mantid::API::IMDHistoWorkspace > ws) const =0
integrate the cluster
IntegratePeaksHybrid : Integrate single crystal peaks algorithm.
const std::string summary() const override
function returns a summary message that will be displayed in the default GUI, and in the help.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
int version() const override
Algorithm's version for identification.
const std::string category() const override
Algorithm's category for identification.
PeakClusterProjection : Maps peaks onto IMDHistoWorkspaces and returns the signal value at the peak c...
Mantid::signal_t signalAtPeakCenter(const Mantid::Geometry::IPeak &peak, Mantid::API::MDNormalization normalization=Mantid::API::NoNormalization) const
Get the signal value at the peak center.
Mantid::Kernel::V3D peakCenter(const Mantid::Geometry::IPeak &peak) const
Get the peak center.
Structure describing a single-crystal peak.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
Validator to check that a property is not left empty.
The concrete, templated class for properties.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< IMDHistoWorkspace > IMDHistoWorkspace_sptr
shared pointer to Mantid::API::IMDHistoWorkspace
MDNormalization
Enum describing different ways to normalize the signal in a MDWorkspace.
@ NoNormalization
Don't normalize = return raw counts.
std::map< size_t, std::shared_ptr< Mantid::Crystal::ICluster > > ClusterMap
boost::tuple< Mantid::API::IMDHistoWorkspace_sptr, ClusterMap > ClusterTuple
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< const IMDDimension > IMDDimension_const_sptr
Shared Pointer to const IMDDimension.
SpecialCoordinateSystem
Special coordinate systems for Q3D.
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.
double signal_t
Typedef for the signal recorded in a MDBox, etc.
@ Input
An input workspace.
@ Output
An output workspace.