BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
QSpecScan Class Reference

Scan type with z-components of scattering vector as coordinate values. More...

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

Public Member Functions

 QSpecScan (const IAxis &qs_nm)
 
 QSpecScan (int nbins, double qz_min, double qz_max)
 Sets q-defined specular scan. More...
 
 QSpecScan (std::vector< double > qs_nm)
 Accepts qz-value vector (in inverse nm) More...
 
 ~QSpecScan () override
 
QSpecScanclone () const override
 
virtual const IAxiscoordinateAxis () const override
 Returns coordinate axis assigned to the data holder. More...
 
std::vector< double > createIntensities (const std::vector< SpecularSimulationElement > &sim_elements) const override
 Returns intensity vector corresponding to convolution of given simulation elements. More...
 
std::vector< double > footprint (size_t i, size_t n_elements) const override
 Returns footprint correction factor for a range of simulation elements of size n_elements and starting from element with index i. More...
 
virtual const IFootprintFactorfootprintFactor () const override
 Returns IFootprintFactor object pointer. More...
 
std::vector< SpecularSimulationElementgenerateSimulationElements (const Instrument &instrument) const override
 Generates simulation elements for specular simulations. More...
 
size_t numberOfSimulationElements () const override
 Returns the number of simulation elements. More...
 
double offset () const
 
const ScanResolutionresolution () const
 
void setAbsoluteQResolution (const IRangedDistribution &distr, const std::vector< double > &std_dev)
 Sets qz resolution values via IRangedDistribution and values of standard deviations. More...
 
void setAbsoluteQResolution (const IRangedDistribution &distr, double std_dev)
 
void setOffset (double offset)
 
void setQResolution (const ScanResolution &resolution)
 Sets q resolution values via ScanResolution object. More...
 
void setRelativeQResolution (const IRangedDistribution &distr, const std::vector< double > &rel_dev)
 Sets qz resolution values via IRangedDistribution and values of relative deviations (that is, rel_dev equals standard deviation divided by the mean value). More...
 
void setRelativeQResolution (const IRangedDistribution &distr, double rel_dev)
 
virtual void transferToCPP ()
 Used for Python overriding of clone (see swig/tweaks.py) More...
 

Private Member Functions

std::vector< std::vector< ParameterSample > > applyQResolution () const
 
void checkInitialization ()
 
std::vector< double > generateQzVector () const
 

Private Attributes

double m_offset = 0.
 
std::vector< std::vector< ParameterSample > > m_q_res_cache
 
const std::unique_ptr< IAxism_qs
 
std::unique_ptr< ScanResolutionm_resolution
 

Detailed Description

Scan type with z-components of scattering vector as coordinate values.

Wavelength and incident angles are not accessible separately.

Definition at line 28 of file QSpecScan.h.

Constructor & Destructor Documentation

◆ QSpecScan() [1/3]

QSpecScan::QSpecScan ( std::vector< double >  qs_nm)

Accepts qz-value vector (in inverse nm)

Definition at line 22 of file QSpecScan.cpp.

23  : m_qs(std::make_unique<PointwiseAxis>("qs", std::move(qs_nm)))
25 {
27 }
std::unique_ptr< ScanResolution > m_resolution
Definition: QSpecScan.h:95
void checkInitialization()
Definition: QSpecScan.cpp:137
const std::unique_ptr< IAxis > m_qs
Definition: QSpecScan.h:94
static ScanResolution * scanEmptyResolution()

References checkInitialization().

Referenced by clone().

Here is the call graph for this function:

◆ QSpecScan() [2/3]

QSpecScan::QSpecScan ( const IAxis qs_nm)

Definition at line 29 of file QSpecScan.cpp.

31 {
33 }
virtual IAxis * clone() const =0
clone function

References checkInitialization().

Here is the call graph for this function:

◆ QSpecScan() [3/3]

