File: OffspecDetector.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 (101 lines) | stat: -rw-r--r-- 3,209 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
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Device/Detector/OffspecDetector.cpp
//! @brief     Implements class OffspecDetector.
//!
//! @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 "Device/Detector/OffspecDetector.h"
#include "Base/Axis/MakeScale.h"
#include "Base/Axis/Pixel.h"
#include "Base/Util/Assert.h"
#include <iostream>

namespace {

const CloneableVector<const Scale> detEquiFrame(size_t n_phi, double phi_min, double phi_max,
                                                size_t n_alpha, double alpha_min, double alpha_max)
{
    if (phi_min >= phi_max)
        throw std::runtime_error("Detector phi: min >= max");
    if (alpha_min >= alpha_max)
        throw std::runtime_error("Detector alpha: min >= max");

    return CloneableVector<const Scale>(
        {newEquiDivision("phi_f (rad)", n_phi, phi_min, phi_max),
         newEquiDivision("alpha_f (rad)", n_alpha, alpha_min, alpha_max)});
}

} // namespace

OffspecDetector::OffspecDetector(size_t n_phi, double phi_min, double phi_max, size_t n_alpha,
                                 double alpha_min, double alpha_max)
    : m_axes(::detEquiFrame(n_phi, phi_min, phi_max, n_alpha, alpha_min, alpha_max))
{
}

OffspecDetector::OffspecDetector(const OffspecDetector& other) = default;

OffspecDetector* OffspecDetector::clone() const
{
    return new OffspecDetector(*this);
}

void OffspecDetector::setAnalyzer(const R3& Bloch_vector, double mean_transmission)
{
    m_pol_analyzer = PolFilter(Bloch_vector, mean_transmission);
}

const Scale& OffspecDetector::axis(size_t index) const
{
    ASSERT(index < 2);
    return *m_axes[index];
}

size_t OffspecDetector::axisBinIndex(size_t i, size_t k_axis) const
{
    if (k_axis == 0)
        return i % m_axes[0]->size();
    else if (k_axis == 1)
        return i / m_axes[0]->size();
    ASSERT_NEVER;
}

size_t OffspecDetector::totalSize() const
{
    return m_axes[0]->size() * m_axes[1]->size();
}

Pixel* OffspecDetector::createPixel(size_t index) const
{
    const Scale& phi_axis = axis(0);
    const Scale& alpha_axis = axis(1);
    const size_t phi_index = axisBinIndex(index, 0);
    const size_t alpha_index = axisBinIndex(index, 1);

    const Bin1D alpha_bin = alpha_axis.bin(alpha_index);
    const Bin1D phi_bin = phi_axis.bin(phi_index);

    return new Pixel(phi_bin, alpha_bin);
}

size_t OffspecDetector::indexOfSpecular(double alpha, double phi) const
{
    const Scale& phi_axis = axis(0);
    const Scale& alpha_axis = axis(1);
    if (phi_axis.rangeComprises(phi) && alpha_axis.rangeComprises(alpha))
        return getGlobalIndex(phi_axis.closestIndex(phi), alpha_axis.closestIndex(alpha));
    return totalSize();
}

size_t OffspecDetector::getGlobalIndex(size_t x, size_t y) const
{
    return y * axis(0).size() + x;
}