BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IDetector.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Detector/IDetector.h
6 //! @brief Defines common detector interface.
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_DEVICE_DETECTOR_IDETECTOR_H
17 #define BORNAGAIN_DEVICE_DETECTOR_IDETECTOR_H
18 
23 
24 class Beam;
25 class DetectorMask;
26 class IAxis;
29 template <class T> class OutputData;
30 class SimulationElement;
31 class RegionOfInterest;
32 
33 //! Abstract detector interface.
34 //! @ingroup detector
35 
36 class IDetector : public ICloneable, public INode {
37 public:
39  IDetector();
40 
41  IDetector* clone() const override = 0;
42 
43  virtual ~IDetector();
44 
45  //! Inits detector with the beam settings
46  virtual void init(const Beam&) {}
47 
48  void addAxis(const IAxis& axis);
49 
50  //! Sets the polarization analyzer characteristics of the detector
51  void setAnalyzerProperties(const kvector_t direction, double efficiency,
52  double total_transmission);
53  //! Sets the detector resolution
54  void setDetectorResolution(const IDetectorResolution& p_detector_resolution);
55  void setResolutionFunction(const IResolutionFunction2D& resFunc);
56 
57  //! Resets region of interest making whole detector plane available for the simulation.
58  virtual void resetRegionOfInterest() = 0;
59  //! Returns detector masks container
60  virtual const DetectorMask* detectorMask() const = 0;
61 
62  std::vector<const INode*> getChildren() const override;
63 
64  void iterate(std::function<void(const_iterator)> func, bool visit_masks = false) const;
65 
66  const IAxis& axis(size_t index) const;
67  //! Returns actual dimensionality of the detector (number of defined axes)
68  size_t dimension() const;
69  //! Calculate axis index for given global index
70  size_t axisBinIndex(size_t index, size_t selected_axis) const;
71  //! Returns total number of pixels
72  size_t totalSize() const;
73  //! Applies the detector resolution to the given intensity maps
74  void applyDetectorResolution(OutputData<double>* p_intensity_map) const;
75  //! Returns a pointer to detector resolution object
77 #ifndef SWIG
78  //! Returns empty detector map in given axes units.
79  std::unique_ptr<OutputData<double>> createDetectorMap() const;
80 #endif // USER_API
81  //! Returns detection properties
82  const DetectionProperties& detectionProperties() const { return m_detection_properties; }
83 
84  //! Returns new intensity map with detector resolution applied. Map will be cropped to ROI
85  //! if ROI is present.
87  createDetectorIntensity(const std::vector<SimulationElement>& elements) const;
88 
89  //! Return default axes units
90  virtual Axes::Units defaultAxesUnits() const { return Axes::Units::DEFAULT; }
91 
92  //! Returns number of simulation elements.
93  size_t numberOfSimulationElements() const;
94 
95  //! Returns region of interest if exists.
96  virtual const RegionOfInterest* regionOfInterest() const = 0;
97 
98 protected:
99  IDetector(const IDetector& other);
100 
101  void clear();
102 
103  //! Returns the name for the axis with given index
104  virtual std::string axisName(size_t index) const = 0;
105 
106  //! Generates an axis with correct name and default binning for given index
107  virtual std::unique_ptr<IAxis> createAxis(size_t index, size_t n_bins, double min,
108  double max) const;
109 
110 private:
111  void setDataToDetectorMap(OutputData<double>& detectorMap,
112  const std::vector<SimulationElement>& elements) const;
113 
116  std::unique_ptr<IDetectorResolution> m_detector_resolution;
117 };
118 
119 #endif // BORNAGAIN_DEVICE_DETECTOR_IDETECTOR_H
120 #endif // USER_API
Defines and implements templated class CloneableVector.
Defines class DetectionProperties.
Defines interface IUnitConverter and possible axis units.
Defines class SimulationAreaIterator.
An incident neutron or x-ray beam.
Definition: Beam.h:27
Detector properties (efficiency, transmission).
Collection of detector masks.
Definition: DetectorMask.h:28
Interface for one-dimensional axes.
Definition: IAxis.h:25
Interface for polymorphic classes that should not be copied, except by explicit cloning.
Definition: ICloneable.h:25
Interface for detector resolution algorithms.
Abstract detector interface.
Definition: IDetector.h:36
void setDataToDetectorMap(OutputData< double > &detectorMap, const std::vector< SimulationElement > &elements) const
Definition: IDetector.cpp:175
void applyDetectorResolution(OutputData< double > *p_intensity_map) const
Applies the detector resolution to the given intensity maps.
Definition: IDetector.cpp:118
virtual std::string axisName(size_t index) const =0
Returns the name for the axis with given index.
virtual ~IDetector()
virtual const DetectorMask * detectorMask() const =0
Returns detector masks container.
void clear()
Definition: IDetector.cpp:51
size_t dimension() const
Returns actual dimensionality of the detector (number of defined axes)
Definition: IDetector.cpp:46
size_t axisBinIndex(size_t index, size_t selected_axis) const
Calculate axis index for given global index.
Definition: IDetector.cpp:63
virtual std::unique_ptr< IAxis > createAxis(size_t index, size_t n_bins, double min, double max) const
Generates an axis with correct name and default binning for given index.
Definition: IDetector.cpp:78
std::vector< const INode * > getChildren() const override
Returns a vector of children.
Definition: IDetector.cpp:192
size_t totalSize() const
Returns total number of pixels.
Definition: IDetector.cpp:88
size_t numberOfSimulationElements() const
Returns number of simulation elements.
Definition: IDetector.cpp:185
std::unique_ptr< IDetectorResolution > m_detector_resolution
Definition: IDetector.h:116
const IAxis & axis(size_t index) const
Definition: IDetector.cpp:56
void setResolutionFunction(const IResolutionFunction2D &resFunc)
Definition: IDetector.cpp:112
DetectionProperties m_detection_properties
Definition: IDetector.h:115
CloneableVector< IAxis > m_axes
Definition: IDetector.h:114
void setAnalyzerProperties(const kvector_t direction, double efficiency, double total_transmission)
Sets the polarization analyzer characteristics of the detector.
Definition: IDetector.cpp:99
virtual void init(const Beam &)
Inits detector with the beam settings.
Definition: IDetector.h:46
void addAxis(const IAxis &axis)
Definition: IDetector.cpp:41
OutputData< double > * createDetectorIntensity(const std::vector< SimulationElement > &elements) const
Returns new intensity map with detector resolution applied.
Definition: IDetector.cpp:144
void setDetectorResolution(const IDetectorResolution &p_detector_resolution)
Sets the detector resolution.
Definition: IDetector.cpp:105
std::unique_ptr< OutputData< double > > createDetectorMap() const
Returns empty detector map in given axes units.
Definition: IDetector.cpp:158
virtual void resetRegionOfInterest()=0
Resets region of interest making whole detector plane available for the simulation.
void iterate(std::function< void(const_iterator)> func, bool visit_masks=false) const
Definition: IDetector.cpp:197
IDetector * clone() const override=0
const IDetectorResolution * detectorResolution() const
Returns a pointer to detector resolution object.
Definition: IDetector.cpp:138
virtual const RegionOfInterest * regionOfInterest() const =0
Returns region of interest if exists.
virtual Axes::Units defaultAxesUnits() const
Return default axes units.
Definition: IDetector.h:90
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
Interface providing two-dimensional resolution function.
Templated class to store data of type double or CumulativeValue in multi-dimensional space.
Definition: OutputData.h:32
Defines rectangular area for the detector which will be simulated/fitted.
An iterator for SimulationArea.
Data stucture containing both input and output of a single detector cell.