QSpecScan::QSpecScan ( int  nbins,
double  qz_min,
double  qz_max 
)

Sets q-defined specular scan.

Accepts either numpy array of q-values sorted in ascending order or an IAxis object with q-values. Alternatively an axis can be defined in-place, then the first passed parameter is the number of bins, second - minimum on-axis q-value, third - maximum on-axis q_value.

Definition at line 35 of file QSpecScan.cpp.

36  : m_qs(std::make_unique<FixedBinAxis>("qs", nbins, qz_min, qz_max))
38 {
40 }

References checkInitialization().

Here is the call graph for this function:

◆ ~QSpecScan()

QSpecScan::~QSpecScan ( )
overridedefault

Member Function Documentation

◆ applyQResolution()

std::vector< std::vector< ParameterSample > > QSpecScan::applyQResolution ( ) const
private

Definition at line 161 of file QSpecScan.cpp.

162 {
163  if (m_q_res_cache.empty())
164  m_q_res_cache = m_resolution->generateSamples(m_qs->binCenters());
165  return m_q_res_cache;
166 }
std::vector< std::vector< ParameterSample > > m_q_res_cache
Definition: QSpecScan.h:96

References m_q_res_cache, m_qs, and m_resolution.

Referenced by createIntensities(), and generateQzVector().

◆ checkInitialization()

void QSpecScan::checkInitialization ( )
private

Definition at line 137 of file QSpecScan.cpp.

138 {
139  std::vector<double> axis_values = m_qs->binCenters();
140  if (!std::is_sorted(axis_values.begin(), axis_values.end()))
141  throw std::runtime_error("Error in QSpecScan::checkInitialization: q-vector values shall "
142  "be sorted in ascending order.");
143 
144  if (axis_values.front() < 0)
145  throw std::runtime_error("Error in QSpecScan::checkInitialization: q-vector values are out "
146  "of acceptable range.");
147 }

References m_qs.

Referenced by QSpecScan().

◆ clone()

QSpecScan * QSpecScan::clone ( ) const
overridevirtual

Implements ISpecularScan.

Definition at line 44 of file QSpecScan.cpp.

45 {
46  auto* result = new QSpecScan(*m_qs);
47  result->setQResolution(*m_resolution);
48  result->setOffset(m_offset);
49  return result;
50 }
double m_offset
Definition: QSpecScan.h:98
QSpecScan(std::vector< double > qs_nm)
Accepts qz-value vector (in inverse nm)
Definition: QSpecScan.cpp:22

References QSpecScan(), m_offset, m_qs, and m_resolution.

Here is the call graph for this function:

◆ coordinateAxis()

virtual const IAxis* QSpecScan::coordinateAxis ( ) const
inlineoverridevirtual

Returns coordinate axis assigned to the data holder.

Implements ISpecularScan.

Definition at line 50 of file QSpecScan.h.

50 { return m_qs.get(); }

References m_qs.

◆ createIntensities()

std::vector< double > QSpecScan::createIntensities ( const std::vector< SpecularSimulationElement > &  sim_elements) const
overridevirtual

Returns intensity vector corresponding to convolution of given simulation elements.

Implements ISpecularScan.

Definition at line 82 of file QSpecScan.cpp.

83 {
84  const size_t axis_size = m_qs->size();
85  std::vector<double> result(axis_size, 0.0);
86 
87  const auto samples = applyQResolution();
88 
89  size_t elem_pos = 0;
90  for (size_t i = 0; i < axis_size; ++i) {
91  double& current = result[i];
92  for (size_t j = 0, size = samples[i].size(); j < size; ++j) {
93  current += sim_elements[elem_pos].intensity() * samples[i][j].weight;
94  ++elem_pos;
95  }
96  }
97  return result;
98 }
std::vector< std::vector< ParameterSample > > applyQResolution() const
Definition: QSpecScan.cpp:161

References applyQResolution(), and m_qs.

