23using Mantid::Types::Event::TofEvent;
31const std::string
ELASTIC(
"Elastic");
33const std::string
Q3D(
"Q3D");
35const std::size_t
DIMS(3);
53 auto ws_valid = std::make_shared<CompositeValidator>();
60 "An input EventWorkspace with units along X-axis and defined "
61 "instrument with defined sample");
63 "Optional path to an hkl file to save. Vectors returned if no file "
66 declareProperty(
"ISAWcoords",
true,
"Save the Q-vector with y gravitationally up and x pointing downstream");
67 std::vector<double> Qx_save, Qy_save, Qz_save;
81 if (wksp->getEventType() !=
API::TOF) {
82 throw std::runtime_error(
"SaveIsawQvector only works for raw events");
85 if (wksp->getNumberEvents() <= 0) {
86 throw std::runtime_error(
"SaveIsawQvector does not work for empty event lists");
92 if (!filename.empty()) {
93 handle.open(filename.c_str(), std::ios::out | std::ios::binary);
94 if (!handle.is_open())
95 throw std::runtime_error(
"Failed to open file for writing");
100 size_t coord_map[
DIMS] = {0, 1, 2};
101 double coord_signs[
DIMS] = {1., 1., 1.};
114 std::transform(std::cbegin(coord_signs), std::cend(coord_signs), std::begin(coord_signs),
127 const size_t numSpectra = wksp->getNumberHistograms();
128 Progress prog(
this, 0.5, 1.0, numSpectra);
132 std::vector<double> Qx_save, Qy_save, Qz_save;
133 for (std::size_t i = 0; i < numSpectra; ++i) {
135 const EventList &events = wksp->getSpectrum(i);
138 if (events.
empty()) {
144 std::vector<coord_t> locCoord(
DIMS, 0.);
146 q_converter->calcYDepCoordinates(locCoord, i);
151 const std::vector<TofEvent> &raw_events = events.
getEvents();
152 for (
const auto &raw_event : raw_events) {
154 q_converter->calcMatrixCoord(val, locCoord, signal, errorSq);
155 for (
size_t dim = 0; dim <
DIMS; ++dim) {
156 buffer[dim] =
static_cast<float>(coord_signs[dim] * locCoord[coord_map[dim]]);
158 if (filename.empty()) {
159 Qx_save.emplace_back(
static_cast<double>(buffer[0]));
160 Qy_save.emplace_back(
static_cast<double>(buffer[1]));
161 Qz_save.emplace_back(
static_cast<double>(buffer[2]));
163 handle.write(
reinterpret_cast<char *
>(buffer),
BUFF_SIZE);
168 if (filename.empty()) {
189 childAlg->setProperty(
"InputWorkspace", wksp);
190 childAlg->executeAsChildAlg();
194 throw(std::runtime_error(
"Can not retrieve results of \"PreprocessDetectorsToMD\""));
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
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.
@ OptionalSave
to specify a file to write to but an empty string is
A validator which checks that a workspace has a valid instrument.
Helper class for reporting progress from algorithms.
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
std::vector< Types::Event::TofEvent > & getEvents()
Return the list of TofEvents contained.
bool empty() const
Much like stl containers, returns true if there is nothing in the event list.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
void setMinMax(const std::vector< double > &minVal, const std::vector< double > &maxVal)
function sets up min-max values to the dimensions, described by the class
std::string AlgID
the string which describes ChildAlgorithm, used to convert source ws to target MD ws.
void buildFromMatrixWS(const API::MatrixWorkspace_sptr &pWS, const std::string &QMode, const std::string &dEMode, const std::vector< std::string > &dimPropertyNames=std::vector< std::string >())
method builds MD Event ws description from a matrix workspace and the transformations,...
DataObjects::TableWorkspace_const_sptr m_PreprDetTable
void setLorentsCorr(bool On=false)
do we need to perform Lorentz corrections
void init() override
Initialize the algorithm's properties.
void initTargetWSDescr(const DataObjects::EventWorkspace_sptr &wksp)
SaveIsawQvector::initTargetWSDescr Initialize the output information for the MD conversion framework.
const std::string category() const override
Algorithm's category for identification.
const std::string name() const override
Algorithm's name for identification.
int version() const override
Algorithm's version for identification.
MDWSDescription m_targWSDescr
void exec() override
Execute the algorithm.
void updateConversion(size_t i)
Method updates unit conversion given the index of detector parameters in the array of detectors.
void initialize(const MDWSDescription &targetWSDescr, const std::string &unitsTo, bool forceViaTOF=false)
Initialize unit conversion helper This method is interface to internal initialize method,...
double convertUnits(double val) const
do actual unit conversion from input to oputput data
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
const std::string Q3D("Q3D")
Only convert to Q-vector.
const std::size_t DIMS(3)
Q-vector is always three dimensional.
std::shared_ptr< MDTransfInterface > MDTransf_sptr
const std::size_t BUFF_SIZE(DIMS *sizeof(float))
Constant for the size of the buffer to write to disk.
const std::string ELASTIC("Elastic")
This only works for diffraction.
@ Input
An input workspace.
@ Output
An output workspace.