43 return "Apply polarization angle correction to MDEventWorkspace";
57 "An input MDEventWorkspace. Must be in Q_sample/Q_lab frame. Must have an axis as DeltaE");
59 auto anglerange = std::make_shared<BoundedValidator<double>>();
60 anglerange->setLower(-180.);
61 anglerange->setUpper(180.);
63 "An in-plane polarization angle, between -180 and 180 degrees");
65 auto precisionrange = std::make_shared<BoundedValidator<double>>();
66 precisionrange->setLower(0.);
67 precisionrange->setUpper(1.);
69 "Precision", 1., precisionrange,
70 "Precision (between 0 and 1). Any event whose absolute value of cosine of 2 of its schaf angle less than this "
71 "precision will be ignored.");
75 "The output MDEventWorkspace with polarization angle correction applied");
93 if (input_ws->getName() == output_ws_name) {
98 output_ws = input_ws->clone();
105 output_ws->refreshCache();
108 output_ws->clearMDMasking();
126 std::map<std::string, std::string> output;
130 if (dim_error !=
"") {
131 output[
"InputWorkspace"] = dim_error;
141template <
typename MDE,
size_t nd>
146 std::vector<API::IMDNode *> boxes;
148 auto numBoxes = int(boxes.size());
154 for (
int i = 0; i < numBoxes; ++i) {
158 if (!box->getIsMasked()) {
160 std::vector<MDE> &events = box->getEvents();
162 for (
auto it = events.begin(); it != events.end(); ++it) {
166 double qx(0.), qz(0.);
169 qx =
static_cast<double>(it->getCenter(
mQxIndex));
170 qz =
static_cast<double>(it->getCenter(
mQzIndex));
174 std::vector<double> qsample;
175 for (
auto d = 0u;
d < nd; ++
d) {
176 qsample.emplace_back(it->getCenter(
d));
182 double gamma(std::atan2(qx, qz));
187 double cosine2alpha = std::cos(2 * alpha);
191 factor =
static_cast<float>(1. / cosine2alpha);
195 auto intensity = it->getSignal() * factor;
196 it->setSignal(intensity);
199 auto error2 = it->getErrorSquared() * factor * factor;
201 it->setErrorSquared(error2);
204 box->releaseEvents();
221 std::string errormsg(
"");
225 size_t numdims = inputws->getNumDims();
226 std::string qxname(
"Q_lab_x");
227 std::string qzname(
"Q_lab_z");
229 errormsg =
"Input workspace must have at least 4 dimensions";
239 qxname =
"Q_sample_x";
240 qzname =
"Q_sample_z";
243 errormsg =
"InputWorkspace is not in Q-Sample or Q-lab frame";
247 for (
size_t i = 0; i < numdims; ++i) {
248 if (inputws->getDimension(i)->getName() == qxname)
250 else if (inputws->getDimension(i)->getName() == qzname)
255 throw std::runtime_error(
"Qx, Qy and Qz are not in (Qx, Qy, Qz) order");
260 if (errormsg.size() > 0 && inputws->getDimension(3)->getName() !=
"DeltaE") {
261 errormsg =
"4-th dimension is " + inputws->getDimension(3)->getName() +
". Must be DeltaE";
267 auto numexpinfo = inputws->getNumExperimentInfo();
268 for (uint16_t i = 0; i < numexpinfo; ++i) {
284 std::string Estring(
"Ei");
285 std::stringstream eiss;
288 uint16_t numexpinfo = mdws->getNumExperimentInfo();
290 for (uint16_t i = 0; i < numexpinfo; ++i) {
294 if (expinfo->run().hasProperty(Estring)) {
295 std::string eistr = expinfo->run().getProperty(Estring)->value();
297 double ei = boost::lexical_cast<double>(eistr);
300 eiss <<
"Experiment Info Ei " << ei <<
" cannot be zero or less than zero.";
304 eiss <<
"Experiment Info Ei " << eistr <<
" cannot be cast to a double number";
308 eiss <<
"Experiment Info " << i <<
" does not have " << Estring;
313 std::string ei_error = eiss.str();
#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...
#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 PRAGMA_OMP(expression)
#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 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::shared_ptr< MDEventWorkspace< MDE, nd > > sptr
Typedef for a shared pointer of this kind of event workspace.
MDBoxBase< MDE, nd > * getBox()
bool isFileBacked() const override
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void information(const std::string &msg)
Logs at information level.
PolarizationAngleCorrection : Perform polarization angle correction to an MDEventWorkspace.
size_t mQxIndex
Qx and Qz indexes.
std::string checkEi(const API::IMDEventWorkspace_sptr &mdws)
Get Ei.
void exec() override
Run the algorithm.
double mPolarizationAngle
Polarization angle.
double mPrecision
Precision.
const std::string summary() const override
Summary.
std::string checkInputMDDimension()
Check input workspace dimension.
void init() override
Initialize the proeprties.
std::map< std::string, std::string > validateInputs() override
Validate inputs.
int version() const override
Algorithm's version for identification.
bool mIsQSample
coordinate system
std::map< uint16_t, Mantid::Kernel::Matrix< double > > mRotationMatrixMap
Map.
void applyPolarizationAngleCorrection(typename Mantid::DataObjects::MDEventWorkspace< MDE, nd >::sptr ws)
Apply polarization angle correction to each MDEvent.
const std::string category() const override
category
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< const ExperimentInfo > ExperimentInfo_const_sptr
Shared pointer to const ExperimentInfo.
SpecialCoordinateSystem
Special coordinate systems for Q3D.
@ Input
An input workspace.
@ Output
An output workspace.