From 017fde9d61d3618ca4d349b146fa1cc6228c7bf4 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Fri, 8 Aug 2014 13:23:02 +0200 Subject: [PATCH] AxisDouble and AxisBin are removed from code. --- App/src/IsGISAXSData.cpp | 108 ++++++------ App/src/TestFormFactor.cpp | 7 +- App/src/TestInfLongBox.cpp | 3 +- App/src/TestInfLongRipple1.cpp | 3 +- App/src/TestInfLongRipple2.cpp | 4 +- Core/Algorithms/inc/Detector.h | 4 - Core/Algorithms/src/Detector.cpp | 24 --- Core/Tools/inc/AxisBin.h | 75 -------- Core/Tools/inc/AxisDouble.h | 85 --------- Core/Tools/inc/OutputDataReadStrategy.h | 28 +-- Core/Tools/src/AxisBin.cpp | 118 ------------- Core/Tools/src/AxisDouble.cpp | 141 --------------- Core/Tools/src/OutputDataIOFactory.cpp | 8 +- Core/Tools/src/OutputDataReadStrategy.cpp | 199 +++++++++++----------- Fit/FitKernel/src/MinimizerScan.cpp | 3 +- Tests/UnitTests/TestCore/AxisBinTest.h | 99 ----------- Tests/UnitTests/TestCore/AxisDoubleTest.h | 90 ---------- Tests/UnitTests/TestCore/DetectorTest.h | 9 +- Tests/UnitTests/TestCore/OutputDataTest.h | 7 +- Tests/UnitTests/TestCore/main.cpp | 2 - 20 files changed, 188 insertions(+), 829 deletions(-) delete mode 100644 Core/Tools/inc/AxisBin.h delete mode 100644 Core/Tools/inc/AxisDouble.h delete mode 100644 Core/Tools/src/AxisBin.cpp delete mode 100644 Core/Tools/src/AxisDouble.cpp delete mode 100644 Tests/UnitTests/TestCore/AxisBinTest.h delete mode 100644 Tests/UnitTests/TestCore/AxisDoubleTest.h diff --git a/App/src/IsGISAXSData.cpp b/App/src/IsGISAXSData.cpp index 75604f5a090..2af9a6d835e 100644 --- a/App/src/IsGISAXSData.cpp +++ b/App/src/IsGISAXSData.cpp @@ -15,7 +15,6 @@ #include "IsGISAXSData.h" #include "BornAgainNamespace.h" -#include "AxisDouble.h" #include <iostream> #include <fstream> @@ -130,60 +129,61 @@ void IsGISAXSData::read_outfile(const std::string& filename, DataSet_t& dataset, //! Convert isgisaxs 1d scan to output data 2d object. -OutputData<double> *IsGISAXSData::convert_isgi_scan(std::vector<IsgiData >& isgi_data) +OutputData<double> *IsGISAXSData::convert_isgi_scan(std::vector<IsgiData >& /* isgi_data */) { - if(isgi_data.size() <2 ) throw LogicErrorException("TestIsGISAXS12::convert_isgi_scan() -> Error! Too short vector."); - - // check if it is scan with fixed phi_f or with fixed alpha_f - bool fixed_phif(true); - bool fixed_alphaf(true); - // if values of phif accross data points are chainging, then phif is not fixed - for(size_t i_point=0; i_point<isgi_data.size()-1; ++i_point) { - if( isgi_data[i_point].phif != isgi_data[i_point+1].phif ) { - fixed_phif = false; - break; - } - } - // if values of alphaf accross data points are chainging, then alphaf is not fixed - for(size_t i_point=0; i_point<isgi_data.size()-1; ++i_point) { - if( isgi_data[i_point].alphaf != isgi_data[i_point+1].alphaf ) { - fixed_alphaf = false; - break; - } - } - if(fixed_phif == fixed_alphaf) - throw LogicErrorException( - "TestIsGISAXS12::convert_isgi_scan() -> " - "Error! Scan can't have both angle phif,alphaf fixed"); - - AxisDouble phi_axis(BornAgain::PHI_AXIS_NAME); - AxisDouble alpha_axis(BornAgain::ALPHA_AXIS_NAME); - if( fixed_phif) { - //m_isgi_fixed_phif = isgi_data.back().phif; - phi_axis.push_back(isgi_data.back().phif); - std::cout << "fixed phi " << isgi_data.back().phif << std::endl; - for(size_t i_point=0; i_point<isgi_data.size(); ++i_point) { - alpha_axis.push_back(isgi_data[i_point].alphaf); - } - } else { - //m_isgi_fixed_alphaf = isgi_data.back().alphaf; - alpha_axis.push_back(isgi_data.back().alphaf); - for(size_t i_point=0; i_point<isgi_data.size(); ++i_point) { - phi_axis.push_back(isgi_data[i_point].phif); - } - } - OutputData<double> *data = new OutputData<double >; - data->addAxis(phi_axis); - data->addAxis(alpha_axis); - data->setAllTo(0.0); - OutputData<double>::iterator it = data->begin(); - int i_point(0); - while( it!= data->end()) { - (*it) = isgi_data[i_point].intensity; - ++i_point; - ++it; - } - return data; + throw Exceptions::NotImplementedException("IsGISAXSData::convert_isgi_scan"); +// if(isgi_data.size() <2 ) throw LogicErrorException("TestIsGISAXS12::convert_isgi_scan() -> Error! Too short vector."); + +// // check if it is scan with fixed phi_f or with fixed alpha_f +// bool fixed_phif(true); +// bool fixed_alphaf(true); +// // if values of phif accross data points are chainging, then phif is not fixed +// for(size_t i_point=0; i_point<isgi_data.size()-1; ++i_point) { +// if( isgi_data[i_point].phif != isgi_data[i_point+1].phif ) { +// fixed_phif = false; +// break; +// } +// } +// // if values of alphaf accross data points are chainging, then alphaf is not fixed +// for(size_t i_point=0; i_point<isgi_data.size()-1; ++i_point) { +// if( isgi_data[i_point].alphaf != isgi_data[i_point+1].alphaf ) { +// fixed_alphaf = false; +// break; +// } +// } +// if(fixed_phif == fixed_alphaf) +// throw LogicErrorException( +// "TestIsGISAXS12::convert_isgi_scan() -> " +// "Error! Scan can't have both angle phif,alphaf fixed"); + +// AxisDouble phi_axis(BornAgain::PHI_AXIS_NAME); +// AxisDouble alpha_axis(BornAgain::ALPHA_AXIS_NAME); +// if( fixed_phif) { +// //m_isgi_fixed_phif = isgi_data.back().phif; +// phi_axis.push_back(isgi_data.back().phif); +// std::cout << "fixed phi " << isgi_data.back().phif << std::endl; +// for(size_t i_point=0; i_point<isgi_data.size(); ++i_point) { +// alpha_axis.push_back(isgi_data[i_point].alphaf); +// } +// } else { +// //m_isgi_fixed_alphaf = isgi_data.back().alphaf; +// alpha_axis.push_back(isgi_data.back().alphaf); +// for(size_t i_point=0; i_point<isgi_data.size(); ++i_point) { +// phi_axis.push_back(isgi_data[i_point].phif); +// } +// } +// OutputData<double> *data = new OutputData<double >; +// data->addAxis(phi_axis); +// data->addAxis(alpha_axis); +// data->setAllTo(0.0); +// OutputData<double>::iterator it = data->begin(); +// int i_point(0); +// while( it!= data->end()) { +// (*it) = isgi_data[i_point].intensity; +// ++i_point; +// ++it; +// } +// return data; } diff --git a/App/src/TestFormFactor.cpp b/App/src/TestFormFactor.cpp index eb400cb9f1f..9a3ab368b9b 100644 --- a/App/src/TestFormFactor.cpp +++ b/App/src/TestFormFactor.cpp @@ -16,12 +16,11 @@ #include "TestFormFactor.h" #include "Types.h" #include "DrawHelper.h" - +#include "FixedBinAxis.h" #include "TCanvas.h" #include "TH2.h" #include "TStyle.h" #include "BornAgainNamespace.h" -#include "AxisDouble.h" #include <cmath> #include <iostream> @@ -31,8 +30,8 @@ TestFormFactor::TestFormFactor() : m_ff(50.0, 50.0) { mp_intensity_output = new OutputData<double>(); - AxisDouble y_axis(std::string("detector y-axis"), 200, -4.0, 4.0); - AxisDouble z_axis(std::string("detector z-axis"), 200, 0.0, 4.0); + FixedBinAxis y_axis(std::string("detector y-axis"), 200, -4.0, 4.0); + FixedBinAxis z_axis(std::string("detector z-axis"), 200, 0.0, 4.0); mp_intensity_output->addAxis(y_axis); mp_intensity_output->addAxis(z_axis); } diff --git a/App/src/TestInfLongBox.cpp b/App/src/TestInfLongBox.cpp index a621f33c88b..19541aca7f0 100644 --- a/App/src/TestInfLongBox.cpp +++ b/App/src/TestInfLongBox.cpp @@ -36,7 +36,6 @@ #include "Units.h" #include "Utils.h" #include "OffSpecSimulation.h" -#include "AxisDouble.h" #define protected public // needed to access the protected evaluate_for_q method #include "FormFactorInfLongBox.h" @@ -172,7 +171,7 @@ void TestInfLongBox::initializeSimulation() mp_simulation = new OffSpecSimulation(mp_options); mp_simulation->setSampleBuilder(mp_sample_builder); mp_simulation->setDetectorParameters(20, -1.0*Units::degree, 1.0*Units::degree, 200, 0.0*Units::degree, 5.2*Units::degree); - AxisDouble *alpha_i_axis = new AxisDouble("alpha_i", 200, 0.0*Units::degree, 5.2*Units::degree); + FixedBinAxis *alpha_i_axis = new FixedBinAxis("alpha_i", 200, 0.0*Units::degree, 5.2*Units::degree); mp_simulation->setBeamParameters(12.0*Units::angstrom, *alpha_i_axis, 0.0*Units::degree); mp_simulation->setBeamIntensity(1e9); diff --git a/App/src/TestInfLongRipple1.cpp b/App/src/TestInfLongRipple1.cpp index 2420b8a882c..a092140d479 100644 --- a/App/src/TestInfLongRipple1.cpp +++ b/App/src/TestInfLongRipple1.cpp @@ -36,7 +36,6 @@ #include "Units.h" #include "Utils.h" #include "OffSpecSimulation.h" -#include "AxisDouble.h" #define protected public // needed to access the protected evaluate_for_q method #include "FormFactorInfLongRipple1.h" @@ -172,7 +171,7 @@ void TestInfLongRipple1::initializeSimulation() mp_simulation = new OffSpecSimulation(mp_options); mp_simulation->setSampleBuilder(mp_sample_builder); mp_simulation->setDetectorParameters(20, -1.0*Units::degree, 1.0*Units::degree, 200, 0.0*Units::degree, 5.2*Units::degree); - AxisDouble *alpha_i_axis = new AxisDouble("alpha_i", 200, 0.0*Units::degree, 5.2*Units::degree); + FixedBinAxis *alpha_i_axis = new FixedBinAxis("alpha_i", 200, 0.0*Units::degree, 5.2*Units::degree); mp_simulation->setBeamParameters(12.0*Units::angstrom, *alpha_i_axis, 0.0*Units::degree); mp_simulation->setBeamIntensity(1e9); diff --git a/App/src/TestInfLongRipple2.cpp b/App/src/TestInfLongRipple2.cpp index 3b0c6f556f9..fa00c9338a5 100644 --- a/App/src/TestInfLongRipple2.cpp +++ b/App/src/TestInfLongRipple2.cpp @@ -21,6 +21,7 @@ #include "IsGISAXSData.h" #include "IsGISAXSTools.h" #include "Layer.h" +#include "FixedBinAxis.h" #include "Materials.h" #include "MathFunctions.h" #include "MultiLayer.h" @@ -36,7 +37,6 @@ #include "Units.h" #include "Utils.h" #include "OffSpecSimulation.h" -#include "AxisDouble.h" #define protected public // needed to access the protected evaluate_for_q method #include "FormFactorInfLongRipple2.h" @@ -172,7 +172,7 @@ void TestInfLongRipple2::initializeSimulation() mp_simulation = new OffSpecSimulation(mp_options); mp_simulation->setSampleBuilder(mp_sample_builder); mp_simulation->setDetectorParameters(20, -1.0*Units::degree, 1.0*Units::degree, 200, 0.0*Units::degree, 5.2*Units::degree); - AxisDouble *alpha_i_axis = new AxisDouble("alpha_i", 200, 0.0*Units::degree, 5.2*Units::degree); + FixedBinAxis *alpha_i_axis = new FixedBinAxis("alpha_i", 200, 0.0*Units::degree, 5.2*Units::degree); mp_simulation->setBeamParameters(12.0*Units::angstrom, *alpha_i_axis, 0.0*Units::degree); mp_simulation->setBeamIntensity(1e9); diff --git a/Core/Algorithms/inc/Detector.h b/Core/Algorithms/inc/Detector.h index b9eaafb59b6..78573553624 100644 --- a/Core/Algorithms/inc/Detector.h +++ b/Core/Algorithms/inc/Detector.h @@ -96,10 +96,6 @@ private: //! swap function void swapContent(Detector& other); - //! Initializes axis the way IsGISAXS does -// void initializeAnglesIsgisaxs( -// AxisDouble *p_axis, const TSampledRange<double>& axis_range) const; - //! Returns the solid angle for the given data element double getSolidAngle(OutputData<double> *p_data, size_t index) const; diff --git a/Core/Algorithms/src/Detector.cpp b/Core/Algorithms/src/Detector.cpp index d41bffd8486..54b918a7316 100644 --- a/Core/Algorithms/src/Detector.cpp +++ b/Core/Algorithms/src/Detector.cpp @@ -15,8 +15,6 @@ #include "Detector.h" -#include "AxisBin.h" -#include "AxisDouble.h" #include "MessageService.h" #include "BornAgainNamespace.h" #include "FixedBinAxis.h" @@ -63,10 +61,6 @@ void Detector::addAxis(const AxisParameters& axis_params) { case AxisParameters::E_DEFAULT: { -// p_new_axis = new AxisBin(axis_params.m_name, -// axis_params.m_range.getNSamples(), -// axis_params.m_range.getLowerBound(), -// axis_params.m_range.getUpperBound()); p_new_axis = new ConstKBinAxis(axis_params.m_name, axis_params.m_range.getNSamples(), @@ -77,9 +71,6 @@ void Detector::addAxis(const AxisParameters& axis_params) } case AxisParameters::E_ISGISAXS: { -// AxisDouble *p_axis = new AxisDouble(axis_params.m_name); -// initializeAnglesIsgisaxs(p_axis, axis_params.m_range); -// p_new_axis = p_axis; p_new_axis = new CustomBinAxis(axis_params.m_name, axis_params.m_range.getNSamples(), axis_params.m_range.getLowerBound(), axis_params.m_range.getUpperBound()); break; @@ -175,21 +166,6 @@ void Detector::normalize(OutputData<double> *p_data, } } -//void Detector::initializeAnglesIsgisaxs( -// AxisDouble* p_axis, const TSampledRange<double>& axis_range) const -//{ -// if (axis_range.getNSamples()>1) { -// double start_sin = std::sin(axis_range.getLowerBound()); -// double end_sin = std::sin(axis_range.getUpperBound()); -// double step = (end_sin-start_sin)/(axis_range.getNSamples()-1); -// for(size_t i=0; i<axis_range.getNSamples(); ++i) { -// p_axis->push_back(std::asin(start_sin + step*i)); -// } -// } -// else { -// p_axis->push_back((axis_range.getUpperBound()-axis_range.getLowerBound())/2.0); -// } -//} double Detector::getSolidAngle(OutputData<double>* p_data, size_t index) const { diff --git a/Core/Tools/inc/AxisBin.h b/Core/Tools/inc/AxisBin.h deleted file mode 100644 index 7cc78c8e5c2..00000000000 --- a/Core/Tools/inc/AxisBin.h +++ /dev/null @@ -1,75 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tools/inc/AxisBin.h -//! @brief Defines class AxisBin. -//! -//! @homepage http://apps.jcns.fz-juelich.de/BornAgain -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#ifndef AXISBIN_H_ -#define AXISBIN_H_ - -#include "IAxis.h" - -//! @class AxisBin -//! @ingroup tools -//! @brief Binned axis. - -class BA_CORE_API_ AxisBin : public IAxis -{ -public: - //! constructors - AxisBin(std::string name); - AxisBin(std::string name, size_t nbr_bins, double start, double end); - - //! clone function - virtual AxisBin *clone() const; - - //! Creates a new axis with half the number of bins - virtual AxisBin *createDoubleBinSize() const; - - //! destructor - virtual ~AxisBin() {} - - //! Adds new bin limit to the end - void push_back(double limit) { m_value_vector.push_back(limit); } - - virtual size_t getSize() const; - - //! indexed accessor retrieves midpoint of given bin - virtual double operator[](size_t index) const; - - virtual Bin1D getBin(size_t index) const; - - virtual double getMin() const { return m_value_vector.front(); } - - virtual double getMax() const { return m_value_vector.back(); } - - //! Initializes axis bins - void initBins(size_t nbr_bins, double start, double end); - - virtual size_t findClosestIndex(double value) const; - -// //! find the bin that contains the given value -// Bin1D findMatchingBin(double value) const; - - //! returns vector containing the bin limits - std::vector<double> getVector() const { return m_value_vector; } - -protected: - virtual void print(std::ostream& ostr) const; - virtual bool equals(const IAxis& other) const; -private: - std::vector<double> m_value_vector; //!< vector containing the bin limits -}; - -#endif /* AXISBIN_H_ */ - - diff --git a/Core/Tools/inc/AxisDouble.h b/Core/Tools/inc/AxisDouble.h deleted file mode 100644 index fbaabdad059..00000000000 --- a/Core/Tools/inc/AxisDouble.h +++ /dev/null @@ -1,85 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tools/inc/AxisDouble.h -//! @brief Defines class AxisDouble. -//! -//! @homepage http://apps.jcns.fz-juelich.de/BornAgain -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#ifndef AXISDOUBLE_H_ -#define AXISDOUBLE_H_ - -#include "IAxis.h" -#include "AxisBin.h" - - -//! @class AxisDouble -//! @ingroup tools -//! @brief Axis with points. - -class BA_CORE_API_ AxisDouble : public IAxis -{ -public: - //! constructors - AxisDouble(std::string name); - AxisDouble(std::string name, size_t size, double start, double end); - - //! explicit conversion from BinAxis - explicit AxisDouble(const AxisBin& source); - - virtual AxisDouble *clone() const; - - virtual AxisDouble *createDoubleBinSize() const; - - //! destructor - virtual ~AxisDouble() {} - - virtual size_t getSize() const { return m_sample_vector.size(); } - - //! Adds point to the end of the axis - void push_back(double element) { m_sample_vector.push_back(element); } - - virtual double operator[](size_t index) const { return m_sample_vector[index]; } - - virtual Bin1D getBin(size_t index) const; - - //! Returns value of first point of axis - virtual double getMin() const { return m_sample_vector.front(); } - - //! Returns value of last point of axis - virtual double getMax() const { return m_sample_vector.back(); } - - //! Initializes axis points - void initElements(size_t size, double start, double end); - - //! find number of bin which is closest to given value - virtual size_t findClosestIndex(double value) const; - - //! find the index that corresponds to the given lower bound (index is inclusive) - size_t getLowerBoundIndex(double value) const; - - //! find the index that corresponds to the given upper bound (index is inclusive) - size_t getUpperBoundIndex(double value) const; - - //! returns vector containing the axis points - std::vector<double> getVector() const { return m_sample_vector; } - -protected: - virtual void print(std::ostream& ostr) const; - virtual bool equals(const IAxis& other) const; - -private: - std::vector<double> m_sample_vector; //!< vector containing the axis points - double m_bin_size; -}; - -#endif /* AXISDOUBLE_H_ */ - - diff --git a/Core/Tools/inc/OutputDataReadStrategy.h b/Core/Tools/inc/OutputDataReadStrategy.h index 7847154e1cf..a498f6dd35c 100644 --- a/Core/Tools/inc/OutputDataReadStrategy.h +++ b/Core/Tools/inc/OutputDataReadStrategy.h @@ -74,20 +74,20 @@ public: //! @brief Strategy to read OutputData from IsGISAXS *.ima files //! which contains 2D array in the form of [nX] lines of [nY] size -class BA_CORE_API_ OutputDataReadStreamIMA : public IOutputDataReadStrategy -{ -public: - OutputData<double > *readOutputData(std::istream& file_stream); -}; - -//! Strategy to read OutputData from ASCII file -//! 1d array for x-axis, 1d array for y-axis, 2d array for data expected - -class OutputDataReadStreamV1 : public IOutputDataReadStrategy -{ -public: - OutputData<double > *readOutputData(std::istream& file_stream); -}; +//class BA_CORE_API_ OutputDataReadStreamIMA : public IOutputDataReadStrategy +//{ +//public: +// OutputData<double > *readOutputData(std::istream& file_stream); +//}; + +////! Strategy to read OutputData from ASCII file +////! 1d array for x-axis, 1d array for y-axis, 2d array for data expected + +//class OutputDataReadStreamV1 : public IOutputDataReadStrategy +//{ +//public: +// OutputData<double > *readOutputData(std::istream& file_stream); +//}; //! Strategy to read BornAgain native IntensityData from ASCII file diff --git a/Core/Tools/src/AxisBin.cpp b/Core/Tools/src/AxisBin.cpp deleted file mode 100644 index 4817331edeb..00000000000 --- a/Core/Tools/src/AxisBin.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tools/src/AxisBin.cpp -//! @brief Implements class AxisBin. -//! -//! @homepage http://apps.jcns.fz-juelich.de/BornAgain -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#include "AxisBin.h" -#include "Numeric.h" -#include "Exceptions.h" -#include <algorithm> - -AxisBin::AxisBin(std::string name) -: IAxis(name) -{ -} - -AxisBin::AxisBin(std::string name, size_t nbr_bins, double start, double end) -: IAxis(name) -{ - initBins(nbr_bins, start, end); -} - -AxisBin *AxisBin::clone() const -{ - AxisBin *p_clone = new AxisBin(getName()); - p_clone->m_value_vector = this->m_value_vector; - return p_clone; -} - -AxisBin *AxisBin::createDoubleBinSize() const -{ - if (getSize() < 2) { - return clone(); - } - AxisBin *p_result = new AxisBin(getName()); - for (size_t source_index=0; source_index<getSize(); source_index+=2) - { - p_result->push_back(m_value_vector[source_index]); - } - p_result->push_back(m_value_vector[getSize()]); - return p_result; -} - -size_t AxisBin::getSize() const -{ - if (m_value_vector.size()<2) { - return 0; - } - return m_value_vector.size() - 1; -} - -double AxisBin::operator[](size_t index) const -{ - return getBin(index).getMidPoint(); -} - -Bin1D AxisBin::getBin(size_t index) const -{ - Bin1D result = { m_value_vector[index], m_value_vector[index+1] }; - return result; -} - -void AxisBin::initBins(size_t nbr_bins, double start, double end) -{ - double step = (end - start)/(nbr_bins); - for (size_t i=0; i<nbr_bins+1; ++i) - { - push_back(start + step*(int)i); - } -} - -size_t AxisBin::findClosestIndex(double value) const -{ - if(m_value_vector.size()<2) { - throw ClassInitializationException("AxisBin::findClosestIndex() -> Error! AxisBin not (yet) correctly initialized"); - } - if (value < getMin() || value > getMax()) { - std::ostringstream ostr; - ostr << "AxisBin::findClosestIndex() -> Error! Given value not in any bin. "; - ostr << "value:" << value << " name:" << getName() << " min:" << getMin() << " max:" << getMax(); - throw OutOfBoundsException(ostr.str()); - } - std::vector<double>::const_iterator top_limit = std::lower_bound(m_value_vector.begin(), m_value_vector.end(), value); - if(top_limit != m_value_vector.begin() ) --top_limit; - size_t nbin = top_limit - m_value_vector.begin(); - return nbin; -} - -bool AxisBin::equals(const IAxis& other) const -{ - if (!IAxis::equals(other)) return false; - if (const AxisBin *p_other_cast = dynamic_cast<const AxisBin *>(&other)) { - if (getSize() != p_other_cast->getSize()) return false; - for(size_t i=0; i<m_value_vector.size(); ++i) { - if( std::abs(m_value_vector[i] - p_other_cast->m_value_vector[i]) > Numeric::double_epsilon ) { - return false; - } - } - return true; - } - return false; -} - -void AxisBin::print(std::ostream& ostr) const -{ - ostr << "AxisBin '" << m_name << "'" << getSize() << " " << getMin() << " " << getMax(); -} - - diff --git a/Core/Tools/src/AxisDouble.cpp b/Core/Tools/src/AxisDouble.cpp deleted file mode 100644 index b29fe6f34f1..00000000000 --- a/Core/Tools/src/AxisDouble.cpp +++ /dev/null @@ -1,141 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tools/src/AxisDouble.cpp -//! @brief Implements class AxisDouble. -//! -//! @homepage http://apps.jcns.fz-juelich.de/BornAgain -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#include "AxisDouble.h" -#include "AxisBin.h" -#include "Numeric.h" -#include "Exceptions.h" -#include <iostream> - -#include <algorithm> - -AxisDouble::AxisDouble(std::string name) -: IAxis(name) -, m_bin_size(0) -{ -} - -AxisDouble::AxisDouble(std::string name, size_t size, double start, double end) -: IAxis(name) -, m_bin_size(0) -{ - initElements(size, start, end); -} - -AxisDouble::AxisDouble(const AxisBin& source) -: IAxis(source.getName()) -, m_bin_size(0) -{ - for (size_t i=0; i<source.getSize(); ++i) { - m_sample_vector.push_back(source[i]); - } -} - -AxisDouble *AxisDouble::clone() const -{ - AxisDouble *p_clone = new AxisDouble(getName()); - p_clone->m_sample_vector = this->m_sample_vector; - p_clone->m_bin_size = this->m_bin_size; - return p_clone; -} - -AxisDouble *AxisDouble::createDoubleBinSize() const -{ - if (getSize() < 2) { - return clone(); - } - AxisDouble *p_result = new AxisDouble(getName()); - for (size_t source_index=0; source_index<getSize(); source_index+=2) - { - double value; - if (source_index==getSize()-1) { - value = (3.0*m_sample_vector.at(source_index) - m_sample_vector.at(source_index-1))/2.0; - } - else { - value = (m_sample_vector.at(source_index) + m_sample_vector.at(source_index+1))/2.0; - } - p_result->push_back(value); - } - p_result->m_bin_size = m_bin_size*2.0; - return p_result; -} - -Bin1D AxisDouble::getBin(size_t index) const -{ - Bin1D result = { m_sample_vector[index] - m_bin_size/2.0, m_sample_vector[index] + m_bin_size/2.0 }; - return result; -} - -void AxisDouble::initElements(size_t size, double start, double end) -{ - double step = size>1 ? (end - start)/(size-1) : end; - for (size_t i=0; i<size; ++i) - { - push_back(start + step*(int)i); - } -} - -size_t AxisDouble::findClosestIndex(double value) const -{ - if(m_sample_vector.size()<2) return 0; - std::vector<double>::const_iterator before = std::lower_bound(m_sample_vector.begin(), m_sample_vector.end(), value); - if(before == m_sample_vector.end() ) --before; - if(before == m_sample_vector.begin() ) ++before; - std::vector<double>::const_iterator after = before; - --before; - size_t nbin(0); - ( *after-value) < (value - *before) ? nbin = std::distance(m_sample_vector.begin(), after) : nbin = std::distance(m_sample_vector.begin(), before); - -// std::cout << "AxisDouble::findClosestIndex " << m_bin_size << std::endl; - return nbin; -} - -size_t AxisDouble::getLowerBoundIndex(double value) const -{ - if(m_sample_vector.size()<2) return 0; - std::vector<double>::const_iterator lbound_it = std::lower_bound(m_sample_vector.begin(), m_sample_vector.end(), value); - if(lbound_it == m_sample_vector.end() ) { - throw RuntimeErrorException("Given lower bound higher than highest present value"); - } - return lbound_it - m_sample_vector.begin(); -} - -size_t AxisDouble::getUpperBoundIndex(double value) const -{ - if(m_sample_vector.size()<2) return 0; - std::vector<double>::const_iterator lbound_it = std::upper_bound(m_sample_vector.begin(), m_sample_vector.end(), value); - return (lbound_it - m_sample_vector.begin()) - 1; -} - -bool AxisDouble::equals(const IAxis& other) const -{ - if (!IAxis::equals(other)) return false; - if (const AxisDouble *p_other_cast = dynamic_cast<const AxisDouble *>(&other)) { - if (getSize() != p_other_cast->getSize()) return false; - for(size_t i=0; i<m_sample_vector.size(); ++i) { - if( std::abs(m_sample_vector[i] - p_other_cast->m_sample_vector[i]) > Numeric::double_epsilon ) { - return false; - } - } - return true; - } - return false; -} - -void AxisDouble::print(std::ostream& ostr) const -{ - ostr << "AxisDouble '" << m_name << "'" << getSize() << " " << getMin() << " " << getMax(); -} - diff --git a/Core/Tools/src/OutputDataIOFactory.cpp b/Core/Tools/src/OutputDataIOFactory.cpp index c1553a1b5f5..09c91037632 100644 --- a/Core/Tools/src/OutputDataIOFactory.cpp +++ b/Core/Tools/src/OutputDataIOFactory.cpp @@ -39,9 +39,9 @@ OutputDataIOFactory::OutputDataReader_t OutputDataIOFactory::getReader( IOutputDataReadStrategy *read_strategy(0); if( Utils::FileSystem::GetFileMainExtension(file_name) == ".txt") { - read_strategy = new OutputDataReadStreamV1(); +// read_strategy = new OutputDataReadStreamV1(); } else if ( Utils::FileSystem::GetFileMainExtension(file_name) == ".ima") { - read_strategy = new OutputDataReadStreamIMA(); +// read_strategy = new OutputDataReadStreamIMA(); } else if ( Utils::FileSystem::GetFileMainExtension(file_name) == ".int") { read_strategy = new OutputDataReadStreamBA(); } else { @@ -74,9 +74,9 @@ OutputDataIOFactory::OutputDataWriter_t OutputDataIOFactory::getWriter( IOutputDataWriteStrategy *write_strategy(0); if( Utils::FileSystem::GetFileExtension(file_name) == ".ima") { - write_strategy = new OutputDataWriteStreamIMA(); +// write_strategy = new OutputDataWriteStreamIMA(); }else if(Utils::FileSystem::GetFileExtension(file_name) == ".txt") { - write_strategy = new OutputDataWriteStreamV1(); +// write_strategy = new OutputDataWriteStreamV1(); }else if(Utils::FileSystem::GetFileExtension(file_name) == ".int") { write_strategy = new OutputDataWriteStreamBA(); } else { diff --git a/Core/Tools/src/OutputDataReadStrategy.cpp b/Core/Tools/src/OutputDataReadStrategy.cpp index 140761ff9a3..d67c10882e4 100644 --- a/Core/Tools/src/OutputDataReadStrategy.cpp +++ b/Core/Tools/src/OutputDataReadStrategy.cpp @@ -20,7 +20,6 @@ #include "BornAgainNamespace.h" #include "OutputData.h" #include "OutputDataIOHelper.h" -#include "AxisDouble.h" #include <iostream> #include <fstream> @@ -62,51 +61,51 @@ OutputData<double > *OutputDataReadStreamGZip::readOutputData(std::istream &inpu /* ************************************************************************* */ // read data from ASCII file (2D assumed) and fill newly created OutputData with it /* ************************************************************************* */ -OutputData<double > *OutputDataReadStreamIMA::readOutputData(std::istream &input_stream) -{ - std::string sline; - vdouble2d_t buff_2d; - // reading file line by line, every line is parsed into vector of double, so at the end we have buffer_2d of doubles - - while( std::getline(input_stream, sline)) - { - //std::string str = Utils::String::round_doubles(sline, 10); - //vdouble1d_t buff = Utils::String::parse_doubles(str); - vdouble1d_t buff = Utils::String::parse_doubles(sline); - - buff_2d.push_back(buff); - } - - // creating new OutputData and filling it with values from buffer_2d -// int y_size = (int)buff_2d.size(); -// int x_size = buff_2d.size() ? (int)buff_2d[0].size() : 0; - int x_size = (int)buff_2d.size(); - int y_size = buff_2d.size() ? (int)buff_2d[0].size() : 0; - if(x_size==0 || y_size==0) { - std::stringstream ostr; - ostr << "OutputDataReadStreamIMA::readOutputData() -> Error. Zero x_size: " - << x_size << " or y_size: " << y_size; - throw LogicErrorException(ostr.str()); - } - - OutputData<double> *p_result = new OutputData<double>; -// p_result->addAxis(NDetector2d::PHI_AXIS_NAME, x_size, 0.0, double(x_size)); -// p_result->addAxis(NDetector2d::ALPHA_AXIS_NAME, y_size, 0.0, double(y_size)); - p_result->addAxis(BornAgain::PHI_AXIS_NAME, x_size, 0.0, double(x_size)); - p_result->addAxis(BornAgain::ALPHA_AXIS_NAME, y_size, 0.0, double(y_size)); - p_result->setAllTo(0.0); - - OutputData<double>::iterator it = p_result->begin(); - while (it != p_result->end()) - { - size_t index_x = p_result->toCoordinates(it.getIndex())[0]; - size_t index_y = p_result->toCoordinates(it.getIndex())[1]; - *it = buff_2d[index_x][index_y]; - ++it; - } - - return p_result; -} +//OutputData<double > *OutputDataReadStreamIMA::readOutputData(std::istream &input_stream) +//{ +// std::string sline; +// vdouble2d_t buff_2d; +// // reading file line by line, every line is parsed into vector of double, so at the end we have buffer_2d of doubles + +// while( std::getline(input_stream, sline)) +// { +// //std::string str = Utils::String::round_doubles(sline, 10); +// //vdouble1d_t buff = Utils::String::parse_doubles(str); +// vdouble1d_t buff = Utils::String::parse_doubles(sline); + +// buff_2d.push_back(buff); +// } + +// // creating new OutputData and filling it with values from buffer_2d +//// int y_size = (int)buff_2d.size(); +//// int x_size = buff_2d.size() ? (int)buff_2d[0].size() : 0; +// int x_size = (int)buff_2d.size(); +// int y_size = buff_2d.size() ? (int)buff_2d[0].size() : 0; +// if(x_size==0 || y_size==0) { +// std::stringstream ostr; +// ostr << "OutputDataReadStreamIMA::readOutputData() -> Error. Zero x_size: " +// << x_size << " or y_size: " << y_size; +// throw LogicErrorException(ostr.str()); +// } + +// OutputData<double> *p_result = new OutputData<double>; +//// p_result->addAxis(NDetector2d::PHI_AXIS_NAME, x_size, 0.0, double(x_size)); +//// p_result->addAxis(NDetector2d::ALPHA_AXIS_NAME, y_size, 0.0, double(y_size)); +// p_result->addAxis(BornAgain::PHI_AXIS_NAME, x_size, 0.0, double(x_size)); +// p_result->addAxis(BornAgain::ALPHA_AXIS_NAME, y_size, 0.0, double(y_size)); +// p_result->setAllTo(0.0); + +// OutputData<double>::iterator it = p_result->begin(); +// while (it != p_result->end()) +// { +// size_t index_x = p_result->toCoordinates(it.getIndex())[0]; +// size_t index_y = p_result->toCoordinates(it.getIndex())[1]; +// *it = buff_2d[index_x][index_y]; +// ++it; +// } + +// return p_result; +//} /* ************************************************************************* */ // parsing stream of double's into OutputData object @@ -118,60 +117,60 @@ OutputData<double > *OutputDataReadStreamIMA::readOutputData(std::istream &input // line representing y bins [nY] // [nX] lines of [nY] size representing data itself /* ************************************************************************* */ -OutputData<double > *OutputDataReadStreamV1::readOutputData(std::istream &input_stream) -{ - std::string sline; - vdouble1d_t buff_xaxis, buff_yaxis; - vdouble2d_t buff_data; // [x][y] - - while( std::getline(input_stream, sline) ) - { - if(sline[0] == '#') continue; - //std::string str = Utils::String::round_doubles(sline, 10); - vdouble1d_t buff = Utils::String::parse_doubles(sline); - - if( buff_xaxis.empty() ) { - buff_xaxis = buff; - } else if( buff_yaxis.empty() ) { - buff_yaxis = buff; - } else { - buff_data.push_back(buff); - } - } - - // check consistency of x dimension and data buffer - if( buff_data.size() != buff_xaxis.size()) { - throw LogicErrorException("OutputDataReadASCII::readOutputData() -> Error. Unconsistent x-size."); - } - // check consistency of y dimension and data buffer - for(size_t i = 0; i<buff_xaxis.size(); ++i) { - if( buff_data[i].size() != buff_yaxis.size()) { - throw LogicErrorException("OutputDataReadASCII::readOutputData() -> Error. Unconsistent y-size."); - } - } - - // creating output data -// AxisDouble xaxis(NDetector2d::PHI_AXIS_NAME); - AxisDouble xaxis(BornAgain::PHI_AXIS_NAME); - for(size_t i=0; i<buff_xaxis.size(); ++i) xaxis.push_back(buff_xaxis[i]); -// AxisDouble yaxis(NDetector2d::ALPHA_AXIS_NAME); - AxisDouble yaxis(BornAgain::ALPHA_AXIS_NAME); - for(size_t i=0; i<buff_yaxis.size(); ++i) yaxis.push_back(buff_yaxis[i]); - - OutputData<double > *p_result = new OutputData<double>; - p_result->addAxis(xaxis); - p_result->addAxis(yaxis); - p_result->setAllTo(0.0); - OutputData<double>::iterator it = p_result->begin(); - while (it != p_result->end()) - { - size_t index_x = p_result->toCoordinates(it.getIndex())[0]; - size_t index_y = p_result->toCoordinates(it.getIndex())[1]; - *it = buff_data[index_x][index_y]; - ++it; - } - return p_result; -} +//OutputData<double > *OutputDataReadStreamV1::readOutputData(std::istream &input_stream) +//{ +// std::string sline; +// vdouble1d_t buff_xaxis, buff_yaxis; +// vdouble2d_t buff_data; // [x][y] + +// while( std::getline(input_stream, sline) ) +// { +// if(sline[0] == '#') continue; +// //std::string str = Utils::String::round_doubles(sline, 10); +// vdouble1d_t buff = Utils::String::parse_doubles(sline); + +// if( buff_xaxis.empty() ) { +// buff_xaxis = buff; +// } else if( buff_yaxis.empty() ) { +// buff_yaxis = buff; +// } else { +// buff_data.push_back(buff); +// } +// } + +// // check consistency of x dimension and data buffer +// if( buff_data.size() != buff_xaxis.size()) { +// throw LogicErrorException("OutputDataReadASCII::readOutputData() -> Error. Unconsistent x-size."); +// } +// // check consistency of y dimension and data buffer +// for(size_t i = 0; i<buff_xaxis.size(); ++i) { +// if( buff_data[i].size() != buff_yaxis.size()) { +// throw LogicErrorException("OutputDataReadASCII::readOutputData() -> Error. Unconsistent y-size."); +// } +// } + +// // creating output data +//// AxisDouble xaxis(NDetector2d::PHI_AXIS_NAME); +// AxisDouble xaxis(BornAgain::PHI_AXIS_NAME); +// for(size_t i=0; i<buff_xaxis.size(); ++i) xaxis.push_back(buff_xaxis[i]); +//// AxisDouble yaxis(NDetector2d::ALPHA_AXIS_NAME); +// AxisDouble yaxis(BornAgain::ALPHA_AXIS_NAME); +// for(size_t i=0; i<buff_yaxis.size(); ++i) yaxis.push_back(buff_yaxis[i]); + +// OutputData<double > *p_result = new OutputData<double>; +// p_result->addAxis(xaxis); +// p_result->addAxis(yaxis); +// p_result->setAllTo(0.0); +// OutputData<double>::iterator it = p_result->begin(); +// while (it != p_result->end()) +// { +// size_t index_x = p_result->toCoordinates(it.getIndex())[0]; +// size_t index_y = p_result->toCoordinates(it.getIndex())[1]; +// *it = buff_data[index_x][index_y]; +// ++it; +// } +// return p_result; +//} OutputData<double > *OutputDataReadStreamBA::readOutputData(std::istream &input_stream) diff --git a/Fit/FitKernel/src/MinimizerScan.cpp b/Fit/FitKernel/src/MinimizerScan.cpp index d9a50237a3b..7795da85b1c 100644 --- a/Fit/FitKernel/src/MinimizerScan.cpp +++ b/Fit/FitKernel/src/MinimizerScan.cpp @@ -14,7 +14,6 @@ // ************************************************************************** // #include "MinimizerScan.h" -#include "AxisDouble.h" #include <algorithm> //! Scan minimizer find minimum of chi2 function by equidistant scanning of fit parameters. @@ -50,7 +49,7 @@ void MinimizerScan::construct_fcnvalues_map() for(size_t i_par=0; i_par < m_parameters.size(); i_par++ ) { const FitParameter *par = m_parameters[i_par]; if( par->hasLowerLimit() && par->hasUpperLimit() ) { - AxisDouble axis(par->getName(), m_nbins, par->getLowerLimit(), par->getUpperLimit()); + FixedBinAxis axis(par->getName(), m_nbins, par->getLowerLimit(), par->getUpperLimit()); m_fcnvalues_map->addAxis(axis); } } diff --git a/Tests/UnitTests/TestCore/AxisBinTest.h b/Tests/UnitTests/TestCore/AxisBinTest.h deleted file mode 100644 index f2f73fa6e02..00000000000 --- a/Tests/UnitTests/TestCore/AxisBinTest.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef AXISBINTEST_H -#define AXISBINTEST_H - -#include "AxisBin.h" -#include "gtest/gtest.h" - -class AxisBinTest: public ::testing::Test -{ -protected: - AxisBinTest() - : angleAxis("angle"), lengthAxis("length", 100, 0.0, 10.0) {} - - AxisBin angleAxis; - AxisBin lengthAxis; -}; - -TEST_F(AxisBinTest, DefaultIsEmpty) -{ - EXPECT_EQ((size_t)0, angleAxis.getSize()); -} - -TEST_F(AxisBinTest, AddElementsToEmpty) -{ - angleAxis.push_back(0.0); - angleAxis.push_back(1.0); - angleAxis.push_back(2.0); - angleAxis.push_back(3.0); - angleAxis.push_back(4.0); - angleAxis.push_back(5.0); - - ASSERT_EQ((size_t)5, angleAxis.getSize()); - EXPECT_DOUBLE_EQ(0.5, (double)angleAxis[0]); - EXPECT_DOUBLE_EQ(1.5, (double)angleAxis[1]); - EXPECT_DOUBLE_EQ(2.5, (double)angleAxis[2]); - EXPECT_DOUBLE_EQ(3.5, (double)angleAxis[3]); - EXPECT_DOUBLE_EQ(4.5, (double)angleAxis[4]); -} - -TEST_F(AxisBinTest, ExtendedConstructor) -{ - ASSERT_EQ((size_t)100, lengthAxis.getSize()); - EXPECT_DOUBLE_EQ(0.05, (double)lengthAxis[0]); - EXPECT_DOUBLE_EQ(0.15, (double)lengthAxis[1]); - EXPECT_DOUBLE_EQ(6.55, (double)lengthAxis[65]); - EXPECT_DOUBLE_EQ(9.95, (double)lengthAxis[99]); -} - -TEST_F(AxisBinTest, VectorOfUnitLength) -{ - AxisBin vec("name", 1, 1.0, 2.0); - EXPECT_EQ((size_t)1, vec.getSize()); - EXPECT_EQ(double(1.0), vec.getMin()); - EXPECT_EQ(double(2.0), vec.getMax()); -} - -TEST_F(AxisBinTest, FindClosestIndex) -{ - AxisBin vec_size2("name", 2, 0.0, 1.0); - EXPECT_EQ( size_t(2), vec_size2.getSize()); - EXPECT_EQ( size_t(0), vec_size2.findClosestIndex(0.1)); - EXPECT_EQ( size_t(0), vec_size2.findClosestIndex(0.2)); - EXPECT_EQ( size_t(0), vec_size2.findClosestIndex(0.5)); - EXPECT_EQ( size_t(1), vec_size2.findClosestIndex(0.6)); - EXPECT_EQ( size_t(1), vec_size2.findClosestIndex(1.0)); - - - AxisBin vec_size10("name", 10, 0.0, 10.0); - EXPECT_EQ( size_t(10), vec_size10.getSize()); - EXPECT_DOUBLE_EQ(0.5, vec_size10[0]); - EXPECT_DOUBLE_EQ(9.5, vec_size10[9]); - - EXPECT_EQ( size_t(0), vec_size10.findClosestIndex(0.0)); - EXPECT_EQ( size_t(1), vec_size10.findClosestIndex(1.2)); - EXPECT_EQ( size_t(0), vec_size10.findClosestIndex(0.49)); - EXPECT_EQ( size_t(0), vec_size10.findClosestIndex(0.51)); - EXPECT_EQ( size_t(5), vec_size10.findClosestIndex(5.01)); - EXPECT_EQ( size_t(6), vec_size10.findClosestIndex(6.61)); - EXPECT_EQ( size_t(9), vec_size10.findClosestIndex(9.9)); -} - -TEST_F(AxisBinTest, CheckBin) -{ - AxisBin bin("name",20,0,10); - - Bin1D bin1d3 = bin.getBin(3); - EXPECT_DOUBLE_EQ( 1.75, bin1d3.getMidPoint()); - EXPECT_DOUBLE_EQ( 1.5, bin1d3.m_lower); - EXPECT_DOUBLE_EQ( 2.0, bin1d3.m_upper); - - Bin1D bin1d10 = bin.getBin(10); - EXPECT_DOUBLE_EQ( 5.25, bin1d10.getMidPoint()); - EXPECT_DOUBLE_EQ( 5.0, bin1d10.m_lower); - EXPECT_DOUBLE_EQ( 5.5, bin1d10.m_upper); - - -} - - -#endif //AXISBINTEST_H diff --git a/Tests/UnitTests/TestCore/AxisDoubleTest.h b/Tests/UnitTests/TestCore/AxisDoubleTest.h deleted file mode 100644 index b544fc65d43..00000000000 --- a/Tests/UnitTests/TestCore/AxisDoubleTest.h +++ /dev/null @@ -1,90 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file ThreadInfoTest.h -//! @brief Defines unit test for AxisDouble class. -//! -//! @homepage http://apps.jcns.fz-juelich.de/BornAgain -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#ifndef AXISDOUBLETEST_H -#define AXISDOUBLETEST_H - -#include "AxisDouble.h" - -#include "gtest/gtest.h" - -class AxisDoubleTest : public ::testing::Test -{ - protected: - AxisDoubleTest() - : angleAxis("angle"), lengthAxis("length", 100, 0.0, 9.9) {} - - AxisDouble angleAxis; - AxisDouble lengthAxis; -}; - -TEST_F(AxisDoubleTest, DefaultIsEmpty) -{ - EXPECT_EQ((size_t)0, angleAxis.getSize()); -} - -TEST_F(AxisDoubleTest, AddElementsToEmpty) -{ - angleAxis.push_back(1.0f); - ASSERT_EQ((size_t)1, angleAxis.getSize()); - EXPECT_FLOAT_EQ(1.0, (float)angleAxis[0]); -} - -TEST_F(AxisDoubleTest, ExtendedConstructor) -{ - ASSERT_EQ((size_t)100, lengthAxis.getSize()); - EXPECT_DOUBLE_EQ(0.0, lengthAxis[0]); - EXPECT_DOUBLE_EQ(0.1, lengthAxis[1]); - EXPECT_DOUBLE_EQ(6.5, lengthAxis[65]); - EXPECT_DOUBLE_EQ(9.9, lengthAxis[99]); -} - -TEST_F(AxisDoubleTest, VectorOfUnitLength) -{ - AxisDouble vec("name", 1, 1.0, 2.0); - EXPECT_EQ((size_t)1, vec.getSize()); - EXPECT_EQ(double(1), vec.getMin()); - EXPECT_EQ(double(1), vec.getMax()); -} - -TEST_F(AxisDoubleTest, FindClosestIndex) -{ - AxisDouble vec_size1("name", 1, 2.0, 4.0); - EXPECT_EQ( size_t(1), vec_size1.getSize()); - EXPECT_EQ( size_t(0), vec_size1.findClosestIndex(1.0)); - EXPECT_EQ( size_t(0), vec_size1.findClosestIndex(3.0)); - EXPECT_EQ( size_t(0), vec_size1.findClosestIndex(5.0)); - - AxisDouble vec_size2("name", 2, 2.0, 4.0); - EXPECT_EQ( size_t(2), vec_size2.getSize() ); - EXPECT_EQ( size_t(0), vec_size2.findClosestIndex(1.0)); - EXPECT_EQ( size_t(0), vec_size2.findClosestIndex(2.9)); - EXPECT_EQ( size_t(1), vec_size2.findClosestIndex(3.1)); - EXPECT_EQ( size_t(1), vec_size2.findClosestIndex(4.1)); - - AxisDouble vec_size11("name", 11, 0.0, 10.0); - EXPECT_EQ( size_t(11), vec_size11.getSize()); - EXPECT_DOUBLE_EQ(double(0), vec_size11[0]); - EXPECT_DOUBLE_EQ(double(10), vec_size11[10]); - EXPECT_EQ( size_t(0), vec_size11.findClosestIndex(-1.0)); - EXPECT_EQ( size_t(0), vec_size11.findClosestIndex(0.0)); - EXPECT_EQ( size_t(1), vec_size11.findClosestIndex(1)); - EXPECT_EQ( size_t(0), vec_size11.findClosestIndex(0.49)); - EXPECT_EQ( size_t(1), vec_size11.findClosestIndex(0.51)); - EXPECT_EQ( size_t(9), vec_size11.findClosestIndex(9.01)); - EXPECT_EQ( size_t(10), vec_size11.findClosestIndex(100.)); -} - -#endif // AXISDOUBLETEST_H diff --git a/Tests/UnitTests/TestCore/DetectorTest.h b/Tests/UnitTests/TestCore/DetectorTest.h index eb978c273e6..780f8c148ce 100644 --- a/Tests/UnitTests/TestCore/DetectorTest.h +++ b/Tests/UnitTests/TestCore/DetectorTest.h @@ -5,6 +5,7 @@ #include "Detector.h" #include "Exceptions.h" #include "OutputData.h" +#include "FixedBinAxis.h" #include "ConvolutionDetectorResolution.h" #include "ResolutionFunction2DSimple.h" @@ -26,8 +27,8 @@ class DetectorTest : public ::testing::Test DetectorTest::DetectorTest() { originalDetector = new Detector(); - AxisDouble axis0("axis0", 10, 0.0, 10.0); - AxisDouble axis1("axis1", 20, 0.0, 20.0); + FixedBinAxis axis0("axis0", 10, 0.0, 10.0); + FixedBinAxis axis1("axis1", 20, 0.0, 20.0); originalDetector->addAxis(axis0); originalDetector->addAxis(axis1); originalDetector->setDetectorResolution(new ConvolutionDetectorResolution( @@ -51,8 +52,8 @@ TEST_F(DetectorTest, InitialDetectorState) TEST_F(DetectorTest, DetectorConstruction) { // pushing two axes - AxisDouble axis0("axis0", 10, 0.0, 10.0); - AxisDouble axis1("axis1", 20, 0.0, 20.0); + FixedBinAxis axis0("axis0", 10, 0.0, 10.0); + FixedBinAxis axis1("axis1", 20, 0.0, 20.0); constructedDetector.addAxis(axis0); constructedDetector.addAxis(axis1); diff --git a/Tests/UnitTests/TestCore/OutputDataTest.h b/Tests/UnitTests/TestCore/OutputDataTest.h index e3fc53f5c80..44658a39149 100644 --- a/Tests/UnitTests/TestCore/OutputDataTest.h +++ b/Tests/UnitTests/TestCore/OutputDataTest.h @@ -6,6 +6,7 @@ #include "OutputDataFunctions.h" #include "IntensityDataHelper.h" #include "VariableBinAxis.h" +#include "FixedBinAxis.h" #include "ThreadInfo.h" #include <boost/assign/list_of.hpp> @@ -31,9 +32,9 @@ OutputDataTest::OutputDataTest() zero_3d_coordinate.push_back(0); zero_3d_coordinate.push_back(0); zero_3d_coordinate.push_back(0); - AxisDouble angle_axis("angle", 20, 0.0, 0.1); - AxisDouble length_axis("length", 10, 0.0, 0.5); - AxisDouble index_axis("index", 10, 1, 10); + FixedBinAxis angle_axis("angle", 20, 0.0, 0.1); + FixedBinAxis length_axis("length", 10, 0.0, 0.5); + FixedBinAxis index_axis("index", 10, 1, 10); fl_data_1d.addAxis(angle_axis); db_data_3d.addAxis(angle_axis); diff --git a/Tests/UnitTests/TestCore/main.cpp b/Tests/UnitTests/TestCore/main.cpp index 3dc97d2ce8c..4945869d5e2 100644 --- a/Tests/UnitTests/TestCore/main.cpp +++ b/Tests/UnitTests/TestCore/main.cpp @@ -3,7 +3,6 @@ #endif #include "gtest/gtest.h" -#include "AxisDoubleTest.h" #include "BeamTest.h" #include "ChiSquaredModuleTest.h" #include "CVectorTest.h" @@ -26,7 +25,6 @@ #include "ParticleInfoTest.h" #include "LLDataTest.h" #include "TRangeTest.h" -#include "AxisBinTest.h" #include "FTDistributionsTest.h" #include "MultiLayerTest.h" #include "ParticleLayoutTest.h" -- GitLab