42 return "Creates MDEvent workspaces with polarization flipping ratio "
44 "The polarization might be angle dependent.";
53 "An input MDEventWorkspace.");
57 "Formula to define the flipping ratio. It can depend on the variables in "
59 "of sample logs defined below");
61 "Comma separated list of sample logs that can appear in the formula for "
64 "Output workspace 1. Equal to Input workspace multiplied by FR/(FR-1).");
66 "Output workspace 2. Equal to Input workspace multiplied by 1/(FR-1).");
73 std::map<std::string, std::string> errors;
75 const std::string message(
"The two output workspace names must be different");
76 errors.emplace(
"OutputWorkspace1", message);
77 errors.emplace(
"OutputWorkspace2", message);
88 std::string inputFormula =
getProperty(
"FlippingRatio");
89 std::vector<std::string> sampleLogStrings =
getProperty(
"SampleLogs");
91 std::vector<double> flippingRatio, C1, C2;
93 for (uint16_t i = 0; i < inWS->getNumExperimentInfo(); i++) {
94 const auto ¤tRun = inWS->getExperimentInfo(i)->run();
95 std::vector<double> sampleLogs(sampleLogStrings.size());
97 for (
size_t j = 0; j < sampleLogStrings.size(); j++) {
98 std::string s = sampleLogStrings[j];
101 muParser.DefineVar(s, &sampleLogs[j]);
103 muParser.DefineConst(
"pi", M_PI);
104 muParser.SetExpr(inputFormula);
106 flippingRatio.emplace_back(muParser.Eval());
107 }
catch (mu::Parser::exception_type &e) {
108 g_log.
error() <<
"Parsing error in experiment info " << i <<
"\n"
109 << e.GetMsg() << std::endl
110 <<
"Formula: " << inputFormula << std::endl;
111 throw std::runtime_error(
"Parsing error");
114 for (
const auto &fr : flippingRatio) {
115 C1.emplace_back(fr / (fr - 1.));
116 C2.emplace_back(1. / (fr - 1.));
121 cloneMD->setRethrows(
true);
122 cloneMD->setProperty(
"InputWorkspace", inWS);
123 cloneMD->setProperty(
"OutputWorkspace",
getPropertyValue(
"OutputWorkspace1"));
124 cloneMD->executeAsChildAlg();
125 outputWS1 = cloneMD->getProperty(
"OutputWorkspace");
127 cloneMD->setProperty(
"OutputWorkspace",
getPropertyValue(
"OutputWorkspace2"));
128 cloneMD->setChildStartProgress(0.25);
129 cloneMD->setChildEndProgress(0.5);
130 cloneMD->executeAsChildAlg();
131 outputWS2 = cloneMD->getProperty(
"OutputWorkspace");
139 throw std::runtime_error(
"Could not clone the workspace for first "
140 "correction (OutputWorkspace1)");
147 throw std::runtime_error(
"Could not clone the workspace for second "
148 "correction (OutputWorkspace2)");
152template <
typename MDE,
size_t nd>
156 std::vector<API::IMDNode *> boxes;
158 parentBox->
getBoxes(boxes, 1000,
true);
162 if (fileBackedTarget) {
165 for (
const auto &boxe : boxes) {
169 const bool hasEvents = !events.empty();
170 for (
auto &event : events) {
171 const auto ind =
static_cast<size_t>(
event.getExpInfoIndex());
172 const auto scalar =
static_cast<float>(
m_factor[ind]);
173 const auto scalarSquared =
static_cast<float>(
m_factor[ind] *
m_factor[ind]);
175 const float oldSignal =
event.getSignal();
176 const float signal = oldSignal * scalar;
177 const float errorSquared = scalarSquared *
event.getErrorSquared();
178 event.setSignal(signal);
179 event.setErrorSquared(errorSquared);
181 box->releaseEvents();
182 if (fileBackedTarget && hasEvents) {
#define DECLARE_ALGORITHM(classname)
#define CALL_MDEVENT_FUNCTION(funcname, workspace)
Macro that makes it possible to call a templated method for a MDEventWorkspace using a IMDEventWorksp...
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 setFileNeedsUpdating(bool value)
Sets the marker set to true when a file-backed workspace needs its back-end file updated (by calling ...
virtual void getBoxes(std::vector< IMDNode * > &boxes, size_t maxDepth, bool leafOnly)=0
Fill a vector with all the boxes who are the childred of this one up to a certain depth.
A property class for workspaces.
Templated super-class of a multi-dimensional event "box".
Templated class for a multi-dimensional event "box".
std::vector< MDE > & getEvents()
Get vector of events to change.
std::shared_ptr< MDEventWorkspace< MDE, nd > > sptr
Typedef for a shared pointer of this kind of event workspace.
MDBoxBase< MDE, nd > * getBox()
void refreshCache() override
Refresh the cache (integrated signal of each box)
Mantid::API::BoxController_sptr getBoxController() override
Returns the BoxController used in this workspace.
bool isFileBacked() const override
Support for a property that holds an array of values.
Buffer objects that need to be written out to disk so as to optimize writing operations.
void toWrite(ISaveable *item)
Call this method when an object is ready to be written out to disk.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
An interface for objects that can be cached or saved to disk.
void error(const std::string &msg)
Logs at error level.
Validator to check that a property is not left empty.
The concrete, templated class for properties.
FlippingRatioCorrectionMD : Algorithm to correct MDEvents for flipping ratio.
int version() const override
Algorithm's version for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
std::vector< double > m_factor
const std::string category() const override
Algorithm's category for identification.
std::map< std::string, std::string > validateInputs() override
Validate inputs.
void init() override
Initialize the algorithm's properties.
void executeTemplatedMDE(typename Mantid::DataObjects::MDEventWorkspace< MDE, nd >::sptr ws)
void exec() override
Execute the algorithm.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< IMDWorkspace > IMDWorkspace_sptr
Shared pointer to the IMDWorkspace base class.
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.