BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Beam Class Reference

Description

An incident neutron or x-ray beam.

Definition at line 28 of file Beam.h.

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

Public Member Functions

 Beam (const Beam &other)
 
 Beam (double intensity, double wavelength, const Direction &direction)
 
 ~Beam () override
 
void checkNodeArgs () const
 Raises exception if a parameter value is invalid. More...
 
std::string className () const final
 Returns the class name, to be hard-coded in each leaf class that inherits from INode. More...
 
Beamclone () const
 
Direction direction () const
 
const IFootprintFactorfootprintFactor () const
 Returns footprint factor. More...
 
double intensity () const
 Returns the beam intensity in neutrons/sec. More...
 
std::vector< const INode * > nodeChildren () const override
 Returns all children. More...
 
std::vector< const INode * > nodeOffspring () const
 Returns all descendants. More...
 
Beamoperator= (const Beam &other)
 
virtual std::vector< ParaMetaparDefs () const
 Returns the parameter definitions, to be hard-coded in each leaf class. More...
 
SpinMatrix polMatrix () const
 Returns the polarization density matrix (in spin basis along z-axis) More...
 
R3 polVector () const
 Returns polarization density as Bloch vector. More...
 
void setAzimuthalAngleGuarded (double value)
 Check for limits, set the value if within limits. Throws if limits are violated. More...
 
void setDirection (const Direction &direction)
 
void setFootprintFactor (const IFootprintFactor &shape_factor)
 Sets footprint factor to the beam. More...
 
void setInclination (double alpha)
 
void setInclinationAngleGuarded (double value)
 Check for limits, set the value if within limits. Throws if limits are violated. More...
 
void setInclinationLimits (const RealLimits &limits)
 
void setIntensity (double intensity)
 Sets the beam intensity in neutrons/sec. More...
 
void setPolarization (R3 bloch_vector)
 Sets the polarization density matrix according to the given Bloch vector. More...
 
void setWavelength (double wavelength)
 
void setWavelengthGuarded (double value)
 Check for limits, set the value if within limits. Throws if limits are violated. More...
 
double wavelength () const
 

Static Public Member Functions

static Beam horizontalBeam ()
 

Protected Attributes

std::vector< double > m_P
 

Private Member Functions

 Beam ()
 

Private Attributes

double m_alpha
 
RealLimits m_alphaLimits
 
R3 m_beamPolarization
 Bloch vector encoding the beam's polarization. More...
 
double m_intensity
 beam intensity (neutrons/sec) More...
 
double m_phi
 
std::unique_ptr< IFootprintFactorm_shape_factor
 footprint correction handler More...
 
double m_wavelength
 

Friends

class DepthProbeSimulationTest
 

Constructor & Destructor Documentation

◆ Beam() [1/3]

Beam::Beam ( double  intensity,
double  wavelength,
const Direction direction 
)

Definition at line 33 of file Beam.cpp.

36  // , m_direction(direction)
38  , m_phi(direction.phi())
39  , m_alphaLimits(RealLimits::limited(-INCLINATION_LIMIT, INCLINATION_LIMIT))
40 {
42 
43  wavelengthLimits.check("Wavelength", m_wavelength);
44  m_alphaLimits.check("InclinationAngle", m_alpha);
45  phiLimits.check("AzimuthalAngle", m_phi);
46 }
double m_alpha
Definition: Beam.h:85
RealLimits m_alphaLimits
Definition: Beam.h:90
Direction direction() const
Definition: Beam.h:46
double m_wavelength
Definition: Beam.h:83
double m_phi
Definition: Beam.h:86
double intensity() const
Returns the beam intensity in neutrons/sec.
Definition: Beam.h:43
double wavelength() const
Definition: Beam.h:44
double m_intensity
beam intensity (neutrons/sec)
Definition: Beam.h:82
double phi() const
Definition: Direction.h:37
double alpha() const
Definition: Direction.h:36
void check(const std::string &name, double value) const
Throws if value is outside limits. Parameter 'name' is for exception message.
Definition: RealLimits.cpp:170
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:124
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:134

References RealLimits::check(), m_alpha, m_alphaLimits, m_intensity, m_phi, m_wavelength, and RealLimits::nonnegative().

Here is the call graph for this function:

◆ Beam() [2/3]

Beam::Beam ( const Beam other)

Definition at line 53 of file Beam.cpp.

54  : Beam(other.m_intensity, other.m_wavelength, other.direction())
55 {
57  if (other.m_shape_factor)
58  m_shape_factor.reset(other.m_shape_factor->clone());
59 }
R3 m_beamPolarization
Bloch vector encoding the beam's polarization.
Definition: Beam.h:88
std::unique_ptr< IFootprintFactor > m_shape_factor
footprint correction handler
Definition: Beam.h:87

References m_beamPolarization, and m_shape_factor.

◆ ~Beam()

Beam::~Beam ( )
overridedefault

◆ Beam() [3/3]

Beam::Beam ( )
private

Referenced by clone(), and horizontalBeam().

Member Function Documentation

◆ checkNodeArgs()

void INode::checkNodeArgs ( ) const
inherited

Raises exception if a parameter value is invalid.

Definition at line 27 of file INode.cpp.

28 {
29  size_t nP = m_P.size();
30  if (parDefs().size() != nP) {
31  std::cerr << "BUG in class " << className() << std::endl;
32  std::cerr << "#m_P = " << nP << std::endl;
33  std::cerr << "#PDf = " << parDefs().size() << std::endl;
34  for (const ParaMeta& pm : parDefs())
35  std::cerr << " PDf: " << pm.name << std::endl;
36  ASSERT(0);
37  }
38  ASSERT(parDefs().size() == nP);
39  for (size_t i = 0; i < nP; ++i) {
40  const ParaMeta pm = parDefs()[i];
41 
43  if (pm.vMin == -INF) {
44  ASSERT(pm.vMax == +INF);
45  // nothing to do
46  } else if (pm.vMax == +INF) {
47  ASSERT(pm.vMin == 0);
48  limits = RealLimits::nonnegative();
49  } else {
50  limits = RealLimits::limited(pm.vMin, pm.vMax);
51  }
52  limits.check(pm.name, m_P[i]);
53  }
54 }
#define ASSERT(condition)
Definition: Assert.h:45
const double INF
Definition: INode.h:26
virtual std::vector< ParaMeta > parDefs() const
Returns the parameter definitions, to be hard-coded in each leaf class.
Definition: INode.h:51
std::vector< double > m_P
Definition: INode.h:63
virtual std::string className() const =0
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Limits for a real fit parameter.
Definition: RealLimits.h:24
static RealLimits limitless()
Creates an object without bounds (default)
Definition: RealLimits.cpp:139
Metadata of one model parameter.
Definition: INode.h:29
double vMin
Definition: INode.h:33
double vMax
Definition: INode.h:34
std::string name
Definition: INode.h:30

References ASSERT, RealLimits::check(), INode::className(), INF, RealLimits::limited(), RealLimits::limitless(), INode::m_P, ParaMeta::name, RealLimits::nonnegative(), INode::parDefs(), ParaMeta::vMax, and ParaMeta::vMin.

Referenced by BarGauss::BarGauss(), BarLorentz::BarLorentz(), Bipyramid4::Bipyramid4(), Box::Box(), CantellatedCube::CantellatedCube(), Cone::Cone(), ConstantBackground::ConstantBackground(), CosineRippleBox::CosineRippleBox(), CosineRippleGauss::CosineRippleGauss(), CosineRippleLorentz::CosineRippleLorentz(), Cylinder::Cylinder(), DistributionCosine::DistributionCosine(), DistributionGate::DistributionGate(), DistributionGaussian::DistributionGaussian(), DistributionLogNormal::DistributionLogNormal(), DistributionLorentz::DistributionLorentz(), DistributionTrapezoid::DistributionTrapezoid(), Dodecahedron::Dodecahedron(), EllipsoidalCylinder::EllipsoidalCylinder(), FootprintGauss::FootprintGauss(), FootprintSquare::FootprintSquare(), FuzzySphere::FuzzySphere(), GaussSphere::GaussSphere(), HemiEllipsoid::HemiEllipsoid(), HollowSphere::HollowSphere(), HorizontalCylinder::HorizontalCylinder(), Icosahedron::Icosahedron(), LongBoxGauss::LongBoxGauss(), LongBoxLorentz::LongBoxLorentz(), PlatonicOctahedron::PlatonicOctahedron(), PlatonicTetrahedron::PlatonicTetrahedron(), Prism3::Prism3(), Prism6::Prism6(), Profile1DCauchy::Profile1DCauchy(), Profile1DCosine::Profile1DCosine(), Profile1DGate::Profile1DGate(), Profile1DGauss::Profile1DGauss(), Profile1DTriangle::Profile1DTriangle(), Profile1DVoigt::Profile1DVoigt(), Profile2DCauchy::Profile2DCauchy(), Profile2DCone::Profile2DCone(), Profile2DGate::Profile2DGate(), Profile2DGauss::Profile2DGauss(), Profile2DVoigt::Profile2DVoigt(), Pyramid2::Pyramid2(), Pyramid3::Pyramid3(), Pyramid4::Pyramid4(), Pyramid6::Pyramid6(), RotationEuler::RotationEuler(), RotationX::RotationX(), RotationY::RotationY(), RotationZ::RotationZ(), SawtoothRippleBox::SawtoothRippleBox(), SawtoothRippleGauss::SawtoothRippleGauss(), SawtoothRippleLorentz::SawtoothRippleLorentz(), Sphere::Sphere(), Spheroid::Spheroid(), TruncatedCube::TruncatedCube(), TruncatedSphere::TruncatedSphere(), and TruncatedSpheroid::TruncatedSpheroid().

Here is the call graph for this function:

◆ className()

std::string Beam::className ( ) const
inlinefinalvirtual

Returns the class name, to be hard-coded in each leaf class that inherits from INode.

Implements INode.

Definition at line 36 of file Beam.h.

36 { return "Beam"; }

◆ clone()

Beam * Beam::clone ( ) const

Definition at line 80 of file Beam.cpp.

81 {
82  return new Beam(*this);
83 }

References Beam().

Here is the call graph for this function:

◆ direction()

◆ footprintFactor()

const IFootprintFactor * Beam::footprintFactor ( ) const

Returns footprint factor.

Definition at line 112 of file Beam.cpp.

113 {
114  return m_shape_factor.get();
115 }

References m_shape_factor.

Referenced by DepthProbeSimulation::normalize().

◆ horizontalBeam()

Beam Beam::horizontalBeam ( )
static

Definition at line 48 of file Beam.cpp.

49 {
50  return Beam(1.0, 1.0, {0, 0});
51 }

References Beam().

Here is the call graph for this function:

◆ intensity()

double Beam::intensity ( ) const
inline

Returns the beam intensity in neutrons/sec.

Definition at line 43 of file Beam.h.

43 { return m_intensity; }

References m_intensity.

Referenced by DepthProbeSimulation::normalize(), ISimulation2D::normalize(), and setIntensity().

◆ nodeChildren()

std::vector< const INode * > Beam::nodeChildren ( ) const
overridevirtual

Returns all children.

Reimplemented from INode.

Definition at line 160 of file Beam.cpp.

161 {
162  if (m_shape_factor)
163  return {m_shape_factor.get()};
164  return {};
165 }

References m_shape_factor.

◆ nodeOffspring()

std::vector< const INode * > INode::nodeOffspring ( ) const
inherited

Returns all descendants.

Definition at line 61 of file INode.cpp.

62 {
63  std::vector<const INode*> result;
64  result.push_back(this);
65  for (const auto* child : nodeChildren()) {
66  for (const auto* p : child->nodeOffspring())
67  result.push_back(p);
68  }
69  return result;
70 }
virtual std::vector< const INode * > nodeChildren() const
Returns all children.
Definition: INode.cpp:56

References INode::nodeChildren().

Here is the call graph for this function:

◆ operator=()

Beam & Beam::operator= ( const Beam other)

Definition at line 61 of file Beam.cpp.

62 {
63  if (&other == this)
64  return *this;
65  m_intensity = other.m_intensity;
66  m_wavelength = other.m_wavelength;
67  // m_direction = other.m_direction;
68  m_alpha = other.m_alpha;
69  m_phi = other.m_phi;
71  if (other.m_shape_factor)
72  m_shape_factor.reset(other.m_shape_factor->clone());
73  else
74  m_shape_factor.release();
75  return *this;
76 }

References m_alpha, m_beamPolarization, m_intensity, m_phi, m_shape_factor, and m_wavelength.

◆ parDefs()

virtual std::vector<ParaMeta> INode::parDefs ( ) const
inlinevirtualinherited

Returns the parameter definitions, to be hard-coded in each leaf class.

Reimplemented in ConstantBackground, GaussSphere, FuzzySphere, RotationEuler, RotationZ, RotationY, RotationX, Crystal, Layer, HexagonalLattice2D, SquareLattice2D, BasicLattice2D, LayerRoughness, TruncatedSpheroid, TruncatedSphere, TruncatedCube, Spheroid, Sphere, SawtoothRippleLorentz, SawtoothRippleGauss, SawtoothRippleBox, Pyramid6, Pyramid4, Pyramid3, Pyramid2, Prism6, Prism3, PlatonicTetrahedron, PlatonicOctahedron, LongBoxLorentz, LongBoxGauss, Icosahedron, HorizontalCylinder, HollowSphere, HemiEllipsoid, EllipsoidalCylinder, Dodecahedron, Cylinder, CosineRippleLorentz, CosineRippleGauss, CosineRippleBox, Cone, CantellatedCube, Box, Bipyramid4, BarLorentz, BarGauss, Profile2DVoigt, Profile2DCone, Profile2DGate, Profile2DGauss, Profile2DCauchy, Profile1DVoigt, Profile1DCosine, Profile1DTriangle, Profile1DGate, Profile1DGauss, Profile1DCauchy, MisesGaussPeakShape, MisesFisherGaussPeakShape, LorentzFisherPeakShape, GaussFisherPeakShape, IsotropicLorentzPeakShape, IsotropicGaussPeakShape, ParticleLayout, InterferenceTwin, InterferenceRadialParaCrystal, InterferenceHardDisk, Interference2DSuperLattice, Interference2DParaCrystal, Interference1DLattice, DistributionTrapezoid, DistributionCosine, DistributionLogNormal, DistributionGaussian, DistributionLorentz, DistributionGate, ResolutionFunction2DGaussian, PolFilter, FootprintSquare, and FootprintGauss.

Definition at line 51 of file INode.h.

51 { return {}; }

Referenced by INode::checkNodeArgs(), and IFormFactor::pythonConstructor().

◆ polMatrix()

SpinMatrix Beam::polMatrix ( ) const

Returns the polarization density matrix (in spin basis along z-axis)

Definition at line 155 of file Beam.cpp.

156 {
158 }
static SpinMatrix FromBlochVector(const R3 &v)
Constructs matrix (I+v*s)/2, where s is the Pauli vector.
Definition: SpinMatrix.cpp:41

References SpinMatrix::FromBlochVector(), and m_beamPolarization.

Referenced by ISimulation2D::generateElements().

Here is the call graph for this function:

◆ polVector()

R3 Beam::polVector ( ) const

Returns polarization density as Bloch vector.

Definition at line 150 of file Beam.cpp.

151 {
152  return m_beamPolarization;
153 }

References m_beamPolarization.

◆ setAzimuthalAngleGuarded()

void Beam::setAzimuthalAngleGuarded ( double  value)

Check for limits, set the value if within limits. Throws if limits are violated.

Definition at line 123 of file Beam.cpp.

124 {
125  phiLimits.check("azimuthal angle", value);
126  m_phi = value;
127 }

References m_phi.

Referenced by ISimulation2D::initDistributionHandler().

◆ setDirection()

void Beam::setDirection ( const Direction direction)

Definition at line 92 of file Beam.cpp.

93 {
94  if (direction.alpha() < 0.0)
95  throw std::runtime_error(
96  "Invalid beam parameter: Inclination angle alpha_i can't be negative.");
97  // m_direction = direction;
99  m_phi = direction.phi();
100 }

References Direction::alpha(), direction(), m_alpha, m_phi, and Direction::phi().

Referenced by DepthProbeSimulation::setBeamParameters(), and OffspecSimulation::setBeamParameters().

Here is the call graph for this function:

◆ setFootprintFactor()

void Beam::setFootprintFactor ( const IFootprintFactor shape_factor)

Sets footprint factor to the beam.

Definition at line 135 of file Beam.cpp.

136 {
137  m_shape_factor.reset(shape_factor.clone());
138 }
IFootprintFactor * clone() const override=0

References IFootprintFactor::clone(), and m_shape_factor.

Referenced by DepthProbeSimulation::setBeamParameters().

Here is the call graph for this function:

◆ setInclination()

void Beam::setInclination ( double  alpha)

Definition at line 102 of file Beam.cpp.

103 {
104  m_alpha = alpha;
105 }

References m_alpha.

Referenced by OffspecSimulation::initElementVector().

◆ setInclinationAngleGuarded()

void Beam::setInclinationAngleGuarded ( double  value)

Check for limits, set the value if within limits. Throws if limits are violated.

Definition at line 117 of file Beam.cpp.

118 {
119  m_alphaLimits.check("inclination angle", value);
120  m_alpha = value;
121 }

References RealLimits::check(), m_alpha, and m_alphaLimits.

Referenced by ISimulation2D::initDistributionHandler().

Here is the call graph for this function:

◆ setInclinationLimits()

void Beam::setInclinationLimits ( const RealLimits limits)

Definition at line 107 of file Beam.cpp.

108 {
109  m_alphaLimits = limits;
110 }

References m_alphaLimits.

Referenced by DepthProbeSimulation::DepthProbeSimulation().

◆ setIntensity()

void Beam::setIntensity ( double  intensity)
inline

Sets the beam intensity in neutrons/sec.

Definition at line 74 of file Beam.h.

References intensity(), and m_intensity.

Here is the call graph for this function:

◆ setPolarization()

void Beam::setPolarization ( R3  bloch_vector)

Sets the polarization density matrix according to the given Bloch vector.

Definition at line 140 of file Beam.cpp.

141 {
142  if (bloch_vector.mag() > 1.0) {
143  throw std::runtime_error(
144  "Beam::setPolarization: "
145  "The given Bloch vector cannot represent a real physical ensemble");
146  }
147  m_beamPolarization = bloch_vector;
148 }

References m_beamPolarization.

◆ setWavelength()

void Beam::setWavelength ( double  wavelength)

Definition at line 85 of file Beam.cpp.

86 {
87  if (wavelength <= 0.0)
88  throw std::runtime_error("Invalid beam parameter: Wavelength can't be negative or zero.");
90 }

References m_wavelength, and wavelength().

Referenced by DepthProbeSimulation::setBeamParameters(), and OffspecSimulation::setBeamParameters().

Here is the call graph for this function:

◆ setWavelengthGuarded()

void Beam::setWavelengthGuarded ( double  value)

Check for limits, set the value if within limits. Throws if limits are violated.

Definition at line 129 of file Beam.cpp.

130 {
131  wavelengthLimits.check("wavelength", value);
132  m_wavelength = value;
133 }

References m_wavelength.

Referenced by ISimulation2D::initDistributionHandler().

◆ wavelength()

Friends And Related Function Documentation

◆ DepthProbeSimulationTest

friend class DepthProbeSimulationTest
friend

Definition at line 92 of file Beam.h.

Member Data Documentation

◆ m_alpha

double Beam::m_alpha
private

◆ m_alphaLimits

RealLimits Beam::m_alphaLimits
private

Definition at line 90 of file Beam.h.

Referenced by Beam(), setInclinationAngleGuarded(), and setInclinationLimits().

◆ m_beamPolarization

R3 Beam::m_beamPolarization
private

Bloch vector encoding the beam's polarization.

Definition at line 88 of file Beam.h.

Referenced by Beam(), operator=(), polMatrix(), polVector(), and setPolarization().

◆ m_intensity

double Beam::m_intensity
private

beam intensity (neutrons/sec)

Definition at line 82 of file Beam.h.

Referenced by Beam(), intensity(), operator=(), and setIntensity().

◆ m_P

◆ m_phi

double Beam::m_phi
private

Definition at line 86 of file Beam.h.

Referenced by Beam(), direction(), operator=(), setAzimuthalAngleGuarded(), and setDirection().

◆ m_shape_factor

std::unique_ptr<IFootprintFactor> Beam::m_shape_factor
private

footprint correction handler

Definition at line 87 of file Beam.h.

Referenced by Beam(), footprintFactor(), nodeChildren(), operator=(), and setFootprintFactor().

◆ m_wavelength

double Beam::m_wavelength
private

Definition at line 83 of file Beam.h.

Referenced by Beam(), operator=(), setWavelength(), setWavelengthGuarded(), and wavelength().


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