BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DetectorItems.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Device/DetectorItems.cpp
6 //! @brief Implements classes DetectorItems
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 
16 #include "Device/Detector/IDetector.h"
17 #include "Device/Mask/IShape2D.h"
18 #include "Device/Resolution/ResolutionFunction2DGaussian.h"
23 
25 
26 std::unique_ptr<IDetector> DetectorItem::createDetector() const
27 {
28  auto result = createDomainDetector();
29  addMasksToCore(result.get());
30 
31  if (auto resFunc = createResolutionFunction())
32  result->setResolutionFunction(*resFunc);
33 
34  return result;
35 }
36 
37 void DetectorItem::importMasks(const MaskContainerItem* maskContainer)
38 {
39  m_maskItems.copy(maskContainer);
40 }
41 
43 {
44  return m_maskItems;
45 }
46 
48 {
49  return m_resolutionFunction.get();
50 }
51 
53 {
54  return m_resolutionFunction;
55 }
56 
57 std::unique_ptr<IResolutionFunction2D> DetectorItem::createResolutionFunction() const
58 {
60 }
61 
62 void DetectorItem::addMasksToCore(IDetector* detector) const
63 {
64  const double scale = axesToCoreUnitsFactor();
65  const auto maskItems = m_maskItems.maskItems();
66  for (auto maskIter = maskItems.rbegin(); maskIter != maskItems.rend(); maskIter++) {
67  if (auto* roiItem = dynamic_cast<RegionOfInterestItem*>(*maskIter)) {
68  const double xlow = scale * roiItem->xLow();
69  const double ylow = scale * roiItem->yLow();
70  const double xup = scale * roiItem->xUp();
71  const double yup = scale * roiItem->yUp();
72  detector->setRegionOfInterest(xlow, ylow, xup, yup);
73  } else {
74  std::unique_ptr<IShape2D> shape((*maskIter)->createShape(scale));
75  detector->addMask(*shape, (*maskIter)->maskValue());
76  }
77  }
78 }
Defines classes DetectorItems.
Defines class GroupInfo.
Defines MaskItems classes.
Defines family of ResolutionFunctionItem.
Defines class SphericalDetectorItem.
MaskItems & maskItems()
virtual double axesToCoreUnitsFactor() const
Scales the values provided by axes (to perform deg->rad conversion on the way to domain).
Definition: DetectorItems.h:57
void importMasks(const MaskContainerItem *maskContainer)
MaskItems m_maskItems
for creation of domain detector; only filled and relevant in jobs
Definition: DetectorItems.h:68
std::unique_ptr< IResolutionFunction2D > createResolutionFunction() const
ResolutionFunctionItem * resolutionFunction() const
SelectionDescriptor< ResolutionFunctionItem * > resolutionFunctionSelection() const
virtual std::unique_ptr< IDetector > createDomainDetector() const =0
SelectionProperty< ResolutionFunctionItem * > m_resolutionFunction
Definition: DetectorItems.h:69
void addMasksToCore(IDetector *detector) const
std::unique_ptr< IDetector > createDetector() const
Container holding various masks as children.
Definition: MaskItems.h:202
List of MaskItems.
Definition: MaskItems.h:232
void copy(const MaskContainerItem *maskContainer)
Copy the mask items stored in the given maskContainer.
Definition: MaskItems.cpp:507
QVector< MaskItem * > maskItems() const
Definition: MaskItems.cpp:502
virtual std::unique_ptr< IResolutionFunction2D > createResolutionFunction(double scale=1.0) const =0
Describes a selection (various possibilities and the current one).
T get() const
Direct access to the stored pointer.