47 "Name of the input MDEventWorkspace that stores detectors "
48 "counts from a constant-wave powder diffraction experiment.");
52 "Input Peaks Workspace");
55 "A comma seperated list of doubles for UB matrix from (0,0), (0,1)"
59 "Name of the output MDEventWorkspace in HKL-space.");
62 "Name of file for sample sample.");
65 "Name of file for HKL.");
74 std::stringstream errmsg;
75 errmsg <<
"Input MDEventWorkspace's coordinate system is not QSample but " << inputWS->getSpecialCoordinateSystem()
77 throw std::invalid_argument(errmsg.str());
85 qsample.
setX(1.36639);
86 qsample.
setY(-2.52888);
87 qsample.
setZ(-4.77349);
89 std::vector<Kernel::V3D> vec_qsample;
90 vec_qsample.emplace_back(qsample);
91 std::vector<Kernel::V3D> vec_mindex(0);
94 g_log.
notice() <<
"[DB Number of returned Miller Index = " << vec_mindex.size() <<
"\n";
95 g_log.
notice() <<
"[DB] Output HKL = " << vec_mindex[0].toString() <<
"\n";
99 std::vector<Kernel::V3D> vec_event_qsample;
100 std::vector<signal_t> vec_event_signal;
101 std::vector<detid_t> vec_event_det;
102 exportEvents(inputWS, vec_event_qsample, vec_event_signal, vec_event_det);
106 if (!qsamplefilename.empty())
107 saveEventsToFile(qsamplefilename, vec_event_qsample, vec_event_signal, vec_event_det);
110 std::vector<Kernel::V3D> vec_event_hkl;
116 if (!hklfilename.empty())
117 saveEventsToFile(hklfilename, vec_event_hkl, vec_event_signal, vec_event_det);
123 expinfo->setInstrument(inputWS->getExperimentInfo(0)->getInstrument());
124 expinfo->mutableRun().setGoniometer(inputWS->getExperimentInfo(0)->run().getGoniometer(),
false);
125 expinfo->mutableRun().addProperty(
"run_number", 1);
139 std::vector<double> ub_array =
getProperty(
"UBMatrix");
140 if (ub_array.size() != 9)
141 throw std::invalid_argument(
"Input UB matrix must have 9 elements");
144 for (
size_t i = 0; i < 3; ++i) {
145 for (
size_t j = 0; j < 3; ++j) {
146 m_UB[i][j] = ub_array[i * 3 + j];
158 std::vector<signal_t> &vec_event_signal, std::vector<detid_t> &vec_event_det) {
160 size_t numevents = mdws->getNEvents();
163 vec_event_qsample.resize(numevents);
164 vec_event_signal.resize(numevents);
165 vec_event_det.resize(numevents);
168 auto mditer = mdws->createIterator();
169 size_t nextindex = 1;
170 bool scancell =
true;
171 size_t currindex = 0;
173 size_t numevent_cell = mditer->getNumEvents();
174 for (
size_t iev = 0; iev < numevent_cell; ++iev) {
176 if (currindex >= vec_event_qsample.size())
177 throw std::runtime_error(
"Logic error in event size!");
179 float tempx = mditer->getInnerPosition(iev, 0);
180 float tempy = mditer->getInnerPosition(iev, 1);
181 float tempz = mditer->getInnerPosition(iev, 2);
182 signal_t signal = mditer->getInnerSignal(iev);
183 detid_t detid = mditer->getInnerDetectorID(iev);
185 vec_event_qsample[currindex] = qsample;
186 vec_event_signal[currindex] = signal;
187 vec_event_det[currindex] = detid;
193 if (mditer->next()) {
195 mditer->jumpTo(nextindex);
208 const std::vector<float> &vecEventSignal) {
213 if (filename.empty())
215 if (vecEventQsample.size() != vecEventSignal.size())
216 throw std::runtime_error(
"Input vectors of Q-sample and signal have different sizes.");
220 ofile.open(filename.c_str());
222 size_t numevents = vecEventQsample.size();
223 for (
size_t i = 0; i < numevents; ++i) {
224 ofile << vecEventQsample[i][0] <<
", " << vecEventQsample[i][1] <<
", " << vecEventQsample[i][2] <<
", "
225 << vecEventSignal[i] <<
"\n";
234 const std::vector<signal_t> &vecEventSignal,
235 const std::vector<detid_t> &vecEventDetid) {
237 if (vecEventDetid.size() != vecEventPos.size() || vecEventPos.size() != vecEventSignal.size())
238 throw std::invalid_argument(
"Input vectors for HKL, signal and detector ID have different size.");
241 ofile.open(filename.c_str());
243 for (
size_t i = 0; i < vecEventPos.size(); ++i) {
244 ofile << vecEventPos[i].X() <<
", " << vecEventPos[i].Y() <<
", " << vecEventPos[i].Z() <<
", " << vecEventSignal[i]
245 <<
", " << vecEventDetid[i] <<
"\n";
257 int original_indexed = 0;
258 double original_error = 0;
263 g_log.
notice() <<
"[DB] " << original_indexed <<
" peaks are indexed."
273 const std::vector<signal_t> &vec_signal,
274 const std::vector<detid_t> &vec_detid) {
276 if (vec_hkl.size() != vec_signal.size() || vec_signal.size() != vec_detid.size())
277 throw std::invalid_argument(
"Input vectors for HKL, signal and detector "
278 "IDs are of different size!");
281 size_t nDimension = 3;
285 std::vector<std::string> vec_ID(3);
290 std::vector<std::string> dimensionNames(3);
291 dimensionNames[0] =
"H";
292 dimensionNames[1] =
"K";
293 dimensionNames[2] =
"L";
298 std::vector<double> m_extentMins(3);
299 std::vector<double> m_extentMaxs(3);
300 std::vector<size_t> m_numBins(3, 100);
301 getRange(vec_hkl, m_extentMins, m_extentMaxs);
308 for (
size_t i = 0; i < nDimension; ++i) {
309 std::string
id = vec_ID[i];
310 std::string
name = dimensionNames[i];
313 id,
name, frame,
static_cast<coord_t>(m_extentMins[i]),
static_cast<coord_t>(m_extentMaxs[i]), m_numBins[i])));
317 mdws->setCoordinateSystem(coordinateSystem);
324 for (
size_t iq = 0; iq < vec_hkl.size(); ++iq) {
326 std::vector<Mantid::coord_t> millerindex(3);
327 millerindex[0] =
static_cast<float>(hkl.
X());
328 millerindex[1] =
static_cast<float>(hkl.
Y());
329 millerindex[2] =
static_cast<float>(hkl.
Z());
333 uint16_t runnumber = 1;
337 inserter.insertMDEvent(
static_cast<float>(signal),
static_cast<float>(
error *
error),
338 static_cast<uint16_t
>(runnumber), 0, detid, millerindex.data());
345 std::vector<double> &extentMaxs) {
346 assert(extentMins.size() == 3);
347 assert(extentMaxs.size() == 3);
349 for (
size_t i = 0; i < 3; ++i) {
350 double minvalue = vec_hkl[0][i];
351 double maxvalue = vec_hkl[0][i];
352 for (
size_t j = 1; j < vec_hkl.size(); ++j) {
353 double thisvalue = vec_hkl[j][i];
354 if (thisvalue < minvalue)
355 minvalue = thisvalue;
356 else if (thisvalue > maxvalue)
357 maxvalue = thisvalue;
359 extentMins[i] = minvalue;
360 extentMaxs[i] = maxvalue;
#define DECLARE_ALGORITHM(classname)
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.
@ OptionalSave
to specify a file to write to but an empty string is
A property class for workspaces.
static API::IMDEventWorkspace_sptr CreateMDWorkspace(size_t nd, const std::string &eventType="MDLeanEvent", const Mantid::API::MDNormalization &preferredNormalization=Mantid::API::MDNormalization::VolumeNormalization, const Mantid::API::MDNormalization &preferredNormalizationHisto=Mantid::API::MDNormalization::VolumeNormalization)
Create a MDEventWorkspace of the given type.
MDEventInserter : Helper class that provides a generic interface for adding events to an MDWorkspace ...
Templated class for the multi-dimensional event workspace.
static int CalculateMillerIndices(const Kernel::DblMatrix &UB, const std::vector< Kernel::V3D > &q_vectors, double tolerance, std::vector< Kernel::V3D > &miller_indices, double &ave_error)
Given a UB, get list of Miller indices for specifed Qs and tolerance.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void information(const std::string &msg)
Logs at information level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
static const UnitLabel RLU
Reciprocal lattice units.
constexpr double X() const noexcept
Get x.
constexpr double Y() const noexcept
Get y.
void setZ(const double zz) noexcept
Set is z position.
void setX(const double xx) noexcept
Set is x position.
void setY(const double yy) noexcept
Set is y position.
constexpr double Z() const noexcept
Get z.
ConvertCWSDMDtoHKL : TODO: DESCRIPTION.
void saveEventsToFile(const std::string &filename, std::vector< Kernel::V3D > &vecEventPos, const std::vector< signal_t > &vecEventSignal, const std::vector< detid_t > &vecEventDetid)
Save HKL to file for 3D visualization.
Kernel::Matrix< double > m_UB
const std::string name() const override
Algorithm's name.
void getRange(const std::vector< Kernel::V3D > &vec_hkl, std::vector< double > &extentMins, std::vector< double > &extentMaxs)
API::IMDEventWorkspace_sptr createHKLMDWorkspace(const std::vector< Kernel::V3D > &vec_hkl, const std::vector< signal_t > &vec_signal, const std::vector< detid_t > &vec_detid)
Create output workspace.
void exec() override
Execution code.
void saveMDToFile(const std::vector< std::vector< coord_t > > &vecEventQsample, const std::vector< float > &vecEventSignal)
Save Q-sample to file.
API::IMDEventWorkspace_sptr m_outputWS
void convertFromQSampleToHKL(const std::vector< Kernel::V3D > &q_vectors, std::vector< Kernel::V3D > &miller_indices)
Convert from Q-sample to HKL.
void exportEvents(const API::IMDEventWorkspace_sptr &mdws, std::vector< Kernel::V3D > &vec_event_qsample, std::vector< signal_t > &vec_event_signal, std::vector< detid_t > &vec_event_det)
Export events from an MDEventWorkspace for future processing It is a convenient algorithm if number o...
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
SpecialCoordinateSystem
Special coordinate systems for Q3D.
MDUnitFactory_uptr MANTID_KERNEL_DLL makeMDUnitFactoryChain()
Convience method. Pre-constructed builder chain.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
int32_t detid_t
Typedef for a detector ID.
double signal_t
Typedef for the signal recorded in a MDBox, etc.
@ Input
An input workspace.
@ Output
An output workspace.