23using namespace Kernel;
25using namespace Geometry;
26using namespace HistogramData;
27using namespace DataObjects;
31const std::string INPUT_WKSP(
"InputWorkspace");
32const std::string OUTPUT_WKSP(
"OutputWorkspace");
33const std::string TRANSMISSION_WKSP(
"TransmissionWorkspace");
34const std::string TRANSMISSION_VALUE(
"TransmissionValue");
35const std::string TRANSMISSION_ERROR(
"TransmissionError");
41 "Workspace to apply the transmission correction to");
44 "Workspace containing the transmission values [optional]");
46 "Workspace to store the corrected data in");
51 "Transmission value to apply to all wavelengths. If specified, "
52 "TransmissionWorkspace will not be used.");
53 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
54 mustBePositive->setLower(0.0);
56 "The error on the transmission value (default 0.0)");
58 declareProperty(
"ThetaDependent",
true,
"If true, a theta-dependent transmission correction will be applied.");
62 std::map<std::string, std::string> result;
65 const double trans_value =
getProperty(PropertyNames::TRANSMISSION_VALUE);
69 const std::string msg(
"Must specify \"TransmissionValue\" or \"TransmissionWorkspace\"");
70 result[PropertyNames::TRANSMISSION_VALUE] = msg;
71 result[PropertyNames::TRANSMISSION_WKSP] = msg;
74 if ((transWS->getNumberHistograms() > 1) && (transWS->getNumberHistograms() != inputWS->getNumberHistograms())) {
75 const std::string msg(
"Input and transmission workspaces have "
76 "incompatible number of spectra");
77 result[PropertyNames::INPUT_WKSP] = msg;
78 result[PropertyNames::TRANSMISSION_WKSP] = msg;
79 }
else if (transWS->y(0).size() != inputWS->y(0).size()) {
80 const std::string msg(
"Input and transmission workspaces have a "
81 "different number of wavelength bins");
82 result[PropertyNames::INPUT_WKSP] = msg;
83 result[PropertyNames::TRANSMISSION_WKSP] = msg;
92 const bool thetaDependent =
getProperty(
"ThetaDependent");
93 const double trans_value =
getProperty(PropertyNames::TRANSMISSION_VALUE);
94 const double trans_error =
getProperty(PropertyNames::TRANSMISSION_ERROR);
103 HistogramY TrIn(inputWS->y(0).size(), trans_value);
104 HistogramE ETrIn(inputWS->y(0).size(), trans_error);
108 TrIn = transWS->y(0);
109 ETrIn = transWS->e(0);
112 const auto numHists =
static_cast<int>(inputWS->getNumberHistograms());
119 const auto &spectrumInfo = inputWS->spectrumInfo();
123 for (
int i = 0; i < numHists; i++) {
126 if (!spectrumInfo.hasDetectors(i)) {
127 g_log.
warning() <<
"Workspace index " << i <<
" has no detector assigned to it - discarding'\n";
132 corrWS->setSharedX(i, inputWS->sharedX(i));
135 if (spectrumInfo.isMonitor(i) || spectrumInfo.isMasked(i))
139 auto &correctionY = corrWS->mutableY(i);
140 auto &correctionE = corrWS->mutableE(i);
142 const double exp_term = 0.5 / cos(spectrumInfo.twoTheta(i)) + 0.5;
143 for (
int j = 0; j < static_cast<int>(inputWS->y(0).size()); j++) {
144 correctionY[j] = pow(TrIn[j], -1. * exp_term);
145 correctionE[j] = std::fabs(ETrIn[j] * exp_term / pow(TrIn[j], exp_term + 1.0));
148 progress.report(
"Calculating transmission correction");
160 divideAlg->setProperty(
"LHSWorkspace",
getPropertyValue(PropertyNames::INPUT_WKSP));
162 divideAlg->setProperty(
"RHSWorkspace",
getPropertyValue(PropertyNames::TRANSMISSION_WKSP));
167 createSingleAlg->setProperty(
"DataValue", trans_value);
168 createSingleAlg->setProperty(
"ErrorValue", trans_error);
169 createSingleAlg->executeAsChildAlg();
172 divideAlg->setProperty(
"RHSWorkspace", singleWS);
174 divideAlg->setProperty(
"OutputWorkspace",
getPropertyValue(PropertyNames::OUTPUT_WKSP));
175 divideAlg->executeAsChildAlg();
#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.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
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.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
Helper class for reporting progress from algorithms.
A property class for workspaces.
void exec() override
Execution code.
void init() override
Initialisation code.
std::map< std::string, std::string > validateInputs() override
Cross check inputs.
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.
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.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.