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