diff --git a/Core/PythonAPI/inc/Histogram1D.pypp.h b/Core/PythonAPI/inc/Histogram1D.pypp.h new file mode 100644 index 0000000000000000000000000000000000000000..ffbc87f72badd39617aebc8409121fc676baf961 --- /dev/null +++ b/Core/PythonAPI/inc/Histogram1D.pypp.h @@ -0,0 +1,23 @@ +// This file has been generated by Py++. + +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Automatically generated boost::python code for BornAgain Python bindings +//! @brief Automatically generated boost::python code for BornAgain Python bindings +//! +//! @homepage http://bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Juelich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef Histogram1D_hpp__pyplusplus_wrapper +#define Histogram1D_hpp__pyplusplus_wrapper + +void register_Histogram1D_class(); + +#endif//Histogram1D_hpp__pyplusplus_wrapper diff --git a/Core/PythonAPI/inc/IHistogram.pypp.h b/Core/PythonAPI/inc/IHistogram.pypp.h new file mode 100644 index 0000000000000000000000000000000000000000..9e0d874aa14185cae5e957891e96798c103ab715 --- /dev/null +++ b/Core/PythonAPI/inc/IHistogram.pypp.h @@ -0,0 +1,23 @@ +// This file has been generated by Py++. + +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Automatically generated boost::python code for BornAgain Python bindings +//! @brief Automatically generated boost::python code for BornAgain Python bindings +//! +//! @homepage http://bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Juelich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef IHistogram_hpp__pyplusplus_wrapper +#define IHistogram_hpp__pyplusplus_wrapper + +void register_IHistogram_class(); + +#endif//IHistogram_hpp__pyplusplus_wrapper diff --git a/Core/PythonAPI/inc/PythonCoreList.h b/Core/PythonAPI/inc/PythonCoreList.h index 31a309ae013aebd3f44514b6c0f07da93ce41024..a5ed18b79691a00a33039cd4f26dd581d9941be2 100644 --- a/Core/PythonAPI/inc/PythonCoreList.h +++ b/Core/PythonAPI/inc/PythonCoreList.h @@ -103,6 +103,8 @@ #include "Units.h" #include "BAVersion.h" #include "MessageService.h" +#include "IHistogram.h" +#include "Histogram1D.h" //! file containig additional exposers #include "PythonCoreExposer.h" diff --git a/Core/PythonAPI/src/Histogram1D.pypp.cpp b/Core/PythonAPI/src/Histogram1D.pypp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..56cd627b2056e99794090a8cbfeccb7f1ffd1c3f --- /dev/null +++ b/Core/PythonAPI/src/Histogram1D.pypp.cpp @@ -0,0 +1,78 @@ +// This file has been generated by Py++. + +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Automatically generated boost::python code for BornAgain Python bindings +//! @brief Automatically generated boost::python code for BornAgain Python bindings +//! +//! @homepage http://bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Juelich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "Macros.h" +GCC_DIAG_OFF(unused-parameter) +GCC_DIAG_OFF(missing-field-initializers) +#include "boost/python.hpp" +GCC_DIAG_ON(unused-parameter) +GCC_DIAG_ON(missing-field-initializers) +#include "PythonCoreList.h" +#include "Histogram1D.pypp.h" + +namespace bp = boost::python; + +void register_Histogram1D_class(){ + + { //::Histogram1D + typedef bp::class_< Histogram1D, bp::bases< IHistogram >, boost::noncopyable > Histogram1D_exposer_t; + Histogram1D_exposer_t Histogram1D_exposer = Histogram1D_exposer_t( "Histogram1D", bp::init< int, double, double >(( bp::arg("nbinsx"), bp::arg("xlow"), bp::arg("xup") ), "Constructor for fix bin size histograms. @param nbinsx number of bins @param xlow low edge of the first bin @param xup upper edge of the last bin \n\n:Parameters:\n - 'nbinsx' - number of bins\n - 'xlow' - low edge of the first bin\n - 'xup' - upper edge of the last bin\n") ); + bp::scope Histogram1D_scope( Histogram1D_exposer ); + Histogram1D_exposer.def( bp::init< int, std::vector< double > const & >(( bp::arg("nbinsx"), bp::arg("xbins") ), "Constructor for variable bin size histograms. @param nbinsx number of bins @param xbins Array of size nbins+1 containing low-edges for each bin and upper edge of last bin. \n\n:Parameters:\n - 'nbinsx' - number of bins\n - 'xbins' - Array of size nbins+1 containing low-edges for each\n") ); + { //::Histogram1D::fill + + typedef int ( ::Histogram1D::*fill_function_type)( double,double ) ; + + Histogram1D_exposer.def( + "fill" + , fill_function_type( &::Histogram1D::fill ) + , ( bp::arg("x"), bp::arg("weight")=1.0e+0 ) + , "Increment bin with abscissa x with a weight." ); + + } + { //::Histogram1D::getBinCenters + + typedef ::std::vector< double > ( ::Histogram1D::*getBinCenters_function_type)( ) const; + + Histogram1D_exposer.def( + "getBinCenters" + , getBinCenters_function_type( &::Histogram1D::getBinCenters ) ); + + } + { //::Histogram1D::getBinValues + + typedef ::std::vector< double > ( ::Histogram1D::*getBinValues_function_type)( ) const; + + Histogram1D_exposer.def( + "getBinValues" + , getBinValues_function_type( &::Histogram1D::getBinValues ) ); + + } + { //::Histogram1D::getXaxis + + typedef ::IAxis const * ( ::Histogram1D::*getXaxis_function_type)( ) const; + + Histogram1D_exposer.def( + "getXaxis" + , getXaxis_function_type( &::Histogram1D::getXaxis ) + , bp::return_value_policy< bp::reference_existing_object >() + , "Increment bin with abscissa x with a weight." ); + + } + } + +} diff --git a/Core/PythonAPI/src/IHistogram.pypp.cpp b/Core/PythonAPI/src/IHistogram.pypp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..711fe26fbb1c617a73df4f9d126604e8a2588ed5 --- /dev/null +++ b/Core/PythonAPI/src/IHistogram.pypp.cpp @@ -0,0 +1,39 @@ +// This file has been generated by Py++. + +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Automatically generated boost::python code for BornAgain Python bindings +//! @brief Automatically generated boost::python code for BornAgain Python bindings +//! +//! @homepage http://bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Juelich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "Macros.h" +GCC_DIAG_OFF(unused-parameter) +GCC_DIAG_OFF(missing-field-initializers) +#include "boost/python.hpp" +GCC_DIAG_ON(unused-parameter) +GCC_DIAG_ON(missing-field-initializers) +#include "PythonCoreList.h" +#include "IHistogram.pypp.h" + +namespace bp = boost::python; + +void register_IHistogram_class(){ + + { //::IHistogram + typedef bp::class_< IHistogram, boost::noncopyable > IHistogram_exposer_t; + IHistogram_exposer_t IHistogram_exposer = IHistogram_exposer_t( "IHistogram", "Base class for 1D and 2D histogram.", bp::init< >() ); + bp::scope IHistogram_scope( IHistogram_exposer ); + IHistogram_exposer.def( bp::init< IAxis const & >(( bp::arg("axis_x") )) ); + IHistogram_exposer.def( bp::init< IAxis const &, IAxis const & >(( bp::arg("axis_x"), bp::arg("axis_y") )) ); + } + +} diff --git a/Core/PythonAPI/src/PythonModule.cpp b/Core/PythonAPI/src/PythonModule.cpp index ac9d6554c8605b7b38e5b0e8f1d6d75e6bf2125b..a5115352d04b870156131bd67ea5163a4d7c2a11 100644 --- a/Core/PythonAPI/src/PythonModule.cpp +++ b/Core/PythonAPI/src/PythonModule.cpp @@ -10,138 +10,140 @@ GCC_DIAG_ON(missing-field-initializers) #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define PY_ARRAY_UNIQUE_SYMBOL BORNAGAIN_PYTHONAPI_ARRAY #include "numpy/arrayobject.h" -#include "FormFactorFullSpheroid.pypp.h" -#include "DistributionGate.pypp.h" -#include "SimpleSelectionRule.pypp.h" -#include "RealParameterWrapper.pypp.h" -#include "vdouble1d_t.pypp.h" -#include "SimulationParameters.pypp.h" -#include "ThreadInfo.pypp.h" -#include "InterferenceFunction2DLattice.pypp.h" -#include "LayerInterface.pypp.h" #include "ILayout.pypp.h" -#include "FormFactorCone6.pypp.h" -#include "FormFactorTetrahedron.pypp.h" -#include "FTDistribution1DCosine.pypp.h" -#include "FTDistribution1DTriangle.pypp.h" +#include "RotationZ.pypp.h" +#include "FTDistribution1DCauchy.pypp.h" +#include "ISampleBuilder.pypp.h" +#include "Beam.pypp.h" #include "FormFactorWeighted.pypp.h" -#include "InterferenceFunctionRadialParaCrystal.pypp.h" -#include "DistributionGaussian.pypp.h" -#include "IDetectorResolution.pypp.h" -#include "FormFactorCylinder.pypp.h" +#include "HomogeneousMagneticMaterial.pypp.h" +#include "DistributionLorentz.pypp.h" +#include "RotationX.pypp.h" +#include "Detector.pypp.h" #include "Crystal.pypp.h" -#include "FTDistribution1DCauchy.pypp.h" -#include "IFormFactorBorn.pypp.h" -#include "FormFactorEllipsoidalCylinder.pypp.h" #include "InterferenceFunctionNone.pypp.h" -#include "vector_less__const_ISample_ptr___greater_.pypp.h" #include "FTDistribution2DGate.pypp.h" -#include "vector_kvector_t.pypp.h" -#include "FormFactorTruncatedSpheroid.pypp.h" -#include "Particle.pypp.h" -#include "vector_string_t.pypp.h" -#include "FormFactorTrivial.pypp.h" +#include "FormFactorPrism6.pypp.h" +#include "FormFactorTruncatedCube.pypp.h" +#include "IFTDistribution2D.pypp.h" +#include "FormFactorLorentz.pypp.h" +#include "FixedBinAxis.pypp.h" +#include "ISample.pypp.h" #include "ConstKBinAxis.pypp.h" +#include "LayerInterface.pypp.h" +#include "IDetectorResolution.pypp.h" +#include "Lattice2DIFParameters.pypp.h" +#include "IntensityData.pypp.h" +#include "LayerRoughness.pypp.h" +#include "vector_integer_t.pypp.h" +#include "FormFactorTruncatedSphere.pypp.h" +#include "FormFactorCylinder.pypp.h" +#include "FormFactorFullSphere.pypp.h" +#include "IAxis.pypp.h" +#include "Simulation.pypp.h" +#include "InterferenceFunction2DParaCrystal.pypp.h" +#include "DistributionLogNormal.pypp.h" +#include "FTDistribution1DCosine.pypp.h" +#include "OffSpecSimulation.pypp.h" +#include "RotationEuler.pypp.h" +#include "FTDistribution1DTriangle.pypp.h" +#include "FormFactorSphereUniformRadius.pypp.h" +#include "IntensityDataFunctions.pypp.h" +#include "Instrument.pypp.h" +#include "FormFactorTrivial.pypp.h" +#include "FormFactorSphereLogNormalRadius.pypp.h" +#include "RotationY.pypp.h" +#include "vector_realparameter_t.pypp.h" +#include "IInterferenceFunction.pypp.h" #include "FTDistribution2DCauchy.pypp.h" -#include "FormFactorCrystal.pypp.h" -#include "ParticleDistribution.pypp.h" +#include "IFormFactor.pypp.h" +#include "IObserver.pypp.h" +#include "ParticleComposition.pypp.h" +#include "Particle.pypp.h" +#include "MultiLayer.pypp.h" +#include "ParameterPool.pypp.h" +#include "FormFactorTetrahedron.pypp.h" +#include "FormFactorFullSpheroid.pypp.h" +#include "IParameterized.pypp.h" +#include "FormFactorAnisoPyramid.pypp.h" +#include "IObservable.pypp.h" +#include "ParticleCoreShell.pypp.h" +#include "FormFactorCone.pypp.h" +#include "vector_string_t.pypp.h" +#include "FormFactorInfLongRipple1.pypp.h" +#include "IDistribution1D.pypp.h" +#include "MesoCrystal.pypp.h" +#include "FTDistribution2DVoigt.pypp.h" +#include "InterferenceFunctionRadialParaCrystal.pypp.h" +#include "IMaterial.pypp.h" +#include "SimulationParameters.pypp.h" +#include "IResolutionFunction2D.pypp.h" +#include "FormFactorTruncatedSpheroid.pypp.h" +#include "FormFactorCone6.pypp.h" +#include "FormFactorSphereGaussianRadius.pypp.h" +#include "VariableBinAxis.pypp.h" #include "vector_longinteger_t.pypp.h" #include "ResolutionFunction2DGaussian.pypp.h" +#include "cvector_t.pypp.h" +#include "FormFactorDecoratorDebyeWaller.pypp.h" +#include "IClusteredParticles.pypp.h" +#include "FTDistribution1DVoigt.pypp.h" +#include "vector_complex_t.pypp.h" +#include "FTDistribution2DCone.pypp.h" +#include "ParticleDistribution.pypp.h" +#include "vector_kvector_t.pypp.h" +#include "FormFactorRipple1.pypp.h" +#include "Bin1D.pypp.h" +#include "FormFactorRipple2.pypp.h" +#include "InterferenceFunction2DLattice.pypp.h" +#include "FormFactorInfLongBox.pypp.h" +#include "ThreadInfo.pypp.h" +#include "DistributionCosine.pypp.h" #include "FTDistribution1DGauss.pypp.h" #include "FTDistribution1DGate.pypp.h" -#include "FormFactorAnisoPyramid.pypp.h" -#include "FixedBinAxis.pypp.h" -#include "MultiLayer.pypp.h" -#include "IFormFactor.pypp.h" -#include "kvector_t.pypp.h" -#include "FormFactorSphereUniformRadius.pypp.h" -#include "OffSpecSimulation.pypp.h" -#include "FormFactorRipple1.pypp.h" -#include "Simulation.pypp.h" -#include "IObservable.pypp.h" -#include "FormFactorLorentz.pypp.h" +#include "FormFactorCuboctahedron.pypp.h" +#include "Layer.pypp.h" +#include "RealParameterWrapper.pypp.h" +#include "Histogram1D.pypp.h" #include "SpecularSimulation.pypp.h" -#include "GISASSimulation.pypp.h" -#include "ISelectionRule.pypp.h" -#include "FormFactorRipple2.pypp.h" -#include "RotationZ.pypp.h" -#include "LayerRoughness.pypp.h" -#include "Bin1DCVector.pypp.h" -#include "FormFactorSphereGaussianRadius.pypp.h" -#include "ParameterPool.pypp.h" +#include "FormFactorCrystal.pypp.h" #include "FormFactorPrism3.pypp.h" -#include "IMaterial.pypp.h" -#include "FTDistribution1DVoigt.pypp.h" -#include "IntensityDataFunctions.pypp.h" -#include "FormFactorPrism6.pypp.h" -#include "IClusteredParticles.pypp.h" -#include "VariableBinAxis.pypp.h" -#include "IParticle.pypp.h" -#include "DistributionCosine.pypp.h" +#include "PythonInterface_global_variables.pypp.h" +#include "FTDistribution2DGauss.pypp.h" +#include "FormFactorGauss.pypp.h" +#include "vector_less__const_ISample_ptr___greater_.pypp.h" #include "FormFactorHemiEllipsoid.pypp.h" -#include "IAxis.pypp.h" -#include "vector_integer_t.pypp.h" -#include "IntensityDataIOFactory.pypp.h" -#include "ParameterDistribution.pypp.h" -#include "Layer.pypp.h" +#include "PythonInterface_free_functions.pypp.h" +#include "IParticle.pypp.h" +#include "vdouble1d_t.pypp.h" +#include "AttLimits.pypp.h" +#include "DistributionGaussian.pypp.h" +#include "FormFactorBox.pypp.h" #include "FormFactorPyramid.pypp.h" -#include "RotationY.pypp.h" -#include "CustomBinAxis.pypp.h" -#include "FTDistribution2DCone.pypp.h" +#include "Lattice.pypp.h" #include "IFTDistribution1D.pypp.h" -#include "DistributionLorentz.pypp.h" -#include "IDistribution1D.pypp.h" -#include "HomogeneousMagneticMaterial.pypp.h" -#include "vector_realparameter_t.pypp.h" -#include "IAbstractParticle.pypp.h" -#include "FormFactorTruncatedCube.pypp.h" -#include "FormFactorCuboctahedron.pypp.h" -#include "cvector_t.pypp.h" -#include "PythonInterface_free_functions.pypp.h" -#include "FormFactorSphereLogNormalRadius.pypp.h" -#include "FormFactorInfLongRipple1.pypp.h" -#include "IResolutionFunction2D.pypp.h" -#include "FormFactorFullSphere.pypp.h" +#include "IFormFactorBorn.pypp.h" +#include "FormFactorEllipsoidalCylinder.pypp.h" #include "ParticleLayout.pypp.h" -#include "FormFactorBox.pypp.h" -#include "IParameterized.pypp.h" -#include "Lattice2DIFParameters.pypp.h" #include "IFormFactorDecorator.pypp.h" -#include "InterferenceFunction1DLattice.pypp.h" -#include "RotationEuler.pypp.h" -#include "ISample.pypp.h" -#include "ISampleBuilder.pypp.h" -#include "IRotation.pypp.h" -#include "PythonInterface_global_variables.pypp.h" -#include "Beam.pypp.h" #include "HomogeneousMaterial.pypp.h" +#include "DistributionGate.pypp.h" +#include "kvector_t.pypp.h" +#include "IAbstractParticle.pypp.h" +#include "ISelectionRule.pypp.h" +#include "IntensityDataIOFactory.pypp.h" +#include "IHistogram.pypp.h" +#include "ParameterDistribution.pypp.h" +#include "SimpleSelectionRule.pypp.h" +#include "InterferenceFunction1DLattice.pypp.h" +#include "Bin1DCVector.pypp.h" +#include "CustomBinAxis.pypp.h" #include "ICloneable.pypp.h" -#include "ParticleCoreShell.pypp.h" -#include "FormFactorDecoratorDebyeWaller.pypp.h" -#include "MesoCrystal.pypp.h" +#include "IRotation.pypp.h" #include "Lattice1DIFParameters.pypp.h" -#include "IObserver.pypp.h" -#include "IntensityData.pypp.h" -#include "Lattice.pypp.h" -#include "AttLimits.pypp.h" -#include "IInterferenceFunction.pypp.h" -#include "Instrument.pypp.h" -#include "FormFactorInfLongBox.pypp.h" -#include "FormFactorCone.pypp.h" -#include "ParticleComposition.pypp.h" -#include "RotationX.pypp.h" -#include "FTDistribution2DGauss.pypp.h" -#include "FormFactorTruncatedSphere.pypp.h" -#include "FTDistribution2DVoigt.pypp.h" -#include "FormFactorGauss.pypp.h" -#include "InterferenceFunction2DParaCrystal.pypp.h" -#include "Detector.pypp.h" -#include "FormFactorInfLongRipple2.pypp.h" #include "ICompositeSample.pypp.h" -#include "Bin1D.pypp.h" -#include "vector_complex_t.pypp.h" -#include "DistributionLogNormal.pypp.h" -#include "IFTDistribution2D.pypp.h" +#include "GISASSimulation.pypp.h" +#include "FormFactorInfLongRipple2.pypp.h" #include "__call_policies.pypp.hpp" #include "__convenience.pypp.hpp" #include "__call_policies.pypp.hpp" @@ -233,6 +235,8 @@ BOOST_PYTHON_MODULE(libBornAgainCore){ register_GISASSimulation_class(); register_kvector_t_class(); register_cvector_t_class(); + register_IHistogram_class(); + register_Histogram1D_class(); register_IMaterial_class(); register_HomogeneousMaterial_class(); register_HomogeneousMagneticMaterial_class(); diff --git a/Core/Tools/inc/CumulativeValue.h b/Core/Tools/inc/CumulativeValue.h index 25c5b79627e41a328b6bf714b9bc2a1bed2174f9..a03e4b282d52dd8c5d88e52313d93da93f34f6bb 100644 --- a/Core/Tools/inc/CumulativeValue.h +++ b/Core/Tools/inc/CumulativeValue.h @@ -47,32 +47,32 @@ private: double m_sum_of_weights; }; -CumulativeValue::CumulativeValue() +inline CumulativeValue::CumulativeValue() { clear(); } -int CumulativeValue::getNumberOfEntries() const +inline int CumulativeValue::getNumberOfEntries() const { return m_n_entries; } -double CumulativeValue::getValue() const +inline double CumulativeValue::getValue() const { return m_sum; } -double CumulativeValue::getAverage() const +inline double CumulativeValue::getAverage() const { return m_average; } -double CumulativeValue::getRMS() const +inline double CumulativeValue::getRMS() const { return std::sqrt(m_rms2); } -void CumulativeValue::add(double value, double weight) +inline void CumulativeValue::add(double value, double weight) { m_n_entries++; m_sum += value; @@ -82,7 +82,7 @@ void CumulativeValue::add(double value, double weight) m_sum_of_weights += weight; } -void CumulativeValue::clear() +inline void CumulativeValue::clear() { m_n_entries = 0; m_sum = 0.0; diff --git a/Core/Tools/inc/Histogram1D.h b/Core/Tools/inc/Histogram1D.h new file mode 100644 index 0000000000000000000000000000000000000000..37d769975b7b5c879f2be95a3f3f05ae0a019f57 --- /dev/null +++ b/Core/Tools/inc/Histogram1D.h @@ -0,0 +1,54 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Tools/inc/Histogram1D.h +//! @brief Defines class Histogram1D. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef HISTOGRAM1D_H +#define HISTOGRAM1D_H + +#include "IHistogram.h" + +////! @class Histogram1D +////! @ingroup tools +////! @brief One dimensional histogram + +class Histogram1D : public IHistogram +{ +public: + //! Constructor for fix bin size histograms. + //! @param nbinsx number of bins + //! @param xlow low edge of the first bin + //! @param xup upper edge of the last bin + Histogram1D(int nbinsx, double xlow, double xup); + + //! Constructor for variable bin size histograms. + //! @param nbinsx number of bins + //! @param xbins Array of size nbins+1 containing low-edges for each + //! bin and upper edge of last bin. + Histogram1D(int nbinsx, const std::vector<double> &xbins); + + //! Constructor for 1D histogram with custom axis + Histogram1D(const IAxis &axis); + + //! Increment bin with abscissa x with a weight. + int fill(double x, double weight = 1.0); + + const IAxis *getXaxis() const; + + std::vector<double> getBinCenters() const; + + std::vector<double> getBinValues() const; +}; + + +#endif diff --git a/Core/Tools/inc/Histogram2D.h b/Core/Tools/inc/Histogram2D.h new file mode 100644 index 0000000000000000000000000000000000000000..8e36087f7e52d369987c66ce9355c3179748ecc1 --- /dev/null +++ b/Core/Tools/inc/Histogram2D.h @@ -0,0 +1,107 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Tools/inc/Histogram2D.h +//! @brief Defines class Histogram2D. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef HISTOGRAM2D_H +#define HISTOGRAM2D_H + +#include "IHistogram.h" +class Histogram1D; + +////! @class Histogram2D +////! @ingroup tools +////! @brief Two dimensional histogram + +class Histogram2D : public IHistogram +{ +public: + //! Constructor for fix bin size histograms. + //! @param nbinsx number of bins on X-axis + //! @param xlow low edge of the first bin of X-axis + //! @param xup upper edge of the last bin of X-axis + //! @param nbinsy number of bins on Y axis + //! @param ylow low edge of the first bin of Y-axis + //! @param yup upper edge of the last bin of Y-axis + Histogram2D(int nbinsx, double xlow, double xup, int nbinsy, double ylow, double yup); + + //! Constructor for variable bin size histograms. + //! @param nbinsx number of bins on X-axis + //! @param xbins Array of size nbins+1 containing low-edges for each + //! bin and upper edge of last bin. + //! @param nbinsy number of bins on Y-axis + //! @param ybins Array of size nbins+1 containing low-edges for each + //! bin and upper edge of last bin. + Histogram2D(int nbinsx, const std::vector<double> &xbins, int nbinsy, const std::vector<double> &ybins); + + //! Constructor for 2D histogram with custom axes + Histogram2D(const IAxis &axis_x, const IAxis &axis_y); + + //! Increment bin with abscissa x and ordinate y with a weight. + int fill(double x, double y, double weight = 1.0); + + const IAxis *getXaxis() const; + + const IAxis *getYaxis() const; + + +// //! Project a 2D histogram into 1D histogram along X. +// Histogram1D *projectionX(ProjectionType = INTEGRAL); + +// //! Project a 2D histogram into 1D histogram along Y. +// Histogram1D *projectionY(ProjectionType = INTEGRAL); + +// //! Project a 2D histogram into 1D histogram along X, the projection +// //! is made from the channels along the Y axis at 'yvalue'. +// Histogram1D *profileX(double yvalue); + +// //! Project a 2D histogram into 1D histogram along X, the projection +// //! is made from the channels along the Y axis ranging from ymin to ymax. +// Histogram1D *profileX(double ymin, double ymax, ProjectionType = INTEGRAL); + +// //! Project a 2D histogram into 1D histogram along X, the projection +// //! is made from the channels along the Y axis at 'yvalue'. +// Histogram1D *profileY(double yvalue); + +// //! Project a 2D histogram into 1D histogram along X, the projection +// //! is made from the channels along the Y axis ranging from ymin to ymax. +// Histogram1D *profileX(double ymin, double ymax, ProjectionType projectionType = INTEGRAL); + +// //! Create new intensity data by applying rectangular clip. +// Histogram1D *createClipped(double xmin, double ymin, double xmax, double ymax); + +// //! +// //! The function returns the corresponding global bin number which has its content +// //! incremented by weight. +// int fill(double x, double y, double weight); + +// PyObject *getArray(DataType dataType = INTENSITY) const; + +// //! Reset this object (intensities, masks, etc) +// void reset(); + +}; + + +//! Sets mask in rectangular area defined by (xmin, xmax, ymin, ymax) to the mask_value. +//! Mask values outisde this area will remain unchanged. +// void setRectangularMask(double xmin, double ymin, double xmax, double ymax, bool mask_value = true); + +//! Sets mask in elliptic area defined by (xcenter, ycenter, rx, ry) to the mask_value. +//! Mask values outisde this area will remain unchanged. +// void setEllipticMask(double xcenter, double ycenter, double rx, double ry, bool mask_value = true); + +//! Sets masks accross whole area to given value +//void setMask(bool mask_value); + +#endif diff --git a/Core/Tools/inc/IHistogram.h b/Core/Tools/inc/IHistogram.h new file mode 100644 index 0000000000000000000000000000000000000000..6c3e6eb86b9e960840cdfe3a4267a8c2c71033f1 --- /dev/null +++ b/Core/Tools/inc/IHistogram.h @@ -0,0 +1,38 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Tools/inc/IHistogram.h +//! @brief Defines class IHistogram. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef IHISTOGRAM_H +#define IHISTOGRAM_H + +#include "OutputData.h" +#include "CumulativeValue.h" + +//! @class IHistogram +//! @ingroup tools +//! @brief Base class for 1D and 2D histograms + +class IHistogram +{ +public: + IHistogram(){} + IHistogram(const IAxis &axis_x); + IHistogram(const IAxis &axis_x, const IAxis &axis_y); + +protected: + OutputData<CumulativeValue> m_data; +}; + +#endif + diff --git a/Core/Tools/src/Histogram1D.cpp b/Core/Tools/src/Histogram1D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fdb05a438c68a6daf5d2e941a06fad9b1d294cee --- /dev/null +++ b/Core/Tools/src/Histogram1D.cpp @@ -0,0 +1,68 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Tools/inc/Histogram1D.cpp +//! @brief Implements class Histogram1D. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "Histogram1D.h" +#include "FixedBinAxis.h" +#include "VariableBinAxis.h" + + +Histogram1D::Histogram1D(int nbinsx, double xlow, double xup) +{ + m_data.addAxis(FixedBinAxis("x-axis", nbinsx, xlow, xup)); +} + +Histogram1D::Histogram1D(int nbinsx, const std::vector<double> &xbins) +{ + m_data.addAxis(VariableBinAxis("x-axis", nbinsx, xbins)); +} + +Histogram1D::Histogram1D(const IAxis &axis) + : IHistogram(axis) +{ + +} + +int Histogram1D::fill(double x, double weight) +{ + const IAxis *axis = m_data.getAxis(0); + if(x < axis->getMin() || x>=axis->getMax()) return -1; + + size_t index = axis->findClosestIndex(x); + + m_data[index].add(weight); + + return (int)index; +} + +const IAxis *Histogram1D::getXaxis() const +{ + return m_data.getAxis(0); +} + +std::vector<double> Histogram1D::getBinCenters() const +{ + return getXaxis()->getBinCenters(); +} + +std::vector<double> Histogram1D::getBinValues() const +{ + std::vector<double> result; + result.resize(getXaxis()->getSize(), 0.0); + for(size_t index = 0; index<m_data.getAllocatedSize(); ++index) { + result[index] = m_data[index].getValue(); + } + return result; +} + diff --git a/Core/Tools/src/Histogram2D.cpp b/Core/Tools/src/Histogram2D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47a3026bc8f6147de6237769935c16ee5a8f0f78 --- /dev/null +++ b/Core/Tools/src/Histogram2D.cpp @@ -0,0 +1,61 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Tools/inc/Histogram2D.cpp +//! @brief Implements class Histogram2D. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "Histogram2D.h" +#include "FixedBinAxis.h" +#include "VariableBinAxis.h" + + +Histogram2D::Histogram2D(int nbinsx, double xlow, double xup, int nbinsy, double ylow, double yup) +{ + m_data.addAxis(FixedBinAxis("x-axis", nbinsx, xlow, xup)); + m_data.addAxis(FixedBinAxis("y-axis", nbinsy, ylow, yup)); +} + +Histogram2D::Histogram2D(int nbinsx, const std::vector<double> &xbins, int nbinsy, const std::vector<double> &ybins) +{ + m_data.addAxis(VariableBinAxis("x-axis", nbinsx, xbins)); + m_data.addAxis(VariableBinAxis("y-axis", nbinsy, ybins)); +} + +Histogram2D::Histogram2D(const IAxis &axis_x, const IAxis &axis_y) + : IHistogram(axis_x, axis_y) +{ + +} + +int Histogram2D::fill(double x, double y, double weight) +{ + if(x < getXaxis()->getMin() || x >= getXaxis()->getMax()) return -1; + if(y < getYaxis()->getMin() || y >= getYaxis()->getMax()) return -1; + + std::vector<double> coordinates; + coordinates.push_back(x); + coordinates.push_back(y); + + size_t index = m_data.findClosestIndex(coordinates); + m_data[index].add(weight); + return (int)index; +} + +const IAxis *Histogram2D::getXaxis() const +{ + return m_data.getAxis(0); +} + +const IAxis *Histogram2D::getYaxis() const +{ + return m_data.getAxis(1); +} diff --git a/Core/Tools/src/IHistogram.cpp b/Core/Tools/src/IHistogram.cpp new file mode 100644 index 0000000000000000000000000000000000000000..48f5ceece89484979b0f93d5f1a8560df70391f2 --- /dev/null +++ b/Core/Tools/src/IHistogram.cpp @@ -0,0 +1,30 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Tools/inc/IntensityDataObject.cpp +//! @brief Implements class IntensityDataObject. +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "IHistogram.h" +#include "FixedBinAxis.h" +#include "VariableBinAxis.h" + + +IHistogram::IHistogram(const IAxis &axis_x) +{ + m_data.addAxis(axis_x); +} + +IHistogram::IHistogram(const IAxis &axis_x, const IAxis &axis_y) +{ + m_data.addAxis(axis_x); + m_data.addAxis(axis_y); +} diff --git a/Fit/PythonAPI/src/PythonModule.cpp b/Fit/PythonAPI/src/PythonModule.cpp index ddc3559c884c5eab2af92e36edfc797044d454fb..5e99d1daad82aeaf5aed0f281357cea90b09fe86 100644 --- a/Fit/PythonAPI/src/PythonModule.cpp +++ b/Fit/PythonAPI/src/PythonModule.cpp @@ -5,36 +5,36 @@ GCC_DIAG_OFF(missing-field-initializers) #include "boost/python.hpp" GCC_DIAG_ON(unused-parameter) GCC_DIAG_ON(missing-field-initializers) -#include "IntensityFunctionSqrt.pypp.h" -#include "MinimizerFactory.pypp.h" -#include "IMinimizer.pypp.h" -#include "SquaredFunctionSystematicError.pypp.h" -#include "IntensityNormalizer.pypp.h" -#include "IIntensityFunction.pypp.h" -#include "INamed.pypp.h" -#include "IntensityFunctionLog.pypp.h" -#include "FitSuiteParameters.pypp.h" -#include "AttFitting.pypp.h" -#include "FitParameter.pypp.h" -#include "IntensityScaleAndShiftNormalizer.pypp.h" +#include "FitSuiteObjects.pypp.h" #include "IChiSquaredModule.pypp.h" -#include "FitStrategyAdjustMinimizer.pypp.h" -#include "IFitStrategy.pypp.h" +#include "FitStrategyDefault.pypp.h" +#include "IntensityFunctionLog.pypp.h" +#include "IntensityNormalizer.pypp.h" #include "FitStrategyFixParameters.pypp.h" +#include "FitStrategyAdjustParameters.pypp.h" #include "SquaredFunctionGaussianError.pypp.h" -#include "IIntensityNormalizer.pypp.h" +#include "IFitStrategy.pypp.h" +#include "MinimizerFactory.pypp.h" #include "FitSuite.pypp.h" -#include "FitStrategyAdjustParameters.pypp.h" -#include "ChiSquaredModule.pypp.h" -#include "MinimizerOptions.pypp.h" -#include "SquaredFunctionDefault.pypp.h" -#include "SquaredFunctionMeanSquaredError.pypp.h" +#include "IMinimizer.pypp.h" +#include "IntensityScaleAndShiftNormalizer.pypp.h" #include "ISquaredFunction.pypp.h" -#include "FitStrategyDefault.pypp.h" -#include "FitObject.pypp.h" -#include "FitSuiteObjects.pypp.h" #include "SquaredFunctionSimError.pypp.h" +#include "FitStrategyAdjustMinimizer.pypp.h" +#include "FitParameter.pypp.h" +#include "SquaredFunctionDefault.pypp.h" +#include "ChiSquaredModule.pypp.h" +#include "SquaredFunctionMeanSquaredError.pypp.h" +#include "IIntensityNormalizer.pypp.h" +#include "FitSuiteParameters.pypp.h" #include "FitStrategyReleaseParameters.pypp.h" +#include "MinimizerOptions.pypp.h" +#include "IIntensityFunction.pypp.h" +#include "IntensityFunctionSqrt.pypp.h" +#include "FitObject.pypp.h" +#include "SquaredFunctionSystematicError.pypp.h" +#include "AttFitting.pypp.h" +#include "INamed.pypp.h" BOOST_PYTHON_MODULE(libBornAgainFit){ boost::python::docstring_options doc_options(true, true, false); diff --git a/Tests/UnitTests/TestCore/main.cpp b/Tests/UnitTests/TestCore/main.cpp index 7d86f5d2d2ff2bff4b2b24c3c8445023e4cb980f..b5659bdc08b33221573d036df6bb4055af5edba1 100644 --- a/Tests/UnitTests/TestCore/main.cpp +++ b/Tests/UnitTests/TestCore/main.cpp @@ -50,6 +50,7 @@ #include "ParticleCoreShellTest.h" #include "ParameterDistributionTest.h" #include "UtilsTest.h" +#include "CumulativeValueTest.h" struct ErrorStreamRedirect { diff --git a/dev-tools/python-bindings/settings_core.py b/dev-tools/python-bindings/settings_core.py index b8b51e40576bba70f15ab8bcbb0064f51190e0a5..ae7241c4d03b65585fdc167c04d9b6344cf96f90 100644 --- a/dev-tools/python-bindings/settings_core.py +++ b/dev-tools/python-bindings/settings_core.py @@ -126,6 +126,8 @@ include_classes = [ "IFormFactorBorn", "IFormFactorDecorator", "IInterferenceFunction", + "IHistogram", + "Histogram1D", "IMaterial", "IObserver", "IObservable", diff --git a/dev-tools/python-bindings/utils_build.py b/dev-tools/python-bindings/utils_build.py index 3a74b0c3b6472faffba346d4bd56fc6296447506..dbd1b28346a85113187e7aa95c244efc4f3ad094 100644 --- a/dev-tools/python-bindings/utils_build.py +++ b/dev-tools/python-bindings/utils_build.py @@ -83,7 +83,7 @@ def IncludeClasses(mb, include_classes): for cl in mb.classes() ): not_found_classes.append(name) if len(not_found_classes): - print( "Error! Can't find classes with requested names " % (not_found_classes) ) + print( "Error! Can't find classes with requested names {0}".format(not_found_classes) ) exit() mb.classes( lambda cls: cls.name in include_classes ).include()