BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
RectangularDetectorItem Class Reference

Description

Definition at line 24 of file RectangularDetectorItem.h.

Inheritance diagram for RectangularDetectorItem:
[legend]
Collaboration diagram for RectangularDetectorItem:
[legend]

Public Member Functions

 RectangularDetectorItem ()
 
QVector< std::variant< VectorDescriptor, DoubleDescriptor > > alignmentPropertiesForUI () const
 The properties of the currently active alignment. Sorted as expected on the UI. More...
 
virtual double axesToCoreUnitsFactor () const
 Scales the values provided by axes (to perform deg->rad conversion on the way to domain). More...
 
std::unique_ptr< IDetector > createDetector () const
 
RectangularDetector::EDetectorArrangement detectorAlignment () const
 
SelectionDescriptor< RectangularDetector::EDetectorArrangement > detectorAlignmentSelection () const
 
 DOUBLE_PROPERTY (distance, Distance)
 
 DOUBLE_PROPERTY (height, Height)
 
 DOUBLE_PROPERTY (u0, U0)
 
 DOUBLE_PROPERTY (v0, V0)
 
 DOUBLE_PROPERTY (width, Width)
 
void importMasks (const MaskContainerItem *maskContainer)
 
MaskItemsmaskItems ()
 
ResolutionFunctionItemresolutionFunction () const
 
SelectionDescriptor< ResolutionFunctionItem * > resolutionFunctionSelection () const
 
void serialize (Streamer &s) override
 
void setDetectorAlignment (RectangularDetector::EDetectorArrangement alignment)
 
template<typename T >
T * setResolutionFunctionType ()
 
void setXSize (size_t nx) override
 sets the size of x-axis of the detector More...
 
void setYSize (size_t ny) override
 sets the size of y-axis of the detector More...
 
 VECTOR_PROPERTY (directionVector, DirectionVector)
 
 VECTOR_PROPERTY (normalVector, NormalVector)
 
int xSize () const override
 Returns the size of x-axis of the detector. More...
 
int ySize () const override
 Returns the size of y-axis of the detector. More...
 

Protected Member Functions

void addMasksToCore (IDetector *detector) const
 
std::unique_ptr< IResolutionFunction2D > createResolutionFunction () const
 

Protected Attributes

MaskItems m_maskItems
 for creation of domain detector; only filled and relevant in jobs More...
 
SelectionProperty< ResolutionFunctionItem * > m_resolutionFunction
 

Private Member Functions

std::unique_ptr< IDetector > createDomainDetector () const override
 
void updateTooltips ()
 

Private Attributes

RectangularDetector::EDetectorArrangement m_detectorAlignment
 
int m_xSize
 
int m_ySize
 

Static Private Attributes

static constexpr auto P_DBEAM_U0 {"u0 (dbeam)"}
 
static constexpr auto P_DBEAM_V0 {"v0 (dbeam)"}
 
static constexpr auto P_DIRECTION {"Direction vector"}
 
static constexpr auto P_DISTANCE {"Distance"}
 
static constexpr auto P_NORMAL {"Normal vector"}
 
static constexpr auto P_U0 {"u0"}
 
static constexpr auto P_V0 {"v0"}
 
static constexpr auto P_X_AXIS {"X axis"}
 
static constexpr auto P_Y_AXIS {"Y axis"}
 

Constructor & Destructor Documentation

◆ RectangularDetectorItem()

RectangularDetectorItem::RectangularDetectorItem ( )

Definition at line 65 of file RectangularDetectorItem.cpp.

66 {
68  "Resolution function", "Detector resolution function", "resolutionFunction",
69  initResolutionFunction);
70 
71  m_xSize = 100;
72  m_ySize = 100;
73  m_width.init("Width (x-axis)", "Width of the detector", default_detector_width, "mm", 3,
74  RealLimits::positive(), "width");
75  m_height.init("Height (y-axis)", "Height of the detector", default_detector_height, "mm", 3,
76  RealLimits::positive(), "height");
77 
78  m_normalVector.init(
79  "Normal vector",
80  "Normal of the detector plane with length equal to the sample detector distance",
81  Unit::unitless, "normalVector");
82  m_normalVector.r3().setX(default_detector_distance);
83  m_directionVector.init("Direction vector",
84  "Detector axis direction vector w.r.t. the sample coordinate system",
85  Unit::unitless, "directionVector");
86  m_directionVector.r3().setY(-1.0);
87 
88  m_u0.init("u0", "", default_detector_width / 2., "mm", 3, RealLimits::limitless(), "u0");
89  m_v0.init("v0", "", 0.0, "mm", 3, RealLimits::limitless(), "v0");
90  m_distance.init("Distance", "Distance from the sample origin to the detector plane",
91  default_detector_distance, "mm", "distance");
92 
93  m_detectorAlignment = RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM;
94 
96 }
@ unitless
SelectionProperty< ResolutionFunctionItem * > m_resolutionFunction
Definition: DetectorItems.h:69
RectangularDetector::EDetectorArrangement m_detectorAlignment
void initWithInitializer(const QString &label, const QString &tooltip, const QString &persistentTag, std::function< void(T newItem, const T oldItem)> initializer)
Initialize by means of a catalog class and an initializer function.

References SelectionProperty< T >::initWithInitializer(), m_detectorAlignment, DetectorItem::m_resolutionFunction, m_xSize, m_ySize, unitless, and updateTooltips().

Here is the call graph for this function:

Member Function Documentation

◆ addMasksToCore()

void DetectorItem::addMasksToCore ( IDetector *  detector) const
protectedinherited

Definition at line 62 of file DetectorItems.cpp.

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 }
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
MaskItems m_maskItems
for creation of domain detector; only filled and relevant in jobs
Definition: DetectorItems.h:68
QVector< MaskItem * > maskItems() const
Definition: MaskItems.cpp:502

References DetectorItem::axesToCoreUnitsFactor(), DetectorItem::m_maskItems, DetectorItem::maskItems(), and MaskItems::maskItems().

Referenced by DetectorItem::createDetector().

Here is the call graph for this function:

◆ alignmentPropertiesForUI()

QVector< std::variant< VectorDescriptor, DoubleDescriptor > > RectangularDetectorItem::alignmentPropertiesForUI ( ) const

The properties of the currently active alignment. Sorted as expected on the UI.

Definition at line 175 of file RectangularDetectorItem.cpp.

176 {
177  if (m_detectorAlignment == RectangularDetector::GENERIC)
178  return {normalVector(), directionVector(), u0(), v0()};
179 
180  return {u0(), v0(), distance()};
181 }

References m_detectorAlignment.

◆ axesToCoreUnitsFactor()

virtual double DetectorItem::axesToCoreUnitsFactor ( ) const
inlinevirtualinherited

Scales the values provided by axes (to perform deg->rad conversion on the way to domain).

Reimplemented in SphericalDetectorItem.

Definition at line 57 of file DetectorItems.h.

57 { return 1.0; }

Referenced by DetectorItem::addMasksToCore(), and DetectorItem::createResolutionFunction().

◆ createDetector()

std::unique_ptr< IDetector > DetectorItem::createDetector ( ) const
inherited

Definition at line 26 of file DetectorItems.cpp.

27 {
28  auto result = createDomainDetector();
29  addMasksToCore(result.get());
30 
31  if (auto resFunc = createResolutionFunction())
32  result->setResolutionFunction(*resFunc);
33 
34  return result;
35 }
std::unique_ptr< IResolutionFunction2D > createResolutionFunction() const
virtual std::unique_ptr< IDetector > createDomainDetector() const =0
void addMasksToCore(IDetector *detector) const

References DetectorItem::addMasksToCore(), DetectorItem::createDomainDetector(), and DetectorItem::createResolutionFunction().

Referenced by Instrument2DItem::createInstrument(), Instrument2DItem::createOffspecSimulation(), and Instrument2DItem::createScatteringSimulation().

Here is the call graph for this function:

◆ createDomainDetector()

std::unique_ptr< IDetector > RectangularDetectorItem::createDomainDetector ( ) const
overrideprivatevirtual

Implements DetectorItem.

Definition at line 183 of file RectangularDetectorItem.cpp.

184 {
185  auto result = std::make_unique<RectangularDetector>(xSize(), width(), ySize(), height());
186 
187  // distance and alignment
188  switch (m_detectorAlignment) {
189  case RectangularDetector::GENERIC:
190  result->setDetectorPosition(m_normalVector, m_u0, m_v0, m_directionVector);
191  break;
192  case RectangularDetector::PERPENDICULAR_TO_SAMPLE:
193  result->setPerpendicularToSampleX(m_distance, m_u0, m_v0);
194  break;
195  case RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM:
196  result->setPerpendicularToDirectBeam(m_distance, m_u0, m_v0);
197  break;
198  case RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM:
199  result->setPerpendicularToReflectedBeam(m_distance, m_u0, m_v0);
200  break;
201  case RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS:
202  result->setPerpendicularToReflectedBeam(m_distance);
203  result->setDirectBeamPosition(m_u0, m_v0);
204  break;
205  default:
206  break;
207  }
208 
209  return std::unique_ptr<IDetector>(result.release());
210 }
int ySize() const override
Returns the size of y-axis of the detector.
int xSize() const override
Returns the size of x-axis of the detector.

