33using namespace Kernel;
36using namespace DataObjects;
43 "An input PeaksWorkspace with an instrument.");
44 std::vector<std::string> cellTypes;
52 declareProperty(
"CellType", cellTypes[0], std::make_shared<StringListValidator>(cellTypes),
"Select the cell type.");
56 declareProperty(
"EdgePixels", 0,
"Remove peaks that are at pixels this close to edge. ");
58 "Returns the goodness of the fit");
60 "The directory where the per run peaks files and orientation matrices "
64 gsl_set_error_handler_off();
80 std::vector<int> badPeaks;
81 std::vector<IPeaksWorkspace_sptr> runWS;
83 if (
auto pw = std::dynamic_pointer_cast<PeaksWorkspace>(ws)) {
85 for (
int i =
int(pw->getNumberPeaks()) - 1; i >= 0; --i) {
86 const std::vector<Peak> &peaks = pw->getPeaks();
87 if (
edgePixel(inst, peaks[i].getBankName(), peaks[i].getCol(), peaks[i].getRow(), edge)) {
88 badPeaks.emplace_back(i);
91 pw->removePeaks(std::move(badPeaks));
93 runWS.emplace_back(ws);
96 std::vector<std::pair<std::string, bool>> criteria;
98 criteria.emplace_back(
"runnumber",
true);
102 for (
int i = 0; i < ws->getNumberPeaks(); i++) {
103 IPeak &peak = ws->getPeak(i);
107 cloneWS->copyExperimentInfoFrom(ws.get());
108 runWS.emplace_back(cloneWS);
109 runWS[
count]->addPeak(peak);
113 runWS[
count]->addPeak(peak);
118 for (
auto &i_run : runWS) {
121 const DblMatrix UB = peakWS->sample().getOrientedLattice().getUB();
122 auto ol = peakWS->sample().getOrientedLattice();
123 DblMatrix modUB = peakWS->mutableSample().getOrientedLattice().getModUB();
124 int maxOrder = peakWS->mutableSample().getOrientedLattice().getMaxOrder();
125 bool crossTerms = peakWS->mutableSample().getOrientedLattice().getCrossTerm();
126 std::vector<double> lat(6);
139 fit_alg->setProperty(
"Function", std::static_pointer_cast<IFunction>(latticeFunction));
140 fit_alg->setProperty(
"Ties",
"ZeroShift=0.0");
141 fit_alg->setProperty(
"InputWorkspace", peakWS);
142 fit_alg->setProperty(
"CostFunction",
"Unweighted least squares");
143 fit_alg->setProperty(
"CreateOutput",
true);
144 fit_alg->executeAsChildAlg();
146 double chisq = fit_alg->getProperty(
"OutputChi2overDoF");
153 g_log.
error(
"Can't locate CalculateUMatrix algorithm");
157 ub_alg->setProperty(
"PeaksWorkspace", peakWS);
158 ub_alg->setProperty(
"a", refinedCell.
a());
159 ub_alg->setProperty(
"b", refinedCell.
b());
160 ub_alg->setProperty(
"c", refinedCell.
c());
161 ub_alg->setProperty(
"alpha", refinedCell.
alpha());
162 ub_alg->setProperty(
"beta", refinedCell.
beta());
163 ub_alg->setProperty(
"gamma", refinedCell.
gamma());
164 ub_alg->executeAsChildAlg();
165 DblMatrix UBnew = peakWS->mutableSample().getOrientedLattice().getUB();
166 auto o_lattice = std::make_unique<OrientedLattice>();
167 o_lattice->setUB(UBnew);
169 o_lattice->setModUB(modUB);
173 o_lattice->set(refinedCell.
a(), refinedCell.
b(), refinedCell.
c(), refinedCell.
alpha(), refinedCell.
beta(),
174 refinedCell.
gamma());
179 g_log.
notice() << i_run->getName() <<
" " << *o_lattice <<
"\n";
181 i_run->mutableSample().setOrientedLattice(std::move(o_lattice));
188 alg->setPropertyValue(
"PeaksWorkspace", i_run->getName());
189 alg->setProperty(
"Tolerance",
tolerance);
190 alg->executeAsChildAlg();
194 std::string outputdir =
getProperty(
"OutputDirectory");
195 if (outputdir.back() !=
'/')
199 savePks_alg->setPropertyValue(
"InputWorkspace", i_run->getName());
200 savePks_alg->setProperty(
"Filename", outputdir +
"ls" + i_run->getName() +
".integrate");
201 savePks_alg->executeAsChildAlg();
202 g_log.
notice() <<
"See output file: " << outputdir +
"ls" + i_run->getName() +
".integrate"
206 saveUB_alg->setPropertyValue(
"InputWorkspace", i_run->getName());
207 saveUB_alg->setProperty(
"Filename", outputdir +
"ls" + i_run->getName() +
".mat");
208 saveUB_alg->executeAsChildAlg();
210 g_log.
notice() <<
"See output file: " << outputdir +
"ls" + i_run->getName() +
".mat"
223 std::ostringstream fun_str;
224 fun_str <<
"name=LatticeFunction,LatticeSystem=" << cellType;
228 if (latticeFunction) {
229 latticeFunction->setUnitCell(cell);
232 return latticeFunction;
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
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.
@ Directory
to specify a directory that must exist
A property class for workspaces.
void exec() override
Executes the algorithm.
API::ILatticeFunction_sptr getLatticeFunction(const std::string &cellType, const Geometry::UnitCell &cell) const
void init() override
Initialisation method.
Structure describing a single-crystal peak.
virtual int getRunNumber() const =0
static bool GetLatticeParameters(const Kernel::DblMatrix &UB, std::vector< double > &lattice_par)
Get the lattice parameters for the specified orientation matrix.
static const std::string HEXAGONAL()
static const std::string MONOCLINIC()
static const std::string RHOMBOHEDRAL()
static const std::string CUBIC()
static const std::string TRICLINIC()
static const std::string TETRAGONAL()
static const std::string ORTHORHOMBIC()
Class to implement unit cell of crystals.
double alpha() const
Get lattice parameter.
double erroralpha(const int angleunit=angDegrees) const
Get lattice parameter error.
double a(int nd) const
Get lattice parameter a1-a3 as function of index (0-2)
double c() const
Get lattice parameter.
double errorgamma(const int angleunit=angDegrees) const
Get lattice parameter error.
double errorbeta(const int angleunit=angDegrees) const
Get lattice parameter error.
double beta() const
Get lattice parameter.
double b() const
Get lattice parameter.
double errorc() const
Get lattice parameter error.
double gamma() const
Get lattice parameter.
double errora() const
Get lattice parameter error.
double errorb() const
Get lattice parameter error.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< ILatticeFunction > ILatticeFunction_sptr
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
MANTID_GEOMETRY_DLL bool edgePixel(const Geometry::Instrument_const_sptr &inst, const std::string &bankName, int col, int row, int Edge)
Function to find peaks near detector edge.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.
@ Output
An output workspace.