Skip to content
Snippets Groups Projects
Commit 9fe7f52f authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

common polarization

parent 0245401d
No related branches found
No related tags found
1 merge request!1908BeamScan now contains vector of Beams
......@@ -40,3 +40,9 @@ bool Numeric::almostEqual(double a, double b, int ulp)
constexpr double eps = std::numeric_limits<double>::epsilon();
return std::abs(a - b) <= eps * ulp * (std::abs(a) + std::abs(b)) / 2;
}
bool Numeric::almostEqual(const R3& a, const R3& b, int ulp)
{
return almostEqual(a.x(), b.x(), ulp) && almostEqual(a.y(), b.y(), ulp)
&& almostEqual(a.z(), b.z(), ulp);
}
......@@ -15,6 +15,8 @@
#ifndef BORNAGAIN_BASE_MATH_NUMERIC_H
#define BORNAGAIN_BASE_MATH_NUMERIC_H
#include <heinz/Vectors3D.h>
void check_scalar(double a, double b, int ulp);
#ifndef SWIG
......@@ -28,6 +30,8 @@ double relativeDifference(double a, double b);
//! Returns true if two doubles agree within machine epsilon times ulp (units in the last place).
bool almostEqual(double a, double b, int ulp);
bool almostEqual(const R3& a, const R3& b, int ulp);
} // namespace Numeric
......
......@@ -100,7 +100,7 @@ std::vector<const Beam*> BeamScan::scanPoints() const
bool BeamScan::isCommonIntensity() const
{
double ref = m_scanPoints.front().intensity();
const auto ref = m_scanPoints.front().intensity();
for (const auto& b : m_scanPoints)
if (!Numeric::almostEqual(b.intensity(), ref, 1))
return false;
......@@ -119,6 +119,27 @@ void BeamScan::setCommonIntensity(double val)
b.setIntensity(val);
}
bool BeamScan::isCommonPolarization() const
{
const auto ref = m_scanPoints.front().polVector();
for (const auto& b : m_scanPoints)
if (!Numeric::almostEqual(b.polVector(), ref, 1))
return false;
return true;
}
R3 BeamScan::commonPolarization() const
{
ASSERT(isCommonPolarization());
return m_scanPoints.front().polVector();
}
void BeamScan::setCommonPolarization(const R3& pol)
{
for (auto& b : m_scanPoints)
b.setPolarization(pol);
}
SpinMatrix BeamScan::polarizerMatrix() const
{
return m_beamPolarization ? SpinMatrix::FromBlochVector(*m_beamPolarization)
......
......@@ -107,6 +107,10 @@ public:
double commonIntensity() const;
void setCommonIntensity(double val);
bool isCommonPolarization() const;
R3 commonPolarization() const;
void setCommonPolarization(const R3& pol);
protected:
const std::unique_ptr<const Scale> m_axis;
double m_intensity = 1; //!< Fudge factor to adjust for imperfect normalization of exp. data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment