20#include <boost/math/special_functions/round.hpp>
43 declareParameter(
"DeltaX", 0.0,
"relative shift along X in meter");
44 declareParameter(
"DeltaY", 0.0,
"relative shift along Y in meter");
45 declareParameter(
"DeltaZ", 0.0,
"relative shift along Z in meter");
47 declareParameter(
"RotX", 0.0,
"relative rotation around X in degree");
48 declareParameter(
"RotY", 0.0,
"relative rotation around Y in degree");
49 declareParameter(
"RotZ", 0.0,
"relative rotation around Z in degree");
52 declareParameter(
"DeltaT0", 0.1,
"delta of TOF");
54 declareParameter(
"DeltaSampleX", 0.0,
"relative shift of sample position along X.");
55 declareParameter(
"DeltaSampleY", 0.0,
"relative shift of sample position along Y.");
56 declareParameter(
"DeltaSampleZ", 0.0,
"relative shift of sample position along Z.");
58 declareParameter(
"ScaleX", 1.0,
"Scale of detector along X-direction (i.e., width).");
59 declareParameter(
"ScaleY", 1.0,
"Scale of detector along Y-direction (i.e., height).");
63 const std::vector<double> &tofs,
bool waveFromUB) {
69 if (inst->getName().compare(
"CORELLI") == 0 &&
m_cmpt !=
"moderator")
72 if (!
m_cmpt.ends_with(
"/sixteenpack"))
73 m_cmpt.append(
"/sixteenpack");
127 bool calibrateT0 = (
m_cmpt ==
"none/sixteenpack") || (
m_cmpt ==
"none");
144 for (
int i = 0; i < pws->getNumberPeaks(); ++i) {
170 const DblMatrix &ubm = pws->sample().getOrientedLattice().getUB();
172 qv_target *= 2 * M_PI;
173 const double dSpacing = 2 * M_PI / qv_target.
norm();
178 const double tof =
m_tofs[i];
182 {{UnitParams::l2, pk.getL2()},
183 {UnitParams::twoTheta, pk.getScattering()},
184 {UnitParams::efixed, pk.getInitialEnergy()}});
188 V3D qv = pk.getQSampleFrame();
189 for (
int j = 0; j < 3; ++j)
190 out[i * 3 + j] = qv[j];
227IPeaksWorkspace_sptr SCDCalibratePanels2ObjFunc::moveInstruentComponentBy(
double deltaX,
double deltaY,
double deltaZ,
228 const std::string &componentName,
233 auto mv_alg = Mantid::API::AlgorithmFactory::Instance().create(
"MoveInstrumentComponent", -1);
234 mv_alg->initialize();
235 mv_alg->setChild(
true);
236 mv_alg->setLogging(LOGCHILDALG);
237 mv_alg->setProperty(
"Workspace", pws);
238 mv_alg->setProperty(
"ComponentName", componentName);
239 mv_alg->setProperty(
"X", deltaX);
240 mv_alg->setProperty(
"Y", deltaY);
241 mv_alg->setProperty(
"Z", deltaZ);
242 mv_alg->setProperty(
"RelativePosition",
true);
243 mv_alg->executeAsChildAlg();
258IPeaksWorkspace_sptr SCDCalibratePanels2ObjFunc::rotateInstrumentComponentBy(
double rotX,
double rotY,
double rotZ,
259 const std::string &componentName,
262 auto rot_alg = Mantid::API::AlgorithmFactory::Instance().create(
"RotateInstrumentComponent", -1);
264 rot_alg->initialize();
265 rot_alg->setChild(
true);
266 rot_alg->setLogging(LOGCHILDALG);
267 rot_alg->setProperty(
"Workspace", pws);
268 rot_alg->setProperty(
"ComponentName", componentName);
269 rot_alg->setProperty(
"X", 1.0);
270 rot_alg->setProperty(
"Y", 0.0);
271 rot_alg->setProperty(
"Z", 0.0);
272 rot_alg->setProperty(
"Angle", rotX);
273 rot_alg->setProperty(
"RelativeRotation",
true);
274 rot_alg->executeAsChildAlg();
276 rot_alg->initialize();
277 rot_alg->setChild(
true);
278 rot_alg->setLogging(LOGCHILDALG);
279 rot_alg->setProperty(
"Workspace", pws);
280 rot_alg->setProperty(
"ComponentName", componentName);
281 rot_alg->setProperty(
"X", 0.0);
282 rot_alg->setProperty(
"Y", 1.0);
283 rot_alg->setProperty(
"Z", 0.0);
284 rot_alg->setProperty(
"Angle", rotY);
285 rot_alg->setProperty(
"RelativeRotation",
true);
286 rot_alg->executeAsChildAlg();
288 rot_alg->initialize();
289 rot_alg->setChild(
true);
290 rot_alg->setLogging(LOGCHILDALG);
291 rot_alg->setProperty(
"Workspace", pws);
292 rot_alg->setProperty(
"ComponentName", componentName);
293 rot_alg->setProperty(
"X", 0.0);
294 rot_alg->setProperty(
"Y", 0.0);
295 rot_alg->setProperty(
"Z", 1.0);
296 rot_alg->setProperty(
"Angle", rotZ);
297 rot_alg->setProperty(
"RelativeRotation",
true);
298 rot_alg->executeAsChildAlg();
304SCDCalibratePanels2ObjFunc::scaleRectagularDetectorSize(
const double &
scalex,
const double &
scaley,
305 const std::string &componentName,
310 std::shared_ptr<const Geometry::RectangularDetector> rectDet =
311 std::dynamic_pointer_cast<const Geometry::RectangularDetector>(comp);
315 auto oldscalex =
pmap.getDouble(rectDet->getName(),
"scalex");
316 auto oldscaley =
pmap.getDouble(rectDet->getName(),
"scaley");
318 if (!oldscalex.empty())
319 relscalex /= oldscalex[0];
320 if (!oldscaley.empty())
321 relscaley /= oldscaley[0];
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
double getParameter(size_t i) const override
Get i-th parameter.
SCDCalibratePanels2ObjFunc : TODO: DESCRIPTION.
Mantid::API::IPeaksWorkspace_sptr m_pws
const Mantid::Kernel::V3D UNSET_HKL
bool m_waveFromUB
if true, wavelength is computed from Bragg's law using the UB matrix and each peak's integer HKL inst...
Mantid::API::IPeaksWorkspace_sptr rotateInstrumentComponentBy(double rotX, double rotY, double rotZ, const std::string &componentName, Mantid::API::IPeaksWorkspace_sptr &pws) const
Rotate the instrument by angle axis.
std::vector< double > m_tofs
Mantid::API::IPeaksWorkspace_sptr scaleRectagularDetectorSize(const double &scalex, const double &scaley, const std::string &componentName, Mantid::API::IPeaksWorkspace_sptr &pws) const
std::string m_cmpt
temp workspace holder
void function1D(double *out, const double *xValues, const size_t order) const override
base objective function
void setPeakWorkspace(Mantid::API::IPeaksWorkspace_sptr &pws, const std::string &componentName, const std::vector< double > &tofs, bool waveFromUB=false)
Mantid::API::IPeaksWorkspace_sptr moveInstruentComponentBy(double deltaX, double deltaY, double deltaZ, const std::string &componentName, Mantid::API::IPeaksWorkspace_sptr &pws) const
helper functions
Mantid::Kernel::V3D getIntHKL() const override
Return the int HKL vector.
Structure describing a single-crystal peak.
void setWavelength(double wavelength) override
Set the incident wavelength of the neutron.
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
void setDetectorID(int id)
Set the detector ID of the pixel at the centre of the peak and look up and cache values related to it...
int getDetectorID() const override
Get the ID of the detector at the center of the peak
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
double getScattering() const override
Calculate the scattering angle of the peak
The Logger class is in charge of the publishing messages from the framework through various channels.
void initialize(const double &_l1, const int &_emode, const UnitParametersMap ¶ms)
Initialize the unit to perform conversion using singleToTof() and singleFromTof()
double norm() const noexcept
std::shared_ptr< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
MANTID_API_DLL void applyRectangularDetectorScaleToComponentInfo(Geometry::ComponentInfo &componentInfo, Geometry::IComponent *componentId, const double scaleX, const double scaleY)
Helpers for resizing RectangularDetectors.
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
Generate a tableworkspace to store the calibration results.
adjust instrument component position and orientation
: detector size scale at y-direction