BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IInterferenceFunctionStrategy.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Interference/IInterferenceFunctionStrategy.cpp
6 //! @brief Implements default behaviour of IInterferenceFunctionStrategy.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
18 #include "Base/Utils/Assert.h"
20 
22  const std::vector<FormFactorCoherentSum>& weighted_formfactors,
23  const SimulationOptions& sim_params, bool polarized)
24  : m_weighted_formfactors(weighted_formfactors)
25  , m_options(sim_params)
26  , m_polarized(polarized)
27  , m_integrator(
28  make_integrator_miser(this, &IInterferenceFunctionStrategy::evaluate_for_fixed_angles, 2))
29 {
31 }
32 
34 
36 {
37  if (m_options.isIntegrate() && (sim_element.solidAngle() > 0.0))
38  return MCIntegratedEvaluate(sim_element);
39  return evaluateSinglePoint(sim_element);
40 }
41 
42 double
44 {
45  if (!m_polarized)
46  return scalarCalculation(sim_element);
47  return polarizedCalculation(sim_element);
48 }
49 
50 //! Performs a Monte Carlo integration over the bin for the evaluation of the intensity.
51 double
53 {
54  double min_array[] = {0.0, 0.0};
55  double max_array[] = {1.0, 1.0};
56  return m_integrator->integrate(min_array, max_array, (void*)&sim_element,
58 }
59 
61  void* params) const
62 {
63  double par0 = fractions[0];
64  double par1 = fractions[1];
65 
66  SimulationElement* pars = static_cast<SimulationElement*>(params);
67 
68  SimulationElement sim_element = pars->pointElement(par0, par1);
69  return pars->integrationFactor(par0, par1) * evaluateSinglePoint(sim_element);
70 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:31
Defines class FormFactorCoherentSum.
Defines interface IInterferenceFunctionStrategy.
Defines and implements template class IntegratorMCMiser.
Defines class SimulationElement.
Base class of all interference function strategy classes.
std::unique_ptr< IntegratorMCMiser< IInterferenceFunctionStrategy > > m_integrator
double evaluate_for_fixed_angles(double *fractions, size_t dim, void *params) const
IInterferenceFunctionStrategy(const std::vector< FormFactorCoherentSum > &weighted_formfactors, const SimulationOptions &sim_params, bool polarized)
virtual double scalarCalculation(const SimulationElement &sim_element) const =0
Evaluates the intensity in the scalar case.
double evaluate(const SimulationElement &sim_element) const
Calculates the intensity for scalar particles/interactions.
double evaluateSinglePoint(const SimulationElement &sim_element) const
double MCIntegratedEvaluate(const SimulationElement &sim_element) const
Performs a Monte Carlo integration over the bin for the evaluation of the intensity.
virtual double polarizedCalculation(const SimulationElement &sim_element) const =0
Evaluates the intensity in the polarized case.
std::vector< FormFactorCoherentSum > m_weighted_formfactors
Data stucture containing both input and output of a single detector cell.
double solidAngle() const
SimulationElement pointElement(double x, double y) const
Returns copy of this SimulationElement with k_f given by in-pixel coordinate x,y.
double integrationFactor(double x, double y) const
Collect the different options for simulation.
size_t getMcPoints() const
bool isIntegrate() const
P_integrator_miser< T > make_integrator_miser(const T *object, miser_integrand< T > mem_function, size_t dim)
Template function to create an integrator object.
matrixFFVector_t polarized(const SimulationElement &sim_element, const std::vector< FormFactorCoherentSum > &ff_wrappers)