BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FootprintSquare.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Beam/FootprintSquare.cpp
6 //! @brief Implements class FootprintSquare.
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 
17 #include "Base/Utils/PyFmt.h"
18 #include <algorithm>
19 #include <stdexcept>
20 
21 FootprintSquare::FootprintSquare(const std::vector<double> P)
22  : IFootprintFactor({"FootprintSquare", "class_tooltip", {}}, P)
23 {
24 }
25 
27  : FootprintSquare(std::vector<double>{width_ratio})
28 {
29 }
30 
32 {
33  return new FootprintSquare(m_width_ratio);
34 }
35 
36 double FootprintSquare::calculate(double alpha) const
37 {
38  if (alpha < 0.0 || alpha > M_PI_2)
39  return 0.0;
40  if (widthRatio() == 0.0)
41  return 1.0;
42  const double arg = std::sin(alpha) / widthRatio();
43  return std::min(arg, 1.0);
44 }
45 
46 std::string FootprintSquare::print() const
47 {
48  std::stringstream result;
49  result << "\n" << pyfmt::indent() << "# Defining footprint:\n";
50  result << pyfmt::indent() << "footprint = ";
51  result << "ba.FootprintSquare";
52  result << "(" << pyfmt::printDouble(widthRatio()) << ")";
53  return result.str();
54 }
55 
56 static_assert(!std::is_copy_constructible<FootprintSquare>::value,
57  "FootprintSquare should not be copy constructable");
58 static_assert(!std::is_copy_assignable<FootprintSquare>::value,
59  "FootprintSquare should not be copy assignable");
Defines class FootprintSquare.
Defines M_PI and some more mathematical constants.
#define M_PI_2
Definition: MathConstants.h:40
Defines functions in namespace pyfmt.
Calculates footprint coefficient for a square beam.
FootprintSquare * clone() const override
double calculate(double alpha) const override
Calculate footprint correction coefficient from the beam incident angle alpha.
FootprintSquare(const std::vector< double > P)
std::string print() const override
Print python-formatted footprint definition.
Abstract base for classes that calculate the beam footprint factor.
double widthRatio() const
const double & m_width_ratio
std::string printDouble(double input)
Definition: PyFmt.cpp:43
std::string indent(size_t width)
Returns a string of blanks with given width.
Definition: PyFmt.cpp:141