26using namespace Kernel;
28using namespace DataObjects;
38 "Name of the Sample workspace.");
40 "Name of the Vanadium workspace.");
42 "Name of the output workspace.");
55 const auto size =
static_cast<int>(inputWS1->x(0).size());
56 const auto nHist =
static_cast<int>(inputWS1->getNumberHistograms());
57 Progress prog(
this, 0.0, 1.0, nHist);
60 for (
int i = 0; i < nHist; i++)
64 outputWS->setSharedX(i, inputWS1->sharedX(i));
66 const auto &
X = inputWS1->x(i);
67 const auto &Y1 = inputWS1->y(i);
68 const auto &Y2 = inputWS2->y(i);
69 const auto &
E1 = inputWS1->e(i);
70 const auto &E2 = inputWS2->e(i);
71 auto &resultY = outputWS->mutableY(i);
72 auto &resultE = outputWS->mutableE(i);
77 std::adjacent_difference(
X.begin(),
X.end(),
79 std::transform(binwidths.begin() + 1, binwidths.end(), Y2.begin(), resultY.begin(),
81 std::transform(Y1.begin(), Y1.end(), resultY.begin(), resultY.begin(),
82 std::multiplies<double>());
86 for (
int j = 0; j < size - 1; j++) {
88 if (std::abs(Y1[j]) > 1e-7)
89 r += std::pow(
E1[j] / Y1[j], 2);
90 if (std::abs(Y2[j]) > 1e-7)
91 r += std::pow(E2[j] / Y2[j], 2);
93 if (errors[j] > DBL_MAX || errors[j] < -DBL_MAX)
98 double factor1 = std::accumulate(Y1.begin(), Y1.end(), 0.0);
99 double factor2 = std::accumulate(resultY.begin(), resultY.end(), 0.0);
100 double factor = factor1 / factor2;
103 double error2_factor1 = std::inner_product(
E1.begin(),
E1.end(),
E1.begin(), 0.0);
104 double error2_factor2 = 0;
106 for (
int j = 0; j < size - 1; j++) {
107 double test = std::abs(std::pow(resultY[j], 2));
110 error2_factor2 += errors[j] * test / factor2 / factor2;
112 double error2_factor = (error2_factor1 / factor1 / factor1 + error2_factor2);
115 using std::placeholders::_1;
124 std::transform(resultY.begin(), resultY.end(), resultY.begin(), [&factor](
double rY) { return rY * factor; });
127 for (
int j = 0; j < size - 1; j++)
128 resultE[j] = resultY[j] * sqrt(errors[j] + error2_factor);
138 outputWS->setYUnitLabel(
"Counts normalised to a vanadium");
139 outputWS->setDistribution(
false);
151 if (w1->getInstrument()->getName() != w2->getInstrument()->getName()) {
152 g_log.
error(
"The input workspaces have different instrument definitions");
153 throw std::runtime_error(
"The input workspaces have different instrument definitions");
156 if (w1->size() != w2->size()) {
157 g_log.
error(
"The input workspaces are not the same size");
158 throw std::runtime_error(
"The input workspaces are not the same size");
162 g_log.
error(
"The input workspaces have different binning");
163 throw std::runtime_error(
"The input workspaces have different binning");
167 if (!((*axis1) == (*axis2)))
170 g_log.
error(
"The two workspaces InputW1 and InputW2 have different spectra list");
171 throw std::runtime_error(
"The two workspaces InputW1 and InputW2 have different spectra list");
174 if (out != w1 && out != w2)
177 out = create<MatrixWorkspace>(*w1);
179 }
else if (out == w2) {
180 g_log.
warning(
"Any masking in the output workspaces will be taken from the "
181 "vanadium workspace (InputW2)");
193 static bool warned =
false;
195 const bool w1masked = w1->hasMaskedBins(
index);
196 const bool w2masked = w2->hasMaskedBins(
index);
197 if ((w1masked && w2masked && (w1->maskedBins(
index) != w2->maskedBins(
index))) || (w1masked && !w2masked) ||
198 (!w1masked && w2masked)) {
199 g_log.
warning(
"The input workspaces do not have matching bin masking");
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#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.
Base class from which all concrete algorithm classes should be derived.
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.
Class to represent the axis of a workspace.
Helper class for reporting progress from algorithms.
A property class for workspaces.
PointByPointVCorrection()
Default constructor.
void check_masks(const API::MatrixWorkspace_const_sptr &w1, const API::MatrixWorkspace_const_sptr &w2, const int &index) const
Checks whether the two input workspaces have the same bin masking.
void check_validity(API::MatrixWorkspace_const_sptr &w1, API::MatrixWorkspace_const_sptr &w2, API::MatrixWorkspace_sptr &out)
Checks that the axes of the input workspaces match and creates the output workspace if necessary.
void exec() override
Virtual method - must be overridden by concrete algorithm.
~PointByPointVCorrection() override
void init() override
Virtual method - must be overridden by concrete algorithm.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
std::complex< double > MANTID_API_DLL E1(std::complex< double > z)
Integral for Gamma.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
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.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
static bool matchingBins(const MatrixWorkspace &ws1, const MatrixWorkspace &ws2, const bool firstOnly=false)
Checks whether the bins (X values) of two workspace are the same.
@ Input
An input workspace.
@ Output
An output workspace.
Divide functor with result reset to 0 if the denominator is null.