BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Instrument.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Instrument/Instrument.cpp
6 //! @brief Implements class Instrument.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
19 
20 Instrument::Instrument(const Beam& beam, const IDetector& detector)
21  : m_beam(beam), m_detector(detector.clone())
22 {
23  setName("Instrument");
26  initDetector();
27 }
28 
30 
31 Instrument::Instrument(const Instrument& other) : INode(), m_beam(other.m_beam)
32 {
33  if (other.m_detector)
34  setDetector(*other.m_detector);
36  setName(other.getName());
37 }
38 
39 Instrument::~Instrument() = default;
40 
42 {
43  if (this != &other) {
44  m_beam = other.m_beam;
46  if (other.m_detector)
47  setDetector(*other.m_detector);
48  }
49  return *this;
50 }
51 
52 void Instrument::setDetector(const IDetector& detector)
53 {
54  m_detector.reset(detector.clone());
56  initDetector();
57 }
58 
60 {
61  if (!m_detector)
62  throw std::runtime_error(
63  "Instrument::initDetector() -> Error. Detector is not initialized.");
64  m_detector->init(beam());
65 }
66 
67 std::vector<const INode*> Instrument::getChildren() const
68 {
69  std::vector<const INode*> result;
70  result.push_back(&m_beam);
71  if (m_detector)
72  result.push_back(m_detector.get());
73  return result;
74 }
75 
76 void Instrument::setBeamParameters(double wavelength, double alpha_i, double phi_i)
77 {
78  m_beam.setWavelength(wavelength);
79  m_beam.setDirection({alpha_i, phi_i});
80  if (m_detector)
81  initDetector();
82 }
83 
84 void Instrument::setBeam(const Beam& beam)
85 {
86  m_beam = beam;
87  if (m_detector)
88  initDetector();
89 }
90 
92 {
93  return m_detector.get();
94 }
95 
97 {
98  return m_detector.get();
99 }
100 
102 {
104  return *m_detector;
105 }
106 
108 {
110  return *m_detector;
111 }
#define ASSERT(condition)
Definition: Assert.h:31
Defines class Histogram2D.
Defines interface class IResolutionFunction2D.
Defines class Instrument.
Defines class SphericalDetector.
An incident neutron or x-ray beam.
Definition: Beam.h:27
void setDirection(const Direction &direction)
Definition: Beam.cpp:86
void setWavelength(double wavelength)
Definition: Beam.cpp:78
Abstract detector interface.
Definition: IDetector.h:36
IDetector * clone() const override=0
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
void registerChild(INode *node)
Definition: INode.cpp:57
const std::string & getName() const
void setName(const std::string &name)
Assembles beam, detector and their relative positions with respect to the sample.
Definition: Instrument.h:32
IDetector * getDetector()
Definition: Instrument.cpp:96
virtual ~Instrument()
void setBeamParameters(double wavelength, double alpha_i, double phi_i)
Sets the beam wavelength and incoming angles.
Definition: Instrument.cpp:76
void setDetector(const IDetector &detector)
Sets the detector (axes can be overwritten later)
Definition: Instrument.cpp:52
IDetector & detector()
Definition: Instrument.cpp:107
void initDetector()
init detector with beam settings
Definition: Instrument.cpp:59
std::vector< const INode * > getChildren() const
Returns a vector of children.
Definition: Instrument.cpp:67
Beam & beam()
Definition: Instrument.h:43
void setBeam(const Beam &beam)
Definition: Instrument.cpp:84
Instrument & operator=(const Instrument &other)
Definition: Instrument.cpp:41
std::unique_ptr< IDetector > m_detector
Definition: Instrument.h:65
Beam m_beam
Definition: Instrument.h:64
A detector with coordinate axes along angles phi and alpha.