Mantid
Loading...
Searching...
No Matches
PeakHKLErrors.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7/*
8 * PeakHKLErrors.cpp
9 *
10 * Created on: Jan 26, 2013
11 * Author: ruth
12 */
19#include "MantidAPI/Sample.h"
22#include <boost/math/special_functions/round.hpp>
23
24using namespace Mantid::DataObjects;
25using namespace Mantid::API;
26using namespace Mantid::Kernel;
27using namespace Mantid::Kernel::Units;
32
33namespace Mantid::Crystal {
34namespace {
36Kernel::Logger g_log("PeakHKLErrors");
37} // namespace
38
39DECLARE_FUNCTION(PeakHKLErrors)
40
41PeakHKLErrors::PeakHKLErrors() : ParamFunction(), IFunction1D(), OptRuns(""), PeakWorkspaceName("") { initMode = 0; }
42
44 declareParameter("SampleXOffset", 0.0, "Sample x offset");
45 declareParameter("SampleYOffset", 0.0, "Sample y offset");
46 declareParameter("SampleZOffset", 0.0, "Sample z offset");
47 declareParameter("GonRotx", 0.0, "3rd Rotation of Goniometer about the x axis");
48 declareParameter("GonRoty", 0.0, "2nd Rotation of Goniometer about the y axis");
49 declareParameter("GonRotz", 0.0, "1st Rotation of Goniometer about the z axis");
50 initMode = 1;
51 if (OptRuns.empty())
52 return;
53
54 initMode = 2;
56}
62
63 std::vector<std::string> OptRunNums;
64 std::string OptRunstemp(OptRuns);
65 if (!OptRuns.empty() && OptRuns.at(0) == '/')
66 OptRunstemp = OptRunstemp.substr(1, OptRunstemp.size() - 1);
67
68 if (!OptRunstemp.empty() && OptRunstemp.at(OptRunstemp.size() - 1) == '/')
69 OptRunstemp = OptRunstemp.substr(0, OptRunstemp.size() - 1);
70
71 boost::split(OptRunNums, OptRunstemp, boost::is_any_of("/"));
72
73 for (auto &OptRunNum : OptRunNums) {
74 declareParameter("phi" + OptRunNum, 0.0, "Phi sample orientation value");
75 declareParameter("chi" + OptRunNum, 0.0, "Chi sample orientation value");
76 declareParameter("omega" + OptRunNum, 0.0, "Omega sample orientation value");
77 }
78}
79
108void PeakHKLErrors::cLone(std::shared_ptr<Geometry::ParameterMap> &pmap,
109 const std::shared_ptr<const Geometry::IComponent> &component,
110 std::shared_ptr<const Geometry::ParameterMap> &pmapSv) {
111 if (!component)
112 return;
113 if (component->isParametrized()) {
114
115 auto nms = pmapSv->names(component.get());
116 for (const auto &nm : nms) {
117
118 if (pmapSv->contains(component.get(), nm, "double")) {
119 std::vector<double> dparams = pmapSv->getDouble(component->getName(), nm);
120 pmap->addDouble(component.get(), nm, dparams[0]);
121 continue;
122 }
123
124 if (pmapSv->contains(component.get(), nm, "V3D")) {
125 std::vector<V3D> V3Dparams = pmapSv->getV3D(component->getName(), nm);
126 pmap->addV3D(component.get(), nm, V3Dparams[0]);
127 continue;
128 }
129
130 if (pmapSv->contains(component.get(), nm, "int")) {
131 std::vector<int> iparams = pmapSv->getType<int>(component->getName(), nm);
132 pmap->addInt(component.get(), nm, iparams[0]);
133 continue;
134 }
135
136 if (pmapSv->contains(component.get(), nm, "string")) {
137 std::vector<std::string> sparams = pmapSv->getString(component->getName(), nm);
138 pmap->addString(component.get(), nm, sparams[0]);
139 continue;
140 }
141
142 if (pmapSv->contains(component.get(), nm, "Quat")) {
143 std::vector<Kernel::Quat> sparams = pmapSv->getType<Kernel::Quat>(component->getName(), nm);
144 pmap->addQuat(component.get(), nm, sparams[0]);
145 continue;
146 }
147 }
148
149 std::shared_ptr<const CompAssembly> parent = std::dynamic_pointer_cast<const CompAssembly>(component);
150 if (parent && parent->nelements() < 180) //# need speed up. Assume pixel
151 // elements of a Panel have no
152 // attributes
153 for (int child = 0; child < parent->nelements(); child++) {
154 std::shared_ptr<const Geometry::IComponent> kid =
155 std::const_pointer_cast<const Geometry::IComponent>(parent->getChild(child));
156 if (kid)
157 cLone(pmap, kid, pmapSv);
158 }
159 }
160}
161
171std::shared_ptr<Geometry::Instrument> PeakHKLErrors::getNewInstrument(const PeaksWorkspace_sptr &peaksWs) const {
172 Geometry::Instrument_const_sptr instSave = peaksWs->getPeak(0).getInstrument();
173
174 if (!instSave) {
175 g_log.error(" Peaks workspace does not have an instrument");
176 throw std::invalid_argument(" Not all peaks have an instrument");
177 }
178
179 auto pmap = std::make_shared<Geometry::ParameterMap>();
180 if (!hasParameterMap) {
181 pmapSv = instSave->getParameterMap();
182 hasParameterMap = true;
183 if (!instSave->isParametrized()) {
184
185 std::shared_ptr<Geometry::Instrument> instClone(instSave->clone());
186 auto Pinsta = std::make_shared<Geometry::Instrument>(instSave, pmap);
187
188 instChange = Pinsta;
189 IComponent_const_sptr sample = instChange->getSample();
190 sampPos = sample->getRelativePos();
191 } else // catch(... )
192 {
193 auto P1 = std::make_shared<Geometry::Instrument>(instSave->baseInstrument(), instSave->makeLegacyParameterMap());
194 instChange = P1;
195 IComponent_const_sptr sample = instChange->getSample();
196 sampPos = sample->getRelativePos();
197 }
198 }
199
200 if (!instChange) {
201 g_log.error("Cannot 'clone' instrument");
202 throw std::logic_error("Cannot clone instrument");
203 }
204 //------------------"clone" orig instruments pmap -------------------
205
206 cLone(pmap, instSave, pmapSv);
207 V3D sampOffsets(getParameter("SampleXOffset"), getParameter("SampleYOffset"), getParameter("SampleZOffset"));
208
209 IComponent_const_sptr sample = instChange->getSample();
210 pmap->addPositionCoordinate(sample.get(), std::string("x"), sampPos.X() + sampOffsets.X());
211 pmap->addPositionCoordinate(sample.get(), std::string("y"), sampPos.Y() + sampOffsets.Y());
212 pmap->addPositionCoordinate(sample.get(), std::string("z"), sampPos.Z() + sampOffsets.Z());
213
214 return instChange;
215}
216
228void PeakHKLErrors::getRun2MatMap(PeaksWorkspace_sptr &Peaks, const std::string &OptRuns,
229 std::map<int, Mantid::Kernel::Matrix<double>> &Res) const {
230
231 for (int i = 0; i < Peaks->getNumberPeaks(); ++i) {
232 Geometry::IPeak &peak_old = Peaks->getPeak(i);
233
234 int runNum = peak_old.getRunNumber();
235 std::string runNumStr = std::to_string(runNum);
236 size_t N = OptRuns.find("/" + runNumStr + "/");
237 if (N < OptRuns.size()) {
238 double chi = getParameter("chi" + boost::lexical_cast<std::string>(runNumStr));
239 double phi = getParameter("phi" + boost::lexical_cast<std::string>(runNumStr));
240 double omega = getParameter("omega" + boost::lexical_cast<std::string>(runNumStr));
242 uniGonio.makeUniversalGoniometer();
243 uniGonio.setRotationAngle("phi", phi);
244 uniGonio.setRotationAngle("chi", chi);
245 uniGonio.setRotationAngle("omega", omega);
246 Res[runNum] = uniGonio.getR();
247 }
248 }
249}
250
262 int cint = toupper(axis);
263 auto c = static_cast<char>(cint);
264 std::string S(std::string("") + c);
265 size_t axisPos = std::string("XYZ").find(S);
266
267 if (axisPos > 2) {
268 Matrix<double> Res(3, 3, true);
269
270 return Res;
271 }
272 double rTheta = theta / 180 * M_PI;
273 Matrix<double> Res(3, 3);
274 Res.zeroMatrix();
275 Res[axisPos][axisPos] = 1.0;
276 Res[(axisPos + 1) % 3][(axisPos + 1) % 3] = cos(rTheta);
277 Res[(axisPos + 1) % 3][(axisPos + 2) % 3] = -sin(rTheta);
278 Res[(axisPos + 2) % 3][(axisPos + 2) % 3] = cos(rTheta);
279 Res[(axisPos + 2) % 3][(axisPos + 1) % 3] = sin(rTheta);
280 return Res;
281}
282
295 int cint = toupper(axis);
296 auto c = static_cast<char>(cint);
297 std::string S(std::string("") + c);
298 size_t axisPos = std::string("XYZ").find(S);
299
300 if (axisPos > 2) {
301 Matrix<double> Res(3, 3, true);
302
303 return Res;
304 }
305 double rTheta = theta / 180 * M_PI;
306 Matrix<double> Res(3, 3);
307 Res.zeroMatrix();
308 Res[axisPos][axisPos] = 0.0;
309 Res[(axisPos + 1) % 3][(axisPos + 1) % 3] = -sin(rTheta);
310 Res[(axisPos + 1) % 3][(axisPos + 2) % 3] = -cos(rTheta);
311 Res[(axisPos + 2) % 3][(axisPos + 2) % 3] = -sin(rTheta);
312 Res[(axisPos + 2) % 3][(axisPos + 1) % 3] = cos(rTheta);
313 return Res * (M_PI / 180.);
314}
315
328void PeakHKLErrors::function1D(double *out, const double *xValues, const size_t nData) const {
330
331 if (!peaksWs)
332 throw std::invalid_argument("Peaks not stored under the name " + PeakWorkspaceName);
333
334 std::shared_ptr<Geometry::Instrument> instNew = getNewInstrument(peaksWs);
335
336 std::map<int, Mantid::Kernel::Matrix<double>> RunNum2GonMatrixMap;
337 getRun2MatMap(peaksWs, OptRuns, RunNum2GonMatrixMap);
338 const DblMatrix &UBx = peaksWs->sample().getOrientedLattice().getUB();
339
340 DblMatrix UBinv(UBx);
341 UBinv.Invert();
342 UBinv /= (2 * M_PI);
343
344 double GonRotx = getParameter("GonRotx");
345 double GonRoty = getParameter("GonRoty");
346 double GonRotz = getParameter("GonRotz");
347 Matrix<double> GonRot = RotationMatrixAboutRegAxis(GonRotx, 'x') * RotationMatrixAboutRegAxis(GonRoty, 'y') *
348 RotationMatrixAboutRegAxis(GonRotz, 'z');
349
350 double ChiSqTot = 0.0;
351 for (size_t i = 0; i < nData; i += 3) {
352 int peakNum = boost::math::iround(xValues[i]);
353 Peak &peak_old = peaksWs->getPeak(peakNum);
354
355 int runNum = peak_old.getRunNumber();
356 std::string runNumStr = std::to_string(runNum);
357 Peak peak = createNewPeak(peak_old, instNew, 0, peak_old.getL1());
358
359 size_t N = OptRuns.find("/" + runNumStr + "/");
360 if (N < OptRuns.size()) {
361 peak.setGoniometerMatrix(GonRot * RunNum2GonMatrixMap[runNum]);
362
363 } else {
364 peak.setGoniometerMatrix(GonRot * peak.getGoniometerMatrix());
365 }
366 V3D sampOffsets(getParameter("SampleXOffset"), getParameter("SampleYOffset"), getParameter("SampleZOffset"));
367 peak.setSamplePos(peak.getSamplePos() + sampOffsets);
368
369 V3D hkl = UBinv * peak.getQSampleFrame();
370
371 for (int k = 0; k < 3; k++) {
372 double d1 = hkl[k] - floor(hkl[k]);
373 if (d1 > .5)
374 d1 = d1 - 1;
375 if (d1 < -.5)
376 d1 = d1 + 1;
377
378 out[i + k] = d1;
379 ChiSqTot += d1 * d1;
380 }
381 }
382
383 g_log.debug() << "------------------------Function---------------------------"
384 "--------------------\n";
385 for (size_t p = 0; p < nParams(); p++) {
386 g_log.debug() << parameterName(p) << "(" << getParameter(p) << "),";
387 }
388 g_log.debug() << '\n';
389 g_log.debug() << "Off constraints=";
390 for (size_t p = 0; p < nParams(); p++) {
391 IConstraint *constr = getConstraint(p);
392 if (constr)
393 if ((constr->check() > 0))
394 g_log.debug() << "(" << parameterName(p) << "=" << constr->check() << ");";
395 }
396 g_log.debug() << '\n';
397
398 g_log.debug() << " Chi**2 = " << ChiSqTot << " nData = " << nData << '\n';
399}
400
401void PeakHKLErrors::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) {
403
404 if (!peaksWs)
405 throw std::invalid_argument("Peaks not stored under the name " + PeakWorkspaceName);
406
407 std::shared_ptr<Geometry::Instrument> instNew = getNewInstrument(peaksWs);
408
409 const DblMatrix &UB = peaksWs->sample().getOrientedLattice().getUB();
410 DblMatrix UBinv(UB);
411 UBinv.Invert();
412 UBinv /= 2 * M_PI;
413
414 double GonRotx = getParameter("GonRotx");
415 double GonRoty = getParameter("GonRoty");
416 double GonRotz = getParameter("GonRotz");
417 Matrix<double> InvGonRotxMat = RotationMatrixAboutRegAxis(GonRotx, 'x');
418 Matrix<double> InvGonRotyMat = RotationMatrixAboutRegAxis(GonRoty, 'y');
419 Matrix<double> InvGonRotzMat = RotationMatrixAboutRegAxis(GonRotz, 'z');
420 Matrix<double> GonRot = InvGonRotxMat * InvGonRotyMat * InvGonRotzMat;
421
422 InvGonRotxMat.Invert();
423 InvGonRotyMat.Invert();
424 InvGonRotzMat.Invert();
425
426 std::map<int, Kernel::Matrix<double>> RunNums2GonMatrix;
427 getRun2MatMap(peaksWs, OptRuns, RunNums2GonMatrix);
428
429 g_log.debug() << "----------------------------Derivative------------------------\n";
430
431 V3D samplePosition = instNew->getSample()->getPos();
432 IPeak &ppeak = peaksWs->getPeak(0);
433 double L0 = ppeak.getL1();
434 double velocity = (L0 + ppeak.getL2()) / ppeak.getTOF();
435
436 double K = 2 * M_PI / ppeak.getWavelength() / velocity; // 2pi/lambda = K* velocity
437 V3D beamDir = instNew->getBeamDirection();
438
439 size_t paramNums[] = {parameterIndex(std::string("SampleXOffset")), parameterIndex(std::string("SampleYOffset")),
440 parameterIndex(std::string("SampleZOffset"))};
441
442 for (size_t i = 0; i < nData; i += 3) {
443 int peakNum = boost::math::iround(xValues[i]);
444 Peak &peak_old = peaksWs->getPeak(peakNum);
445 Peak peak = createNewPeak(peak_old, instNew, 0, peak_old.getL1());
446
447 int runNum = peak_old.getRunNumber();
448 std::string runNumStr = std::to_string(runNum);
449
450 for (int kk = 0; kk < static_cast<int>(nParams()); kk++) {
451 out->set(i, kk, 0.0);
452 out->set(i + 1, kk, 0.0);
453 out->set(i + 2, kk, 0.0);
454 }
455
456 double chi, phi, omega;
457 size_t chiParamNum, phiParamNum, omegaParamNum;
458
459 size_t N = OptRuns.find("/" + runNumStr);
460 if (N < OptRuns.size()) {
461 chi = getParameter("chi" + (runNumStr));
462 phi = getParameter("phi" + (runNumStr));
463 omega = getParameter("omega" + (runNumStr));
464
465 peak.setGoniometerMatrix(GonRot * RunNums2GonMatrix[runNum]);
466
467 chiParamNum = parameterIndex("chi" + (runNumStr));
468 phiParamNum = parameterIndex("phi" + (runNumStr));
469 omegaParamNum = parameterIndex("omega" + (runNumStr));
470 } else {
471
473 std::vector<double> phichiOmega = Gon.getEulerAngles("YZY");
474 chi = phichiOmega[1];
475 phi = phichiOmega[2];
476 omega = phichiOmega[0];
477 // peak.setGoniometerMatrix( GonRot*Gon.getR());
478 chiParamNum = phiParamNum = omegaParamNum = nParams() + 10;
479 peak.setGoniometerMatrix(GonRot * peak.getGoniometerMatrix());
480 }
481 V3D sampOffsets(getParameter("SampleXOffset"), getParameter("SampleYOffset"), getParameter("SampleZOffset"));
482 peak.setSamplePos(peak.getSamplePos() + sampOffsets);
483 // NOTE:Use getQLabFrame except for below.
484 // For parameters the getGoniometerMatrix should remove GonRot, for derivs
485 // wrt GonRot*, wrt chi*,phi*,etc.
486
487 // Deriv wrt chi phi and omega
488 if (phiParamNum < nParams()) {
489 Matrix<double> chiMatrix = RotationMatrixAboutRegAxis(chi, 'z');
490 Matrix<double> phiMatrix = RotationMatrixAboutRegAxis(phi, 'y');
491 Matrix<double> omegaMatrix = RotationMatrixAboutRegAxis(omega, 'y');
492
493 Matrix<double> dchiMatrix = DerivRotationMatrixAboutRegAxis(chi, 'z');
494 Matrix<double> dphiMatrix = DerivRotationMatrixAboutRegAxis(phi, 'y');
495 Matrix<double> domegaMatrix = DerivRotationMatrixAboutRegAxis(omega, 'y');
496
497 Matrix<double> InvG = omegaMatrix * chiMatrix * phiMatrix;
498 InvG.Invert();
499 // Calculate Derivatives wrt chi(phi,omega) in degrees
500 Matrix<double> R = omegaMatrix * chiMatrix * dphiMatrix;
501 Matrix<double> InvR = InvG * R * InvG * -1;
502 V3D lab = peak.getQLabFrame();
503 V3D Dhkl0 = UBinv * InvR * lab;
504
505 R = omegaMatrix * dchiMatrix * phiMatrix;
506 InvR = InvG * R * InvG * -1;
507 V3D Dhkl1 = UBinv * InvR * peak.getQLabFrame();
508
509 R = domegaMatrix * chiMatrix * phiMatrix;
510 InvR = InvG * R * InvG * -1;
511 V3D Dhkl2 = UBinv * InvR * peak.getQLabFrame(); // R.transpose should be R inverse
512
513 out->set(i, chiParamNum, Dhkl1[0]);
514 out->set(i + 1, chiParamNum, Dhkl1[1]);
515 out->set(i + 2, chiParamNum, Dhkl1[2]);
516 out->set(i, phiParamNum, Dhkl0[0]);
517 out->set(i + 1, phiParamNum, Dhkl0[1]);
518 out->set(i + 2, phiParamNum, Dhkl0[2]);
519 out->set(i, omegaParamNum, Dhkl2[0]);
520 out->set(i + 1, omegaParamNum, Dhkl2[1]);
521 out->set(i + 2, omegaParamNum, Dhkl2[2]);
522
523 } // if optimize for chi phi and omega on this peak
524
525 //------------------------Goniometer Rotation Derivatives
526 //-----------------------
527 Matrix<double> InvGonRot(GonRot);
528 InvGonRot.Invert();
529 Matrix<double> InvGon = InvGonRot * peak.getGoniometerMatrix();
530 InvGon.Invert();
531 V3D DGonx = (UBinv * InvGon * InvGonRotzMat * InvGonRotyMat *
532 DerivRotationMatrixAboutRegAxis(-GonRotx, 'x') * // - gives inverse of GonRot
533 peak.getQLabFrame()) *
534 -1;
535
536 V3D DGony = (UBinv * InvGon * InvGonRotzMat * DerivRotationMatrixAboutRegAxis(-GonRoty, 'y') * InvGonRotxMat *
537 peak.getQLabFrame()) *
538 -1;
539 V3D DGonz = (UBinv * InvGon * DerivRotationMatrixAboutRegAxis(-GonRotz, 'z') * InvGonRotyMat * InvGonRotxMat *
540 peak.getQLabFrame()) *
541 -1;
542
543 size_t paramnum = parameterIndex("GonRotx");
544 out->set(i, paramnum, DGonx[0]);
545 out->set(i + 1, paramnum, DGonx[1]);
546 out->set(i + 2, paramnum, DGonx[2]);
547 out->set(i, parameterIndex("GonRoty"), DGony[0]);
548 out->set(i + 1, parameterIndex("GonRoty"), DGony[1]);
549 out->set(i + 2, parameterIndex("GonRoty"), DGony[2]);
550 out->set(i, parameterIndex("GonRotz"), DGonz[0]);
551 out->set(i + 1, parameterIndex("GonRotz"), DGonz[1]);
552 out->set(i + 2, parameterIndex("GonRotz"), DGonz[2]);
553 //-------------------- Sample Orientation derivatives
554 //----------------------------------
555 // Qlab = -KV + k|V|*beamdir
556 // D = pos-sampPos
557 //|V|= vmag=(L0 + D )/tof
558 // t1= tof - L0/|V| {time from sample to pixel}
559 // V = D/t1
560 V3D D = peak.getDetPos() - samplePosition;
561 double vmag = (L0 + D.norm()) / peak.getTOF();
562 double t1 = peak.getTOF() - L0 / vmag;
563
564 // Derivs wrt sample x, y, z
565 // Ddsx =( - 1, 0, 0), d|D|^2/dsx -> 2|D|d|D|/dsx =d(tranp(D)* D)/dsx =2
566 // Ddsx* tranp(D)
567 //|D| also called Dmag
568 V3D Dmagdsxsysz(D);
569 Dmagdsxsysz *= (-1 / D.norm());
570
571 V3D vmagdsxsysz = Dmagdsxsysz / peak.getTOF();
572
573 V3D t1dsxsysz = vmagdsxsysz * (L0 / vmag / vmag);
575 Gon.Invert();
576
577 // x=0 is deriv wrt SampleXoffset, x=1 is deriv wrt SampleYoffset, etc.
578 for (int x = 0; x < 3; x++) {
579 V3D pp;
580 pp[x] = 1;
581 V3D dQlab1 = pp / -t1 - D * (t1dsxsysz[x] / t1 / t1);
582 V3D dQlab2 = beamDir * vmagdsxsysz[x];
583 V3D dQlab = dQlab2 - dQlab1;
584 dQlab *= K;
585
586 V3D dQSamp = Gon * dQlab;
587 V3D dhkl = UBinv * dQSamp;
588
589 out->set(i, paramNums[x], dhkl[0]);
590 out->set(i + 1, paramNums[x], dhkl[1]);
591 out->set(i + 2, paramNums[x], dhkl[2]);
592 }
593 }
594}
595
597 double T0, double L0) {
599 if (inst->getComponentID() != instrNew->getComponentID()) {
600 g_log.error("All peaks must have the same instrument");
601 throw std::invalid_argument("All peaks must have the same instrument");
602 }
603
604 double T = peak_old.getTOF() + T0;
605
606 int ID = peak_old.getDetectorID();
607
608 Kernel::V3D hkl = peak_old.getHKL();
609 // peak_old.setDetectorID(ID); //set det positions
610 Peak peak(instrNew, ID, peak_old.getWavelength(), hkl, peak_old.getGoniometerMatrix());
611
612 Wavelength wl;
613
614 wl.initialize(L0, 0,
615 {{UnitParams::l2, peak.getL2()},
616 {UnitParams::twoTheta, peak.getScattering()},
617 {UnitParams::efixed, peak_old.getInitialEnergy()}});
618
619 peak.setWavelength(wl.singleFromTOF(T));
620 peak.setIntensity(peak_old.getIntensity());
621 peak.setSigmaIntensity(peak_old.getSigmaIntensity());
622 peak.setRunNumber(peak_old.getRunNumber());
623 peak.setBinCount(peak_old.getBinCount());
624
626 return peak;
627}
628} // namespace Mantid::Crystal
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
An interface to a constraint.
Definition: IConstraint.h:26
virtual double check()=0
Returns a penalty number which is bigger than or equal to zero If zero it means that the constraint i...
This is a specialization of IFunction for functions of one real argument.
Definition: IFunction1D.h:43
static Kernel::Logger g_log
Logger instance.
Definition: IFunction1D.h:74
virtual IConstraint * getConstraint(size_t i) const
Get constraint of i-th parameter.
Definition: IFunction.cpp:392
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
Implements the part of IFunction interface dealing with parameters.
Definition: ParamFunction.h:33
size_t parameterIndex(const std::string &name) const override
Returns the index of parameter name.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
size_t nParams() const override
Total number of parameters.
Definition: ParamFunction.h:53
double getParameter(size_t i) const override
Get i-th parameter.
static DataObjects::Peak createNewPeak(const DataObjects::Peak &peak_old, const Geometry::Instrument_sptr &instrNew, double T0, double L0)
Creates a new peak, matching the old peak except for a different instrument.
std::shared_ptr< Geometry::Instrument > instChange
static Kernel::Matrix< double > DerivRotationMatrixAboutRegAxis(double theta, char axis)
Returns the derivative of the matrix corresponding to a rotation of theta(degrees) around axis with r...
void getRun2MatMap(DataObjects::PeaksWorkspace_sptr &Peaks, const std::string &OptRuns, std::map< int, Mantid::Kernel::Matrix< double > > &Res) const
Updates the map from run number to GoniometerMatrix.
static Kernel::Matrix< double > RotationMatrixAboutRegAxis(double theta, char axis)
Returns the matrix corresponding to a rotation of theta(degrees) around axis.
void function1D(double *out, const double *xValues, const size_t nData) const override
Calculates the h,k, and l offsets from an integer for (some of )the peaks, given the parameter values...
void functionDeriv1D(Mantid::API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to active parameters.
static void cLone(std::shared_ptr< Geometry::ParameterMap > &pmap, const std::shared_ptr< const Geometry::IComponent > &component, std::shared_ptr< const Geometry::ParameterMap > &pmapSv)
"Clones" a parameter map duplicating all Parameters with double,V3D,int and string parameter values t...
std::shared_ptr< const Geometry::ParameterMap > pmapSv
void init() override
Function initialization. Declare function parameters in this method.
std::shared_ptr< Geometry::Instrument > getNewInstrument(const DataObjects::PeaksWorkspace_sptr &peaksWs) const
Creates a new parameterized instrument for which the parameter values can be changed.
void setUpOptRuns()
Declares parameters for the chi,phi and omega angles for the run numbers where these will be optimize...
void setSigmaIntensity(double m_sigmaIntensity) override
Set the error on the integrated peak intensity.
Definition: BasePeak.cpp:206
void setRunNumber(int m_runNumber) override
Set the run number that measured this peak.
Definition: BasePeak.cpp:82
double getIntensity() const override
Return the integrated peak intensity.
Definition: BasePeak.cpp:185
Mantid::Kernel::V3D getSamplePos() const override
Return the sample position vector.
Definition: BasePeak.cpp:156
double getSigmaIntensity() const override
Return the error on the integrated peak intensity.
Definition: BasePeak.cpp:188
int getRunNumber() const override
Return the run number this peak was measured at.
Definition: BasePeak.cpp:78
void setIntensity(double m_intensity) override
Set the integrated peak intensity.
Definition: BasePeak.cpp:198
Mantid::Kernel::V3D getHKL() const override
Return the HKL vector.
Definition: BasePeak.cpp:103
double getBinCount() const override
Return the # of counts in the bin at its peak.
Definition: BasePeak.cpp:182
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
Definition: BasePeak.cpp:210
void setSamplePos(double samX, double samY, double samZ) override
Set sample position.
Definition: BasePeak.cpp:162
void setGoniometerMatrix(const Mantid::Kernel::Matrix< double > &goniometerMatrix) override
Set the goniometer rotation matrix at which this peak was measured.
Definition: BasePeak.cpp:220
void setBinCount(double m_binCount) override
Set the # of counts in the bin at its peak.
Definition: BasePeak.cpp:202
Structure describing a single-crystal peak.
Definition: Peak.h:34
Geometry::Instrument_const_sptr getInstrument() const
Return a shared ptr to the instrument for this peak.
Definition: Peak.cpp:326
void setWavelength(double wavelength) override
Set the incident wavelength of the neutron.
Definition: Peak.cpp:194
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
Definition: Peak.cpp:714
double getInitialEnergy() const override
Get the initial (incident) neutron energy in meV.
Definition: Peak.cpp:695
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition: Peak.cpp:441
double getWavelength() const override
Calculate the neutron wavelength (in angstroms) at the peak (Note for inelastic scattering - it is th...
Definition: Peak.cpp:364
double getTOF() const override
Calculate the time of flight (in microseconds) of the neutrons for this peak, using the geometry of t...
Definition: Peak.cpp:379
virtual Mantid::Kernel::V3D getDetPos() const
Return the detector position vector.
Definition: Peak.cpp:710
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition: Peak.cpp:472
double getL2() const override
Return the L2 flight path length (sample to detector), in meters.
Definition: Peak.cpp:718
int getDetectorID() const
Get the ID of the detector at the center of the peak
Definition: Peak.cpp:271
double getScattering() const override
Calculate the scattering angle of the peak
Definition: Peak.cpp:397
The class PeaksWorkspace stores information about a set of SCD peaks.
Class for Assembly of geometric components.
Definition: CompAssembly.h:31
Class to represent a particular goniometer setting, which is described by the rotation matrix.
Definition: Goniometer.h:55
void setRotationAngle(const std::string &name, double value)
Set rotation angle for an axis using motor name.
Definition: Goniometer.cpp:161
std::vector< double > getEulerAngles(const std::string &convention="YZX")
Return Euler angles acording to a convention.
Definition: Goniometer.cpp:282
void makeUniversalGoniometer()
Make a default universal goniometer with phi,chi,omega angles according to SNS convention.
Definition: Goniometer.cpp:271
const Kernel::DblMatrix & getR() const
Return global rotation matrix.
Definition: Goniometer.cpp:80
Structure describing a single-crystal peak.
Definition: IPeak.h:26
virtual double getTOF() const =0
virtual double getWavelength() const =0
virtual double getL2() const =0
virtual int getRunNumber() const =0
virtual double getL1() const =0
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
Numerical Matrix class.
Definition: Matrix.h:42
T Invert()
LU inversion routine.
Definition: Matrix.cpp:924
void zeroMatrix()
Set the matrix to zero.
Definition: Matrix.cpp:646
Class for quaternions.
Definition: Quat.h:39
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
void initialize(const double &_l1, const int &_emode, const UnitParametersMap &params)
Initialize the unit to perform conversion using singleToTof() and singleFromTof()
Definition: Unit.cpp:132
Wavelength in Angstrom.
Definition: Unit.h:302
double singleFromTOF(const double tof) const override
Convert a single tof value to this unit.
Definition: Unit.cpp:393
Class for 3D vectors.
Definition: V3D.h:34
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
double norm() const noexcept
Definition: V3D.h:263
constexpr double Z() const noexcept
Get z.
Definition: V3D.h:234
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
Definition: IComponent.h:161
std::shared_ptr< const IObjComponent > IObjComponent_const_sptr
Shared pointer to IObjComponent (const version)
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
The namespace for concrete units classes.
Definition: IQTransform.h:18
Generate a tableworkspace to store the calibration results.
std::string to_string(const wide_integer< Bits, Signed > &n)