BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ISimulation2D.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Core/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 USER_API
16 #ifndef BORNAGAIN_CORE_SIMULATION_ISIMULATION2D_H
17 #define BORNAGAIN_CORE_SIMULATION_ISIMULATION2D_H
18 
20 
21 class DetectorContext;
22 
23 //! Abstract base class of OffSpecularSimulation and GISASSimulation.
24 //! Holds the common implementations for simulations with a 2D detector
25 //! @ingroup simulation
26 
27 class ISimulation2D : public ISimulation {
28 public:
29  ISimulation2D(const Beam& beam, const MultiLayer& sample, const IDetector& detector);
30 #ifndef SWIG
31  ISimulation2D(const Beam& beam, const IDetector& detector);
32 #endif // SWIG
34  ~ISimulation2D() override;
35 
36  ISimulation2D* clone() const override = 0;
37 
39  const IDetector2D& detector2D() const;
40 
41  //! Put into a clean state for running a simulation
42  void prepareSimulation() override;
43 
44  //! Sets spherical detector parameters using angle ranges
45  //! @param n_phi number of phi-axis bins
46  //! @param phi_min low edge of first phi-bin
47  //! @param phi_max upper edge of last phi-bin
48  //! @param n_alpha number of alpha-axis bins
49  //! @param alpha_min low edge of first alpha-bin
50  //! @param alpha_max upper edge of last alpha-bin
51  void setDetectorParameters(size_t n_phi, double phi_min, double phi_max, size_t n_alpha,
52  double alpha_min, double alpha_max);
53 
54  //! Sets the detector (axes can be overwritten later)
55  void setDetector(const IDetector2D& detector);
56 
57  //! Adds mask of given shape to the stack of detector masks. The mask value 'true' means
58  //! that the channel will be excluded from the simulation. The mask which is added last
59  //! has priority.
60  //! @param shape The shape of mask (Rectangle, Polygon, Line, Ellipse)
61  //! @param mask_value The value of mask
62  void addMask(const IShape2D& shape, bool mask_value = true);
63 
64  //! Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
65  void maskAll();
66 
67  //! Sets rectangular region of interest with lower left and upper right corners defined.
68  void setRegionOfInterest(double xlow, double ylow, double xup, double yup);
69 
70 protected:
71  ISimulation2D(const ISimulation2D& other);
72 
73  virtual void initUnitConverter() {}
74 
75  //! Gets the number of elements this simulation needs to calculate
76  size_t numberOfSimulationElements() const override;
77 
78  //! Generate a single threaded computation for a given range of simulation elements
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> generateSingleThreadedComputation(size_t start,
82  size_t n_elements) override;
83 
84  //! Generate simulation elements for given beam
85  std::vector<SimulationElement> generateSimulationElements(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::vector<SimulationElement> m_sim_elements;
99  std::vector<double> m_cache;
100 
101 private:
102  std::vector<double> rawResults() const override;
103  void setRawResults(const std::vector<double>& raw_data) override;
104  std::unique_ptr<DetectorContext> m_detector_context;
105 };
106 
107 #endif // BORNAGAIN_CORE_SIMULATION_ISIMULATION2D_H
108 #endif // USER_API
Defines interface ISimulation.
An incident neutron or x-ray beam.
Definition: Beam.h:27
Holds precalculated information for faster SimulationElement generation.
Abstract 2D detector interface.
Definition: IDetector2D.h:31
Abstract detector interface.
Definition: IDetector.h:36
Basic class for all shapes in 2D.
Definition: IShape2D.h:27
Abstract base class of OffSpecularSimulation and GISASSimulation.
Definition: ISimulation2D.h:27
std::unique_ptr< DetectorContext > m_detector_context
void setDetector(const IDetector2D &detector)
Sets the detector (axes can be overwritten later)
std::unique_ptr< IComputation > generateSingleThreadedComputation(size_t start, size_t n_elements) override
Generate a single threaded computation for a given range of simulation elements.
size_t numberOfSimulationElements() const override
Gets the number of elements this simulation needs to calculate.
void setRawResults(const std::vector< double > &raw_data) override
ISimulation2D * clone() const override=0
void moveDataFromCache() override
void setDetectorParameters(size_t n_phi, double phi_min, double phi_max, size_t n_alpha, double alpha_min, double alpha_max)
Sets spherical detector parameters using angle ranges.
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::vector< SimulationElement > generateSimulationElements(const Beam &beam)
Generate simulation elements for given beam.
std::vector< double > rawResults() const override
void setRegionOfInterest(double xlow, double ylow, double xup, double yup)
Sets rectangular region of interest with lower left and upper right corners defined.
IDetector2D & detector2D()
std::vector< SimulationElement > m_sim_elements
Definition: ISimulation2D.h:98
~ISimulation2D() override
virtual void initUnitConverter()
Definition: ISimulation2D.h:73
void maskAll()
Put the mask for all detector channels (i.e. exclude whole detector from the analysis)
void prepareSimulation() override
Put into a clean state for running a simulation.
std::vector< double > m_cache
Definition: ISimulation2D.h:99
void addBackgroundIntensity(size_t start_ind, size_t n_elements) override
void addDataToCache(double weight) override
void addMask(const IShape2D &shape, bool mask_value=true)
Adds mask of given shape to the stack of detector masks.
Abstract base class of OffSpecularSimulation, GISASSimulation and SpecularSimulation.
Definition: ISimulation.h:38
const MultiLayer * sample() const
IDetector & detector()
Definition: ISimulation.h:63
Beam & beam()
Definition: ISimulation.h:58
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:41