#ifndef __JAANET__JEVTWEIGHTFACTORCONSTANT__ #define __JAANET__JEVTWEIGHTFACTORCONSTANT__ #include "JLang/JManip.hh" #include "JLang/JClonable.hh" #include "JLang/JComparable.hh" #include "Jeep/JProperties.hh" #include "JAAnet/JEvtWeightFactor.hh" /** * \author bjung */ namespace JAANET {} namespace JPP { using namespace JAANET; } namespace JAANET { using JLANG::JClonable; using JLANG::JComparable; using JEEP::JProperties; /** * Class for constant event-weight factors. * * The template argument refers to the type of event-weighter. */ template struct JEvtWeightFactorConstant : public JComparable >, public JClonable > { typedef JEvtWeightFactorConstant JEvtWeightFactorConstant_t; /** * Default constructor. */ JEvtWeightFactorConstant() : constant(1.0) {} /** * Constructor. * * \param constant constant */ JEvtWeightFactorConstant(const double constant) : constant(constant) { this->check_validity(); } /** * Check whether this constant event-weight factor is valid. * * \return true if valid; else false */ bool is_valid() const override final { return constant > 0.0; } /** * Get event-weight factor of given event. * * \param evt event * \return event-weight factor */ double getFactor(const Evt& evt) const override final { return constant; } /** * Check if this event-weight constant is less than given event-weight constant. * * \param object event-weight constant * \return true if this event-weight constant is less than given event-weight constant; else false */ bool less(const JEvtWeightFactorConstant_t& object) const { return this->constant < object.constant; } /** * Get properties of this class. * * \param eqpars equation parameters */ JProperties getProperties(const JEquationParameters& eqpars = JEvtWeightFactor::getEquationParameters()) override final { return JEvtWeightFactorConstantHelper(*this, eqpars); } /** * Get properties of this class. * * \param eqpars equation parameters */ JProperties getProperties(const JEquationParameters& eqpars = JEvtWeightFactor::getEquationParameters()) const override final { return JEvtWeightFactorConstantHelper(*this, eqpars); } /** * Stream input. * * \param in input stream * \return input stream */ std::istream& read(std::istream& in) override final { using namespace std; streampos pos = in.tellg(); if (!(in >> constant)) { in.clear(); in.seekg(pos); JProperties properties = getProperties(); in >> properties; } this->check_validity(); return in; } /** * Write event-weight factor to output * * \param out output stream * \return output stream */ std::ostream& write(std::ostream& out) const override final { using namespace JPP; return out << FIXED(10,3) << constant; } private: /** * Auxiliary class for I/O of constant event-weight factor. */ struct JEvtWeightFactorConstantHelper : public JProperties { /** * Constructor. * * \param factor constant event-weight factor * \param eqpars equation parameters */ template JEvtWeightFactorConstantHelper(JEvtWeightFactorConstant_T& factor, const JEquationParameters& eqpars) : JProperties(eqpars, 1) { (*this)[JEvtWeightFactor::getTypeKey()] = "constant"; this->insert(gmake_property(factor.constant)); } }; double constant; //!< constant value }; } #endif