References m_detectorAlignment, xSize(), and ySize().

Here is the call graph for this function:

◆ createResolutionFunction()

std::unique_ptr< IResolutionFunction2D > DetectorItem::createResolutionFunction ( ) const
protectedinherited

Definition at line 57 of file DetectorItems.cpp.

58 {
60 }
virtual std::unique_ptr< IResolutionFunction2D > createResolutionFunction(double scale=1.0) const =0

References DetectorItem::axesToCoreUnitsFactor(), ResolutionFunctionItem::createResolutionFunction(), and DetectorItem::m_resolutionFunction.

Referenced by DetectorItem::createDetector().

Here is the call graph for this function:

◆ detectorAlignment()

RectangularDetector::EDetectorArrangement RectangularDetectorItem::detectorAlignment ( ) const

Definition at line 132 of file RectangularDetectorItem.cpp.

133 {
134  return m_detectorAlignment;
135 }

References m_detectorAlignment.

Referenced by DetectorAlignmentEditor::createAligmentWidgets().

◆ detectorAlignmentSelection()

SelectionDescriptor< RectangularDetector::EDetectorArrangement > RectangularDetectorItem::detectorAlignmentSelection ( ) const

Definition at line 158 of file RectangularDetectorItem.cpp.

159 {
161 
162  d.label = "Alignment";
163  for (auto a : alignments())
164  d.options << alignmentTitle(a);
165 
166  d.currentIndexSetter = [&](int newIndex) {
167  const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignments()[newIndex]);
168  };
169 
170  d.currentIndexGetter = [&]() { return alignments().indexOf(m_detectorAlignment); };
171  return d;
172 }
void setDetectorAlignment(RectangularDetector::EDetectorArrangement alignment)
Describes a selection (various possibilities and the current one).
function< int()> currentIndexGetter
Function to get currently selected option.
QString label
A label text (short, no trailing colon)
function< void(int)> currentIndexSetter
Function to set currently selected option.
QStringList options
List of options, usually presented as combo entries.

References SelectionDescriptor< T >::currentIndexGetter, SelectionDescriptor< T >::currentIndexSetter, SelectionDescriptor< T >::label, m_detectorAlignment, SelectionDescriptor< T >::options, and setDetectorAlignment().

Referenced by DetectorAlignmentEditor::DetectorAlignmentEditor().

Here is the call graph for this function:

◆ DOUBLE_PROPERTY() [1/5]

RectangularDetectorItem::DOUBLE_PROPERTY ( distance  ,
Distance   
)

◆ DOUBLE_PROPERTY() [2/5]

RectangularDetectorItem::DOUBLE_PROPERTY ( height  ,
Height   
)

◆ DOUBLE_PROPERTY() [3/5]

RectangularDetectorItem::DOUBLE_PROPERTY ( u0  ,
U0   
)

◆ DOUBLE_PROPERTY() [4/5]

RectangularDetectorItem::DOUBLE_PROPERTY ( v0  ,
V0   
)

◆ DOUBLE_PROPERTY() [5/5]

RectangularDetectorItem::DOUBLE_PROPERTY ( width  ,
Width   
)

◆ importMasks()

void DetectorItem::importMasks ( const MaskContainerItem maskContainer)
inherited

Definition at line 37 of file DetectorItems.cpp.

38 {
39  m_maskItems.copy(maskContainer);
40 }
void copy(const MaskContainerItem *maskContainer)
Copy the mask items stored in the given maskContainer.
Definition: MaskItems.cpp:507

References MaskItems::copy(), and DetectorItem::m_maskItems.

Referenced by Instrument2DItem::importMasks().

Here is the call graph for this function:

◆ maskItems()

MaskItems & DetectorItem::maskItems ( )
inherited

Definition at line 42 of file DetectorItems.cpp.

43 {
44  return m_maskItems;
45 }

References DetectorItem::m_maskItems.

Referenced by DetectorItem::addMasksToCore().

◆ resolutionFunction()

ResolutionFunctionItem * DetectorItem::resolutionFunction ( ) const
inherited

Definition at line 47 of file DetectorItems.cpp.

48 {
49  return m_resolutionFunction.get();
50 }
T get() const
Direct access to the stored pointer.

References SelectionProperty< T >::get(), and DetectorItem::m_resolutionFunction.

Here is the call graph for this function:

