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) {
43 "An input MDEventWorkspace.");
47 "A PeaksWorkspace containing the peaks to integrate.");
50 "The output PeaksWorkspace will be a copy of the input PeaksWorkspace "
51 "with the peaks' integrated intensities.");
55 "Output Masking Workspace");
58 "A comma separated list for peak centre in Q-sample frame. "
59 "Its length is either 3 (Qx, Qy, Qz) or 0. "
60 "If peak center is defined, then all the data among all the runs will be "
61 "integrated in respect to this peak center. Otherwise, the peaks that "
63 "be integrated shall be found in the given peak workspace.");
68 "In case that there are more than 1 run number in the given "
70 "and MDEVentWorkspace, if it is set to true, then the peaks' intensities "
74 "If selected, then all the signals will be normalized by monitor counts."
75 "Otherwise, the output peak intensity will be just simple addition of "
77 "It is only applied to the situation that Mergepeaks is not selected.");
80 "It selected, then all the signals will be normalized by time "
81 "in the case that the counting time is very short and thus the beam "
86 "If NormalizeByMonitor or NormalizeByTime is selected, the intensity "
87 "will be scaled by this factor.");
122 std::vector<double> peak_center =
getProperty(
"PeakCentre");
123 if (!peak_center.empty()) {
125 if (peak_center.size() != 3)
126 throw std::invalid_argument(
"PeakCentre must have 3 elements.");
136 if (peakWSName.length() == 0)
137 throw std::invalid_argument(
"It is not allowed that neither peak center "
138 "nor PeaksWorkspace is specified.");
145 throw std::invalid_argument(
"It is not allowed to merge peaks when there are "
146 "multiple peaks present in PeaksWorkspace.");
151 throw std::invalid_argument(
"It is not allowed to select to be normalized both "
152 "by time and by monitor counts.");
154 throw std::invalid_argument(
"Either being normalized by time or being normalized "
155 "by monitor must be selected if merge-peak is selected.");
173 throw std::invalid_argument(
"Peak radius cannot be left empty.");
177 if (!maskwsname.empty()) {
197 const std::map<int, signal_t> &run_monitor_map) {
200 throw std::runtime_error(
"MDEventWorkspace is not defined.");
203 auto mditer =
m_inputWS->createIterator();
204 size_t nextindex = 1;
205 bool scancell =
true;
210 int current_run_number = -1;
211 signal_t current_monitor_counts = 0;
215 double min_distance = 10000000;
216 double max_distance = -1;
220 size_t numeventincell = mditer->getNumEvents();
222 for (
size_t iev = 0; iev < numeventincell; ++iev) {
224 signal_t signal = mditer->getInnerSignal(iev);
228 uint16_t run_number = mditer->getInnerExpInfoIndex(iev);
229 auto run_number_i =
static_cast<int>(run_number);
241 detid_t detid = mditer->getInnerDetectorID(iev);
242 std::vector<detid_t>::const_iterator it;
268 if (current_run_number != run_number_i) {
270 current_run_number = run_number_i;
273 auto m_finder = run_monitor_map.find(current_run_number);
274 if (m_finder != run_monitor_map.end())
275 current_monitor_counts = m_finder->second;
277 std::stringstream errss;
278 errss <<
"Unable to find run number " << current_run_number <<
" in monitor counts map";
279 throw std::runtime_error(errss.str());
282 current_monitor_counts = 1.;
291 float tempx = mditer->getInnerPosition(iev, 0);
292 float tempy = mditer->getInnerPosition(iev, 1);
293 float tempz = mditer->getInnerPosition(iev, 2);
295 double distance = current_peak_center.
distance(pixel_pos);
310 <<
": Center = " << current_peak_center.
toString() <<
", Pixel = " << pixel_pos.
toString()
314 if (distance < min_distance)
315 min_distance = distance;
316 if (distance > max_distance)
317 max_distance = distance;
321 if (mditer->next()) {
323 mditer->jumpTo(nextindex);
332 g_log.
notice() <<
"Distance range is " << min_distance <<
", " << max_distance <<
"\n";
356 size_t numspec = maskws->getNumberHistograms();
357 const auto &specInfo = maskws->spectrumInfo();
358 for (
size_t iws = 0; iws < numspec; ++iws) {
359 const auto &vecY = maskws->y(iws);
362 const detid_t detid = specInfo.detector(iws).getID();
382 double total_intensity = 0;
383 double total_monitor_counts = 0.;
386 std::map<int, signal_t>::iterator mon_iter;
388 int run_number_i = mon_iter->first;
389 signal_t monitor_i = mon_iter->second;
391 total_intensity += monitor_i * intensity_i;
392 total_monitor_counts += monitor_i;
396 double merged_intensity = total_intensity / total_monitor_counts;
399 std::map<int, double>::iterator count_iter;
401 count_iter->second = merged_intensity;
413 size_t num_peaks = outws->getNumberPeaks();
414 for (
size_t i_peak = 0; i_peak < num_peaks; ++i_peak) {
433 g_log.
notice(
"Create peak workspace for output ... ...");
438 size_t numruns = mdws->getNumExperimentInfo();
439 for (
size_t i_run = 0; i_run < numruns; ++i_run) {
442 int runnumber = expinfo->getRunNumber();
447 peakcount = miter->second;
448 g_log.
notice() <<
"[DB] Get peak count of run " << runnumber <<
" as " << peakcount <<
"\n";
450 g_log.
notice() <<
"[DB] Unable to find run " << runnumber <<
" in peak count map."
460 }
catch (
const std::exception &) {
461 throw std::runtime_error(
"Unable to set instrument and goniometer matrix.");
468 peakws->addPeak(newpeak);
481 std::map<int, signal_t> run_monitor_map;
483 uint16_t num_expinfo =
m_inputWS->getNumExperimentInfo();
484 for (
size_t iexpinfo = 0; iexpinfo < num_expinfo; ++iexpinfo) {
486 std::string run_str = expinfo->run().getProperty(
"run_number")->value();
487 g_log.
information() <<
"run number of exp " << iexpinfo <<
" is " << run_str <<
"\n";
488 int run_number = std::stoi(run_str);
490 run_number = run_number % 1000;
491 std::string mon_str = expinfo->run().getProperty(
"monitor")->value();
492 auto monitor =
static_cast<signal_t>(std::stod(mon_str));
493 run_monitor_map.insert(std::make_pair(run_number, monitor));
494 g_log.
information() <<
"From MD workspace add run " << run_number <<
", monitor = " << monitor <<
"\n";
497 return run_monitor_map;
507 std::map<int, double> run_time_map;
509 uint16_t num_expinfo =
m_inputWS->getNumExperimentInfo();
510 for (
size_t iexpinfo = 0; iexpinfo < num_expinfo; ++iexpinfo) {
512 std::string run_str = expinfo->run().getProperty(
"run_number")->value();
513 int run_number = std::stoi(run_str);
516 run_number = run_number % 1000;
517 std::string duration_str = expinfo->run().getProperty(
"duration")->value();
518 double duration = std::stod(duration_str);
519 run_time_map.insert(std::make_pair(run_number, duration));
520 g_log.
warning() <<
"MD workspace exp info " << iexpinfo <<
": run " << run_number
521 <<
", measuring time = " << duration <<
"\n";
533 for (
size_t ipeak = 0; ipeak < numpeaks; ++ipeak) {
553 std::map<int, double>::iterator count_iter;
555 int run_number_i = count_iter->first;
560 signal_t monitor_i = mon_iter->second;
561 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.
void deprecatedDate(const std::string &)
The date the algorithm was deprecated on.
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.
void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, std::optional< double > detectorDistance=std::nullopt) override
Set the peak using the peak's position in reciprocal space, in the sample frame.
Geometry::Instrument_const_sptr getInstrument() const
Return a shared ptr to the instrument for this peak.
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.