41#include <gsl/gsl_sf_erf.h>
44#define PEAKFITRANGEFACTOR 5.0
47#define PEAKBOUNDARYFACTOR 2.5
50#define EXCLUDEPEAKRANGEFACTOR 8.0
71 : m_wsIndex(-1), m_tofMin(0.), m_tofMax(0.), m_useGivenTOFh(false), m_confidentInInstrumentParameters(false),
72 m_minimumHKL(), m_numPeaksLowerToMin(-1), m_indexGoodFitPeaks(), m_chi2GoodFitPeaks(), m_fitMode(ROBUSTFIT),
73 m_genPeakStartingValue(HKLCALCULATION), m_rightmostPeakHKL(), m_rightmostPeakLeftBound(0.),
74 m_rightmostPeakRightBound(0.), m_minPeakHeight(0.), m_unitCell(), m_fitPeakBackgroundComposite(false) {}
82 "Input workspace for data (diffraction pattern). ");
86 "Output Workspace2D for the fitted peaks. ");
91 "TableWorkspace containg all peaks' parameters.");
96 "TableWorkspace containg instrument's parameters.");
101 "Output TableWorkspace containing the fitted peak parameters for each "
107 "Output Workspace2D containing fitted peak parameters for "
108 "further refinement.");
113 "Output TableWorkspace containing the Zscore of the fitted "
114 "peak parameters. ");
117 declareProperty(
"WorkspaceIndex", 0,
"Worskpace index for the data to refine against.");
123 vector<string> fitmodes(2);
124 fitmodes[0] =
"Robust";
125 fitmodes[1] =
"Confident";
126 auto fitvalidator = std::make_shared<StringListValidator>(fitmodes);
128 "Fitting mode such that user can determine"
129 "whether the input parameters are trustful or not.");
133 "Use each Bragg peak's centre in TOF given in "
134 "BraggPeakParameterWorkspace."
135 "Otherwise, calculate each peak's centre from d-spacing.");
137 vector<string> genpeakoptions{
"(HKL) & Calculation",
"From Bragg Peak Table"};
138 auto propvalidator = std::make_shared<StringListValidator>(genpeakoptions);
139 declareProperty(
"PeakParametersStartingValueFrom",
"(HKL) & Calculation", propvalidator,
140 "Choice of how to generate starting values of "
141 "Bragg peak profile parmeters.");
144 "Minimum peak height (with background removed) "
145 "Any peak whose maximum height under this value will be "
146 "treated as zero intensity. ");
155 "Flag for fact that all peaks' corresponding profile parameters "
156 "are correlated by an analytical function");
159 auto arrayprop = std::make_unique<ArrayProperty<int>>(
"MinimumHKL",
"");
160 declareProperty(std::move(arrayprop),
"Miller index of the left most peak (peak with "
161 "minimum d-spacing) to be fitted. ");
165 "Number of peaks to fit with d-spacing value "
166 "less than specified minimum. ");
169 auto righthklprop = std::make_unique<ArrayProperty<int>>(
"RightMostPeakHKL",
"");
170 declareProperty(std::move(righthklprop),
"Miller index of the right most peak. "
171 "It is only required and used in RobustFit mode.");
174 "Left bound of the right most peak. "
175 "Used in RobustFit mode.");
178 "Right bound of the right most peak. "
179 "Used in RobustFit mode.");
183 "Flag to do fit to both peak and background in a composite "
184 "function as last fit step.");
203 throw runtime_error(
"Input instrument table workspace lacks LatticeConstant. "
204 "Unable to complete processing.");
205 m_unitCell.
set(latticesize, latticesize, latticesize, 90.0, 90.0, 90.0);
230 throw runtime_error(
"Unsupported fit mode.");
238 setProperty(
"OutputBraggPeakParameterWorkspace", outputpeaksws);
247 setProperty(
"OutputBraggPeakParameterDataWorkspace", peakparamvaluews);
257 if (m_wsIndex < 0 || m_wsIndex >
static_cast<int>(
m_dataWS->getNumberHistograms())) {
259 errss <<
"Input workspace = " <<
m_wsIndex <<
" is out of range [0, " <<
m_dataWS->getNumberHistograms();
261 throw std::invalid_argument(errss.str());
281 if (fitmode ==
"Robust") {
283 }
else if (fitmode ==
"Confident") {
286 throw runtime_error(
"Input fit mode can only accept either Robust or Confident. ");
294 string genpeakparamalg =
getProperty(
"PeakParametersStartingValueFrom");
295 if (genpeakparamalg ==
"(HKL) & Calculation") {
297 }
else if (genpeakparamalg ==
"From Bragg Peak Table") {
300 throw runtime_error(
"Input option from PeakParametersStaringValueFrom is not supported.");
312 errss <<
"If fit mode is 'RobustFit', then user must specify all 3 "
313 "properties of right most peak "
318 throw runtime_error(errss.str());
342 bool isrightmost =
true;
345 throw runtime_error(
"There is no peak to fit!");
347 vector<string> peakparnames =
m_vecPeakFunctions[0].second.second->getParameterNames();
351 backgroundfunction->setAttributeValue(
"n", 1);
352 backgroundfunction->initialize();
356 double refpeakshift = 0.0;
358 for (
int peakindex =
static_cast<int>(numpeaks) - 1; peakindex >= 0; --peakindex) {
364 bool goodfit =
false;
370 double peakleftbound, peakrightbound;
374 double predictpeakcentre = thispeak->centre();
376 infoss <<
"[DBx102] The " << numpeaks - 1 - peakindex <<
"-th rightmost peak's miller index = " << peakhkl[0]
377 <<
", " << peakhkl[1] <<
", " << peakhkl[2] <<
", predicted at TOF = " << thispeak->centre()
378 <<
"; User specify boundary = [" << peakleftbound <<
", " << peakrightbound <<
"].";
381 map<string, double> rightpeakparameters;
382 goodfit =
fitSinglePeakRobust(thispeak, std::dynamic_pointer_cast<BackgroundFunction>(backgroundfunction),
383 peakleftbound, peakrightbound, rightpeakparameters, chi2);
388 throw runtime_error(
"Failed to fit the right most peak. Unable to process. ");
390 stringstream robmsgss;
391 for (
auto &parname : peakparnames) {
392 robmsgss << parname <<
" = " << thispeak->getParameter(parname) <<
'\n';
394 g_log.
information() <<
"[DB1151] Robust Fit Result: Chi^2 = " << chi2 <<
'\n' << robmsgss.str();
396 rightpeak = thispeak;
400 refpeakshift = thispeak->centre() - predictpeakcentre;
402 g_log.
notice() <<
"[DBx332] Peak -" <<
static_cast<int>(numpeaks) - peakindex - 1
403 <<
": shifted = " << refpeakshift <<
'\n';
404 }
else if (!isrightmost) {
407 if (peakindex ==
static_cast<int>(numpeaks) - 1)
408 throw runtime_error(
"Impossible to have peak index as the right most peak here!");
410 double predictcentre = thispeak->centre();
413 double peakleftbound, peakrightbound;
414 observePeakRange(thispeak, rightpeak, refpeakshift, peakleftbound, peakrightbound);
418 for (
int i = 0; i < 10; ++i)
419 dbxss <<
"==\n[DBx323] Peak (" << peakhkl[0] <<
", " << peakhkl[1] <<
"," << peakhkl[2]
420 <<
"). Centre predicted @ TOF = " << predictcentre <<
". Observed range = " << peakleftbound <<
", "
431 map<string, double> rightpeakparameters;
433 goodfit =
fitSinglePeakRobust(thispeak, std::dynamic_pointer_cast<BackgroundFunction>(backgroundfunction),
434 peakleftbound, peakrightbound, rightpeakparameters, chi2);
441 rightpeak = thispeak;
442 refpeakshift = thispeak->centre() - predictcentre;
448 g_log.
warning() <<
"Fitting peak @ " << thispeak->centre() <<
" failed. \n";
453 double peakleftbound, peakrightbound;
457 infoss <<
"[DBx102] The " << numpeaks - 1 - peakindex <<
"-th rightmost peak's miller index = " << peakhkl[0]
458 <<
", " << peakhkl[1] <<
", " << peakhkl[2] <<
", predicted at TOF = " << thispeak->centre() <<
"; "
461 <<
", " << peakrightbound <<
"].";
475 double &peakleftbound,
double &peakrightbound) {
476 double predictcentre = thispeak->centre();
477 double rightfwhm = rightpeak->fwhm();
482 if (refpeakshift > 0) {
484 peakleftbound = predictcentre - rightfwhm;
485 peakrightbound = predictcentre + rightfwhm + refpeakshift;
488 peakleftbound = predictcentre - rightfwhm + refpeakshift;
489 peakrightbound = predictcentre + rightfwhm;
491 if (peakrightbound > rightpeak->centre() - 3 * rightpeak->fwhm()) {
495 peakrightbound = rightpeak->centre() - 3 * rightpeak->fwhm();
502 double peakcentre = vecX[icentre];
505 peakleftbound = vecX[icentre] - 4.0 * rightfwhm;
506 peakrightbound = vecX[icentre] + 4.0 * rightfwhm;
508 double rightpeakleftbound = rightpeak->centre() - 3 * rightfwhm;
509 if (peakrightbound > rightpeakleftbound) {
510 peakrightbound = rightpeakleftbound;
511 if (peakrightbound < 2.0 * rightfwhm + peakcentre)
512 g_log.
warning() <<
"Peak @ " << peakcentre <<
"'s right boundary is too close to its right peak!\n";
557 double peakrightbound,
const map<string, double> &rightpeakparammap,
561 g_log.
debug() <<
"[DB1208] Build partial workspace for peak @ " << peak->centre() <<
" (predicted).\n";
564 size_t rawdata_wsindex = 0;
565 size_t estbkgd_wsindex = 2;
566 size_t peak_wsindex = 1;
570 dbss <<
"[DBx203] Removed background peak data: \n";
571 for (
size_t i = 0; i < peakws->x(peak_wsindex).size(); ++i)
572 dbss << peakws->x(peak_wsindex)[i] <<
"\t\t" << peakws->y(peak_wsindex)[i] <<
"\t\t" << peakws->e(peak_wsindex)[i]
577 double centre, fwhm,
height;
584 throw runtime_error(errmsg);
586 g_log.
notice(
"Unable to observe peak parameters. Proceed to next peak.");
590 g_log.
notice() <<
"[FLAGx409] Peak proposed @ TOF = " << peak->centre() <<
" has a trivial "
591 <<
"peak height = " <<
height <<
" by observation. Skipped.\n";
595 <<
", Estimated (observation) Centre = " << centre <<
", FWHM = " << fwhm
596 <<
" Height = " <<
height <<
'\n';
605 vector<string> peakparnames = peak->getParameterNames();
606 for (
size_t i = 0; i < peakparnames.size(); ++i)
610 peak->setParameter(
"I",
height * fwhm);
611 peak->setParameter(
"X0", tof_h);
614 vector<string> minimizers(numsteps);
615 minimizers[0] =
"Simplex";
616 minimizers[1] =
"Levenberg-Marquardt";
617 vector<size_t> maxiterations(numsteps, 10000);
618 vector<double> dampfactors(numsteps, 0.0);
621 map<string, double> origparammap;
624 vector<double> chi2s;
625 vector<bool> goodfits;
626 vector<map<string, double>> solutions;
629 string peakinfoa0 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
630 g_log.
notice() <<
"[DBx533A] Approach A: Starting Peak Function Information: \n" << peakinfoa0 <<
'\n';
633 bool fitgooda =
doFit1PeakSequential(peakws, peak_wsindex, peak, minimizers, maxiterations, dampfactors, chi2a);
634 map<string, double> solutiona;
637 chi2s.emplace_back(chi2a);
638 goodfits.emplace_back(fitgooda);
639 solutions.emplace_back(solutiona);
641 string peakinfoa1 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
642 g_log.
notice() <<
"[DBx533A] Approach A: Fit Successful = " << fitgooda <<
", Chi2 = " << chi2a
643 <<
", Peak Function Information: \n"
644 << peakinfoa1 <<
'\n';
648 peak->setParameter(
"S",
sigma);
650 string peakinfob0 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
651 g_log.
notice() <<
"[DBx533B] Approach B: Starting Peak Function Information: \n" << peakinfob0 <<
'\n';
654 bool fitgoodb =
doFit1PeakSequential(peakws, peak_wsindex, peak, minimizers, maxiterations, dampfactors, chi2b);
656 map<string, double> solutionb;
659 chi2s.emplace_back(chi2b);
660 goodfits.emplace_back(fitgoodb);
661 solutions.emplace_back(solutionb);
663 string peakinfob1 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
664 g_log.
notice() <<
"[DBx533B] Approach 2: Fit Successful = " << fitgoodb <<
", Chi2 = " << chi2b
665 <<
", Peak Function Information: \n"
666 << peakinfob1 <<
'\n';
669 if (!rightpeakparammap.empty()) {
671 peak->setParameter(
"X0", tof_h);
672 peak->setParameter(
"I",
height * fwhm);
674 string peakinfoc0 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
675 g_log.
notice() <<
"[DBx533C] Approach C: Starting Peak Function Information: \n" << peakinfoc0 <<
'\n';
678 bool fitgoodc =
doFit1PeakSequential(peakws, peak_wsindex, peak, minimizers, maxiterations, dampfactors, chi2c);
679 map<string, double> solutionc;
682 chi2s.emplace_back(chi2c);
683 goodfits.emplace_back(fitgoodc);
684 solutions.emplace_back(solutionc);
686 string peakinfoc1 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
687 g_log.
notice() <<
"[DBx533C] Approach C: Fit Successful = " << fitgoodc <<
", Chi2 = " << chi2c
688 <<
", Peak Function Information: \n"
689 << peakinfoc1 <<
'\n';
692 chi2s.emplace_back(DBL_MAX);
693 goodfits.emplace_back(
false);
694 solutions.emplace_back(rightpeakparammap);
698 size_t bestapproach = goodfits.size() + 1;
699 double bestchi2 = DBL_MAX;
700 for (
size_t i = 0; i < goodfits.size(); ++i) {
701 if (goodfits[i] && chi2s[i] < bestchi2) {
707 stringstream fitsumss;
708 fitsumss <<
"Best fit result is obtained by approach " << bestapproach <<
" of total " << goodfits.size()
709 <<
" approaches. Best Chi^2 = " << bestchi2 <<
", Peak Height = " << peak->height();
710 g_log.
notice() <<
"[DB1127] " << fitsumss.str() <<
'\n';
713 if (bestapproach < goodfits.size()) {
721 peak->setParameter(
"S",
sigma);
722 peak->setParameter(
"I",
height * fwhm);
723 peak->setParameter(
"X0", tof_h);
725 vector<string> paramsinmc{
"A",
"B"};
734 bool fitcompfunsuccess =
doFit1PeakBackground(peakws, rawdata_wsindex, peak, backgroundfunction, chi2compf);
735 if (fitcompfunsuccess) {
736 finalchi2 = chi2compf;
738 finalchi2 = bestchi2;
739 g_log.
warning(
"Fit peak-background composite function failed! Need to "
740 "find out how this case peak value is changed from best "
745 finalchi2 = bestchi2;
763 string minimzername(
"Levenberg-MarquardtMD");
764 double startx = peak->centre() - 3.0 * peak->fwhm();
765 double endx = peak->centre() + 3.0 * peak->fwhm();
769 compfunc->addFunction(peak);
770 compfunc->addFunction(backgroundfunction);
773 vector<string> comparnames = compfunc->getParameterNames();
774 for (
size_t ipar = 0; ipar < comparnames.size(); ++ipar)
775 compfunc->unfix(ipar);
779 g_log.
notice() <<
"[DBx533X-0] Fit All: Starting Peak Function Information: \n"
780 << cominfoa <<
"Fit range = " << startx <<
", " << endx <<
'\n';
784 fitalg->initialize();
786 fitalg->setProperty(
"Function", std::dynamic_pointer_cast<API::IFunction>(compfunc));
787 fitalg->setProperty(
"InputWorkspace", dataws);
788 fitalg->setProperty(
"WorkspaceIndex",
static_cast<int>(wsindex));
789 fitalg->setProperty(
"Minimizer", minimzername);
790 fitalg->setProperty(
"CostFunction",
"Least squares");
791 fitalg->setProperty(
"MaxIterations", 1000);
792 fitalg->setProperty(
"Output",
"FitPeakBackground");
793 fitalg->setProperty(
"StartX", startx);
794 fitalg->setProperty(
"EndX", endx);
797 bool isexecute = fitalg->execute();
805 stringstream cominfob;
806 cominfob <<
"[DBx533X] Fit All: Fit Successful = " << fitsuccess <<
", Chi^2 = " << chi2 <<
'\n';
807 cominfob <<
"Detailed info = " << fitresult <<
'\n';
813 g_log.
notice() <<
"[DB1203B] Failed To Fit Peak+Background @ " << peak->centre() <<
'\n';
824 const vector<string> ¶mtodomc) {
827 throw runtime_error(
"To Be Implemented Soon!");
1030 backgroundfunction->setAttributeValue(
"n", 1);
1031 backgroundfunction->initialize();
1039 while (ipeak >= 0) {
1041 vector<size_t> indexpeakgroup;
1043 bool makegroup =
true;
1052 indexpeakgroup.emplace_back(ipeak);
1062 double thispeakleftbound = thispeak->centre() - thispeak->fwhm() * 2.5;
1064 double leftpeakrightbound = leftpeak->centre() + leftpeak->fwhm() * 2.5;
1065 if (thispeakleftbound > leftpeakrightbound) {
1072 if (indexpeakgroup.size() == 1) {
1074 const size_t ifit = indexpeakgroup[0];
1075 double peakfitleftbound, peakfitrightbound;
1079 <<
")\t----------------------------------\n";
1082 bool annihilatedpeak;
1086 if (annihilatedpeak)
1087 thispeak->setHeight(0.0);
1092 dbss <<
"Peak [" << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
"] expected @ TOF = " << thispeak->centre()
1094 if (annihilatedpeak)
1095 dbss <<
"Annihilated!";
1097 dbss <<
"Fit Status = " <<
m_goodFit[ifit] <<
", Chi2 = " << chi2;
1101 vector<BackToBackExponential_sptr> peaksgroup;
1102 for (
auto ipk : indexpeakgroup) {
1104 peaksgroup.emplace_back(temppeak);
1131 double rightbound,
double &chi2,
bool &annhilatedpeak) {
1134 if (leftbound < 0 || leftbound >= peak->centre())
1135 leftbound = peak->centre() - 5 * peak->fwhm();
1136 if (rightbound < 0 || rightbound <= peak->centre())
1137 rightbound = peak->centre() + 5 * peak->fwhm();
1146 dbss2 <<
"[T] Partial workspace No Background: \n";
1147 for (
size_t i = 0; i < peakdataws->x(1).size(); ++i)
1148 dbss2 << peakdataws->x(1)[i] <<
"\t\t" << peakdataws->y(1)[i] <<
"\t\t" << peakdataws->e(1)[i] <<
"\t\t"
1149 << peakdataws->y(0)[i] <<
'\n';
1153 size_t imaxheight =
findMaxValue(peakdataws->y(1).rawData());
1154 double maxheight = peakdataws->y(1)[imaxheight];
1158 annhilatedpeak =
true;
1162 annhilatedpeak =
false;
1167 double peakcentreleftbound = peak->centre() - peak->fwhm();
1168 double peakcentrerightbound = peak->centre() + peak->fwhm();
1169 auto x0bc = std::make_unique<BoundaryConstraint>(peak.get(),
"X0", peakcentreleftbound, peakcentrerightbound);
1170 peak->addConstraint(std::move(x0bc));
1173 auto abc = std::make_unique<BoundaryConstraint>(peak.get(),
"A", 1.0E-10,
false);
1174 peak->addConstraint(std::move(abc));
1177 auto bbc = std::make_unique<BoundaryConstraint>(peak.get(),
"B", 1.0E-10,
false);
1178 peak->addConstraint(std::move(bbc));
1181 peak->setHeight(maxheight);
1185 dbss0 <<
"[DBx100] Peak @" << peak->centre() <<
", FWHM = " << peak->fwhm() <<
'\n';
1186 vector<string> peakparams = peak->getParameterNames();
1187 for (
size_t i = 0; i < peakparams.size(); ++i)
1188 dbss0 << peakparams[i] <<
" = " << peak->getParameter(i) <<
'\n';
1192 vector<string> peakparamnames = peak->getParameterNames();
1193 vector<map<string, double>> fitparamvaluemaps;
1194 vector<pair<double, size_t>> chi2indexvec;
1197 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1198 string &parname = peakparams[iparam];
1200 peak->unfix(iparam);
1205 bool goodfit1 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2height);
1208 map<string, double> step1params;
1210 fitparamvaluemaps.emplace_back(step1params);
1212 chi2height = 1.0E20;
1213 chi2indexvec.emplace_back(chi2height, 0);
1216 vector<string> bkgdparnames = backgroundfunction->getParameterNames();
1217 for (
size_t iname = 0; iname < bkgdparnames.size(); ++iname)
1218 backgroundfunction->fix(iname);
1222 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam)
1223 peak->unfix(iparam);
1224 bool goodfitA =
doFit1PeakSimple(peakdataws, 1, peak,
"Simplex", 10000, chi2planA);
1227 map<string, double> planAparams;
1231 fitparamvaluemaps.emplace_back(planAparams);
1232 chi2indexvec.emplace_back(chi2planA, 1);
1240 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1241 string parname = peakparams[iparam];
1245 peak->unfix(iparam);
1247 bool goodfitB1 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2planB);
1250 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1251 string parname = peakparams[iparam];
1252 if (parname ==
"A" || parname ==
"I")
1253 peak->unfix(iparam);
1257 bool goodfitB2 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2planB);
1259 bool goodfitB = goodfitB1 || goodfitB2;
1260 map<string, double> planBparams;
1264 fitparamvaluemaps.emplace_back(planBparams);
1265 chi2indexvec.emplace_back(chi2planB, 2);
1273 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1274 string parname = peakparams[iparam];
1278 peak->unfix(iparam);
1280 bool goodfitC1 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2planC);
1283 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1284 string parname = peakparams[iparam];
1288 peak->unfix(iparam);
1290 bool goodfitC2 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2planB);
1292 bool goodfitC = goodfitC1 || goodfitC2;
1293 map<string, double> planCparams;
1297 fitparamvaluemaps.emplace_back(planCparams);
1298 chi2indexvec.emplace_back(chi2planC, 3);
1302 sumss <<
"[DBx833] Confident fit on peak summary: \n";
1303 for (
size_t i = 0; i < 4; ++i)
1304 sumss <<
"Index " << i <<
": chi^2 = " << chi2indexvec[i].first <<
'\n';
1307 sort(chi2indexvec.begin(), chi2indexvec.end());
1310 if (chi2indexvec[0].first < 1.0E19) {
1312 size_t goodindex = chi2indexvec[0].second;
1314 chi2 = chi2indexvec[0].first;
1329 errss <<
"Fit Peak @ " << peak->centre() <<
" Error! Chi^2 (false) = " << chi2
1330 <<
". Do Not Know How To Proceed To Next Peak!";
1332 throw runtime_error(errss.str());
1336 vector<string> parnames = peak->getParameterNames();
1337 stringstream debugss;
1338 debugss <<
"DB1251 Single Peak Confident Fit Result: Chi^2 = " << chi2 <<
'\n';
1339 for (
auto &parname : parnames) {
1340 debugss << parname <<
" = " << peak->getParameter(parname) <<
'\n';
1360 double &peakrightboundary) {
1367 int ileftneighbor =
static_cast<int>(ileftpeak) - 1;
1368 if (ileftneighbor < 0) {
1375 double leftneighborrightbound = leftneighbor->centre() +
PEAKBOUNDARYFACTOR * leftneighbor->fwhm();
1376 if (leftneighborrightbound > peakleftboundary)
1377 peakleftboundary = leftneighborrightbound;
1383 size_t irightneighbor = irightpeak + 1;
1387 double rightneighborleftbound = rightneighbor->centre() -
PEAKBOUNDARYFACTOR * rightneighbor->fwhm();
1388 if (rightneighborleftbound < peakrightboundary)
1389 peakrightboundary = rightneighborleftbound;
1409 double guessedfwhm) {
1411 if (guessedfwhm > 0) {
1412 double tof_h = peakfunction->centre();
1413 double centerleftend = tof_h - guessedfwhm * 3.0;
1414 double centerrightend = tof_h + guessedfwhm * 3.0;
1416 std::make_unique<BoundaryConstraint>(peakfunction.get(),
"X0", centerleftend, centerrightend,
false);
1417 peakfunction->addConstraint(std::move(centerbound));
1419 g_log.
debug() <<
"[DoFitPeak] Peak Center Boundary = " << centerleftend <<
", " << centerrightend <<
'\n';
1423 auto abound = std::make_unique<BoundaryConstraint>(peakfunction.get(),
"A", 0.0000001, DBL_MAX,
false);
1424 peakfunction->addConstraint(std::move(abound));
1426 auto bbound = std::make_unique<BoundaryConstraint>(peakfunction.get(),
"B", 0.0000001, DBL_MAX,
false);
1427 peakfunction->addConstraint(std::move(bbound));
1429 auto sbound = std::make_unique<BoundaryConstraint>(peakfunction.get(),
"S", 0.0001, DBL_MAX,
false);
1430 peakfunction->addConstraint(std::move(sbound));
1433 vector<string> paramnames = peakfunction->getParameterNames();
1434 size_t numparams = paramnames.size();
1435 for (
size_t i = 0; i < numparams; ++i)
1436 peakfunction->unfix(i);
1439 vector<vector<string>> vecMinimizers;
1440 vector<vector<size_t>> vecMaxIterations;
1441 vector<vector<double>> vecDampings;
1455 vector<string> minimizers2(3);
1456 minimizers2[0] =
"Simplex";
1457 minimizers2[1] =
"Levenberg-MarquardtMD";
1458 minimizers2[2] =
"Levenberg-Marquardt";
1459 vector<size_t> maxiterations2(3, 1000);
1460 maxiterations2[0] = 10000;
1461 vector<double> dampings2(3, 0.0);
1462 vecMinimizers.emplace_back(minimizers2);
1463 vecMaxIterations.emplace_back(maxiterations2);
1464 vecDampings.emplace_back(dampings2);
1467 bool goodfit =
false;
1468 size_t numschemes = vecMinimizers.size();
1470 map<string, double> origparams, bestparams;
1472 bestparams = origparams;
1473 double bestchi2 = DBL_MAX;
1475 for (
size_t is = 0; is < numschemes; ++is) {
1481 bool localgoodfit =
doFit1PeakSequential(dataws, 1, peakfunction, vecMinimizers[is], vecMaxIterations[is],
1482 vecDampings[is], thischi2);
1485 if (localgoodfit && !goodfit) {
1487 bestchi2 = thischi2;
1490 }
else if (localgoodfit && goodfit) {
1492 if (thischi2 < bestchi2) {
1493 bestchi2 = thischi2;
1499 pair<bool, double> returnvalue = make_pair(goodfit, bestchi2);
1508 vector<string> paramnames = function->getParameterNames();
1510 for (
auto ¶mname : paramnames)
1511 parammaps.emplace(paramname, function->getParameter(paramname));
1518 vector<string> paramnames = function->getParameterNames();
1519 for (
auto &parname : paramnames) {
1520 auto miter = parammap.find(parname);
1521 if (miter != parammap.end())
1522 function->setParameter(parname, miter->second);
1541 size_t maxiteration,
double &chi2) {
1543 dbss << peakfunction->asString() <<
'\n';
1544 dbss <<
"Starting Value: ";
1545 vector<string> names = peakfunction->getParameterNames();
1546 for (
auto &
name : names)
1547 dbss <<
name <<
"= " << peakfunction->getParameter(
name) <<
", \t";
1548 for (
size_t i = 0; i < dataws->x(workspaceindex).size(); ++i)
1549 dbss << dataws->x(workspaceindex)[i] <<
"\t\t" << dataws->y(workspaceindex)[i] <<
"\t\t"
1550 << dataws->e(workspaceindex)[i] <<
'\n';
1551 g_log.
debug() <<
"DBx430 " << dbss.str() <<
'\n';
1554 if (peakfunction->height() < 1.0E-5)
1555 peakfunction->setHeight(4.0);
1559 fitalg->initialize();
1562 fitalg->setProperty(
"Function", std::dynamic_pointer_cast<API::IFunction>(peakfunction));
1563 fitalg->setProperty(
"InputWorkspace", dataws);
1564 fitalg->setProperty(
"WorkspaceIndex",
static_cast<int>(workspaceindex));
1565 fitalg->setProperty(
"Minimizer", minimzername);
1566 fitalg->setProperty(
"CostFunction",
"Least squares");
1567 fitalg->setProperty(
"MaxIterations",
static_cast<int>(maxiteration));
1568 fitalg->setProperty(
"Output",
"FitPeak");
1571 bool isexecute = fitalg->execute();
1572 bool fitsuccess =
false;
1576 std::string fitresult =
parseFitResult(fitalg, chi2, fitsuccess);
1579 g_log.
information() <<
"[DBx138A] Fit Peak @ " << peakfunction->centre() <<
" Result:" << fitsuccess <<
"\n"
1580 <<
"Detailed info = " << fitresult <<
", Chi^2 = " << chi2 <<
'\n';
1587 g_log.
error() <<
"[DBx128B] Failed to execute fitting peak @ " << peakfunction->centre() <<
'\n';
1605 vector<string> minimzernames, vector<size_t> maxiterations,
1606 const vector<double> &dampfactors,
double &chi2) {
1608 if (minimzernames.size() != maxiterations.size() && minimzernames.size() != dampfactors.size()) {
1609 throw runtime_error(
"doFit1PeakSequential should have the input vectors of same size.");
1613 map<string, double> parambeforefit;
1617 doFit1PeakSimple(dataws, workspaceindex, peakfunction,
"Levenberg-MarquardtMD", 0, startchi2);
1621 double currchi2 = startchi2;
1622 bool goodfit =
false;
1625 for (
size_t i = 0; i < minimzernames.size(); ++i) {
1626 string minimizer = minimzernames[i];
1627 size_t maxiteration = maxiterations[i];
1628 g_log.
notice() <<
"DBx315 Start Chi2 = " << startchi2 <<
", Minimizer = " << minimizer
1629 <<
", Max Iterations = " << maxiteration <<
", Workspace Index = " << workspaceindex
1630 <<
", Data Range = " << dataws->x(workspaceindex)[0] <<
", " << dataws->x(workspaceindex).back()
1636 bool localgoodfit =
doFit1PeakSimple(dataws, workspaceindex, peakfunction, minimizer, maxiteration, newchi2);
1638 if (localgoodfit && newchi2 < currchi2) {
1645 g_log.
information() <<
"DBx315C Fit Failed. Fit Good = " << localgoodfit <<
'\n';
1659 double in_center,
double leftfwhm,
double rightfwhm,
double ¢er,
1662 const auto &
X = dataws->x(workspaceindex);
1663 const auto &
Y = dataws->y(workspaceindex);
1666 for (
size_t i = 1; i <
X.size(); ++i) {
1669 sigma = (leftfwhm + rightfwhm) * 0.5;
1673 auto gaussianpeak = std::dynamic_pointer_cast<API::IPeakFunction>(temppeak);
1674 gaussianpeak->setHeight(
height);
1675 gaussianpeak->setCentre(in_center);
1676 gaussianpeak->setFwhm(
sigma);
1679 double centerleftend = in_center - leftfwhm * 0.5;
1680 double centerrightend = in_center + rightfwhm * 0.5;
1682 std::make_unique<BoundaryConstraint>(gaussianpeak.get(),
"PeakCentre", centerleftend, centerrightend,
false);
1683 gaussianpeak->addConstraint(std::move(centerbound));
1687 fitalg->initialize();
1689 fitalg->setProperty(
"Function", std::dynamic_pointer_cast<API::IFunction>(gaussianpeak));
1690 fitalg->setProperty(
"InputWorkspace", dataws);
1691 fitalg->setProperty(
"WorkspaceIndex", 1);
1692 fitalg->setProperty(
"Minimizer",
"Levenberg-MarquardtMD");
1693 fitalg->setProperty(
"CostFunction",
"Least squares");
1694 fitalg->setProperty(
"MaxIterations", 1000);
1695 fitalg->setProperty(
"Output",
"FitGaussianPeak");
1698 bool successfulfit = fitalg->execute();
1699 if (!fitalg->isExecuted() || !successfulfit) {
1701 g_log.
warning() <<
"Fitting Gaussian peak for peak around " << gaussianpeak->centre() <<
'\n';
1707 std::string fitresult =
parseFitResult(fitalg, chi2, fitsuccess);
1708 g_log.
information() <<
"[Fit Gaussian Peak] Successful = " << fitsuccess <<
", Result:\n" << fitresult <<
'\n';
1711 center = gaussianpeak->centre();
1712 height = gaussianpeak->height();
1713 double fwhm = gaussianpeak->fwhm();
1717 sigma = fwhm / 2.35;
1722 g_log.
information() <<
"[DBx133] Fitted Gaussian Parameters: \n" << infofit <<
'\n';
1736 vector<pair<double, BackToBackExponential_sptr>> tofpeakpairs(peaks.size());
1737 for (
size_t i = 0; i < peaks.size(); ++i)
1738 tofpeakpairs[i] = make_pair(peaks[i]->centre(), peaks[i]);
1739 sort(tofpeakpairs.begin(), tofpeakpairs.end());
1744 double peaksleftboundary, peaksrightboundary;
1747 peaksleftboundary = leftpeak->centre() - 4 * leftpeak->fwhm();
1748 peaksrightboundary = rightpeak->centre() + 4 * rightpeak->fwhm();
1751 peaksleftboundary = leftpeak->centre() - 4 * gfwhm;
1752 peaksrightboundary = rightpeak->centre() + 4 * gfwhm;
1763 piss << peaks.size() <<
"-Peaks Group Information: \n";
1764 for (
size_t ipk = 0; ipk < tofpeakpairs.size(); ++ipk) {
1766 piss <<
"Peak " << ipk <<
" @ TOF = " << tmppeak->centre() <<
", A = " << tmppeak->getParameter(
"A")
1767 <<
", B = " << tmppeak->getParameter(
"B") <<
", S = " << tmppeak->getParameter(
"S")
1768 <<
", FWHM = " << tmppeak->fwhm() <<
'\n';
1772 stringstream datass;
1773 datass <<
"Partial workspace for peaks: \n";
1774 for (
size_t i = 0; i < peaksws->x(0).size(); ++i)
1775 datass << peaksws->x(1)[i] <<
"\t\t" << peaksws->y(1)[i] <<
"\t\t" << peaksws->e(1)[i] <<
"\t\t" << peaksws->y(0)[i]
1787 for (
auto &peak : peaks)
1788 peaksfunction->addFunction(peak);
1791 vector<double> chi2s;
1792 vector<bool> fitgoods;
1793 bool fitsuccess =
doFitMultiplePeaks(peaksws, 1, peaksfunction, peaks, fitgoods, chi2s);
1798 plotFunction(peaksfunction, backgroundfunction, domain);
1809 vector<BackToBackExponential_sptr> peakfuncs, vector<bool> &vecfitgood,
1810 vector<double> &vecchi2s) {
1813 dbss <<
"[DBx529] Composite Function: " << peaksfunc->asString();
1817 const size_t numpeaks = peakfuncs.size();
1818 map<string, double> peaksfuncparams;
1821 vector<string> peakparnames = peakfuncs[0]->getParameterNames();
1822 for (
size_t ipn = 0; ipn < peakparnames.size(); ++ipn) {
1823 bool isI = peakparnames[ipn] ==
"I";
1825 for (
size_t ipk = 0; ipk < numpeaks; ++ipk) {
1828 thispeak->unfix(ipn);
1835 dbss1 <<
"[DBx529A] Composite Function: " << peaksfunc->asString();
1840 bool fitgood =
doFitNPeaksSimple(dataws, wsindex, peaksfunc, peakfuncs,
"Levenberg-MarquardtMD", 1000, chi2);
1841 bool evergood = fitgood;
1845 vecfitgood.resize(numpeaks,
false);
1846 vecchi2s.resize(numpeaks, -1.0);
1849 vecfitgood.resize(numpeaks,
true);
1850 vecchi2s.resize(numpeaks, chi2);
1854 for (
size_t ipkfit = 0; ipkfit < numpeaks; ++ipkfit) {
1856 for (
size_t ipk = 0; ipk < numpeaks; ++ipk) {
1858 for (
size_t iparam = 0; iparam < peakparnames.size(); ++iparam) {
1859 if (ipk == ipkfit) {
1861 thispeak->unfix(iparam);
1864 thispeak->fix(iparam);
1872 fitgood =
doFitNPeaksSimple(dataws, wsindex, peaksfunc, peakfuncs,
"Levenberg-MarquardtMD", 1000, chi2);
1883 for (
size_t ipk = 0; ipk < numpeaks; ++ipk) {
1885 for (
size_t iparam = 0; iparam < peakparnames.size(); ++iparam)
1886 thispeak->unfix(iparam);
1890 fitgood =
doFitNPeaksSimple(dataws, wsindex, peaksfunc, peakfuncs,
"Levenberg-MarquardtMD", 1000, chi2);
1900 peaksfunc->function(domain, values);
1902 for (
size_t i = 0; i < domain.
size(); ++i)
1903 rss << domain[i] <<
"\t\t" << values[i] <<
'\n';
1904 g_log.
information() <<
"[T] Multiple peak fitting pattern:\n" << rss.str();
1916 vector<BackToBackExponential_sptr> peaks) {
1920 vector<vector<double>> peakvalues;
1921 for (
size_t i = 0; i < (peaks.size() + 1); ++i) {
1922 vector<double> peakvalue(domain.
size(), 0.0);
1923 peakvalues.emplace_back(peakvalue);
1927 size_t isum = peaks.size();
1928 for (
size_t ipk = 0; ipk < peaks.size(); ++ipk) {
1930 thispeak->setHeight(1.0);
1931 thispeak->function(domain, values);
1932 for (
size_t j = 0; j < domain.
size(); ++j) {
1933 peakvalues[ipk][j] = values[j];
1934 peakvalues[isum][j] += values[j];
1939 const auto &vecY = dataws->y(wsindex);
1940 for (
size_t ipk = 0; ipk < peaks.size(); ++ipk) {
1942 for (
size_t j = 0; j < domain.
size() - 1; ++j) {
1943 if (vecY[j] > 0.0 && peakvalues[isum][j] > 1.0E-5) {
1944 double dtof = domain[j + 1] - domain[j];
1945 double temp = vecY[j] * peakvalues[ipk][j] / peakvalues[isum][j] * dtof;
1951 thispeak->setHeight(
height);
1954 <<
" Set Guessed Height (LeBail) = " << thispeak->height() <<
'\n';
1962 for (
const auto &thispeak : peaks) {
1964 double fwhm = thispeak->fwhm();
1965 double centre = thispeak->centre();
1966 double leftcentrebound = centre - 0.5 * fwhm;
1967 double rightcentrebound = centre + 0.5 * fwhm;
1969 auto bc = std::make_unique<BoundaryConstraint>(thispeak.get(),
"X0", leftcentrebound, rightcentrebound,
false);
1970 thispeak->addConstraint(std::move(bc));
1979 const vector<BackToBackExponential_sptr> &peakfuncs,
1980 const string &minimizername,
size_t maxiteration,
double &chi2) {
1983 dbss0 <<
"Starting Value: ";
1984 vector<string> names = peaksfunc->getParameterNames();
1985 for (
auto &
name : names)
1986 dbss0 <<
name <<
"= " << peaksfunc->getParameter(
name) <<
", \t";
1991 fitalg->initialize();
1994 fitalg->setProperty(
"Function", std::dynamic_pointer_cast<API::IFunction>(peaksfunc));
1995 fitalg->setProperty(
"InputWorkspace", dataws);
1996 fitalg->setProperty(
"WorkspaceIndex",
static_cast<int>(wsindex));
1997 fitalg->setProperty(
"Minimizer", minimizername);
1998 fitalg->setProperty(
"CostFunction",
"Least squares");
1999 fitalg->setProperty(
"MaxIterations",
static_cast<int>(maxiteration));
2000 fitalg->setProperty(
"Output",
"FitPeak");
2003 bool isexecute = fitalg->execute();
2004 bool fitsuccess =
false;
2009 dbss <<
"Fit N-Peaks @ ";
2010 for (
auto &peakfunc : peakfuncs)
2011 dbss << peakfunc->centre() <<
", ";
2015 std::string fitresult =
parseFitResult(fitalg, chi2, fitsuccess);
2017 dbss <<
" Result:" << fitsuccess <<
"\n"
2018 <<
"Detailed info = " << fitresult;
2025 g_log.
information() <<
"[DBx149B] Fitted Parameters: \n" << infofit <<
'\n';
2027 dbss <<
": Failed ";
2028 g_log.
error() <<
"[DBx149C] " << dbss.str() <<
'\n';
2042 chi2 = fitalg->getProperty(
"OutputChi2overDoF");
2043 string fitstatus = fitalg->getProperty(
"OutputStatus");
2045 fitsuccess = (fitstatus ==
"success");
2047 rss <<
" [Algorithm Fit]: Chi^2 = " << chi2 <<
"; Fit Status = " << fitstatus;
2058 g_log.
warning() <<
"Input table workspace is NULL. \n";
2063 std::stringstream msgss;
2064 size_t numrows = paramws->rowCount();
2065 for (
size_t i = 0; i < numrows; ++i) {
2067 std::string parname;
2068 double parvalue, parerror;
2069 row >> parname >> parvalue >> parerror;
2071 msgss << parname <<
" = " << setw(10) << setprecision(5) << parvalue <<
" +/- " << setw(10) << setprecision(5)
2072 << parerror <<
'\n';
2086 std::vector<std::string> colnames = parameterWS->getColumnNames();
2087 if (colnames.size() < 2) {
2089 errss <<
"Input parameter table workspace does not have enough number of "
2091 <<
" Number of columns = " << colnames.size() <<
" >= 2 as required. ";
2093 throw std::runtime_error(errss.str());
2096 if (colnames[0] !=
"Name" || colnames[1] !=
"Value") {
2098 errss <<
"Input parameter table workspace does not have the columns in "
2100 <<
"Name, Value and etc. ";
2102 throw std::runtime_error(errss.str());
2105 size_t numrows = parameterWS->rowCount();
2107 g_log.
notice() <<
"[DBx409] Import TableWorkspace " << parameterWS->getName() <<
" containing " << numrows
2108 <<
" instrument profile parameters\n";
2111 std::string parname;
2115 for (
size_t ir = 0; ir < numrows; ++ir) {
2117 trow >> parname >>
value;
2119 g_log.
notice() <<
"[DBx211] Import parameter " << parname <<
": " <<
value <<
'\n';
2126 vector<map<string, int>> &hklmaps) {
2128 vector<string> paramnames = peakws->getColumnNames();
2129 size_t numcols = paramnames.size();
2130 vector<string> coltypes(numcols);
2131 for (
size_t i = 0; i < numcols; ++i) {
2133 string coltype = col->type();
2134 coltypes[i] = coltype;
2138 size_t numrows = peakws->rowCount();
2139 for (
size_t irow = 0; irow < numrows; ++irow) {
2141 map<string, int> intmap;
2142 map<string, double> doublemap;
2145 for (
size_t icol = 0; icol < numcols; ++icol) {
2146 string coltype = coltypes[icol];
2147 string colname = paramnames[icol];
2149 if (coltype ==
"int") {
2151 int temp = peakws->cell<
int>(irow, icol);
2152 intmap.emplace(colname, temp);
2153 }
else if (coltype ==
"double") {
2155 double temp = peakws->cell<
double>(irow, icol);
2156 doublemap.emplace(colname, temp);
2161 parammaps.emplace_back(doublemap);
2162 hklmaps.emplace_back(intmap);
2166 g_log.
information() <<
"Import " << hklmaps.size() <<
" entries from Bragg peak TableWorkspace " << peakws->getName()
2176 const auto &
X =
m_dataWS->x(workspaceindex);
2178 if (pattern.size() !=
X.size()) {
2179 stringstream errmsg;
2180 errmsg <<
"Input pattern (" << pattern.size() <<
") and algorithm's input workspace (" <<
X.size()
2181 <<
") have different size. ";
2183 throw std::logic_error(errmsg.str());
2186 size_t numpts =
X.size();
2193 for (
size_t iw = 0; iw < 5; ++iw) {
2194 dataws->setSharedX(iw,
m_dataWS->sharedX(workspaceindex));
2197 dataws->setSharedY(0,
m_dataWS->sharedY(workspaceindex));
2198 dataws->mutableY(1) = pattern;
2199 dataws->mutableY(2) =
m_dataWS->y(workspaceindex) - pattern;
2203 std::ofstream ofile;
2204 ofile.open(
"fittedpeaks.dat");
2205 for (
size_t i = 0; i < numpts; ++i) {
2206 ofile << setw(12) << setprecision(5) <<
X[i] << setw(12) << setprecision(5) << pattern[i] << setw(12)
2207 << setprecision(5) << dataws->y(0)[i] << setw(12) << setprecision(5) << dataws->y(2)[i] <<
'\n';
2220 throw runtime_error(
"Wrong definition of m_peakFitChi2");
2226 vector<double> vecdh, vectofh, vecalpha, vecbeta, vecsigma, vecchi2;
2227 for (
size_t i = 0; i < numpeaks; ++i) {
2234 double p_a = peak->getParameter(
"A");
2235 double p_b = peak->getParameter(
"B");
2236 double p_x = peak->getParameter(
"X0");
2237 double p_s = peak->getParameter(
"S");
2240 vecchi2.emplace_back(chi2);
2241 vecdh.emplace_back(dh);
2242 vectofh.emplace_back(p_x);
2243 vecalpha.emplace_back(p_a);
2244 vecbeta.emplace_back(p_b);
2245 vecsigma.emplace_back(p_s);
2250 size_t numgoodpeaks = vecdh.size();
2253 for (
size_t j = 0; j < 4; ++j) {
2254 paramws->mutableX(j) = vecdh;
2255 paramws->mutableE(j) = vecchi2;
2257 paramws->mutableY(0) = vectofh;
2258 paramws->mutableY(1) = vecalpha;
2259 paramws->mutableY(2) = vecbeta;
2260 paramws->mutableY(3) = vecsigma;
2263 paramws->getAxis(0)->setUnit(
"dSpacing");
2265 auto tAxis = std::make_unique<TextAxis>(4);
2266 tAxis->setLabel(0,
"X0");
2267 tAxis->setLabel(1,
"A");
2268 tAxis->setLabel(2,
"B");
2269 tAxis->setLabel(3,
"S");
2271 paramws->replaceAxis(1, std::move(tAxis));
2288 throw runtime_error(
"Wrong definition of m_peakFitChi2");
2292 vector<double> vectofh(numpeaks), vecalpha(numpeaks), vecbeta(numpeaks), vecsigma(numpeaks);
2298 tablews->addColumn(
"int",
"H");
2299 tablews->addColumn(
"int",
"K");
2300 tablews->addColumn(
"int",
"L");
2302 tablews->addColumn(
"double",
"d_h");
2303 tablews->addColumn(
"double",
"TOF_h");
2304 tablews->addColumn(
"double",
"Height");
2305 tablews->addColumn(
"double",
"Alpha");
2306 tablews->addColumn(
"double",
"Beta");
2307 tablews->addColumn(
"double",
"Sigma");
2308 tablews->addColumn(
"double",
"Chi2");
2318 for (
size_t i = 0; i < numpeaks; ++i) {
2326 TableRow newrow = tablews->appendRow();
2329 newrow << hkl[0] << hkl[1] << hkl[2] << dh;
2332 double p_a = peak->getParameter(
"A");
2333 double p_b = peak->getParameter(
"B");
2334 double p_i = peak->getParameter(
"I");
2335 double p_x = peak->getParameter(
"X0");
2336 double p_s = peak->getParameter(
"S");
2337 newrow << p_x << p_i << p_a << p_b << p_s;
2376 ztablews->addColumn(
"int",
"H");
2377 ztablews->addColumn(
"int",
"K");
2378 ztablews->addColumn(
"int",
"L");
2380 ztablews->addColumn(
"double",
"d_h");
2381 ztablews->addColumn(
"double",
"Z_TOF_h");
2382 ztablews->addColumn(
"double",
"Z_Alpha");
2383 ztablews->addColumn(
"double",
"Z_Beta");
2384 ztablews->addColumn(
"double",
"Z_Sigma");
2394 TableRow newrow = ztablews->appendRow();
2395 newrow << hkl[0] << hkl[1] << hkl[2] << dh;
2398 double p_x = zcentres[i];
2399 double p_a = zalphas[i];
2400 double p_b = zbetas[i];
2401 double p_s = zsigma[i];
2403 newrow << p_x << p_a << p_b << p_s;
2407 return make_pair(tablews, ztablews);
2419 errss <<
"Input tableworkspace for peak parameters is invalid!";
2421 throw std::invalid_argument(errss.str());
2433 vector<map<std::string, double>> peakparametermaps;
2434 vector<map<std::string, int>> peakhkls;
2439 map<string, string> bk2bk2braggmap{{
"A",
"Alpha"}, {
"B",
"Beta"}, {
"X0",
"TOF_h"},
2440 {
"I",
"Height"}, {
"S",
"Sigma"}, {
"S2",
"Sigma2"}};
2443 size_t numbadrows = 0;
2444 size_t numrows = peakparamws->rowCount();
2445 for (
size_t ir = 0; ir < numrows; ++ir) {
2466 dbss <<
"Specified range for peaks in TOF: " << tofmin <<
", " << tofmax <<
"\n";
2470 double d_h = deliter->first;
2471 vector<int> &hkl = deliter->second.first;
2473 double tofh = peak->getParameter(
"X0");
2475 dbss <<
"\tPeak (" << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
") @ d = " << d_h
2476 <<
" (calculated TOF) = " << tofh <<
" ";
2478 if (tofh < tofmin || tofh > tofmax) {
2481 dbss <<
": Delete due to out of range. \n";
2486 dbss <<
": Kept. \n";
2490 g_log.
notice() <<
"[DBx453] " << dbss.str() <<
"\n";
2496 vector<int> hkl = deliter->second.first;
2505 if (ind1stpeak > 0) {
2512 g_log.
warning() <<
"Minimum peak " << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
" does not exit. \n";
2519 vector<int> hkl = deliter->second.first;
2520 double d_h = deliter->first;
2521 double tof_h = deliter->second.second->centre();
2522 dbout <<
"Peak (" << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
") @ d = " << d_h <<
", TOF = " << tof_h <<
'\n';
2540 map<string, string> bk2bk2braggmap,
bool &good, vector<int> &hkl,
2544 newpeakptr->initialize();
2580 errss <<
"In input InstrumentParameterTable, one of the following is not "
2581 "given. Unable to process. \n";
2582 errss <<
"Tcross = " << tcross <<
"; Width = " << width <<
", Dtt1 = " << dtt1 <<
", Dtt1t = " << dtt1t <<
'\n';
2583 errss <<
"Dtt2t = " << dtt2t <<
", Zero = " << zero <<
", Zerot = " << zerot;
2586 throw runtime_error(errss.str());
2589 bool caltofonly =
false;
2594 g_log.
warning() <<
"[DBx343] At least one of the input instrument-peak "
2595 "profile parameters is not given. "
2596 <<
"Use (HKL) only!\n";
2597 g_log.
warning() <<
"Alph0 = " << alph0 <<
", Alph1 = " << alph1 <<
", Alph0t = " << alph0t
2598 <<
", Alph1t = " << alph1t <<
'\n';
2599 g_log.
warning() <<
"Beta0 = " << beta0 <<
", Beta1 = " << beta1 <<
", Beta0t = " << beta0t
2600 <<
", Beta1t = " << beta1t <<
'\n';
2601 g_log.
warning() <<
"Sig0 = " << sig0 <<
", Sig1 = " << sig1 <<
", Sig2 = " << sig2 <<
'\n';
2610 if ((d_h != d_h) || (d_h < -DBL_MAX) || (d_h > DBL_MAX)) {
2611 stringstream warnss;
2612 warnss <<
"Peak with Miller Index = " << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2]
2613 <<
" has unphysical d-spacing value = " << d_h;
2621 newpeakptr->setCentre(tof_h);
2632 for (
const auto &parname : tnb2bfuncparnames) {
2633 if (parname !=
"Height") {
2637 errss <<
"Cannot find peak parameter " << parname <<
" in input instrument parameter "
2638 <<
"TableWorkspace. This mode is unable to execute. Quit!";
2640 throw runtime_error(errss.str());
2642 double parvalue = miter->second;
2653 double tof_h = tnb2bfunc.
centre();
2655 newpeakptr->setParameter(
"A", alpha);
2656 newpeakptr->setParameter(
"B", beta);
2657 newpeakptr->setParameter(
"S", sqrt(sigma2));
2658 newpeakptr->setParameter(
"X0", tof_h);
2661 peakcalmode =
"Calculate all parameters by thermal neutron peak function.";
2666 vector<string>::iterator nameiter;
2669 string b2bexpname = *nameiter;
2671 map<string, string>::iterator refiter;
2672 refiter = bk2bk2braggmap.find(b2bexpname);
2673 if (refiter == bk2bk2braggmap.end())
2674 throw runtime_error(
"Programming error!");
2675 string instparname = refiter->second;
2678 map<string, double>::iterator miter;
2679 miter = parammap.find(instparname);
2680 if (miter != parammap.end()) {
2682 double parvalue = miter->second;
2683 if (b2bexpname ==
"S2") {
2684 newpeakptr->setParameter(
"S", sqrt(parvalue));
2686 newpeakptr->setParameter(b2bexpname, parvalue);
2691 peakcalmode =
"Import from Bragg peaks table";
2695 stringstream infoss;
2696 string peakinfo =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(newpeakptr));
2698 infoss <<
"Generate Peak (" << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
") Of Mode " << peakcalmode <<
".\n";
2719 double x0 = domain[0];
2720 auto viter = lower_bound(vecX.cbegin(), vecX.cend(), x0);
2721 int ix0 =
static_cast<int>(std::distance(vecX.cbegin(), viter));
2724 if ((
static_cast<int>(domain.
size()) + ix0) >
static_cast<int>(
m_peakData.size()))
2725 throw runtime_error(
"Plot single peak out of boundary error!");
2729 peakfunction->function(domain, values1);
2731 for (
int i = 0; i < static_cast<int>(domain.
size()); ++i)
2736 background->function(domain, values2);
2738 for (
int i = 0; i < static_cast<int>(domain.
size()); ++i)
2751 vector<string> strhkl(3);
2758 map<string, int>::iterator miter;
2759 for (
size_t i = 0; i < 3; ++i) {
2760 string parname = strhkl[i];
2761 miter = intmap.find(parname);
2762 if (miter == intmap.end())
2765 hkl.emplace_back(miter->second);
2778 cropalg->initialize();
2780 cropalg->setProperty(
"InputWorkspace",
m_dataWS);
2781 cropalg->setPropertyValue(
"OutputWorkspace",
"MyData");
2782 cropalg->setProperty(
"XMin", tofmin);
2783 cropalg->setProperty(
"XMax", tofmax);
2785 bool cropstatus = cropalg->execute();
2787 std::stringstream errmsg;
2789 errmsg <<
"DBx309 Cropping workspace unsuccessful. Fatal Error. Quit!";
2791 throw std::runtime_error(errmsg.str());
2794 m_dataWS = cropalg->getProperty(
"OutputWorkspace");
2796 errmsg <<
"Unable to retrieve a Workspace2D object from ChildAlgorithm Crop.";
2798 throw std::runtime_error(errmsg.str());
2811 map<string, double>::iterator mapiter;
2817 <<
"does not have parameter " << parname <<
". ";
2822 return mapiter->second;
2833 size_t workspaceindex,
double leftbound,
double rightbound) {
2835 const auto &
X = sourcews->x(workspaceindex);
2836 const auto &
Y = sourcews->y(workspaceindex);
2837 const auto &E = sourcews->e(workspaceindex);
2839 if (leftbound >= rightbound) {
2840 stringstream errmsg;
2841 errmsg <<
"[BuildPartialWorkspace] Input left boundary = " << leftbound <<
" is larger than input right boundary "
2842 << rightbound <<
". It is not allowed. ";
2843 throw std::invalid_argument(errmsg.str());
2845 if (leftbound >=
X.back() || rightbound <=
X[0]) {
2846 throw std::invalid_argument(
"Boundary is out side of the input data set. ");
2850 int ileft =
static_cast<int>(std::lower_bound(
X.begin(),
X.end(), leftbound) -
X.begin());
2853 int iright =
static_cast<int>(std::lower_bound(
X.begin(),
X.end(), rightbound) -
X.begin());
2854 if (iright >=
static_cast<int>(
X.size()))
2855 iright =
static_cast<int>(
X.size() - 1);
2857 auto wssize =
static_cast<size_t>(iright - ileft + 1);
2866 for (
size_t iw = 0; iw < partws->getNumberHistograms(); ++iw) {
2868 for (
size_t i = 0; i < wssize; ++i) {
2869 nX[i] =
X[i + ileft];
2872 auto &nY = partws->mutableY(0);
2873 auto &nE = partws->mutableE(0);
2874 for (
size_t i = 0; i < wssize; ++i) {
2875 nY[i] =
Y[i + ileft];
2876 nE[i] = E[i + ileft];
2888 vector<string> parnames = function->getParameterNames();
2889 size_t numpars = parnames.size();
2890 outss <<
"Number of Parameters = " << numpars <<
'\n';
2891 for (
size_t i = 0; i < numpars; ++i)
2892 outss << parnames[i] <<
" = " << function->getParameter(i) <<
", \t\tFitted = " << function->isActive(i) <<
'\n';
2910 size_t wsindexraw,
size_t wsindexbkgd,
size_t wsindexpeak) {
2912 if (dataws->getNumberHistograms() < 3) {
2914 errss <<
"Function estimateBackgroundCoase() requires input Workspace2D "
2915 "has at least 3 spectra."
2916 <<
"Present input has " << dataws->getNumberHistograms() <<
" spectra.";
2917 throw runtime_error(errss.str());
2919 const auto &
X = dataws->x(wsindexraw);
2920 const auto &
Y = dataws->y(wsindexraw);
2923 size_t numsamplepts = 2;
2924 if (
X.size() <= 10) {
2933 for (
size_t i = 0; i < numsamplepts; ++i) {
2937 x0 = x0 /
static_cast<double>(numsamplepts);
2938 y0 = y0 /
static_cast<double>(numsamplepts);
2942 for (
size_t i =
X.size() - numsamplepts; i <
X.size(); ++i) {
2946 xf = xf /
static_cast<double>(numsamplepts);
2947 yf = yf /
static_cast<double>(numsamplepts);
2950 double b1 = (yf - y0) / (xf - x0);
2951 double b0 = yf - b1 * xf;
2953 background->setParameter(
"A0", b0);
2954 background->setParameter(
"A1", b1);
2959 background->function(domain, values);
2961 dataws->mutableY(wsindexbkgd) = values.
toVector();
2962 dataws->mutableY(wsindexpeak) = dataws->y(wsindexraw) - dataws->y(wsindexbkgd);
2963 dataws->mutableE(wsindexpeak) = dataws->e(wsindexraw);
2983 const auto &
X = dataws->x(wsindex);
2984 const auto &
Y = dataws->y(wsindex);
2988 centre =
X[icentre];
2991 if (icentre <= 1 || icentre >
X.size() - 2) {
2993 errss <<
"Peak center = " << centre <<
" is at the edge of the input workspace [" <<
X[0] <<
", " <<
X.back()
2994 <<
". It is unable to proceed the estimate of FWHM. Quit with error!.";
2995 errmsg = errss.str();
3000 errss <<
"Max height = " <<
height <<
" in input workspace [" <<
X[0] <<
", " <<
X.back()
3001 <<
" is negative. Fatal error is design of the algorithm.";
3002 errmsg = errss.str();
3007 double halfMax =
height * 0.5;
3010 bool continueloop =
true;
3011 size_t index = icentre - 1;
3012 while (continueloop) {
3013 if (
Y[
index] <= halfMax) {
3015 continueloop =
false;
3016 }
else if (
index == 0) {
3019 errss <<
"The peak is not complete (left side) in the given data range.";
3020 errmsg = errss.str();
3028 double xf =
X[
index + 1];
3030 double yf =
Y[
index + 1];
3035 double lefthalffwhm = centre - xl;
3038 continueloop =
true;
3039 index = icentre + 1;
3040 while (continueloop) {
3041 if (
Y[
index] <= halfMax) {
3043 continueloop =
false;
3044 }
else if (
index ==
Y.size() - 1) {
3047 errss <<
"The peak is not complete (right side) in the given data range.";
3048 errmsg = errss.str();
3062 double righthalffwhm = xr - centre;
3065 fwhm = lefthalffwhm + righthalffwhm;
3077 auto maxIt = std::max_element(
Y.begin(),
Y.end());
3078 return std::distance(
Y.begin(), maxIt);
3090 const auto &
X = dataws->x(wsindex);
3091 const auto &
Y = dataws->y(wsindex);
3094 std::vector<double>::const_iterator viter;
3096 viter = std::lower_bound(
X.begin(),
X.end(), leftbound);
3097 size_t ixmin = size_t(viter -
X.begin());
3100 viter = std::lower_bound(
X.begin(),
X.end(), rightbound);
3101 size_t ixmax = size_t(viter -
X.begin());
3104 size_t imax = ixmin;
3105 double maxY =
Y[ixmin];
3106 for (
size_t i = ixmin + 1; i <= ixmax; ++i) {
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
#define PEAKFITRANGEFACTOR
Factor on FWHM for fitting a peak.
#define PEAKBOUNDARYFACTOR
Factor on FWHM for defining a peak's range.
std::map< DeltaEMode::Type, std::string > index
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
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.
A composite function is a function containing other functions.
Implements FunctionDomain1D with its own storage in form of a std::vector.
size_t size() const override
Return the number of arguments in the domain.
A class to store values calculated by a function.
std::vector< double > toVector() const
Return the calculated values as a vector.
virtual void initialize()
Iinialize the function.
std::vector< std::string > getParameterNames() const
Return a vector with all parameter names.
virtual void setMillerIndex(int h, int k, int l)
Set Miller Indicies.
virtual double centre() const
Overwrite IFunction base class methods.
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
FitPowderDiffPeaks : Fit peaks in powder diffraction pattern.
double m_rightmostPeakLeftBound
Right most peak's left boundary.
void init() override
Implement abstract Algorithm methods.
void restoreFunctionParameters(const API::IFunction_sptr &function, std::map< std::string, double > parammap)
Restore the function's parameter values from a map.
bool doFit1PeakSequential(const DataObjects::Workspace2D_sptr &dataws, size_t workspaceindex, const Functions::BackToBackExponential_sptr &peakfunction, std::vector< std::string > minimzernames, std::vector< size_t > maxiterations, const std::vector< double > &dampfactors, double &chi2)
Fit 1 peak by using a sequential of minimizer.
void observePeakRange(const Functions::BackToBackExponential_sptr &thispeak, const Functions::BackToBackExponential_sptr &rightpeak, double refpeakshift, double &peakleftbound, double &peakrightbound)
Observe peak range with hint from right peak's properties.
void storeFunctionParameters(const API::IFunction_sptr &function, std::map< std::string, double > ¶mmaps)
Store the function's parameter values to a map.
double getParameter(const std::string &parname)
Get parameter value from m_instrumentParameters.
std::vector< double > m_chi2GoodFitPeaks
bool doFitMultiplePeaks(const DataObjects::Workspace2D_sptr &dataws, size_t wsindex, const API::CompositeFunction_sptr &peaksfunc, std::vector< Functions::BackToBackExponential_sptr > peakfuncs, std::vector< bool > &vecfitgood, std::vector< double > &vecchi2s)
Fit multiple (overlapped) peaks.
bool doFitGaussianPeak(const DataObjects::Workspace2D_sptr &dataws, size_t workspaceindex, double in_center, double leftfwhm, double rightfwhm, double ¢er, double &sigma, double &height)
Fit background-removed peak by Gaussian.
std::vector< int > m_rightmostPeakHKL
Right most peak HKL.
std::vector< int > m_minimumHKL
Minimum HKL.
std::string parseFitResult(const API::IAlgorithm_sptr &fitalg, double &chi2, bool &fitsuccess)
Parse the fitting result.
enum Mantid::CurveFitting::Algorithms::FitPowderDiffPeaks::@0 m_fitMode
Fit mode.
std::pair< DataObjects::TableWorkspace_sptr, DataObjects::TableWorkspace_sptr > genPeakParametersWorkspace()
Generate output peak parameters workspace.
double m_tofMin
TOF Min and TOF Max.
bool getHKLFromMap(std::map< std::string, int > intmap, std::vector< int > &hkl)
Get (HKL) from a map; Return false if the information is incomplete.
double m_rightmostPeakRightBound
Right most peak's right boundary.
std::vector< bool > m_goodFit
Peak fitting status.
std::vector< double > m_peakFitChi2
Peak fitting information.
double m_minPeakHeight
Minimum peak height for peak to be refined.
bool doFit1PeakSimple(const DataObjects::Workspace2D_sptr &dataws, size_t workspaceindex, const Functions::BackToBackExponential_sptr &peakfunction, const std::string &minimzername, size_t maxiteration, double &chi2)
Fit 1 peak by 1 minimizer of 1 call of minimzer (simple version)
void exec() override
Implement abstract Algorithm methods.
bool m_fitPeakBackgroundComposite
Fit peak + background as the last step.
void importInstrumentParameterFromTable(const DataObjects::TableWorkspace_sptr ¶meterWS)
Import instrument parameters from (input) table workspace.
void setOverlappedPeaksConstraints(const std::vector< Functions::BackToBackExponential_sptr > &peaks)
Set constraints on a group of overlapped peaks for fitting.
DataObjects::TableWorkspace_sptr m_profileTable
Instrument profile parameter table workspace.
void genPeaksFromTable(const DataObjects::TableWorkspace_sptr &peakparamws)
Generate peaks from input table workspace.
void calculatePeakFitBoundary(size_t ileftpeak, size_t irightpeak, double &peakleftboundary, double &peakrightboundary)
Calculate the range to fit peak/peaks group.
Geometry::UnitCell m_unitCell
Unit cell of powder crystal.
std::pair< bool, double > doFitPeak(const DataObjects::Workspace2D_sptr &dataws, const Functions::BackToBackExponential_sptr &peakfunction, double guessedfwhm)
Fit peak with flexiblity in multiple steps Prerequisit:
DataObjects::Workspace2D_sptr genOutputFittedPatternWorkspace(std::vector< double > pattern, int workspaceindex)
Create a Workspace2D for fitted peaks (pattern)
void fitPeaksWithGoodStartingValues()
Fit peaks.
std::vector< double > m_peakData
Data for each individual peaks. (HKL)^2, vector index, function values.
void parseBraggPeakTable(const DataObjects::TableWorkspace_sptr &peakws, std::vector< std::map< std::string, double > > ¶mmaps, std::vector< std::map< std::string, int > > &hklmaps)
Import Bragg peak table workspace.
void cropWorkspace(double tofmin, double tofmax)
Crop data workspace.
enum Mantid::CurveFitting::Algorithms::FitPowderDiffPeaks::@1 m_genPeakStartingValue
Choice to generate peak profile paramter starting value.
DataObjects::Workspace2D_sptr genPeakParameterDataWorkspace()
Create data workspace for X0, A, B and S of peak with good fit.
DataObjects::TableWorkspace_sptr m_peakParamTable
Bragg peak parameter.
Functions::BackToBackExponential_sptr genPeak(std::map< std::string, int > hklmap, std::map< std::string, double > parammap, std::map< std::string, std::string > bk2bk2braggmap, bool &good, std::vector< int > &hkl, double &d_h)
Generate a peak.
void processInputProperties()
Process input properties.
std::vector< std::string > mPeakParameterNames
Peak parmeter names.
bool fitOverlappedPeaks(std::vector< Functions::BackToBackExponential_sptr > peaks, const Functions::BackgroundFunction_sptr &backgroundfunction, double gfwhm)
Fit peaks with confidence in fwhm and etc.
std::map< std::string, double > m_instrumentParmaeters
Map for function (instrument parameter)
std::vector< std::pair< double, std::pair< std::vector< int >, Functions::BackToBackExponential_sptr > > > m_vecPeakFunctions
Sorted vector for peaks. double = d_h, vector = (HKL), peak.
int m_numPeaksLowerToMin
Number of peaks to fit lower to minimum HKL.
bool doFit1PeakBackground(const DataObjects::Workspace2D_sptr &dataws, size_t wsindex, const Functions::BackToBackExponential_sptr &peak, const Functions::BackgroundFunction_sptr &backgroundfunction, double &chi2)
Fit 1 peak and background.
void plotFunction(const API::IFunction_sptr &peakfunction, const Functions::BackgroundFunction_sptr &background, const API::FunctionDomain1DVector &domain)
Plot a single peak to output vector.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
std::string parseFitParameterWorkspace(const API::ITableWorkspace_sptr ¶mws)
Parse Fit() output parameter workspace.
DataObjects::Workspace2D_sptr buildPartialWorkspace(const API::MatrixWorkspace_sptr &sourcews, size_t workspaceindex, double leftbound, double rightbound)
Build partial workspace for fitting.
bool m_useGivenTOFh
Flag to use given Bragg peaks' centre in TOF.
bool fitSinglePeakRobust(const Functions::BackToBackExponential_sptr &peak, const Functions::BackgroundFunction_sptr &backgroundfunction, double peakleftbound, double peakrightbound, const std::map< std::string, double > &rightpeakparammap, double &finalchi2)
Fit single peak in robust mode (no hint)
void fitPeaksRobust()
Fit peaks in robust algorithm.
void estimatePeakHeightsLeBail(const DataObjects::Workspace2D_sptr &dataws, size_t wsindex, std::vector< Functions::BackToBackExponential_sptr > peaks)
Use Le Bail method to estimate and set the peak heights.
bool fitSinglePeakConfident(const Functions::BackToBackExponential_sptr &peak, const Functions::BackgroundFunction_sptr &backgroundfunction, double leftbound, double rightbound, double &chi2, bool &annhilatedpeak)
Fit peak with trustful peak parameters.
int m_wsIndex
TOF vector of data workspace to process with.
bool doFitNPeaksSimple(const DataObjects::Workspace2D_sptr &dataws, size_t wsindex, const API::CompositeFunction_sptr &peaksfunc, const std::vector< Functions::BackToBackExponential_sptr > &peakfuncs, const std::string &minimizername, size_t maxiteration, double &chi2)
Fit N overlapped peaks in a simple manner.
API::MatrixWorkspace_sptr m_dataWS
Data.
bool fitSinglePeakSimulatedAnnealing(const Functions::BackToBackExponential_sptr &peak, const std::vector< std::string > ¶mtodomc)
Fit signle peak by Monte Carlo/simulated annealing.
std::vector< size_t > m_indexGoodFitPeaks
Provide BackToBackExponential peak shape function interface to IPeakFunction.
ThermalNeutronBk2BkExpConvPVoigt : Back-to-back exponential convoluted with pseudo Voigt for thermal ...
double getPeakParameter(const std::string &) override
Overwrite IPeakFunction base class methods.
void setParameter(size_t i, const double &value, bool explicitlySet=true) override
Core function to calcualte peak values for whole region.
void calculateParameters(bool explicitoutput) const override
Calculate peak parameters (alpha, beta, sigma2..)
TableWorkspace is an implementation of Workspace in which the data are organised in columns of same s...
void set(double _a, double _b, double _c, double _alpha, double _beta, double _gamma, const int angleunit=angDegrees)
Set lattice parameters.
double d(double h, double k, double l) const
Return d-spacing ( ) for a given h,k,l coordinate.
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 error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning 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...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< Column > Column_sptr
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< CompositeFunction > CompositeFunction_sptr
shared pointer to the composite function base class
double linearInterpolateX(double x0, double xf, double y0, double yf, double y)
Formular for linear iterpolation: X = [(xf-x0)*Y - (xf*y0-x0*yf)]/(yf-y0)
size_t findMaxValue(const std::vector< double > &Y)
Find maximum value.
bool observePeakParameters(const DataObjects::Workspace2D_sptr &dataws, size_t wsindex, double ¢re, double &height, double &fwhm, std::string &errmsg)
Estimate peak parameters;.
void estimateBackgroundCoarse(const DataObjects::Workspace2D_sptr &dataws, const Functions::BackgroundFunction_sptr &background, size_t wsindexraw, size_t wsindexbkgd, size_t wsindexpeak)
Estimate background for a pattern in a coarse mode.
std::string getFunctionInfo(const API::IFunction_sptr &function)
Get function parameter name, value and etc information in string.
double calThermalNeutronTOF(double dh, double dtt1, double dtt1t, double dtt2t, double zero, double zerot, double width, double tcross)
Calcualte TOF from d-spacing value for thermal neutron.
std::shared_ptr< Polynomial > Polynomial_sptr
std::shared_ptr< BackToBackExponential > BackToBackExponential_sptr
std::shared_ptr< BackgroundFunction > BackgroundFunction_sptr
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
std::vector< double > getZscore(const std::vector< TYPE > &data)
Return the Z score values for a dataset.
Helper class which provides the Collimation Length for SANS instruments.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.
@ Output
An output workspace.