◆ resolutionFunctionSelection()

◆ serialize()

void RectangularDetectorItem::serialize ( Streamer s)
overridevirtual

Implements DetectorItem.

Definition at line 98 of file RectangularDetectorItem.cpp.

99 {
100  int alignment = m_detectorAlignment;
101 
102  s.assertVersion(0);
103  // base class members
104  Serialize::rwClass(s, "masks", m_maskItems);
105  Serialize::rwSelected<ResolutionFunctionItemCatalog>(s, m_resolutionFunction);
106 
107  // own members
108  Serialize::rwValue(s, "xSize", m_xSize);
109  Serialize::rwValue(s, "ySize", m_ySize);
110  Serialize::rwProperty(s, m_width);
111  Serialize::rwProperty(s, m_height);
112  Serialize::rwValue(s, "alignment", alignment);
113  Serialize::rwProperty(s, m_normalVector);
114  Serialize::rwProperty(s, m_directionVector);
115  Serialize::rwProperty(s, m_u0);
116  Serialize::rwProperty(s, m_v0);
117  Serialize::rwProperty(s, m_distance);
118 
119  if (s.xmlReader()) {
120  setDetectorAlignment(static_cast<RectangularDetector::EDetectorArrangement>(alignment));
122  }
123 }
virtual void setUnit(const std::variant< QString, Unit > &)
Set the unit of the distributed value.
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
Definition: Streamer.h:48
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26
void rwProperty(Streamer &s, DoubleProperty &d)
void rwValue(Streamer &s, const QString &tag, bool &val)
Definition: Serialize.cpp:19
void rwClass(Streamer &s, const QString &tag, T &t)
Serializes an item from a class that provides the function void serialize(Streamer&).
Definition: Serialize.h:77

References Streamer::assertVersion(), m_detectorAlignment, DetectorItem::m_maskItems, DetectorItem::m_resolutionFunction, m_xSize, m_ySize, Serialize::rwClass(), Serialize::rwProperty(), Serialize::rwValue(), setDetectorAlignment(), ResolutionFunctionItem::setUnit(), and Streamer::xmlReader().

Here is the call graph for this function:

◆ setDetectorAlignment()

void RectangularDetectorItem::setDetectorAlignment ( RectangularDetector::EDetectorArrangement  alignment)

Definition at line 125 of file RectangularDetectorItem.cpp.

127 {
128  m_detectorAlignment = alignment;
129  updateTooltips();
130 }

References m_detectorAlignment, and updateTooltips().

Referenced by detectorAlignmentSelection(), and serialize().

Here is the call graph for this function:

◆ setResolutionFunctionType()

template<typename T >
T * DetectorItem::setResolutionFunctionType
inherited

Definition at line 73 of file DetectorItems.h.

74 {
76  return dynamic_cast<T*>(m_resolutionFunction.get());
77 }
void set(T t, bool callInitializer=false)
Directly set the new item.

References SelectionProperty< T >::get(), DetectorItem::m_resolutionFunction, and SelectionProperty< T >::set().

Here is the call graph for this function:

◆ setXSize()

void RectangularDetectorItem::setXSize ( size_t  nx)
overridevirtual

sets the size of x-axis of the detector

Implements DetectorItem.

Definition at line 147 of file RectangularDetectorItem.cpp.

148 {
149  m_xSize = static_cast<int>(nx);
150 }

References m_xSize.

Referenced by RectangularDetectorEditor::RectangularDetectorEditor().

◆ setYSize()

void RectangularDetectorItem::setYSize ( size_t  ny)
overridevirtual

sets the size of y-axis of the detector

Implements DetectorItem.

Definition at line 152 of file RectangularDetectorItem.cpp.

153 {
154  m_ySize = static_cast<int>(ny);
155 }

References m_ySize.

Referenced by RectangularDetectorEditor::RectangularDetectorEditor().

◆ updateTooltips()

void RectangularDetectorItem::updateTooltips ( )
private

Definition at line 212 of file RectangularDetectorItem.cpp.

213 {
214  switch (m_detectorAlignment) {
215  case RectangularDetector::GENERIC:
216  m_u0.setTooltip(
217  "u-coordinate of point of intersection of normal vector and detector plane");
218  m_v0.setTooltip(
219  "v-coordinate of point of intersection of normal vector and detector plane");
220  break;
221  case RectangularDetector::PERPENDICULAR_TO_SAMPLE:
222  m_u0.setTooltip("u-coordinate of point where sample x-axis crosses the detector");
223  m_v0.setTooltip("v-coordinate of point where sample x-axis crosses the detector");
224  break;
225  case RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM:
226  m_u0.setTooltip("u-coordinate of point where reflected beam hits the detector");
227  m_v0.setTooltip("v-coordinate of point where reflected beam hits the detector");
228  break;
229  case RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM: // fall-through!
230  case RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS:
231  m_u0.setTooltip("u-coordinate of point where direct beam hits the detector");
232  m_v0.setTooltip("v-coordinate of point where direct beam hits the detector");
233  break;
234  default:
235  break;
236  }
237 }

