BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ISimulation2D.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Simulation/ISimulation2D.h
6 //! @brief Defines interface ISimulation2D.
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 
15 #ifndef BORNAGAIN_SIM_SIMULATION_ISIMULATION2D_H
16 #define BORNAGAIN_SIM_SIMULATION_ISIMULATION2D_H
17 
19 #include <memory>
20 
21 class Beam;
22 class IDetector;
23 class DetectorContext;
24 class DiffuseElement;
25 class IDetector;
26 class IShape2D;
27 
28 //! Abstract base class of simulations that generate 2D patterns.
29 //!
30 //! Base class of OffspecSimulation and ScatteringSimulation.
31 //!
32 //! Holds the common implementations for simulations with a 2D detector.
33 
34 class ISimulation2D : public ISimulation {
35 public:
36  ISimulation2D(const Beam& beam, const MultiLayer& sample, const IDetector& detector);
38  ~ISimulation2D() override;
39 
40  std::vector<const INode*> nodeChildren() const override;
41 
42  //! Adds mask of given shape to the stack of detector masks. The mask value 'true' means
43  //! that the channel will be excluded from the simulation. The mask which is added last
44  //! has priority.
45  //! @param shape The shape of mask (Rectangle, Polygon, Line, Ellipse)
46  //! @param mask_value The value of mask
47  void addMask(const IShape2D& shape, bool mask_value = true);
48 
49  //! Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
50  void maskAll();
51 
52  //! Sets rectangular region of interest with lower left and upper right corners defined.
53  void setRegionOfInterest(double xlow, double ylow, double xup, double yup);
54 
55  bool force_polarized() const override;
56 
57  Beam& beam() { return *m_beam; }
58  IDetector& detector() { return *m_detector; }
59 
60 #ifndef SWIG
61 
62  const Beam& beam() const { return *m_beam; }
63  const IDetector& detector() const { return *m_detector; }
64  const IDetector* getDetector() const { return m_detector.get(); }
65 
66 protected:
67  //! Put into a clean state for running a simulation
68  void prepareSimulation() override;
69 
70  virtual void initCoordSystem() {}
71 
72  void initDistributionHandler() override;
73 
74  //! Gets the number of elements this simulation needs to calculate
75  size_t numberOfElements() const override;
76 
77  //! Generate a single threaded computation for a given range of simulation elements
78  //! @param re_sample Preprocessed version of our sample
79  //! @param start Index of the first element to include into computation
80  //! @param n_elements Number of elements to process
81  std::unique_ptr<IComputation> createComputation(const reSample& re_sample, size_t start,
82  size_t n_elements) override;
83 
84  //! Generate simulation elements for given beam
85  std::vector<std::unique_ptr<DiffuseElement>> generateElements(const Beam& beam);
86 
87  //! Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.
88  //! @param start_ind Index of the first element to operate on
89  //! @param n_elements Number of elements to process
90  void normalize(size_t start_ind, size_t n_elements) override;
91 
92  void addBackgroundIntensity(size_t start_ind, size_t n_elements) override;
93 
94  void addDataToCache(double weight) override;
95 
96  void moveDataFromCache() override;
97 
98  std::unique_ptr<Beam> m_beam;
99  std::unique_ptr<IDetector> m_detector;
100  std::vector<std::unique_ptr<DiffuseElement>> m_eles;
101  std::vector<double> m_cache;
102 
103 private:
104  std::unique_ptr<DetectorContext> m_detector_context;
105 #endif // SWIG
106 };
107 
108 #endif // BORNAGAIN_SIM_SIMULATION_ISIMULATION2D_H
Defines interface ISimulation.
An incident neutron or x-ray beam.
Definition: Beam.h:28
Holds precalculated information for faster DiffuseElement generation.
Data stucture containing both input and output of a single detector cell.
Abstract detector interface.
Definition: IDetector.h:57
Basic class for all shapes in 2D.
Definition: IShape2D.h:26
Abstract base class of simulations that generate 2D patterns.
Definition: ISimulation2D.h:34
std::unique_ptr< DetectorContext > m_detector_context
void moveDataFromCache() override
IDetector & detector()
Definition: ISimulation2D.h:58
void normalize(size_t start_ind, size_t n_elements) override
Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.
std::unique_ptr< IComputation > createComputation(const reSample &re_sample, size_t start, size_t n_elements) override
Generate a single threaded computation for a given range of simulation elements.
void setRegionOfInterest(double xlow, double ylow, double xup, double yup)
Sets rectangular region of interest with lower left and upper right corners defined.
std::vector< const INode * > nodeChildren() const override
Returns all children.
bool force_polarized() const override
Force polarized computation even in absence of sample magnetization or external fields.
virtual void initCoordSystem()
Definition: ISimulation2D.h:70
std::vector< std::unique_ptr< DiffuseElement > > generateElements(const Beam &beam)
Generate simulation elements for given beam.
~ISimulation2D() override
std::unique_ptr< IDetector > m_detector
Definition: ISimulation2D.h:99
Beam & beam()
Definition: ISimulation2D.h:57
void maskAll()
Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
const Beam & beam() const
Definition: ISimulation2D.h:62
void prepareSimulation() override
Put into a clean state for running a simulation.
std::unique_ptr< Beam > m_beam
Definition: ISimulation2D.h:98
std::vector< double > m_cache
size_t numberOfElements() const override
Gets the number of elements this simulation needs to calculate.
std::vector< std::unique_ptr< DiffuseElement > > m_eles
void addBackgroundIntensity(size_t start_ind, size_t n_elements) override
void addDataToCache(double weight) override
const IDetector * getDetector() const
Definition: ISimulation2D.h:64
void addMask(const IShape2D &shape, bool mask_value=true)
Adds mask of given shape to the stack of detector masks. The mask value 'true' means that the channel...
ISimulation2D(const Beam &beam, const MultiLayer &sample, const IDetector &detector)
const IDetector & detector() const
Definition: ISimulation2D.h:63
void initDistributionHandler() override
init callbacks for setting the parameter values
Abstract base class, holds the infrastructure to run a simulation.
Definition: ISimulation.h:42
const MultiLayer * sample() const
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:43
Data structure that contains all the necessary data for scattering calculations.
Definition: ReSample.h:41