Here is the call graph for this function:

◆ footprint()

std::vector< double > QSpecScan::footprint ( size_t  i,
size_t  n_elements 
) const
overridevirtual

Returns footprint correction factor for a range of simulation elements of size n_elements and starting from element with index i.

Implements ISpecularScan.

Definition at line 67 of file QSpecScan.cpp.

68 {
69  if (i + n_elements > numberOfSimulationElements())
70  throw std::runtime_error("Error in QSpecScan::footprint: given index exceeds the "
71  "number of simulation elements");
72  return std::vector<double>(n_elements, 1.0);
73 }
size_t numberOfSimulationElements() const override
Returns the number of simulation elements.
Definition: QSpecScan.cpp:76

References numberOfSimulationElements().

Here is the call graph for this function:

◆ footprintFactor()

virtual const IFootprintFactor* QSpecScan::footprintFactor ( ) const
inlineoverridevirtual

Returns IFootprintFactor object pointer.

Implements ISpecularScan.

Definition at line 53 of file QSpecScan.h.

53 { return nullptr; }

◆ generateQzVector()

std::vector< double > QSpecScan::generateQzVector ( ) const
private

Definition at line 149 of file QSpecScan.cpp.

150 {
151  const auto samples = applyQResolution();
152 
153  std::vector<double> result;
154  result.reserve(numberOfSimulationElements());
155  for (size_t i = 0, size_out = samples.size(); i < size_out; ++i)
156  for (size_t j = 0, size_in = samples[i].size(); j < size_in; ++j)
157  result.push_back(samples[i][j].value);
158  return result;
159 }

References applyQResolution(), and numberOfSimulationElements().

Referenced by generateSimulationElements().

Here is the call graph for this function:

◆ generateSimulationElements()

std::vector< SpecularSimulationElement > QSpecScan::generateSimulationElements ( const Instrument instrument) const
overridevirtual

Generates simulation elements for specular simulations.

Implements ISpecularScan.

Definition at line 54 of file QSpecScan.cpp.

55 {
56  const std::vector<double> qz = generateQzVector();
57 
58  std::vector<SpecularSimulationElement> result;
59  result.reserve(qz.size());
60  for (size_t i = 0, size = qz.size(); i < size; ++i)
61  result.emplace_back(
62  SpecularSimulationElement(-(qz[i] + m_offset) / 2.0, instrument, qz[i] >= 0));
63 
64  return result;
65 }
std::vector< double > generateQzVector() const
Definition: QSpecScan.cpp:149
Data stucture containing both input and output of a single image pixel for specular simulation.

References generateQzVector(), and m_offset.

Here is the call graph for this function:

◆ numberOfSimulationElements()

size_t QSpecScan::numberOfSimulationElements ( ) const
overridevirtual

Returns the number of simulation elements.

Implements ISpecularScan.

Definition at line 76 of file QSpecScan.cpp.

77 {
78  return m_qs->size() * m_resolution->nSamples();
79 }

References m_qs, and m_resolution.

Referenced by footprint(), and generateQzVector().

◆ offset()

double QSpecScan::offset ( ) const
inline

Definition at line 87 of file QSpecScan.h.

87 { return m_offset; }

References m_offset.

Referenced by setOffset().

◆ resolution()

const ScanResolution* QSpecScan::resolution ( ) const
inline

Definition at line 42 of file QSpecScan.h.

42 { return m_resolution.get(); }

References m_resolution.

Referenced by setAbsoluteQResolution(), setQResolution(), and setRelativeQResolution().

◆ setAbsoluteQResolution() [1/2]

void QSpecScan::setAbsoluteQResolution ( const IRangedDistribution distr,
const std::vector< double > &  std_dev 
)

Sets qz resolution values via IRangedDistribution and values of standard deviations.

std_dev can be either single-valued or a numpy array. In the latter case the length of the array should coinside with the length of the qz-axis.

Definition at line 129 of file QSpecScan.cpp.

131 {
132  std::unique_ptr<ScanResolution> resolution(
135 }
void setQResolution(const ScanResolution &resolution)
Sets q resolution values via ScanResolution object.
Definition: QSpecScan.cpp:100
const ScanResolution * resolution() const
Definition: QSpecScan.h:42
static ScanResolution * scanAbsoluteResolution(const IRangedDistribution &distr, double stddev)

References resolution(), ScanResolution::scanAbsoluteResolution(), and setQResolution().

Here is the call graph for this function:

◆ setAbsoluteQResolution() [2/2]

void QSpecScan::setAbsoluteQResolution ( const IRangedDistribution distr,
double  std_dev 
)

Definition at line 122 of file QSpecScan.cpp.

123 {
124  std::unique_ptr<ScanResolution> resolution(
127 }

References resolution(), ScanResolution::scanAbsoluteResolution(), and setQResolution().

Referenced by StandardSimulations::TOFRWithPointwiseResolution().

Here is the call graph for this function:

◆ setOffset()

void QSpecScan::setOffset ( double  offset)
inline

Definition at line 86 of file QSpecScan.h.

86 { m_offset = offset; }
double offset() const
Definition: QSpecScan.h:87

References m_offset, and offset().

Here is the call graph for this function:

◆ setQResolution()

void QSpecScan::setQResolution ( const ScanResolution resolution)

Sets q resolution values via ScanResolution object.

Definition at line 100 of file QSpecScan.cpp.

101 {
102  m_resolution.reset(resolution.clone());
103  m_q_res_cache.clear();
104  m_q_res_cache.shrink_to_fit();
105 }
ScanResolution * clone() const override=0

References ScanResolution::clone(), m_q_res_cache, m_resolution, and resolution().

Referenced by setAbsoluteQResolution(), and setRelativeQResolution().

Here is the call graph for this function:

◆ setRelativeQResolution() [1/2]

void QSpecScan::setRelativeQResolution ( const IRangedDistribution distr,
const std::vector< double > &  rel_dev 
)

Sets qz resolution values via IRangedDistribution and values of relative deviations (that is, rel_dev equals standard deviation divided by the mean value).

rel_dev can be either single-valued or a numpy array. In the latter case the length of the array should coinside with the length of the qz-axis.

Definition at line 114 of file QSpecScan.cpp.

116 {
117  std::unique_ptr<ScanResolution> resolution(
120 }
static ScanResolution * scanRelativeResolution(const IRangedDistribution &distr, double stddev)

References resolution(), ScanResolution::scanRelativeResolution(), and setQResolution().

Here is the call graph for this function:

◆ setRelativeQResolution() [2/2]

void QSpecScan::setRelativeQResolution ( const IRangedDistribution distr,
double  rel_dev 
)

Definition at line 107 of file QSpecScan.cpp.

108 {
109  std::unique_ptr<ScanResolution> resolution(
112 }

References resolution(), ScanResolution::scanRelativeResolution(), and setQResolution().

Referenced by StandardSimulations::TOFRWithRelativeResolution().

Here is the call graph for this function:

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

Used for Python overriding of clone (see swig/tweaks.py)

Definition at line 34 of file ICloneable.h.

Member Data Documentation

◆ m_offset

double QSpecScan::m_offset = 0.
private

Definition at line 98 of file QSpecScan.h.

Referenced by clone(), generateSimulationElements(), offset(), and setOffset().

◆ m_q_res_cache

std::vector<std::vector<ParameterSample> > QSpecScan::m_q_res_cache
mutableprivate

Definition at line 96 of file QSpecScan.h.

Referenced by applyQResolution(), and setQResolution().

◆ m_qs

const std::unique_ptr<IAxis> QSpecScan::m_qs
private

◆ m_resolution

std::unique_ptr<ScanResolution> QSpecScan::m_resolution
private

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