Skip to content
Snippets Groups Projects
DepthprobeSimulation.h 3.72 KiB
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sim/Simulation/DepthprobeSimulation.h
//! @brief     Defines class DepthprobeSimulation
//!
//! @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)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_SIM_SIMULATION_DEPTHPROBESIMULATION_H
#define BORNAGAIN_SIM_SIMULATION_DEPTHPROBESIMULATION_H

#include "Sim/Simulation/ISimulation.h"
#include <valarray>

class Beam;
class DepthprobeElement;
class IAxis;
class IFootprintFactor;

//! Simulation of radiation depth profile.
//!
//! Holds an instrument and sample model.
//! Computes radiation intensity as function of incoming glancing angle and penetration depth.
//! Scattered rays are neglected.
//! Only refraction, reflection and attenuation of the incoming beam are accounted for.
//! @ingroup simulation

class DepthprobeSimulation : public ISimulation {
public:
    DepthprobeSimulation(const MultiLayer& sample);
    ~DepthprobeSimulation() override;

    std::string className() const final { return "DepthprobeSimulation"; }

    //! Sets beam parameters with alpha_i of the beam defined in the range.
    void setBeamParameters(double lambda, int nbins, double alpha_i_min, double alpha_i_max,
                           const IFootprintFactor* beam_shape = nullptr);

    //! Set z positions for intensity calculations. Negative z's correspond to the area
    //! under sample surface. The more negative z is, the deeper layer corresponds to it.
    void setzSpan(size_t n_bins, double z_min, double z_max);

    Beam& beam() { return *m_beam; }

#ifndef SWIG

    const Beam& beam() const
    {
        return *m_beam;
    }

    const ICoordSystem* simCoordSystem() const override;

    std::vector<const INode*> nodeChildren() const override;

private:
    //... Overridden executors:
    void initDistributionHandler() override;

    void prepareSimulation() override {}

    void initElementVector() override;

    //! Generates a single threaded computation for a given range of simulation elements
    std::unique_ptr<IComputation> createComputation(const ReSample& re_sample, size_t start,
                                                    size_t n_elements) override;

    //! Normalizes the detector counts to beam intensity, to solid angle, and to exposure angle.
    void normalize(size_t start, size_t n_elements) override;

    void addBackgroundIntensity(size_t start, size_t n_elements) override;

    void addDataToCache(double weight) override;

    //... Overridden getters:
    bool force_polarized() const override
    {
        return false;
    }

    //! Returns the number of elements this simulation needs to calculate
    size_t numberOfElements() const override;

    SimulationResult packResult() override;

    //! Checks the distribution validity for simulation.
    void validateParametrization(const ParameterDistribution& par_distr) const override;

    //... Local functions:
    //! Returns a pointer to incident angle axis.
    const IAxis* alphaAxis() const;

    //! Returns a pointer to z-position axis.
    const IAxis* zAxis() const;

    //... Model components:
    std::shared_ptr<Beam> m_beam;

    //... Caches:
    std::unique_ptr<IAxis> m_alpha_axis;
    std::unique_ptr<IAxis> m_z_axis;
    std::vector<std::valarray<double>> m_cache;
    std::vector<DepthprobeElement> m_depth_eles;
#endif // SWIG
};

#endif // BORNAGAIN_SIM_SIMULATION_DEPTHPROBESIMULATION_H