15#include "boost/math/special_functions/round.hpp"
35 :
API::
Algorithm(), m_profileParamMap(), m_profileTableWS(), m_outIrfFilename(), m_bankID(-1),
36 m_fpProfileNumber(-1), m_append(false) {}
43 "Input TableWorkspace containing the parameters for .irf file.");
45 std::vector<std::string> exts{
".irf"};
47 "Name of the output .irf file.");
49 std::shared_ptr<BoundedValidator<int>> bankboundval = std::make_shared<BoundedValidator<int>>();
50 bankboundval->setLower(0);
53 vector<string> supportedfunctions;
54 supportedfunctions.emplace_back(
"Back-to-back exponential convoluted with pseudo-voigt (profile 9)");
55 supportedfunctions.emplace_back(
"Jason Hodge's function (profile 10)");
56 auto funcvalidator = std::make_shared<StringListValidator>(supportedfunctions);
57 declareProperty(
"ProfileFunction",
"Jason Hodge's function (profile 10)", funcvalidator,
58 "Profile number defined in Fullprof.");
61 "If true and the output file exists, the "
62 "bank will be appended to the existing "
88 throw runtime_error(
"Profile number is not supported yet.");
95 ofile.open(
m_outIrfFilename.c_str(), std::ofstream::out | std::ofstream::app);
99 ofile.open(
m_outIrfFilename.c_str(), std::ofstream::out | std::ofstream::trunc);
117 throw runtime_error(
"Input file name invalid. ");
130 string proffunction =
getProperty(
"ProfileFunction");
131 if (proffunction ==
"Back-to-back exponential convoluted with pseudo-voigt (profile 9)")
133 else if (proffunction ==
"Jason Hodge's function (profile 10)")
137 errmsg <<
"It is impossible to have profile function " << proffunction <<
" input. ";
139 throw runtime_error(errmsg.str());
150 size_t numcols = colnames.size();
152 stringstream dbmsgss(
"Input table's column names: ");
153 for (
const auto &colname : colnames) {
154 dbmsgss << setw(20) << colname;
158 if (colnames[0] !=
"Name")
159 throw runtime_error(
"First colunm must be 'Name'");
163 vector<string> vec_parnames(numpars);
164 int rowbankindex = -1;
165 for (
size_t i = 0; i < numpars; ++i) {
167 vec_parnames[i] = parname;
168 if (parname ==
"BANK")
169 rowbankindex =
static_cast<int>(i);
174 if (rowbankindex < 0) {
177 const auto it = std::find_if(colnames.begin() + 1, colnames.end(),
178 [](
const std::string &colname) { return colname.starts_with(
"Value"); });
179 if (it != colnames.end()) {
180 colindex =
static_cast<int>(std::distance(colnames.begin(), it));
185 for (
size_t i = 1; i < numcols; ++i) {
186 if (colnames[i].starts_with(
"Value")) {
187 int bankid = boost::math::iround(
m_profileTableWS->cell<
double>(rowbankindex, i));
189 colindex =
static_cast<int>(i);
197 throw runtime_error(
"Unable to find column");
199 throw runtime_error(
"Impossible to have this situation.");
206 for (
size_t ir = 0; ir < numpars; ++ir) {
207 double parvalue =
m_profileTableWS->cell<
double>(ir,
static_cast<size_t>(colindex));
212 stringstream dbss(
"Imported Parameter Table: \n");
213 map<string, double>::iterator mit;
215 dbss << setw(20) << mit->first <<
" = " << setprecision(5) << mit->second <<
'\n';
252 if (profindex == 0) {
254 }
else if (profindex != 10) {
256 errmsg <<
"This column in table has profile number " << profindex <<
" other than 10.";
258 throw runtime_error(errmsg.str());
261 stringstream content;
266 content <<
" Instrumental resolution function for POWGEN/SNS ireso: 6"
268 content <<
"! To be used with function NPROF=" << profindex <<
" in FullProf (Res=6)"
273 content <<
"! ---------------------------------------------- Bank " <<
m_bankID <<
" ";
277 content <<
"CWL = " << setprecision(4) << cwl <<
"A"
286 content <<
"! Type of profile function: back-to-back exponentials * pseudo-Voigt"
288 content <<
"NPROF " << profindex <<
"\n";
290 content <<
"! Tof-min(us) step Tof-max(us)"
292 content <<
"TOFRG " << setprecision(3) << tofmin <<
" " << setw(16) << setprecision(5) << tofstep <<
" " << setw(16)
293 << setprecision(3) << tofmax <<
"\n";
295 content <<
"! Zero Dtt1"
297 content <<
"ZD2TOF " << setw(16) << setprecision(5) << zero << setw(16) << setprecision(5) << dtt1 <<
"\n";
299 content <<
"! Zerot Dtt1t Dtt2t x-cross Width"
301 content <<
"ZD2TOT " << setprecision(5) << zerot << setw(16) << setprecision(5) << dtt1t << setw(16)
302 << setprecision(5) << dtt2t << setw(16) << setprecision(10) << xcross << setw(16) << setprecision(5) << width
305 content <<
"! TOF-TWOTH of the bank"
307 content <<
"TWOTH " << setprecision(3) << twotheta <<
"\n";
312 content <<
"! Sig-2 Sig-1 Sig-0"
314 content <<
"SIGMA " << setprecision(6) << sig2 * sig2 << setw(16) << setprecision(6) << sig1 * sig1 << setw(16)
315 << setprecision(6) << sig0 * sig0 <<
"\n";
317 content <<
"! Gam-2 Gam-1 Gam-0"
319 content <<
"GAMMA " << setw(16) << setprecision(6) << gam2 <<
" " << setw(16) << setprecision(6) << gam1 <<
" "
320 << setw(16) << setprecision(6) << gam0 <<
"\n";
322 content <<
"! alph0 beta0 alph1 beta1"
324 content <<
"ALFBE " << setprecision(6) << alph0 <<
" " << setw(16) << setprecision(6) << beta0 <<
" "
325 << setw(16) << setprecision(6) << alph1 <<
" " << setw(16) << setprecision(6) << beta1 <<
"\n";
327 content <<
"! alph0t beta0t alph1t beta1t"
329 content <<
"ALFBT " << setprecision(6) << alph0t <<
" " << setw(16) << setprecision(6) << beta0t <<
" "
330 << setw(16) << setprecision(6) << alph1t <<
" " << setw(16) << setprecision(6) << beta1t <<
"\n";
334 return content.str();
364 if (profindex == 0) {
366 }
else if (profindex != 9) {
368 errmsg <<
"This column in table has profile number " << profindex <<
" other than 9.";
370 throw runtime_error(errmsg.str());
373 stringstream content;
378 content <<
"Instrumental resolution function for HRPD/ISIS L. Chapon "
381 content <<
"! To be used with function NPROF=" << profindex <<
" in FullProf (Res=5)"
386 content <<
"! ---------------------------------------------- Bank " <<
m_bankID <<
" ";
390 content <<
"CWL = " << setprecision(4) << cwl <<
"A"
399 content <<
"! Type of profile function: back-to-back exponentials * pseudo-Voigt"
401 content <<
"NPROF " << profindex <<
"\n";
402 content <<
"! Tof-min(us) step Tof-max(us)"
404 content <<
"TOFRG " << setprecision(3) << tofmin <<
" " << setw(16) << setprecision(5) << tofstep <<
" " << setw(16)
405 << setprecision(3) << tofmax <<
"\n";
407 content <<
"! Dtt1 Dtt2 Zero"
409 content <<
"D2TOF " << setw(16) << setprecision(5) << dtt1 << setw(16) << setprecision(5) << dtt2 << setw(16)
410 << setprecision(5) << zero <<
"\n";
412 content <<
"! TOF-TWOTH of the bank"
414 content <<
"TWOTH " << setprecision(3) << twotheta <<
"\n";
419 content <<
"! Sig-2 Sig-1 Sig-0"
421 content <<
"SIGMA " << setprecision(6) << sig2 * sig2 << setw(16) << setprecision(6) << sig1 * sig1 << setw(16)
422 << setprecision(6) << sig0 * sig0 <<
"\n";
424 content <<
"! Gam-2 Gam-1 Gam-0"
426 content <<
"GAMMA " << setw(16) << setprecision(6) << gam2 <<
" " << setw(16) << setprecision(6) << gam1 <<
" "
427 << setw(16) << setprecision(6) << gam0 <<
"\n";
429 content <<
"! alph0 beta0 alph1 beta1"
431 content <<
"ALFBE " << setprecision(6) << alph0 <<
" " << setw(16) << setprecision(6) << beta0 <<
" "
432 << setw(16) << setprecision(6) << alph1 <<
" " << setw(16) << setprecision(6) << beta1 <<
"\n";
437 return content.str();
444 map<string, double>::iterator fiter;
445 fiter = profmap.find(key);
447 if (fiter == profmap.end())
#define DECLARE_ALGORITHM(classname)
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
@ Save
to specify a file to write to, the file may or may not exist
A property class for workspaces.
SaveFullprofResolution : TODO: DESCRIPTION.
void parseTableWorkspace()
Parse input workspace to map of parameters.
void exec() override
Execution code.
int m_bankID
Bank to write.
std::string m_outIrfFilename
Output Irf file name.
void processProperties()
Write the header information.
std::string toProf10IrfString()
Write out string for profile 10 .irf file.
int m_fpProfileNumber
Profile number.
DataObjects::TableWorkspace_sptr m_profileTableWS
Input table workspace.
void init() override
Initialisation code.
std::string toProf9IrfString()
Write out string for profile 9 .irf file.
bool has_key(std::map< std::string, double > profmap, const std::string &key)
Check wether a profile parameter map has the parameter.
std::map< std::string, double > m_profileParamMap
Map containing the name of value of each parameter required by .irf file.
bool m_append
Append to existing file.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
Helper class which provides the Collimation Length for SANS instruments.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
@ Input
An input workspace.