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<IPeaksWorkspace_sptr> runWS;
82 if (
auto pw = std::dynamic_pointer_cast<PeaksWorkspace>(ws)) {
83 std::vector<int> badPeaks;
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);
95 int maxOrder = ws->mutableSample().getOrientedLattice().getMaxOrder();
96 DblMatrix modHKL = ws->mutableSample().getOrientedLattice().getModHKL();
99 for (
int i = 0; i < ws->getNumberPeaks(); i++) {
100 IPeak &peak = ws->getPeak(i);
107 std::vector<std::pair<std::string, bool>> criteria;
109 criteria.emplace_back(
"runnumber",
true);
113 for (
int i = 0; i < ws->getNumberPeaks(); i++) {
114 IPeak &peak = ws->getPeak(i);
118 cloneWS->copyExperimentInfoFrom(ws.get());
119 runWS.emplace_back(cloneWS);
120 runWS[
count]->addPeak(peak);
122 AnalysisDataService::Instance().addOrReplace(
std::to_string(run) + ws->getName(), runWS[
count]);
124 runWS[
count]->addPeak(peak);
129 for (
auto &i_run : runWS) {
131 AnalysisDataService::Instance().addOrReplace(
"_peaks", peakWS);
132 const DblMatrix UB = peakWS->sample().getOrientedLattice().getUB();
133 auto ol = peakWS->sample().getOrientedLattice();
134 DblMatrix modUB = peakWS->mutableSample().getOrientedLattice().getModUB();
135 bool crossTerms = peakWS->mutableSample().getOrientedLattice().getCrossTerm();
136 std::vector<double> lat(6);
149 fit_alg->setProperty(
"Function", std::static_pointer_cast<IFunction>(latticeFunction));
150 fit_alg->setProperty(
"Ties",
"ZeroShift=0.0");
151 fit_alg->setProperty(
"InputWorkspace", peakWS);
152 fit_alg->setProperty(
"CostFunction",
"Unweighted least squares");
153 fit_alg->setProperty(
"CreateOutput",
true);
154 fit_alg->executeAsChildAlg();
156 double chisq = fit_alg->getProperty(
"OutputChi2overDoF");
163 g_log.
error(
"Can't locate CalculateUMatrix algorithm");
167 ub_alg->setProperty(
"PeaksWorkspace", peakWS);
168 ub_alg->setProperty(
"a", refinedCell.
a());
169 ub_alg->setProperty(
"b", refinedCell.
b());
170 ub_alg->setProperty(
"c", refinedCell.
c());
171 ub_alg->setProperty(
"alpha", refinedCell.
alpha());
172 ub_alg->setProperty(
"beta", refinedCell.
beta());
173 ub_alg->setProperty(
"gamma", refinedCell.
gamma());
174 ub_alg->executeAsChildAlg();
175 DblMatrix UBnew = peakWS->mutableSample().getOrientedLattice().getUB();
176 auto o_lattice = std::make_unique<OrientedLattice>();
177 o_lattice->setUB(UBnew);
179 o_lattice->setModUB(modUB);
182 o_lattice->setModHKL(modHKL);
184 o_lattice->set(refinedCell.
a(), refinedCell.
b(), refinedCell.
c(), refinedCell.
alpha(), refinedCell.
beta(),
185 refinedCell.
gamma());
190 g_log.
notice() << i_run->getName() <<
" " << *o_lattice <<
"\n";
192 i_run->mutableSample().setOrientedLattice(std::move(o_lattice));
199 alg->setPropertyValue(
"PeaksWorkspace", i_run->getName());
200 alg->setProperty(
"Tolerance",
tolerance);
201 alg->executeAsChildAlg();
203 AnalysisDataService::Instance().remove(
"_peaks");
205 std::string outputdir =
getProperty(
"OutputDirectory");
206 if (outputdir.back() !=
'/')
210 savePks_alg->setPropertyValue(
"InputWorkspace", i_run->getName());
211 savePks_alg->setProperty(
"Filename", outputdir +
"ls" + i_run->getName() +
".integrate");
212 savePks_alg->executeAsChildAlg();
213 g_log.
notice() <<
"See output file: " << outputdir +
"ls" + i_run->getName() +
".integrate" <<
"\n";
216 saveUB_alg->setPropertyValue(
"InputWorkspace", i_run->getName());
217 saveUB_alg->setProperty(
"Filename", outputdir +
"ls" + i_run->getName() +
".mat");
218 saveUB_alg->executeAsChildAlg();
220 g_log.
notice() <<
"See output file: " << outputdir +
"ls" + i_run->getName() +
".mat" <<
"\n";
232 std::ostringstream fun_str;
233 fun_str <<
"name=LatticeFunction,LatticeSystem=" << cellType;
235 API::IFunction_sptr rawFunction = API::FunctionFactory::Instance().createInitialized(fun_str.str());
237 if (latticeFunction) {
238 latticeFunction->setUnitCell(cell);
241 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 void setHKL(double H, double K, double L)=0
virtual Mantid::Kernel::V3D getIntHKL() const =0
virtual int getRunNumber() const =0
virtual Mantid::Kernel::V3D getIntMNP() 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.