References m_detectorAlignment.

Referenced by RectangularDetectorItem(), and setDetectorAlignment().

◆ VECTOR_PROPERTY() [1/2]

RectangularDetectorItem::VECTOR_PROPERTY ( directionVector  ,
DirectionVector   
)

◆ VECTOR_PROPERTY() [2/2]

RectangularDetectorItem::VECTOR_PROPERTY ( normalVector  ,
NormalVector   
)

◆ xSize()

int RectangularDetectorItem::xSize ( ) const
overridevirtual

Returns the size of x-axis of the detector.

Implements DetectorItem.

Definition at line 137 of file RectangularDetectorItem.cpp.

138 {
139  return m_xSize;
140 }

References m_xSize.

Referenced by RectangularDetectorEditor::RectangularDetectorEditor(), and createDomainDetector().

◆ ySize()

int RectangularDetectorItem::ySize ( ) const
overridevirtual

Returns the size of y-axis of the detector.

Implements DetectorItem.

Definition at line 142 of file RectangularDetectorItem.cpp.

143 {
144  return m_ySize;
145 }

References m_ySize.

Referenced by RectangularDetectorEditor::RectangularDetectorEditor(), and createDomainDetector().

Member Data Documentation

◆ m_detectorAlignment

RectangularDetector::EDetectorArrangement RectangularDetectorItem::m_detectorAlignment
private

◆ m_maskItems

MaskItems DetectorItem::m_maskItems
protectedinherited

for creation of domain detector; only filled and relevant in jobs

Definition at line 68 of file DetectorItems.h.

Referenced by DetectorItem::addMasksToCore(), DetectorItem::importMasks(), DetectorItem::maskItems(), serialize(), and SphericalDetectorItem::serialize().

◆ m_resolutionFunction

◆ m_xSize

int RectangularDetectorItem::m_xSize
private

Definition at line 71 of file RectangularDetectorItem.h.

Referenced by RectangularDetectorItem(), serialize(), setXSize(), and xSize().

◆ m_ySize

int RectangularDetectorItem::m_ySize
private

Definition at line 72 of file RectangularDetectorItem.h.

Referenced by RectangularDetectorItem(), serialize(), setYSize(), and ySize().

◆ P_DBEAM_U0

constexpr auto RectangularDetectorItem::P_DBEAM_U0 {"u0 (dbeam)"}
staticconstexprprivate

Definition at line 32 of file RectangularDetectorItem.h.

◆ P_DBEAM_V0

constexpr auto RectangularDetectorItem::P_DBEAM_V0 {"v0 (dbeam)"}
staticconstexprprivate

Definition at line 33 of file RectangularDetectorItem.h.

◆ P_DIRECTION

constexpr auto RectangularDetectorItem::P_DIRECTION {"Direction vector"}
staticconstexprprivate

Definition at line 29 of file RectangularDetectorItem.h.

◆ P_DISTANCE

constexpr auto RectangularDetectorItem::P_DISTANCE {"Distance"}
staticconstexprprivate

Definition at line 34 of file RectangularDetectorItem.h.

◆ P_NORMAL

constexpr auto RectangularDetectorItem::P_NORMAL {"Normal vector"}
staticconstexprprivate

Definition at line 28 of file RectangularDetectorItem.h.

◆ P_U0

constexpr auto RectangularDetectorItem::P_U0 {"u0"}
staticconstexprprivate

Definition at line 30 of file RectangularDetectorItem.h.

◆ P_V0

constexpr auto RectangularDetectorItem::P_V0 {"v0"}
staticconstexprprivate

Definition at line 31 of file RectangularDetectorItem.h.

◆ P_X_AXIS

constexpr auto RectangularDetectorItem::P_X_AXIS {"X axis"}
staticconstexprprivate

Definition at line 26 of file RectangularDetectorItem.h.

◆ P_Y_AXIS

constexpr auto RectangularDetectorItem::P_Y_AXIS {"Y axis"}
staticconstexprprivate

Definition at line 27 of file RectangularDetectorItem.h.


The documentation for this class was generated from the following files: