BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
QSpecScan Class Reference
Inheritance diagram for QSpecScan:
Collaboration diagram for QSpecScan:

Public Member Functions

 QSpecScan (std::vector< double > qs_nm)
 
 QSpecScan (const IAxis &qs_nm)
 
 QSpecScan (int nbins, double qz_min, double qz_max)
 
 ~QSpecScan () override
 
QSpecScanclone () const override
 
std::vector< SpecularSimulationElementgenerateSimulationElements () const override
 
virtual const IAxiscoordinateAxis () const override
 
virtual const IFootprintFactorfootprintFactor () const override
 
std::vector< double > footprint (size_t i, size_t n_elements) const override
 
size_t numberOfSimulationElements () const override
 
std::vector< double > createIntensities (const std::vector< SpecularSimulationElement > &sim_elements) const override
 
std::string print () const override
 
void setQResolution (const ScanResolution &resolution)
 
void setRelativeQResolution (const RangedDistribution &distr, double rel_dev)
 
void setRelativeQResolution (const RangedDistribution &distr, const std::vector< double > &rel_dev)
 
void setAbsoluteQResolution (const RangedDistribution &distr, double std_dev)
 
void setAbsoluteQResolution (const RangedDistribution &distr, const std::vector< double > &std_dev)
 
virtual void transferToCPP ()
 

Private Member Functions

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

Private Attributes

std::unique_ptr< IAxism_qs
 
std::unique_ptr< ScanResolutionm_resolution
 
std::vector< std::vector< ParameterSample > > m_q_res_cache
 

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 23 of file QSpecScan.cpp.

24  : m_qs(std::make_unique<PointwiseAxis>("qs", std::move(qs_nm))),
26 {
28 }
std::unique_ptr< IAxis > m_qs
Definition: QSpecScan.h:91
std::unique_ptr< ScanResolution > m_resolution
Definition: QSpecScan.h:92
void checkInitialization()
Definition: QSpecScan.cpp:150
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 30 of file QSpecScan.cpp.

31  : m_qs(qs_nm.clone()),
33 {
35 }
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 37 of file QSpecScan.cpp.

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

References checkInitialization().

Here is the call graph for this function:

◆ ~QSpecScan()

QSpecScan::~QSpecScan ( )
overridedefault

Member Function Documentation

◆ clone()

QSpecScan * QSpecScan::clone ( ) const
overridevirtual

Implements ISpecularScan.

Definition at line 46 of file QSpecScan.cpp.

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

References m_qs, m_resolution, and QSpecScan().

Here is the call graph for this function:

◆ generateSimulationElements()

std::vector< SpecularSimulationElement > QSpecScan::generateSimulationElements ( ) 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(SpecularSimulationElement(-qz[i] / 2.0, qz[i] >= 0));
62  return result;
63 }
std::vector< double > generateQzVector() const
Definition: QSpecScan.cpp:162
Data stucture containing both input and output of a single image pixel for specular simulation.

References generateQzVector().

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 48 of file QSpecScan.h.

48 { return m_qs.get(); }

References m_qs.

Referenced by print().

◆ footprintFactor()

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

Returns IFootprintFactor object pointer.

Implements ISpecularScan.

Definition at line 51 of file QSpecScan.h.

51 { return nullptr; }

◆ 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 65 of file QSpecScan.cpp.

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

References numberOfSimulationElements().

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 74 of file QSpecScan.cpp.

75 {
76  return m_qs->size() * m_resolution->nSamples();
77 }

References m_qs, and m_resolution.

Referenced by footprint(), and generateQzVector().

◆ 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 80 of file QSpecScan.cpp.

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

References applyQResolution(), and m_qs.

Here is the call graph for this function:

◆ print()

std::string QSpecScan::print ( ) const
overridevirtual

Print scan definition in python format.

Implements ISpecularScan.

Definition at line 98 of file QSpecScan.cpp.

99 {
100  std::stringstream result;
101  const std::string axis_def = pyfmt::indent() + "axis = ";
102  result << axis_def << coordinateAxis()->pyString("", axis_def.size()) << "\n";
103 
104  result << pyfmt::indent() << "scan = ba.QSpecScan(axis)";
105  if (!m_resolution->empty()) {
106  result << "\n";
107  result << *m_resolution << "\n";
108  result << pyfmt::indent() << "scan.setQResolution(resolution)";
109  }
110  return result.str();
111 }
virtual std::string pyString(const std::string &units, size_t offset) const =0
virtual const IAxis * coordinateAxis() const override
Returns coordinate axis assigned to the data holder.
Definition: QSpecScan.h:48
std::string indent(size_t width)
Returns a string of blanks with given width.
Definition: PyFmt.cpp:141

References coordinateAxis(), pyfmt::indent(), m_resolution, and IAxis::pyString().

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 113 of file QSpecScan.cpp.

114 {
115  m_resolution.reset(resolution.clone());
116  m_q_res_cache.clear();
117  m_q_res_cache.shrink_to_fit();
118 }
std::vector< std::vector< ParameterSample > > m_q_res_cache
Definition: QSpecScan.h:93
ScanResolution * clone() const override=0

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

Referenced by setAbsoluteQResolution(), and setRelativeQResolution().

Here is the call graph for this function:

◆ setRelativeQResolution() [1/2]

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

Definition at line 120 of file QSpecScan.cpp.

121 {
122  std::unique_ptr<ScanResolution> resolution(
124  setQResolution(*resolution);
125 }
void setQResolution(const ScanResolution &resolution)
Sets q resolution values via ScanResolution object.
Definition: QSpecScan.cpp:113
static ScanResolution * scanRelativeResolution(const RangedDistribution &distr, double stddev)

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

Referenced by StandardSimulations::TOFRWithRelativeResolution().

Here is the call graph for this function:

◆ setRelativeQResolution() [2/2]

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

Sets qz resolution values via RangedDistribution 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 127 of file QSpecScan.cpp.

129 {
130  std::unique_ptr<ScanResolution> resolution(
132  setQResolution(*resolution);
133 }

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

Here is the call graph for this function:

◆ setAbsoluteQResolution() [1/2]

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

Definition at line 135 of file QSpecScan.cpp.

136 {
137  std::unique_ptr<ScanResolution> resolution(
139  setQResolution(*resolution);
140 }
static ScanResolution * scanAbsoluteResolution(const RangedDistribution &distr, double stddev)

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

Referenced by StandardSimulations::TOFRWithPointwiseResolution().

Here is the call graph for this function:

◆ setAbsoluteQResolution() [2/2]

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

Sets qz resolution values via RangedDistribution 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 142 of file QSpecScan.cpp.

144 {
145  std::unique_ptr<ScanResolution> resolution(
147  setQResolution(*resolution);
148 }

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

Here is the call graph for this function:

◆ checkInitialization()

void QSpecScan::checkInitialization ( )
private

Definition at line 150 of file QSpecScan.cpp.

151 {
152  std::vector<double> axis_values = m_qs->getBinCenters();
153  if (!std::is_sorted(axis_values.begin(), axis_values.end()))
154  throw std::runtime_error("Error in QSpecScan::checkInitialization: q-vector values shall "
155  "be sorted in ascending order.");
156 
157  if (axis_values.front() < 0)
158  throw std::runtime_error("Error in QSpecScan::checkInitialization: q-vector values are out "
159  "of acceptable range.");
160 }

References m_qs.

Referenced by QSpecScan().

◆ generateQzVector()

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

Definition at line 162 of file QSpecScan.cpp.

163 {
164  const auto samples = applyQResolution();
165 
166  std::vector<double> result;
167  result.reserve(numberOfSimulationElements());
168  for (size_t i = 0, size_out = samples.size(); i < size_out; ++i)
169  for (size_t j = 0, size_in = samples[i].size(); j < size_in; ++j)
170  result.push_back(samples[i][j].value);
171  return result;
172 }

References applyQResolution(), and numberOfSimulationElements().

Referenced by generateSimulationElements().

Here is the call graph for this function:

◆ applyQResolution()

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

Definition at line 174 of file QSpecScan.cpp.

175 {
176  if (m_q_res_cache.empty())
177  m_q_res_cache = m_resolution->generateSamples(m_qs->getBinCenters());
178  return m_q_res_cache;
179 }

References m_q_res_cache, m_qs, and m_resolution.

Referenced by createIntensities(), and generateQzVector().

◆ 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_qs

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

◆ m_resolution

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

◆ m_q_res_cache

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

Definition at line 93 of file QSpecScan.h.

Referenced by applyQResolution(), and setQResolution().


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