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
23#include <boost/algorithm/string/classification.hpp>
24#include <boost/algorithm/string/split.hpp>
25#include <boost/math/special_functions/round.hpp>
26
27using namespace Mantid::DataObjects;
28using namespace Mantid::API;
29using namespace Mantid::Kernel;
30using namespace Mantid::Kernel::Units;
35
36namespace Mantid::Crystal {
37namespace {
39Kernel::Logger g_log("PeakHKLErrors");
40} // namespace
41
42DECLARE_FUNCTION(PeakHKLErrors)
43
44PeakHKLErrors::PeakHKLErrors() : ParamFunction(), IFunction1D(), OptRuns(""), PeakWorkspaceName("") { initMode = 0; }
45
47 declareParameter("SampleXOffset", 0.0, "Sample x offset");
48 declareParameter("SampleYOffset", 0.0, "Sample y offset");
49 declareParameter("SampleZOffset", 0.0, "Sample z offset");
50 declareParameter("GonRotx", 0.0, "3rd Rotation of Goniometer about the x axis");
51 declareParameter("GonRoty", 0.0, "2nd Rotation of Goniometer about the y axis");
52 declareParameter("GonRotz", 0.0, "1st Rotation of Goniometer about the z axis");
53 initMode = 1;
54 if (OptRuns.empty())
55 return;
56
57 initMode = 2;
59}
65
66 std::vector<std::string> OptRunNums;
67 std::string OptRunstemp(OptRuns);
68 if (!OptRuns.empty() && OptRuns.at(0) == '/')
69 OptRunstemp = OptRunstemp.substr(1, OptRunstemp.size() - 1);
70
71 if (!OptRunstemp.empty() && OptRunstemp.at(OptRunstemp.size() - 1) == '/')
72 OptRunstemp.pop_back();
73
74 boost::split(OptRunNums, OptRunstemp, boost::is_any_of("/"));
75
76 for (const auto &OptRunNum : OptRunNums) {
77 declareParameter("phi" + OptRunNum, 0.0, "Phi sample orientation value");
78 declareParameter("chi" + OptRunNum, 0.0, "Chi sample orientation value");
79 declareParameter("omega" + OptRunNum, 0.0, "Omega sample orientation value");
80 }
81}
82
111void PeakHKLErrors::cLone(std::shared_ptr<Geometry::ParameterMap> &pmap,
112 const std::shared_ptr<const Geometry::IComponent> &component,
113 std::shared_ptr<const Geometry::ParameterMap> &pmapSv) {
114 if (!component)
115 return;
116 if (component->isParametrized()) {
117
118 auto nms = pmapSv->names(component.get());
119 for (const auto &nm : nms) {
120
121 if (pmapSv->contains(component.get(), nm, "double")) {
122 std::vector<double> dparams = pmapSv->getDouble(component->getName(), nm);
123 pmap->addDouble(component.get(), nm, dparams[0]);
124 continue;
125 }
126
127 if (pmapSv->contains(component.get(), nm, "V3D")) {
128 std::vector<V3D> V3Dparams = pmapSv->getV3D(component->getName(), nm);
129 pmap->addV3D(component.get(), nm, V3Dparams[0]);
130 continue;
131 }
132
133 if (pmapSv->contains(component.get(), nm, "int")) {
134 std::vector<int> iparams = pmapSv->getType<int>(component->getName(), nm);
135 pmap->addInt(component.get(), nm, iparams[0]);
136 continue;
137 }
138
139 if (pmapSv->contains(component.get(), nm, "string")) {
140 std::vector<std::string> sparams = pmapSv->getString(component->getName(), nm);
141 pmap->addString(component.get(), nm, sparams[0]);
142 continue;
143 }
144
145 if (pmapSv->contains(component.get(), nm, "Quat")) {
146 std::vector<Kernel::Quat> sparams = pmapSv->getType<Kernel::Quat>(component->getName(), nm);
147 pmap->addQuat(component.get(), nm, sparams[0]);
148 continue;
149 }
150 }
151
152 std::shared_ptr<const CompAssembly> parent = std::dynamic_pointer_cast<const CompAssembly>(component);
153 if (parent && parent->nelements() < 180) // # need speed up. Assume pixel
154 // elements of a Panel have no
155 // attributes
156 for (int child = 0; child < parent->nelements(); child++) {
157 std::shared_ptr<const Geometry::IComponent> kid =
158 std::const_pointer_cast<const Geometry::IComponent>(parent->getChild(child));
159 if (kid)
160 cLone(pmap, kid, pmapSv);
161 }
162 }
163}
164
174std::shared_ptr<Geometry::Instrument> PeakHKLErrors::getNewInstrument(const PeaksWorkspace_sptr &peaksWs) const {
175 Geometry::Instrument_const_sptr instSave = peaksWs->getPeak(0).getInstrument();
176
177 if (!instSave) {
178 g_log.error(" Peaks workspace does not have an instrument");
179 throw std::invalid_argument(" Not all peaks have an instrument");
180 }
181
182 auto pmap = std::make_shared<Geometry::ParameterMap>();
183 if (!hasParameterMap) {
184 pmapSv = instSave->getParameterMap();
185 hasParameterMap = true;
186 if (!instSave->isParametrized()) {
187
188 std::shared_ptr<Geometry::Instrument> instClone(instSave->clone());
189 auto Pinsta = std::make_shared<Geometry::Instrument>(instSave, pmap);
190
191 instChange = Pinsta;
192 IComponent_const_sptr sample = instChange->getSample();
193 sampPos = sample->getRelativePos();
194 } else // catch(... )
195 {
196 auto P1 = std::make_shared<Geometry::Instrument>(instSave->baseInstrument(), instSave->makeLegacyParameterMap());
197 instChange = P1;
198 IComponent_const_sptr sample = instChange->getSample();
199 sampPos = sample->getRelativePos();
200 }
201 }
202
203 if (!instChange) {
204 g_log.error("Cannot 'clone' instrument");
205 throw std::logic_error("Cannot clone instrument");
206 }
207 //------------------"clone" orig instruments pmap -------------------
208
209 cLone(pmap, instSave, pmapSv);
210 V3D sampOffsets(getParameter("SampleXOffset"), getParameter("SampleYOffset"), getParameter("SampleZOffset"));
211
212 IComponent_const_sptr sample = instChange->getSample();
213 pmap->addPositionCoordinate(sample.get(), std::string("x"), sampPos.X() + sampOffsets.X());
214 pmap->addPositionCoordinate(sample.get(), std::string("y"), sampPos.Y() + sampOffsets.Y());
215 pmap->addPositionCoordinate(sample.get(), std::string("z"), sampPos.Z() + sampOffsets.Z());
216
217 return instChange;
218}
219
231void PeakHKLErrors::getRun2MatMap(PeaksWorkspace_sptr &Peaks, const std::string &OptRuns,
232 std::map<int, Mantid::Kernel::Matrix<double>> &Res) const {
233
234 for (int i = 0; i < Peaks->getNumberPeaks(); ++i) {
235 const Geometry::IPeak &peak_old = Peaks->getPeak(i);
236
237 int runNum = peak_old.getRunNumber();
238 std::string runNumStr = std::to_string(runNum);
239 size_t N = OptRuns.find("/" + runNumStr + "/");
240 if (N < OptRuns.size()) {
241 double chi = getParameter("chi" + boost::lexical_cast<std::string>(runNumStr));
242 double phi = getParameter("phi" + boost::lexical_cast<std::string>(runNumStr));
243 double omega = getParameter("omega" + boost::lexical_cast<std::string>(runNumStr));
245 uniGonio.makeUniversalGoniometer();
246 uniGonio.setRotationAngle("phi", phi);
247 uniGonio.setRotationAngle("chi", chi);
248 uniGonio.setRotationAngle("omega", omega);
249 Res[runNum] = uniGonio.getR();
250 }
251 }
252}
253
265 int cint = toupper(axis);
266 auto c = static_cast<char>(cint);
267 std::string S(std::string("") + c);
268 size_t axisPos = std::string("XYZ").find(S);
269
270 if (axisPos > 2) {
271 Matrix<double> Res(3, 3, true);
272
273 return Res;
274 }
275 double rTheta = theta / 180 * M_PI;
276 Matrix<double> Res(3, 3);
277 Res.zeroMatrix();
278 Res[axisPos][axisPos] = 1.0;
279 Res[(axisPos + 1) % 3][(axisPos + 1) % 3] = cos(rTheta);
280 Res[(axisPos + 1) % 3][(axisPos + 2) % 3] = -sin(rTheta);
281 Res[(axisPos + 2) % 3][(axisPos + 2) % 3] = cos(rTheta);
282 Res[(axisPos + 2) % 3][(axisPos + 1) % 3] = sin(rTheta);
283 return Res;
284}
285
298 int cint = toupper(axis);
299 auto c = static_cast<char>(cint);
300 std::string S(std::string("") + c);
301 size_t axisPos = std::string("XYZ").find(S);
302
303 if (axisPos > 2) {
304 Matrix<double> Res(3, 3, true);
305
306 return Res;
307 }
308 double rTheta = theta / 180 * M_PI;
309 Matrix<double> Res(3, 3);
310 Res.zeroMatrix();
311 Res[axisPos][axisPos] = 0.0;
312 Res[(axisPos + 1) % 3][(axisPos + 1) % 3] = -sin(rTheta);
313 Res[(axisPos + 1) % 3][(axisPos + 2) % 3] = -cos(rTheta);
314 Res[(axisPos + 2) % 3][(axisPos + 2) % 3] = -sin(rTheta);
315 Res[(axisPos + 2) % 3][(axisPos + 1) % 3] = cos(rTheta);
316 return Res * (M_PI / 180.);
317}
318
331void PeakHKLErrors::function1D(double *out, const double *xValues, const size_t nData) const {
332 PeaksWorkspace_sptr peaksWs = AnalysisDataService::Instance().retrieveWS<PeaksWorkspace>(PeakWorkspaceName);
333
334 if (!peaksWs)
335 throw std::invalid_argument("Peaks not stored under the name " + PeakWorkspaceName);
336
337 std::shared_ptr<Geometry::Instrument> instNew = getNewInstrument(peaksWs);
338
339 std::map<int, Mantid::Kernel::Matrix<double>> RunNum2GonMatrixMap;
340 getRun2MatMap(peaksWs, OptRuns, RunNum2GonMatrixMap);
341 const DblMatrix &UBx = peaksWs->sample().getOrientedLattice().getUB();
342
343 DblMatrix UBinv(UBx);
344 UBinv.Invert();
345 UBinv /= (2 * M_PI);
346
347 double GonRotx = getParameter("GonRotx");
348 double GonRoty = getParameter("GonRoty");
349 double GonRotz = getParameter("GonRotz");
350 Matrix<double> GonRot = RotationMatrixAboutRegAxis(GonRotx, 'x') * RotationMatrixAboutRegAxis(GonRoty, 'y') *
351 RotationMatrixAboutRegAxis(GonRotz, 'z');
352
353 double ChiSqTot = 0.0;
354 for (size_t i = 0; i < nData; i += 3) {
355 int peakNum = boost::math::iround(xValues[i]);
356 const Peak &peak_old = peaksWs->getPeak(peakNum);
357
358 int runNum = peak_old.getRunNumber();
359 std::string runNumStr = std::to_string(runNum);
360 Peak peak = createNewPeak(peak_old, instNew, 0, peak_old.getL1());
361
362 size_t N = OptRuns.find("/" + runNumStr + "/");
363 if (N < OptRuns.size()) {
364 peak.setGoniometerMatrix(GonRot * RunNum2GonMatrixMap[runNum]);
365
366 } else {
367 peak.setGoniometerMatrix(GonRot * peak.getGoniometerMatrix());
368 }
369 V3D sampOffsets(getParameter("SampleXOffset"), getParameter("SampleYOffset"), getParameter("SampleZOffset"));
370 peak.setSamplePos(peak.getSamplePos() + sampOffsets);
371
372 V3D hkl = UBinv * peak.getQSampleFrame();
373
374 for (int k = 0; k < 3; k++) {
375 double d1 = hkl[k] - floor(hkl[k]);
376 if (d1 > .5)
377 d1 = d1 - 1;
378 if (d1 < -.5)
379 d1 = d1 + 1;
380
381 out[i + k] = d1;
382 ChiSqTot += d1 * d1;
383 }
384 }
385
386 g_log.debug() << "------------------------Function---------------------------"
387 "--------------------\n";
388 for (size_t p = 0; p < nParams(); p++) {
389 g_log.debug() << parameterName(p) << "(" << getParameter(p) << "),";
390 }
391 g_log.debug() << '\n';
392 g_log.debug() << "Off constraints=";
393 for (size_t p = 0; p < nParams(); p++) {
394 IConstraint *constr = getConstraint(p);
395 if (constr)
396 if ((constr->check() > 0))
397 g_log.debug() << "(" << parameterName(p) << "=" << constr->check() << ");";
398 }
399 g_log.debug() << '\n';
400
401 g_log.debug() << " Chi**2 = " << ChiSqTot << " nData = " << nData << '\n';
402}
403
404void PeakHKLErrors::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) {
405 PeaksWorkspace_sptr peaksWs = AnalysisDataService::Instance().retrieveWS<PeaksWorkspace>(PeakWorkspaceName);
406
407 if (!peaksWs)
408 throw std::invalid_argument("Peaks not stored under the name " + PeakWorkspaceName);
409
410 std::shared_ptr<Geometry::Instrument> instNew = getNewInstrument(peaksWs);
411
412 const DblMatrix &UB = peaksWs->sample().getOrientedLattice().getUB();
413 DblMatrix UBinv(UB);
414 UBinv.Invert();
415 UBinv /= 2 * M_PI;
416
417 double GonRotx = getParameter("GonRotx");
418 double GonRoty = getParameter("GonRoty");
419 double GonRotz = getParameter("GonRotz");
420 Matrix<double> InvGonRotxMat = RotationMatrixAboutRegAxis(GonRotx, 'x');
421 Matrix<double> InvGonRotyMat = RotationMatrixAboutRegAxis(GonRoty, 'y');
422 Matrix<double> InvGonRotzMat = RotationMatrixAboutRegAxis(GonRotz, 'z');
423 Matrix<double> GonRot = InvGonRotxMat * InvGonRotyMat * InvGonRotzMat;
424
425 InvGonRotxMat.Invert();
426 InvGonRotyMat.Invert();
427 InvGonRotzMat.Invert();
428
429 std::map<int, Kernel::Matrix<double>> RunNums2GonMatrix;
430 getRun2MatMap(peaksWs, OptRuns, RunNums2GonMatrix);
431
432 g_log.debug() << "----------------------------Derivative------------------------\n";
433
434 V3D samplePosition = instNew->getSample()->getPos();
435 const IPeak &ppeak = peaksWs->getPeak(0);
436 double L0 = ppeak.getL1();
437 double velocity = (L0 + ppeak.getL2()) / ppeak.getTOF();
438
439 double K = 2 * M_PI / ppeak.getWavelength() / velocity; // 2pi/lambda = K* velocity
440 V3D beamDir = instNew->getBeamDirection();
441
442 const size_t paramNums[] = {parameterIndex(std::string("SampleXOffset")),
443 parameterIndex(std::string("SampleYOffset")),
444 parameterIndex(std::string("SampleZOffset"))};
445
446 for (size_t i = 0; i < nData; i += 3) {
447 int peakNum = boost::math::iround(xValues[i]);
448 const Peak &peak_old = peaksWs->getPeak(peakNum);
449 Peak peak = createNewPeak(peak_old, instNew, 0, peak_old.getL1());
450
451 int runNum = peak_old.getRunNumber();
452 std::string runNumStr = std::to_string(runNum);
453
454 for (int kk = 0; kk < static_cast<int>(nParams()); kk++) {
455 out->set(i, kk, 0.0);
456 out->set(i + 1, kk, 0.0);
457 out->set(i + 2, kk, 0.0);
458 }
459
460 double chi, phi, omega;
461 size_t chiParamNum, phiParamNum, omegaParamNum;
462
463 size_t N = OptRuns.find("/" + runNumStr);
464 if (N < OptRuns.size()) {
465 chi = getParameter("chi" + (runNumStr));
466 phi = getParameter("phi" + (runNumStr));
467 omega = getParameter("omega" + (runNumStr));
468
469 peak.setGoniometerMatrix(GonRot * RunNums2GonMatrix[runNum]);
470
471 chiParamNum = parameterIndex("chi" + (runNumStr));
472 phiParamNum = parameterIndex("phi" + (runNumStr));
473 omegaParamNum = parameterIndex("omega" + (runNumStr));
474 } else {
475
477 std::vector<double> phichiOmega = Gon.getEulerAngles("YZY");
478 chi = phichiOmega[1];
479 phi = phichiOmega[2];
480 omega = phichiOmega[0];
481 // peak.setGoniometerMatrix( GonRot*Gon.getR());
482 chiParamNum = phiParamNum = omegaParamNum = nParams() + 10;
483 peak.setGoniometerMatrix(GonRot * peak.getGoniometerMatrix());
484 }
485 V3D sampOffsets(getParameter("SampleXOffset"), getParameter("SampleYOffset"), getParameter("SampleZOffset"));
486 peak.setSamplePos(peak.getSamplePos() + sampOffsets);
487 // NOTE:Use getQLabFrame except for below.
488 // For parameters the getGoniometerMatrix should remove GonRot, for derivs
489 // wrt GonRot*, wrt chi*,phi*,etc.
490
491 // Deriv wrt chi phi and omega
492 if (phiParamNum < nParams()) {
493 Matrix<double> chiMatrix = RotationMatrixAboutRegAxis(chi, 'z');
494 Matrix<double> phiMatrix = RotationMatrixAboutRegAxis(phi, 'y');
495 Matrix<double> omegaMatrix = RotationMatrixAboutRegAxis(omega, 'y');
496
497 Matrix<double> dchiMatrix = DerivRotationMatrixAboutRegAxis(chi, 'z');
498 Matrix<double> dphiMatrix = DerivRotationMatrixAboutRegAxis(phi, 'y');
499 Matrix<double> domegaMatrix = DerivRotationMatrixAboutRegAxis(omega, 'y');
500
501 Matrix<double> InvG = omegaMatrix * chiMatrix * phiMatrix;
502 InvG.Invert();
503 // Calculate Derivatives wrt chi(phi,omega) in degrees
504 Matrix<double> R = omegaMatrix * chiMatrix * dphiMatrix;
505 Matrix<double> InvR = InvG * R * InvG * -1;
506 V3D lab = peak.getQLabFrame();
507 V3D Dhkl0 = UBinv * InvR * lab;
508
509 R = omegaMatrix * dchiMatrix * phiMatrix;
510 InvR = InvG * R * InvG * -1;
511 V3D Dhkl1 = UBinv * InvR * peak.getQLabFrame();
512
513 R = domegaMatrix * chiMatrix * phiMatrix;
514 InvR = InvG * R * InvG * -1;
515 V3D Dhkl2 = UBinv * InvR * peak.getQLabFrame(); // R.transpose should be R inverse
516
517 out->set(i, chiParamNum, Dhkl1[0]);
518 out->set(i + 1, chiParamNum, Dhkl1[1]);
519 out->set(i + 2, chiParamNum, Dhkl1[2]);
520 out->set(i, phiParamNum, Dhkl0[0]);
521 out->set(i + 1, phiParamNum, Dhkl0[1]);
522 out->set(i + 2, phiParamNum, Dhkl0[2]);
523 out->set(i, omegaParamNum, Dhkl2[0]);
524 out->set(i + 1, omegaParamNum, Dhkl2[1]);
525 out->set(i + 2, omegaParamNum, Dhkl2[2]);
526
527 } // if optimize for chi phi and omega on this peak
528
529 //------------------------Goniometer Rotation Derivatives
530 //-----------------------
531 Matrix<double> InvGonRot(GonRot);
532 InvGonRot.Invert();
533 Matrix<double> InvGon = InvGonRot * peak.getGoniometerMatrix();
534 InvGon.Invert();
535 V3D DGonx = (UBinv * InvGon * InvGonRotzMat * InvGonRotyMat *
536 DerivRotationMatrixAboutRegAxis(-GonRotx, 'x') * // - gives inverse of GonRot
537 peak.getQLabFrame()) *
538 -1;
539
540 V3D DGony = (UBinv * InvGon * InvGonRotzMat * DerivRotationMatrixAboutRegAxis(-GonRoty, 'y') * InvGonRotxMat *
541 peak.getQLabFrame()) *
542 -1;
543 V3D DGonz = (UBinv * InvGon * DerivRotationMatrixAboutRegAxis(-GonRotz, 'z') * InvGonRotyMat * InvGonRotxMat *
544 peak.getQLabFrame()) *
545 -1;
546
547 size_t paramnum = parameterIndex("GonRotx");
548 out->set(i, paramnum, DGonx[0]);
549 out->set(i + 1, paramnum, DGonx[1]);
550 out->set(i + 2, paramnum, DGonx[2]);
551 out->set(i, parameterIndex("GonRoty"), DGony[0]);
552 out->set(i + 1, parameterIndex("GonRoty"), DGony[1]);
553 out->set(i + 2, parameterIndex("GonRoty"), DGony[2]);
554 out->set(i, parameterIndex("GonRotz"), DGonz[0]);
555 out->set(i + 1, parameterIndex("GonRotz"), DGonz[1]);
556 out->set(i + 2, parameterIndex("GonRotz"), DGonz[2]);
557 //-------------------- Sample Orientation derivatives
558 //----------------------------------
559 // Qlab = -KV + k|V|*beamdir
560 // D = pos-sampPos
561 //|V|= vmag=(L0 + D )/tof
562 // t1= tof - L0/|V| {time from sample to pixel}
563 // V = D/t1
564 V3D D = peak.getDetPos() - samplePosition;
565 double vmag = (L0 + D.norm()) / peak.getTOF();
566 double t1 = peak.getTOF() - L0 / vmag;
567
568 // Derivs wrt sample x, y, z
569 // Ddsx =( - 1, 0, 0), d|D|^2/dsx -> 2|D|d|D|/dsx =d(tranp(D)* D)/dsx =2
570 // Ddsx* tranp(D)
571 //|D| also called Dmag
572 V3D Dmagdsxsysz(D);
573 Dmagdsxsysz *= (-1 / D.norm());
574
575 V3D vmagdsxsysz = Dmagdsxsysz / peak.getTOF();
576
577 V3D t1dsxsysz = vmagdsxsysz * (L0 / vmag / vmag);
579 Gon.Invert();
580
581 // x=0 is deriv wrt SampleXoffset, x=1 is deriv wrt SampleYoffset, etc.
582 for (int x = 0; x < 3; x++) {
583 V3D pp;
584 pp[x] = 1;
585 V3D dQlab1 = pp / -t1 - D * (t1dsxsysz[x] / t1 / t1);
586 V3D dQlab2 = beamDir * vmagdsxsysz[x];
587 V3D dQlab = dQlab2 - dQlab1;
588 dQlab *= K;
589
590 V3D dQSamp = Gon * dQlab;
591 V3D dhkl = UBinv * dQSamp;
592
593 out->set(i, paramNums[x], dhkl[0]);
594 out->set(i + 1, paramNums[x], dhkl[1]);
595 out->set(i + 2, paramNums[x], dhkl[2]);
596 }
597 }
598}
599
601 double T0, double L0) {
603 if (inst->getComponentID() != instrNew->getComponentID()) {
604 g_log.error("All peaks must have the same instrument");
605 throw std::invalid_argument("All peaks must have the same instrument");
606 }
607
608 double T = peak_old.getTOF() + T0;
609
610 int ID = peak_old.getDetectorID();
611
612 Kernel::V3D hkl = peak_old.getHKL();
613 // peak_old.setDetectorID(ID); //set det positions
614 Peak peak(instrNew, ID, peak_old.getWavelength(), hkl, peak_old.getGoniometerMatrix());
615
616 Wavelength wl;
617
618 wl.initialize(L0, 0,
619 {{UnitParams::l2, peak.getL2()},
620 {UnitParams::twoTheta, peak.getScattering()},
621 {UnitParams::efixed, peak_old.getInitialEnergy()}});
622
623 peak.setWavelength(wl.singleFromTOF(T));
624 peak.setIntensity(peak_old.getIntensity());
625 peak.setSigmaIntensity(peak_old.getSigmaIntensity());
626 peak.setRunNumber(peak_old.getRunNumber());
627 peak.setBinCount(peak_old.getBinCount());
628
630 return peak;
631}
632} // 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.
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.
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.
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:205
void setRunNumber(int m_runNumber) override
Set the run number that measured this peak.
Definition BasePeak.cpp:81
double getIntensity() const override
Return the integrated peak intensity.
Definition BasePeak.cpp:184
Mantid::Kernel::V3D getSamplePos() const override
Return the sample position vector.
Definition BasePeak.cpp:155
double getSigmaIntensity() const override
Return the error on the integrated peak intensity.
Definition BasePeak.cpp:187
int getRunNumber() const override
Return the run number this peak was measured at.
Definition BasePeak.cpp:77
void setIntensity(double m_intensity) override
Set the integrated peak intensity.
Definition BasePeak.cpp:197
Mantid::Kernel::V3D getHKL() const override
Return the HKL vector.
Definition BasePeak.cpp:102
double getBinCount() const override
Return the # of counts in the bin at its peak.
Definition BasePeak.cpp:181
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:209
void setSamplePos(double samX, double samY, double samZ) override
Set sample position.
Definition BasePeak.cpp:161
void setGoniometerMatrix(const Mantid::Kernel::Matrix< double > &goniometerMatrix) override
Set the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:219
void setBinCount(double m_binCount) override
Set the # of counts in the bin at its peak.
Definition BasePeak.cpp:201
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:320
void setWavelength(double wavelength) override
Set the incident wavelength of the neutron.
Definition Peak.cpp:188
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
Definition Peak.cpp:724
double getInitialEnergy() const override
Get the initial (incident) neutron energy in meV.
Definition Peak.cpp:705
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition Peak.cpp:451
int getDetectorID() const override
Get the ID of the detector at the center of the peak
Definition Peak.cpp:265
double getWavelength() const override
Calculate the neutron wavelength (in angstroms) at the peak (Note for inelastic scattering - it is th...
Definition Peak.cpp:358
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:373
virtual Mantid::Kernel::V3D getDetPos() const
Return the detector position vector.
Definition Peak.cpp:720
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition Peak.cpp:482
double getL2() const override
Return the L2 flight path length (sample to detector), in meters.
Definition Peak.cpp:728
double getScattering() const override
Calculate the scattering angle of the peak
Definition Peak.cpp:391
The class PeaksWorkspace stores information about a set of SCD peaks.
Class for Assembly of geometric components.
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.
std::vector< double > getEulerAngles(const std::string &convention="YZX")
Return Euler angles acording to a convention.
void makeUniversalGoniometer()
Make a default universal goniometer with phi,chi,omega angles according to SNS convention.
const Kernel::DblMatrix & getR() const
Return global rotation matrix.
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:51
void debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
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
void initialize(const double &_l1, const int &_emode, const UnitParametersMap &params)
Initialize the unit to perform conversion using singleToTof() and singleFromTof()
Definition Unit.cpp:133
Wavelength in Angstrom.
Definition Unit.h:267
double singleFromTOF(const double tof) const override
Convert a single tof value to this unit.
Definition Unit.cpp:394
Class for 3D vectors.
Definition V3D.h:34
constexpr double X() const noexcept
Get x.
Definition V3D.h:238
constexpr double Y() const noexcept
Get y.
Definition V3D.h:239
double norm() const noexcept
Definition V3D.h:269
constexpr double Z() const noexcept
Get z.
Definition V3D.h:240
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:167
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)