39#include <gsl/gsl_sf_erf.h>
42#define PEAKFITRANGEFACTOR 5.0
45#define PEAKBOUNDARYFACTOR 2.5
48#define EXCLUDEPEAKRANGEFACTOR 8.0
69 : m_wsIndex(-1), m_tofMin(0.), m_tofMax(0.), m_useGivenTOFh(false), m_confidentInInstrumentParameters(false),
70 m_minimumHKL(), m_numPeaksLowerToMin(-1), m_indexGoodFitPeaks(), m_chi2GoodFitPeaks(), m_fitMode(ROBUSTFIT),
71 m_genPeakStartingValue(HKLCALCULATION), m_rightmostPeakHKL(), m_rightmostPeakLeftBound(0.),
72 m_rightmostPeakRightBound(0.), m_minPeakHeight(0.), m_unitCell(), m_fitPeakBackgroundComposite(false) {}
80 "Input workspace for data (diffraction pattern). ");
84 "Output Workspace2D for the fitted peaks. ");
89 "TableWorkspace containg all peaks' parameters.");
94 "TableWorkspace containg instrument's parameters.");
99 "Output TableWorkspace containing the fitted peak parameters for each "
105 "Output Workspace2D containing fitted peak parameters for "
106 "further refinement.");
111 "Output TableWorkspace containing the Zscore of the fitted "
112 "peak parameters. ");
115 declareProperty(
"WorkspaceIndex", 0,
"Worskpace index for the data to refine against.");
121 vector<string> fitmodes(2);
122 fitmodes[0] =
"Robust";
123 fitmodes[1] =
"Confident";
124 auto fitvalidator = std::make_shared<StringListValidator>(fitmodes);
126 "Fitting mode such that user can determine"
127 "whether the input parameters are trustful or not.");
131 "Use each Bragg peak's centre in TOF given in "
132 "BraggPeakParameterWorkspace."
133 "Otherwise, calculate each peak's centre from d-spacing.");
135 vector<string> genpeakoptions{
"(HKL) & Calculation",
"From Bragg Peak Table"};
136 auto propvalidator = std::make_shared<StringListValidator>(genpeakoptions);
137 declareProperty(
"PeakParametersStartingValueFrom",
"(HKL) & Calculation", propvalidator,
138 "Choice of how to generate starting values of "
139 "Bragg peak profile parmeters.");
142 "Minimum peak height (with background removed) "
143 "Any peak whose maximum height under this value will be "
144 "treated as zero intensity. ");
153 "Flag for fact that all peaks' corresponding profile parameters "
154 "are correlated by an analytical function");
157 auto arrayprop = std::make_unique<ArrayProperty<int>>(
"MinimumHKL",
"");
158 declareProperty(std::move(arrayprop),
"Miller index of the left most peak (peak with "
159 "minimum d-spacing) to be fitted. ");
163 "Number of peaks to fit with d-spacing value "
164 "less than specified minimum. ");
167 auto righthklprop = std::make_unique<ArrayProperty<int>>(
"RightMostPeakHKL",
"");
168 declareProperty(std::move(righthklprop),
"Miller index of the right most peak. "
169 "It is only required and used in RobustFit mode.");
172 "Left bound of the right most peak. "
173 "Used in RobustFit mode.");
176 "Right bound of the right most peak. "
177 "Used in RobustFit mode.");
181 "Flag to do fit to both peak and background in a composite "
182 "function as last fit step.");
201 throw runtime_error(
"Input instrument table workspace lacks LatticeConstant. "
202 "Unable to complete processing.");
203 m_unitCell.
set(latticesize, latticesize, latticesize, 90.0, 90.0, 90.0);
228 throw runtime_error(
"Unsupported fit mode.");
236 setProperty(
"OutputBraggPeakParameterWorkspace", outputpeaksws);
245 setProperty(
"OutputBraggPeakParameterDataWorkspace", peakparamvaluews);
255 if (m_wsIndex < 0 || m_wsIndex >
static_cast<int>(
m_dataWS->getNumberHistograms())) {
257 errss <<
"Input workspace = " <<
m_wsIndex <<
" is out of range [0, " <<
m_dataWS->getNumberHistograms();
259 throw std::invalid_argument(errss.str());
279 if (fitmode ==
"Robust") {
281 }
else if (fitmode ==
"Confident") {
284 throw runtime_error(
"Input fit mode can only accept either Robust or Confident. ");
292 string genpeakparamalg =
getProperty(
"PeakParametersStartingValueFrom");
293 if (genpeakparamalg ==
"(HKL) & Calculation") {
295 }
else if (genpeakparamalg ==
"From Bragg Peak Table") {
298 throw runtime_error(
"Input option from PeakParametersStaringValueFrom is not supported.");
310 errss <<
"If fit mode is 'RobustFit', then user must specify all 3 "
311 "properties of right most peak "
316 throw runtime_error(errss.str());
340 bool isrightmost =
true;
343 throw runtime_error(
"There is no peak to fit!");
345 vector<string> peakparnames =
m_vecPeakFunctions[0].second.second->getParameterNames();
349 backgroundfunction->setAttributeValue(
"n", 1);
350 backgroundfunction->initialize();
354 double refpeakshift = 0.0;
356 for (
int peakindex =
static_cast<int>(numpeaks) - 1; peakindex >= 0; --peakindex) {
362 bool goodfit =
false;
368 double peakleftbound, peakrightbound;
372 double predictpeakcentre = thispeak->centre();
374 infoss <<
"[DBx102] The " << numpeaks - 1 - peakindex <<
"-th rightmost peak's miller index = " << peakhkl[0]
375 <<
", " << peakhkl[1] <<
", " << peakhkl[2] <<
", predicted at TOF = " << thispeak->centre()
376 <<
"; User specify boundary = [" << peakleftbound <<
", " << peakrightbound <<
"].";
379 map<string, double> rightpeakparameters;
380 goodfit =
fitSinglePeakRobust(thispeak, std::dynamic_pointer_cast<BackgroundFunction>(backgroundfunction),
381 peakleftbound, peakrightbound, rightpeakparameters, chi2);
386 throw runtime_error(
"Failed to fit the right most peak. Unable to process. ");
388 stringstream robmsgss;
389 for (
auto &parname : peakparnames) {
390 robmsgss << parname <<
" = " << thispeak->getParameter(parname) <<
'\n';
392 g_log.
information() <<
"[DB1151] Robust Fit Result: Chi^2 = " << chi2 <<
'\n' << robmsgss.str();
394 rightpeak = thispeak;
398 refpeakshift = thispeak->centre() - predictpeakcentre;
400 g_log.
notice() <<
"[DBx332] Peak -" <<
static_cast<int>(numpeaks) - peakindex - 1
401 <<
": shifted = " << refpeakshift <<
'\n';
402 }
else if (!isrightmost) {
405 if (peakindex ==
static_cast<int>(numpeaks) - 1)
406 throw runtime_error(
"Impossible to have peak index as the right most peak here!");
408 double predictcentre = thispeak->centre();
411 double peakleftbound, peakrightbound;
412 observePeakRange(thispeak, rightpeak, refpeakshift, peakleftbound, peakrightbound);
416 for (
int i = 0; i < 10; ++i)
417 dbxss <<
"==\n[DBx323] Peak (" << peakhkl[0] <<
", " << peakhkl[1] <<
"," << peakhkl[2]
418 <<
"). Centre predicted @ TOF = " << predictcentre <<
". Observed range = " << peakleftbound <<
", "
429 map<string, double> rightpeakparameters;
431 goodfit =
fitSinglePeakRobust(thispeak, std::dynamic_pointer_cast<BackgroundFunction>(backgroundfunction),
432 peakleftbound, peakrightbound, rightpeakparameters, chi2);
439 rightpeak = thispeak;
440 refpeakshift = thispeak->centre() - predictcentre;
446 g_log.
warning() <<
"Fitting peak @ " << thispeak->centre() <<
" failed. \n";
451 double peakleftbound, peakrightbound;
455 infoss <<
"[DBx102] The " << numpeaks - 1 - peakindex <<
"-th rightmost peak's miller index = " << peakhkl[0]
456 <<
", " << peakhkl[1] <<
", " << peakhkl[2] <<
", predicted at TOF = " << thispeak->centre() <<
"; "
459 <<
", " << peakrightbound <<
"].";
473 double &peakleftbound,
double &peakrightbound) {
474 double predictcentre = thispeak->centre();
475 double rightfwhm = rightpeak->fwhm();
480 if (refpeakshift > 0) {
482 peakleftbound = predictcentre - rightfwhm;
483 peakrightbound = predictcentre + rightfwhm + refpeakshift;
486 peakleftbound = predictcentre - rightfwhm + refpeakshift;
487 peakrightbound = predictcentre + rightfwhm;
489 if (peakrightbound > rightpeak->centre() - 3 * rightpeak->fwhm()) {
493 peakrightbound = rightpeak->centre() - 3 * rightpeak->fwhm();
502 peakleftbound = vecX[icentre] - 4.0 * rightfwhm;
503 peakrightbound = vecX[icentre] + 4.0 * rightfwhm;
505 double rightpeakleftbound = rightpeak->centre() - 3 * rightfwhm;
506 if (peakrightbound > rightpeakleftbound) {
507 peakrightbound = rightpeakleftbound;
508 double peakcentre = vecX[icentre];
509 if (peakrightbound < 2.0 * rightfwhm + peakcentre)
510 g_log.
warning() <<
"Peak @ " << peakcentre <<
"'s right boundary is too close to its right peak!\n";
555 double peakrightbound,
const map<string, double> &rightpeakparammap,
559 g_log.
debug() <<
"[DB1208] Build partial workspace for peak @ " << peak->centre() <<
" (predicted).\n";
562 size_t rawdata_wsindex = 0;
563 size_t estbkgd_wsindex = 2;
564 size_t peak_wsindex = 1;
568 dbss <<
"[DBx203] Removed background peak data: \n";
569 for (
size_t i = 0; i < peakws->x(peak_wsindex).size(); ++i)
570 dbss << peakws->x(peak_wsindex)[i] <<
"\t\t" << peakws->y(peak_wsindex)[i] <<
"\t\t" << peakws->e(peak_wsindex)[i]
575 double centre, fwhm,
height;
582 throw runtime_error(errmsg);
584 g_log.
notice(
"Unable to observe peak parameters. Proceed to next peak.");
588 g_log.
notice() <<
"[FLAGx409] Peak proposed @ TOF = " << peak->centre() <<
" has a trivial "
589 <<
"peak height = " <<
height <<
" by observation. Skipped.\n";
593 <<
", Estimated (observation) Centre = " << centre <<
", FWHM = " << fwhm
594 <<
" Height = " <<
height <<
'\n';
603 vector<string> peakparnames = peak->getParameterNames();
604 for (
size_t i = 0; i < peakparnames.size(); ++i)
608 peak->setParameter(
"I",
height * fwhm);
609 peak->setParameter(
"X0", tof_h);
612 vector<string> minimizers(numsteps);
613 minimizers[0] =
"Simplex";
614 minimizers[1] =
"Levenberg-Marquardt";
615 vector<size_t> maxiterations(numsteps, 10000);
616 vector<double> dampfactors(numsteps, 0.0);
619 map<string, double> origparammap;
622 vector<double> chi2s;
623 vector<bool> goodfits;
624 vector<map<string, double>> solutions;
627 string peakinfoa0 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
628 g_log.
notice() <<
"[DBx533A] Approach A: Starting Peak Function Information: \n" << peakinfoa0 <<
'\n';
631 bool fitgooda =
doFit1PeakSequential(peakws, peak_wsindex, peak, minimizers, maxiterations, dampfactors, chi2a);
632 map<string, double> solutiona;
635 chi2s.emplace_back(chi2a);
636 goodfits.emplace_back(fitgooda);
637 solutions.emplace_back(solutiona);
639 string peakinfoa1 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
640 g_log.
notice() <<
"[DBx533A] Approach A: Fit Successful = " << fitgooda <<
", Chi2 = " << chi2a
641 <<
", Peak Function Information: \n"
642 << peakinfoa1 <<
'\n';
646 peak->setParameter(
"S",
sigma);
648 string peakinfob0 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
649 g_log.
notice() <<
"[DBx533B] Approach B: Starting Peak Function Information: \n" << peakinfob0 <<
'\n';
652 bool fitgoodb =
doFit1PeakSequential(peakws, peak_wsindex, peak, minimizers, maxiterations, dampfactors, chi2b);
654 map<string, double> solutionb;
657 chi2s.emplace_back(chi2b);
658 goodfits.emplace_back(fitgoodb);
659 solutions.emplace_back(solutionb);
661 string peakinfob1 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
662 g_log.
notice() <<
"[DBx533B] Approach 2: Fit Successful = " << fitgoodb <<
", Chi2 = " << chi2b
663 <<
", Peak Function Information: \n"
664 << peakinfob1 <<
'\n';
667 if (!rightpeakparammap.empty()) {
669 peak->setParameter(
"X0", tof_h);
670 peak->setParameter(
"I",
height * fwhm);
672 string peakinfoc0 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
673 g_log.
notice() <<
"[DBx533C] Approach C: Starting Peak Function Information: \n" << peakinfoc0 <<
'\n';
676 bool fitgoodc =
doFit1PeakSequential(peakws, peak_wsindex, peak, minimizers, maxiterations, dampfactors, chi2c);
677 map<string, double> solutionc;
680 chi2s.emplace_back(chi2c);
681 goodfits.emplace_back(fitgoodc);
682 solutions.emplace_back(solutionc);
684 string peakinfoc1 =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(peak));
685 g_log.
notice() <<
"[DBx533C] Approach C: Fit Successful = " << fitgoodc <<
", Chi2 = " << chi2c
686 <<
", Peak Function Information: \n"
687 << peakinfoc1 <<
'\n';
690 chi2s.emplace_back(DBL_MAX);
691 goodfits.emplace_back(
false);
692 solutions.emplace_back(rightpeakparammap);
696 size_t bestapproach = goodfits.size() + 1;
697 double bestchi2 = DBL_MAX;
698 for (
size_t i = 0; i < goodfits.size(); ++i) {
699 if (goodfits[i] && chi2s[i] < bestchi2) {
705 stringstream fitsumss;
706 fitsumss <<
"Best fit result is obtained by approach " << bestapproach <<
" of total " << goodfits.size()
707 <<
" approaches. Best Chi^2 = " << bestchi2 <<
", Peak Height = " << peak->height();
708 g_log.
notice() <<
"[DB1127] " << fitsumss.str() <<
'\n';
711 if (bestapproach < goodfits.size()) {
719 peak->setParameter(
"S",
sigma);
720 peak->setParameter(
"I",
height * fwhm);
721 peak->setParameter(
"X0", tof_h);
723 vector<string> paramsinmc{
"A",
"B"};
732 bool fitcompfunsuccess =
doFit1PeakBackground(peakws, rawdata_wsindex, peak, backgroundfunction, chi2compf);
733 if (fitcompfunsuccess) {
734 finalchi2 = chi2compf;
736 finalchi2 = bestchi2;
737 g_log.
warning(
"Fit peak-background composite function failed! Need to "
738 "find out how this case peak value is changed from best "
743 finalchi2 = bestchi2;
761 string minimzername(
"Levenberg-MarquardtMD");
762 double startx = peak->centre() - 3.0 * peak->fwhm();
763 double endx = peak->centre() + 3.0 * peak->fwhm();
767 compfunc->addFunction(peak);
768 compfunc->addFunction(backgroundfunction);
771 vector<string> comparnames = compfunc->getParameterNames();
772 for (
size_t ipar = 0; ipar < comparnames.size(); ++ipar)
773 compfunc->unfix(ipar);
777 g_log.
notice() <<
"[DBx533X-0] Fit All: Starting Peak Function Information: \n"
778 << cominfoa <<
"Fit range = " << startx <<
", " << endx <<
'\n';
782 fitalg->initialize();
784 fitalg->setProperty(
"Function", std::dynamic_pointer_cast<API::IFunction>(compfunc));
785 fitalg->setProperty(
"InputWorkspace", dataws);
786 fitalg->setProperty(
"WorkspaceIndex",
static_cast<int>(wsindex));
787 fitalg->setProperty(
"Minimizer", minimzername);
788 fitalg->setProperty(
"CostFunction",
"Least squares");
789 fitalg->setProperty(
"MaxIterations", 1000);
790 fitalg->setProperty(
"Output",
"FitPeakBackground");
791 fitalg->setProperty(
"StartX", startx);
792 fitalg->setProperty(
"EndX", endx);
795 bool isexecute = fitalg->execute();
803 stringstream cominfob;
804 cominfob <<
"[DBx533X] Fit All: Fit Successful = " << fitsuccess <<
", Chi^2 = " << chi2 <<
'\n';
805 cominfob <<
"Detailed info = " << fitresult <<
'\n';
811 g_log.
notice() <<
"[DB1203B] Failed To Fit Peak+Background @ " << peak->centre() <<
'\n';
822 const vector<string> ¶mtodomc) {
825 throw runtime_error(
"To Be Implemented Soon!");
1028 backgroundfunction->setAttributeValue(
"n", 1);
1029 backgroundfunction->initialize();
1037 while (ipeak >= 0) {
1039 vector<size_t> indexpeakgroup;
1041 bool makegroup =
true;
1050 indexpeakgroup.emplace_back(ipeak);
1060 double thispeakleftbound = thispeak->centre() - thispeak->fwhm() * 2.5;
1062 double leftpeakrightbound = leftpeak->centre() + leftpeak->fwhm() * 2.5;
1063 if (thispeakleftbound > leftpeakrightbound) {
1070 if (indexpeakgroup.size() == 1) {
1072 const size_t ifit = indexpeakgroup[0];
1073 double peakfitleftbound, peakfitrightbound;
1077 <<
")\t----------------------------------\n";
1080 bool annihilatedpeak;
1084 if (annihilatedpeak)
1085 thispeak->setHeight(0.0);
1090 dbss <<
"Peak [" << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
"] expected @ TOF = " << thispeak->centre()
1092 if (annihilatedpeak)
1093 dbss <<
"Annihilated!";
1095 dbss <<
"Fit Status = " <<
m_goodFit[ifit] <<
", Chi2 = " << chi2;
1099 vector<BackToBackExponential_sptr> peaksgroup;
1100 for (
auto ipk : indexpeakgroup) {
1102 peaksgroup.emplace_back(temppeak);
1129 double rightbound,
double &chi2,
bool &annhilatedpeak) {
1132 if (leftbound < 0 || leftbound >= peak->centre())
1133 leftbound = peak->centre() - 5 * peak->fwhm();
1134 if (rightbound < 0 || rightbound <= peak->centre())
1135 rightbound = peak->centre() + 5 * peak->fwhm();
1144 dbss2 <<
"[T] Partial workspace No Background: \n";
1145 for (
size_t i = 0; i < peakdataws->x(1).size(); ++i)
1146 dbss2 << peakdataws->x(1)[i] <<
"\t\t" << peakdataws->y(1)[i] <<
"\t\t" << peakdataws->e(1)[i] <<
"\t\t"
1147 << peakdataws->y(0)[i] <<
'\n';
1151 size_t imaxheight =
findMaxValue(peakdataws->y(1).rawData());
1152 double maxheight = peakdataws->y(1)[imaxheight];
1156 annhilatedpeak =
true;
1160 annhilatedpeak =
false;
1165 double peakcentreleftbound = peak->centre() - peak->fwhm();
1166 double peakcentrerightbound = peak->centre() + peak->fwhm();
1167 auto x0bc = std::make_unique<BoundaryConstraint>(peak.get(),
"X0", peakcentreleftbound, peakcentrerightbound);
1168 peak->addConstraint(std::move(x0bc));
1171 auto abc = std::make_unique<BoundaryConstraint>(peak.get(),
"A", 1.0E-10,
false);
1172 peak->addConstraint(std::move(abc));
1175 auto bbc = std::make_unique<BoundaryConstraint>(peak.get(),
"B", 1.0E-10,
false);
1176 peak->addConstraint(std::move(bbc));
1179 peak->setHeight(maxheight);
1183 dbss0 <<
"[DBx100] Peak @" << peak->centre() <<
", FWHM = " << peak->fwhm() <<
'\n';
1184 vector<string> peakparams = peak->getParameterNames();
1185 for (
size_t i = 0; i < peakparams.size(); ++i)
1186 dbss0 << peakparams[i] <<
" = " << peak->getParameter(i) <<
'\n';
1190 vector<string> peakparamnames = peak->getParameterNames();
1191 vector<map<string, double>> fitparamvaluemaps;
1192 vector<pair<double, size_t>> chi2indexvec;
1195 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1196 const string &parname = peakparams[iparam];
1198 peak->unfix(iparam);
1203 bool goodfit1 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2height);
1206 map<string, double> step1params;
1208 fitparamvaluemaps.emplace_back(step1params);
1210 chi2height = 1.0E20;
1211 chi2indexvec.emplace_back(chi2height, 0);
1214 vector<string> bkgdparnames = backgroundfunction->getParameterNames();
1215 for (
size_t iname = 0; iname < bkgdparnames.size(); ++iname)
1216 backgroundfunction->fix(iname);
1220 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam)
1221 peak->unfix(iparam);
1222 bool goodfitA =
doFit1PeakSimple(peakdataws, 1, peak,
"Simplex", 10000, chi2planA);
1225 map<string, double> planAparams;
1229 fitparamvaluemaps.emplace_back(planAparams);
1230 chi2indexvec.emplace_back(chi2planA, 1);
1238 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1239 string parname = peakparams[iparam];
1243 peak->unfix(iparam);
1245 bool goodfitB1 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2planB);
1248 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1249 string parname = peakparams[iparam];
1250 if (parname ==
"A" || parname ==
"I")
1251 peak->unfix(iparam);
1255 bool goodfitB2 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2planB);
1257 bool goodfitB = goodfitB1 || goodfitB2;
1258 map<string, double> planBparams;
1262 fitparamvaluemaps.emplace_back(planBparams);
1263 chi2indexvec.emplace_back(chi2planB, 2);
1271 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1272 string parname = peakparams[iparam];
1276 peak->unfix(iparam);
1278 bool goodfitC1 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2planC);
1281 for (
size_t iparam = 0; iparam < peakparamnames.size(); ++iparam) {
1282 string parname = peakparams[iparam];
1286 peak->unfix(iparam);
1288 bool goodfitC2 =
doFit1PeakSimple(peakdataws, 1, peak,
"Levenberg-MarquardtMD", 10000, chi2planB);
1290 bool goodfitC = goodfitC1 || goodfitC2;
1291 map<string, double> planCparams;
1295 fitparamvaluemaps.emplace_back(planCparams);
1296 chi2indexvec.emplace_back(chi2planC, 3);
1300 sumss <<
"[DBx833] Confident fit on peak summary: \n";
1301 for (
size_t i = 0; i < 4; ++i)
1302 sumss <<
"Index " << i <<
": chi^2 = " << chi2indexvec[i].first <<
'\n';
1305 sort(chi2indexvec.begin(), chi2indexvec.end());
1308 if (chi2indexvec[0].first < 1.0E19) {
1310 size_t goodindex = chi2indexvec[0].second;
1312 chi2 = chi2indexvec[0].first;
1327 errss <<
"Fit Peak @ " << peak->centre() <<
" Error! Chi^2 (false) = " << chi2
1328 <<
". Do Not Know How To Proceed To Next Peak!";
1330 throw runtime_error(errss.str());
1334 vector<string> parnames = peak->getParameterNames();
1335 stringstream debugss;
1336 debugss <<
"DB1251 Single Peak Confident Fit Result: Chi^2 = " << chi2 <<
'\n';
1337 for (
auto &parname : parnames) {
1338 debugss << parname <<
" = " << peak->getParameter(parname) <<
'\n';
1358 double &peakrightboundary) {
1365 int ileftneighbor =
static_cast<int>(ileftpeak) - 1;
1366 if (ileftneighbor < 0) {
1373 double leftneighborrightbound = leftneighbor->centre() +
PEAKBOUNDARYFACTOR * leftneighbor->fwhm();
1374 if (leftneighborrightbound > peakleftboundary)
1375 peakleftboundary = leftneighborrightbound;
1381 size_t irightneighbor = irightpeak + 1;
1385 double rightneighborleftbound = rightneighbor->centre() -
PEAKBOUNDARYFACTOR * rightneighbor->fwhm();
1386 if (rightneighborleftbound < peakrightboundary)
1387 peakrightboundary = rightneighborleftbound;
1407 double guessedfwhm) {
1409 if (guessedfwhm > 0) {
1410 double tof_h = peakfunction->centre();
1411 double centerleftend = tof_h - guessedfwhm * 3.0;
1412 double centerrightend = tof_h + guessedfwhm * 3.0;
1414 std::make_unique<BoundaryConstraint>(peakfunction.get(),
"X0", centerleftend, centerrightend,
false);
1415 peakfunction->addConstraint(std::move(centerbound));
1417 g_log.
debug() <<
"[DoFitPeak] Peak Center Boundary = " << centerleftend <<
", " << centerrightend <<
'\n';
1421 auto abound = std::make_unique<BoundaryConstraint>(peakfunction.get(),
"A", 0.0000001, DBL_MAX,
false);
1422 peakfunction->addConstraint(std::move(abound));
1424 auto bbound = std::make_unique<BoundaryConstraint>(peakfunction.get(),
"B", 0.0000001, DBL_MAX,
false);
1425 peakfunction->addConstraint(std::move(bbound));
1427 auto sbound = std::make_unique<BoundaryConstraint>(peakfunction.get(),
"S", 0.0001, DBL_MAX,
false);
1428 peakfunction->addConstraint(std::move(sbound));
1431 vector<string> paramnames = peakfunction->getParameterNames();
1432 size_t numparams = paramnames.size();
1433 for (
size_t i = 0; i < numparams; ++i)
1434 peakfunction->unfix(i);
1437 vector<vector<string>> vecMinimizers;
1438 vector<vector<size_t>> vecMaxIterations;
1439 vector<vector<double>> vecDampings;
1453 vector<string> minimizers2(3);
1454 minimizers2[0] =
"Simplex";
1455 minimizers2[1] =
"Levenberg-MarquardtMD";
1456 minimizers2[2] =
"Levenberg-Marquardt";
1457 vector<size_t> maxiterations2(3, 1000);
1458 maxiterations2[0] = 10000;
1459 vector<double> dampings2(3, 0.0);
1460 vecMinimizers.emplace_back(minimizers2);
1461 vecMaxIterations.emplace_back(maxiterations2);
1462 vecDampings.emplace_back(dampings2);
1465 bool goodfit =
false;
1466 size_t numschemes = vecMinimizers.size();
1468 map<string, double> origparams, bestparams;
1470 bestparams = origparams;
1471 double bestchi2 = DBL_MAX;
1473 for (
size_t is = 0; is < numschemes; ++is) {
1479 bool localgoodfit =
doFit1PeakSequential(dataws, 1, peakfunction, vecMinimizers[is], vecMaxIterations[is],
1480 vecDampings[is], thischi2);
1483 if (localgoodfit && !goodfit) {
1485 bestchi2 = thischi2;
1488 }
else if (localgoodfit && goodfit) {
1490 if (thischi2 < bestchi2) {
1491 bestchi2 = thischi2;
1497 pair<bool, double> returnvalue = make_pair(goodfit, bestchi2);
1506 vector<string> paramnames = function->getParameterNames();
1508 for (
auto ¶mname : paramnames)
1509 parammaps.emplace(paramname, function->getParameter(paramname));
1516 vector<string> paramnames = function->getParameterNames();
1517 for (
auto &parname : paramnames) {
1518 auto miter = parammap.find(parname);
1519 if (miter != parammap.end())
1520 function->setParameter(parname, miter->second);
1539 size_t maxiteration,
double &chi2) {
1541 dbss << peakfunction->asString() <<
'\n';
1542 dbss <<
"Starting Value: ";
1543 vector<string> paramNames = peakfunction->getParameterNames();
1544 for (
auto ¶mName : paramNames)
1545 dbss << paramName <<
"= " << peakfunction->getParameter(paramName) <<
", \t";
1546 for (
size_t i = 0; i < dataws->x(workspaceindex).size(); ++i)
1547 dbss << dataws->x(workspaceindex)[i] <<
"\t\t" << dataws->y(workspaceindex)[i] <<
"\t\t"
1548 << dataws->e(workspaceindex)[i] <<
'\n';
1549 g_log.
debug() <<
"DBx430 " << dbss.str() <<
'\n';
1552 if (peakfunction->height() < 1.0E-5)
1553 peakfunction->setHeight(4.0);
1557 fitalg->initialize();
1560 fitalg->setProperty(
"Function", std::dynamic_pointer_cast<API::IFunction>(peakfunction));
1561 fitalg->setProperty(
"InputWorkspace", dataws);
1562 fitalg->setProperty(
"WorkspaceIndex",
static_cast<int>(workspaceindex));
1563 fitalg->setProperty(
"Minimizer", minimzername);
1564 fitalg->setProperty(
"CostFunction",
"Least squares");
1565 fitalg->setProperty(
"MaxIterations",
static_cast<int>(maxiteration));
1566 fitalg->setProperty(
"Output",
"FitPeak");
1569 bool isexecute = fitalg->execute();
1570 bool fitsuccess =
false;
1574 std::string fitresult =
parseFitResult(fitalg, chi2, fitsuccess);
1577 g_log.
information() <<
"[DBx138A] Fit Peak @ " << peakfunction->centre() <<
" Result:" << fitsuccess <<
"\n"
1578 <<
"Detailed info = " << fitresult <<
", Chi^2 = " << chi2 <<
'\n';
1585 g_log.
error() <<
"[DBx128B] Failed to execute fitting peak @ " << peakfunction->centre() <<
'\n';
1603 vector<string> minimzernames, vector<size_t> maxiterations,
1604 const vector<double> &dampfactors,
double &chi2) {
1606 if (minimzernames.size() != maxiterations.size() && minimzernames.size() != dampfactors.size()) {
1607 throw runtime_error(
"doFit1PeakSequential should have the input vectors of same size.");
1611 map<string, double> parambeforefit;
1615 doFit1PeakSimple(dataws, workspaceindex, peakfunction,
"Levenberg-MarquardtMD", 0, startchi2);
1619 double currchi2 = startchi2;
1620 bool goodfit =
false;
1623 for (
size_t i = 0; i < minimzernames.size(); ++i) {
1624 string minimizer = minimzernames[i];
1625 size_t maxiteration = maxiterations[i];
1626 g_log.
notice() <<
"DBx315 Start Chi2 = " << startchi2 <<
", Minimizer = " << minimizer
1627 <<
", Max Iterations = " << maxiteration <<
", Workspace Index = " << workspaceindex
1628 <<
", Data Range = " << dataws->x(workspaceindex)[0] <<
", " << dataws->x(workspaceindex).back()
1634 bool localgoodfit =
doFit1PeakSimple(dataws, workspaceindex, peakfunction, minimizer, maxiteration, newchi2);
1636 if (localgoodfit && newchi2 < currchi2) {
1643 g_log.
information() <<
"DBx315C Fit Failed. Fit Good = " << localgoodfit <<
'\n';
1657 double in_center,
double leftfwhm,
double rightfwhm,
double ¢er,
1660 const auto &
X = dataws->x(workspaceindex);
1661 const auto &
Y = dataws->y(workspaceindex);
1664 for (
size_t i = 1; i <
X.size(); ++i) {
1667 sigma = (leftfwhm + rightfwhm) * 0.5;
1670 auto temppeak = API::FunctionFactory::Instance().createFunction(
"Gaussian");
1671 auto gaussianpeak = std::dynamic_pointer_cast<API::IPeakFunction>(temppeak);
1672 gaussianpeak->setHeight(
height);
1673 gaussianpeak->setCentre(in_center);
1674 gaussianpeak->setFwhm(
sigma);
1677 double centerleftend = in_center - leftfwhm * 0.5;
1678 double centerrightend = in_center + rightfwhm * 0.5;
1680 std::make_unique<BoundaryConstraint>(gaussianpeak.get(),
"PeakCentre", centerleftend, centerrightend,
false);
1681 gaussianpeak->addConstraint(std::move(centerbound));
1685 fitalg->initialize();
1687 fitalg->setProperty(
"Function", std::dynamic_pointer_cast<API::IFunction>(gaussianpeak));
1688 fitalg->setProperty(
"InputWorkspace", dataws);
1689 fitalg->setProperty(
"WorkspaceIndex", 1);
1690 fitalg->setProperty(
"Minimizer",
"Levenberg-MarquardtMD");
1691 fitalg->setProperty(
"CostFunction",
"Least squares");
1692 fitalg->setProperty(
"MaxIterations", 1000);
1693 fitalg->setProperty(
"Output",
"FitGaussianPeak");
1696 bool successfulfit = fitalg->execute();
1697 if (!fitalg->isExecuted() || !successfulfit) {
1699 g_log.
warning() <<
"Fitting Gaussian peak for peak around " << gaussianpeak->centre() <<
'\n';
1705 std::string fitresult =
parseFitResult(fitalg, chi2, fitsuccess);
1706 g_log.
information() <<
"[Fit Gaussian Peak] Successful = " << fitsuccess <<
", Result:\n" << fitresult <<
'\n';
1709 center = gaussianpeak->centre();
1710 height = gaussianpeak->height();
1711 double fwhm = gaussianpeak->fwhm();
1715 sigma = fwhm / 2.35;
1720 g_log.
information() <<
"[DBx133] Fitted Gaussian Parameters: \n" << infofit <<
'\n';
1734 vector<pair<double, BackToBackExponential_sptr>> tofpeakpairs(peaks.size());
1735 for (
size_t i = 0; i < peaks.size(); ++i)
1736 tofpeakpairs[i] = make_pair(peaks[i]->centre(), peaks[i]);
1737 sort(tofpeakpairs.begin(), tofpeakpairs.end());
1742 double peaksleftboundary, peaksrightboundary;
1745 peaksleftboundary = leftpeak->centre() - 4 * leftpeak->fwhm();
1746 peaksrightboundary = rightpeak->centre() + 4 * rightpeak->fwhm();
1749 peaksleftboundary = leftpeak->centre() - 4 * gfwhm;
1750 peaksrightboundary = rightpeak->centre() + 4 * gfwhm;
1760 stringstream peakInfo;
1761 peakInfo << peaks.size() <<
"-Peaks Group Information: \n";
1762 for (
size_t ipk = 0; ipk < tofpeakpairs.size(); ++ipk) {
1764 peakInfo <<
"Peak " << ipk <<
" @ TOF = " << tmppeak->centre() <<
", A = " << tmppeak->getParameter(
"A")
1765 <<
", B = " << tmppeak->getParameter(
"B") <<
", S = " << tmppeak->getParameter(
"S")
1766 <<
", FWHM = " << tmppeak->fwhm() <<
'\n';
1770 stringstream peakWSData;
1771 peakWSData <<
"Partial workspace for peaks: \n";
1772 for (
size_t i = 0; i < peaksws->x(0).size(); ++i)
1773 peakWSData << peaksws->x(1)[i] <<
"\t\t" << peaksws->y(1)[i] <<
"\t\t" << peaksws->e(1)[i] <<
"\t\t"
1774 << peaksws->y(0)[i] <<
'\n';
1785 for (
auto &peak : peaks)
1786 peaksfunction->addFunction(peak);
1789 vector<double> chi2s;
1790 vector<bool> fitgoods;
1791 bool fitsuccess =
doFitMultiplePeaks(peaksws, 1, peaksfunction, peaks, fitgoods, chi2s);
1796 plotFunction(peaksfunction, backgroundfunction, domain);
1807 vector<BackToBackExponential_sptr> peakfuncs, vector<bool> &vecfitgood,
1808 vector<double> &vecchi2s) {
1811 dbss <<
"[DBx529] Composite Function: " << peaksfunc->asString();
1815 const size_t numpeaks = peakfuncs.size();
1816 map<string, double> peaksfuncparams;
1819 vector<string> peakparnames = peakfuncs[0]->getParameterNames();
1820 for (
size_t ipn = 0; ipn < peakparnames.size(); ++ipn) {
1821 bool isI = peakparnames[ipn] ==
"I";
1823 for (
size_t ipk = 0; ipk < numpeaks; ++ipk) {
1826 thispeak->unfix(ipn);
1833 dbss1 <<
"[DBx529A] Composite Function: " << peaksfunc->asString();
1838 bool fitgood =
doFitNPeaksSimple(dataws, wsindex, peaksfunc, peakfuncs,
"Levenberg-MarquardtMD", 1000, chi2);
1839 bool evergood = fitgood;
1843 vecfitgood.resize(numpeaks,
false);
1844 vecchi2s.resize(numpeaks, -1.0);
1847 vecfitgood.resize(numpeaks,
true);
1848 vecchi2s.resize(numpeaks, chi2);
1852 for (
size_t ipkfit = 0; ipkfit < numpeaks; ++ipkfit) {
1854 for (
size_t ipk = 0; ipk < numpeaks; ++ipk) {
1856 for (
size_t iparam = 0; iparam < peakparnames.size(); ++iparam) {
1857 if (ipk == ipkfit) {
1859 thispeak->unfix(iparam);
1862 thispeak->fix(iparam);
1870 fitgood =
doFitNPeaksSimple(dataws, wsindex, peaksfunc, peakfuncs,
"Levenberg-MarquardtMD", 1000, chi2);
1881 for (
size_t ipk = 0; ipk < numpeaks; ++ipk) {
1883 for (
size_t iparam = 0; iparam < peakparnames.size(); ++iparam)
1884 thispeak->unfix(iparam);
1888 fitgood =
doFitNPeaksSimple(dataws, wsindex, peaksfunc, peakfuncs,
"Levenberg-MarquardtMD", 1000, chi2);
1898 peaksfunc->function(domain, values);
1900 for (
size_t i = 0; i < domain.
size(); ++i)
1901 rss << domain[i] <<
"\t\t" << values[i] <<
'\n';
1902 g_log.
information() <<
"[T] Multiple peak fitting pattern:\n" << rss.str();
1914 vector<BackToBackExponential_sptr> peaks) {
1918 vector<vector<double>> peakvalues;
1919 for (
size_t i = 0; i < (peaks.size() + 1); ++i) {
1920 vector<double> peakvalue(domain.
size(), 0.0);
1921 peakvalues.emplace_back(peakvalue);
1925 size_t isum = peaks.size();
1926 for (
size_t ipk = 0; ipk < peaks.size(); ++ipk) {
1928 thispeak->setHeight(1.0);
1929 thispeak->function(domain, values);
1930 for (
size_t j = 0; j < domain.
size(); ++j) {
1931 peakvalues[ipk][j] = values[j];
1932 peakvalues[isum][j] += values[j];
1937 const auto &vecY = dataws->y(wsindex);
1938 for (
size_t ipk = 0; ipk < peaks.size(); ++ipk) {
1940 for (
size_t j = 0; j < domain.
size() - 1; ++j) {
1941 if (vecY[j] > 0.0 && peakvalues[isum][j] > 1.0E-5) {
1942 double dtof = domain[j + 1] - domain[j];
1943 double temp = vecY[j] * peakvalues[ipk][j] / peakvalues[isum][j] * dtof;
1949 thispeak->setHeight(
height);
1952 <<
" Set Guessed Height (LeBail) = " << thispeak->height() <<
'\n';
1960 for (
const auto &thispeak : peaks) {
1962 double fwhm = thispeak->fwhm();
1963 double centre = thispeak->centre();
1964 double leftcentrebound = centre - 0.5 * fwhm;
1965 double rightcentrebound = centre + 0.5 * fwhm;
1967 auto bc = std::make_unique<BoundaryConstraint>(thispeak.get(),
"X0", leftcentrebound, rightcentrebound,
false);
1968 thispeak->addConstraint(std::move(bc));
1977 const vector<BackToBackExponential_sptr> &peakfuncs,
1978 const string &minimizername,
size_t maxiteration,
double &chi2) {
1981 dbss0 <<
"Starting Value: ";
1982 vector<string> paramNames = peaksfunc->getParameterNames();
1983 for (
auto ¶mName : paramNames)
1984 dbss0 << paramName <<
"= " << peaksfunc->getParameter(paramName) <<
", \t";
1989 fitalg->initialize();
1992 fitalg->setProperty(
"Function", std::dynamic_pointer_cast<API::IFunction>(peaksfunc));
1993 fitalg->setProperty(
"InputWorkspace", dataws);
1994 fitalg->setProperty(
"WorkspaceIndex",
static_cast<int>(wsindex));
1995 fitalg->setProperty(
"Minimizer", minimizername);
1996 fitalg->setProperty(
"CostFunction",
"Least squares");
1997 fitalg->setProperty(
"MaxIterations",
static_cast<int>(maxiteration));
1998 fitalg->setProperty(
"Output",
"FitPeak");
2001 bool isexecute = fitalg->execute();
2002 bool fitsuccess =
false;
2007 dbss <<
"Fit N-Peaks @ ";
2008 for (
auto &peakfunc : peakfuncs)
2009 dbss << peakfunc->centre() <<
", ";
2013 std::string fitresult =
parseFitResult(fitalg, chi2, fitsuccess);
2015 dbss <<
" Result:" << fitsuccess <<
"\n"
2016 <<
"Detailed info = " << fitresult;
2023 g_log.
information() <<
"[DBx149B] Fitted Parameters: \n" << infofit <<
'\n';
2025 dbss <<
": Failed ";
2026 g_log.
error() <<
"[DBx149C] " << dbss.str() <<
'\n';
2040 chi2 = fitalg->getProperty(
"OutputChi2overDoF");
2041 string fitstatus = fitalg->getProperty(
"OutputStatus");
2043 fitsuccess = (fitstatus ==
"success");
2045 rss <<
" [Algorithm Fit]: Chi^2 = " << chi2 <<
"; Fit Status = " << fitstatus;
2056 g_log.
warning() <<
"Input table workspace is NULL. \n";
2061 std::stringstream msgss;
2062 size_t numrows = paramws->rowCount();
2063 for (
size_t i = 0; i < numrows; ++i) {
2065 std::string parname;
2066 double parvalue, parerror;
2067 row >> parname >> parvalue >> parerror;
2069 msgss << parname <<
" = " << setw(10) << setprecision(5) << parvalue <<
" +/- " << setw(10) << setprecision(5)
2070 << parerror <<
'\n';
2084 std::vector<std::string> colnames = parameterWS->getColumnNames();
2085 if (colnames.size() < 2) {
2087 errss <<
"Input parameter table workspace does not have enough number of "
2089 <<
" Number of columns = " << colnames.
size() <<
" >= 2 as required. ";
2091 throw std::runtime_error(errss.str());
2094 if (colnames[0] !=
"Name" || colnames[1] !=
"Value") {
2096 errss <<
"Input parameter table workspace does not have the columns in "
2098 <<
"Name, Value and etc. ";
2100 throw std::runtime_error(errss.str());
2103 size_t numrows = parameterWS->rowCount();
2105 g_log.
notice() <<
"[DBx409] Import TableWorkspace " << parameterWS->getName() <<
" containing " << numrows
2106 <<
" instrument profile parameters\n";
2109 std::string parname;
2113 for (
size_t ir = 0; ir < numrows; ++ir) {
2115 trow >> parname >>
value;
2117 g_log.
notice() <<
"[DBx211] Import parameter " << parname <<
": " <<
value <<
'\n';
2124 vector<map<string, int>> &hklmaps) {
2126 vector<string> paramnames = peakws->getColumnNames();
2127 size_t numcols = paramnames.size();
2128 vector<string> coltypes(numcols);
2129 for (
size_t i = 0; i < numcols; ++i) {
2131 string coltype = col->type();
2132 coltypes[i] = coltype;
2136 size_t numrows = peakws->rowCount();
2137 for (
size_t irow = 0; irow < numrows; ++irow) {
2139 map<string, int> intmap;
2140 map<string, double> doublemap;
2143 for (
size_t icol = 0; icol < numcols; ++icol) {
2144 string coltype = coltypes[icol];
2145 string colname = paramnames[icol];
2147 if (coltype ==
"int") {
2149 int temp = peakws->cell<
int>(irow, icol);
2150 intmap.emplace(colname, temp);
2151 }
else if (coltype ==
"double") {
2153 double temp = peakws->cell<
double>(irow, icol);
2154 doublemap.emplace(colname, temp);
2159 parammaps.emplace_back(doublemap);
2160 hklmaps.emplace_back(intmap);
2164 g_log.
information() <<
"Import " << hklmaps.size() <<
" entries from Bragg peak TableWorkspace " << peakws->getName()
2173 int workspaceindex) {
2175 const auto &
X =
m_dataWS->x(workspaceindex);
2177 if (pattern.size() !=
X.size()) {
2178 stringstream errmsg;
2179 errmsg <<
"Input pattern (" << pattern.size() <<
") and algorithm's input workspace (" <<
X.size()
2180 <<
") have different size. ";
2182 throw std::logic_error(errmsg.str());
2190 for (
size_t iw = 0; iw < 5; ++iw) {
2191 dataws->setSharedX(iw,
m_dataWS->sharedX(workspaceindex));
2194 dataws->setSharedY(0,
m_dataWS->sharedY(workspaceindex));
2195 dataws->mutableY(1) = pattern;
2196 dataws->mutableY(2) =
m_dataWS->y(workspaceindex) - pattern;
2207 throw runtime_error(
"Wrong definition of m_peakFitChi2");
2213 vector<double> vecdh, vectofh, vecalpha, vecbeta, vecsigma, vecchi2;
2214 for (
size_t i = 0; i < numpeaks; ++i) {
2221 double p_a = peak->getParameter(
"A");
2222 double p_b = peak->getParameter(
"B");
2223 double p_x = peak->getParameter(
"X0");
2224 double p_s = peak->getParameter(
"S");
2227 vecchi2.emplace_back(chi2);
2228 vecdh.emplace_back(dh);
2229 vectofh.emplace_back(p_x);
2230 vecalpha.emplace_back(p_a);
2231 vecbeta.emplace_back(p_b);
2232 vecsigma.emplace_back(p_s);
2237 size_t numgoodpeaks = vecdh.size();
2240 for (
size_t j = 0; j < 4; ++j) {
2241 paramws->mutableX(j) = vecdh;
2242 paramws->mutableE(j) = vecchi2;
2244 paramws->mutableY(0) = vectofh;
2245 paramws->mutableY(1) = vecalpha;
2246 paramws->mutableY(2) = vecbeta;
2247 paramws->mutableY(3) = vecsigma;
2250 paramws->getAxis(0)->setUnit(
"dSpacing");
2252 auto tAxis = std::make_unique<TextAxis>(4);
2253 tAxis->setLabel(0,
"X0");
2254 tAxis->setLabel(1,
"A");
2255 tAxis->setLabel(2,
"B");
2256 tAxis->setLabel(3,
"S");
2258 paramws->replaceAxis(1, std::move(tAxis));
2275 throw runtime_error(
"Wrong definition of m_peakFitChi2");
2279 vector<double> vectofh(numpeaks), vecalpha(numpeaks), vecbeta(numpeaks), vecsigma(numpeaks);
2285 tablews->addColumn(
"int",
"H");
2286 tablews->addColumn(
"int",
"K");
2287 tablews->addColumn(
"int",
"L");
2289 tablews->addColumn(
"double",
"d_h");
2290 tablews->addColumn(
"double",
"TOF_h");
2291 tablews->addColumn(
"double",
"Height");
2292 tablews->addColumn(
"double",
"Alpha");
2293 tablews->addColumn(
"double",
"Beta");
2294 tablews->addColumn(
"double",
"Sigma");
2295 tablews->addColumn(
"double",
"Chi2");
2305 for (
size_t i = 0; i < numpeaks; ++i) {
2313 TableRow newrow = tablews->appendRow();
2316 newrow << hkl[0] << hkl[1] << hkl[2] << dh;
2319 double p_a = peak->getParameter(
"A");
2320 double p_b = peak->getParameter(
"B");
2321 double p_i = peak->getParameter(
"I");
2322 double p_x = peak->getParameter(
"X0");
2323 double p_s = peak->getParameter(
"S");
2324 newrow << p_x << p_i << p_a << p_b << p_s;
2363 ztablews->addColumn(
"int",
"H");
2364 ztablews->addColumn(
"int",
"K");
2365 ztablews->addColumn(
"int",
"L");
2367 ztablews->addColumn(
"double",
"d_h");
2368 ztablews->addColumn(
"double",
"Z_TOF_h");
2369 ztablews->addColumn(
"double",
"Z_Alpha");
2370 ztablews->addColumn(
"double",
"Z_Beta");
2371 ztablews->addColumn(
"double",
"Z_Sigma");
2381 TableRow newrow = ztablews->appendRow();
2382 newrow << hkl[0] << hkl[1] << hkl[2] << dh;
2385 double p_x = zcentres[i];
2386 double p_a = zalphas[i];
2387 double p_b = zbetas[i];
2388 double p_s = zsigma[i];
2390 newrow << p_x << p_a << p_b << p_s;
2394 return make_pair(tablews, ztablews);
2406 errss <<
"Input tableworkspace for peak parameters is invalid!";
2408 throw std::invalid_argument(errss.str());
2420 vector<map<std::string, double>> peakparametermaps;
2421 vector<map<std::string, int>> peakhkls;
2426 map<string, string> bk2bk2braggmap{{
"A",
"Alpha"}, {
"B",
"Beta"}, {
"X0",
"TOF_h"},
2427 {
"I",
"Height"}, {
"S",
"Sigma"}, {
"S2",
"Sigma2"}};
2430 size_t numrows = peakparamws->rowCount();
2431 for (
size_t ir = 0; ir < numrows; ++ir) {
2450 dbss <<
"Specified range for peaks in TOF: " << tofmin <<
", " << tofmax <<
"\n";
2454 double d_h = deliter->first;
2455 const vector<int> &hkl = deliter->second.first;
2457 double tofh = peak->getParameter(
"X0");
2459 dbss <<
"\tPeak (" << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
") @ d = " << d_h
2460 <<
" (calculated TOF) = " << tofh <<
" ";
2462 if (tofh < tofmin || tofh > tofmax) {
2465 dbss <<
": Delete due to out of range. \n";
2470 dbss <<
": Kept. \n";
2474 g_log.
notice() <<
"[DBx453] " << dbss.str() <<
"\n";
2480 vector<int> hkl = deliter->second.first;
2489 if (ind1stpeak > 0) {
2496 g_log.
warning() <<
"Minimum peak " << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
" does not exit. \n";
2503 vector<int> hkl = deliter->second.first;
2504 double d_h = deliter->first;
2505 double tof_h = deliter->second.second->centre();
2506 dbout <<
"Peak (" << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
") @ d = " << d_h <<
", TOF = " << tof_h <<
'\n';
2524 map<string, string> bk2bk2braggmap,
bool &good, vector<int> &hkl,
2528 newpeakptr->initialize();
2564 errss <<
"In input InstrumentParameterTable, one of the following is not "
2565 "given. Unable to process. \n";
2566 errss <<
"Tcross = " << tcross <<
"; Width = " << width <<
", Dtt1 = " << dtt1 <<
", Dtt1t = " << dtt1t <<
'\n';
2567 errss <<
"Dtt2t = " << dtt2t <<
", Zero = " << zero <<
", Zerot = " << zerot;
2570 throw runtime_error(errss.str());
2573 bool caltofonly =
false;
2578 g_log.
warning() <<
"[DBx343] At least one of the input instrument-peak "
2579 "profile parameters is not given. "
2580 <<
"Use (HKL) only!\n";
2581 g_log.
warning() <<
"Alph0 = " << alph0 <<
", Alph1 = " << alph1 <<
", Alph0t = " << alph0t
2582 <<
", Alph1t = " << alph1t <<
'\n';
2583 g_log.
warning() <<
"Beta0 = " << beta0 <<
", Beta1 = " << beta1 <<
", Beta0t = " << beta0t
2584 <<
", Beta1t = " << beta1t <<
'\n';
2585 g_log.
warning() <<
"Sig0 = " << sig0 <<
", Sig1 = " << sig1 <<
", Sig2 = " << sig2 <<
'\n';
2594 if ((d_h != d_h) || (d_h < -DBL_MAX) || (d_h > DBL_MAX)) {
2595 stringstream warnss;
2596 warnss <<
"Peak with Miller Index = " << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2]
2597 <<
" has unphysical d-spacing value = " << d_h;
2605 newpeakptr->setCentre(tof_h);
2616 for (
const auto &parname : tnb2bfuncparnames) {
2617 if (parname !=
"Height") {
2621 errss <<
"Cannot find peak parameter " << parname <<
" in input instrument parameter "
2622 <<
"TableWorkspace. This mode is unable to execute. Quit!";
2624 throw runtime_error(errss.str());
2626 double parvalue = miter->second;
2637 double tof_h = tnb2bfunc.
centre();
2639 newpeakptr->setParameter(
"A", alpha);
2640 newpeakptr->setParameter(
"B", beta);
2641 newpeakptr->setParameter(
"S", sqrt(sigma2));
2642 newpeakptr->setParameter(
"X0", tof_h);
2645 peakcalmode =
"Calculate all parameters by thermal neutron peak function.";
2650 vector<string>::iterator nameiter;
2653 string b2bexpname = *nameiter;
2655 map<string, string>::iterator refiter;
2656 refiter = bk2bk2braggmap.find(b2bexpname);
2657 if (refiter == bk2bk2braggmap.end())
2658 throw runtime_error(
"Programming error!");
2659 string instparname = refiter->second;
2662 map<string, double>::iterator miter;
2663 miter = parammap.find(instparname);
2664 if (miter != parammap.end()) {
2666 double parvalue = miter->second;
2667 if (b2bexpname ==
"S2") {
2668 newpeakptr->setParameter(
"S", sqrt(parvalue));
2670 newpeakptr->setParameter(b2bexpname, parvalue);
2675 peakcalmode =
"Import from Bragg peaks table";
2679 stringstream infoss;
2680 string peakinfo =
getFunctionInfo(std::dynamic_pointer_cast<IFunction>(newpeakptr));
2682 infoss <<
"Generate Peak (" << hkl[0] <<
", " << hkl[1] <<
", " << hkl[2] <<
") Of Mode " << peakcalmode <<
".\n";
2703 double x0 = domain[0];
2704 auto viter = lower_bound(vecX.cbegin(), vecX.cend(), x0);
2705 int ix0 =
static_cast<int>(std::distance(vecX.cbegin(), viter));
2708 if ((
static_cast<int>(domain.
size()) + ix0) >
static_cast<int>(
m_peakData.size()))
2709 throw runtime_error(
"Plot single peak out of boundary error!");
2713 peakfunction->function(domain, values1);
2715 for (
int i = 0; i < static_cast<int>(domain.
size()); ++i)
2720 background->function(domain, values2);
2722 for (
int i = 0; i < static_cast<int>(domain.
size()); ++i)
2735 vector<string> strhkl(3);
2742 map<string, int>::iterator miter;
2743 for (
size_t i = 0; i < 3; ++i) {
2744 string parname = strhkl[i];
2745 miter = intmap.find(parname);
2746 if (miter == intmap.end())
2749 hkl.emplace_back(miter->second);
2762 cropalg->initialize();
2764 cropalg->setProperty(
"InputWorkspace",
m_dataWS);
2765 cropalg->setPropertyValue(
"OutputWorkspace",
"MyData");
2766 cropalg->setProperty(
"XMin", tofmin);
2767 cropalg->setProperty(
"XMax", tofmax);
2769 bool cropstatus = cropalg->execute();
2771 std::stringstream errmsg;
2773 errmsg <<
"DBx309 Cropping workspace unsuccessful. Fatal Error. Quit!";
2775 throw std::runtime_error(errmsg.str());
2778 m_dataWS = cropalg->getProperty(
"OutputWorkspace");
2780 errmsg <<
"Unable to retrieve a Workspace2D object from ChildAlgorithm Crop.";
2782 throw std::runtime_error(errmsg.str());
2795 map<string, double>::iterator mapiter;
2801 <<
"does not have parameter " << parname <<
". ";
2806 return mapiter->second;
2817 size_t workspaceindex,
double leftbound,
double rightbound) {
2819 const auto &
X = sourcews->x(workspaceindex);
2820 const auto &
Y = sourcews->y(workspaceindex);
2821 const auto &E = sourcews->e(workspaceindex);
2823 if (leftbound >= rightbound) {
2824 stringstream errmsg;
2825 errmsg <<
"[BuildPartialWorkspace] Input left boundary = " << leftbound <<
" is larger than input right boundary "
2826 << rightbound <<
". It is not allowed. ";
2827 throw std::invalid_argument(errmsg.str());
2829 if (leftbound >=
X.back() || rightbound <=
X[0]) {
2830 throw std::invalid_argument(
"Boundary is out side of the input data set. ");
2834 int ileft =
static_cast<int>(std::lower_bound(
X.begin(),
X.end(), leftbound) -
X.begin());
2837 int iright =
static_cast<int>(std::lower_bound(
X.begin(),
X.end(), rightbound) -
X.begin());
2838 if (iright >=
static_cast<int>(
X.size()))
2839 iright =
static_cast<int>(
X.size() - 1);
2841 auto wssize =
static_cast<size_t>(iright - ileft + 1);
2850 for (
size_t iw = 0; iw < partws->getNumberHistograms(); ++iw) {
2852 for (
size_t i = 0; i < wssize; ++i) {
2853 nX[i] =
X[i + ileft];
2856 auto &nY = partws->mutableY(0);
2857 auto &nE = partws->mutableE(0);
2858 for (
size_t i = 0; i < wssize; ++i) {
2859 nY[i] =
Y[i + ileft];
2860 nE[i] = E[i + ileft];
2872 vector<string> parnames = function->getParameterNames();
2873 size_t numpars = parnames.size();
2874 outss <<
"Number of Parameters = " << numpars <<
'\n';
2875 for (
size_t i = 0; i < numpars; ++i)
2876 outss << parnames[i] <<
" = " << function->getParameter(i) <<
", \t\tFitted = " << function->isActive(i) <<
'\n';
2894 size_t wsindexraw,
size_t wsindexbkgd,
size_t wsindexpeak) {
2896 if (dataws->getNumberHistograms() < 3) {
2898 errss <<
"Function estimateBackgroundCoase() requires input Workspace2D "
2899 "has at least 3 spectra."
2900 <<
"Present input has " << dataws->getNumberHistograms() <<
" spectra.";
2901 throw runtime_error(errss.str());
2903 const auto &
X = dataws->x(wsindexraw);
2904 const auto &
Y = dataws->y(wsindexraw);
2907 size_t numsamplepts = 2;
2908 if (
X.size() <= 10) {
2917 for (
size_t i = 0; i < numsamplepts; ++i) {
2921 x0 = x0 /
static_cast<double>(numsamplepts);
2922 y0 = y0 /
static_cast<double>(numsamplepts);
2926 for (
size_t i =
X.size() - numsamplepts; i <
X.size(); ++i) {
2930 xf = xf /
static_cast<double>(numsamplepts);
2931 yf = yf /
static_cast<double>(numsamplepts);
2934 double b1 = (yf - y0) / (xf - x0);
2935 double b0 = yf - b1 * xf;
2937 background->setParameter(
"A0", b0);
2938 background->setParameter(
"A1", b1);
2943 background->function(domain, values);
2945 dataws->mutableY(wsindexbkgd) = values.
toVector();
2946 dataws->mutableY(wsindexpeak) = dataws->y(wsindexraw) - dataws->y(wsindexbkgd);
2947 dataws->mutableE(wsindexpeak) = dataws->e(wsindexraw);
2967 const auto &
X = dataws->x(wsindex);
2968 const auto &
Y = dataws->y(wsindex);
2972 centre =
X[icentre];
2975 if (icentre <= 1 || icentre >
X.size() - 2) {
2977 errss <<
"Peak center = " << centre <<
" is at the edge of the input workspace [" <<
X[0] <<
", " <<
X.back()
2978 <<
". It is unable to proceed the estimate of FWHM. Quit with error!.";
2979 errmsg = errss.str();
2984 errss <<
"Max height = " <<
height <<
" in input workspace [" <<
X[0] <<
", " <<
X.back()
2985 <<
" is negative. Fatal error is design of the algorithm.";
2986 errmsg = errss.str();
2991 double halfMax =
height * 0.5;
2994 bool continueloop =
true;
2995 size_t index = icentre - 1;
2996 while (continueloop) {
2997 if (
Y[
index] <= halfMax) {
2999 continueloop =
false;
3000 }
else if (
index == 0) {
3003 errss <<
"The peak is not complete (left side) in the given data range.";
3004 errmsg = errss.str();
3012 double xf =
X[
index + 1];
3014 double yf =
Y[
index + 1];
3019 double lefthalffwhm = centre - xl;
3022 continueloop =
true;
3023 index = icentre + 1;
3024 while (continueloop) {
3025 if (
Y[
index] <= halfMax) {
3027 continueloop =
false;
3028 }
else if (
index ==
Y.size() - 1) {
3031 errss <<
"The peak is not complete (right side) in the given data range.";
3032 errmsg = errss.str();
3046 double righthalffwhm = xr - centre;
3049 fwhm = lefthalffwhm + righthalffwhm;
3061 auto maxIt = std::max_element(
Y.begin(),
Y.end());
3062 return std::distance(
Y.begin(), maxIt);
3074 const auto &
X = dataws->x(wsindex);
3075 const auto &
Y = dataws->y(wsindex);
3078 std::vector<double>::const_iterator viter;
3080 viter = std::lower_bound(
X.begin(),
X.end(), leftbound);
3081 size_t ixmin = size_t(viter -
X.begin());
3084 viter = std::lower_bound(
X.begin(),
X.end(), rightbound);
3085 size_t ixmax = size_t(viter -
X.begin());
3088 size_t imax = ixmin;
3089 double maxY =
Y[ixmin];
3090 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.
const 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.
size_t size() const
Returns the number of rows in the 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.
DataObjects::Workspace2D_sptr genOutputFittedPatternWorkspace(const std::vector< double > &pattern, int workspaceindex)
Create a Workspace2D for fitted peaks (pattern)
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:
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.
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.