48 "Name of the input MDEventWorkspace that stores detectors "
49 "counts from a constant-wave powder diffraction experiment.");
53 "Input Peaks Workspace");
56 "A comma seperated list of doubles for UB matrix from (0,0), (0,1)"
60 "Name of the output MDEventWorkspace in HKL-space.");
63 "Name of file for sample sample.");
66 "Name of file for HKL.");
75 std::stringstream errmsg;
76 errmsg <<
"Input MDEventWorkspace's coordinate system is not QSample but " << inputWS->getSpecialCoordinateSystem()
78 throw std::invalid_argument(errmsg.str());
86 qsample.
setX(1.36639);
87 qsample.
setY(-2.52888);
88 qsample.
setZ(-4.77349);
90 std::vector<Kernel::V3D> vec_qsample;
91 vec_qsample.emplace_back(qsample);
92 std::vector<Kernel::V3D> vec_mindex(0);
95 g_log.
notice() <<
"[DB Number of returned Miller Index = " << vec_mindex.size() <<
"\n";
96 g_log.
notice() <<
"[DB] Output HKL = " << vec_mindex[0].toString() <<
"\n";
100 std::vector<Kernel::V3D> vec_event_qsample;
101 std::vector<signal_t> vec_event_signal;
102 std::vector<detid_t> vec_event_det;
103 exportEvents(inputWS, vec_event_qsample, vec_event_signal, vec_event_det);
107 if (!qsamplefilename.empty())
108 saveEventsToFile(qsamplefilename, vec_event_qsample, vec_event_signal, vec_event_det);
111 std::vector<Kernel::V3D> vec_event_hkl;
117 if (!hklfilename.empty())
118 saveEventsToFile(hklfilename, vec_event_hkl, vec_event_signal, vec_event_det);
124 expinfo->setInstrument(inputWS->getExperimentInfo(0)->getInstrument());
125 expinfo->mutableRun().setGoniometer(inputWS->getExperimentInfo(0)->run().getGoniometer(),
false);
126 expinfo->mutableRun().addProperty(
"run_number", 1);
134 if (!peakwsname.empty() && AnalysisDataService::Instance().doesExist(peakwsname)) {
140 std::vector<double> ub_array =
getProperty(
"UBMatrix");
141 if (ub_array.size() != 9)
142 throw std::invalid_argument(
"Input UB matrix must have 9 elements");
145 for (
size_t i = 0; i < 3; ++i) {
146 for (
size_t j = 0; j < 3; ++j) {
147 m_UB[i][j] = ub_array[i * 3 + j];
159 std::vector<signal_t> &vec_event_signal, std::vector<detid_t> &vec_event_det) {
161 size_t numevents = mdws->getNEvents();
164 vec_event_qsample.resize(numevents);
165 vec_event_signal.resize(numevents);
166 vec_event_det.resize(numevents);
169 auto mditer = mdws->createIterator();
170 size_t nextindex = 1;
171 bool scancell =
true;
172 size_t currindex = 0;
174 size_t numevent_cell = mditer->getNumEvents();
175 for (
size_t iev = 0; iev < numevent_cell; ++iev) {
177 if (currindex >= vec_event_qsample.size())
178 throw std::runtime_error(
"Logic error in event size!");
180 float tempx = mditer->getInnerPosition(iev, 0);
181 float tempy = mditer->getInnerPosition(iev, 1);
182 float tempz = mditer->getInnerPosition(iev, 2);
183 signal_t signal = mditer->getInnerSignal(iev);
184 detid_t detid = mditer->getInnerDetectorID(iev);
186 vec_event_qsample[currindex] = qsample;
187 vec_event_signal[currindex] = signal;
188 vec_event_det[currindex] = detid;
194 if (mditer->next()) {
196 mditer->jumpTo(nextindex);
209 const std::vector<float> &vecEventSignal) {
214 if (filename.empty())
216 if (vecEventQsample.size() != vecEventSignal.size())
217 throw std::runtime_error(
"Input vectors of Q-sample and signal have different sizes.");
221 ofile.open(filename.c_str());
223 size_t numevents = vecEventQsample.size();
224 for (
size_t i = 0; i < numevents; ++i) {
225 ofile << vecEventQsample[i][0] <<
", " << vecEventQsample[i][1] <<
", " << vecEventQsample[i][2] <<
", "
226 << vecEventSignal[i] <<
"\n";
235 const std::vector<signal_t> &vecEventSignal,
236 const std::vector<detid_t> &vecEventDetid) {
238 if (vecEventDetid.size() != vecEventPos.size() || vecEventPos.size() != vecEventSignal.size())
239 throw std::invalid_argument(
"Input vectors for HKL, signal and detector ID have different size.");
242 ofile.open(filename.c_str());
244 for (
size_t i = 0; i < vecEventPos.size(); ++i) {
245 ofile << vecEventPos[i].X() <<
", " << vecEventPos[i].Y() <<
", " << vecEventPos[i].Z() <<
", " << vecEventSignal[i]
246 <<
", " << vecEventDetid[i] <<
"\n";
258 int original_indexed = 0;
259 double original_error = 0;
264 g_log.
notice() <<
"[DB] " << original_indexed <<
" peaks are indexed."
274 const std::vector<signal_t> &vec_signal,
275 const std::vector<detid_t> &vec_detid) {
277 if (vec_hkl.size() != vec_signal.size() || vec_signal.size() != vec_detid.size())
278 throw std::invalid_argument(
"Input vectors for HKL, signal and detector "
279 "IDs are of different size!");
282 size_t nDimension = 3;
286 std::vector<std::string> vec_ID(3);
291 std::vector<std::string> dimensionNames(3);
292 dimensionNames[0] =
"H";
293 dimensionNames[1] =
"K";
294 dimensionNames[2] =
"L";
299 std::vector<double> m_extentMins(3);
300 std::vector<double> m_extentMaxs(3);
301 std::vector<size_t> m_numBins(3, 100);
302 getRange(vec_hkl, m_extentMins, m_extentMaxs);
309 for (
size_t i = 0; i < nDimension; ++i) {
310 std::string
id = vec_ID[i];
311 std::string
name = dimensionNames[i];
314 id,
name, frame,
static_cast<coord_t>(m_extentMins[i]),
static_cast<coord_t>(m_extentMaxs[i]), m_numBins[i])));
318 mdws->setCoordinateSystem(coordinateSystem);
325 for (
size_t iq = 0; iq < vec_hkl.size(); ++iq) {
327 std::vector<Mantid::coord_t> millerindex(3);
328 millerindex[0] =
static_cast<float>(hkl.
X());
329 millerindex[1] =
static_cast<float>(hkl.
Y());
330 millerindex[2] =
static_cast<float>(hkl.
Z());
334 uint16_t runnumber = 1;
338 inserter.insertMDEvent(
static_cast<float>(signal),
static_cast<float>(
error *
error),
339 static_cast<uint16_t
>(runnumber), 0, detid, millerindex.data());
346 std::vector<double> &extentMaxs) {
347 assert(extentMins.size() == 3);
348 assert(extentMaxs.size() == 3);
350 for (
size_t i = 0; i < 3; ++i) {
351 double minvalue = vec_hkl[0][i];
352 double maxvalue = vec_hkl[0][i];
353 for (
size_t j = 1; j < vec_hkl.size(); ++j) {
354 double thisvalue = vec_hkl[j][i];
355 if (thisvalue < minvalue)
356 minvalue = thisvalue;
357 else if (thisvalue > maxvalue)
358 maxvalue = thisvalue;
360 extentMins[i] = minvalue;
361 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 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.