Mantid
Loading...
Searching...
No Matches
BeamProfileFactory.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2022 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation BeamProfileFactory,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
14#include "MantidKernel/V3D.h"
15
16namespace Mantid::Algorithms {
17std::unique_ptr<IBeamProfile> BeamProfileFactory::createBeamProfile(const Geometry::Instrument &instrument,
18 const API::Sample &sample) {
19 const auto frame = instrument.getReferenceFrame();
20 const auto source = instrument.getSource();
21
22 const std::string beamShapeParam = source->getParameterAsString("beam-shape");
23 if (beamShapeParam == "Slit") {
24 const auto beamWidthParam = source->getNumberParameter("beam-width");
25 const auto beamHeightParam = source->getNumberParameter("beam-height");
26 if (beamWidthParam.size() == 1 && beamHeightParam.size() == 1) {
27 return std::make_unique<RectangularBeamProfile>(*frame, source->getPos(), beamWidthParam[0], beamHeightParam[0]);
28 }
29 } else if (beamShapeParam == "Circle") {
30 const auto beamRadiusParam = source->getNumberParameter("beam-radius");
31 if (beamRadiusParam.size() == 1) {
32 return std::make_unique<CircularBeamProfile>(*frame, source->getPos(), beamRadiusParam[0]);
33 }
34 }
35 // revert to rectangular profile enclosing sample dimensions if no return by this point
36 if (!sample.getShape().hasValidShape() && !sample.hasEnvironment()) {
37 throw std::invalid_argument("Cannot determine beam profile without a sample shape and environment");
38 }
39 Kernel::V3D bbox;
40 Kernel::V3D bboxCentre;
41 if (sample.getShape().hasValidShape()) {
42 bbox = sample.getShape().getBoundingBox().width();
43 bboxCentre = sample.getShape().getBoundingBox().centrePoint();
44 } else {
45 bbox = sample.getEnvironment().boundingBox().width();
46 bboxCentre = sample.getEnvironment().boundingBox().centrePoint();
47 }
48 // beam profile always centred on zero so set half width = centre + sample half width
49 const double beamWidth = 2 * bboxCentre[frame->pointingHorizontal()] + bbox[frame->pointingHorizontal()];
50 const double beamHeight = 2 * bboxCentre[frame->pointingUp()] + bbox[frame->pointingUp()];
51 return std::make_unique<RectangularBeamProfile>(*frame, source->getPos(), beamWidth, beamHeight);
52}
53} // namespace Mantid::Algorithms
This class stores information about the sample used in particular run.
Definition: Sample.h:33
bool hasEnvironment() const
Definition: Sample.cpp:129
const Geometry::IObject & getShape() const
Return the sample shape.
Definition: Sample.cpp:102
const Geometry::SampleEnvironment & getEnvironment() const
Get a reference to the sample's environment.
Definition: Sample.cpp:136
static std::unique_ptr< IBeamProfile > createBeamProfile(const Geometry::Instrument &instrument, const API::Sample &sample)
Kernel::V3D width() const
Returns the width of the box.
Definition: BoundingBox.h:98
Kernel::V3D centrePoint() const
Returns the centre of the bounding box.
Definition: BoundingBox.h:94
virtual const BoundingBox & getBoundingBox() const =0
Return cached value of axis-aligned bounding box.
virtual bool hasValidShape() const =0
Base Instrument Class.
Definition: Instrument.h:47
IComponent_const_sptr getSource() const
Gets a pointer to the source.
Definition: Instrument.cpp:322
std::shared_ptr< const ReferenceFrame > getReferenceFrame() const
Get refernce Frame.
Geometry::BoundingBox boundingBox() const
Class for 3D vectors.
Definition: V3D.h:34