File: BeamScan.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (137 lines) | stat: -rw-r--r-- 3,807 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sim/Scan/BeamScan.cpp
//! @brief     Implements interface BeamScan.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "Sim/Scan/BeamScan.h"
#include "Base/Axis/Frame.h"
#include "Base/Axis/Scale.h"
#include "Base/Math/Numeric.h"
#include "Base/Spin/SpinMatrix.h"
#include "Base/Util/Assert.h"
#include "Device/Beam/Beam.h"
#include "Device/Pol/PolFilter.h"
#include "Param/Distrib/Distributions.h"
#include "Param/Distrib/ParameterSample.h"
#include "Resample/Slice/KzComputation.h"

BeamScan::BeamScan(const Scale& axis)
    : m_axis(axis.clone())
{
}

BeamScan::~BeamScan() = default;

void BeamScan::copyBeamScan(BeamScan* dest) const
{
    dest->m_beams = m_beams; // TODO cleanup: here we are overwriting what was set in the c'tor
    if (m_pol_analyzer)
        dest->setAnalyzer(m_pol_analyzer->BlochVector(), m_pol_analyzer->transmission());
}

std::vector<const INode*> BeamScan::nodeChildren() const
{
    std::vector<const INode*> result;
    if (m_pol_analyzer)
        result << m_pol_analyzer.get();
    return result;
}

void BeamScan::setAnalyzer(const R3& Bloch_vector, double mean_transmission)
{
    m_pol_analyzer = std::make_unique<PolFilter>(Bloch_vector, mean_transmission);
}

size_t BeamScan::nScan() const
{
    return m_axis->size();
}

double BeamScan::commonIntensity() const
{
    if (!isCommonIntensity())
        throw std::runtime_error("Intensity changes during scan. "
                                 "Use 'intensityAt(i)' instead.");
    return m_beams.front()->intensity();
}

void BeamScan::setIntensity(double intensity)
{
    for (auto& b : m_beams)
        b->setIntensity(intensity);
}

double BeamScan::intensityAt(size_t i) const
{
    return m_beams[i]->intensity();
}

const R3& BeamScan::commonPolarization() const
{
    if (!isCommonPolarization())
        throw std::runtime_error("Polarization changes during scan. "
                                 "Use 'polarizationAt(i)' instead.");
    return m_beams.front()->polVector();
}

R3 BeamScan::polarizationAt(size_t i) const
{
    return m_beams[i]->polVector();
}

void BeamScan::setPolarization(const R3& bloch_vector)
{
    for (auto& b : m_beams)
        b->setPolarization(bloch_vector);
}

SpinMatrix BeamScan::polarizerMatrixAt(size_t i) const
{
    return m_beams[i]->polMatrix();
}

SpinMatrix BeamScan::analyzerMatrix() const
{
    return m_pol_analyzer ? m_pol_analyzer->matrix() : SpinMatrix::One();
}

std::vector<complex_t> BeamScan::produceKz(const SliceStack& slices, const R3& k) const
{
    return Compute::Kz::computeKzFromRefIndices(slices, k);
}

bool BeamScan::isCommonIntensity() const
{
    const auto ref = m_beams.front()->intensity();
    for (const auto& b : m_beams)
        if (!Numeric::almostEqual(b->intensity(), ref, 1))
            return false;
    return true;
}

bool BeamScan::isCommonPolarization() const
{
    const auto ref = m_beams.front()->polVector();
    for (const auto& b : m_beams)
        if (!Numeric::almostEqual(b->polVector(), ref, 1))
            return false;
    return true;
}

std::vector<ParameterSample> BeamScan::drawDistribution(IDistribution1D* distrib,
                                                        double point) const
{
    if (!distrib)
        return {{point, 1}};
    distrib->setMean(point);
    return distrib->distributionSamples();
}