#ifndef __JOSCPROB__JCOMPLEXPHASE__ #define __JOSCPROB__JCOMPLEXPHASE__ #include "JLang/JException.hh" #include "JTools/JGrid.hh" #include "JOscProb/JOscParameter.hh" /** * \author bjung, mdejong */ namespace JOSCPROB {} namespace JPP { using namespace JOSCPROB; } namespace JOSCPROB { using JTOOLS::JGrid; /** * Implementation of oscillation complex phase. */ template struct JComplexPhase final : public JOscParameter { typedef JComplexPhase JComplexPhase_t; typedef JOscParameter JOscParameter_t; typedef typename JOscParameter_t::JParameter_t JParameter_t; typedef typename JOscParameter_t::argument_type argument_type; typedef typename JOscParameter_t::value_type value_type; /** * Default constructor. */ JComplexPhase() : JOscParameter_t() {} /** * Constructor. * * \param value complex phase value [rad] */ explicit JComplexPhase(argument_type value) : JOscParameter_t(value) { using namespace JPP; if (!is_valid()) { THROW(JValueOutOfRange, "JComplexPhase::JComplexPhase(): Invalid complex phase " << value); } } /** * Assignment operator. * * \param value complex phase value [rad] * \return complex phase */ JComplexPhase_t& operator=(const value_type& value) { this->setValue(value); return *this; } /** * Check validity of oscillation parameter. * * \return true if valid; else false */ bool is_valid() const override final { const value_type phase = this->getValue(); return this->isDefined() ? !(phase < 0.0 || phase > 2 * M_PI) : true; } /** * Auxiliary function to create a complex phase parameter grid. * * \param value complex phase value [rad] * \return complex phase parameter */ static JComplexPhase_t make_parameter(argument_type value) { return JComplexPhase_t(value); } }; /** * Template specialization for parameter grid. */ template<> struct JComplexPhase > final : public JOscParameter > { typedef JGrid JGrid_t; typedef JComplexPhase JComplexPhase_t; typedef JOscParameter JOscParameter_t; typedef typename JOscParameter_t::JParameter_t JParameter_t; /** * Default constructor. */ JComplexPhase() {} /** * Constructor. * * \param grid complex phase parameter grid [rad] */ explicit JComplexPhase(const JGrid_t& grid) : JOscParameter_t(grid) { using namespace JPP; if (!is_valid()) { THROW(JValueOutOfRange, "JComplexPhase::JComplexPhase(): Invalid complex phase grid " << grid); } } /** * Constructor. * * \param nx number of elements * \param xmin lower limit [rad] * \param xmax upper limit [rad] */ JComplexPhase(const int nx, const double xmin, const double xmax) : JOscParameter_t(JGrid_t(nx, xmin, xmax)) {} /** * Constructor. * * \param value complex phase value [rad] */ explicit JComplexPhase(const double value) : JComplexPhase(1, value, value) {} /** * Assignment operator. * * \param grid complex phase parameter grid [rad] * \return complex phase */ JComplexPhase_t& operator=(const JGrid_t& grid) { this->setValue(grid); return *this; } /** * Check validity of oscillation parameter. * * \return true if valid; else false */ bool is_valid() const override final { const double minPhase = this->getValue().getXmin(); const double maxPhase = this->getValue().getXmax(); return (this->isDefined() ? !(minPhase < 0.0 || minPhase > 2 * M_PI || maxPhase < 0.0 || maxPhase > 2 * M_PI) : true); } /** * Auxiliary function to create a complex phase parameter grid. * * \param value complex phase value [rad] * \return complex phase parameter */ static JComplexPhase_t make_parameter(const double value) { return JComplexPhase_t(value); } }; } #endif