34 : m_haveMultipleRun(false), m_useSinglePeakCenterFmUser(false), m_peakRadius(), m_doMergePeak(false),
35 m_normalizeByMonitor(false), m_normalizeByTime(false), m_scaleFactor(0), m_haveInputPeakWS(false) {}
41 "An input MDEventWorkspace.");
45 "A PeaksWorkspace containing the peaks to integrate.");
48 "The output PeaksWorkspace will be a copy of the input PeaksWorkspace "
49 "with the peaks' integrated intensities.");
53 "Output Masking Workspace");
56 "A comma separated list for peak centre in Q-sample frame. "
57 "Its length is either 3 (Qx, Qy, Qz) or 0. "
58 "If peak center is defined, then all the data among all the runs will be "
59 "integrated in respect to this peak center. Otherwise, the peaks that "
61 "be integrated shall be found in the given peak workspace.");
66 "In case that there are more than 1 run number in the given "
68 "and MDEVentWorkspace, if it is set to true, then the peaks' intensities "
72 "If selected, then all the signals will be normalized by monitor counts."
73 "Otherwise, the output peak intensity will be just simple addition of "
75 "It is only applied to the situation that Mergepeaks is not selected.");
78 "It selected, then all the signals will be normalized by time "
79 "in the case that the counting time is very short and thus the beam "
84 "If NormalizeByMonitor or NormalizeByTime is selected, the intensity "
85 "will be scaled by this factor.");
120 std::vector<double> peak_center =
getProperty(
"PeakCentre");
121 if (!peak_center.empty()) {
123 if (peak_center.size() != 3)
124 throw std::invalid_argument(
"PeakCentre must have 3 elements.");
134 if (peakWSName.length() == 0)
135 throw std::invalid_argument(
"It is not allowed that neither peak center "
136 "nor PeaksWorkspace is specified.");
143 throw std::invalid_argument(
"It is not allowed to merge peaks when there are "
144 "multiple peaks present in PeaksWorkspace.");
149 throw std::invalid_argument(
"It is not allowed to select to be normalized both "
150 "by time and by monitor counts.");
152 throw std::invalid_argument(
"Either being normalized by time or being normalized "
153 "by monitor must be selected if merge-peak is selected.");
171 throw std::invalid_argument(
"Peak radius cannot be left empty.");
175 if (!maskwsname.empty()) {
195 const std::map<int, signal_t> &run_monitor_map) {
198 throw std::runtime_error(
"MDEventWorkspace is not defined.");
201 auto mditer =
m_inputWS->createIterator();
202 size_t nextindex = 1;
203 bool scancell =
true;
208 int current_run_number = -1;
209 signal_t current_monitor_counts = 0;
213 double min_distance = 10000000;
214 double max_distance = -1;
218 size_t numeventincell = mditer->getNumEvents();
220 for (
size_t iev = 0; iev < numeventincell; ++iev) {
222 signal_t signal = mditer->getInnerSignal(iev);
226 uint16_t run_number = mditer->getInnerExpInfoIndex(iev);
227 auto run_number_i =
static_cast<int>(run_number);
239 detid_t detid = mditer->getInnerDetectorID(iev);
240 std::vector<detid_t>::const_iterator it;
266 if (current_run_number != run_number_i) {
268 current_run_number = run_number_i;
271 auto m_finder = run_monitor_map.find(current_run_number);
272 if (m_finder != run_monitor_map.end())
273 current_monitor_counts = m_finder->second;
275 std::stringstream errss;
276 errss <<
"Unable to find run number " << current_run_number <<
" in monitor counts map";
277 throw std::runtime_error(errss.str());
280 current_monitor_counts = 1.;
289 float tempx = mditer->getInnerPosition(iev, 0);
290 float tempy = mditer->getInnerPosition(iev, 1);
291 float tempz = mditer->getInnerPosition(iev, 2);
293 double distance = current_peak_center.
distance(pixel_pos);
308 <<
": Center = " << current_peak_center.
toString() <<
", Pixel = " << pixel_pos.
toString()
312 if (distance < min_distance)
313 min_distance = distance;
314 if (distance > max_distance)
315 max_distance = distance;
319 if (mditer->next()) {
321 mditer->jumpTo(nextindex);
330 g_log.
notice() <<
"Distance range is " << min_distance <<
", " << max_distance <<
"\n";
354 size_t numspec = maskws->getNumberHistograms();
355 const auto &specInfo = maskws->spectrumInfo();
356 for (
size_t iws = 0; iws < numspec; ++iws) {
357 const auto &vecY = maskws->y(iws);
360 const detid_t detid = specInfo.detector(iws).getID();
380 double total_intensity = 0;
381 double total_monitor_counts = 0.;
384 std::map<int, signal_t>::iterator mon_iter;
386 int run_number_i = mon_iter->first;
387 signal_t monitor_i = mon_iter->second;
389 total_intensity += monitor_i * intensity_i;
390 total_monitor_counts += monitor_i;
394 double merged_intensity = total_intensity / total_monitor_counts;
397 std::map<int, double>::iterator count_iter;
399 count_iter->second = merged_intensity;
411 size_t num_peaks = outws->getNumberPeaks();
412 for (
size_t i_peak = 0; i_peak < num_peaks; ++i_peak) {
431 g_log.
notice(
"Create peak workspace for output ... ...");
436 size_t numruns = mdws->getNumExperimentInfo();
437 for (
size_t i_run = 0; i_run < numruns; ++i_run) {
440 int runnumber = expinfo->getRunNumber();
445 peakcount = miter->second;
446 g_log.
notice() <<
"[DB] Get peak count of run " << runnumber <<
" as " << peakcount <<
"\n";
448 g_log.
notice() <<
"[DB] Unable to find run " << runnumber <<
" in peak count map."
458 }
catch (
const std::exception &) {
459 throw std::runtime_error(
"Unable to set instrument and goniometer matrix.");
466 peakws->addPeak(newpeak);
479 std::map<int, signal_t> run_monitor_map;
481 uint16_t num_expinfo =
m_inputWS->getNumExperimentInfo();
482 for (
size_t iexpinfo = 0; iexpinfo < num_expinfo; ++iexpinfo) {
484 std::string run_str = expinfo->run().getProperty(
"run_number")->value();
485 g_log.
information() <<
"run number of exp " << iexpinfo <<
" is " << run_str <<
"\n";
486 int run_number = std::stoi(run_str);
488 run_number = run_number % 1000;
489 std::string mon_str = expinfo->run().getProperty(
"monitor")->value();
490 auto monitor =
static_cast<signal_t>(std::stod(mon_str));
491 run_monitor_map.insert(std::make_pair(run_number, monitor));
492 g_log.
information() <<
"From MD workspace add run " << run_number <<
", monitor = " << monitor <<
"\n";
495 return run_monitor_map;
505 std::map<int, double> run_time_map;
507 uint16_t num_expinfo =
m_inputWS->getNumExperimentInfo();
508 for (
size_t iexpinfo = 0; iexpinfo < num_expinfo; ++iexpinfo) {
510 std::string run_str = expinfo->run().getProperty(
"run_number")->value();
511 int run_number = std::stoi(run_str);
514 run_number = run_number % 1000;
515 std::string duration_str = expinfo->run().getProperty(
"duration")->value();
516 double duration = std::stod(duration_str);
517 run_time_map.insert(std::make_pair(run_number, duration));
518 g_log.
warning() <<
"MD workspace exp info " << iexpinfo <<
": run " << run_number
519 <<
", measuring time = " << duration <<
"\n";
532 for (
size_t ipeak = 0; ipeak < numpeaks; ++ipeak) {
552 std::map<int, double>::iterator count_iter;
554 int run_number_i = count_iter->first;
559 signal_t monitor_i = mon_iter->second;
560 count_iter->second /= monitor_i;
#define DECLARE_ALGORITHM(classname)
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.
A property class for workspaces.
void setRunNumber(int m_runNumber) override
Set the run number that measured this peak.
int getRunNumber() const override
Return the run number this peak was measured at.
void setIntensity(double m_intensity) override
Set the integrated peak intensity.
void setGoniometerMatrix(const Mantid::Kernel::Matrix< double > &goniometerMatrix) override
Set the goniometer rotation matrix at which this peak was measured.
Structure describing a single-crystal peak.
Geometry::Instrument_const_sptr getInstrument() const
Return a shared ptr to the instrument for this peak.
void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, boost::optional< double > detectorDistance=boost::none) override
Set the peak using the peak's position in reciprocal space, in the sample frame.
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
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 debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
double distance(const V3D &v) const noexcept
Calculates the distance between two vectors.
std::string toString() const
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.
std::map< int, signal_t > getMonitorCounts()
Get the run/monitor counts map.
Mantid::DataObjects::PeaksWorkspace_sptr m_peaksWS
Input PeaksWorkspace.
void exec() override
Run the algorithm.
Mantid::API::IMDEventWorkspace_sptr m_inputWS
Input MDEventWorkspace.
void init() override
Initialise the properties.
std::map< int, double > getMeasureTime()
Get the run/measuring time map.
std::map< int, double > m_runPeakCountsMap
Integrated peaks' intensity per run number.
void processInputs()
Process and check input properties.
DataObjects::PeaksWorkspace_sptr createOutputs()
Create otuput workspace.
bool m_haveMultipleRun
Peak centers.
DataObjects::PeaksWorkspace_sptr createPeakworkspace(Kernel::V3D peakCenter, const API::IMDEventWorkspace_sptr &mdws)
IntegratePeaksCWSD::createPeakworkspace.
std::vector< detid_t > processMaskWorkspace(const DataObjects::MaskWorkspace_const_sptr &maskws)
Purpose: Process mask workspace Requirement: m_maskWS is not None Guarantees: an array will be set up...
std::map< int, Kernel::V3D > m_runPeakCenterMap
void mergePeaks()
Merge the peaks' counts.
DataObjects::MaskWorkspace_sptr m_maskWS
std::vector< DataObjects::Peak > m_vecPeaks
Peaks.
std::map< int, double > m_runNormMap
a map for run number and normalization value (monitor or time)
void normalizePeaksIntensities()
Implement this method to normalize the intensity of each Pt.
bool m_haveInputPeakWS
Peak workspace.
bool m_normalizeByMonitor
IntegratePeaksCWSD()
Constructor.
void simplePeakIntegration(const std::vector< detid_t > &vecMaskedDetID, const std::map< int, signal_t > &run_monitor_map)
IntegratePeaksCWSD::simplePeakIntegration Purpose: Integrate a single crystal peak with the simplest ...
std::vector< detid_t > vecMaskedDetID
void getPeakInformation()
Get peak information from peaks workspace.
bool m_useSinglePeakCenterFmUser
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.
std::shared_ptr< const MaskWorkspace > MaskWorkspace_const_sptr
shared pointer to a const MaskWorkspace
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
const signal_t THRESHOLD_SIGNAL
int32_t detid_t
Typedef for a detector ID.
double signal_t
Typedef for the signal recorded in a MDBox, etc.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.